Skip to content

fix(lp-gfx-wgpu): hoist struct/const declarations above generated prototypes#112

Merged
Yona-Appletree merged 1 commit into
mainfrom
claude/adoring-edison-a73199
Jul 16, 2026
Merged

fix(lp-gfx-wgpu): hoist struct/const declarations above generated prototypes#112
Yona-Appletree merged 1 commit into
mainfrom
claude/adoring-edison-a73199

Conversation

@Yona-Appletree

Copy link
Copy Markdown
Member

Summary

  • assemble_fragment_glsl spliced generated function prototypes above the authored GLSL, so any signature referencing a user-defined struct (Point make_point(float)) failed naga glsl-in with "Unknown type: Point", and files carrying their own forward declarations hit "Prototype already defined" duplicates.
  • New hoist_declarations pass over the texture-lowered authored text: top-level struct definitions and const declarations move above the generated prototypes (both signatures and struct members may use consts as array sizes), and authored prototypes are stripped with newline-preserving blanking so diagnostics keep their line numbers.
  • Stripping-and-regenerating was chosen over "skip generating a duplicate": skipping would assign the function's naga arena slot at the authored prototype's position — after every generated prototype — breaking the callee-first arena order its callers need.
  • The test-side reference renderer (tests/util/reference.rs) used the same splice pattern and now shares the hoist.
  • Corpus: removed the ~120 splice-rationale @unsupported(wgpu.f32) annotations across 23 files; 21 now pass on the GPU. Two files fail for distinct, genuine naga limitations and are re-annotated with accurate rationales: function/edge-const-out-error.glsl (glsl-in rejects the const in parameter qualifier) and function/access-lvalue-local-out-inout.glsl (WGSL forbids addressing a vector component; wgsl-out emits &v[i] for vector-lane out/inout args).

Validation

  • 4 new unit tests in assembly.rs (hoist ordering, prototype stripping vs. globals, struct-returning prototypes, line-count preservation); cargo test -p lp-gfx-wgpu fully green including render-parity and differential suites (Metal adapter).
  • Full wgpu.f32 filetest corpus: 5246/5246 files pass (5222 directives pass, 0 fail; net −103 unsupported).
  • The 23 re-enabled files: 600/600 across all CPU targets (interp.f32, wasm.q32, rv32c/n/lpn.q32).
  • just check and just test both pass.

Contribution Terms

By opening this pull request, I confirm that I have the right to submit these
changes and agree to the contribution terms in CONTRIBUTING.md.

🤖 Generated with Claude Code

…totypes

The GPU assembly spliced generated function prototypes above the authored
GLSL, so any signature referencing a user-defined struct failed naga
glsl-in with "Unknown type" (the struct definition sat below the
prototype), and files carrying their own forward declarations hit
"Prototype already defined" duplicates.

Add a hoist_declarations pass over the texture-lowered authored text:
top-level struct definitions and const declarations move above the
generated prototypes (signatures and struct members may use consts as
array sizes), and authored prototypes are stripped with line-preserving
blanking — merely skipping duplicate generation would assign the
function's naga arena slot at the authored prototype's position, after
every generated prototype, breaking callee-first arena order for its
callers. The test-side reference renderer used the same splice pattern
and now shares the hoist.

Corpus: drop the ~120 splice-rationale @unsupported(wgpu.f32)
annotations across 23 files; 21 now pass on the GPU. Two files fail for
distinct genuine naga limitations and are re-annotated accurately:
edge-const-out-error.glsl (glsl-in rejects the `const in` parameter
qualifier) and access-lvalue-local-out-inout.glsl (WGSL forbids
addressing a vector component; wgsl-out emits `&v[i]` for vector-lane
out/inout args).

Verified: wgpu.f32 corpus 5246/5246 files (net -103 unsupported), the
23 files 600/600 on all CPU targets, lp-gfx-wgpu suites, just check,
just test.

Co-Authored-By: Claude Fable 5 <[email protected]>
@Yona-Appletree
Yona-Appletree merged commit 7192171 into main Jul 16, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant