summaryrefslogtreecommitdiff
path: root/src/gpu/wgsl_effect.h
blob: 062f8854f5046e3d691ad8f38ef94d30b7ffd72f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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_;
};