refactor(webgpu): data-driven gating for WGSL built-in inputs#8739
Merged
Conversation
Follow-up to #8733. Generalizes gating of optional WGSL built-in inputs across all stages, fixes invalid WGSL for shaders without varyings, and restructures emission to be data-driven. Fixes: - Empty FragmentInput struct for fragment shaders with no varyings and no pc* references (e.g. gizmo-unlit). Sentinel built-in emitted only when struct would otherwise be empty. - Detection now recognises both pc* globals and input.field access. - Word-boundary regex prevents identifier-substring false positives. Changes: - FRAGMENT_BUILTINS / VERTEX_BUILTINS tables describe each optional built-in; adding one is a single-row change. - vertex_index / instance_index now gated symmetrically with fragment built-ins (previously always emitted). - Per-stage sentinel fallback (position for fragment, vertex_index for vertex) guarantees non-empty input structs. - processAttributes signature extended with device, source, entryInputName (internal only). - copyInputs re-runs ENTRY_FUNCTION match against the post-rename source to avoid stale brace positions.
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.
Follow-up to #8733. Generalizes the WebGPU shader processor's gating of optional WGSL built-in inputs so that all stages are handled consistently, fixes a regression that produced invalid WGSL for shaders without varyings, and restructures the emission to be data-driven so adding a new built-in is a one-row change.
Fixes:
FragmentInputstruct (invalid WGSL) for fragment shaders with no varyings and nopc*references (e.g. thegizmo-unlitshader). A sentinel built-in is now emitted only when the input struct would otherwise be empty.input.frontFacing,input.sampleIndex, ...), not only thepc*global form. Both forms are documented as supported inwgsl-specifics.md.String.includes) prevents false positives on identifiers containing the name as a substring.Changes:
FRAGMENT_BUILTINS/VERTEX_BUILTINStables describe each optional built-in (name, type,@builtin(...), publicpc*global, optional feature flag, optional sentinel role).vertex_index/instance_indexare now gated symmetrically with the fragment built-ins (previously always emitted). Gating uses bothpcVertexIndex/pcInstanceIndexandinput.vertexIndex/input.instanceIndex.positionfor fragment,vertex_indexfor vertex) keeps input structs non-empty even when nothing else is referenced.No public API changes — all changes are internal to the WGSL shader processor. Behaviour for existing engine shaders is unchanged (the few vertex chunks that reference `pcVertexIndex` / `pcInstanceIndex` continue to receive those built-ins; the rest now no longer carry two unused inputs).