diff options
| author | skal <pascal.massimino@gmail.com> | 2026-02-17 13:05:11 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-02-17 13:05:11 +0100 |
| commit | bdb1a4e95a545f3f4d88630b8aec6ab771776d99 (patch) | |
| tree | 97a3a15381a7ff9780644ec8876535dd219f23cf /doc | |
| parent | a32c7456588abf4f44866d0c055fa94d105e8ef7 (diff) | |
refactor(effects): Streamline uniforms initialization
Centralized uniforms_buffer_ initialization and updates to Effect base class:
- init_uniforms_buffer() now automatic in Effect::Effect()
- uniforms_buffer_.update() now automatic in dispatch_render()
- Removed redundant calls from all effect subclasses
- Updated effect.h comments to reflect automatic behavior
- Updated EFFECT_WORKFLOW.md templates
Benefits:
- 16 lines removed from effect implementations
- Consistent pattern enforced at compile time
- Reduced boilerplate for new effects
Tests: 34/34 passing
handoff(Claude): Effect base class now handles uniforms automatically
Diffstat (limited to 'doc')
| -rw-r--r-- | doc/EFFECT_WORKFLOW.md | 39 |
1 files changed, 22 insertions, 17 deletions
diff --git a/doc/EFFECT_WORKFLOW.md b/doc/EFFECT_WORKFLOW.md index c4010db..46aebd2 100644 --- a/doc/EFFECT_WORKFLOW.md +++ b/doc/EFFECT_WORKFLOW.md @@ -44,14 +44,18 @@ void render(WGPUCommandEncoder encoder, void declare_nodes(NodeRegistry& registry) override; ``` -**Uniforms**: +**Uniforms** (auto-updated by base class): ```cpp +// Available in render() via params: params.time; // Physical seconds params.beat_time; // Musical beats params.beat_phase; // Fractional beat 0.0-1.0 params.audio_intensity; // Audio peak params.resolution; // vec2(width, height) params.aspect_ratio; // width/height + +// uniforms_buffer_ automatically initialized and updated +// No need to call init_uniforms_buffer() or uniforms_buffer_.update() ``` ### 2. Add Shader to Assets @@ -143,17 +147,15 @@ class MyEffect : public Effect { MyEffect::MyEffect(const GpuContext& ctx, const std::vector<std::string>& inputs, - const std::vector<std::string>& outputs) - : Effect(ctx, inputs, outputs), pipeline_(nullptr), bind_group_(nullptr) { - uniforms_buffer_.init(ctx_.device); - pipeline_ = create_post_process_pipeline(ctx_.device, - WGPUTextureFormat_RGBA8Unorm, - my_shader_wgsl); -} + const std::vector<std::string>& outputs, + float start_time, float end_time) + : Effect(ctx, inputs, outputs, start_time, end_time) { + HEADLESS_RETURN_IF_NULL(ctx_.device); -MyEffect::~MyEffect() { - if (bind_group_) wgpuBindGroupRelease(bind_group_); - if (pipeline_) wgpuRenderPipelineRelease(pipeline_); + // uniforms_buffer_ already initialized by base class + pipeline_.set(create_post_process_pipeline(ctx_.device, + WGPUTextureFormat_RGBA8Unorm, + my_shader_wgsl)); } void MyEffect::render(WGPUCommandEncoder encoder, @@ -162,9 +164,9 @@ void MyEffect::render(WGPUCommandEncoder encoder, WGPUTextureView input_view = nodes.get_view(input_nodes_[0]); WGPUTextureView output_view = nodes.get_view(output_nodes_[0]); - uniforms_buffer_.update(ctx_.queue, params); - pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view, - uniforms_buffer_.get(), {nullptr, 0}); + // uniforms_buffer_ already updated by base class dispatch_render() + pp_update_bind_group(ctx_.device, pipeline_.get(), bind_group_.get_address(), + input_view, uniforms_buffer_.get(), {nullptr, 0}); WGPURenderPassColorAttachment color_attachment = { .view = output_view, @@ -196,9 +198,12 @@ void MyEffect::render(WGPUCommandEncoder encoder, class My3DEffect : public Effect { std::string depth_node_; - My3DEffect(const GpuContext& ctx, ...) - : Effect(ctx, inputs, outputs), - depth_node_(outputs[0] + "_depth") {} + My3DEffect(const GpuContext& ctx, ..., float start_time, float end_time) + : Effect(ctx, inputs, outputs, start_time, end_time), + depth_node_(outputs[0] + "_depth") { + HEADLESS_RETURN_IF_NULL(ctx_.device); + // Custom uniforms if needed (don't use base uniforms_buffer_) + } void declare_nodes(NodeRegistry& registry) override { registry.declare_node(depth_node_, NodeType::DEPTH24, -1, -1); |
