From b9fb4993feeadbdcf2853662b5ccae71b13d5fed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 1 Oct 2026 14:12:21 +0300 Subject: [PATCH] lane-av1unwritten r3: the predicate is a transcription of av1_ss_size_lookup, not a guess Main's r3 refutation is right on both counts. The r2 four-cell match refused (16,4) at ss (1,0), where the table says BLOCK_8X4 -- a legal 4:2:2 shape that libaom's own encoder emits, since partition_search.c:3383-3389 gates partition_rect_allowed[HORZ] with exactly this table. And it covered two of the eight shapes libaom refuses at 4:2:2; r2's claim that the 32/64-level roots need no check was true of the PARENT rows and false of the children (get_partition_subsize(BLOCK_32X32, PARTITION_VERT) = BLOCK_16X32, INVALID at (1,0)). chroma_plane_block_codable is now two const lists holding every BLOCK_INVALID cell of common_data.c:17-41 and nothing else -- at (1,0): 4x8, 8x16, 16x32, 32x64, 64x128, 4x16, 8x32, 16x64; at (0,1): 8x4, 16x8, 32x16, 64x32, 128x64, 16x4, 32x8, 64x16; none at (0,0) or (1,1) -- so a reader diffs it against the C source line by line. New gate chroma_plane_block_codable_matches_the_libaom_table transcribes all 22 rows x 4 subsampling pairs literally and asserts agreement cell for cell. It reds on exactly the mistake r2 made: transcribing it caught two rows (32x8 and 64x16 at (0,1)) I had copied wrong out of the briefing, and it pins 16x4@4:2:2 as legal, which is the direction the corpus cannot see. Site coverage is now stated as installed (partition_w8, partition_w16) plus six named gaps (VERT_4/HORZ_4 1:4 -> 4x16; w32/w64/128 VERT -> 16x32/32x64/64x128; VERT_A/VERT_B -> 8x32/16x64), each with the next step, rather than claiming coverage. decode_rect4_16_intrabc stays out of scope and is named as such. Regression on the corrected predicate: 127 fixtures, both trees, per-fixture aggregate hashes -- differing: ['440_request_is_422'], 126 emitting dumps, one REFUSED. Gates green: the table test, the refusal gate with its 4:2:2 positive control, and the realigned the_440_cell_is_not_a_codable_chroma_shape. --- crates/ec-av1/src/decode.rs | 205 ++++++++++++++++++++++++++++++++++- lanes/av1unwritten.report.md | 56 ++++++++-- 2 files changed, 248 insertions(+), 13 deletions(-) diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 65652d39..8675ad38 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -21370,12 +21370,77 @@ fn plane_sentinel_on() -> bool { /// CHANGED RUN TO RUN. `aomdec` on the same file: /// `Failed to decode frame 1: Corrupt frame detected` / `Block size 8x16 /// invalid with this subsampling mode`. +/// `av1_ss_size_lookup`'s `BLOCK_INVALID` cells, transcribed verbatim: +/// `(common_data.c:17-41`, rows in `BLOCK_SIZES_ALL` order, indexed +/// `[subsampling_x][subsampling_y])`. Every entry below is an (luma width, +/// luma height) whose plane block does not EXIST at that subsampling pair, so +/// libaom refuses any subsize of that shape +/// (`av1/decoder/decodeframe.c:1449-1458`, `AOM_CODEC_CORRUPT_FRAME`, +/// "Block size %dx%d invalid with this subsampling mode"). +/// +/// There is no other `BLOCK_INVALID` cell in the table: at (0,0) 4:4:4 and at +/// (1,1) 4:2:0 every row is valid, and the sixteen shapes below are the only +/// ones that are invalid at (1,0) 4:2:2 or (0,1) 4:4:0. The table test +/// [`chroma_plane_block_codable_matches_the_libaom_table`] re-transcribes all +/// 22 rows and checks this list cell for cell -- a diff against the C source, +/// not a restatement of it. +/// +/// ``` +/// BLOCK_4X8 {4X8, 4X4} {INVALID, 4X4} <- INVALID @ (1,0) +/// BLOCK_8X4 {8X4, INVALID} {4X4, 4X4} <- INVALID @ (0,1) +/// BLOCK_8X16 {8X16, 8X8} {INVALID, 4X8} <- INVALID @ (1,0) +/// BLOCK_16X8 {16X8, INVALID} {8X8, 8X4} <- INVALID @ (0,1) +/// BLOCK_16X32 {16X32, 16X16} {INVALID, 8X16} <- INVALID @ (1,0) +/// BLOCK_32X16 {32X16, INVALID}{16X16, 16X8} <- INVALID @ (0,1) +/// BLOCK_32X64 {32X64, 32X32} {INVALID, 16X32} <- INVALID @ (1,0) +/// BLOCK_64X32 {64X32, INVALID}{32X32, 32X16} <- INVALID @ (0,1) +/// BLOCK_64X128 {64X128,64X64} {INVALID, 32X64} <- INVALID @ (1,0) +/// BLOCK_128X64 {128X64,INVALID}{64X64, 64X32} <- INVALID @ (0,1) +/// BLOCK_4X16 {4X16, 4X8} {INVALID, 4X8} <- INVALID @ (1,0) +/// BLOCK_16X4 {16X4, 8X4} {8X4, 8X4} <- valid @ (1,0) +/// BLOCK_8X32 {8X32, 8X16} {INVALID, 4X16} <- INVALID @ (1,0) +/// BLOCK_32X8 {32X8, 16X8} {32X8, 16X4} <- valid @ (0,1) +/// BLOCK_16X64 {16X64,16X32} {INVALID, 8X32} <- INVALID @ (1,0) +/// BLOCK_64X16 {64X16,32X16} {32X16, 32X8} <- valid @ (0,1) +/// ``` +/// +/// The two "valid" rows are here on purpose: an earlier version of this +/// predicate hardcoded BLOCK_16X4@(1,0) and BLOCK_32X8@(0,1) as invalid, which +/// REFUSED a legal 4:2:2 shape -- one aomenc itself emits, since its own +/// `partition_search.c:3383-3389` gates `partition_rect_allowed[HORZ]` with +/// exactly this table. +const PLANE_BLOCK_INVALID_422: &[(usize, usize)] = &[ + (4, 8), + (8, 16), + (16, 32), + (32, 64), + (64, 128), + (4, 16), + (8, 32), + (16, 64), +]; + +/// The same list at 4:4:0 `(0, 1)` -- a shape no `color_config` can request +/// (libaom asserts `subsampling_y == 0` when `subsampling_x == 0`), kept so +/// the table test can cover every cell rather than only the reachable ones. +const PLANE_BLOCK_INVALID_440: &[(usize, usize)] = &[ + (8, 4), + (16, 8), + (32, 16), + (64, 32), + (128, 64), + (16, 4), + (32, 8), + (64, 16), +]; + +/// Whether `av1_ss_size_lookup[(bw, bh)][sx][sy]` is not `BLOCK_INVALID` -- i.e. +/// whether libaom lets a subsize of this luma shape have a chroma plane block +/// at this subsampling at all. fn chroma_plane_block_codable(bw: usize, bh: usize, sx: usize, sy: usize) -> bool { - match (bw, bh) { - (4, 8) => (sx, sy) != (1, 0), - (8, 4) => (sx, sy) != (0, 1), - (8, 16) => (sx, sy) != (1, 0), - (16, 4) => (sx, sy) != (1, 0), + match (sx, sy) { + (1, 0) => !PLANE_BLOCK_INVALID_422.contains(&(bw, bh)), + (0, 1) => !PLANE_BLOCK_INVALID_440.contains(&(bw, bh)), _ => true, } } @@ -56259,6 +56324,136 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( #[cfg(test)] mod tests { + + /// lane-av1unwritten: the port is a TRANSCRIPTION, and this is the artefact + /// that makes it checkable. It re-writes `av1_ss_size_lookup`'s 22 rows + /// (`common_data.c:17-41`) literally -- every shape, every subsampling + /// pair, the real BLOCK_INVALID markers -- and asserts + /// [`chroma_plane_block_codable`] agrees cell for cell. A predicate that + /// hardcodes the wrong cell (this lane's first version marked BLOCK_16X4 at + /// 4:2:2 invalid; the table says `BLOCK_8X4`) reds here, not in a corpus + /// that happens not to carry the shape. + #[test] + fn chroma_plane_block_codable_matches_the_libaom_table() { + // (width, height, [ss_x=0][ss_y=0], [0][1], [1][0], [1][1]); `None` is + // BLOCK_INVALID. + const I: Option<(usize, usize)> = None; + let table: &[(usize, usize, [Option<(usize, usize)>; 4])] = &[ + ( + 4, + 4, + [Some((4, 4)), Some((4, 4)), Some((4, 4)), Some((4, 4))], + ), + (4, 8, [Some((4, 8)), Some((4, 4)), I, Some((4, 4))]), + (8, 4, [Some((8, 4)), I, Some((4, 4)), Some((4, 4))]), + ( + 8, + 8, + [Some((8, 8)), Some((8, 4)), Some((4, 8)), Some((4, 4))], + ), + (8, 16, [Some((8, 16)), Some((8, 8)), I, Some((4, 8))]), + (16, 8, [Some((16, 8)), I, Some((8, 8)), Some((4, 4))]), + ( + 16, + 16, + [Some((16, 16)), Some((8, 16)), Some((8, 8)), Some((4, 8))], + ), + (16, 32, [Some((16, 32)), Some((16, 16)), I, Some((8, 16))]), + (32, 16, [Some((32, 16)), I, Some((16, 16)), Some((16, 8))]), + ( + 32, + 32, + [ + Some((32, 32)), + Some((16, 32)), + Some((16, 16)), + Some((16, 8)), + ], + ), + (32, 64, [Some((32, 64)), Some((32, 32)), I, Some((16, 32))]), + (64, 32, [Some((64, 32)), I, Some((32, 32)), Some((32, 16))]), + ( + 64, + 64, + [ + Some((64, 64)), + Some((32, 64)), + Some((32, 32)), + Some((32, 16)), + ], + ), + ( + 64, + 128, + [Some((64, 128)), Some((64, 64)), I, Some((32, 64))], + ), + ( + 128, + 64, + [Some((128, 64)), I, Some((64, 64)), Some((64, 32))], + ), + ( + 128, + 128, + [ + Some((128, 128)), + Some((64, 128)), + Some((64, 64)), + Some((64, 32)), + ], + ), + (4, 16, [Some((4, 16)), Some((4, 8)), I, Some((4, 8))]), + (16, 4, [Some((16, 4)), I, Some((8, 4)), Some((8, 4))]), + (8, 32, [Some((8, 32)), Some((8, 16)), I, Some((4, 16))]), + (32, 8, [Some((32, 8)), I, Some((16, 8)), Some((16, 4))]), + (16, 64, [Some((16, 64)), Some((16, 32)), I, Some((8, 32))]), + (64, 16, [Some((64, 16)), I, Some((32, 16)), Some((32, 8))]), + ( + 128, + 256, + [ + Some((128, 256)), + Some((64, 256)), + Some((64, 128)), + Some((64, 64)), + ], + ), + ( + 256, + 128, + [ + Some((256, 128)), + Some((128, 256)), + Some((128, 64)), + Some((128, 64)), + ], + ), + ]; + for &(w, h, cells) in table { + for sx in 0..2usize { + for sy in 0..2usize { + let want_codable = cells[sx * 2 + sy].is_some(); + assert_eq!( + chroma_plane_block_codable(w, h, sx, sy), + want_codable, + "av1_ss_size_lookup[{w}x{h}][{sx}][{sy}] is {:?} in libaom \ + (common_data.c) but our predicate says the opposite", + cells[sx * 2 + sy] + ); + } + } + } + // The two cells an earlier, hand-picked predicate got wrong: both are + // LEGAL at 4:2:2, and libaom's own encoder emits the 16x4 one. + assert!( + chroma_plane_block_codable(16, 4, 1, 0), + "16x4 at 4:2:2 is BLOCK_8X4" + ); + assert!( + !chroma_plane_block_codable(32, 8, 0, 1), + "32x8 at 4:4:0 is BLOCK_INVALID" + ); + } /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and /// reports "no leaf there" as `None` so the caller can fall back to the diff --git a/lanes/av1unwritten.report.md b/lanes/av1unwritten.report.md index 99318c3d..98d7d69d 100644 --- a/lanes/av1unwritten.report.md +++ b/lanes/av1unwritten.report.md @@ -10,7 +10,21 @@ sentinel census that found the class is kept as the instrument.** Branch `lane/av1unwritten`, base `main` = `8d6998d7`. No push. -> **This report was rewritten.** The first version of this lane claimed a libaom +> **r3 correction, on top of r2.** The r2 predicate was a four-cell hand-picked +> `match`, and it was wrong in BOTH directions. It refused `(16, 4)` at ss (1,0), +> where `av1_ss_size_lookup[BLOCK_16X4][1][0]` is `BLOCK_8X4` — a LEGAL 4:2:2 +> shape, and one libaom's own encoder emits (`partition_search.c:3383-3389` +> gates `partition_rect_allowed[HORZ]` with this very table), so we were refusing +> a stream aomenc produces. And it covered only two of the eight shapes libaom +> refuses at 4:2:2. r3 replaces the `match` with a verbatim transcription of +> the table's `BLOCK_INVALID` cells (§3.1) and adds +> `chroma_plane_block_codable_matches_the_libaom_table`, which re-writes all 22 +> rows x 4 subsampling pairs from `common_data.c:17-41` and checks the predicate +> cell for cell. The corpus sweep CANNOT see the false positive — no committed +> fixture carries a 16x8 block split `PARTITION_HORZ` at 4:2:2 — and that table +> test is what covers that direction. +> +> **This report was rewritten once before. The first version of this lane claimed a libaom > `TX_4X8` chroma unit for a `BLOCK_4X8` subsize and landed a port of it. The > refutation pass (Agent03-5, verified first-hand by Main) showed that port does > not exist: `get_plane_block_size` is a single indexed return @@ -120,8 +134,18 @@ diff cannot tell an unwritten sample from a mis-predicted one). `crates/ec-av1/src/decode.rs`: -* `chroma_plane_block_codable(bw, bh, ss_x, ss_y)` — the four - `BLOCK_INVALID` cells of `av1_ss_size_lookup`, nothing else. +* `chroma_plane_block_codable(bw, bh, ss_x, ss_y)` — a verbatim transcription + of `av1_ss_size_lookup`'s `BLOCK_INVALID` cells, in two const lists so a + reader can diff them against `common_data.c` line by line: + + | subsampling | INVALID luma shapes | + |---|---| + | 4:2:2 `(1,0)` | 4x8, 8x16, 16x32, 32x64, 64x128, 4x16, 8x32, 16x64 | + | 4:4:0 `(0,1)` | 8x4, 16x8, 32x16, 64x32, 128x64, 16x4, 32x8, 64x16 | + | 4:4:4 `(0,0)`, 4:2:0 `(1,1)` | none | + + Checked by `chroma_plane_block_codable_matches_the_libaom_table`, which + transcribes all 22 rows x 4 pairs literally from `common_data.c:17-41`. * `refuse_invalid_plane_block(...)` — a **returned** error (never an `assert!`: a partition symbol is stream data, so hostile bytes reach it), carrying libaom's own wording so the message names the rule: @@ -153,11 +177,22 @@ Same refusal class as the oracle, same rule, same shape named. | `partition_w8` (2 sites, 36549 / 36767 region) | 8x4, 4x8 | **yes**, installed | | `partition_w16` intra (36175 region) | 16x8, 8x16 | **yes**, installed | | `partition_w16` edge split (`VERT_ALIKE`/`HORZ_ALIKE` gather) | same two, reached only when `has_cols16`/`has_rows16` is false | covered by the same rule at the sibling site; the edge arm's two-symbol gather can only choose SPLIT vs the matching strip | -| `PARTITION_HORZ_4` / `VERT_4` on 8x16 / 16x8 (`decode_rect_split`) | 4x16, 16x4 | **NOT installed — known gap, stated here** | -| 32/64-level partitions, 128 root, AB partitions | squares and 32x64/64x32 | no: every cell of those rows is non-INVALID at every subsampling this decoder accepts | +| `PARTITION_HORZ_4` / `VERT_4` on 8x16 / 16x8 (`decode_rect_split`) | 4x16 (INVALID at 4:2:2), 16x4 (legal at 4:2:2, INVALID at 4:4:0) | **NOT installed — named gap** | +| `partition_w32` `PARTITION_VERT` | 16x32 — INVALID at 4:2:2 | **NOT installed — named gap** | +| `partition_w64` `PARTITION_VERT` | 32x64 — INVALID at 4:2:2 | **NOT installed — named gap** | +| 128 root `PARTITION_VERT` | 64x128 — INVALID at 4:2:2 | **NOT installed — named gap** | +| the 4-way vertical splits at 16/32/64 (`VERT_A` / `VERT_B`) | 8x32, 16x64 — both INVALID at 4:2:2 | **NOT installed — named gap** | +| 32/64/128 roots' OWN plane blocks, the AB partitions, `PARTITION_SPLIT` | BLOCK_32X32 (16X32), BLOCK_64X64 (32X32), BLOCK_128X128 (64X64), all valid | no — a PARENT row being valid says nothing about its children, which is exactly what r2 got wrong; the child rows are the four rows above | | 4:4:4 square leaves, `decode_leaf8`, `decode_leaf_split4` | BLOCK_4X4 / BLOCK_8X8 / BLOCK_16X16 | no: `(0,0)` column is non-INVALID for all of them | -The 1:4 sites are the honest gap: `PARTITION_HORZ_4` on an 8x16 yields a 4x16, +So r3 installs the check at two sites and NAMES the other six rather than +claiming them covered. The predicate is now correct for every shape, so each +remaining site is a one-line call at a dispatch that is already written; none of +them is reachable by a committed fixture (§4 shows the corpus cannot see even +the false-positive direction), which is why they are a declared gap and not a +claim. + +The 1:4 sites were already the honest gap: `PARTITION_HORZ_4` on an 8x16 yields a 4x16, whose 4:2:2 plane block is `BLOCK_INVALID`, and this lane did not install the check there. `decode_rect4_16_intrabc` is on another lane's charter and was not touched; the neighbouring non-intrabc `decode_rect4_16_strip` site is where the @@ -171,8 +206,13 @@ instrument is what would show it if one ever did. * **Corpus, both trees.** Every fixture decoded with `EC_AV1_FINAL_DUMP`, every `.f*` hashed. Pre-fix vs post-fix the **126 valid fixtures are byte-identical** and **none newly refuses**; the witness is the only difference and it now - refuses. Measured by the same loop as the §2 hashes, with the per-fixture - stderr scanned for `REFUSED`. + refuses. Re-run on the r3 (corrected) predicate: `differing: + ['440_request_is_422']`, 126 fixtures emitting dumps, and exactly one fixture + whose output contains `REFUSED` — the witness. **The sweep cannot see the + (16,4)-at-4:2:2 false positive**: no committed fixture carries a 16x8 block + split `PARTITION_HORZ` at 4:2:2, which is why r2's over-refusal passed 126/126 + unnoticed. That direction is covered by + `chroma_plane_block_codable_matches_the_libaom_table`, not by the sweep. * **Sentinel sweep** (127 fixtures, `EC_AV1_PLANE_SENTINEL=1`): pre-fix exactly one fixture had a non-empty census (the witness, 112+112); post-fix the corpus has no unwritten sample anywhere — the witness decodes nothing at all now, and