summaryrefslogtreecommitdiff
path: root/src/gpu/effects/flash_effect.cc
diff options
context:
space:
mode:
authorskal <pascal.massimino@gmail.com>2026-02-08 16:33:24 +0100
committerskal <pascal.massimino@gmail.com>2026-02-08 16:33:24 +0100
commit775c0ea61faeaa8a09638d94b2399117f8b8cea3 (patch)
treeeebe2e59f3a8f50d97585bdbf334cebd15651e4d /src/gpu/effects/flash_effect.cc
parentc7d1dd7ecb23d79cb00bc81ea8ec5ef61192f22a (diff)
fix(gpu): Correct FlashUniforms struct alignment for WGSL
Critical bugfix: Buffer size mismatch causing validation error **Problem:** Demo crashed with WebGPU validation error: "Buffer is bound with size 24 where the shader expects 32" **Root Cause:** WGSL struct alignment rules: - vec3<f32> has 16-byte alignment (not 12-byte) - C++ struct was 24 bytes, WGSL expected 32 bytes **Incorrect Layout (24 bytes):** ```cpp struct FlashUniforms { float flash_intensity; // 0-3 float intensity; // 4-7 float color[3]; // 8-19 (WRONG: no padding) float _pad; // 20-23 }; ``` **Correct Layout (32 bytes):** ```cpp struct FlashUniforms { float flash_intensity; // 0-3 float intensity; // 4-7 float _pad1[2]; // 8-15 (padding for vec3 alignment) float color[3]; // 16-27 (vec3 aligned to 16 bytes) float _pad2; // 28-31 }; ``` **WGSL Alignment Rules:** - vec3<f32> has size=12 bytes but alignment=16 bytes - Must pad before vec3 to maintain 16-byte boundary **Files Modified:** - src/gpu/effects/flash_effect.h (struct layout + static_assert) - src/gpu/effects/flash_effect.cc (field names: _pad → _pad1, _pad2) **Verification:** ✅ Demo runs without validation errors ✅ All 32 tests pass (100%) ✅ static_assert enforces correct size at compile time handoff(Claude): Critical alignment bug fixed, demo stable
Diffstat (limited to 'src/gpu/effects/flash_effect.cc')
-rw-r--r--src/gpu/effects/flash_effect.cc5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/gpu/effects/flash_effect.cc b/src/gpu/effects/flash_effect.cc
index e02ea75..1bb4d93 100644
--- a/src/gpu/effects/flash_effect.cc
+++ b/src/gpu/effects/flash_effect.cc
@@ -85,8 +85,9 @@ void FlashEffect::render(WGPURenderPassEncoder pass, float time, float beat,
const FlashUniforms u = {
.flash_intensity = flash_intensity_,
.intensity = intensity,
- .color = {r, g, b}, // Time-dependent, computed every frame
- ._pad = 0.0f};
+ ._pad1 = {0.0f, 0.0f}, // Padding for vec3 alignment
+ .color = {r, g, b}, // Time-dependent, computed every frame
+ ._pad2 = 0.0f};
uniforms_.update(ctx_.queue, u);
wgpuRenderPassEncoderSetPipeline(pass, pipeline_);