Commit 97fe275
authored
feat: naga v0.14.0 — Essential 15 reference shaders, major WGSL coverage expansion
* fix(spirv): let semantics, ImageQuery capability, matrix multiply, deferred stores
- parser: letStmt() returns ConstDecl (named expression), not VarDecl
- spirv: add CapabilityImageQuery (50) for textureDimensions
- spirv: matrix multiply ops (mat*vec, vec*mat, mat*mat, mat*scalar)
- spirv: deferred complex stores for var x = func() - 0.5 pattern
- tests: function call in let, ImageQuery, full MSDF text shader
- hlsl: fix test for dead code elimination after let fix
* fix(spirv): Mul result type for scalar*vector, MatrixStride decoration
- ir/resolve: resolveBinaryType for Multiply now returns correct result
type (vec4 for scalar*vec4, not scalar). Matches WGSL spec.
- spirv/backend: add ColMajor + MatrixStride decorations for matrix
members in uniform blocks (required by Vulkan SPIR-V validation).
- tests: add spirv-val validation via Vulkan SDK in MSDF shader test.
* test(spirv): add spirv-val validation, SDF render shader test
- validateWithVulkanSDK: run spirv-val/spirv-dis from Vulkan SDK
- TestCompileSDFRenderShader: full SDF shape shader (both pass spirv-val)
- TestCompileMSDFTextShader: now validated by spirv-val
* fix(wgsl): emit let bindings at declaration point for SSA dominance
let bindings (ConstDecl) were lazily emitted at first use site by the
SPIR-V backend. When a let binding was first used inside an if/else
branch, the SPIR-V ID was defined in that branch block and could not
be used in the other branch — violating SSA dominance rules.
Fix: add StmtEmit at the let declaration point in lowerLocalConst,
forcing the expression to be emitted before any control flow.
Also adds 5 new shader compilation tests with spirv-val validation
covering gogpu and gg shaders (positionedQuad, texturedQuad,
stencilFill, cover, blit).
* fix(wgsl,spirv): module constants, switch termination, select/divide vector promotion
Four fixes for complex shader compilation:
1. Module-level const: lowerConstant now evaluates literal initializers
and registers them in IR, enabling switch cases with named constants
(e.g., case BLEND_NORMAL in blend shader).
2. Switch termination: blockEndsWithTerminator now handles StmtSwitch,
and emitSwitch adds OpUnreachable in unreachable merge blocks when
all cases return.
3. OpSelect vector promotion: when condition is scalar bool but operands
are vectors, splat condition to matching bool vector via
OpCompositeConstruct (WGSL broadcasts, SPIR-V does not).
4. OpFDiv vector/scalar: added promoteScalarToVector for divide operations
where one operand is vector and other is scalar, splatting the scalar.
Tested with gg blend shader (29 blend modes, HSL, switch, select, step).
* fix(spirv): vector/scalar promotion for add, subtract, modulo
Extends the scalar-to-vector splatting from divide to add, subtract,
and modulo operations. WGSL allows vec3 + scalar (broadcasts), but
SPIR-V OpFAdd/OpFSub/OpFMod require matching operand types.
* fix(spirv,wgsl): type resolution for scalar-vec ops, select float-to-bool, arrayed textures, image store
- Fix binary type resolution: scalar op vec returns vec type (not scalar)
- Fix OpSelect with float condition: convert to bool via OpFOrdNotEqual
- Fix getSampledImageType to resolve actual image type from expression
- Add array index handling for texture_2d_array sampling (SPIR-V vec3 coord)
- Add StmtImageStore (OpImageWrite) for textureStore() in compute shaders
- Add isTextureArrayed check in WGSL lowerer for arrayed texture sampling
- Add tests for full gg production shaders: blend (424 lines), strip, composite
- All 12 shader tests pass spirv-val validation
* fix(spirv): derive sampled type from storage format for storage texture OpTypeImage
Storage textures with uint/sint formats (e.g. rgba8uint) require the sampled
type to match the format (u32/i32), not hardcoded f32.
* fix(spirv): atomicStore/Load, workgroup layout, storage decorations, production shader tests
- Add atomicStore/atomicLoad WGSL lowering and SPIR-V emission
- AtomicStore uses Release semantics, AtomicLoad uses Acquire semantics
- Use emitPointerExpression for atomic pointer operands (not auto-load)
- Resolve AtomicType to ScalarType for constant emission
- Exclude workgroup variables from SPIR-V 1.3 entry point interfaces
- Emit workgroup array types without ArrayStride decoration
- Add NonReadable/NonWritable decorations for storage images
- Resolve ExprAtomicResult type by searching function body
- Add flatten, coarse, fine production shader compilation tests (all spirv-val VALID)
* fix(wgsl,spirv): loop continuing blocks, duplicate Block decoration
- Parse loop { ... continuing { ... } } syntax in WGSL parser
- Deduplicate Block decoration when multiple variables share a struct type
- Add boids (loop+continuing, runtime arrays) and collatz (while, function calls) reference shader tests
* fix(spirv,wgsl): uniform struct wrapping, vector type conversion, trailing semicolons
- Wrap non-struct Uniform variables in OpTypeStruct (VUID-StandaloneSpirv-Uniform-06807)
- Add AccessChain through wrapper struct when loading wrapped uniform values
- Add matrix ColMajor/MatrixStride decorations for wrapper struct members
- Handle vec2<i32>(vec2<f32>) as type conversion (ExprAs) instead of composition
- Parse optional trailing semicolons after struct declarations
- Export TypeResInner for cross-package use
- Add cube, hello_triangle, hello_compute reference shader tests
* fix(wgsl): float literals without trailing digit, increment/decrement, vector type inference
- Lex '1.' as float literal (WGSL allows trailing-dot floats like 1., -3.)
- Parse i++ and i-- as compound assignment (desugar to i += 1 / i -= 1)
- Infer vec2/vec3/vec4 scalar type from arguments when template params omitted
- Add MSAA line, uniform values (skipped), cube, hello_triangle, hello_compute tests
* test(spirv): add hello_workgroups, render_to_texture reference shader tests
- render_to_texture passes spirv-val (local arrays, vertex-less rendering)
- hello_workgroups skipped (requires abstract integer literal handling)
* fix(wgsl,spirv): const constructors, transpose, depth textures, angle bracket splitting
- Add composite constant lowering (vec3/vec4 constructors in module constants)
- Add unary negation support in constant expressions
- Add MathTranspose with native OpTranspose SPIR-V opcode
- Add matrix type caching to prevent duplicate OpTypeMatrix declarations
- Add texture_depth_2d_array as non-parameterized type
- Add textureSampleCompare/textureSampleCompareLevel lowering
- Fix textureDimensions to accept 1 argument (texture only)
- Fix >> token splitting for nested template closing (ptr<function, vec3<f32>>)
* fix(wgsl): struct constructors, pointer deref LHS, compound assignment
- Struct constructor syntax: StructName(field1, field2) creates ExprCompose
- Pointer dereference on assignment LHS: *ptr = val extracts inner pointer
- Compound assignment: remove explicit ExprLoad, use auto-load from SPIR-V backend
* feat(wgsl,spirv): short type aliases, switch parsing, discard, modf, call tree traversal
- Add 48 WGSL predeclared short type aliases (vec3f, mat4x4f, etc.)
- Fix switch/default parsing: default as case selector, trailing commas, optional colon
- Implement _ discard identifier in assignments and let bindings
- Implement modf().fract/whole and frexp().fract/exp member access
- Extend findCallResultInTree to handle 12 expression types (swizzle, access, compose, etc.)
- Refactor token.go String() to map-based lookup with full coverage
Essential 15 reference shaders: 8/15 pass (was 7/14)
* feat(wgsl,spirv): abstract constructors, bitcast, math functions, texture gather, pointer access
Parser:
- Abstract type constructors without template params (vec3(...), array(...))
- bitcast<T>(expr) template syntax with BitcastExpr AST node
- Float literal f/h suffix without decimal point (1f, 1h)
Lowerer:
- Constant expression evaluator for switch case selectors
- dot4I8Packed/dot4U8Packed math builtins
- textureGather, textureGatherCompare, textureSampleBaseClampToEdge
- evalGatherComponent for compile-time component validation
SPIR-V backend:
- 25 new math functions: bit manipulation, pack/unpack, quantizeF16, dot product packed
- OpImageGather/OpImageDrefGather emission with component index
- Pointer access chains on function arguments (ExprLoad, ExprFunctionArgument)
- SPV_KHR_integer_dot_product extension support
- findCallResultInTree extended to 12+ expression types
Essential 15 reference shaders: 10/15 pass (was 8/15)
* feat(wgsl,spirv): Essential 15 reference shaders — 15/15 pass
Complete WGSL language coverage for all Essential 15 Rust naga reference shaders:
Parser:
- Abstract constructors for all types (vec/mat/array without <T>)
- binding_array<T, N> type syntax
Lowerer:
- BitcastExpr handling (ExprAs with CastBitcast)
- Global variable type inference from initializer
- textureGather depth overloads (3-4 args, no component)
- Constant expression evaluator for switch case selectors
- BindingArrayType resolution and opaque resource detection
IR:
- BindingArrayType for descriptor array types
SPIR-V:
- BindingArrayType emission (OpTypeArray/OpTypeRuntimeArray)
- Access chain indexing into binding arrays
- Identity conversion early return (bool(bool()))
- Inline type handling in pointer access chains
Essential 15: 15/15 pass (was 10/15)
* test(spirv): Essential 15 + 2 bonus reference shader regression tests
Embedded 17 Rust naga reference WGSL shaders as regression tests:
- 15 Essential shaders covering core WGSL features
- 2 bonus shaders (skybox, water) for advanced coverage
- Full pipeline: lex → parse → lower → SPIR-V compile
- SPIR-V magic number and size validation
- Shader sources embedded as string literals (CI-ready, no external deps)
* docs: add ARCHITECTURE.md, update CHANGELOG and README for v0.14.01 parent 8ed2b77 commit 97fe275
File tree
17 files changed
+7426
-268
lines changed- docs
- hlsl
- ir
- spirv
- wgsl
17 files changed
+7426
-268
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
8 | 90 | | |
9 | 91 | | |
10 | 92 | | |
| |||
726 | 808 | | |
727 | 809 | | |
728 | 810 | | |
| 811 | + | |
729 | 812 | | |
730 | 813 | | |
731 | 814 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
34 | 34 | | |
35 | 35 | | |
36 | 36 | | |
37 | | - | |
| 37 | + | |
38 | 38 | | |
39 | 39 | | |
| 40 | + | |
40 | 41 | | |
41 | 42 | | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | | - | |
| 48 | + | |
| 49 | + | |
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
51 | 53 | | |
52 | 54 | | |
53 | 55 | | |
54 | 56 | | |
55 | | - | |
| 57 | + | |
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
62 | 64 | | |
| 65 | + | |
63 | 66 | | |
64 | 67 | | |
65 | 68 | | |
| |||
240 | 243 | | |
241 | 244 | | |
242 | 245 | | |
243 | | - | |
244 | | - | |
| 246 | + | |
| 247 | + | |
245 | 248 | | |
246 | | - | |
| 249 | + | |
247 | 250 | | |
248 | | - | |
| 251 | + | |
249 | 252 | | |
| 253 | + | |
| 254 | + | |
250 | 255 | | |
251 | 256 | | |
252 | 257 | | |
| |||
313 | 318 | | |
314 | 319 | | |
315 | 320 | | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
316 | 325 | | |
317 | 326 | | |
318 | 327 | | |
| |||
331 | 340 | | |
332 | 341 | | |
333 | 342 | | |
| 343 | + | |
334 | 344 | | |
335 | 345 | | |
336 | 346 | | |
| |||
0 commit comments