fix(lower): reject fragment-only builtins in vertex stage - #6
Merged
Conversation
- Derivatives (dpdx/dpdy/fwidth) are illegal in vertex shaders on every backend (WGSL, GLSL, Metal, GLES) — not merely unflagged — so they now produce a compile-time diagnostic (SEL2003) instead of reaching the emitter and failing naga or glslangValidator - Texture sampling calls (sample/sampleLevel/sampleCube) had no binding wired through to the vertex scaffold on three of four backends (GLSL ES, GLES 3.00, Metal omit texture/sampler params from the vertex signature), so they are now rejected at compile time with a diagnostic rather than emitting an undeclared identifier - inVertexStage guard added to resolver.go and typer.go, enabled from lower_vertex.go when lowering an authored vertex() body; the fragment resolver/typer for lowerMeshWithVertex is not affected - Tests added to lower/ for rejection and for allowing derivatives in surface() alongside an authored vertex(); validate/ gains empirical proof via naga and glslangValidator that the old, unguarded behaviour would have failed validation - README, roadmap, and language-guide updated to reflect that the full vertex() -> vec4 replacement stage shipped in v0.3.1; only the composing hook remains unimplemented
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
Fixes a bug where fragment-stage-only builtins (derivatives and texture sampling functions) were silently accepted in authored vertex() stages, causing validation failures on every backend. Introduces compile-time diagnostics to reject these calls in the vertex stage while preserving their functionality in the surface stage.
Changes
inVertexStageflag toresolverandtyperduring mesh authored vertex lowering.dpdx,dpdy,fwidth,sample,sampleLevel, andsampleCubeinsidevertex()with aCodeInvalidCalldiagnostic.surface()and other valid stages.surface()or usestateAt()for simulation state.lowerandvalidatepackages to verify compile-time rejection and prove the prior behavior failed backend validators.Testing
go test ./lower -run "TestLowerRejects|TestLowerAllows" -vgo test ./validate -run "TestVertexStageRejects|TestPreFix" -vsample()ordpdx()insidevertex()and verify it produces a SEL2003 diagnostic instead of emitting invalid shaders.