From e50db1721f67a6c1b565b0ac151ba32fcae21cbf Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 9 Feb 2026 10:34:01 +0100 Subject: fix: Resolve WebGPU uniform buffer alignment issues (Task #74) Fixed multiple WGSL/C++ struct alignment mismatches causing validation errors: Padding fixes: - fade_effect.cc: Changed EffectParams padding from vec3 to _pad0/1/2 - theme_modulation_effect.cc: Same padding fix for EffectParams - Root cause: WGSL vec3 has 16-byte alignment, creating 32-byte structs ODR violation fix: - demo_effects.h: Added includes for fade_effect.h, theme_modulation_effect.h - Removed incomplete forward declarations (88 bytes) conflicting with complete definitions (96 bytes), causing heap buffer overflow in make_shared Member shadowing cleanup: - Renamed Effect::uniforms_ shadowing members to descriptive names: - FadeEffect: uniforms_ -> common_uniforms_ - FlashEffect: uniforms_ -> flash_uniforms_ - ThemeModulationEffect: uniforms_ -> common_uniforms_ Results: - demo64k runs without crashes - 33/33 tests passing (100%) - Added Task #75: WGSL uniform validation tool handoff(Claude): Uniform buffer alignment debugged and fixed --- src/gpu/effects/flash_effect.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gpu/effects/flash_effect.cc') diff --git a/src/gpu/effects/flash_effect.cc b/src/gpu/effects/flash_effect.cc index ccf0756..57c1d73 100644 --- a/src/gpu/effects/flash_effect.cc +++ b/src/gpu/effects/flash_effect.cc @@ -55,12 +55,12 @@ FlashEffect::FlashEffect(const GpuContext& ctx, const FlashEffectParams& params) pipeline_ = create_post_process_pipeline(ctx_.device, ctx_.format, shader_code); - uniforms_.init(ctx_.device); + flash_uniforms_.init(ctx_.device); } void FlashEffect::update_bind_group(WGPUTextureView input_view) { pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view, - uniforms_.get(), {}); + flash_uniforms_.get(), {}); } void FlashEffect::render(WGPURenderPassEncoder pass, float time, float beat, @@ -88,7 +88,7 @@ void FlashEffect::render(WGPURenderPassEncoder pass, float time, float beat, ._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); + flash_uniforms_.update(ctx_.queue, u); wgpuRenderPassEncoderSetPipeline(pass, pipeline_); wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr); -- cgit v1.2.3