microts: AOT image baking ignores @2x variants and images.json, and accepts textures the core rejects
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 66/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- rust, typescript
- 领域
- build-system
调研方向
Start at tools/aot-compile.ts:148-159, the image branch that decodes the 1x PNG and hardcodes PSM_8888. Compare it with the guest build's path in tools/build.ts:442-520, framework/compiler/raster-assets.ts (densityVariantPath, assertDensityVariantDimensions, encodeImageEntry) and the pow2/TEX_MAX_DIM check in framework/compiler/pak.ts:161-163, then mirror them in the AOT emitter, including upload_texture_flags for linear. Done when gen/include.rs bakes the @2x sibling at the raster density, honours images.json psm/linear, and compile fails with the guest error for a 100×60 texture, verified by the harness cargo test and the two repros.
由索引模型根据 Issue 内容生成。
描述
Version
PocketJS v0.17.0 (83c6cac9, current main). macOS 27.2 arm64, Bun 1.4.2, Rust 1.98.1.
Repro 1: density 2 and images.json
logo.png is any 32×32 RGBA PNG and [email protected] any 64×64 RGBA PNG.
pocket.host.json:
{
"format": "pocket-host/2",
"id": "repro-density2",
"platform": "esp-idf",
"form": "takeover",
"cadences": [30],
"display": {
"logicalViewports": [[160, 120]],
"presentations": ["native"],
"rasterDensity": 2,
"animation": "repaint"
},
"panel": { "primary": [320, 240] },
"capabilities": ["input.buttons", "text.glyphs.baked"]
}
// pocket.host.config.ts
import { defineHostConfig } from "@pocketjs/framework/host-config";
export default defineHostConfig({
host: "./pocket.host.json",
app: {
id: "dev.example.repro",
title: "Repro",
version: "0.1.0",
entry: "main.tsx",
output: "repro",
framework: "solid",
viewport: { logical: [160, 120], presentation: "native" },
features: ["input.buttons", "text.glyphs.baked"],
aot: true,
model: "compiled",
},
});
images.json:
{ "logo.png": { "psm": 2, "linear": true } }
// main.tsx
import { mount } from "@pocketjs/framework/solid";
import App from "./app.tsx";
mount(() => <App />);
// app.ts
import { createSignal } from "solid-js";
import type { i32 } from "@pocketjs/framework/solid/std";
export const [count, setCount] = createSignal<i32>(0);
// app.tsx
import { Image, Text, View } from "@pocketjs/framework/solid/components";
import { count } from "./app";
export default function App() {
return (
<View class="w-full h-full p-2 bg-slate-100">
<Image class="w-8 h-8" src="logo.png" />
<Text class="text-xs text-slate-900">{count()}</Text>
</View>
);
}
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --output out/app.pkb
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --aot --out gen
Actual 1
The guest build takes the @2x file and the images.json entry:
image: logo.png <- [email protected] (64x64, @2x for 32x32)
image: logo.png sampled linear (images.json)
Its pak entry ui:img.logo.png is 64×64, psm 2 (PSM_4444), flags 2 (IMG_FLAG_LINEAR), 8,200 bytes.
The AOT build writes gen/images/image-0.rgba (4,096 bytes) from the 1x file, and gen/include.rs uploads it as RGBA8888 without flags:
{ let id = ui.core_mut().upload_texture(include_bytes!("images/image-0.rgba"), 32, 32, microts::pocketjs_core::spec::psm::PSM_8888); assert!(id >= 0); ui.register_image("logo.png", id); }
On a density-2 panel the AOT image is upscaled from 32×32, unfiltered, and uses twice the bytes per pixel the application asked for.
Repro 2: a texture size the core rejects
The files of repro 1 at density 1 (logicalViewports [[240, 240]], panel.primary [240, 240], rasterDensity 1, viewport.logical [240, 240], no images.json), with banner.png any 100×60 RGBA PNG and:
// app.tsx
import { Image, Text, View } from "@pocketjs/framework/solid/components";
import { count } from "./app";
export default function App() {
return (
<View class="w-full h-full p-2 bg-slate-100">
<Image class="w-[100] h-[60]" src="banner.png" />
<Text class="text-xs text-slate-900">{count()}</Text>
</View>
);
}
To run the generated loader on the host:
# harness/Cargo.toml
[package]
name = "aot-load"
version = "0.0.0"
edition = "2021"
[dependencies]
microts = { path = "<pocketjs>/engine/microts-runtime" }
[workspace]
// harness/src/lib.rs
#![no_std]
extern crate alloc;
include!("../../gen/include.rs");
pub fn mount(ui: &mut microts::Ui) {
load_fonts(ui);
load_images(ui);
}
// harness/tests/load.rs
#[test]
fn generated_loaders() {
aot_load::mount(&mut microts::Ui::new());
}
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --output out/app.pkb
bun $POCKETJS/tools/pocket.ts compile --config pocket.host.config.ts --aot --out gen
(cd harness && cargo test)
Actual 2
The guest build stops:
error: pak image: dims must be pow2 <= 512, got 100x60
The AOT build succeeds and emits upload_texture(include_bytes!("images/image-0.rgba"), 100, 60, …PSM_8888); assert!(id >= 0);. The firmware panics when it mounts:
thread 'generated_loaders' panicked at src/../../gen/include.rs:13:135:
assertion failed: id >= 0
Expected
pocket compile --aot bakes images from the same inputs and with the same checks as the guest build:
- the
@{density}xsibling when the raster density is above 1, with the dimension check ofassertDensityVariantDimensions; images.jsonpsm(pixels converted asencodeImageEntrydoes) andlinear(upload_texture_flagswithIMG_FLAG_LINEAR);- the power-of-two and
TEX_MAX_DIMcheck at compile time, with the guest build's message.
Cause
tools/aot-compile.ts:148–159 resolves the name in the component's directory and the asset directories, decodes the PNG at 1x (decodePng), writes RGBA and emits upload_texture(…, PSM_8888). It does not call densityVariantPath, does not read images.json and does not check dimensions. SVGs are the exception: bakeSvg receives the raster density.
The guest build does the three in tools/build.ts:442–520, framework/compiler/raster-assets.ts and framework/compiler/pak.ts:161–163. The core returns -1 for a non-power-of-two size or one above TEX_MAX_DIM (engine/core/src/lib.rs:1167–1170), which the generated assert! turns into a panic.
Workaround
Ship power-of-two images no larger than 512 px. For density and format there is no workaround in the generated loader; a product can replace load_images with its own code.
- 主要语言
- TypeScript
- 星标
- 1.6k
- 派生
- 88
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
pocket-stack/pocketjs 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 74/100
pocket-stack/pocketjs#729 ·
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
pocket-stack/pocketjs#725 ·
-
enhancement
难度 1/5 1 小时以内 新手友好度 85/100
pocket-stack/pocketjs#724 ·
-
enhancement
难度 4/5 3-5 天 新手友好度 62/100
pocket-stack/pocketjs#728 ·
-
enhancement
难度 5/5 一周以上 新手友好度 30/100
pocket-stack/pocketjs#727 ·
查看 pocket-stack/pocketjs 的全部 Issue
相似的 Issue
-
kind:defect
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
mux-labs/mux-frontend#1240 ·
维护者通常 1 天内回复
-
area: agents-mcp priority: normal
难度 2/5 1-3 小时 新手友好度 64/100
维护者通常 1 天内回复
-
Wait for the IDS correction dialog to settle in the stale-audit test可能已有人在做 @louistrue 今天认领。 未关闭ready
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
Hono path parameters with a regex pattern keep the pattern in the OpenAPI path可能已有人在做 @0z5a 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
cloudflare/chanfana#400 ·
维护者通常 1 天内回复