diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 02655be7..b4c14851 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -4170,6 +4170,31 @@ impl Neighbours { /// existing corner-cut, `Neighbours::tx_grid`'s own doc comment -- a /// rectangular strip's transform is `TX_32X16`/`TX_16X32`, not tracked /// per-axis, matching lane-warp r5's `HORZ_B` top-strip precedent). + /// libaom `set_one_param_for_line_luma`/`_chroma`: an edge that is a + /// transform-unit edge but NOT a prediction-unit edge is not filtered when + /// `curr_skipped = mbmi->skip_txfm && is_inter_block(mbmi)`. Widening this + /// block's published transform extent to its own size is exactly that + /// suppression for the deblocker's `x0 % tx != 0` test -- the only shape + /// that needs it is the 128 root, whose chroma extent (64) is the one + /// [`Self::fill_lf_grid_rect`]'s TX_32X32 cap narrows. An INTRA block is + /// never suppressed (libaom's `is_inter_block` term), so this is called + /// only from the skipped-inter branch. + fn suppress_internal_lf_edges(&mut self, at_mi: (usize, usize), w_mi: usize, h_mi: usize) { + let (mi_r, mi_c) = at_mi; + let (uv_w, uv_h) = ((w_mi * MI / 2).max(4) as u8, (h_mi * MI / 2).max(4) as u8); + for rr in 0..h_mi { + for cc in 0..w_mi { + let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc); + if let Some(cell) = self.uv_tx_grid.get_mut(idx) { + *cell = uv_w; + } + if let Some(cell) = self.uv_tx_h_grid.get_mut(idx) { + *cell = uv_h; + } + } + } + } + fn fill_lf_grid_rect( &mut self, at_mi: (usize, usize), @@ -4181,17 +4206,10 @@ impl Neighbours { ) { let (mi_r, mi_c) = at_mi; // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is - // half its luma one (min 4 px, the smallest transform). - // lane-sb128c r4: the old `.min(32)` TX_32X32 cap was inert for every - // block up to 64 wide (64/2 == 32) and WRONG for a 128-sided one: it - // published an internal chroma TU edge every 32 chroma px inside the - // block, which libaom only filters when the block is not - // `curr_skipped` -- and a non-skip 128 block reaches here again - // through its own per-leaf calls (`w_mi * MI == 64`, uv 32), which - // publish that edge correctly. The cap is therefore redundant where - // it was right and harmful where it was not. - let uv_tx_w = (w_mi * MI / 2).max(4) as u8; - let uv_tx_h = (h_mi * MI / 2).max(4) as u8; + // half its luma one (min 4 px, the smallest transform), capped at + // TX_32X32 -- independent of this block's luma `tx_depth`. + let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8; + let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8; let cur = CURRENT_DELTA_LF.with(|c| c.get()); let snapshot: [i8; 4] = if DELTA_LF_MULTI.with(|c| c.get()) { std::array::from_fn(|i| cur[i].clamp(-63, 63) as i8) @@ -19271,6 +19289,9 @@ fn decode_inter_block( // reaches here skipped is the 128 root (`read_block_tx_size` hands back // four TX_64X64 leaves for `side > 64` regardless of `skip`); leaving its // block-level 128 publication in place is exactly that suppression. + if skip && is_inter { + neighbours.suppress_internal_lf_edges((rmi, cmi), write_w / MI, write_h / MI); + } if let Some(leaves) = (!(skip && is_inter)).then_some(()).and(vartx_leaves.as_ref()) { for &(row, col, tx_px) in leaves { neighbours.fill_lf_grid_rect( diff --git a/lanes/sb128c-r4.handoff.md b/lanes/sb128c-r4.handoff.md index 7777dbf2..53f71fd7 100644 --- a/lanes/sb128c-r4.handoff.md +++ b/lanes/sb128c-r4.handoff.md @@ -1,79 +1,129 @@ # lane-sb128c r4 -> r5 handoff Tip `lane-sb128c` (worktree `edith_codecs-sb128c`, -`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`). Full detail: -`lanes/sb128c-r4.report.md`. - -## Done in r4 - -- r3 suite line: `371 passed; 1 failed; 32 ignored` (the known-RED gate). -- **Deblock root cause fixed** (`6226c27`): libaom's `curr_skipped` suppression - (`set_one_param_for_line_luma`, `av1_loopfilter.c`) -- a TU edge that is not - a PU edge is never filtered when `skip_txfm && is_inter`. Our 128 root - published four TX_64X64 luma leaves and a capped 32-px uv extent into the lf - grid even when skipped. Gated the per-leaf `fill_lf_grid_rect` loop on - `!(skip && is_inter)`; dropped the inert-and-harmful `.min(32)` uv cap. -- `dump_stage` now indexes per decode-order picture (`EC_AV1_POSTDEBLOCK_DUMP` - used to overwrite `.f0`). This is the instrument that found the defect. -- CDEF-for-128-root claim in the r4 charter DISPROVED by reading `read_cdef`: - ONE `cdef_idx` symbol for a NONE 128 root (one block => one call => index 0), - replicated across the four units via the shared `MB_MODE_INFO`. r1 was right; - no change needed. Four symbols only when the root SPLITs. -- ReelC re-probe: same stop string, 1 `EC_AV1_FINAL_DUMP` frame, and that frame - is byte-identical to ffmpeg's 10-bit decode (`cmp` clean, 4561920 bytes). - -## The residue -- this is r5's first job - -Gate `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact` is still RED, -now on a DIFFERENT, independent defect one frame later. - -Stream `$HOME/.cache/sb128c-work/g-61-8-0.obu` (8-bit, 256x256, sb-size 128, -9 decode-order pictures, 8 shown). All stages of decode-order frames 0..4 are -now exact -- pre-filter, post-deblock and final (`EC_AV1_FINAL_DUMP`, which -includes the hidden frame). Decode-order frame 5 is wrong ALREADY AT -PRE-FILTER, so every reference it uses is exact and this is not propagation: +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`). Detail: `lanes/sb128c-r4.report.md` +(written before the uv-cap correction below -- this file supersedes its fix description). +## (0) r3 suite result line + +`sb128c-suite-r3-1788327685.service`, `$HOME/.cache/sb128c-suite-r3.log`: +`test result: FAILED. 371 passed; 1 failed; 32 ignored; 0 measured; 0 filtered out; finished in 797.36s` +The single failure was r3's own known-RED gate. + +## (1) The x=64 deblock band -- ROOT CAUSE, FIXED + +Stage bisection (aomdec rungs, decode order) on `$HOME/.cache/sb128c-work/g-61-8-0.obu`: +decode-order frames 0..4 pre-filter EXACT, frame 4 post-deblock WRONG (98 luma px +in a 9-px band at x=64, 274 chroma) => loop filter, not a symbol. Decisive: +aomdec's own post-deblock dump changes ZERO pixels in luma cols 50..78 of that +frame; ours changed 98 (peak 26 at col 63). libaom filters that edge not at all. + +libaom `av1/common/av1_loopfilter.c`, `set_one_param_for_line_luma` (~line 690) +and `set_one_param_for_line_chroma`: +```c +const int32_t pu_edge = mi_prev != mbmi; +if (!pu_edge) curr_skipped = mbmi->skip_txfm && is_inter_block(mbmi); +if ((pu_edge || !curr_skipped) && level) { params->filter_length = ...; } ``` -frame 5 pre-filter Y: 19609 px, rows 128..255, cols 0..255, maxd 33, first (128,0) +`get_transform_size` still reports TX_64X64 (luma) / TX_32X32 (chroma) for a +SKIP 128x128 INTER block, so the TU edge at x=64 / y=64 exists -- it is +suppressed because it is not a PU edge and the block is skipped. Every 128 +block in the gate stream is `is_inter=1 skip=1`. + +GRID WRITE (`crates/ec-av1/src/decode.rs`), final shape: +- the per-leaf `fill_lf_grid_rect` loop in `decode_inter_block` is gated on + `!(skip && is_inter)`, so the block-level publication (`write_w = 128`) stays + and no internal LUMA edge exists. The 128 root is the only block reaching + that loop skipped (`read_block_tx_size` returns four TX_64X64 leaves for + `side > 64` regardless of `skip`; every `side <= 64` skip inter block gets `None`). +- new `Neighbours::suppress_internal_lf_edges(at_mi, w_mi, h_mi)` writes the + UNCAPPED chroma extent (64 for a 128 block) into `uv_tx_grid`/`uv_tx_h_grid`, + called ONLY from the `skip && is_inter` branch of `decode_inter_block`. +- `dump_stage` now indexes its file per decode-order picture + (`EC_AV1_POSTDEBLOCK_DUMP` overwrote `.f0` every frame, so only the last + picture was comparable against aomdec's indexed rung). This is the instrument + that found the defect. + +## (1b) THE UV-CAP TRAP (cost one suite run; do not repeat) + +My first fix instead removed the `.min(32)` TX_32X32 cap inside +`fill_lf_grid_rect` outright, reasoning it was inert for every block up to 64 +wide. It is inert only for the INTER path. libaom's `curr_skipped` term +contains `is_inter_block(mbmi)`, so an INTRA 128x128 block's internal chroma TU +edges (every 32 chroma px, `av1_get_max_uv_txsize(BLOCK_128X128) == TX_32X32`) +ARE filtered. Removing the cap broke the sibling gate +`a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` +(caught mid-suite at 293/404). The cap is restored; suppression is now explicit +and inter-only. Both gates re-run together after the correction: +`key_frame_with_a_128x128_none_partition ... ok`, inter gate now fails one +frame LATER (see below). Class: `fix-trades-sibling-gate`. + +## (1c) cdef_idx per 64x64 quadrant -- the r4 charter's suspicion is WRONG + +`read_cdef` (`av1/decoder/decodemv.c`) reads at most ONE literal per CALL and is +called once per BLOCK. A `PARTITION_NONE` 128 root is one block, so exactly ONE +`cdef_idx` symbol is read (`index = cdef_unit_col_in_sb + 2*cdef_unit_row_in_sb` += 0 at the SB origin) and stored in the block's own `MB_MODE_INFO`, which all +four 64x64 CDEF units point at. r1's "replicated over 4 quadrants" is CORRECT; +no change was made. Four symbols are read only when the root SPLITs into four +non-skip 64s -- and for a 128-level HORZ/VERT root there are TWO blocks, hence +up to TWO literals: re-derive the index from that function, do not assume. + +## GATE STATES + +- `a_real_aomenc_key_frame_with_a_128x128_none_partition_decodes_pixel_exact` -- **GREEN** +- `a_real_aomenc_inter_128x128_none_root_decodes_pixel_exact` -- **RED**, advanced + from `decode-order frame 4 of 9` (deblock) to `decode-order frame 5 of 9` + (reconstruction): `differs at byte 32264 (ours 140 vs 141), 24858 bytes differ`. +- Full suite r4: NOT COMPLETED -- I stopped `sb128c-suite-r4-1788328542.service` + at 293/404 to apply the uv-cap correction. It had exactly two failures, both + named above; the key-frame one is now fixed. r5 must run a fresh full suite. + +## EXACT NEXT STEP (r5's first job) + +Decode-order frame 5 of `$HOME/.cache/sb128c-work/g-61-8-0.obu` is wrong ALREADY +AT PRE-FILTER, and every reference it uses is now exact at every stage +(pre-filter, post-deblock and `EC_AV1_FINAL_DUMP` incl. the hidden frame, frames +0..4 all zero-diff). So this is a genuine reconstruction defect, not propagation. + +``` +frame 5 pre-filter Y: 19609 px, rows 128..255, cols 0..255, maxd 33, first bad (128,0) frame 5 pre-filter C: 5207 px per-64x64 quadrant Y: [0,0,0,0] [0,0,0,0] [3707,844,3137,3889] [183,177,3844,3828] ``` - -The whole BOTTOM superblock row (both 128x128 SBs), rows 0..127 exact. -Our mode trace lists that row as two `side=128 is_inter=1 skip=1` blocks -- a -skipped inter block is pure motion compensation. Entropy stays in sync for all -9 frames. The quadrant diff is content-dependent (flat quadrants mostly match), -which is a slightly-wrong PREDICTOR, not a wrong write geometry. Frame 4's own -`(32,0)` 128 skip block is exact, so 128-wide MC itself works. - -Suspects, in order: the 128 block's mv (mv stack / GLOBALMV resolution), its -`ref_frame`, its `switchable_interp` filter, and `motion_mode`/OBMC for a -128x128 block. NOT the lf grid (pre-filter dump). +The whole BOTTOM superblock row (both 128x128 SBs); rows 0..127 exact. Our mode +trace lists that row as two `side=128 is_inter=1 skip=1` blocks -- pure motion +compensation. Entropy stays in sync for all 9 frames (no refusal, no desync). +The quadrant diff is content-dependent (flat quadrants mostly match, detailed +ones do not) = a slightly wrong PREDICTOR, not a wrong write geometry. Frame 4's +own `(32,0)` 128 skip block is exact, so 128-wide MC itself works. +Suspects in order: the block's mv (mv-stack / GLOBALMV resolution), `ref_frame`, +`switchable_interp`, `motion_mode`/OBMC at 128x128. Reproduce: ``` -cd $HOME/.cache/sb128c-work -rm -f pf-o.f* pf-m.f* +cd $HOME/.cache/sb128c-work && rm -f pf-o.f* pf-m.f* systemd-run --user --scope -q -p MemoryMax=6G env EC_AV1_PREFILT_DUMP=$PWD/pf-o \ ~/.cache/aom-oracle/build/aomdec --rawvideo -o /dev/null g-61-8-0.obu systemd-run --user --scope -q -p MemoryMax=6G env EC_NOMEMGUARD=1 EC_AV1_PREFILT_DUMP=$PWD/pf-m \ $HOME/.cache/cargo-target-sb128c/debug/examples/decode_probe g-61-8-0.obu -# compare pf-o.fN vs pf-m.fN, 256x256 yuv420p8 +# 256x256 yuv420p8, pf-o.fN vs pf-m.fN ``` -Oracle rungs available: `EC_AV1_PREFILT_DUMP`, `EC_AV1_POSTDEBLOCK_DUMP`, -`EC_AV1_FINAL_DUMP` (all indexed, decode order, hidden frames included), and -`EC_TRACE_MODE` (`EC_MODE_MV` / `EC_MODE_VAL` carry `mode`, `ref0`, `ref1`, -`mv0`, `stack`, `rng` -- 62 lines on this stream, none in the bottom SB row of -the failing frame, so a per-block mv trace for skip blocks has to come from -`EC_PRED`/`EC_PREDOUT` or a new rung). +Oracle rungs: `EC_AV1_PREFILT_DUMP`, `EC_AV1_POSTDEBLOCK_DUMP`, +`EC_AV1_FINAL_DUMP` (all indexed, decode order, hidden frames included), +`EC_TRACE_MODE` (`EC_MODE_MV`/`EC_MODE_VAL` carry mode/ref0/ref1/mv0/stack/rng -- +only 62 lines on this stream and NONE in the failing bottom SB row, so a skip +block's mv needs `EC_PRED`/`EC_PREDOUT` or a new rung). +NOTE (ledger constraint): our `EC_AV1_POSTDEBLOCK_DUMP` site runs AFTER +`apply_cdef` on the inter path -- pair it with `EC_AV1_DEBUG_SKIP_CDEF=1` or a +CDEF defect reads as a deblock defect. ## (3) 128-level HORZ/VERT + AB -- NOT STARTED deferred: 128x64 / 64x128 and AB at the 128 root, key and inter paths -- r4's -budget went to the stage bisection; unblocked by nothing. This is the exact -string both ReelC extracts still stop at and it is the film frontier. -Charter facts from r4's charter that are still unverified: max tx TX_64X64, -2 mu chunks, chroma 64x32 -> 2x TX_32X32 with offset-10 `txb_skip` rows, -lf grid per unit, cdef per 64x64 quadrant (NOTE: for HORZ/VERT the 128 root has -TWO blocks, so `read_cdef` is called twice and can read up to 2 literals -- -re-derive the index per block from `decodemv.c:read_cdef` rather than assuming). +budget went to the stage bisection and the uv-cap correction; unblocked by +nothing. Both ReelC extracts (`$HOME/.cache/sb128c-work/reelc2s.obu` and +`$HOME/.cache/reelc-head.obu`, 1428 B, `use_128x128_superblock=true bit_depth=10`) +still stop at `a 128x128 superblock HORZ/VERT or AB partition (only SPLIT and +NONE are decoded at the 128 root)`, `EC_AV1_FINAL_DUMP` count 1 -- and that one +frame is BYTE-IDENTICAL to ffmpeg's `yuv420p10le` decode (4561920 B, `cmp` clean).