From 05fdd78a78b83a322abc1b507325644662f3a9c1 Mon Sep 17 00:00:00 2001 From: skal Date: Thu, 12 Feb 2026 00:40:53 +0100 Subject: refactor: use CommonUniforms from common_uniforms.wgsl in test_demo MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Instead of duplicating the uniform structure definition, PeakMeterEffect now uses ShaderComposer to include the common_uniforms snippet, ensuring the struct definition always matches the canonical version. Changes: - Added shader_composer.h include - Use ShaderComposer::Get().Compose() to prepend common_uniforms - Changed 'Uniforms' → 'CommonUniforms' in shader - Removed duplicate struct definition This ensures consistency across all shaders and eliminates potential drift between duplicate definitions. Co-Authored-By: Claude Sonnet 4.5 --- src/test_demo.cc | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src') diff --git a/src/test_demo.cc b/src/test_demo.cc index 595ca6a..b564b9b 100644 --- a/src/test_demo.cc +++ b/src/test_demo.cc @@ -21,33 +21,25 @@ extern void LoadTimeline(MainSequence& main_seq, const GpuContext& ctx); // Inline peak meter effect for debugging audio-visual sync #include "gpu/effects/post_process_helper.h" +#include "gpu/effects/shader_composer.h" + class PeakMeterEffect : public PostProcessEffect { public: PeakMeterEffect(const GpuContext& ctx) : PostProcessEffect(ctx) { - // Use standard post-process binding macros - const char* shader_code = R"( + // Use ShaderComposer to include CommonUniforms from common_uniforms.wgsl + const char* shader_main = R"( struct VertexOutput { @builtin(position) position: vec4, @location(0) uv: vec2, }; - struct Uniforms { - resolution: vec2, - aspect_ratio: f32, - time: f32, - beat_time: f32, - beat_phase: f32, - audio_intensity: f32, - _pad: f32, - }; - struct EffectParams { unused: f32, }; @group(0) @binding(0) var inputSampler: sampler; @group(0) @binding(1) var inputTexture: texture_2d; - @group(0) @binding(2) var uniforms: Uniforms; + @group(0) @binding(2) var uniforms: CommonUniforms; @group(0) @binding(3) var params: EffectParams; @vertex @@ -86,8 +78,12 @@ class PeakMeterEffect : public PostProcessEffect { } )"; + // Compose shader with common_uniforms to get CommonUniforms definition + std::string shader_code = ShaderComposer::Get().Compose( + {"common_uniforms"}, shader_main); + pipeline_ = - create_post_process_pipeline(ctx_.device, ctx_.format, shader_code); + create_post_process_pipeline(ctx_.device, ctx_.format, shader_code.c_str()); } void update_bind_group(WGPUTextureView input_view) { -- cgit v1.2.3