From 5d20c892dedce7bc7486acbd72fbd35da69e413e Mon Sep 17 00:00:00 2001 From: skal Date: Wed, 20 May 2026 22:44:44 +0200 Subject: fix: code review cleanup — bugs, dead code, factorization (-167 lines) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bugs: - B1: fix dead tempo debug (prev_tempo captured after assignment) - B2: fix ReloadAssetsFromFile leak for disk-loaded assets; simplify DropAsset - B3: fix get_free_pool_slot leak (unregister synth + free data on reuse) - B4: volatile -> std::atomic with acquire/release in miniaudio_backend, synth - B5: fix unaligned reads in scene_loader (memcpy-based read_f32/read_u32) - B6: fix shader module + BGL + pipeline layout leaks in gpu.cc, pipeline_builder Dead code: - D1: remove unused particle_defs.h - D3: remove create_post_process_pipeline_simple (zero callers) - D4: remove empty gpu_draw() - D5: remove write-only Hybrid3D::initialized_ - D6: remove legacy pending buffer path in audio.cc Factorization: - F1: Effect::run_fullscreen_pass() replaces boilerplate in 5 effects - F2: particle_common.wgsl snippet, #include in 3 WGSL shaders - F3: gpu_create_shader_module() helper, used in 3 call sites - F5: get_world_aabb() shared between bvh.cc and physics.cc - F6: samples_to_seconds() replaces 6 inline expressions - F7: gpu_create_linear/nearest_sampler use SamplerCache; add nearest() preset 37/37 tests passing. handoff(Claude): code review batch — all items verified, no regressions. --- src/effects/hybrid3_d_effect.cc | 2 -- src/effects/hybrid3_d_effect.h | 1 - src/effects/particle_compute.wgsl | 8 +------- src/effects/particle_defs.h | 13 ------------- src/effects/particle_render.wgsl | 8 +------- src/effects/particle_spray_compute.wgsl | 8 +------- src/effects/peak_meter_effect.cc | 17 ++--------------- src/effects/placeholder_effect.cc | 15 +-------------- src/effects/scene1_effect.cc | 15 +-------------- src/effects/scene2_effect.cc | 15 +-------------- src/effects/shaders.cc | 2 ++ 11 files changed, 10 insertions(+), 94 deletions(-) delete mode 100644 src/effects/particle_defs.h (limited to 'src/effects') diff --git a/src/effects/hybrid3_d_effect.cc b/src/effects/hybrid3_d_effect.cc index 33a2d73..bef82b4 100644 --- a/src/effects/hybrid3_d_effect.cc +++ b/src/effects/hybrid3_d_effect.cc @@ -42,8 +42,6 @@ Hybrid3D::Hybrid3D(const GpuContext& ctx, renderer_.set_noise_texture(dummy_texture_view_); renderer_.set_sky_texture(dummy_texture_view_); - initialized_ = true; - // Setup simple scene (1 center cube + 8 surrounding objects) scene_.clear(); Object3D center(ObjectType::BOX); diff --git a/src/effects/hybrid3_d_effect.h b/src/effects/hybrid3_d_effect.h index 13fd7df..88047dd 100644 --- a/src/effects/hybrid3_d_effect.h +++ b/src/effects/hybrid3_d_effect.h @@ -24,7 +24,6 @@ class Hybrid3D : public Effect { Renderer3D renderer_; Scene scene_; Camera camera_; - bool initialized_ = false; std::string depth_node_; WGPUTexture dummy_texture_; WGPUTextureView dummy_texture_view_; diff --git a/src/effects/particle_compute.wgsl b/src/effects/particle_compute.wgsl index f3e8051..148a2c3 100644 --- a/src/effects/particle_compute.wgsl +++ b/src/effects/particle_compute.wgsl @@ -1,11 +1,5 @@ // Particle simulation (compute shader) - V2 -struct Particle { - pos: vec4f, - vel: vec4f, - rot: vec4f, - color: vec4f, -}; - +#include "particle_common" #include "sequence_uniforms" @group(0) @binding(0) var particles: array; diff --git a/src/effects/particle_defs.h b/src/effects/particle_defs.h deleted file mode 100644 index dcbb830..0000000 --- a/src/effects/particle_defs.h +++ /dev/null @@ -1,13 +0,0 @@ -// This file is part of the 64k demo project. -// It defines common structures for particle-based effects. - -#pragma once - -static const int NUM_PARTICLES = 10000; - -struct Particle { - float pos[4]; - float vel[4]; - float rot[4]; - float color[4]; -}; diff --git a/src/effects/particle_render.wgsl b/src/effects/particle_render.wgsl index ef0db42..66b0b9c 100644 --- a/src/effects/particle_render.wgsl +++ b/src/effects/particle_render.wgsl @@ -1,11 +1,5 @@ // Particle rendering (vertex + fragment) - V2 -struct Particle { - pos: vec4f, - vel: vec4f, - rot: vec4f, - color: vec4f, -}; - +#include "particle_common" #include "sequence_uniforms" @group(0) @binding(0) var particles: array; diff --git a/src/effects/particle_spray_compute.wgsl b/src/effects/particle_spray_compute.wgsl index 7bdae88..84a51f4 100644 --- a/src/effects/particle_spray_compute.wgsl +++ b/src/effects/particle_spray_compute.wgsl @@ -1,10 +1,4 @@ -struct Particle { - pos: vec4f, - vel: vec4f, - rot: vec4f, - color: vec4f, -}; - +#include "particle_common" #include "common_uniforms" @group(0) @binding(0) var particles: array; diff --git a/src/effects/peak_meter_effect.cc b/src/effects/peak_meter_effect.cc index d462fa0..c2ef42e 100644 --- a/src/effects/peak_meter_effect.cc +++ b/src/effects/peak_meter_effect.cc @@ -78,19 +78,6 @@ void PeakMeter::render(WGPUCommandEncoder encoder, pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view, uniforms_buffer_.get(), {nullptr, 0}); - WGPURenderPassColorAttachment color_attachment = {}; - gpu_init_color_attachment(color_attachment, output_view); - color_attachment.loadOp = WGPULoadOp_Load; - - WGPURenderPassDescriptor pass_desc = {}; - pass_desc.colorAttachmentCount = 1; - pass_desc.colorAttachments = &color_attachment; - - WGPURenderPassEncoder pass = - wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc); - wgpuRenderPassEncoderSetPipeline(pass, pipeline_); - wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr); - wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); - wgpuRenderPassEncoderEnd(pass); - wgpuRenderPassEncoderRelease(pass); + run_fullscreen_pass(encoder, pipeline_, bind_group_, output_view, + WGPULoadOp_Load); } diff --git a/src/effects/placeholder_effect.cc b/src/effects/placeholder_effect.cc index beb5f33..4221a74 100644 --- a/src/effects/placeholder_effect.cc +++ b/src/effects/placeholder_effect.cc @@ -32,18 +32,5 @@ void Placeholder::render(WGPUCommandEncoder encoder, pp_update_bind_group(ctx_.device, pipeline_, &bind_group_, input_view, uniforms_buffer_.get(), {nullptr, 0}); - WGPURenderPassColorAttachment color_attachment = {}; - gpu_init_color_attachment(color_attachment, output_view); - - WGPURenderPassDescriptor pass_desc = {}; - pass_desc.colorAttachmentCount = 1; - pass_desc.colorAttachments = &color_attachment; - - WGPURenderPassEncoder pass = - wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc); - wgpuRenderPassEncoderSetPipeline(pass, pipeline_); - wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr); - wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); - wgpuRenderPassEncoderEnd(pass); - wgpuRenderPassEncoderRelease(pass); + run_fullscreen_pass(encoder, pipeline_, bind_group_, output_view); } diff --git a/src/effects/scene1_effect.cc b/src/effects/scene1_effect.cc index 0aae94a..bf99fc7 100644 --- a/src/effects/scene1_effect.cc +++ b/src/effects/scene1_effect.cc @@ -49,18 +49,5 @@ void Scene1::render(WGPUCommandEncoder encoder, dummy_texture_view_.get(), uniforms_buffer_.get(), camera_params_.get()); - WGPURenderPassColorAttachment color_attachment = {}; - gpu_init_color_attachment(color_attachment, output_view); - - WGPURenderPassDescriptor pass_desc = {}; - pass_desc.colorAttachmentCount = 1; - pass_desc.colorAttachments = &color_attachment; - - WGPURenderPassEncoder pass = - wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc); - wgpuRenderPassEncoderSetPipeline(pass, pipeline_.get()); - wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_.get(), 0, nullptr); - wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); // Fullscreen triangle - wgpuRenderPassEncoderEnd(pass); - wgpuRenderPassEncoderRelease(pass); + run_fullscreen_pass(encoder, pipeline_.get(), bind_group_.get(), output_view); } diff --git a/src/effects/scene2_effect.cc b/src/effects/scene2_effect.cc index 8c05574..92e5ecd 100644 --- a/src/effects/scene2_effect.cc +++ b/src/effects/scene2_effect.cc @@ -30,18 +30,5 @@ void Scene2Effect::render(WGPUCommandEncoder encoder, dummy_texture_view_.get(), uniforms_buffer_.get(), {nullptr, 0}); - WGPURenderPassColorAttachment color_attachment = {}; - gpu_init_color_attachment(color_attachment, output_view); - - WGPURenderPassDescriptor pass_desc = {}; - pass_desc.colorAttachmentCount = 1; - pass_desc.colorAttachments = &color_attachment; - - WGPURenderPassEncoder pass = - wgpuCommandEncoderBeginRenderPass(encoder, &pass_desc); - wgpuRenderPassEncoderSetPipeline(pass, pipeline_.get()); - wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_.get(), 0, nullptr); - wgpuRenderPassEncoderDraw(pass, 3, 1, 0, 0); - wgpuRenderPassEncoderEnd(pass); - wgpuRenderPassEncoderRelease(pass); + run_fullscreen_pass(encoder, pipeline_.get(), bind_group_.get(), output_view); } diff --git a/src/effects/shaders.cc b/src/effects/shaders.cc index 8b625ee..7ca66fa 100644 --- a/src/effects/shaders.cc +++ b/src/effects/shaders.cc @@ -61,6 +61,8 @@ void InitShaderComposer() { AssetId::ASSET_SHADER_RENDER_NTSC_COMMON); register_if_exists("render/fullscreen_vs", AssetId::ASSET_SHADER_RENDER_FULLSCREEN_VS); + register_if_exists("particle_common", + AssetId::ASSET_SHADER_COMPUTE_PARTICLE_COMMON); register_if_exists("render/fullscreen_uv_vs", AssetId::ASSET_SHADER_RENDER_FULLSCREEN_UV_VS); register_if_exists("math/color", AssetId::ASSET_SHADER_MATH_COLOR); -- cgit v1.2.3