From 1e3813355e37f903314ec2069ff788c6f69becfd Mon Sep 17 00:00:00 2001 From: skal Date: Mon, 23 Mar 2026 07:31:14 +0100 Subject: feat(cnn_v3): GBufferEffect temporal feedback via post_render() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Add Effect::post_render() virtual hook, called after all effects in the sequence have rendered each frame. Default is no-op. - Sequence::render_effects() runs a second pass invoking post_render() on all DAG nodes after the render pass completes. - GBufferEffect: declare internal node_prev_tex_ (U8X4_NORM) for persistent prev-frame CNN output. post_render() copies cnn_output_node_ → node_prev_tex_ via CopyTextureToTexture. render() binds node_prev_tex_ as prev_cnn (binding 6) — zero on frame 0 (matches training convention). - Expose set_cnn_output_node(name) API; call once at setup. - Drop brittle ping-pong / input_nodes_[0] fallback. - Update doc/SEQUENCE.md: post_render() semantics, frame execution order, temporal feedback canonical pattern, node types table with G-buffer types. - Update cnn_v3/docs/HOWTO.md: temporal feedback wiring section. 36/36 tests passing. handoff(Gemini): prev.rgb temporal feedback now correct and generic. Set set_cnn_output_node("sink") (or CNN output node name) once at setup. --- src/gpu/effect.h | 7 +++++++ src/gpu/sequence.cc | 5 +++++ 2 files changed, 12 insertions(+) (limited to 'src') diff --git a/src/gpu/effect.h b/src/gpu/effect.h index 8055783..566faba 100644 --- a/src/gpu/effect.h +++ b/src/gpu/effect.h @@ -34,6 +34,13 @@ class Effect { const UniformsSequenceParams& params, NodeRegistry& nodes) = 0; + // Called after ALL effects in the sequence have rendered for this frame. + // Use for end-of-frame bookkeeping (e.g. copying temporal feedback buffers). + virtual void post_render(WGPUCommandEncoder encoder, NodeRegistry& nodes) { + (void)encoder; + (void)nodes; + } + virtual void resize(int width, int height) { width_ = width; height_ = height; diff --git a/src/gpu/sequence.cc b/src/gpu/sequence.cc index 91ca187..78647b2 100644 --- a/src/gpu/sequence.cc +++ b/src/gpu/sequence.cc @@ -269,6 +269,11 @@ void Sequence::render_effects(WGPUCommandEncoder encoder) { for (const auto& dag_node : effect_dag_) { dag_node.effect->dispatch_render(encoder, params_, nodes_); } + // End-of-frame hook: allows effects to persist data for the next frame + // (e.g. temporal feedback copies) after all rendering is done. + for (const auto& dag_node : effect_dag_) { + dag_node.effect->post_render(encoder, nodes_); + } } void Sequence::resize(int width, int height) { -- cgit v1.2.3