From 1e3e3f54a4f80bd05d168c9ae749ed32e1275868 Mon Sep 17 00:00:00 2001 From: skal Date: Fri, 6 Feb 2026 14:08:09 +0100 Subject: fix(shaders): Resolve WGSL validation errors and add shader compilation tests Fixed three critical WGSL shader issues causing demo64k and test_3d_render to crash: 1. **renderer_3d.wgsl**: Removed dead code using non-existent `inverse()` function - WGSL doesn't have `inverse()` for matrices - Dead code was unreachable but still validated by shader compiler - Also removed reference to undefined `in.normal` vertex input 2. **sdf_utils.wgsl & lighting.wgsl**: Fixed `get_normal_basic()` signature mismatch - Changed parameter from `obj_type: f32` to `obj_params: vec4` - Now correctly matches `get_dist()` function signature 3. **scene_query_linear.wgsl**: Fixed incorrect BVH binding declaration - Linear mode was incorrectly declaring binding 2 (BVH buffer) - Replaced BVH traversal with simple linear object loop - Root cause: Both BVH and Linear shaders were identical (copy-paste error) Added comprehensive shader compilation test (test_shader_compilation.cc): - Tests all production shaders compile successfully through WebGPU - Validates both BVH and Linear composition modes - Catches WGSL syntax errors, binding mismatches, and type errors - Would have caught all three bugs fixed in this commit Why tests didn't catch this: - Existing test_shader_assets only checked for keywords, not compilation - No test actually created WebGPU shader modules from composed code - New test fills this gap with real GPU validation Results: - demo64k runs without WebGPU errors - test_3d_render no longer crashes - All 22/23 tests pass (FftTest unrelated issue from FFT Phase 1) Co-Authored-By: Claude Sonnet 4.5 --- assets/final/shaders/lighting.wgsl | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'assets/final/shaders/lighting.wgsl') diff --git a/assets/final/shaders/lighting.wgsl b/assets/final/shaders/lighting.wgsl index 277909b..ac2142b 100644 --- a/assets/final/shaders/lighting.wgsl +++ b/assets/final/shaders/lighting.wgsl @@ -1,10 +1,11 @@ -fn get_normal_basic(p: vec3, obj_type: f32) -> vec3 { +fn get_normal_basic(p: vec3, obj_params: vec4) -> vec3 { + let obj_type = obj_params.x; if (obj_type == 1.0) { return normalize(p); } let e = vec2(0.001, 0.0); return normalize(vec3( - get_dist(p + e.xyy, obj_type) - get_dist(p - e.xyy, obj_type), - get_dist(p + e.yxy, obj_type) - get_dist(p - e.yxy, obj_type), - get_dist(p + e.yyx, obj_type) - get_dist(p - e.yyx, obj_type) + get_dist(p + e.xyy, obj_params) - get_dist(p - e.xyy, obj_params), + get_dist(p + e.yxy, obj_params) - get_dist(p - e.yxy, obj_params), + get_dist(p + e.yyx, obj_params) - get_dist(p - e.yyx, obj_params) )); } -- cgit v1.2.3