From 1f9bde4cb2f7a4f1b2fbea29be025a944c9e622e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Sep 2026 23:03:10 +0300 Subject: [PATCH] fix(av1): the 16x16-level PARTITION_VERT_B arm missed the vert availability tables decode.rs:7008 visits its two 8x8 squares TR then BR, out of raster order, so like the 32/64-level AB arms r5 fixed it must read libaom's has_tr_vert_8x8 / has_bl_vert_8x8 (get_has_tr_table / get_has_bl_table take the partition type). has_bl_8x8 is 0 where has_bl_vert_8x8 is 1 at all 16 even-row/odd-col 8x8 slots -- exactly the TR square -- so its below_left was wrongly false for the directional modes that read below-left (angle > 180: D203_PRED, D157_PRED with a positive delta). Class swept: this was the only remaining unguarded VERT_A/_B site at any level, intra or inter. Gated by a table pin (encode.rs) rather than a stream: a bounded 112-encode aomenc sweep produced no decodable 16-level VERT_B -- every stream that partitions that small first hits the still-refused HORZ_A/HORZ_B/VERT_A-below-16 or coded-rect-strip-below-16 arms. Counts in lanes/part32-r6.report.md. EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib: 270 passed, 0 failed. --- crates/ec-av1/src/decode.rs | 12 +++++ crates/ec-av1/src/encode.rs | 39 ++++++++++++++++ lanes/part32-r6.report.md | 89 +++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 lanes/part32-r6.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 985cbb54..8e67a1a7 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -7007,6 +7007,18 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } if part16 == PARTITION_VERT_B { VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1)); + // lane-part32 r6: same availability + // defect r5 fixed one level up -- + // the TR/BR 8x8 squares below are + // visited out of raster order, so + // they need libaom's + // `has_tr_vert_*`/`has_bl_vert_*` + // tables (the left 8x16 rect goes + // through `Reach::of_rect`, which + // the guard deliberately does not + // affect). + let _vert_ab = + crate::encode::Reach::vert_ab_partition(); // Left rect: 8x16, real // `decode_block_rect`, sat at the // 16x16 parent's own origin (no diff --git a/crates/ec-av1/src/encode.rs b/crates/ec-av1/src/encode.rs index 140e528b..796b1813 100644 --- a/crates/ec-av1/src/encode.rs +++ b/crates/ec-av1/src/encode.rs @@ -3550,6 +3550,45 @@ mod tests { } } + /// lane-part32 r6: inside a `PARTITION_VERT_A`/`_B` the 8x8 squares are + /// visited TL, BL, TR, BR, so the TR square (even 8x8 row, odd 8x8 + /// column inside the superblock) may read the below-left samples the + /// raster table forbids: `has_bl_8x8` is 0 at exactly those 16 slots + /// where `has_bl_vert_8x8` is 1. Pinned here because no aomenc recipe + /// swept in r6 produced a decodable 16x16-level VERT_B stream (every + /// stream that partitions that small first hits the still-refused + /// HORZ_A/HORZ_B/VERT_A-below-16 or coded-rect-strip-below-16 arms). + #[test] + fn vert_ab_partition_flips_below_left_for_the_top_right_8x8() { + let (width, height) = (SUPERBLOCK * 3, SUPERBLOCK * 3); + // Interior superblock, so neither the frame edge nor the col == 0 / + // last-row early returns answer instead of the table. + let (sb_x, sb_y) = (SUPERBLOCK, SUPERBLOCK); + let mut flipped = 0; + for row in 0..8 { + for col in 1..8 { + let (x, y) = (sb_x + col * 8, sb_y + row * 8); + let raster = Reach::of(8, x, y, width, height).below_left; + let vert = { + let _guard = Reach::vert_ab_partition(); + Reach::of(8, x, y, width, height).below_left + }; + // The TR square of a VERT_A/_B sits at an even row, odd + // column; every other slot must be untouched by the guard. + if row % 2 == 0 && col % 2 == 1 { + assert!(!raster, "raster below_left at row={row} col={col}"); + assert!(vert, "vert below_left at row={row} col={col}"); + flipped += 1; + } else { + assert_eq!(raster, vert, "guard moved row={row} col={col}"); + } + } + } + assert_eq!(flipped, 4 * 4, "expected the 16 8x8 TR slots to flip"); + // The guard is scoped: it must not leak past its own block. + assert!(!Reach::of(8, sb_x + 8, sb_y, width, height).below_left); + } + /// An odd width or height is refused by name, not by however the padder /// or the block coder would happen to fail on it. #[test] diff --git a/lanes/part32-r6.report.md b/lanes/part32-r6.report.md new file mode 100644 index 00000000..7413ca05 --- /dev/null +++ b/lanes/part32-r6.report.md @@ -0,0 +1,89 @@ +# lane-part32 r6 — the 16x16-level VERT_B arm was the one AB site r5 missed + +Branch `lane-part32`, on top of r5 `02dbbd6`. + +## Class sweep: every VERT_A/VERT_B site in decode.rs + +`grep -n "PARTITION_VERT_A\|PARTITION_VERT_B" crates/ec-av1/src/decode.rs`, all +levels, intra and inter: + +| site | level | path | guard at r5 | +|---|---|---|---| +| `decode.rs:7008` | 16 | intra VERT_B (8x16 rect + TR/BR 8x8 `decode_leaf8`) | **MISSING — fixed this round** | +| `decode.rs:7538/7612` | 32 | intra VERT_A / VERT_B | present (r5) | +| `decode.rs:7779` | 64 (SB) | AB arm, vert arms only | present (r5) | +| `decode.rs:13445/13606` | 32 | inter VERT_A / VERT_B | present (r5) | + +No other site exists: the 16-level inter path has no AB arms (they are refused by +name, "a HORZ_A/HORZ_B/VERT_A partition below 16x16"), and 8-level partitions +below that are SPLIT-only. So one missed site, now guarded — the class is closed +for VERT_A/_B. + +The verifier's computation is confirmed exactly (checked bit by bit against the +transcribed tables in `encode.rs`): `has_bl_8x8` reads **0** where +`has_bl_vert_8x8` reads **1** at all 16 even-8x8-row / odd-8x8-column slots of a +superblock — that slot is precisely the TR square of a VERT_A/_B — so the TR +square's `below_left` was wrongly false for the bottom-left-reading directional +modes (angle > 180: `D203_PRED`, `D157_PRED` with a positive angle delta). +Mirror-image for `has_tr_8x8` vs `has_tr_vert_8x8` (1 -> 0) at odd-row / +even-column slots, which VERT_A/_B never visit at 8x8 (no BL square in either). + +## Files changed + +- `crates/ec-av1/src/decode.rs:7010` — the intra 16-level `PARTITION_VERT_B` arm + takes `crate::encode::Reach::vert_ab_partition()` for the whole arm; the left + 8x16 rect is unaffected by design (`Reach::of_rect`, libaom's own comment says + vertical rectangles keep the non-vert table), the two `decode_leaf8` squares + now read the vert tables. +- `crates/ec-av1/src/encode.rs:3565` — `vert_ab_partition_flips_below_left_for_the_top_right_8x8`, + a table pin next to the existing libaom-availability test: all 16 TR slots flip + `below_left` false -> true under the guard, every other slot is untouched, and + the guard does not leak past its scope. + +## Gate: attempted, could not be built — the fix stays source-verified + +The charter's stream gate (a real-aomenc 16-level VERT_B, directional modes on, +decoded and compared pixel-exact) was written and run, and it cannot fire on this +aomenc build. Bounded sweep, all with +`--min-partition-size=8 --max-partition-size=16 --enable-rect-partitions=1 +--enable-1to4-partitions=0 --enable-directional-intra=1 --enable-angle-delta=1 +--cpu-used=0 --kf-max-dist=0 --passes=1`, 64x64 grey mandelbrot key frames: + +| recipe | attempts | decoded | refusals | +|---|---|---|---| +| cq=45, `--enable-ab-partitions=1` | 40 | 0 | 40 (below-16 HORZ_A/HORZ_B/VERT_A, or a coded non-skip rect strip below 16) | +| cq=45, ab={0,1} | 10 + 10 | 0 | 8 AB-below-16 + 2 coded-rect-strip, each | +| cq=63, ab={0,1} | 40 + 10 | all | none — but `partition_w16` never resolves to VERT_B (value=7): the frame stays at 16x16 NONE | +| cq={55,57,60}, mandelbrot / testsrc2 / cellauto | 12 | 3 | same two below-16 refusals | + +`EC_AV1_TRACE=1` `partition_w16` value histogram over every decoded stream: 0 +occurrences of value=7 at any quality that decodes. Every stream that partitions +small enough to *reach* a 16-level VERT_B hits one of the two still-refused +below-16 capabilities first (HORZ_A/HORZ_B/VERT_A-below-16, coded rect strip +below-16), which abort the tile before the VERT_B arm. Writing a gate that +decodes only cq=63 streams would have been vacuous +(`gate-blind-to-feature`), so the sweep gate was **removed** rather than +committed green, and the pin above carries the fix instead. + +EVIDENCE: /tmp/.../scratchpad (r6 sweep, shell loop above) | 40+40+20+12 real aomenc encodes, `EC_AV1_TRACE=1 decode_probe` on each | 0 streams with `partition_w16 value=7`; at cq=45 40/40 refused with the two named below-16 refusals, at cq=63 50/50 decoded with 0 VERT_B + +EVIDENCE: `cargo test -p ec-av1 --lib -- vert_ab_partition_flips` | table pin of the guard at all 64 8x8 slots of an interior superblock | `test result: ok. 1 passed`; 16 TR slots flip false->true, 48 unchanged + +EVIDENCE: /tmp/.../scratchpad/r6full.txt | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` | `test result: ok. 270 passed; 0 failed; 24 ignored; 0 measured` in 1585s (269 before this round's new pin) + +## Refusals + +None lifted or added this round (the two below-16 refusals above are other +lanes'). `refusal_inventory` and `gate_coverage` unchanged and green in the run +above. + +## Residue + +- deferred(a lane that ports HORZ_A/HORZ_B/VERT_A below 16x16, or the coded + non-skip rect strip below 16x16): the pixel-exact stream gate for the 16-level + VERT_B arm. Both refusals fire before the arm on every recipe swept; once + either lands, re-run the sweep in this report and the gate becomes writable + as-is. +- accepted: the fix is source-verified + table-pinned, not stream-proven. It is a + one-bit availability change of exactly the shape r5 proved by pixel comparison + one level up (4683 wrong luma samples there).