From 76749a1148bd5189bc35845c49dd5f7d6a785804 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 10:00:24 +0300 Subject: [PATCH] fix(av1): gate the top-right mv probe on the bs>64 half of has_top_right only, and cap inter var-tx leaves per root size The r5 wiring applied libaom's whole has_top_right, position mask included, without its three shape refinements (is_last_vertical_rect, is_first_horizontal_rect, the PARTITION_VERT_A bottom-left square). That is right for a 128 block (bs > 64 -> no candidate, the defect r5 fixed) and wrong below it: the 64-level AB, free-partition and 1:4 stream gates lost frame 16 luma. Gate on the size half only; ceiling and upgrade path named at the helper. Also: the merged var-tx leaf ceiling is per root (32 below the 128 root, 64 at it, where the mu-chunk reader codes a TX_64X64's 32x32 coded corner), and the skipped-inter internal-edge suppression is narrowed to the 128 root, the only size whose leaves are not the block. --- crates/ec-av1/src/decode.rs | 16 ++++++-- crates/ec-av1/src/mvstack.rs | 24 +++++++++++- lanes/sb128c-r6.handoff.md | 75 ++++++++++++++++++++++++++++++++++++ 3 files changed, 110 insertions(+), 5 deletions(-) create mode 100644 lanes/sb128c-r6.handoff.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index f9eb4f01..c714813d 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -11800,7 +11800,12 @@ fn read_block_tx_size( } } let single = leaves.len() == 1 && leaves[0].2 == side && leaves[0].3 == side; - if !single && leaves.iter().any(|leaf| leaf.2.max(leaf.3) > 64) { + // lane-sb128c r6: below the 128 root the ceiling is main's TX_32X32 + // ([`inter_txbset_for`] has no 64-point *inter* table set); a 128x128 + // block's own var-tx tree legitimately bottoms out at TX_64X64 leaves, + // which the mu-chunk reader above codes as their 32x32 coded corner. + let leaf_ceiling = if side > 64 { 64 } else { 32 }; + if !single && leaves.iter().any(|leaf| leaf.2.max(leaf.3) > leaf_ceiling) { // Only a block wider than a superblock's own 64x64 max transform // reaches here; this crate has no 64-point *inter* coefficient // table set ([`inter_txbset_for`] stops at 32). @@ -19650,10 +19655,15 @@ 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 { + // lane-sb128c r6: narrowed to the 128 root. Below it `read_block_tx_size` + // hands a skipped inter block a single leaf equal to the block, so the + // per-leaf write is the block-level one and this branch is a no-op either + // way; only the 128 root gets four TX_64X64 leaves regardless of `skip`. + let skip_inter_128 = skip && is_inter && write_w.max(write_h) > 64; + if skip_inter_128 { 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()) { + if let Some(leaves) = (!skip_inter_128).then_some(()).and(vartx_leaves.as_ref()) { for &(row, col, tw, th) in leaves { neighbours.fill_lf_grid_leaf_luma( (at_mi.0 + row, at_mi.1 + col), diff --git a/crates/ec-av1/src/mvstack.rs b/crates/ec-av1/src/mvstack.rs index 77d590a2..4755c69c 100644 --- a/crates/ec-av1/src/mvstack.rs +++ b/crates/ec-av1/src/mvstack.rs @@ -631,6 +631,26 @@ fn scan_col( found } +/// The half of libaom's `has_top_right` (mvref_common.c:264) that +/// `setup_ref_mv_list` (mvref_common.c:497/546) gates the top-right mv probe on +/// and that this crate can state exactly: `if (bs > mi_size_wide[BLOCK_64X64]) +/// return 0`. A 128x128 / 128x64 / 64x128 block has NO top-right candidate even +/// though the cell diagonally above-right of it sits in decoded memory -- an +/// ungated grid probe invented `(441,441) w=644` at `mi(32,0)` and desynced the +/// drl symbols of the 128 inter gate (lane-sb128c r5). +/// +/// corner-cut: the position-mask half of `has_top_right` is deliberately NOT +/// applied here. It needs libaom's three shape refinements +/// (`is_last_vertical_rect`, `is_first_horizontal_rect`, the `PARTITION_VERT_A` +/// bottom-left square) which [`has_top_right`] does not port; applying the mask +/// without them cost the 64-level AB, free-partition and 1:4 gates frame 16 +/// (measured lane-sb128c r6). Ceiling: a sub-128 block may still probe a +/// top-right libaom would not, exactly as main does today; upgrade path = port +/// the three refinements into [`has_top_right`] and gate on it whole. +fn top_right_scan_allowed(bw4: usize, bh4: usize) -> bool { + bw4.max(bh4) <= 16 +} + /// libaom `has_top_right` (mvref_common.c:264): whether the unit diagonally /// above-right of this block has been decoded *by the superblock's own /// recursion order*. The mask is `sb_size`-relative, so at a 128x128 @@ -879,7 +899,7 @@ pub fn find_mv_stack_with_sign_bias( // (mvref_common.c:497/546): the diagonally-above-right unit of a 128x128 // block sits in decoded memory but is NOT available (bs > 16), so an // ungated grid probe invents a candidate and desyncs the drl symbols. - let found_top_right = has_top_right(mi_row, mi_col, bw4, bh4) + let found_top_right = top_right_scan_allowed(bw4, bh4) && scan_top_right( grid, mi_row, @@ -1677,7 +1697,7 @@ pub fn find_mv_stack_compound( // (mvref_common.c:497/546): the diagonally-above-right unit of a 128x128 // block sits in decoded memory but is NOT available (bs > 16), so an // ungated grid probe invents a candidate and desyncs the drl symbols. - let found_top_right = has_top_right(mi_row, mi_col, bw4, bh4) + let found_top_right = top_right_scan_allowed(bw4, bh4) && scan_top_right_compound( grid, mi_row, diff --git a/lanes/sb128c-r6.handoff.md b/lanes/sb128c-r6.handoff.md new file mode 100644 index 00000000..490ebbb8 --- /dev/null +++ b/lanes/sb128c-r6.handoff.md @@ -0,0 +1,75 @@ +# lane-sb128c r6 -> r7 handoff: the 128-root HORZ/VERT/AB partition work + +Worktree `edith_codecs-sb128c`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`. +r6 merged main 727f29a + lane-golomb 173b793 and re-greened the five 128 gate arms; +it did NOT start the partition work. Everything below is measured this round. + +## The blocker on the 1080p AV1 film is ONE arm: the GATHERED bottom-edge HORZ + +`decode_probe` on four extracts of the 1080p 10-bit AV1 film (2 s each, `-c:v copy`) +all stop at `a 128x128 superblock HORZ/VERT or AB partition`, and +`EC_AV1_TRACE=1 | grep partition_w128` shows values **0 and 3 only** right up to the +stop -- i.e. the refusing partition never came from the full-alphabet symbol (which +traces every value) but from `read_sb128_root`'s GATHERED branch (`decode.rs:13317`, +no trace line): frame height 1080 gives `mi_rows = 270`, so the bottom 128 row has +`mi_r128 = 256`, `256 + SB_MI(16) = 272 > 270` -> `has_rows128 == false`, one gathered +bit, and the film codes it as `PARTITION_HORZ` (a 128x64 block whose bottom 8 luma rows +are the only ones in frame). Frame width 1920 = 15*128 exactly, so `has_cols128` is +always true and the VERT gathered arm is unreachable on this film. +=> r7's minimum for the film is the **128x64 block** (key + inter), not the whole set. + +## What aomenc actually emits (measured, 90 streams) + +- Sweep A, 72 streams (`sweep.sh`: seeds 41/42/43/61/62/71 x 256x256,384x384 x cq + 40/55/63 x 8+10-bit, `--sb-size=128 --cpu-used=0 --min-partition-size=64 + --enable-rect-partitions=1 --enable-ab-partitions=1`): partition_w128 takes ONLY + value 0 (NONE) and 3 (SPLIT). No HORZ, no VERT, no AB, at any setting. +- Sweep B, 18 streams (`sweep2.sh`, 512x512 synthetic sources designed to favour the + arms): horizontal-stripe and vertical-stripe sources still give NONE only; the + **AB-shaped** source (`geq` = top 64 rows of every 128 uniform, bottom split into two + 64x64 levels) gives `value=1` (**PARTITION_HORZ at the 128 root**) at every cq + (32/50/63) and both `--min-partition-size` 64 and 16. + Reproduce: `nullsrc=s=512x512:d=0.32:r=25,geq=lum='if(lt(mod(Y\,128)\,64),200,if(lt(mod(X\,128)\,64),40,120))':cb=128:cr=128,noise=all_seed=7:alls=3:allf=t` + Streams kept at `$HOME/.cache/sb128c-work/s2-abshape-*.obu` (decode stops at the + 5th 128 root of the KEY frame). +- Whether VERT / the four AB values (4..7) are reachable is still UNKNOWN: our decoder + stops at the first refusing root, so nothing past it is observable. Re-run both + sweeps once HORZ decodes -- only then is "aomenc never picks arm X" a measured claim + (class `refusal-lifted-without-a-gate`: keep the unreached arms refused BY NAME). + +## Shape of the 128x64 / 64x128 block (spec + libaom, for r7) + +- luma: `max_txsize_rect_lookup[BLOCK_128X64] = TX_64X64` -> two TX_64X64 units, each + coding only its top-left 32x32 (`default_scan(tx_px.min(32))`, already the convention + at decode.rs:17540/:18670). +- chroma: `av1_get_max_uv_txsize(BLOCK_128X64) = TX_32X32` over a 64x32 uv block -> two + units per plane, uv block > uv tx, so the txb_skip CDF takes the offset-10 rows. +- coding order: two 64x64 mu chunks (`decode_token_recon_block`), Y then U then V per + chunk -- the existing `side > 64` chunk loop in `decode_inter_block` (decode.rs:17568) + already does this for four chunks; it keys the chunk on `(row/16, col/16)`. +- `motion_mode`/`obmc` rows BLOCK_64X128 (14) / BLOCK_128X64 (15) are already in + `cdf.rs` (added r5, packed indices 14/15/16 with 128X128). +- `has_top_right`: `mvstack::has_top_right` returns 0 for `bs0 = max(bw4,bh4) > 16`, so + both 128x64 and 64x128 have no top-right candidate; the probe is now gated + (mvstack.rs:882/:1680), nothing more to do there. +- lf grid: per-unit write with the skip-inter suppression, luma-only leaf write + (`fill_lf_grid_leaf_luma`, from lane-golomb) -- both already merged in r6. +- one `cdef_idx` literal per block, copied to every 64x64 CDEF unit the block covers + (the pattern at decode.rs:13606 / :21744). +- palette (>64), CfL (>32) and filter intra are all size-refused already. +- AB visit order (libaom `decode_partition`): VERT_A = 64x64 TL, 64x64 BL, 64x128 right; + VERT_B = 64x128 left, 64x64 TR, 64x64 BR; HORZ_A = 64x64 TL, 64x64 TR, 128x64 bottom; + HORZ_B = 128x64 top, 64x64 BL, 64x64 BR. + +## Entry points to touch + +- `read_sb128_root` decode.rs:13277 (the refusal at :13345, both branches). +- key-frame tile: decode.rs:13554 (`part128 == PARTITION_NONE` arm; the 128 NONE block + goes through `decode_block(..., SB * 2, ...)`; a 128x64 needs the rect analogue -- + `decode_block_rect64` (decode.rs:8061) is the 64x32/32x64 one and is corner-cropped + for a 32x32 real transform, so it does NOT generalise as-is). +- inter tile: decode.rs:21642 + the `inter_piece!` macro at :21683 -- there a 128x64 is + plausibly `inter_piece!(mi, SB * 2, ..., ww = SB * 2, wh = SB)` because + `decode_inter_block` is already (write_w, write_h)-general; try the inter arm FIRST, + it is much cheaper than the key one. +- `refusal_inventory.rs:46` + `gate_coverage.rs` in the same commit as the gate.