fix(lp-gfx-wgpu): hoist struct/const declarations above generated prototypes#112
Merged
Merged
Conversation
…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 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
assemble_fragment_glslspliced 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.hoist_declarationspass over the texture-lowered authored text: top-levelstructdefinitions andconstdeclarations 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.tests/util/reference.rs) used the same splice pattern and now shares the hoist.@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 theconst inparameter qualifier) andfunction/access-lvalue-local-out-inout.glsl(WGSL forbids addressing a vector component; wgsl-out emits&v[i]for vector-lane out/inout args).Validation
assembly.rs(hoist ordering, prototype stripping vs. globals, struct-returning prototypes, line-count preservation);cargo test -p lp-gfx-wgpufully green including render-parity and differential suites (Metal adapter).just checkandjust testboth 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