microts: AOT image baking ignores @2x variants and images.json, and accepts textures the core rejects

Aperta
#718 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
66/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
rust, typescript
Ambito
build-system

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

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}x sibling when the raster density is above 1, with the dimension check of assertDensityVariantDimensions;
  • images.json psm (pixels converted as encodeImageEntry does) and linear (upload_texture_flags with IMG_FLAG_LINEAR);
  • the power-of-two and TEX_MAX_DIM check 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.

Lingua principale
TypeScript
Stelle
1.6k
Fork
88
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Non abbiamo ancora controllato i file di configurazione di questo progetto. Parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di pocket-stack/pocketjs

Tutte le issue di pocket-stack/pocketjs

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.