diff options
| author | skal <pascal.massimino@gmail.com> | 2026-03-07 19:02:07 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-03-07 19:02:07 +0100 |
| commit | e4851ae9f310b44dab25eb979733281002c8953d (patch) | |
| tree | ee93eb4f2890acfac37a52ca204081783fa46b2e /src/gpu/wgsl_effect.h | |
| parent | 95802739b8ccaf9112fe4fe6e496ba7ae4158aae (diff) | |
refactor(effects): introduce WgslEffect for shader-only post-process effects
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 <noreply@anthropic.com>
Diffstat (limited to 'src/gpu/wgsl_effect.h')
| -rw-r--r-- | src/gpu/wgsl_effect.h | 38 |
1 files changed, 38 insertions, 0 deletions
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<std::string>& inputs, + const std::vector<std::string>& 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<WgslEffectParams> params_buffer_; + WGPULoadOp load_op_; +}; |
