blob: dba0b60b7afeea3cd8e0ec5a51d84e99195670db (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# CNN Effect Black Screen Bug - Resolution (2026-02)
## Problem
CNN post-processing effect showed black screen when activated at 11.50s, despite scene rendering correctly before CNN started.
## Root Causes
### Bug 1: Framebuffer Capture Timing
**Location**: `src/gpu/effect.cc`
**Issue**: Capture ran INSIDE post-effect loop after ping-pong buffer swaps. CNN layers 1+ captured wrong buffer (output being written to, not scene).
**Fix**: Moved capture before loop starts (lines 308-346). Capture now copies `framebuffer_a` to `captured_frame` auxiliary texture ONCE before any post-effects run.
### Bug 2: Missing Uniforms Update ⚠️ CRITICAL
**Location**: `src/gpu/effects/cnn_effect.cc`
**Issue**: `CNNEffect::update_bind_group()` never updated `uniforms_` buffer. `uniforms.resolution` uninitialized (0,0 or garbage) → UV calculation `p.xy / uniforms.resolution` produced NaN → all texture samples black.
**Fix**: Added uniforms update before bind group creation (lines 132-142):
```cpp
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);
```
## Key Lessons
1. **All post-process effects MUST update `uniforms_` buffer** - Required for UV calculations and shader parameters
2. **Framebuffer capture timing is critical** - Must happen before post-chain ping-pong starts
3. **Uninitialized uniforms cause silent failures** - Produces black output without validation errors
4. **Post-effects must render or chain breaks** - `loadOp=Load` preserves previous (black) content if no draw call executes
## Files Modified
- `src/gpu/effect.cc`: Lines 308-346 (capture timing)
- `src/gpu/effects/cnn_effect.cc`: Lines 132-142 (uniforms update)
## Verification
Test: `demo64k --seek 11.5`
- ✅ Scene visible with RotatingCube
- ✅ CNN stylization applied
- ✅ All 3 layers process with correct original texture reference
|