Merge branch 'lane-sqdrift' (7d498c0): square-only inter sequence with a 64x64 intra superblock gate
Browse files at this commit5 changed files +401 -1
- crates/ec-av1/src/decode.rs +8 -1
- crates/ec-av1/src/stream.rs +160 -0
- lanes/sqdrift-r1.handoff.md +40 -0
- lanes/sqdrift-r1.report.md +100 -0
- lanes/sqdrift-r2.report.md +93 -0
crates/ec-av1/src/decode.rsmodified+8 -1
| @@ -18748,6 +18748,12 @@ fn decode_inter_block( | |||
| 18748 | return Ok(()); | 18748 | return Ok(()); |
| 18749 | } | 18749 | } |
| 18750 | let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]); | 18750 | let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]); |
| 18751 | + if std::env::var_os("EC_IIS").is_some() { | ||
| 18752 | + eprintln!( | ||
| 18753 | + "TRACE iis px={px} py={py} side={side} w={write_w} h={write_h} sg={} mode={mode} skip={skip}", | ||
| 18754 | + size_group_wh(write_w, write_h) | ||
| 18755 | + ); | ||
| 18756 | + } | ||
| 18751 | if mode >= 13 { | 18757 | if mode >= 13 { |
| 18752 | return Err(unsupported( | 18758 | return Err(unsupported( |
| 18753 | "an intra mode this decoder does not code (round 2)", | 18759 | "an intra mode this decoder does not code (round 2)", |
| @@ -21304,10 +21310,11 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 21304 | // instead of silently decoding as SPLIT and desyncing. | 21310 | // instead of silently decoding as SPLIT and desyncing. |
| 21305 | let part64 = match (has_cols, has_rows) { | 21311 | let part64 = match (has_cols, has_rows) { |
| 21306 | (true, true) => { | 21312 | (true, true) => { |
| 21313 | + let pre_rng = dec.debug_state().0; | ||
| 21307 | let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); | 21314 | let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]); |
| 21308 | if std::env::var_os("EC_AV1_TRACE").is_some() { | 21315 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 21309 | eprintln!( | 21316 | eprintln!( |
| 21310 | - "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p}", | 21317 | + "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}", |
| 21311 | sb_r * SB_MI, | 21318 | sb_r * SB_MI, |
| 21312 | sb_c * SB_MI | 21319 | sb_c * SB_MI |
| 21313 | ); | 21320 | ); |
crates/ec-av1/src/stream.rsmodified+160 -0
| @@ -7237,6 +7237,166 @@ mod tests { | |||
| 7237 | ); | 7237 | ); |
| 7238 | } | 7238 | } |
| 7239 | } | 7239 | } |
| 7240 | + /// lane-sqdrift r2: the SQUARE-ONLY twin of the no-CFL `uv_mode` gate | ||
| 7241 | + /// above. With `--enable-rect-partitions=0` the encoder codes only | ||
| 7242 | + /// `PARTITION_NONE` and `PARTITION_SPLIT`, and on detailed content the RD | ||
| 7243 | + /// eventually hands one whole 64x64 superblock of an INTER frame to an | ||
| 7244 | + /// INTRA block -- `bsize == sb_size`, the one shape whose `uv_mode` must | ||
| 7245 | + /// come off the 13-symbol `uv_mode_no_cfl` alphabet because libaom's | ||
| 7246 | + /// `is_cfl_allowed` (`blockd.h`: `wide <= 32 && high <= 32`) excludes it. | ||
| 7247 | + /// | ||
| 7248 | + /// Before the fix this decoder read the 14-symbol CFL alphabet there: the | ||
| 7249 | + /// same `DC_PRED` value, a different interval, and the tile desynced from | ||
| 7250 | + /// that block on. r1 measured the damage on the pinned 192x128 stream | ||
| 7251 | + /// (sha256 `c6af4fb4...`): decode-order frames 0-3 pre-filter byte-exact, | ||
| 7252 | + /// frame 4 luma 3540 samples wrong over exactly the last superblock | ||
| 7253 | + /// (x 128..191, y 64..127), then 24k wrong by frame 7 -- and the decoder | ||
| 7254 | + /// did not even report a mismatch, it reported an intra-rect-strip refusal | ||
| 7255 | + /// read out of the already-desynced stream (class `refusal-from-own-desync`; | ||
| 7256 | + /// aomdec's own partition histogram over that stream is rect-free). | ||
| 7257 | + /// After the fix the same stream is byte-exact on all 8 frames. | ||
| 7258 | + /// | ||
| 7259 | + /// Distinct from the sibling gate: rect partitions OFF (so the 64x64 NONE | ||
| 7260 | + /// really is a whole superblock), `--min-partition-size=16`, natural | ||
| 7261 | + /// mandelbrot detail instead of a synthetic half-noise ramp, and 8 frames | ||
| 7262 | + /// of drift so a desync that survives one frame still fails here. Every | ||
| 7263 | + /// decode-order frame of every attempt is compared against ffmpeg, so a | ||
| 7264 | + /// mismatch of ANY shape fails; the gate never turns one into a SKIP. | ||
| 7265 | + #[test] | ||
| 7266 | + fn a_real_aomenc_square_only_inter_sequence_with_a_64x64_intra_superblock_decodes_pixel_exact() | ||
| 7267 | + { | ||
| 7268 | + const NAME: &str = "a_real_aomenc_square_only_inter_sequence_with_a_64x64_intra_superblock_decodes_pixel_exact"; | ||
| 7269 | + let _gate_lock = lock_gate_counters(); | ||
| 7270 | + if !have_ffmpeg() { | ||
| 7271 | + eprintln!("SKIP {NAME}: no ffmpeg"); | ||
| 7272 | + return; | ||
| 7273 | + } | ||
| 7274 | + if !have_aomenc() { | ||
| 7275 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | ||
| 7276 | + return; | ||
| 7277 | + } | ||
| 7278 | + let (width, height, frame_count) = (192usize, 128usize, 8usize); | ||
| 7279 | + for bit_depth in [8u32, 10u32] { | ||
| 7280 | + let (mut named_refusals, mut matched, mut carried_none) = (0u32, 0u32, 0u32); | ||
| 7281 | + let mut total_hits = 0usize; | ||
| 7282 | + for attempt in 0..4u32 { | ||
| 7283 | + // r1's pinned recipe is (start_scale 4.76, cq 55); the other | ||
| 7284 | + // three points move the detail level and the quantiser, which | ||
| 7285 | + // is what moves WHICH superblock the RD codes intra. | ||
| 7286 | + let start_scale = ["4.76", "3.20"][(attempt % 2) as usize]; | ||
| 7287 | + let cq = [55, 45][(attempt / 2) as usize]; | ||
| 7288 | + let duration = frame_count as f64 / 25.0; | ||
| 7289 | + let source = format!( | ||
| 7290 | + "mandelbrot=size={width}x{height}:start_scale={start_scale}:\ | ||
| 7291 | + end_scale=0.004:end_pts=8:rate=25" | ||
| 7292 | + ); | ||
| 7293 | + let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" }; | ||
| 7294 | + let y4m = Command::new("ffmpeg") | ||
| 7295 | + .args([ | ||
| 7296 | + "-v", "error", "-f", "lavfi", "-i", &source, "-vf", "hue=s=0", | ||
| 7297 | + "-t", &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1", | ||
| 7298 | + "-f", "yuv4mpegpipe", "-strict", "-1", "-", | ||
| 7299 | + ]) | ||
| 7300 | + .stdin(Stdio::null()) | ||
| 7301 | + .stdout(Stdio::piped()) | ||
| 7302 | + .stderr(Stdio::piped()) | ||
| 7303 | + .output() | ||
| 7304 | + .expect("ffmpeg failed to run"); | ||
| 7305 | + assert!( | ||
| 7306 | + y4m.status.success(), | ||
| 7307 | + "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}", | ||
| 7308 | + String::from_utf8_lossy(&y4m.stderr) | ||
| 7309 | + ); | ||
| 7310 | + let cq_arg = format!("--cq-level={cq}"); | ||
| 7311 | + let depth_arg = format!("--bit-depth={bit_depth}"); | ||
| 7312 | + let input_depth_arg = format!("--input-bit-depth={bit_depth}"); | ||
| 7313 | + let args: Vec<&str> = vec![ | ||
| 7314 | + "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=1", | ||
| 7315 | + "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg, | ||
| 7316 | + "--lag-in-frames=0", "--auto-alt-ref=0", | ||
| 7317 | + "--kf-min-dist=1000", "--kf-max-dist=1000", | ||
| 7318 | + "--enable-rect-partitions=0", "--enable-ab-partitions=0", | ||
| 7319 | + "--enable-1to4-partitions=0", "--min-partition-size=16", | ||
| 7320 | + "--max-partition-size=64", "--enable-tx-size-search=0", | ||
| 7321 | + "--enable-order-hint=0", "--enable-warped-motion=0", "--enable-obmc=0", | ||
| 7322 | + "--enable-masked-comp=0", "--enable-interintra-comp=0", | ||
| 7323 | + "--enable-dist-wtd-comp=0", "--enable-diff-wtd-comp=0", | ||
| 7324 | + "--enable-onesided-comp=0", "--enable-interintra-wedge=0", | ||
| 7325 | + "--enable-smooth-interintra=0", "--enable-filter-intra=0", | ||
| 7326 | + "--enable-smooth-intra=0", "--enable-paeth-intra=0", | ||
| 7327 | + "--enable-directional-intra=0", "--enable-angle-delta=0", | ||
| 7328 | + "--enable-cdef=0", "--enable-restoration=0", "--enable-palette=0", | ||
| 7329 | + "--enable-intrabc=0", "--enable-cfl-intra=0", "--enable-ref-frame-mvs=0", | ||
| 7330 | + "--obu", "-o", "-", "-", | ||
| 7331 | + ]; | ||
| 7332 | + let mut child = Command::new(aomenc_path()) | ||
| 7333 | + .args(&args) | ||
| 7334 | + .stdin(Stdio::piped()) | ||
| 7335 | + .stdout(Stdio::piped()) | ||
| 7336 | + .stderr(Stdio::piped()) | ||
| 7337 | + .spawn() | ||
| 7338 | + .expect("aomenc failed to start"); | ||
| 7339 | + child | ||
| 7340 | + .stdin | ||
| 7341 | + .take() | ||
| 7342 | + .expect("aomenc stdin") | ||
| 7343 | + .write_all(&y4m.stdout) | ||
| 7344 | + .expect("writing y4m to aomenc"); | ||
| 7345 | + let out = child.wait_with_output().expect("aomenc failed to run"); | ||
| 7346 | + assert!( | ||
| 7347 | + out.status.success(), | ||
| 7348 | + "aomenc refused the fixture: {}", | ||
| 7349 | + String::from_utf8_lossy(&out.stderr) | ||
| 7350 | + ); | ||
| 7351 | + let stream = out.stdout; | ||
| 7352 | + let before = crate::decode::nocfl_uv_mode_hits(); | ||
| 7353 | + let frames = match decode_stream(&stream) { | ||
| 7354 | + Err(e) => { | ||
| 7355 | + let msg = e.to_string(); | ||
| 7356 | + assert!( | ||
| 7357 | + msg.contains("unsupported"), | ||
| 7358 | + "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \ | ||
| 7359 | + attempt {attempt}): {msg}" | ||
| 7360 | + ); | ||
| 7361 | + named_refusals += 1; | ||
| 7362 | + eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}"); | ||
| 7363 | + continue; | ||
| 7364 | + } | ||
| 7365 | + Ok(frames) => frames, | ||
| 7366 | + }; | ||
| 7367 | + let hits = crate::decode::nocfl_uv_mode_hits() - before; | ||
| 7368 | + let ffmpeg_frames = if bit_depth == 10 { | ||
| 7369 | + ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count) | ||
| 7370 | + } else { | ||
| 7371 | + ffmpeg_decode_sequence(&stream, width, height, frame_count) | ||
| 7372 | + }; | ||
| 7373 | + assert_eq!(frames.len(), frame_count); | ||
| 7374 | + if hits == 0 { | ||
| 7375 | + carried_none += 1; | ||
| 7376 | + } | ||
| 7377 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | ||
| 7378 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); | ||
| 7379 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); | ||
| 7380 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})"); | ||
| 7381 | + } | ||
| 7382 | + if hits > 0 { | ||
| 7383 | + matched += 1; | ||
| 7384 | + total_hits += hits; | ||
| 7385 | + } | ||
| 7386 | + } | ||
| 7387 | + eprintln!( | ||
| 7388 | + "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \ | ||
| 7389 | + attempts carrying a 64x64 intra superblock ({total_hits} no-CFL uv_mode reads), \ | ||
| 7390 | + {carried_none} attempts carried none" | ||
| 7391 | + ); | ||
| 7392 | + assert!( | ||
| 7393 | + matched > 0 && total_hits > 0, | ||
| 7394 | + "{NAME} ({bit_depth}-bit): no square-only attempt decoded a 64x64 intra block \ | ||
| 7395 | + inside an inter frame, so the no-CFL uv_mode alphabet was never exercised -- \ | ||
| 7396 | + gate proved nothing ({named_refusals} refusals, {carried_none} carried none)" | ||
| 7397 | + ); | ||
| 7398 | + } | ||
| 7399 | + } | ||
| 7240 | 7400 | ||
| 7241 | /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` | 7401 | /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` |
| 7242 | /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 | 7402 | /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 |
lanes/sqdrift-r1.handoff.mdadded+40 -0
| @@ -0,0 +1,40 @@ | |||
| 1 | +# lane-sqdrift r1 -> r2 handoff | ||
| 2 | + | ||
| 3 | +Branch `lane-sqdrift` @ 6edd5af (off main 85887c7). Worktree | ||
| 4 | +`/home/user/Documents/Code/Rust/edith_codecs-sqdrift`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sqdrift`. | ||
| 5 | + | ||
| 6 | +## Do NOT redo any of this (all measured, see lanes/sqdrift-r1.report.md for the EVIDENCE lines) | ||
| 7 | +* Stream: `/home/user/.cache/sqdrift/gen.sh` -> `s.obu`, sha256 | ||
| 8 | + `c6af4fb4ebdc3d74dcfa0c945c0ef2d5e1e3a0902891d9e0a97a5608776b5d55`, hashed twice. | ||
| 9 | +* Frames 0-3 byte-exact pre-filter AND post-filter (both dumps). No poisoned reference. | ||
| 10 | +* Frame 4 damage = exactly the last SB, mi(16,32), PARTITION_NONE at 64x64, INTRA in an | ||
| 11 | + inter frame (aomdec prints neither EC_MODE nor EC_IMODE for it). | ||
| 12 | +* We enter that block IN SYNC: our `pre_rng=33730` == aomdec `EC_PART ... rng=33730`. | ||
| 13 | +* TX_64X64 dequant + inverse transform EXONERATED against real libaom (0/4096). | ||
| 14 | +* The stream contains no rect/AB/1:4 partition at all; main's 1:4-strip refusal on it is | ||
| 15 | + a phantom of this desync. | ||
| 16 | +* aomdec's prediction there is none of DC/SMOOTH/SMOOTH_V/SMOOTH_H/PAETH computed from | ||
| 17 | + the true neighbours, so its coefficients differ too -> a SYMBOL diverges, not a predictor. | ||
| 18 | + | ||
| 19 | +## The one open question | ||
| 20 | +Which symbol between `partition_w64` and the end of that block. Ordered suspects: | ||
| 21 | +1. `read_delta_q_params` -- delta_q IS present (base_q_idx 80/110/168) and this is the | ||
| 22 | + only block in the stream with `bsize == sb_size`, libaom's own special case | ||
| 23 | + (`decodemv.c`: `if (bsize != cm->seq_params->sb_size || !mbmi->skip_txfm)`), incl. the | ||
| 24 | + `delta_lf` sub-read. | ||
| 25 | +2. `skip` / `is_inter` ctx at a 64x64 block. | ||
| 26 | +3. `y_mode[size_group_lookup[BLOCK_64X64]=3]` CDF content (adaptation drift; frames 0-3 | ||
| 27 | + never crossed a decision boundary). | ||
| 28 | +4. `tx_depth`: `--enable-tx-size-search=0`, so TX_64X64 must code no depth symbol. | ||
| 29 | +5. The 64x64 luma coefficient read (eob_pt alphabet at TX_64X64, `all_zero` ctx). | ||
| 30 | + | ||
| 31 | +## Instruments already in the tree | ||
| 32 | +* `EC_AV1_TRACE=1` -> `TRACE partition_w64 ... pre_rng=<range before the symbol>`. | ||
| 33 | +* `EC_IIS=1` -> `TRACE iis px= py= side= w= h= sg= mode= skip=` at the square | ||
| 34 | + intra-in-inter `y_mode` read (decode.rs, right after `cdfs.y_mode[size_group_wh(..)]`). | ||
| 35 | +* `/home/user/.cache/sqdrift/h.c` -- libaom inverse-transform harness. Build: | ||
| 36 | + `gcc -O1 -o h h.c -I$SRC -I$BUILD -I$SRC/apps $BUILD/libaom.a -lm -lpthread`. | ||
| 37 | + MUST call `av1_rtcd(); aom_dsp_rtcd();` first or `av1_idct64` is a NULL fn ptr (segfault). | ||
| 38 | +* The oracle has NO range print inside `read_intra_block_mode_info` / | ||
| 39 | + `read_delta_q_params`. Add one via `scripts/instrument-aom-oracle.sh` into a PRIVATE | ||
| 40 | + build dir; never rebuild the shared `~/.cache/aom-oracle/build/aomdec` in place. | ||
lanes/sqdrift-r1.report.mdadded+100 -0
| @@ -0,0 +1,100 @@ | |||
| 1 | +# lane-sqdrift r1 -- the square-only silent pixel drift, localised to ONE block | ||
| 2 | + | ||
| 3 | +## Verdict: RED (defect localised and bounded, not yet fixed). No refusal lifted. | ||
| 4 | + | ||
| 5 | +## The stream (pinned, reproducible) | ||
| 6 | + | ||
| 7 | +`/home/user/.cache/sqdrift/gen.sh` (kept; recipe = lane-intra14's gate recipe with | ||
| 8 | +`--enable-rect-partitions=0`): 192x128 8-bit `mandelbrot start_scale=4.76 end_scale=0.004 | ||
| 9 | +end_pts=8 rate=25`, hue=s=0, `-t 0.32`, real `~/.cache/aom-oracle/build/aomenc` | ||
| 10 | +`--cpu-used=1 --cq-level=55 --min-partition-size=16 --max-partition-size=64 | ||
| 11 | +--enable-tx-size-search=0 --kf-min/max-dist=1000 --threads=1 --row-mt=0`, order-hint / | ||
| 12 | +warped / obmc / masked / interintra / dist-wtd / diff-wtd / onesided / ab / 1to4 / | ||
| 13 | +filter-intra / smooth-intra / paeth-intra / directional-intra / angle-delta / cdef / | ||
| 14 | +restoration / palette / intrabc / cfl / ref-frame-mvs ALL `=0`. | ||
| 15 | +sha256 `c6af4fb4ebdc3d74dcfa0c945c0ef2d5e1e3a0902891d9e0a97a5608776b5d55`, hashed twice | ||
| 16 | +from two independent encodes -- reproducible. | ||
| 17 | + | ||
| 18 | +## What is actually wrong (measured, not reasoned) | ||
| 19 | + | ||
| 20 | +1. `aomdec EC_TRACE=1` partition histogram over the whole stream: only | ||
| 21 | + `value=0 (NONE)` and `value=3 (SPLIT)` at bsize 12/9/6. **No rect, no AB, no 1:4 | ||
| 22 | + partition exists in this stream at all** -- so main's refusal | ||
| 23 | + "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path", which this | ||
| 24 | + stream stops at on `main@85887c7`, is a PHANTOM read out of an already-diverged | ||
| 25 | + bitstream (class `refusal-from-own-desync`). | ||
| 26 | +2. Pre-loop-filter dumps, our `EC_AV1_PREFILT_DUMP` vs aomdec's, per decode-order frame: | ||
| 27 | + f0..f3 **byte-exact (luma AND chroma)**; f4 luma 3540 samples wrong, max |d| = 6, | ||
| 28 | + **chroma exact**. Post-filter reference dumps (`EC_AV1_FINAL_DUMP`) f0..f3 exact too, | ||
| 29 | + so no reference frame is poisoned going into f4. | ||
| 30 | +3. The f4 damage is EXACTLY one superblock: bbox x 128..191, y 64..127 -- the last SB, | ||
| 31 | + mi (16,32), which frame 4 codes as `PARTITION_NONE` at 64x64. It is the ONLY | ||
| 32 | + 64x64 PARTITION_NONE block in any inter frame of this stream. | ||
| 33 | +4. Range ladder at that block's entry: our pre-read msac range for its `partition_w64` | ||
| 34 | + symbol is **33730**, identical to aomdec's `EC_PART mi_row=16 mi_col=32 bsize=12 | ||
| 35 | + ctx=15 tell=25598 rng=33730`, and the ctx matches too (aomdec prints `bsl*4+ctx` | ||
| 36 | + = 12+3, ours `ctx=3`). **We enter that block bit-exactly in sync.** | ||
| 37 | +5. The divergence is INSIDE that block. aomdec prints neither `EC_MODE` (= | ||
| 38 | + `read_inter_block_mode_info`) nor `EC_IMODE`, i.e. libaom takes | ||
| 39 | + `read_intra_block_mode_info` -- an INTRA block inside an inter frame. Our decoder | ||
| 40 | + takes the same arm and reads `y_mode[size_group=3] = 0 (DC_PRED)` | ||
| 41 | + (new `EC_IIS=1` rung: `TRACE iis px=128 py=64 side=64 w=64 h=64 sg=3 mode=0 skip=false`). | ||
| 42 | + Our reconstruction there is a FLAT 93, which is exactly | ||
| 43 | + `(sum(above 64) + sum(left 64) + 64) >> 7` -- textbook DC_PRED. aomdec's | ||
| 44 | + reconstruction is not flat. | ||
| 45 | +6. The luma residual is NOT the defect. The block's 5 non-zero levels were pushed | ||
| 46 | + through libaom itself (`av1_inv_txfm2d_add_64x64_c`, real `libaom.a`, dequant | ||
| 47 | + replicated from `decodetxb.c:361-374` with `av1_dc/ac_quant_QTX(80,0,8)` = 74/87 and | ||
| 48 | + `av1_get_tx_scale` shift 2): **0 mismatches** against our own `residual` for those | ||
| 49 | + levels (and 2171 with the axes swapped, so the layout is right too). Our TX_64X64 | ||
| 50 | + dequant + inverse transform is exact. | ||
| 51 | +7. Everything after that block drifts: frame 5's SB0 `partition_w64` still reads 3, SB1 | ||
| 52 | + reads 8 where aomdec reads 3 -- a CDF-state divergence carried across the frame | ||
| 53 | + boundary (frame 5 restarts its own msac, so only the adapted CDFs can carry the | ||
| 54 | + damage). f5..f7 then drift to ~24k samples / max |d| ~220 as they predict from f4. | ||
| 55 | + | ||
| 56 | +So: **the first divergent symbol is in the mode-info or coefficient read of a 64x64 | ||
| 57 | +PARTITION_NONE intra-in-inter block, after `partition_w64` and at/after `y_mode`.** | ||
| 58 | +The candidate set is now tiny: `skip`, `read_delta_q_params` (this is the ONE block in | ||
| 59 | +the stream where `bsize == sb_size`, the exact case libaom's | ||
| 60 | +`read_delta_q_params` special-cases), `is_inter`, `y_mode[3]`, `uv_mode_cfl[0]`, | ||
| 61 | +`tx_depth` (`--enable-tx-size-search=0`, so a TX_64X64 must code no depth symbol), or the | ||
| 62 | +64x64 coefficient read itself. `base_q_idx` in our trace takes three values (80/110/168) | ||
| 63 | +across the stream, i.e. **delta_q IS present in this stream** -- that makes the | ||
| 64 | +`bsize == sb_size` delta-q exception a first-class suspect. | ||
| 65 | + | ||
| 66 | +## What changed (all env-gated instrumentation, no decode behaviour) | ||
| 67 | + | ||
| 68 | +* `crates/ec-av1/src/decode.rs` (`decode_inter_frame_tile_with_cdfs`'s `partition_w64` | ||
| 69 | + read) -- the `EC_AV1_TRACE` line now carries `pre_rng=`, the msac range BEFORE the | ||
| 70 | + symbol, which is what makes it directly comparable to aomdec's `EC_PART ... rng=` | ||
| 71 | + (class `compare-range-not-tell`). This is the measurement that proved fact 4. | ||
| 72 | +* `crates/ec-av1/src/decode.rs` (square intra-in-inter `y_mode` read) -- new `EC_IIS=1` | ||
| 73 | + rung printing `px/py/side/w/h/size_group/mode/skip` for every intra block in an inter | ||
| 74 | + frame. That is fact 5. | ||
| 75 | + | ||
| 76 | +## Gate | ||
| 77 | + | ||
| 78 | +None added -- there is no fix to gate yet. Adding a gate now would pin the defect, not a | ||
| 79 | +capability; the reproducing recipe is `scripts`-free and lives in this report plus | ||
| 80 | +`/home/user/.cache/sqdrift/gen.sh`. | ||
| 81 | + | ||
| 82 | +## EVIDENCE | ||
| 83 | + | ||
| 84 | +EVIDENCE: /home/user/.cache/sqdrift/{op,aom}.f0..f4 | our EC_AV1_PREFILT_DUMP vs aomdec EC_AV1_PREFILT_DUMP on the pinned stream, every decode-order frame compared Y/U/V | f0-f3 0 bad samples; f4 luma 3540 bad, max |d| 6, chroma 0 bad, bbox exactly x128-191 y64-127 | ||
| 85 | +EVIDENCE: /home/user/.cache/sqdrift/{of,af}.f0..f4 | EC_AV1_FINAL_DUMP (post-filter reference buffers) both decoders | f0-f3 0 bad; f4 first bad (145,58), 3848 bad, max 6 -- deblocking only spreads the f4 damage, no reference is poisoned earlier | ||
| 86 | +EVIDENCE: /home/user/.cache/sqdrift/aom.trace | aomdec EC_TRACE=1 partition histogram, whole stream | bsize12 {0:2, 3:46}, bsize9 {0:58, 3:126}, bsize6 {0:504} -- zero rect/AB/1:4 partitions, so main's 1:4-strip refusal on this stream is a phantom | ||
| 87 | +EVIDENCE: our EC_AV1_TRACE pre_rng vs /home/user/.cache/sqdrift/aom.both | range ladder at frame 4 SB (16,32) | ours pre_rng=33730 ctx=3, aomdec rng=33730 ctx=15(=12+3) -- in sync at block entry, so the defect is inside the block | ||
| 88 | +EVIDENCE: /home/user/.cache/sqdrift/{h.c,aomres1.txt,ourres.txt} | the block's 5 non-zero levels through real libaom av1_inv_txfm2d_add_64x64_c vs our residual | 0/4096 mismatches (swapped-axis control: 2171) -- TX_64X64 dequant+inverse is exact | ||
| 89 | +EVIDENCE: EC_IIS=1 rung on the pinned stream | our intra-in-inter mode read at the failing block | `TRACE iis px=128 py=64 side=64 w=64 h=64 sg=3 mode=0 skip=false`, reconstruction flat 93 = DC_PRED of the true neighbours; aomdec's is not flat (SMOOTH/SMOOTH_V/SMOOTH_H/PAETH all rejected numerically too, so aomdec's coefficients differ as well -- the divergence is a SYMBOL, not a predictor) | ||
| 90 | + | ||
| 91 | +## Residue | ||
| 92 | + | ||
| 93 | +* fix-now (next round, r2): bisect the ~6 remaining symbols of that one block. The | ||
| 94 | + cheapest decisive instrument is a `pre_rng` print on every symbol of | ||
| 95 | + `read_inter_frame_mode_info`'s square intra arm plus an aomdec-side `rng` print at the | ||
| 96 | + same points in `read_intra_block_mode_info` / `read_delta_q_params` (the oracle has no | ||
| 97 | + print there today -- add one to `scripts/instrument-aom-oracle.sh`, do NOT rebuild the | ||
| 98 | + shared aomdec in place). Start with `read_delta_q_params`' `bsize == sb_size` exception. | ||
| 99 | +* deferred: 10-bit arm -- unblocked by the fix; there is nothing to gate yet. | ||
| 100 | +* accepted: the two `EC_*` trace rungs ship as permanent debug instrumentation. | ||
lanes/sqdrift-r2.report.mdadded+93 -0
| @@ -0,0 +1,93 @@ | |||
| 1 | +# lane-sqdrift r2 -- the square-only silent drift is the no-CFL `uv_mode` alphabet | ||
| 2 | + | ||
| 3 | +## Verdict: GREEN. Root cause confirmed by ablation, gated with a new real-aomenc gate. | ||
| 4 | + | ||
| 5 | +Tip `2b750e6` on `lane-sqdrift` (base main `85887c7`). | ||
| 6 | + | ||
| 7 | +## 1. What the divergence was | ||
| 8 | + | ||
| 9 | +r1 had localised it to one 64x64 `PARTITION_NONE` INTRA block inside an INTER frame | ||
| 10 | +(frame 4, mi(16,32) = the last superblock), entered bit-exactly in sync (`pre_rng=33730` | ||
| 11 | +== aomdec's `rng=33730`), with TX_64X64 dequant+inverse already exonerated against real | ||
| 12 | +libaom. The open question was "which symbol inside that block". | ||
| 13 | + | ||
| 14 | +Answer: `uv_mode`. libaom's `is_cfl_allowed` (`blockd.h`: `block_size_wide[bsize] <= 32 && | ||
| 15 | +block_size_high[bsize] <= 32`, spec 5.11.5) excludes a 64-axis block from CFL, so its | ||
| 16 | +`uv_mode` comes off the **13-symbol `uv_mode_no_cfl`** alphabet. We read the 14-symbol | ||
| 17 | +`uv_mode_cfl` one: the same `DC_PRED` VALUE, a different interval narrowing, and the tile | ||
| 18 | +desynced from that block on (class `wrong-alphabet-same-value`). | ||
| 19 | + | ||
| 20 | +The fix was found independently by lane-sbrect10 (`9f1f108`) and is merged here, not | ||
| 21 | +rewritten: commit `cbcbf13` merges `lane-sbrect10` into this branch. `decode.rs` gets the | ||
| 22 | +`cfl_allowed = write_w.max(write_h) <= 32` test at the intra-in-inter square arm plus the | ||
| 23 | +same `is_cfl_allowed` bound enforced at the two funnels `read_intra_mode` / | ||
| 24 | +`read_intra_mode_rect`, and the `nocfl_uv_mode_hits()` witness counter. No decoder line in | ||
| 25 | +this round is mine; my round's contributions are the confirmation, the ablation, and the | ||
| 26 | +square-only gate. | ||
| 27 | + | ||
| 28 | +## 2. The decisive before/after, same stream, same tree | ||
| 29 | + | ||
| 30 | +Pinned stream `/home/user/.cache/sqdrift/keep-s.obu`, sha256 | ||
| 31 | +`c6af4fb4ebdc3d74dcfa0c945c0ef2d5e1e3a0902891d9e0a97a5608776b5d55` (r1's `gen.sh`, | ||
| 32 | +hashed twice from two independent encodes), compared PRE-LOOP-FILTER, per decode-order | ||
| 33 | +frame, byte for byte against instrumented aomdec's own `EC_AV1_PREFILT_DUMP`: | ||
| 34 | + | ||
| 35 | +| | f0 | f1 | f2 | f3 | f4 | f5 | f6 | f7 | outcome | | ||
| 36 | +|---|---|---|---|---|---|---|---|---|---| | ||
| 37 | +| before (`cfl_allowed = true` ablation on THIS tree) | 0 | 0 | 0 | 0 | **3540** | - | - | - | REFUSED after f4: "an intra-coded 1:4 (or other non-2:1) rect strip on the inter block path" | | ||
| 38 | +| after (merged fix) | 0 | 0 | 0 | 0 | **0** | 0 | 0 | 0 | 8 frames decoded, all byte-exact | | ||
| 39 | + | ||
| 40 | +The "before" row is not r1's memory: it is the one-line ablation | ||
| 41 | +`decode.rs:18548 let cfl_allowed = true;` rebuilt and re-run in this round, then reverted | ||
| 42 | +(`git diff --stat` after revert shows stream.rs only). It also re-confirms r1's finding | ||
| 43 | +that the refusal main stops at on this stream is a PHANTOM of the desync -- aomdec's | ||
| 44 | +partition histogram over the stream contains no rect partition at all (class | ||
| 45 | +`refusal-from-own-desync`). | ||
| 46 | + | ||
| 47 | +## 3. The gate (new) | ||
| 48 | + | ||
| 49 | +`crates/ec-av1/src/stream.rs:6900` | ||
| 50 | +`a_real_aomenc_square_only_inter_sequence_with_a_64x64_intra_superblock_decodes_pixel_exact` | ||
| 51 | + | ||
| 52 | +The SQUARE-ONLY twin of lane-sbrect10's gate, pinning r1's recipe: real aomenc, | ||
| 53 | +192x128 mandelbrot (`start_scale` 4.76/3.20), cq 55/45, `--cpu-used=1 --sb-size=64 | ||
| 54 | +--enable-rect-partitions=0 --enable-ab-partitions=0 --enable-1to4-partitions=0 | ||
| 55 | +--min-partition-size=16 --max-partition-size=64 --enable-tx-size-search=0`, 8 decode-order | ||
| 56 | +frames, **both bit depths**. Rect OFF is what makes the 64x64 `PARTITION_NONE` a WHOLE | ||
| 57 | +superblock (`bsize == sb_size`), a shape the sibling gate's rect-on recipe does not pin; | ||
| 58 | +8 frames of drift means a desync that survives one frame still fails here. | ||
| 59 | + | ||
| 60 | +Asserts: every decode-order frame's Y/U/V compared against ffmpeg (a mismatch of ANY shape | ||
| 61 | +is a failure, never a SKIP -- so out-of-scope mismatches are structurally 0); a decode | ||
| 62 | +error must be a named `unsupported` refusal; and `nocfl_uv_mode_hits` delta per attempt | ||
| 63 | +must be > 0 on at least one pixel-exact attempt per depth. | ||
| 64 | + | ||
| 65 | +Result (`--exact --nocapture --test-threads=1`), 10.4 s: | ||
| 66 | + | ||
| 67 | +* 8-bit: 0 named refusals, **4/4 pixel-exact attempts**, 6 no-CFL `uv_mode` reads, 0 carried none | ||
| 68 | +* 10-bit: 0 named refusals, **4/4 pixel-exact attempts**, 6 no-CFL `uv_mode` reads, 0 carried none | ||
| 69 | + | ||
| 70 | +No refusal string is removed in this round: the refusal this stream used to hit was never | ||
| 71 | +about this shape. | ||
| 72 | + | ||
| 73 | +## 4. Suite | ||
| 74 | + | ||
| 75 | +`cargo test -p ec-av1 --lib` under `systemd-run --user --unit=sqdrift-suite-r2-...`, | ||
| 76 | +log `$HOME/.cache/sqdrift-suite-r2.log`: **379 passed, 0 failed, 33 ignored** in 958.68 s (r1 baseline on the unfixed tree never completed). | ||
| 77 | + | ||
| 78 | +## EVIDENCE | ||
| 79 | + | ||
| 80 | +EVIDENCE: /home/user/.cache/sqdrift/np.f0..f7 vs aom.f0..f7 | decode_probe with EC_AV1_PREFILT_DUMP on the pinned stream (sha256 c6af4fb4...) after merging lane-sbrect10, cmp -l per decode-order frame Y+U+V | 0 differing bytes on all 8 frames (r1: f4 3540 wrong luma samples, then refusal) | ||
| 81 | +EVIDENCE: /home/user/.cache/sqdrift/ab.f0..f4 | same binary with decode.rs:18548 ablated to `cfl_allowed = true`, rebuilt, re-run, then reverted | f0-f3 0, f4 3540 differing bytes, decode then REFUSES "an intra-coded 1:4 ... rect strip on the inter block path" -- the phantom refusal is produced by this desync alone | ||
| 82 | +EVIDENCE: cargo test -p ec-av1 --lib -- --exact --nocapture a_real_aomenc_square_only_inter_sequence_with_a_64x64_intra_superblock_decodes_pixel_exact | 4 attempts x 2 bit depths of real aomenc, rect partitions off, every decode-order frame vs ffmpeg | ok in 10.38s; 8-bit 4 exact/6 hits, 10-bit 4 exact/6 hits, 0 refusals, 0 attempts carried none | ||
| 83 | + | ||
| 84 | +## Residue | ||
| 85 | + | ||
| 86 | +* deferred(lane-intra14 re-runs its own gate): `lanes/intra14-r2.report.md` records its | ||
| 87 | + blocker as "decode-order frame 3/4 luma ~3.7-4.5k samples at max |d| 6..17, first diff | ||
| 88 | + around x=128..141, y=58..59, then frames 5-7 drift to ~24k at max |d| ~220" on the same | ||
| 89 | + 192x128 mandelbrot source -- the identical signature to this lane's, at the identical | ||
| 90 | + coordinates. Very likely the same defect, so its two `#[ignore]`d 1:4-strip arms should | ||
| 91 | + be re-measured on a tree carrying this fix. Not measured here: its recipe (1:4 on) is | ||
| 92 | + another lane's surface. | ||
| 93 | +* accepted: r1's `EC_AV1_TRACE pre_rng` and `EC_IIS` rungs stay as debug instrumentation. | ||