From b3eded8d56219fa19029a1b9bb7e7e7584f093d9 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 17 Feb 2026 12:35:59 +0100 Subject: refactor(effects): Factor shared initialization into Effect base class Eliminate ~100 lines of duplicated code across effect subclasses by moving common resource initialization to the base Effect class. Most effects repeatedly created uniforms buffers, samplers, and dummy textures with identical configurations. Changes: - Add shared members to Effect: uniforms_buffer_, sampler_, dummy_texture_* - Add helpers: init_uniforms_buffer(), create_*_sampler(), create_dummy_scene_texture() - Add gpu_create_*_sampler() and gpu_create_dummy_scene_texture() to gpu.h - Move HEADLESS_RETURN_IF_NULL to Effect constructor - Update 7 effects to use base class helpers (Flash, Heptagon, Passthrough, Placeholder, GaussianBlur, Particles, PeakMeter) Benefits: Improved consistency, easier maintenance, reduced binary size. Co-Authored-By: Claude Sonnet 4.5 --- src/effects/particles_effect.cc | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) (limited to 'src/effects/particles_effect.cc') diff --git a/src/effects/particles_effect.cc b/src/effects/particles_effect.cc index d83f303..3c9feb7 100644 --- a/src/effects/particles_effect.cc +++ b/src/effects/particles_effect.cc @@ -12,11 +12,9 @@ Particles::Particles(const GpuContext& ctx, const std::vector& outputs, float start_time, float end_time) : Effect(ctx, inputs, outputs, start_time, end_time) { - // Headless mode: skip GPU resource creation (compiled out in STRIP_ALL) HEADLESS_RETURN_IF_NULL(ctx_.device); - // Initialize uniforms - uniforms_.init(ctx_.device); + init_uniforms_buffer(); // Initialize particles buffer std::vector init_p(NUM_PARTICLES); @@ -49,7 +47,7 @@ Particles::Particles(const GpuContext& ctx, // Create compute shader (particle simulation) ResourceBinding compute_bindings[] = { {particles_buffer_, WGPUBufferBindingType_Storage}, - {uniforms_.get(), WGPUBufferBindingType_Uniform}}; + {uniforms_buffer_.get(), WGPUBufferBindingType_Uniform}}; compute_pass_ = gpu_create_compute_pass(ctx_.device, particle_compute_wgsl, compute_bindings, 2); compute_pass_.workgroup_size_x = (NUM_PARTICLES + 63) / 64; @@ -57,7 +55,7 @@ Particles::Particles(const GpuContext& ctx, // Create render shader (particle rendering) ResourceBinding render_bindings[] = { {particles_buffer_, WGPUBufferBindingType_ReadOnlyStorage}, - {uniforms_.get(), WGPUBufferBindingType_Uniform}}; + {uniforms_buffer_.get(), WGPUBufferBindingType_Uniform}}; render_pass_ = gpu_create_render_pass(ctx_.device, WGPUTextureFormat_RGBA8Unorm, particle_render_wgsl, render_bindings, 2); @@ -69,7 +67,7 @@ void Particles::render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, NodeRegistry& nodes) { // Update uniforms - uniforms_.update(ctx_.queue, params); + uniforms_buffer_.update(ctx_.queue, params); // Run compute pass (particle simulation) WGPUComputePassEncoder compute = -- cgit v1.2.3