From ff5d3c5b3fd1ffba4e620fcd8c3f27402b65f4a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Sep 2026 15:49:01 +0300 Subject: [PATCH] docs(av1): name the var-tx parent-side publish defect at its site, keep the shipped value r3 proved the root cause of the straddling-band partition-ctx divergence (a var-tx inter block is not always square: a superblock-level PARTITION_VERT strip is 32x64 with side == 64 and stamps the parent's 64 into the partition-context bands, so the next superblock reads CDF row 0 where the oracle reads row 1) and reverts the fix: all four variants -- true footprint in the record call, per-piece band republish, parent-span band republish, and VERT-only -- take the straddling gate 3622 -> 3376 differing pixels AND turn two attempts of the 1:4 rect var-tx gate into the named "non-skip rectangular strip needs rectangular residual coding" refusal, failing its hit assert. `side` is not the parent bsize at every call site, so the band write belongs in the partition arms; that is r4's job. Site comment records the finding, lanes/mergefix-r3.report.md the ladders, variants and swept sites. --- crates/ec-av1/src/decode.rs | 23 +++++++--- lanes/mergefix-r3.report.md | 86 +++++++++++++++++++++++++++++++++++++ 2 files changed, 102 insertions(+), 7 deletions(-) create mode 100644 lanes/mergefix-r3.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b14a1537..8cc1cbf3 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -20850,13 +20850,22 @@ fn decode_inter_block( if vartx_leaves.is_some() { // Plane 0 is already correct per transform unit // ([`Neighbours::record_mi_luma`] above); this writes everything else - // [`Neighbours::record_rect`] would. - // lane-mergefix r3 (class `tx-grid-published-block-side`): a var-tx - // block is NOT always square -- a superblock-level PARTITION_VERT - // inter strip is 32x64 with `side == 64`, and publishing `side, side` - // stamped the PARENT's 64 into `above_side_mi`/`left_side_mi`, so the - // next superblock's partition ctx read 0 where libaom read 1. - neighbours.record_split_luma_rect_mi(at, write_w, write_h, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); + // [`Neighbours::record_rect`] would (a var-tx block is always square, + // so `write_w == write_h == side`). + // + // lane-mergefix r3 (class `tx-grid-published-block-side`, OPEN): that + // premise is FALSE for a superblock-level PARTITION_VERT inter strip + // (32x64 with `side == 64`), which stamps the PARENT's 64 into + // `above_side_mi`/`left_side_mi` and makes the next superblock's + // 64-level partition ctx read 0 where the oracle reads 1. Passing + // `write_w, write_h` here (or republishing only the two side bands, + // per piece or over the parent span) fixes that ladder AND turns two + // attempts of `real_aomenc_1to4_streams_..._rect_vartx_leaves_fire` + // into the named "non-skip rectangular strip needs rectangular + // residual coding" refusal -- all three variants measured in r3, see + // lanes/mergefix-r3.report.md. Left at the parent value until the + // band write moves into the partition arms. + neighbours.record_split_luma_rect_mi(at, side, side, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]); } else { neighbours.record_rect_mi( at, diff --git a/lanes/mergefix-r3.report.md b/lanes/mergefix-r3.report.md new file mode 100644 index 00000000..fafcb2c0 --- /dev/null +++ b/lanes/mergefix-r3.report.md @@ -0,0 +1,86 @@ +# lane-mergefix r3 report + +## Verdict +Root cause of the `a_frame_edge_straddling_band_decodes_pixel_exact` partition-ctx +divergence FOUND and proven against the instrumented oracle; the fix is NOT shipped +because all three variants of it turn a green sibling gate red (class +`fix-trades-sibling-gate`). Branch is code-identical to r2 plus a `lane-mergefix r3` +comment at the site (`crates/ec-av1/src/decode.rs:20852`) naming the defect and the +three measured variants. Straddling gate stays RED at 3622 px, exactly as r2 left it. + +## Root cause (proven) +`decode_inter_block`'s var-tx branch (decode.rs ~20857) calls +`record_split_luma_rect_mi(at, side, side, ..)` on the comment's premise "a var-tx +block is always square, so `write_w == write_h == side`". FALSE: a superblock-level +`PARTITION_VERT` inter strip is 32x64 with `side == 64`, so the strip stamps the +PARENT's 64 into `above_side_mi`/`left_side_mi`. `Neighbours::partition_ctx_mi` +(decode.rs ~4985) then reads `above_side_mi[32] * 2 <= 64` as false and picks +partition CDF row 0 where libaom picks row 1. Class `tx-grid-published-block-side`, +7th instance. + +EVIDENCE: ladder at mi(16,32) of the pinned stream (md5 a14892ed0ba88b6ad2b566e251ea2d33, +192x68 cq61 tile_cols=1 8-bit, `~/.cache/mergefix-tmp/mkstr.sh`) | +`EC_TRACE_PART=1 /debug/examples/decode_probe str61.obu` vs +`EC_TRACE_MODE=1 aomdec --rawvideo -o /dev/null str61.obu` | +ours `EC_PARTG mi_row=16 mi_col=32 bsize=12 ctx=0 rng=51641` -> with `write_w/write_h` +`ctx=1 rng=51641` then `bsize=9 rng=38495`, matching aomdec `EC_PART ... ctx=13 +(= bsl*4+1) rng=51641 -> value=3 (SPLIT) rng=38495`. + +EVIDENCE: gate delta | `cargo test -p ec-av1 --lib -- a_frame_edge_straddling_band_decodes_pixel_exact` +with the fix applied | 3622 -> 3376 differing pixels, same first pixel (frame 1, row 0 +col 64, ours 56 vs ffmpeg 178). + +## Why it is not shipped (the trade, measured 3 ways) +With the fix, `real_aomenc_1to4_streams_decode_pixel_exact_and_rect_vartx_leaves_fire_before_a_named_refusal` +goes green -> RED: two 8-bit attempts (16, 17) that previously decoded pixel-exact now +stop at the named refusal `unsupported: AV1 tile (a non-skip rectangular +(HORZ/VERT/HORZ_B) strip needs rectangular residual coding)`, so the gate's rect var-tx +leaf counter drops to 0 and it fails its own hard assert. + +Variants measured, each with both gates in one invocation: +1. `record_split_luma_rect_mi(at, write_w, write_h, ..)` -- straddling 3376, 1to4 "0 leaves, 0 refusals" FAIL. +2. keep the call at `side, side`, republish only `above_side_mi`/`left_side_mi` per piece with `write_w/write_h` -- straddling 3376, 1to4 2 refusals FAIL. +3. same, but over the PARENT span (`rmi & !(n-1)`, `n = side / MI`; libaom's `update_partition_context` takes `bsize`, not the piece) -- straddling 3376, 1to4 2 refusals FAIL. +4. variant 3 restricted to VERT shapes only (`write_w * 2 == side && write_h == side`) -- straddling 3376, 1to4 2 refusals FAIL. + +Reading: `side` at those 1:4-gate call sites is not necessarily the piece's PARENT +bsize (sb128 streams pass `side = 64` for pieces whose parent is 128), so a +parent-span write keyed off `side` stamps the wrong span there. The band write belongs +in the partition arms, where the parent bsize and origin are known -- that is the r4 job. + +## Swept sites (class sweep, `side`/parent dimension into a per-mi side band) +- decode.rs:20857 `record_split_luma_rect_mi(at, side, side, ..)` in `decode_inter_block` var-tx branch -- THE DEFECT (documented, not changed). +- decode.rs:6791 `record_split_luma_rect_mi(at_mi, bw, bh, ..)` -- already true footprint, OK. +- decode.rs:10798 `record_split_luma(at, side, ..)` in `decode_block` -- square intra block, `side` is its own, OK. +- decode.rs:5383 `record_mi_rect` / :5567 `record_split_luma_rect_mi` band writes -- take w/h from the caller, OK. +- decode.rs:8596, :11235, :11565, :11919, :21364, :21847 direct `above_side_mi`/`left_side_mi` writes -- all use the block's own `bw`/`bh` (or the documented 4/8 constants), OK. +- `record_rect_mi`/`record_inter_rect_mi`/`record_compound_ctx_rect_mi` square wrappers (:4821, :5097, :5497) -- callers are square blocks, OK. +No second instance of the parent-dimension shape found. + +## Second residue (unchanged by all of the above) +With the fix in place, frame 1 of the pinned stream is element-exact against the oracle +in BOTH ladders yet still differs by 3376 px: EC_MODE ladder identical for all 66 +blocks of frame 1 (first divergence is frame 2's block at mi(0,16)); the +`tag=all_zero`/`tag=eob` range ladder is identical for its first 225 entries (all of +frames 0-1) and only then diverges. The first bad pixel is frame 1 row 0 col 64 = +mi(0,16), a 32x32 compound skip block (`EC_MODE ... is_inter=1 skip=1 side=32`, +`mode=19 ref0=1 ref1=7 mv0=(0,0)`), so frame 1 is a RECONSTRUCTION defect (compound +prediction), not an entropy one. +EVIDENCE: ~/.cache/mergefix-tmp/{ours.txt,aom.txt,oc.txt,ac.txt} | `EC_TRACE_MODE=1` and +`EC_TRACE_COEFF=1` on both decoders over str61.obu | `paste`d EC_MODE rng columns equal +through frame 1 (66 blocks), coefficient ladders equal for 225/225 entries. + +## Suite +`systemd-run --user --unit=mergefix-suite-r3-1788352226 ... cargo test -p ec-av1 --lib -j3` +(log `$HOME/.cache/mergefix-suite-r3.log`, run WITH variant 1 applied): +`test result: FAILED. 404 passed; 2 failed; 37 ignored` -- +`a_frame_edge_straddling_band_decodes_pixel_exact` (3376 px) and +`real_aomenc_1to4_streams_..._rect_vartx_leaves_fire` (the trade above). +After reverting to the shipped state, the two gates re-run in one invocation give +`1 passed; 1 failed`: 1to4 ok, straddling 3622 px (r2's number, no regression). + +## Disposition +- fix-now for r4: move the partition-context band write out of `decode_inter_block` and + into the partition arms (parent bsize + origin known there), then re-run BOTH gates. +- deferred: frame-1 compound-skip reconstruction defect at mi(0,16) -- unblocked by a + prediction-side ladder (EC_AV1_PREFILT_DUMP on frame 1), independent of the above.