forge
Explore
Log in

Don't you dare go Hollow

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

Browse files at this commit

76749a1148bd5189bc35845c49dd5f7d6a785804Ahmet Kaan GümüşParent: 3191098
  • fix
    • 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
Show full message
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.rsmodified+13 -3
@@ -11800,7 +11800,12 @@ fn read_block_tx_size(
1180011800 }
1180111801 }
1180211802 let single = leaves.len() == 1 && leaves[0].2 == side && leaves[0].3 == side;
11803- if !single && leaves.iter().any(|leaf| leaf.2.max(leaf.3) > 64) {
11803+ // lane-sb128c r6: below the 128 root the ceiling is main's TX_32X32
11804+ // ([`inter_txbset_for`] has no 64-point *inter* table set); a 128x128
11805+ // block's own var-tx tree legitimately bottoms out at TX_64X64 leaves,
11806+ // which the mu-chunk reader above codes as their 32x32 coded corner.
11807+ let leaf_ceiling = if side > 64 { 64 } else { 32 };
11808+ if !single && leaves.iter().any(|leaf| leaf.2.max(leaf.3) > leaf_ceiling) {
1180411809 // Only a block wider than a superblock's own 64x64 max transform
1180511810 // reaches here; this crate has no 64-point *inter* coefficient
1180611811 // table set ([`inter_txbset_for`] stops at 32).
@@ -19650,10 +19655,15 @@ fn decode_inter_block(
1965019655 // reaches here skipped is the 128 root (`read_block_tx_size` hands back
1965119656 // four TX_64X64 leaves for `side > 64` regardless of `skip`); leaving its
1965219657 // block-level 128 publication in place is exactly that suppression.
19653- if skip && is_inter {
19658+ // lane-sb128c r6: narrowed to the 128 root. Below it `read_block_tx_size`
19659+ // hands a skipped inter block a single leaf equal to the block, so the
19660+ // per-leaf write is the block-level one and this branch is a no-op either
19661+ // way; only the 128 root gets four TX_64X64 leaves regardless of `skip`.
19662+ let skip_inter_128 = skip && is_inter && write_w.max(write_h) > 64;
19663+ if skip_inter_128 {
1965419664 neighbours.suppress_internal_lf_edges((rmi, cmi), write_w / MI, write_h / MI);
1965519665 }
19656- if let Some(leaves) = (!(skip && is_inter)).then_some(()).and(vartx_leaves.as_ref()) {
19666+ if let Some(leaves) = (!skip_inter_128).then_some(()).and(vartx_leaves.as_ref()) {
1965719667 for &(row, col, tw, th) in leaves {
1965819668 neighbours.fill_lf_grid_leaf_luma(
1965919669 (at_mi.0 + row, at_mi.1 + col),
crates/ec-av1/src/mvstack.rsmodified+22 -2
@@ -631,6 +631,26 @@ fn scan_col(
631631 found
632632 }
633633
634+/// The half of libaom's `has_top_right` (mvref_common.c:264) that
635+/// `setup_ref_mv_list` (mvref_common.c:497/546) gates the top-right mv probe on
636+/// and that this crate can state exactly: `if (bs > mi_size_wide[BLOCK_64X64])
637+/// return 0`. A 128x128 / 128x64 / 64x128 block has NO top-right candidate even
638+/// though the cell diagonally above-right of it sits in decoded memory -- an
639+/// ungated grid probe invented `(441,441) w=644` at `mi(32,0)` and desynced the
640+/// drl symbols of the 128 inter gate (lane-sb128c r5).
641+///
642+/// corner-cut: the position-mask half of `has_top_right` is deliberately NOT
643+/// applied here. It needs libaom's three shape refinements
644+/// (`is_last_vertical_rect`, `is_first_horizontal_rect`, the `PARTITION_VERT_A`
645+/// bottom-left square) which [`has_top_right`] does not port; applying the mask
646+/// without them cost the 64-level AB, free-partition and 1:4 gates frame 16
647+/// (measured lane-sb128c r6). Ceiling: a sub-128 block may still probe a
648+/// top-right libaom would not, exactly as main does today; upgrade path = port
649+/// the three refinements into [`has_top_right`] and gate on it whole.
650+fn top_right_scan_allowed(bw4: usize, bh4: usize) -> bool {
651+ bw4.max(bh4) <= 16
652+}
653+
634654 /// libaom `has_top_right` (mvref_common.c:264): whether the unit diagonally
635655 /// above-right of this block has been decoded *by the superblock's own
636656 /// recursion order*. The mask is `sb_size`-relative, so at a 128x128
@@ -879,7 +899,7 @@ pub fn find_mv_stack_with_sign_bias(
879899 // (mvref_common.c:497/546): the diagonally-above-right unit of a 128x128
880900 // block sits in decoded memory but is NOT available (bs > 16), so an
881901 // ungated grid probe invents a candidate and desyncs the drl symbols.
882- let found_top_right = has_top_right(mi_row, mi_col, bw4, bh4)
902+ let found_top_right = top_right_scan_allowed(bw4, bh4)
883903 && scan_top_right(
884904 grid,
885905 mi_row,
@@ -1677,7 +1697,7 @@ pub fn find_mv_stack_compound(
16771697 // (mvref_common.c:497/546): the diagonally-above-right unit of a 128x128
16781698 // block sits in decoded memory but is NOT available (bs > 16), so an
16791699 // ungated grid probe invents a candidate and desyncs the drl symbols.
1680- let found_top_right = has_top_right(mi_row, mi_col, bw4, bh4)
1700+ let found_top_right = top_right_scan_allowed(bw4, bh4)
16811701 && scan_top_right_compound(
16821702 grid,
16831703 mi_row,
lanes/sb128c-r6.handoff.mdadded+75 -0
@@ -0,0 +1,75 @@
1+# lane-sb128c r6 -> r7 handoff: the 128-root HORZ/VERT/AB partition work
2+
3+Worktree `edith_codecs-sb128c`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sb128c`.
4+r6 merged main 727f29a + lane-golomb 173b793 and re-greened the five 128 gate arms;
5+it did NOT start the partition work. Everything below is measured this round.
6+
7+## The blocker on the 1080p AV1 film is ONE arm: the GATHERED bottom-edge HORZ
8+
9+`decode_probe` on four extracts of the 1080p 10-bit AV1 film (2 s each, `-c:v copy`)
10+all stop at `a 128x128 superblock HORZ/VERT or AB partition`, and
11+`EC_AV1_TRACE=1 | grep partition_w128` shows values **0 and 3 only** right up to the
12+stop -- i.e. the refusing partition never came from the full-alphabet symbol (which
13+traces every value) but from `read_sb128_root`'s GATHERED branch (`decode.rs:13317`,
14+no trace line): frame height 1080 gives `mi_rows = 270`, so the bottom 128 row has
15+`mi_r128 = 256`, `256 + SB_MI(16) = 272 > 270` -> `has_rows128 == false`, one gathered
16+bit, and the film codes it as `PARTITION_HORZ` (a 128x64 block whose bottom 8 luma rows
17+are the only ones in frame). Frame width 1920 = 15*128 exactly, so `has_cols128` is
18+always true and the VERT gathered arm is unreachable on this film.
19+=> r7's minimum for the film is the **128x64 block** (key + inter), not the whole set.
20+
21+## What aomenc actually emits (measured, 90 streams)
22+
23+- Sweep A, 72 streams (`sweep.sh`: seeds 41/42/43/61/62/71 x 256x256,384x384 x cq
24+ 40/55/63 x 8+10-bit, `--sb-size=128 --cpu-used=0 --min-partition-size=64
25+ --enable-rect-partitions=1 --enable-ab-partitions=1`): partition_w128 takes ONLY
26+ value 0 (NONE) and 3 (SPLIT). No HORZ, no VERT, no AB, at any setting.
27+- Sweep B, 18 streams (`sweep2.sh`, 512x512 synthetic sources designed to favour the
28+ arms): horizontal-stripe and vertical-stripe sources still give NONE only; the
29+ **AB-shaped** source (`geq` = top 64 rows of every 128 uniform, bottom split into two
30+ 64x64 levels) gives `value=1` (**PARTITION_HORZ at the 128 root**) at every cq
31+ (32/50/63) and both `--min-partition-size` 64 and 16.
32+ 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`
33+ Streams kept at `$HOME/.cache/sb128c-work/s2-abshape-*.obu` (decode stops at the
34+ 5th 128 root of the KEY frame).
35+- Whether VERT / the four AB values (4..7) are reachable is still UNKNOWN: our decoder
36+ stops at the first refusing root, so nothing past it is observable. Re-run both
37+ sweeps once HORZ decodes -- only then is "aomenc never picks arm X" a measured claim
38+ (class `refusal-lifted-without-a-gate`: keep the unreached arms refused BY NAME).
39+
40+## Shape of the 128x64 / 64x128 block (spec + libaom, for r7)
41+
42+- luma: `max_txsize_rect_lookup[BLOCK_128X64] = TX_64X64` -> two TX_64X64 units, each
43+ coding only its top-left 32x32 (`default_scan(tx_px.min(32))`, already the convention
44+ at decode.rs:17540/:18670).
45+- chroma: `av1_get_max_uv_txsize(BLOCK_128X64) = TX_32X32` over a 64x32 uv block -> two
46+ units per plane, uv block > uv tx, so the txb_skip CDF takes the offset-10 rows.
47+- coding order: two 64x64 mu chunks (`decode_token_recon_block`), Y then U then V per
48+ chunk -- the existing `side > 64` chunk loop in `decode_inter_block` (decode.rs:17568)
49+ already does this for four chunks; it keys the chunk on `(row/16, col/16)`.
50+- `motion_mode`/`obmc` rows BLOCK_64X128 (14) / BLOCK_128X64 (15) are already in
51+ `cdf.rs` (added r5, packed indices 14/15/16 with 128X128).
52+- `has_top_right`: `mvstack::has_top_right` returns 0 for `bs0 = max(bw4,bh4) > 16`, so
53+ both 128x64 and 64x128 have no top-right candidate; the probe is now gated
54+ (mvstack.rs:882/:1680), nothing more to do there.
55+- lf grid: per-unit write with the skip-inter suppression, luma-only leaf write
56+ (`fill_lf_grid_leaf_luma`, from lane-golomb) -- both already merged in r6.
57+- one `cdef_idx` literal per block, copied to every 64x64 CDEF unit the block covers
58+ (the pattern at decode.rs:13606 / :21744).
59+- palette (>64), CfL (>32) and filter intra are all size-refused already.
60+- AB visit order (libaom `decode_partition`): VERT_A = 64x64 TL, 64x64 BL, 64x128 right;
61+ VERT_B = 64x128 left, 64x64 TR, 64x64 BR; HORZ_A = 64x64 TL, 64x64 TR, 128x64 bottom;
62+ HORZ_B = 128x64 top, 64x64 BL, 64x64 BR.
63+
64+## Entry points to touch
65+
66+- `read_sb128_root` decode.rs:13277 (the refusal at :13345, both branches).
67+- key-frame tile: decode.rs:13554 (`part128 == PARTITION_NONE` arm; the 128 NONE block
68+ goes through `decode_block(..., SB * 2, ...)`; a 128x64 needs the rect analogue --
69+ `decode_block_rect64` (decode.rs:8061) is the 64x32/32x64 one and is corner-cropped
70+ for a 32x32 real transform, so it does NOT generalise as-is).
71+- inter tile: decode.rs:21642 + the `inter_piece!` macro at :21683 -- there a 128x64 is
72+ plausibly `inter_piece!(mi, SB * 2, ..., ww = SB * 2, wh = SB)` because
73+ `decode_inter_block` is already (write_w, write_h)-general; try the inter arm FIRST,
74+ it is much cheaper than the key one.
75+- `refusal_inventory.rs:46` + `gate_coverage.rs` in the same commit as the gate.