diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index b76ea5b2..c943001a 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -51,6 +51,8 @@ const PARTITION_HORZ_A: usize = 4; const PARTITION_HORZ_B: usize = 5; const PARTITION_VERT_A: usize = 6; const PARTITION_VERT_B: usize = 7; +const PARTITION_HORZ_4: usize = 8; +const PARTITION_VERT_4: usize = 9; const SB_MI: u32 = 16; const BLOCK_MI: u32 = 8; @@ -1383,6 +1385,26 @@ pub(crate) fn sb_ab_hits_by_arm() -> [usize; 4] { SB_AB_HITS.with(std::cell::Cell::get) } +// lane-tx64x16: the two 1:4 superblock arms, counted per orientation -- +// `PARTITION_HORZ_4` (four 64x16 strips) and `PARTITION_VERT_4` (four 16x64 +// strips). Two counters, not one, because a gate that only proved "some 1:4 +// strip fired" would pass on a stream that never coded the other axis, and +// every scan/context table this round added comes in a transposed pair. +thread_local! { + static SB_RECT4_HORZ_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; + static SB_RECT4_VERT_HITS: std::cell::Cell = const { std::cell::Cell::new(0) }; +} + +/// Current value of `SB_RECT4_HORZ_HITS` (64x16 strips decoded). +pub(crate) fn sb_rect4_horz_hits() -> usize { + SB_RECT4_HORZ_HITS.with(|c| c.get()) +} + +/// Current value of `SB_RECT4_VERT_HITS` (16x64 strips decoded). +pub(crate) fn sb_rect4_vert_hits() -> usize { + SB_RECT4_VERT_HITS.with(|c| c.get()) +} + // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not @@ -1920,6 +1942,46 @@ const SCAN_8X16: [u16; 128] = [ 123, 103, 110, 117, 124, 111, 118, 125, 119, 126, 127, ]; +/// `Default_Scan_32x8`, this decoder's own row-major transcription (see +/// [`SCAN_32X16`]'s doc comment) -- the chroma plane of a 64x16 +/// `PARTITION_HORZ_4` superblock strip (lane-tx64x16). libaom stores its +/// scans column-major (`p = col * height + row`), so a naive copy of +/// `default_scan_32x8` would silently install the TRANSPOSED 8x32 order +/// (class reference-layout-not-spec): `default_scan_16x8`'s literal bytes +/// are byte-identical to this decoder's [`SCAN_8X16`]. +const SCAN_32X8: [u16; 256] = [ + 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, 130, + 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 225, 194, 163, 132, 101, 70, 39, 8, 226, 195, + 164, 133, 102, 71, 40, 9, 227, 196, 165, 134, 103, 72, 41, 10, 228, 197, 166, 135, 104, 73, 42, + 11, 229, 198, 167, 136, 105, 74, 43, 12, 230, 199, 168, 137, 106, 75, 44, 13, 231, 200, 169, + 138, 107, 76, 45, 14, 232, 201, 170, 139, 108, 77, 46, 15, 233, 202, 171, 140, 109, 78, 47, 16, + 234, 203, 172, 141, 110, 79, 48, 17, 235, 204, 173, 142, 111, 80, 49, 18, 236, 205, 174, 143, + 112, 81, 50, 19, 237, 206, 175, 144, 113, 82, 51, 20, 238, 207, 176, 145, 114, 83, 52, 21, 239, + 208, 177, 146, 115, 84, 53, 22, 240, 209, 178, 147, 116, 85, 54, 23, 241, 210, 179, 148, 117, + 86, 55, 24, 242, 211, 180, 149, 118, 87, 56, 25, 243, 212, 181, 150, 119, 88, 57, 26, 244, 213, + 182, 151, 120, 89, 58, 27, 245, 214, 183, 152, 121, 90, 59, 28, 246, 215, 184, 153, 122, 91, + 60, 29, 247, 216, 185, 154, 123, 92, 61, 30, 248, 217, 186, 155, 124, 93, 62, 31, 249, 218, 187, + 156, 125, 94, 63, 250, 219, 188, 157, 126, 95, 251, 220, 189, 158, 127, 252, 221, 190, 159, 253, + 222, 191, 254, 223, 255, +]; +/// `Default_Scan_8x32`, [`SCAN_32X8`]'s transpose (the chroma plane of a +/// 16x64 `PARTITION_VERT_4` strip). +const SCAN_8X32: [u16; 256] = [ + 0, 1, 8, 2, 9, 16, 3, 10, 17, 24, 4, 11, 18, 25, 32, 5, 12, 19, 26, 33, 40, 6, 13, 20, 27, 34, + 41, 48, 7, 14, 21, 28, 35, 42, 49, 56, 15, 22, 29, 36, 43, 50, 57, 64, 23, 30, 37, 44, 51, 58, + 65, 72, 31, 38, 45, 52, 59, 66, 73, 80, 39, 46, 53, 60, 67, 74, 81, 88, 47, 54, 61, 68, 75, 82, + 89, 96, 55, 62, 69, 76, 83, 90, 97, 104, 63, 70, 77, 84, 91, 98, 105, 112, 71, 78, 85, 92, 99, + 106, 113, 120, 79, 86, 93, 100, 107, 114, 121, 128, 87, 94, 101, 108, 115, 122, 129, 136, 95, + 102, 109, 116, 123, 130, 137, 144, 103, 110, 117, 124, 131, 138, 145, 152, 111, 118, 125, 132, + 139, 146, 153, 160, 119, 126, 133, 140, 147, 154, 161, 168, 127, 134, 141, 148, 155, 162, 169, + 176, 135, 142, 149, 156, 163, 170, 177, 184, 143, 150, 157, 164, 171, 178, 185, 192, 151, 158, + 165, 172, 179, 186, 193, 200, 159, 166, 173, 180, 187, 194, 201, 208, 167, 174, 181, 188, 195, + 202, 209, 216, 175, 182, 189, 196, 203, 210, 217, 224, 183, 190, 197, 204, 211, 218, 225, 232, + 191, 198, 205, 212, 219, 226, 233, 240, 199, 206, 213, 220, 227, 234, 241, 248, 207, 214, 221, + 228, 235, 242, 249, 215, 222, 229, 236, 243, 250, 223, 230, 237, 244, 251, 231, 238, 245, 252, + 239, 246, 253, 247, 254, 255, +]; + /// [`neighbour`] with independent `w` (row stride)/`h` (row-bound) extents /// (lane-rectwire, mirrors [`record_rect`](Neighbours::record_rect)'s /// asymmetric-extent pattern). @@ -4909,30 +4971,63 @@ fn decode_block_rect64( ); } else { let around = neighbours.around_rect(at, bw, bh); - // LUMA: a real 32x32 corner, embedded top-left of the true bw x bh - // grid (see this function's own doc comment). + // LUMA: the coded corner, embedded top-left of the true bw x bh grid + // (see this function's own doc comment). A 64-length axis codes only + // its low 32 coefficients, so the corner is `min(bw, 32)` x + // `min(bh, 32)`: 32x32 under a 64x32/32x64 HORZ/VERT strip, and + // 32x16/16x32 under a 64x16/16x64 1:4 strip (lane-tx64x16). + let (luma_cw, luma_ch) = (bw.min(32), bh.min(32)); let scan32 = default_scan(TX32); - let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode); if std::env::var_os("EC_TRACE_COEFF").is_some() { let (rng, _) = dec.debug_state(); - eprintln!("EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size=64corner rng={rng}"); + eprintln!("EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size={luma_cw}x{luma_ch} rng={rng}"); } - let (luma_corner, luma_tx_type) = read_coeffs( - dec, - &mut luma_coding, - &scan32, - 0, - dc_sign_ctx(around[0].2), - TxType::DctDct, - Some((bw, bh)), - )?; + let (luma_corner, luma_tx_type) = if (luma_cw, luma_ch) == (32, 32) { + let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode); + read_coeffs( + dec, + &mut luma_coding, + &scan32, + 0, + dc_sign_ctx(around[0].2), + TxType::DctDct, + Some((bw, bh)), + )? + } else { + // `av1_get_adjusted_tx_size` (`blockd.h:1361`) maps TX_64X16 -> + // TX_32X16 and TX_16X64 -> TX_16X32, and `av1_scan_orders` + // (`scan.c`) gives both the very same `default_scan_32x16` / + // `default_scan_16x32` the 2:1 sizes use ("Half of the + // coefficients of tx64 at higher frequencies are set to zeros. So + // tx32's scan order is used"). `get_txsize_entropy_ctx` is + // (txsize_sqr + txsize_sqr_up + 1) >> 1 = (TX_16X16 + TX_64X64 + + // 1) >> 1 = TX_32X32 and `txsize_log2_minus4[TX_64X16]` is 5 (a + // 512-position eob group) -- BOTH identical to TX_32X16, so the + // 2:1 CDF set `LumaRect32x16` is bit-exact here and no new table + // is owed. `av1_nz_map_ctx_offset[TX_64X16]` is literally + // `av1_nz_map_ctx_offset_32x16` (`txb_common.c:340`), which is + // what `base_ctx_rect` computes at (32, 16). + let luma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 }; + let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); + read_coeffs_rect( + dec, + &mut luma_coding, + luma_scan, + luma_cw, + luma_ch, + 0, + dc_sign_ctx(around[0].2), + TxType::DctDct, + )? + }; if std::env::var_os("EC_TRACE_COEFF").is_some() { let (rng, _) = dec.debug_state(); eprintln!("EC_COEFF_VAL plane=0 row={mi_r} col={mi_c} rng={rng}"); } let mut luma_levels = vec![0i32; bw * bh]; - for row in 0..32 { - luma_levels[row * bw..][..32].copy_from_slice(&luma_corner[row * 32..][..32]); + for row in 0..luma_ch { + luma_levels[row * bw..][..luma_cw] + .copy_from_slice(&luma_corner[row * luma_cw..][..luma_cw]); } { let cur = block_q_idx(); @@ -4985,9 +5080,20 @@ fn decode_block_rect64( // CHROMA: a real, untruncated chroma_w x chroma_h transform -- no // corner crop needed (see doc comment). let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); - let chroma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 }; + // The chroma plane is never truncated (both axes <= 32 after + // subsampling). Under a 1:4 strip it is a true 32x8/8x32: + // `get_txsize_entropy_ctx(TX_32X8)` = (TX_8X8 + TX_32X32 + 1) >> 1 = + // TX_16X16 and `txsize_log2_minus4[TX_32X8]` = 4 (256 positions), + // both identical to TX_16X16 -- so [`TxbSet::Chroma16`] is the exact + // set, and only the scan is new (lane-tx64x16). + let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (bw, bh) { + (64, 16) => (TxbSet::Chroma16, &SCAN_32X8), + (16, 64) => (TxbSet::Chroma16, &SCAN_8X32), + (64, _) => (TxbSet::ChromaRect32x16, &SCAN_32X16), + _ => (TxbSet::ChromaRect32x16, &SCAN_16X32), + }; let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); - let mut u_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode); + let mut u_coding = cdfs.txb(chroma_set, uv_predict_mode); if std::env::var_os("EC_TRACE_COEFF").is_some() { let (rng, _) = dec.debug_state(); eprintln!("EC_COEFF plane=1 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); @@ -5041,7 +5147,7 @@ fn decode_block_rect64( smooth_neighbor_uv, ); let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); - let mut v_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode); + let mut v_coding = cdfs.txb(chroma_set, uv_predict_mode); if std::env::var_os("EC_TRACE_COEFF").is_some() { let (rng, _) = dec.debug_state(); eprintln!("EC_COEFF plane=2 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); @@ -5100,6 +5206,11 @@ fn decode_block_rect64( neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); SB_RECT_HITS.with(|c| c.set(c.get() + 1)); + match (bw, bh) { + (64, 16) => SB_RECT4_HORZ_HITS.with(|c| c.set(c.get() + 1)), + (16, 64) => SB_RECT4_VERT_HITS.with(|c| c.set(c.get() + 1)), + _ => {} + } if std::env::var_os("EC_AV1_TRACE").is_some() { let (rng, _) = dec.debug_state(); eprintln!("TRACE_RECT64_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} rng={rng}"); @@ -9442,10 +9553,49 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } } } + PARTITION_HORZ_4 | PARTITION_VERT_4 => { + // lane-tx64x16: the 1:4 pair at 64x64 -- four 64x16 (or + // 16x64) strips in raster order. `decode_partition` + // (`decodeframe.c`) steps by `quarter_step = mi_size / 4` + // (4 mi = 16 px = one SUB unit here) and BREAKS at the + // frame edge for `i > 0`, so a partial superblock codes + // only the strips whose origin is inside the frame. + let horz = part == PARTITION_HORZ_4; + for i in 0..4 { + let step_mi = i * (SB_MI as usize / 4); + let (this_r_mi, this_c_mi) = if horz { + (sb_r as usize * SB_MI as usize + step_mi, sb_c as usize * SB_MI as usize) + } else { + (sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize + step_mi) + }; + if i > 0 + && (this_r_mi >= mi_rows as usize || this_c_mi >= mi_cols as usize) + { + break; + } + let strip_at = if horz { (at.0 + i, at.1) } else { (at.0, at.1 + i) }; + let (bw, bh) = if horz { (64, 16) } else { (16, 64) }; + decode_block_rect64( + &mut dec, + &mut cdfs, + &mut neighbours, + strip_at, + bw, + bh, + &mut y, + &mut u, + &mut v, + enable_filter_intra, + allow_screen_content_tools, + base_q_idx, + tx_select, + reduced_tx_set, + )?; + } + } _ => { return Err(unsupported( - "a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, \ - four 64x16/16x64 strips)", + "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", )); } } diff --git a/crates/ec-av1/src/refusal_inventory.rs b/crates/ec-av1/src/refusal_inventory.rs index 82bc3b66..06a0c8dc 100644 --- a/crates/ec-av1/src/refusal_inventory.rs +++ b/crates/ec-av1/src/refusal_inventory.rs @@ -47,7 +47,7 @@ const REFUSALS: &[&str] = &[ "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)", "a tx_type symbol outside its CDF's own set: {t}", "an INTER 32x32 partition type this decoder does not code (value={part32})", - "a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, four 64x16/16x64 strips)", + "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", "a block that actually uses a palette (UV) -- reconstruction is out of scope", "a block that actually uses a palette (Y) -- reconstruction is out of scope", diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index bd6fd9dc..35c3e54f 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -12933,4 +12933,197 @@ mod tests { assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (pinned sbpart)"); } } + + /// lane-tx64x16 r1: a real `aomenc` stream whose superblock-level + /// partition decision is `PARTITION_HORZ_4`/`PARTITION_VERT_4` (four + /// 64x16 / 16x64 strips) must decode pixel-exact. Both arms are HARD + /// asserted, and only hits earned inside an attempt that then compared + /// pixel-exact against ffmpeg are counted -- a strip decoded by an + /// attempt that later refused proves nothing (class + /// gate-skips-on-its-own-failure). `--enable-1to4-partitions=1` is the + /// tool switch; `--min-partition-size=16` keeps the RD search from + /// recursing below 16x16, where several other unlanded partition shapes + /// live. + #[test] + fn a_real_aomenc_stream_with_a_superblock_level_1to4_partition_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_stream_with_a_superblock_level_1to4_partition_decodes_pixel_exact"; + let _gate_lock = lock_gate_counters(); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); + return; + } + let (width, height, frame_count) = (192usize, 128usize, 1usize); + let mut named_refusals = 0u32; + let mut matched = 0u32; + let (mut horz_proved, mut vert_proved) = (0usize, 0usize); + let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); + let n_attempts: u32 = std::env::var("EC_TX64X16_GATE_ATTEMPTS") + .ok() + .and_then(|s| s.parse().ok()) + .unwrap_or(40); + for attempt in 0..n_attempts { + let seed = 42 + attempt; + let duration = frame_count as f64 / 25.0; + // Odd attempts render the SAME generator rotated 90 degrees + // (generated at height x width, then `transpose`), because + // aomenc's RD picks `PARTITION_VERT_4` on this content and + // essentially never `HORZ_4`: the two arms are a transposed + // pair, and a gate that only ever sees one of them cannot catch + // a transposed scan/context table (class scan-weights-cross-axis). + let source = if attempt % 2 == 0 { + gradients_source(seed, width, height, &format!("duration={duration}:rate=25")) + } else { + format!( + "{},transpose=1", + gradients_source(seed, height, width, &format!("duration={duration}:rate=25")) + ) + }; + let y4m = Command::new("ffmpeg") + .args([ + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", + "yuv4mpegpipe", "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!( + y4m.status.success(), + "ffmpeg fixture: {}", + String::from_utf8_lossy(&y4m.stderr) + ); + let args: Vec<&str> = vec![ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=45", + "--cpu-used=0", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=1", + "--min-partition-size=16", + "--max-partition-size=64", + "--enable-restoration=0", + "--enable-palette=0", + "--deltaq-mode=0", + "--enable-filter-intra=0", + "--enable-cfl-intra=0", + "--enable-intrabc=0", + "--enable-tx-size-search=0", + "--obu", + "-o", + "-", + "-", + ]; + let mut child = Command::new(aomenc_path()) + .args(&args) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + let stream = out.stdout; + let before = ( + crate::decode::sb_rect4_horz_hits(), + crate::decode::sb_rect4_vert_hits(), + ); + let frames = match decode_stream(&stream) { + Err(e) => { + let msg = e.to_string(); + assert!( + msg.contains("unsupported"), + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" + ); + named_refusals += 1; + eprintln!("seed {seed} refusal: {msg}"); + continue; + } + Ok(frames) => frames, + }; + let (horz, vert) = ( + crate::decode::sb_rect4_horz_hits() - before.0, + crate::decode::sb_rect4_vert_hits() - before.1, + ); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); + assert_eq!(frames.len(), frame_count); + let mismatched = frames + .iter() + .zip(&ffmpeg_frames) + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); + if horz + vert == 0 { + // Out of this gate's territory: aomenc's RD picked no 1:4 + // partition at all for this seed, so the attempt can neither + // prove nor disprove the arms under test. NOT silently + // dropped -- counted and printed, and a mismatch here is + // reported as a defect of another lane's shape (r1 found + // one: seed 55 of this very recipe decodes 3944 wrong luma + // samples with zero 1:4 blocks in the stream, first at + // (154, 59), inside the 64x32 `PARTITION_HORZ` superblock at + // (128, 64) -- see lanes/tx64x16-r1.report.md). Selecting on + // "the stream contains the feature", never on "the stream + // decoded correctly", is what keeps this from being survivor + // bias. + out_of_scope += 1; + if mismatched { + out_of_scope_mismatch += 1; + eprintln!( + "{NAME}: seed {seed} MISMATCHES with zero 1:4 blocks -- a pre-existing \ + defect of another shape, not this gate's arms" + ); + } + continue; + } + if mismatched { + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { + std::fs::write(&path, &stream).expect("writing pinned stream"); + eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); + } + } + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); + } + horz_proved += horz; + vert_proved += vert; + matched += 1; + } + assert!( + matched > 0, + "{NAME}: every attempt refused; the gate never decoded a stream" + ); + assert!( + horz_proved > 0 && vert_proved > 0, + "{NAME}: a 1:4 arm never fired inside a pixel-exact attempt \ + (horz={horz_proved}, vert={vert_proved}, {matched} matches, {named_refusals} \ + refusals out of {n_attempts}) -- gate proved nothing this run" + ); + eprintln!( + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of \ + {n_attempts}, horz_4 strips={horz_proved}, vert_4 strips={vert_proved}, \ + {out_of_scope} attempts carried no 1:4 block ({out_of_scope_mismatch} of them \ + mismatched -- other lanes' shapes)" + ); + } } diff --git a/lanes/tx64x16-r1.report.md b/lanes/tx64x16-r1.report.md new file mode 100644 index 00000000..3c37a726 --- /dev/null +++ b/lanes/tx64x16-r1.report.md @@ -0,0 +1,118 @@ +# lane-tx64x16 r1 — the 1:4 pair at 64x64 (TX_64X16 / TX_16X64) + +Branch `lane-tx64x16`, worktree `edith_codecs-tx64x16`, off main `dc5553f`. + +## STATUS: INCOMPLETE — gate RED. The refusal is narrowed in the code but NOT +proven: a real `PARTITION_VERT_4` stream with coefficients still mismatches. +Do not merge as is. + +## Premises re-measured (charter carried two stale ones) + +- "the refusal string now names the 1:4 pair" — FALSE at `dc5553f`. It read + *"a superblock-level partition type other than NONE or SPLIT"* + (`refusal_inventory.rs:48`) while `decode.rs` already coded HORZ/VERT; the AB + arms part32-r5 reports are NOT on main. Command: + `grep -n "64" crates/ec-av1/src/refusal_inventory.rs`. +- "requires the transform primitives (TX_64X16 / TX_16X64 …)" — FALSE. They + already exist: `inverse_transform_2d_typed_wh` (transform.rs:817) is generic + in (w,h), already zeroes everything past the low 32 on a 64-length axis + (`transform.rs:842`), already gets the rect scale right (fires only at + log2 ratio 1, i.e. never for 4:1 — `transform.rs:837`, and its comment + already names 16x64/64x16), and `row_shift_wh` (transform.rs:288) already + carries `(16,64)|(64,16) => 2` and `(8,32)|(32,8) => 2`, both verified + against `av1_inv_txfm_shift_ls` / `inv_shift_64x16` == `{-2,-4}` + (`~/.cache/aom-oracle/src/av1/common/av1_inv_txfm2d.c:150`). Dequant is + area-keyed (`dq_denom_area`), and `av1_get_tx_scale` is too (1024 pels → 1). + Nothing was owed here; the real work was entropy wiring + partition wiring. + +## What changed + +- `crates/ec-av1/src/decode.rs` + - `SCAN_32X8` / `SCAN_8X32` (new, ~line 1650): row-major transcriptions of + libaom `default_scan_32x8` / `default_scan_8x32`, converted with + `row*w+col = (p % h)*w + (p / h)` from libaom's COLUMN-major `p`. The rule + was validated by reproducing this repo's existing `SCAN_16X8` byte for byte + from `default_scan_16x8` before generating anything new — and libaom's + `default_scan_16x8` literal is byte-identical to this repo's `SCAN_8X16`, + i.e. a naive copy installs the transpose (class + reference-layout-not-spec). + - `decode_block_rect64`: luma corner generalised from a hardcoded 32x32 to + `(bw.min(32), bh.min(32))`, reading 32x16/16x32 through `read_coeffs_rect` + with `SCAN_32X16`/`SCAN_16X32` and `TxbSet::LumaRect32x16`; chroma set/scan + picked per shape, 32x8/8x32 reading `TxbSet::Chroma16` with the new scans. + Why no new CDF tables are owed, all read out of the oracle source: + `av1_get_adjusted_tx_size` maps TX_64X16→TX_32X16, TX_16X64→TX_16X32 + (`blockd.h:1361`); `av1_scan_orders` gives TX_64X16 `default_scan_32x16` + ("tx32's scan order is used", `scan.c`); `get_txsize_entropy_ctx` is 3 for + both TX_64X16 and TX_32X16 and 2 for both TX_32X8 and TX_16X16; + `txsize_log2_minus4` is 5 for TX_64X16 *and* TX_32X16, 4 for TX_32X8 *and* + TX_16X16 (`common_data.h:346`) so the eob alphabet matches too; and + `av1_nz_map_ctx_offset[TX_64X16]` is literally + `av1_nz_map_ctx_offset_32x16` (`txb_common.c:340`) — which is what + `base_ctx_rect(32,16)` computes, since both raw and coded dims are w>h. + - `PARTITION_HORZ_4`/`PARTITION_VERT_4` (8/9) wired at the superblock level: + four strips, `quarter_step` = 1 SUB unit, with libaom's `i > 0` frame-edge + break. + - New per-orientation hit counters `sb_rect4_horz_hits()` / + `sb_rect4_vert_hits()`. +- `crates/ec-av1/src/refusal_inventory.rs`: SB-level string narrowed to + "a superblock-level HORZ_A/HORZ_B/VERT_A/VERT_B partition (… codes NONE, + SPLIT, HORZ, VERT and the 1:4 pair at 64x64)". +- `crates/ec-av1/src/stream.rs`: new gate + `a_real_aomenc_stream_with_a_superblock_level_1to4_partition_decodes_pixel_exact`. +- `crates/ec-av1/fixtures/tx64x16-vert4-mismatch-seed73.obu`: the failing + stream, pinned. + +## Gate + +`cargo test -p ec-av1 --lib -- --exact stream::tests::a_real_aomenc_stream_with_a_superblock_level_1to4_partition_decodes_pixel_exact` +(`EC_TX64X16_GATE_ATTEMPTS`, default 40). aomenc recipe = the sbpart gate's, +with `--enable-1to4-partitions=1` and `--min-partition-size=16`; odd attempts +render the generator rotated 90 degrees (`transpose=1`) because aomenc picks +VERT_4 on this content and essentially never HORZ_4, and the two arms are a +transposed pair. Attempts whose decode fired zero 1:4 strips are counted and +printed, never asserted on — selection is on "the stream contains the +feature", never on "the stream decoded correctly". + +RESULT: **FAIL**. `seed 73` (a stream with four real 16x64 `PARTITION_VERT_4` +strips at mi(16,16..28)) mismatches ffmpeg: 10754 wrong luma samples, first at +(64, 56) — one row band ABOVE the strips, i.e. across the y=64 deblock edge. +An earlier 13-attempt run (before the transpose arm) had VERT_4 fire 4 strips +and decode PIXEL-EXACT, so the skip/low-energy case works and the coded case +does not. + +EVIDENCE: /home/user/Documents/Code/Rust/edith_codecs-tx64x16/crates/ec-av1/fixtures/tx64x16-vert4-mismatch-seed73.obu | decode_probe dump vs `ffmpeg -f rawvideo`, EC_AV1_TRACE partition trace | 10754/24576 luma samples differ, first (64,56); trace shows `partition_w64 value=9` then four `TRACE_RECT64_END bw=16 bh=64` +EVIDENCE: gate stdout above | 40 aomenc attempts, seeds 42..81, `--enable-1to4-partitions=1` | 21 named refusals, VERT_4 arm reached a real decode, HORZ_4 arm never selected by aomenc on this content + +## Open, with dispositions + +- **fix-now (r2)**: the coded-16x64 mismatch above. Not yet root-caused. + Ruled out by reading the oracle source, NOT by experiment: shift chain + (`inv_shift_64x16`/`inv_shift_16x64` = {-2,-4} = our `row_shift_wh` 2), rect + scale (4:1 gets none), dequant denominator (area 1024 → 2), eob alphabet + (512), CDF set, scan choice, nz-map offset table. Untested suspects, in + order: (1) the deblock grid for a 1:4 strip + (`fill_lf_grid_rect(.., tx_w=16, tx_h=64, 0)`) — the first diffs are on the + OTHER side of the edge; (2) 16x64 intra prediction edge reach; (3) the + chroma 8x32 plane. First move should be a prefilt dump + (`EC_AV1_PREFILT_DUMP`) to split "reconstruction wrong" from "deblock + wrong" — the diff band starting above the block is exactly the tell that + cost lane-tiny a round. +- **deferred(a green 64-level gate)**: the 32x32-level 1:4 arms. They ARE + requested by this recipe — `a 32x32 partition type this decoder does not + code (value=9)` appears in the sweep — and need TX_32X8/TX_8X32 luma + (`TxbSet::Luma16` exactly: entropy ctx 2, eob 256) plus 16x4/4x16 chroma + (`TxbSet::Chroma8`: ctx 1, eob 64) and two more scans. Same shape of work, + not started. +- **flagged, not this lane's shape (pre-existing)**: with + `--min-partition-size=16`, seed 55 of this recipe decodes 3944 wrong luma + samples with ZERO 1:4 blocks in the stream (trace: SB(1,0) SPLIT with a + 32x32 `PARTITION_HORZ`, SB(1,2) a 64x32 `PARTITION_HORZ`), first diff at + (154, 59). My diff cannot reach that stream (every path it touches needs a + 16-with-64 dimension pair), so it is a pre-existing defect of the 32x16 / + 64x32 strip shapes exposed by a recipe the existing sbpart gate + (`--min-partition-size=32`) never uses. Stream: rerun the gate with + `EC_AV1_GATE_DUMP` at `EC_TX64X16_GATE_ATTEMPTS=14`. +- **accepted**: `palette_bsize_ctx_wh` has no rect caller at all + (`read_intra_mode_rect` never reads a palette symbol), so 64x16/16x64 need + no entry there; a screen-content rect strip is a different lane's hole.