From e4851ae9f310b44dab25eb979733281002c8953d Mon Sep 17 00:00:00 2001 From: skal Date: Sat, 7 Mar 2026 19:02:07 +0100 Subject: refactor(effects): introduce WgslEffect for shader-only post-process effects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace boilerplate .h/.cc pairs for simple single-pass effects with a generic WgslEffect base class that takes a shader string + optional WgslEffectParams (binding 3). Port Flash, Passthrough, Heptagon, Scratch, and GaussianBlur to thin header-only wrappers — no .cc files, no CMake entries needed. Removes 5 .cc files (-243 lines). Update EFFECT_WORKFLOW.md, CONTRIBUTING.md, and AI_RULES.md to document the WgslEffect (Path A) vs full class (Path B) workflow. Doc cleanup: fix stale GaussianBlurParams/PostProcessEffect references and test counts. handoff(Claude): WgslEffect landed; 5 effects ported; docs updated. Co-Authored-By: Claude Sonnet 4.6 --- src/gpu/wgsl_effect.h | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/gpu/wgsl_effect.h (limited to 'src/gpu/wgsl_effect.h') diff --git a/src/gpu/wgsl_effect.h b/src/gpu/wgsl_effect.h new file mode 100644 index 0000000..062f885 --- /dev/null +++ b/src/gpu/wgsl_effect.h @@ -0,0 +1,38 @@ +// WgslEffect: generic shader-only post-process effect. +// Replaces boilerplate .h/.cc pairs for simple single-pass effects. + +#pragma once +#include "gpu/effect.h" +#include "gpu/uniform_helper.h" +#include "gpu/wgpu_resource.h" + +// Generic per-effect uniform params (binding 3, 32 bytes). +// Matches WgslEffectParams in WGSL: struct { p: vec4f, c: vec4f } +// effect_params.p — 4 generic floats (strength, scale, etc.) +// effect_params.c — color or secondary vec4 +struct WgslEffectParams { + float p[4]; // vec4: generic float params + float c[4]; // vec4: color / secondary params +}; +static_assert(sizeof(WgslEffectParams) == 32, "WgslEffectParams must be 32 bytes"); + +class WgslEffect : public Effect { + public: + // Mutate per-frame for dynamic parameter modulation. + WgslEffectParams effect_params; + + WgslEffect(const GpuContext& ctx, const std::vector& inputs, + const std::vector& outputs, float start_time, + float end_time, const char* shader_code, + WGPULoadOp load_op = WGPULoadOp_Clear, + WgslEffectParams initial_params = {}); + + void render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, + NodeRegistry& nodes) override; + + private: + RenderPipeline pipeline_; + BindGroup bind_group_; + UniformBuffer params_buffer_; + WGPULoadOp load_op_; +}; -- cgit v1.2.3