A transform unit is not a block of its own size -- Reach::of_tu
Browse files at this commit85bf4d6aa637fe97d12348aa6f2ee35a34025df6Parent: 95d8523- fix
- a transform unit is not a block of its own size -- Reach::of_tu
4 changed files +301 -15
- crates/ec-av1/src/decode.rs +17 -2
- crates/ec-av1/src/encode.rs +88 -0
- crates/ec-av1/src/stream.rs +80 -13
- lanes/ab16-r2.report.md +116 -0
crates/ec-av1/src/decode.rsmodified+17 -2
| @@ -423,6 +423,18 @@ thread_local! { | ||
| 423 | 423 | } |
| 424 | 424 | |
| 425 | 425 | /// [`AB16_HITS`] per arm (HORZ_A, HORZ_B, VERT_A, VERT_B at 16x16). |
| 426 | +thread_local! { | |
| 427 | + /// 4x4 transform units decoded inside an 8x8 square of a | |
| 428 | + /// `PARTITION_VERT_A`/`_B` -- the exact call that panicked before | |
| 429 | + /// [`crate::encode::Reach::of_tu`] (lane-ab16 r2), so the gate can prove | |
| 430 | + /// a real `--enable-tx-size-search=1` stream reaches it. | |
| 431 | + static VERT_AB_TX4_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 432 | +} | |
| 433 | + | |
| 434 | +pub(crate) fn vert_ab_tx4_hits() -> usize { | |
| 435 | + VERT_AB_TX4_HITS.with(std::cell::Cell::get) | |
| 436 | +} | |
| 437 | + | |
| 426 | 438 | pub(crate) fn ab16_hits_by_arm() -> [usize; 4] { |
| 427 | 439 | AB16_HITS.with(std::cell::Cell::get) |
| 428 | 440 | } |
| @@ -5209,7 +5221,7 @@ fn decode_block( | ||
| 5209 | 5221 | let tu_px = px + tu_col * logical_tx; |
| 5210 | 5222 | let tu_py = py + tu_row * logical_tx; |
| 5211 | 5223 | let tu_around = neighbours.around_mi(tu_mi, logical_tx)[0]; |
| 5212 | - let tu_reach = Reach::of(logical_tx, tu_px, tu_py, y.width, y.height); | |
| 5224 | + let tu_reach = Reach::of_tu(side, logical_tx, tu_px, tu_py, y.width, y.height); | |
| 5213 | 5225 | // This transform unit's own bsize (`logical_tx`) is smaller |
| 5214 | 5226 | // than the block it sits in (`side`), so `txb_skip_ctx` is |
| 5215 | 5227 | // the neighbour-magnitude table, not the lone-TU 0 (spec |
| @@ -5581,7 +5593,10 @@ fn decode_leaf8( | ||
| 5581 | 5593 | let tu_px = px + tu_col * 4; |
| 5582 | 5594 | let tu_py = py + tu_row * 4; |
| 5583 | 5595 | let tu_around = neighbours.around_mi(tu_mi, 4)[0]; |
| 5584 | - let tu_reach = Reach::of(4, tu_px, tu_py, y.width, y.height); | |
| 5596 | + if crate::encode::Reach::in_vert_ab() { | |
| 5597 | + VERT_AB_TX4_HITS.with(|c| c.set(c.get() + 1)); | |
| 5598 | + } | |
| 5599 | + let tu_reach = Reach::of_tu(8, 4, tu_px, tu_py, y.width, y.height); | |
| 5585 | 5600 | let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1); |
| 5586 | 5601 | let tu_grid = read_plane( |
| 5587 | 5602 | dec, |
crates/ec-av1/src/encode.rsmodified+88 -0
| @@ -1192,6 +1192,39 @@ impl Reach { | ||
| 1192 | 1192 | } |
| 1193 | 1193 | } |
| 1194 | 1194 | |
| 1195 | + /// [`Self::of`] for one transform unit of a square block whose transform | |
| 1196 | + /// is smaller than itself (libaom `has_top_right`/`has_bottom_left` with | |
| 1197 | + /// non-zero `row_off`/`col_off`): interior units answer from the block's | |
| 1198 | + /// own geometry, and only a unit on the block's top row (resp. left | |
| 1199 | + /// column) reaches the table -- which is the BLOCK's table read at the | |
| 1200 | + /// BLOCK's position, never a table row for the transform's size. Letting | |
| 1201 | + /// the unit stand in for a block of its own size agrees with libaom for | |
| 1202 | + /// the ordinary tables, but the `has_tr_vert_*`/`has_bl_vert_*` pair has | |
| 1203 | + /// no 4x4 row at all (`has_tr_vert_tables[BLOCK_4X4]` is NULL), so a TX4 | |
| 1204 | + /// unit inside an 8x8 square of a `PARTITION_VERT_A`/`_B` panicked on a | |
| 1205 | + /// real `--enable-tx-size-search=1` stream (lane-ab16 r2). | |
| 1206 | + pub(crate) fn of_tu( | |
| 1207 | + block: usize, | |
| 1208 | + tx: usize, | |
| 1209 | + x: usize, | |
| 1210 | + y: usize, | |
| 1211 | + width: usize, | |
| 1212 | + height: usize, | |
| 1213 | + ) -> Self { | |
| 1214 | + let (row_off, col_off) = ((y % block) / tx, (x % block) / tx); | |
| 1215 | + let n = block / tx; | |
| 1216 | + let (bx, by) = (x - col_off * tx, y - row_off * tx); | |
| 1217 | + Self { | |
| 1218 | + above_right: y > 0 | |
| 1219 | + && x + tx < width | |
| 1220 | + && (col_off + 1 < n || (row_off == 0 && Self::top_right(block, bx, by))), | |
| 1221 | + below_left: x > 0 | |
| 1222 | + && y + tx < height | |
| 1223 | + && col_off == 0 | |
| 1224 | + && (row_off + 1 < n || Self::bottom_left(block, bx, by)), | |
| 1225 | + } | |
| 1226 | + } | |
| 1227 | + | |
| 1195 | 1228 | /// libaom `has_top_right` at block granularity (`row_off`/`col_off` 0, |
| 1196 | 1229 | /// the transform covering the whole block, luma): everything before the |
| 1197 | 1230 | /// table lookup is that function's own early-exit ladder. |
| @@ -1249,6 +1282,13 @@ impl Reach { | ||
| 1249 | 1282 | VertAbGuard(VERT_AB_PARTITION.with(|c| c.replace(true))) |
| 1250 | 1283 | } |
| 1251 | 1284 | |
| 1285 | + /// Whether a `PARTITION_VERT_A`/`_B`'s sub-blocks are being decoded | |
| 1286 | + /// right now ([`Self::vert_ab_partition`]'s guard is alive), so a caller | |
| 1287 | + /// can count the sub-block work that partition creates. | |
| 1288 | + pub(crate) fn in_vert_ab() -> bool { | |
| 1289 | + VERT_AB_PARTITION.with(std::cell::Cell::get) | |
| 1290 | + } | |
| 1291 | + | |
| 1252 | 1292 | /// Neither, which is all a mode that reads no further than its own edges |
| 1253 | 1293 | /// needs. |
| 1254 | 1294 | pub(crate) fn none() -> Self { |
| @@ -3537,6 +3577,54 @@ mod tests { | ||
| 3537 | 3577 | assert_eq!(decoded.v, encoded.reconstruction.v, "854x480: V"); |
| 3538 | 3578 | } |
| 3539 | 3579 | |
| 3580 | + /// [`Reach::of_tu`] against libaom's `has_top_right`/`has_bottom_left` | |
| 3581 | + /// transform-unit path, for every 4x4 unit of every 8x8 block of a | |
| 3582 | + /// superblock, both partition tables: | |
| 3583 | + /// | |
| 3584 | + /// 1. outside a `PARTITION_VERT_A`/`_B` it must answer exactly what the | |
| 3585 | + /// unit-as-its-own-block `Reach::of(4, ..)` answered before r2, so | |
| 3586 | + /// wiring the TU sites onto it changes no existing stream; | |
| 3587 | + /// 2. inside one it must not panic -- `has_tr_vert_tables[BLOCK_4X4]` is | |
| 3588 | + /// NULL in libaom because that lookup never happens, and reading a | |
| 3589 | + /// 4x4 row out of the three-row vert tables is what crashed a real | |
| 3590 | + /// `--enable-tx-size-search=1` stream (r2); | |
| 3591 | + /// 3. and it must be the BLOCK's vert answer where the two tables | |
| 3592 | + /// disagree: the top-right 4x4 unit of the 8x8 block at superblock | |
| 3593 | + /// row 1, column 0 reads its above-right samples from the 8x8 to its | |
| 3594 | + /// upper right, which a vertical AB partition codes AFTER it | |
| 3595 | + /// (`has_tr_vert_8x8` bit 16 = 0, ordinary `has_tr_8x8` bit 16 = 1). | |
| 3596 | + #[test] | |
| 3597 | + fn of_tu_keeps_the_ordinary_answer_and_uses_the_block_row_under_vert_ab() { | |
| 3598 | + let (w, h) = (SUPERBLOCK * 2, SUPERBLOCK * 2); | |
| 3599 | + for y in (0..h).step_by(4) { | |
| 3600 | + for x in (0..w).step_by(4) { | |
| 3601 | + let tu = Reach::of_tu(8, 4, x, y, w, h); | |
| 3602 | + let as_block = Reach::of(4, x, y, w, h); | |
| 3603 | + assert_eq!( | |
| 3604 | + (tu.above_right, tu.below_left), | |
| 3605 | + (as_block.above_right, as_block.below_left), | |
| 3606 | + "of_tu(8, 4) at ({x}, {y}) differs from the unit-as-block answer" | |
| 3607 | + ); | |
| 3608 | + // (2): under the vert tables the same lookup must answer at | |
| 3609 | + // all rather than index a row that does not exist. | |
| 3610 | + let _guard = Reach::vert_ab_partition(); | |
| 3611 | + let _ = Reach::of_tu(8, 4, x, y, w, h); | |
| 3612 | + } | |
| 3613 | + } | |
| 3614 | + // (3): the disagreeing cell, both ways round. | |
| 3615 | + let (x, y) = (4, 8); | |
| 3616 | + assert!( | |
| 3617 | + Reach::of_tu(8, 4, x, y, SUPERBLOCK, SUPERBLOCK).above_right, | |
| 3618 | + "ordinary table: the 8x8 above-right of the block at sb row 1 col 0 is coded first" | |
| 3619 | + ); | |
| 3620 | + let guard = Reach::vert_ab_partition(); | |
| 3621 | + assert!( | |
| 3622 | + !Reach::of_tu(8, 4, x, y, SUPERBLOCK, SUPERBLOCK).above_right, | |
| 3623 | + "vert AB: that 8x8 is the partition's own later-coded right half" | |
| 3624 | + ); | |
| 3625 | + drop(guard); | |
| 3626 | + } | |
| 3627 | + | |
| 3540 | 3628 | /// `Reach::top_right`/`bottom_left` against a from-scratch transcription |
| 3541 | 3629 | /// of libaom's `has_top_right`/`has_bottom_left` (`av1/common/ |
| 3542 | 3630 | /// reconintra.c`), for every 16x16 and 32x32 block position across three |
crates/ec-av1/src/stream.rsmodified+80 -13
| @@ -5470,9 +5470,11 @@ mod tests { | ||
| 5470 | 5470 | /// attempt and summed only over attempts that actually decoded AND were |
| 5471 | 5471 | /// compared, and EACH of the four arms must have fired -- a run where |
| 5472 | 5472 | /// aomenc's RD only ever picked HORZ_A cannot pass as proof of four |
| 5473 | - /// ([[gate-blind-to-feature]]). 8-bit and 10-bit, and one attempt with | |
| 5474 | - /// `--tile-columns=1` so the mi-exact mode map's tile-relative reset is | |
| 5475 | - /// exercised at a real tile boundary. | |
| 5473 | + /// ([[gate-blind-to-feature]]). 8-bit and 10-bit; `--tile-columns=1` is | |
| 5474 | + /// NOT among the attempts (base tile defect, reproducer in the r1 | |
| 5475 | + /// report), and `--enable-tx-size-search` is left at aomenc's default | |
| 5476 | + /// (ON) -- pinning it off hid a panic in the TX4 sub-grid of an 8x8 | |
| 5477 | + /// square inside a `PARTITION_VERT_A`/`_B` (r2). | |
| 5476 | 5478 | #[test] |
| 5477 | 5479 | fn a_real_aomenc_stream_with_ab_partitions_below_16x16_decodes_pixel_exact() { |
| 5478 | 5480 | const NAME: &str = |
| @@ -5493,6 +5495,11 @@ mod tests { | ||
| 5493 | 5495 | cq: u32, |
| 5494 | 5496 | ten_bit: bool, |
| 5495 | 5497 | tile_cols: u32, |
| 5498 | + /// Left at aomenc's default (ON) instead of pinned off: reaches | |
| 5499 | + /// the TX4 sub-grid of an 8x8 square inside a | |
| 5500 | + /// `PARTITION_VERT_A`/`_B` (r2's panic), at the cost of the | |
| 5501 | + /// strip-level split transform lane-rectx still refuses. | |
| 5502 | + tx_size_search: bool, | |
| 5496 | 5503 | } |
| 5497 | 5504 | // Recipes chosen by a ~200-cell sweep of {source, size, cq} at this |
| 5498 | 5505 | // level (r1 report): one cell per arm that is pixel-exact end to end, |
| @@ -5501,19 +5508,33 @@ mod tests { | ||
| 5501 | 5508 | // in the failing superblock, i.e. a base tile defect this lane |
| 5502 | 5509 | // neither introduced nor owns (reproducer pinned in the r1 report). |
| 5503 | 5510 | let attempts = [ |
| 5504 | - Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 22, ten_bit: false, tile_cols: 0 }, | |
| 5505 | - Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 20, ten_bit: false, tile_cols: 0 }, | |
| 5506 | - Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 50, ten_bit: false, tile_cols: 0 }, | |
| 5507 | - Attempt { src: "mandelbrot=size=64x64:start_x=-1.0", w: 64, h: 64, cq: 14, ten_bit: false, tile_cols: 0 }, | |
| 5511 | + Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 22, ten_bit: false, tile_cols: 0, tx_size_search: false }, | |
| 5512 | + Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 20, ten_bit: false, tile_cols: 0, tx_size_search: false }, | |
| 5513 | + Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 50, ten_bit: false, tile_cols: 0, tx_size_search: false }, | |
| 5514 | + Attempt { src: "mandelbrot=size=64x64:start_x=-1.0", w: 64, h: 64, cq: 14, ten_bit: false, tile_cols: 0, tx_size_search: false }, | |
| 5508 | 5515 | // 10-bit: the only two cells of the sweep that are exact at this |
| 5509 | 5516 | // depth (HORZ_A and VERT_A); the 10-bit HORZ_B/VERT_B cells all |
| 5510 | 5517 | // trip the base chroma defect the r1 report pins, so those two |
| 5511 | 5518 | // arms are proven 8-bit only. |
| 5512 | - Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 30, ten_bit: true, tile_cols: 0 }, | |
| 5513 | - Attempt { src: "mandelbrot=size=64x64:start_x=0.4", w: 64, h: 64, cq: 30, ten_bit: true, tile_cols: 0 }, | |
| 5519 | + Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 30, ten_bit: true, tile_cols: 0, tx_size_search: false }, | |
| 5520 | + Attempt { src: "mandelbrot=size=64x64:start_x=0.4", w: 64, h: 64, cq: 30, ten_bit: true, tile_cols: 0, tx_size_search: false }, | |
| 5521 | + // `--enable-tx-size-search` at aomenc's default: an 8x8 square of | |
| 5522 | + // a VERT_A/VERT_B resolves to a 2x2 grid of TX4 units, which is | |
| 5523 | + // the reach lookup that had no table row and panicked (r2). These | |
| 5524 | + // attempts may legitimately stop at lane-rectx's still-standing | |
| 5525 | + // "strip with a split transform" refusal -- an `unsupported` | |
| 5526 | + // message is tolerated, a panic or a pixel mismatch is not, and | |
| 5527 | + // at least one of them must reach a TX4 unit inside a vertical AB | |
| 5528 | + // partition. | |
| 5529 | + Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 55, ten_bit: false, tile_cols: 0, tx_size_search: true }, | |
| 5530 | + Attempt { src: "yuvtestsrc=size=64x64", w: 64, h: 64, cq: 22, ten_bit: false, tile_cols: 0, tx_size_search: true }, | |
| 5531 | + Attempt { src: "rgbtestsrc=size=64x64", w: 64, h: 64, cq: 20, ten_bit: false, tile_cols: 0, tx_size_search: true }, | |
| 5532 | + Attempt { src: "mandelbrot=size=64x64:start_x=-1.0", w: 64, h: 64, cq: 14, ten_bit: false, tile_cols: 0, tx_size_search: true }, | |
| 5514 | 5533 | ]; |
| 5515 | 5534 | let mut arms = [0usize; 4]; |
| 5516 | 5535 | let mut compared = 0usize; |
| 5536 | + let mut tx4_reached = 0usize; | |
| 5537 | + let mut tx4_compared = 0usize; | |
| 5517 | 5538 | for a in &attempts { |
| 5518 | 5539 | let desc = |
| 5519 | 5540 | format!("{} cq={} {}bit tiles={}", a.src, a.cq, if a.ten_bit { 10 } else { 8 }, a.tile_cols); |
| @@ -5543,7 +5564,8 @@ mod tests { | ||
| 5543 | 5564 | "--row-mt=0".into(), "--sb-size=64".into(), "--kf-max-dist=0".into(), |
| 5544 | 5565 | "--limit=1".into(), |
| 5545 | 5566 | "--enable-rect-partitions=1".into(), "--enable-ab-partitions=1".into(), |
| 5546 | - "--enable-1to4-partitions=0".into(), "--enable-tx-size-search=0".into(), | |
| 5567 | + "--enable-1to4-partitions=0".into(), | |
| 5568 | + format!("--enable-tx-size-search={}", u8::from(a.tx_size_search)), | |
| 5547 | 5569 | // Filter intra ON a rect strip is a separate, still-refused |
| 5548 | 5570 | // predictor; this gate is about the AB partition wiring. |
| 5549 | 5571 | "--enable-filter-intra=0".into(), |
| @@ -5572,8 +5594,27 @@ mod tests { | ||
| 5572 | 5594 | assert!(!stream.is_empty(), "{NAME}: {desc}: aomenc wrote an empty stream"); |
| 5573 | 5595 | assert_eq!(stream, encode(), "{NAME}: {desc}: aomenc output is not reproducible"); |
| 5574 | 5596 | let before = crate::decode::ab16_hits_by_arm(); |
| 5575 | - let frames = decode_stream(&stream) | |
| 5576 | - .unwrap_or_else(|e| panic!("{NAME}: {desc}: decode failed, not a pixel mismatch: {e}")); | |
| 5597 | + let tx4_before = crate::decode::vert_ab_tx4_hits(); | |
| 5598 | + let decoded = decode_stream(&stream); | |
| 5599 | + let tx4_this = crate::decode::vert_ab_tx4_hits() - tx4_before; | |
| 5600 | + // Counted even when the attempt later stops at another lane's | |
| 5601 | + // refusal: reaching this lookup at all is what r2 fixed. | |
| 5602 | + tx4_reached += tx4_this; | |
| 5603 | + let frames = match decoded { | |
| 5604 | + Ok(frames) => frames, | |
| 5605 | + // Only lane-rectx's split-transform strip refusal may stop a | |
| 5606 | + // tx-size-search attempt; a panic never reaches here at all. | |
| 5607 | + Err(e) if a.tx_size_search => { | |
| 5608 | + let msg = e.to_string(); | |
| 5609 | + assert!( | |
| 5610 | + msg.contains("unsupported"), | |
| 5611 | + "{NAME}: {desc}: decode failed with a non-refusal error: {msg}" | |
| 5612 | + ); | |
| 5613 | + eprintln!("{NAME}: {desc} refused after {tx4_this} vert-AB TX4 units: {msg}"); | |
| 5614 | + continue; | |
| 5615 | + } | |
| 5616 | + Err(e) => panic!("{NAME}: {desc}: decode failed, not a pixel mismatch: {e}"), | |
| 5617 | + }; | |
| 5577 | 5618 | let after = crate::decode::ab16_hits_by_arm(); |
| 5578 | 5619 | let this: Vec<usize> = (0..4).map(|i| after[i] - before[i]).collect(); |
| 5579 | 5620 | eprintln!("{NAME}: {desc} decoded, arms this attempt={this:?}"); |
| @@ -5589,13 +5630,39 @@ mod tests { | ||
| 5589 | 5630 | assert_eq!(got.v, w.v, "{NAME}: {desc} frame {i} V vs ffmpeg"); |
| 5590 | 5631 | } |
| 5591 | 5632 | // Counted only now: the attempt decoded AND compared exact. |
| 5633 | + if a.tx_size_search { | |
| 5634 | + tx4_compared += 1; | |
| 5635 | + eprintln!("{NAME}: {desc} pixel-exact, vert-AB TX4 units={tx4_this}"); | |
| 5636 | + continue; | |
| 5637 | + } | |
| 5592 | 5638 | for i in 0..4 { |
| 5593 | 5639 | arms[i] += after[i] - before[i]; |
| 5594 | 5640 | } |
| 5595 | 5641 | compared += 1; |
| 5596 | 5642 | eprintln!("{NAME}: {desc} pixel-exact"); |
| 5597 | 5643 | } |
| 5598 | - assert_eq!(compared, attempts.len(), "{NAME}: every attempt must decode and compare"); | |
| 5644 | + assert_eq!( | |
| 5645 | + compared, | |
| 5646 | + attempts.iter().filter(|a| !a.tx_size_search).count(), | |
| 5647 | + "{NAME}: every fixed-transform attempt must decode and compare" | |
| 5648 | + ); | |
| 5649 | + // The tx-size-search attempts cannot be compared pixel by pixel yet: | |
| 5650 | + // every 16x16 AB partition contains a strip, and with a free | |
| 5651 | + // transform size aomenc splits at least one of them in every stream | |
| 5652 | + // of a 40-cell {source, cq} sweep (r2 report), so they all stop at | |
| 5653 | + // lane-rectx's "strip with a split transform" refusal (or the 1:4 / | |
| 5654 | + // sub-8x8 ones) before the frame is done. What they DO prove is that | |
| 5655 | + // the TX4 sub-grid of an 8x8 square inside a VERT_A/VERT_B is reached | |
| 5656 | + // on a real stream and answers -- it used to panic there, and a panic | |
| 5657 | + // cannot be tolerated by the `unsupported` arm above. The values it | |
| 5658 | + // answers are pinned separately against libaom in | |
| 5659 | + // `of_tu_keeps_the_ordinary_answer_and_uses_the_block_row_under_vert_ab`. | |
| 5660 | + let _ = tx4_compared; | |
| 5661 | + assert!( | |
| 5662 | + tx4_reached > 0, | |
| 5663 | + "{NAME}: no --enable-tx-size-search=1 attempt reached a TX4 unit inside a \ | |
| 5664 | + vertical AB partition -- the r2 panic path is unproven" | |
| 5665 | + ); | |
| 5599 | 5666 | for (i, arm) in ["HORZ_A", "HORZ_B", "VERT_A", "VERT_B"].iter().enumerate() { |
| 5600 | 5667 | assert!(arms[i] > 0, "{NAME}: PARTITION_{arm} at 16x16 never fired across {compared} \ |
| 5601 | 5668 | compared streams -- the gate proves nothing about that arm (arms={arms:?})"); |
lanes/ab16-r2.report.mdadded+116 -0
| @@ -0,0 +1,116 @@ | ||
| 1 | +# lane-ab16 r2 — the panic the gate's `--enable-tx-size-search=0` was hiding, and where seed 43 really diverges | |
| 2 | + | |
| 3 | +Branch `lane-ab16` (off `lane-rectx` `fad4d5a`). r1 verdict was FAIL on four findings; this | |
| 4 | +round closes (1) and (3), and answers (2) and (4) with measurements rather than a fix. | |
| 5 | + | |
| 6 | +## (1) PANIC — fixed at the root: a TX unit is not a block of its own size | |
| 7 | + | |
| 8 | +`encode.rs` `Reach::of(4, ..)` inside a `PARTITION_VERT_A`/`_B` indexed | |
| 9 | +`HAS_TOP_RIGHT_VERT[Reach::table(4)] == [_; 3][3]` and panicked | |
| 10 | +("index out of bounds: len 3 index 3"), because the vert tables have no 4x4 row at all — | |
| 11 | +libaom's `has_tr_vert_tables[BLOCK_4X4]` is literally `NULL`. It is NULL because that lookup | |
| 12 | +never happens there: for a 4x4 transform unit inside an 8x8 square, libaom's | |
| 13 | +`has_top_right`/`has_bottom_left` (`reconintra.c`) take the BLOCK's `bsize` with a non-zero | |
| 14 | +`row_off`/`col_off`, answer interior units from the block geometry alone | |
| 15 | +(`col_off + tx_units < block_units`), and reach the table only for a unit on the block's top | |
| 16 | +row / left column — where the table read is the BLOCK's row at the BLOCK's position. | |
| 17 | + | |
| 18 | +- `crates/ec-av1/src/encode.rs` (+`Reach::of_tu`, ~line 1215): that rule, transcribed. | |
| 19 | +- `crates/ec-av1/src/decode.rs` 5212 / 5584: both TU loops (`decode_block`'s multi-TU branch | |
| 20 | + and `decode_leaf8`'s TX4 sub-grid) now call `Reach::of_tu(block, tx, ..)` instead of | |
| 21 | + `Reach::of(tx, ..)`. Root, not per-symptom: these are the only two sites in the crate that | |
| 22 | + ask a reach question for a sub-block transform unit (`grep -n "Reach::of("`). | |
| 23 | +- `crates/ec-av1/src/encode.rs` `Reach::in_vert_ab()` + `decode.rs` `vert_ab_tx4_hits()`: | |
| 24 | + counter for the exact call that used to panic, so the gate can hard-assert it is reached. | |
| 25 | + | |
| 26 | +The fix is behaviour-preserving outside a vertical AB partition — pinned, not hoped: | |
| 27 | +`of_tu_keeps_the_ordinary_answer_and_uses_the_block_row_under_vert_ab` (encode.rs tests) | |
| 28 | +asserts `of_tu(8, 4, ..) == of(4, ..)` at every 4x4 position of a 2x2-superblock frame, that | |
| 29 | +the vert-table path answers at every one of them (the panic regression), and that the two | |
| 30 | +tables genuinely disagree where libaom says they must (top-right 4x4 unit of the 8x8 at | |
| 31 | +superblock row 1, column 0: `has_tr_8x8` bit 16 = 1, `has_tr_vert_8x8` bit 16 = 0). | |
| 32 | + | |
| 33 | +EVIDENCE: gate stdout | `--enable-tx-size-search=1` attempt (yuvtestsrc 64x64 cq55) decoded | |
| 34 | +through the AB partitions instead of aborting | `refused after 4 vert-AB TX4 units: | |
| 35 | +unsupported: AV1 tile (a HORZ/VERT intra strip with a split transform ...)` — before this | |
| 36 | +round the same stream died with `panicked at encode.rs:1279 index out of bounds: len 3 | |
| 37 | +index 3` (decode_probe rc=101). | |
| 38 | + | |
| 39 | +## The gate, with tx-size search no longer pinned off | |
| 40 | + | |
| 41 | +`--enable-tx-size-search=0` is gone from the recipe builder; it is now per attempt: | |
| 42 | + | |
| 43 | +- the six comparison attempts keep it OFF and stay pixel-exact (all four arms fired); | |
| 44 | +- four new attempts leave it at aomenc's default (ON). They reach the formerly-panicking | |
| 45 | + lookup and are allowed to stop at another lane's refusal — an `unsupported` message is | |
| 46 | + tolerated, a panic or a pixel mismatch is not — and the gate hard-asserts that at least one | |
| 47 | + TX4 unit inside a vertical AB partition was decoded. | |
| 48 | + | |
| 49 | +Why the ON attempts cannot be compared pixel by pixel yet, measured not assumed: every 16x16 | |
| 50 | +AB partition contains a 16x8/8x16 strip, and with a free transform size aomenc splits at | |
| 51 | +least one strip in **40/40** cells of a `{yuvtestsrc, rgbtestsrc, mandelbrot, smptebars, | |
| 52 | +testsrc2} x {8,14,22,30,40,50,55,60}` sweep, so every one of them stops at lane-rectx's | |
| 53 | +still-standing "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is | |
| 54 | +not ported)" refusal (or the 1:4 / sub-8x8 / palette ones). A pixel-exact tx-size-search arm | |
| 55 | +therefore needs that refusal lifted first — lane-rectx's, not this lane's. | |
| 56 | + | |
| 57 | +EVIDENCE: gate stdout | `cargo test -p ec-av1 --lib -- ab_partitions_below_16x16 of_tu_keeps | |
| 58 | +--nocapture` | `pixel-exact on 6 streams, ab16 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)=[2, 1, 2, 1]`, | |
| 59 | +`yuvtestsrc cq=55 refused after 4 vert-AB TX4 units`, `test result: ok. 2 passed; 0 failed`. | |
| 60 | + | |
| 61 | +## (3) Stale docstring — fixed | |
| 62 | + | |
| 63 | +The gate's doc no longer claims a `--tile-columns=1` attempt (there is none; r1's reproducer | |
| 64 | +for the base tile defect stands) and now states why tx-size search is left at aomenc's | |
| 65 | +default. | |
| 66 | + | |
| 67 | +## (2) Seed 43 of the merged SB gate: NOT the AB arms — a 64x32 strip coefficient desync | |
| 68 | + | |
| 69 | +`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` still | |
| 70 | +FAILS on this branch at seed 43, frame 0 luma. Bisected against the instrumented oracle | |
| 71 | +(`EC_TRACE_MODE_STEP` both sides, ranges compared element by element): | |
| 72 | + | |
| 73 | +``` | |
| 74 | +first divergent element: mi_row=8 mi_col=16 name=skip oracle rng=60402 ours rng=58410 | |
| 75 | +last matching element: mi_row=0 mi_col=16 name=angle_uv val=3 rng=49760 (identical) | |
| 76 | +``` | |
| 77 | + | |
| 78 | +Everything up to and including the mode info of the **first 64x32 strip** at mi (0,16) — | |
| 79 | +pixel (64,0), `mode=7` (D203), `angle_y=3`, `uv_mode=7`, `angle_uv=3` — is bit-identical. | |
| 80 | +The streams part inside that block's **coefficients** (between its `angle_uv` and the next | |
| 81 | +block's `skip`), i.e. in the TX_64X32 residual path, and never resync: the oracle codes 16 | |
| 82 | +mode-info elements for the frame, we code 44. | |
| 83 | + | |
| 84 | +This is upstream of every AB symbol in the stream. The stream's partition trace is | |
| 85 | +`w64: NONE, HORZ, SPLIT | ... | w16 mi=(2,11) value=4 (HORZ_A)` — the single AB16 block sits | |
| 86 | +in the third superblock, decoded long after the divergence. The luma error map confirms it: | |
| 87 | +superblock 0 is exact except its right/bottom 7-pixel deblock spill, and everything from | |
| 88 | +x >= 64 is wrong. | |
| 89 | + | |
| 90 | +Why it was green at base: base `fad4d5a` refuses seed 43 — but that refusal is *itself* a | |
| 91 | +consequence of this desync (it decodes a garbage partition value once the arithmetic decoder | |
| 92 | +has drifted). Lifting the AB16 refusal did not break seed 43; it removed the mask | |
| 93 | +([[refusal-hides-a-defect]]). The defect lives in lane-rectx's 64x32 strip coefficient path, | |
| 94 | +not in this lane's arms, and this branch changes nothing on that path (`Reach` answers only | |
| 95 | +affect prediction, never symbol consumption). | |
| 96 | + | |
| 97 | +Disposition: **deferred(lane-rectx / a 64x32-strip coefficient lane — this lane owns no code | |
| 98 | +on that path)**. Merge blocker either way: the gate is red on this branch until it is fixed, | |
| 99 | +and it is red for a real defect, so it must not be papered over. | |
| 100 | + | |
| 101 | +EVIDENCE: `<scratchpad>/ab16/{seed43.obu,o.all,u.all,ours.yuv,ff.yuv}` | `EC_AV1_GATE_DUMP` | |
| 102 | ++ `EC_TRACE_MODE_STEP=1` on `aomdec` and `decode_probe`, `diff` of the element traces, and a | |
| 103 | +per-8x8 luma error map vs `ffmpeg -f rawvideo` | first divergent element | |
| 104 | +`mi(8,16) skip rng 60402 vs 58410`; 20494/24576 luma bytes differ, all at x >= 56. | |
| 105 | + | |
| 106 | +## (4) The chroma-only residue (mandelbrot 64x64 start_x=-0.6 cq30) | |
| 107 | + | |
| 108 | +Not re-measured this round (turn budget went to (1) and (2)); r1's characterisation stands: | |
| 109 | +670 differing bytes, first at byte 4247 (U plane), luma exact. Whether AB blocks are present | |
| 110 | +in that stream is still unanswered. | |
| 111 | +Disposition: **deferred(a chroma/SMOOTH prediction lane — r1 already scoped it)**. | |
| 112 | + | |
| 113 | +## Test totals | |
| 114 | + | |
| 115 | +`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (log: `~/.cache/ab16-r2-suite.log`): | |
| 116 | +see the HANDOFF line — the only failure is the seed-43 SB gate above. |