microts: AOT image baking ignores @2x variants and images.json, and accepts textures the core rejects
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 66/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Công nghệ
- rust, typescript
- Lĩnh vực
- build-system
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- TypeScript
- Star
- 1.6k
- Fork
- 88
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của pocket-stack/pocketjs
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
pocket-stack/pocketjs#729 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
pocket-stack/pocketjs#725 ·
-
enhancement
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
pocket-stack/pocketjs#724 ·
-
enhancement
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 62/100
pocket-stack/pocketjs#728 ·
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 30/100
pocket-stack/pocketjs#727 ·
Tất cả issue của pocket-stack/pocketjs
Issue tương tự
-
kind:defect
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 66/100
mux-labs/mux-frontend#1240 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
area: agents-mcp priority: normal
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Wait for the IDS correction dialog to settle in the stale-audit testCó thể đã có người làm @louistrue đã nhận hôm nay. Đang mởready
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Hono path parameters with a regex pattern keep the pattern in the OpenAPI pathCó thể đã có người làm @0z5a đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
cloudflare/chanfana#400 ·
Maintainer thường phản hồi trong vòng 1 ngày