diff options
| author | skal <pascal.massimino@gmail.com> | 2026-03-22 19:41:16 +0100 |
|---|---|---|
| committer | skal <pascal.massimino@gmail.com> | 2026-03-22 19:41:16 +0100 |
| commit | d41e26b4a0be6fa7f27fc5d6e26505472eb946a9 (patch) | |
| tree | be7ca4684ea94912548467dd71c187155c9f082d /cnn_v3/src | |
| parent | be5b63ea000daca9458d7b92138ae36fabb9dd96 (diff) | |
Remove dead code and reduce duplication:
- drop create_bilinear_sampler() (never called)
- drop update_pack_bind_group() stub and pack_bind_group_ member
- drop node_feat0_/node_feat1_; use output_nodes_[0/1] directly
- Compose({}, src) consistently for all three pipelines
- extract clear_r8_node() helper to replace two identical 10-line blocks
No behavior change. 36/36 tests pass.
Diffstat (limited to 'cnn_v3/src')
| -rw-r--r-- | cnn_v3/src/gbuffer_effect.cc | 78 | ||||
| -rw-r--r-- | cnn_v3/src/gbuffer_effect.h | 4 |
2 files changed, 25 insertions, 57 deletions
diff --git a/cnn_v3/src/gbuffer_effect.cc b/cnn_v3/src/gbuffer_effect.cc index 89ed8fc..06e5e66 100644 --- a/cnn_v3/src/gbuffer_effect.cc +++ b/cnn_v3/src/gbuffer_effect.cc @@ -42,18 +42,6 @@ struct GBufGlobalUniforms { static_assert(sizeof(GBufGlobalUniforms) == sizeof(float) * 44, "GBufGlobalUniforms must be 176 bytes"); -// Create bilinear sampler. -static WGPUSampler create_bilinear_sampler(WGPUDevice device) { - WGPUSamplerDescriptor desc = {}; - desc.addressModeU = WGPUAddressMode_ClampToEdge; - desc.addressModeV = WGPUAddressMode_ClampToEdge; - desc.magFilter = WGPUFilterMode_Linear; - desc.minFilter = WGPUFilterMode_Linear; - desc.mipmapFilter = WGPUMipmapFilterMode_Linear; - desc.maxAnisotropy = 1; - return wgpuDeviceCreateSampler(device, &desc); -} - // ---- GBufferEffect ---- GBufferEffect::GBufferEffect(const GpuContext& ctx, @@ -70,9 +58,6 @@ GBufferEffect::GBufferEffect(const GpuContext& ctx, node_depth_ = prefix + "_depth"; node_shadow_ = prefix + "_shadow"; node_transp_ = prefix + "_transp"; - node_feat0_ = outputs.size() > 0 ? outputs[0] : prefix + "_feat0"; - node_feat1_ = outputs.size() > 1 ? outputs[1] : prefix + "_feat1"; - // Allocate GPU buffers for scene data. global_uniforms_buf_ = gpu_create_buffer(ctx_.device, sizeof(GBufGlobalUniforms), @@ -99,11 +84,11 @@ void GBufferEffect::declare_nodes(NodeRegistry& registry) { registry.declare_node(node_transp_, NodeType::GBUF_R8, -1, -1); // feat_tex0 / feat_tex1 are the declared output_nodes_ — they get registered // by the sequence infrastructure; declare them here as well if not already. - if (!registry.has_node(node_feat0_)) { - registry.declare_node(node_feat0_, NodeType::GBUF_RGBA32UINT, -1, -1); + if (!registry.has_node(output_nodes_[0])) { + registry.declare_node(output_nodes_[0], NodeType::GBUF_RGBA32UINT, -1, -1); } - if (!registry.has_node(node_feat1_)) { - registry.declare_node(node_feat1_, NodeType::GBUF_RGBA32UINT, -1, -1); + if (!registry.has_node(output_nodes_[1])) { + registry.declare_node(output_nodes_[1], NodeType::GBUF_RGBA32UINT, -1, -1); } } @@ -178,6 +163,22 @@ void GBufferEffect::set_scene() { scene_ready_ = true; } +static void clear_r8_node(WGPUCommandEncoder encoder, WGPUTextureView view, + float value) { + WGPURenderPassColorAttachment att = {}; + att.view = view; + att.loadOp = WGPULoadOp_Clear; + att.storeOp = WGPUStoreOp_Store; + att.clearValue = {value, value, value, value}; + att.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; + WGPURenderPassDescriptor pd = {}; + pd.colorAttachmentCount = 1; + pd.colorAttachments = &att; + WGPURenderPassEncoder p = wgpuCommandEncoderBeginRenderPass(encoder, &pd); + wgpuRenderPassEncoderEnd(p); + wgpuRenderPassEncoderRelease(p); +} + void GBufferEffect::render(WGPUCommandEncoder encoder, const UniformsSequenceParams& params, NodeRegistry& nodes) { @@ -225,8 +226,8 @@ void GBufferEffect::render(WGPUCommandEncoder encoder, WGPUTextureView albedo_view = nodes.get_view(node_albedo_); WGPUTextureView normal_mat_view = nodes.get_view(node_normal_mat_); WGPUTextureView depth_view = nodes.get_view(node_depth_); - WGPUTextureView feat0_view = nodes.get_view(node_feat0_); - WGPUTextureView feat1_view = nodes.get_view(node_feat1_); + WGPUTextureView feat0_view = nodes.get_view(output_nodes_[0]); + WGPUTextureView feat1_view = nodes.get_view(output_nodes_[1]); // prev_cnn: first input node if available, else dummy. WGPUTextureView prev_view = nullptr; @@ -340,36 +341,11 @@ void GBufferEffect::render(WGPUCommandEncoder encoder, wgpuBindGroupRelease(shadow_bg); } else { // Fallback: clear to 1.0 (fully lit) if pipeline not ready. - WGPURenderPassColorAttachment att = {}; - att.view = nodes.get_view(node_shadow_); - att.loadOp = WGPULoadOp_Clear; - att.storeOp = WGPUStoreOp_Store; - att.clearValue = {1.0f, 1.0f, 1.0f, 1.0f}; - att.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; - WGPURenderPassDescriptor pd = {}; - pd.colorAttachmentCount = 1; - pd.colorAttachments = &att; - WGPURenderPassEncoder p = wgpuCommandEncoderBeginRenderPass(encoder, &pd); - wgpuRenderPassEncoderEnd(p); - wgpuRenderPassEncoderRelease(p); + clear_r8_node(encoder, nodes.get_view(node_shadow_), 1.0f); } // Pass 3: Transparency — TODO (deferred; opaque scenes only) - // Clear transp node to 0.0 (fully opaque) until pass 3 is implemented. - { - WGPURenderPassColorAttachment att = {}; - att.view = nodes.get_view(node_transp_); - att.loadOp = WGPULoadOp_Clear; - att.storeOp = WGPUStoreOp_Store; - att.clearValue = {0.0f, 0.0f, 0.0f, 0.0f}; - att.depthSlice = WGPU_DEPTH_SLICE_UNDEFINED; - WGPURenderPassDescriptor pd = {}; - pd.colorAttachmentCount = 1; - pd.colorAttachments = &att; - WGPURenderPassEncoder p = wgpuCommandEncoderBeginRenderPass(encoder, &pd); - wgpuRenderPassEncoderEnd(p); - wgpuRenderPassEncoderRelease(p); - } + clear_r8_node(encoder, nodes.get_view(node_transp_), 0.0f); // --- Pass 4: Pack compute --- // Rebuild pack bind group with current node views. @@ -509,7 +485,7 @@ void GBufferEffect::create_raster_pipeline() { } const std::string composed = - ShaderComposer::Get().Compose({"common_uniforms"}, src); + ShaderComposer::Get().Compose({}, src); WGPUShaderSourceWGSL wgsl_src = {}; wgsl_src.chain.sType = WGPUSType_ShaderSourceWGSL; @@ -793,7 +769,3 @@ void GBufferEffect::update_raster_bind_group(NodeRegistry& nodes) { wgpuBindGroupLayoutRelease(bgl); } -void GBufferEffect::update_pack_bind_group(NodeRegistry& nodes) { - (void)nodes; - // Pack bind group is rebuilt inline in render() to use current node views. -} diff --git a/cnn_v3/src/gbuffer_effect.h b/cnn_v3/src/gbuffer_effect.h index c39219b..13d394d 100644 --- a/cnn_v3/src/gbuffer_effect.h +++ b/cnn_v3/src/gbuffer_effect.h @@ -68,8 +68,6 @@ class GBufferEffect : public Effect { std::string node_depth_; std::string node_shadow_; std::string node_transp_; - std::string node_feat0_; - std::string node_feat1_; // Owned scene and camera — populated by set_scene() Scene scene_; @@ -88,7 +86,6 @@ class GBufferEffect : public Effect { // Pass 4: Pack compute pipeline ComputePipeline pack_pipeline_; - BindGroup pack_bind_group_; UniformBuffer<GBufResUniforms> pack_res_uniform_; UniformBuffer<GBufLightsUniforms> lights_uniform_; @@ -102,7 +99,6 @@ class GBufferEffect : public Effect { void create_pack_pipeline(); void update_raster_bind_group(NodeRegistry& nodes); - void update_pack_bind_group(NodeRegistry& nodes); void upload_scene_data(const Scene& scene, const Camera& camera, float time); |
