From 139059e1fdbcace3e233c6109a61446b14b774e4 Mon Sep 17 00:00:00 2001 From: skal Date: Tue, 10 Feb 2026 15:58:46 +0100 Subject: fix: Resolve CNN effect black screen bug (framebuffer capture + uniforms) Two bugs causing black screen when CNN post-processing activated: 1. Framebuffer capture timing: Capture ran inside post-effect loop after ping-pong swaps, causing layers 1+ to capture wrong buffer. Moved capture before loop to copy framebuffer_a once before post-chain starts. 2. Missing uniforms update: CNNEffect never updated uniforms_ buffer, leaving uniforms.resolution uninitialized (0,0). UV calculation p.xy/uniforms.resolution produced NaN, causing all texture samples to return black. Added uniforms update in update_bind_group(). Files modified: - src/gpu/effect.cc: Capture before post-chain (lines 308-346) - src/gpu/effects/cnn_effect.cc: Add uniforms update (lines 132-142) - workspaces/main/shaders/cnn/cnn_layer.wgsl: Remove obsolete comment - doc/CNN_DEBUG.md: Historical debugging doc - CLAUDE.md: Reference CNN_DEBUG.md in historical section Co-Authored-By: Claude Sonnet 4.5 --- src/gpu/effects/cnn_effect.cc | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/gpu/effects') diff --git a/src/gpu/effects/cnn_effect.cc b/src/gpu/effects/cnn_effect.cc index cb00455..7107bea 100644 --- a/src/gpu/effects/cnn_effect.cc +++ b/src/gpu/effects/cnn_effect.cc @@ -104,7 +104,10 @@ void CNNEffect::init(MainSequence* demo) { void CNNEffect::render(WGPURenderPassEncoder pass, float time, float beat, float intensity, float aspect_ratio) { - if (!bind_group_) return; + if (!bind_group_) { + fprintf(stderr, "CNN render: no bind_group\n"); + return; + } wgpuRenderPassEncoderSetPipeline(pass, pipeline_); wgpuRenderPassEncoderSetBindGroup(pass, 0, bind_group_, 0, nullptr); @@ -114,6 +117,16 @@ void CNNEffect::render(WGPURenderPassEncoder pass, float time, float beat, void CNNEffect::update_bind_group(WGPUTextureView input_view) { input_view_ = input_view; + // Update common uniforms (CRITICAL for UV calculation!) + const CommonPostProcessUniforms u = { + .resolution = {(float)width_, (float)height_}, + .aspect_ratio = (float)width_ / (float)height_, + .time = 0.0f, + .beat = 0.0f, + .audio_intensity = 0.0f, + }; + uniforms_.update(ctx_.queue, u); + // All layers: get captured frame (original input from layer 0) if (demo_) { original_view_ = demo_->get_auxiliary_view("captured_frame"); -- cgit v1.2.3