1:4 partitions at 64x64 (TX_64X16/TX_16X64 luma, 32x8/8x32 chroma) -- wiring lands, gate still RED
Browse files at this commit1dd6e1ed55dd402fbc36f3076664d1ecd460f696Parent: 628d9cb- feat
- 1:4 partitions at 64x64 (TX_64X16/TX_16X64 luma, 32x8/8x32 chroma) -- wiring lands, gate still RED
4 changed files +482 -21
- crates/ec-av1/src/decode.rs +170 -20
- crates/ec-av1/src/refusal_inventory.rs +1 -1
- crates/ec-av1/src/stream.rs +193 -0
- lanes/tx64x16-r1.report.md +118 -0
crates/ec-av1/src/decode.rsmodified+170 -20
| @@ -51,6 +51,8 @@ const PARTITION_HORZ_A: usize = 4; | ||
| 51 | 51 | const PARTITION_HORZ_B: usize = 5; |
| 52 | 52 | const PARTITION_VERT_A: usize = 6; |
| 53 | 53 | const PARTITION_VERT_B: usize = 7; |
| 54 | +const PARTITION_HORZ_4: usize = 8; | |
| 55 | +const PARTITION_VERT_4: usize = 9; | |
| 54 | 56 | const SB_MI: u32 = 16; |
| 55 | 57 | const BLOCK_MI: u32 = 8; |
| 56 | 58 | |
| @@ -1383,6 +1385,26 @@ pub(crate) fn sb_ab_hits_by_arm() -> [usize; 4] { | ||
| 1383 | 1385 | SB_AB_HITS.with(std::cell::Cell::get) |
| 1384 | 1386 | } |
| 1385 | 1387 | |
| 1388 | +// lane-tx64x16: the two 1:4 superblock arms, counted per orientation -- | |
| 1389 | +// `PARTITION_HORZ_4` (four 64x16 strips) and `PARTITION_VERT_4` (four 16x64 | |
| 1390 | +// strips). Two counters, not one, because a gate that only proved "some 1:4 | |
| 1391 | +// strip fired" would pass on a stream that never coded the other axis, and | |
| 1392 | +// every scan/context table this round added comes in a transposed pair. | |
| 1393 | +thread_local! { | |
| 1394 | + static SB_RECT4_HORZ_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 1395 | + static SB_RECT4_VERT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 1396 | +} | |
| 1397 | + | |
| 1398 | +/// Current value of `SB_RECT4_HORZ_HITS` (64x16 strips decoded). | |
| 1399 | +pub(crate) fn sb_rect4_horz_hits() -> usize { | |
| 1400 | + SB_RECT4_HORZ_HITS.with(|c| c.get()) | |
| 1401 | +} | |
| 1402 | + | |
| 1403 | +/// Current value of `SB_RECT4_VERT_HITS` (16x64 strips decoded). | |
| 1404 | +pub(crate) fn sb_rect4_vert_hits() -> usize { | |
| 1405 | + SB_RECT4_VERT_HITS.with(|c| c.get()) | |
| 1406 | +} | |
| 1407 | + | |
| 1386 | 1408 | // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane |
| 1387 | 1409 | // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the |
| 1388 | 1410 | // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not |
| @@ -1920,6 +1942,46 @@ const SCAN_8X16: [u16; 128] = [ | ||
| 1920 | 1942 | 123, 103, 110, 117, 124, 111, 118, 125, 119, 126, 127, |
| 1921 | 1943 | ]; |
| 1922 | 1944 | |
| 1945 | +/// `Default_Scan_32x8`, this decoder's own row-major transcription (see | |
| 1946 | +/// [`SCAN_32X16`]'s doc comment) -- the chroma plane of a 64x16 | |
| 1947 | +/// `PARTITION_HORZ_4` superblock strip (lane-tx64x16). libaom stores its | |
| 1948 | +/// scans column-major (`p = col * height + row`), so a naive copy of | |
| 1949 | +/// `default_scan_32x8` would silently install the TRANSPOSED 8x32 order | |
| 1950 | +/// (class reference-layout-not-spec): `default_scan_16x8`'s literal bytes | |
| 1951 | +/// are byte-identical to this decoder's [`SCAN_8X16`]. | |
| 1952 | +const SCAN_32X8: [u16; 256] = [ | |
| 1953 | + 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, 130, | |
| 1954 | + 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 225, 194, 163, 132, 101, 70, 39, 8, 226, 195, | |
| 1955 | + 164, 133, 102, 71, 40, 9, 227, 196, 165, 134, 103, 72, 41, 10, 228, 197, 166, 135, 104, 73, 42, | |
| 1956 | + 11, 229, 198, 167, 136, 105, 74, 43, 12, 230, 199, 168, 137, 106, 75, 44, 13, 231, 200, 169, | |
| 1957 | + 138, 107, 76, 45, 14, 232, 201, 170, 139, 108, 77, 46, 15, 233, 202, 171, 140, 109, 78, 47, 16, | |
| 1958 | + 234, 203, 172, 141, 110, 79, 48, 17, 235, 204, 173, 142, 111, 80, 49, 18, 236, 205, 174, 143, | |
| 1959 | + 112, 81, 50, 19, 237, 206, 175, 144, 113, 82, 51, 20, 238, 207, 176, 145, 114, 83, 52, 21, 239, | |
| 1960 | + 208, 177, 146, 115, 84, 53, 22, 240, 209, 178, 147, 116, 85, 54, 23, 241, 210, 179, 148, 117, | |
| 1961 | + 86, 55, 24, 242, 211, 180, 149, 118, 87, 56, 25, 243, 212, 181, 150, 119, 88, 57, 26, 244, 213, | |
| 1962 | + 182, 151, 120, 89, 58, 27, 245, 214, 183, 152, 121, 90, 59, 28, 246, 215, 184, 153, 122, 91, | |
| 1963 | + 60, 29, 247, 216, 185, 154, 123, 92, 61, 30, 248, 217, 186, 155, 124, 93, 62, 31, 249, 218, 187, | |
| 1964 | + 156, 125, 94, 63, 250, 219, 188, 157, 126, 95, 251, 220, 189, 158, 127, 252, 221, 190, 159, 253, | |
| 1965 | + 222, 191, 254, 223, 255, | |
| 1966 | +]; | |
| 1967 | +/// `Default_Scan_8x32`, [`SCAN_32X8`]'s transpose (the chroma plane of a | |
| 1968 | +/// 16x64 `PARTITION_VERT_4` strip). | |
| 1969 | +const SCAN_8X32: [u16; 256] = [ | |
| 1970 | + 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, | |
| 1971 | + 41, 48, 7, 14, 21, 28, 35, 42, 49, 56, 15, 22, 29, 36, 43, 50, 57, 64, 23, 30, 37, 44, 51, 58, | |
| 1972 | + 65, 72, 31, 38, 45, 52, 59, 66, 73, 80, 39, 46, 53, 60, 67, 74, 81, 88, 47, 54, 61, 68, 75, 82, | |
| 1973 | + 89, 96, 55, 62, 69, 76, 83, 90, 97, 104, 63, 70, 77, 84, 91, 98, 105, 112, 71, 78, 85, 92, 99, | |
| 1974 | + 106, 113, 120, 79, 86, 93, 100, 107, 114, 121, 128, 87, 94, 101, 108, 115, 122, 129, 136, 95, | |
| 1975 | + 102, 109, 116, 123, 130, 137, 144, 103, 110, 117, 124, 131, 138, 145, 152, 111, 118, 125, 132, | |
| 1976 | + 139, 146, 153, 160, 119, 126, 133, 140, 147, 154, 161, 168, 127, 134, 141, 148, 155, 162, 169, | |
| 1977 | + 176, 135, 142, 149, 156, 163, 170, 177, 184, 143, 150, 157, 164, 171, 178, 185, 192, 151, 158, | |
| 1978 | + 165, 172, 179, 186, 193, 200, 159, 166, 173, 180, 187, 194, 201, 208, 167, 174, 181, 188, 195, | |
| 1979 | + 202, 209, 216, 175, 182, 189, 196, 203, 210, 217, 224, 183, 190, 197, 204, 211, 218, 225, 232, | |
| 1980 | + 191, 198, 205, 212, 219, 226, 233, 240, 199, 206, 213, 220, 227, 234, 241, 248, 207, 214, 221, | |
| 1981 | + 228, 235, 242, 249, 215, 222, 229, 236, 243, 250, 223, 230, 237, 244, 251, 231, 238, 245, 252, | |
| 1982 | + 239, 246, 253, 247, 254, 255, | |
| 1983 | +]; | |
| 1984 | + | |
| 1923 | 1985 | /// [`neighbour`] with independent `w` (row stride)/`h` (row-bound) extents |
| 1924 | 1986 | /// (lane-rectwire, mirrors [`record_rect`](Neighbours::record_rect)'s |
| 1925 | 1987 | /// asymmetric-extent pattern). |
| @@ -4909,30 +4971,63 @@ fn decode_block_rect64( | ||
| 4909 | 4971 | ); |
| 4910 | 4972 | } else { |
| 4911 | 4973 | let around = neighbours.around_rect(at, bw, bh); |
| 4912 | - // LUMA: a real 32x32 corner, embedded top-left of the true bw x bh | |
| 4913 | - // grid (see this function's own doc comment). | |
| 4974 | + // LUMA: the coded corner, embedded top-left of the true bw x bh grid | |
| 4975 | + // (see this function's own doc comment). A 64-length axis codes only | |
| 4976 | + // its low 32 coefficients, so the corner is `min(bw, 32)` x | |
| 4977 | + // `min(bh, 32)`: 32x32 under a 64x32/32x64 HORZ/VERT strip, and | |
| 4978 | + // 32x16/16x32 under a 64x16/16x64 1:4 strip (lane-tx64x16). | |
| 4979 | + let (luma_cw, luma_ch) = (bw.min(32), bh.min(32)); | |
| 4914 | 4980 | let scan32 = default_scan(TX32); |
| 4915 | - let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode); | |
| 4916 | 4981 | if std::env::var_os("EC_TRACE_COEFF").is_some() { |
| 4917 | 4982 | let (rng, _) = dec.debug_state(); |
| 4918 | - eprintln!("EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size=64corner rng={rng}"); | |
| 4983 | + eprintln!("EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size={luma_cw}x{luma_ch} rng={rng}"); | |
| 4919 | 4984 | } |
| 4920 | - let (luma_corner, luma_tx_type) = read_coeffs( | |
| 4921 | - dec, | |
| 4922 | - &mut luma_coding, | |
| 4923 | - &scan32, | |
| 4924 | - 0, | |
| 4925 | - dc_sign_ctx(around[0].2), | |
| 4926 | - TxType::DctDct, | |
| 4927 | - Some((bw, bh)), | |
| 4928 | - )?; | |
| 4985 | + let (luma_corner, luma_tx_type) = if (luma_cw, luma_ch) == (32, 32) { | |
| 4986 | + let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode); | |
| 4987 | + read_coeffs( | |
| 4988 | + dec, | |
| 4989 | + &mut luma_coding, | |
| 4990 | + &scan32, | |
| 4991 | + 0, | |
| 4992 | + dc_sign_ctx(around[0].2), | |
| 4993 | + TxType::DctDct, | |
| 4994 | + Some((bw, bh)), | |
| 4995 | + )? | |
| 4996 | + } else { | |
| 4997 | + // `av1_get_adjusted_tx_size` (`blockd.h:1361`) maps TX_64X16 -> | |
| 4998 | + // TX_32X16 and TX_16X64 -> TX_16X32, and `av1_scan_orders` | |
| 4999 | + // (`scan.c`) gives both the very same `default_scan_32x16` / | |
| 5000 | + // `default_scan_16x32` the 2:1 sizes use ("Half of the | |
| 5001 | + // coefficients of tx64 at higher frequencies are set to zeros. So | |
| 5002 | + // tx32's scan order is used"). `get_txsize_entropy_ctx` is | |
| 5003 | + // (txsize_sqr + txsize_sqr_up + 1) >> 1 = (TX_16X16 + TX_64X64 + | |
| 5004 | + // 1) >> 1 = TX_32X32 and `txsize_log2_minus4[TX_64X16]` is 5 (a | |
| 5005 | + // 512-position eob group) -- BOTH identical to TX_32X16, so the | |
| 5006 | + // 2:1 CDF set `LumaRect32x16` is bit-exact here and no new table | |
| 5007 | + // is owed. `av1_nz_map_ctx_offset[TX_64X16]` is literally | |
| 5008 | + // `av1_nz_map_ctx_offset_32x16` (`txb_common.c:340`), which is | |
| 5009 | + // what `base_ctx_rect` computes at (32, 16). | |
| 5010 | + let luma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 }; | |
| 5011 | + let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); | |
| 5012 | + read_coeffs_rect( | |
| 5013 | + dec, | |
| 5014 | + &mut luma_coding, | |
| 5015 | + luma_scan, | |
| 5016 | + luma_cw, | |
| 5017 | + luma_ch, | |
| 5018 | + 0, | |
| 5019 | + dc_sign_ctx(around[0].2), | |
| 5020 | + TxType::DctDct, | |
| 5021 | + )? | |
| 5022 | + }; | |
| 4929 | 5023 | if std::env::var_os("EC_TRACE_COEFF").is_some() { |
| 4930 | 5024 | let (rng, _) = dec.debug_state(); |
| 4931 | 5025 | eprintln!("EC_COEFF_VAL plane=0 row={mi_r} col={mi_c} rng={rng}"); |
| 4932 | 5026 | } |
| 4933 | 5027 | let mut luma_levels = vec![0i32; bw * bh]; |
| 4934 | - for row in 0..32 { | |
| 4935 | - luma_levels[row * bw..][..32].copy_from_slice(&luma_corner[row * 32..][..32]); | |
| 5028 | + for row in 0..luma_ch { | |
| 5029 | + luma_levels[row * bw..][..luma_cw] | |
| 5030 | + .copy_from_slice(&luma_corner[row * luma_cw..][..luma_cw]); | |
| 4936 | 5031 | } |
| 4937 | 5032 | { |
| 4938 | 5033 | let cur = block_q_idx(); |
| @@ -4985,9 +5080,20 @@ fn decode_block_rect64( | ||
| 4985 | 5080 | // CHROMA: a real, untruncated chroma_w x chroma_h transform -- no |
| 4986 | 5081 | // corner crop needed (see doc comment). |
| 4987 | 5082 | let ac = alpha.map(|_| cfl_ac_q3_rect(y, px, py, bw, bh)); |
| 4988 | - let chroma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 }; | |
| 5083 | + // The chroma plane is never truncated (both axes <= 32 after | |
| 5084 | + // subsampling). Under a 1:4 strip it is a true 32x8/8x32: | |
| 5085 | + // `get_txsize_entropy_ctx(TX_32X8)` = (TX_8X8 + TX_32X32 + 1) >> 1 = | |
| 5086 | + // TX_16X16 and `txsize_log2_minus4[TX_32X8]` = 4 (256 positions), | |
| 5087 | + // both identical to TX_16X16 -- so [`TxbSet::Chroma16`] is the exact | |
| 5088 | + // set, and only the scan is new (lane-tx64x16). | |
| 5089 | + let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (bw, bh) { | |
| 5090 | + (64, 16) => (TxbSet::Chroma16, &SCAN_32X8), | |
| 5091 | + (16, 64) => (TxbSet::Chroma16, &SCAN_8X32), | |
| 5092 | + (64, _) => (TxbSet::ChromaRect32x16, &SCAN_32X16), | |
| 5093 | + _ => (TxbSet::ChromaRect32x16, &SCAN_16X32), | |
| 5094 | + }; | |
| 4989 | 5095 | let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); |
| 4990 | - let mut u_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode); | |
| 5096 | + let mut u_coding = cdfs.txb(chroma_set, uv_predict_mode); | |
| 4991 | 5097 | if std::env::var_os("EC_TRACE_COEFF").is_some() { |
| 4992 | 5098 | let (rng, _) = dec.debug_state(); |
| 4993 | 5099 | eprintln!("EC_COEFF plane=1 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); |
| @@ -5041,7 +5147,7 @@ fn decode_block_rect64( | ||
| 5041 | 5147 | smooth_neighbor_uv, |
| 5042 | 5148 | ); |
| 5043 | 5149 | let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); |
| 5044 | - let mut v_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode); | |
| 5150 | + let mut v_coding = cdfs.txb(chroma_set, uv_predict_mode); | |
| 5045 | 5151 | if std::env::var_os("EC_TRACE_COEFF").is_some() { |
| 5046 | 5152 | let (rng, _) = dec.debug_state(); |
| 5047 | 5153 | eprintln!("EC_COEFF plane=2 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); |
| @@ -5100,6 +5206,11 @@ fn decode_block_rect64( | ||
| 5100 | 5206 | neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); |
| 5101 | 5207 | neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0); |
| 5102 | 5208 | SB_RECT_HITS.with(|c| c.set(c.get() + 1)); |
| 5209 | + match (bw, bh) { | |
| 5210 | + (64, 16) => SB_RECT4_HORZ_HITS.with(|c| c.set(c.get() + 1)), | |
| 5211 | + (16, 64) => SB_RECT4_VERT_HITS.with(|c| c.set(c.get() + 1)), | |
| 5212 | + _ => {} | |
| 5213 | + } | |
| 5103 | 5214 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 5104 | 5215 | let (rng, _) = dec.debug_state(); |
| 5105 | 5216 | 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( | ||
| 9442 | 9553 | } |
| 9443 | 9554 | } |
| 9444 | 9555 | } |
| 9556 | + PARTITION_HORZ_4 | PARTITION_VERT_4 => { | |
| 9557 | + // lane-tx64x16: the 1:4 pair at 64x64 -- four 64x16 (or | |
| 9558 | + // 16x64) strips in raster order. `decode_partition` | |
| 9559 | + // (`decodeframe.c`) steps by `quarter_step = mi_size / 4` | |
| 9560 | + // (4 mi = 16 px = one SUB unit here) and BREAKS at the | |
| 9561 | + // frame edge for `i > 0`, so a partial superblock codes | |
| 9562 | + // only the strips whose origin is inside the frame. | |
| 9563 | + let horz = part == PARTITION_HORZ_4; | |
| 9564 | + for i in 0..4 { | |
| 9565 | + let step_mi = i * (SB_MI as usize / 4); | |
| 9566 | + let (this_r_mi, this_c_mi) = if horz { | |
| 9567 | + (sb_r as usize * SB_MI as usize + step_mi, sb_c as usize * SB_MI as usize) | |
| 9568 | + } else { | |
| 9569 | + (sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize + step_mi) | |
| 9570 | + }; | |
| 9571 | + if i > 0 | |
| 9572 | + && (this_r_mi >= mi_rows as usize || this_c_mi >= mi_cols as usize) | |
| 9573 | + { | |
| 9574 | + break; | |
| 9575 | + } | |
| 9576 | + let strip_at = if horz { (at.0 + i, at.1) } else { (at.0, at.1 + i) }; | |
| 9577 | + let (bw, bh) = if horz { (64, 16) } else { (16, 64) }; | |
| 9578 | + decode_block_rect64( | |
| 9579 | + &mut dec, | |
| 9580 | + &mut cdfs, | |
| 9581 | + &mut neighbours, | |
| 9582 | + strip_at, | |
| 9583 | + bw, | |
| 9584 | + bh, | |
| 9585 | + &mut y, | |
| 9586 | + &mut u, | |
| 9587 | + &mut v, | |
| 9588 | + enable_filter_intra, | |
| 9589 | + allow_screen_content_tools, | |
| 9590 | + base_q_idx, | |
| 9591 | + tx_select, | |
| 9592 | + reduced_tx_set, | |
| 9593 | + )?; | |
| 9594 | + } | |
| 9595 | + } | |
| 9445 | 9596 | _ => { |
| 9446 | 9597 | return Err(unsupported( |
| 9447 | - "a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, \ | |
| 9448 | - four 64x16/16x64 strips)", | |
| 9598 | + "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", | |
| 9449 | 9599 | )); |
| 9450 | 9600 | } |
| 9451 | 9601 | } |
crates/ec-av1/src/refusal_inventory.rsmodified+1 -1
| @@ -47,7 +47,7 @@ const REFUSALS: &[&str] = &[ | ||
| 47 | 47 | "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)", |
| 48 | 48 | "a tx_type symbol outside its CDF's own set: {t}", |
| 49 | 49 | "an INTER 32x32 partition type this decoder does not code (value={part32})", |
| 50 | - "a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, four 64x16/16x64 strips)", | |
| 50 | + "a superblock-level partition value outside PARTITION_NONE..PARTITION_VERT_4", | |
| 51 | 51 | "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)", |
| 52 | 52 | "a block that actually uses a palette (UV) -- reconstruction is out of scope", |
| 53 | 53 | "a block that actually uses a palette (Y) -- reconstruction is out of scope", |
crates/ec-av1/src/stream.rsmodified+193 -0
| @@ -12933,4 +12933,197 @@ mod tests { | ||
| 12933 | 12933 | assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (pinned sbpart)"); |
| 12934 | 12934 | } |
| 12935 | 12935 | } |
| 12936 | + | |
| 12937 | + /// lane-tx64x16 r1: a real `aomenc` stream whose superblock-level | |
| 12938 | + /// partition decision is `PARTITION_HORZ_4`/`PARTITION_VERT_4` (four | |
| 12939 | + /// 64x16 / 16x64 strips) must decode pixel-exact. Both arms are HARD | |
| 12940 | + /// asserted, and only hits earned inside an attempt that then compared | |
| 12941 | + /// pixel-exact against ffmpeg are counted -- a strip decoded by an | |
| 12942 | + /// attempt that later refused proves nothing (class | |
| 12943 | + /// gate-skips-on-its-own-failure). `--enable-1to4-partitions=1` is the | |
| 12944 | + /// tool switch; `--min-partition-size=16` keeps the RD search from | |
| 12945 | + /// recursing below 16x16, where several other unlanded partition shapes | |
| 12946 | + /// live. | |
| 12947 | + #[test] | |
| 12948 | + fn a_real_aomenc_stream_with_a_superblock_level_1to4_partition_decodes_pixel_exact() { | |
| 12949 | + const NAME: &str = | |
| 12950 | + "a_real_aomenc_stream_with_a_superblock_level_1to4_partition_decodes_pixel_exact"; | |
| 12951 | + let _gate_lock = lock_gate_counters(); | |
| 12952 | + if !have_ffmpeg() { | |
| 12953 | + eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 12954 | + return; | |
| 12955 | + } | |
| 12956 | + if !have_aomenc() { | |
| 12957 | + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); | |
| 12958 | + return; | |
| 12959 | + } | |
| 12960 | + let (width, height, frame_count) = (192usize, 128usize, 1usize); | |
| 12961 | + let mut named_refusals = 0u32; | |
| 12962 | + let mut matched = 0u32; | |
| 12963 | + let (mut horz_proved, mut vert_proved) = (0usize, 0usize); | |
| 12964 | + let (mut out_of_scope, mut out_of_scope_mismatch) = (0u32, 0u32); | |
| 12965 | + let n_attempts: u32 = std::env::var("EC_TX64X16_GATE_ATTEMPTS") | |
| 12966 | + .ok() | |
| 12967 | + .and_then(|s| s.parse().ok()) | |
| 12968 | + .unwrap_or(40); | |
| 12969 | + for attempt in 0..n_attempts { | |
| 12970 | + let seed = 42 + attempt; | |
| 12971 | + let duration = frame_count as f64 / 25.0; | |
| 12972 | + // Odd attempts render the SAME generator rotated 90 degrees | |
| 12973 | + // (generated at height x width, then `transpose`), because | |
| 12974 | + // aomenc's RD picks `PARTITION_VERT_4` on this content and | |
| 12975 | + // essentially never `HORZ_4`: the two arms are a transposed | |
| 12976 | + // pair, and a gate that only ever sees one of them cannot catch | |
| 12977 | + // a transposed scan/context table (class scan-weights-cross-axis). | |
| 12978 | + let source = if attempt % 2 == 0 { | |
| 12979 | + gradients_source(seed, width, height, &format!("duration={duration}:rate=25")) | |
| 12980 | + } else { | |
| 12981 | + format!( | |
| 12982 | + "{},transpose=1", | |
| 12983 | + gradients_source(seed, height, width, &format!("duration={duration}:rate=25")) | |
| 12984 | + ) | |
| 12985 | + }; | |
| 12986 | + let y4m = Command::new("ffmpeg") | |
| 12987 | + .args([ | |
| 12988 | + "-v", "error", "-f", "lavfi", "-i", &source, "-pix_fmt", "yuv420p", "-f", | |
| 12989 | + "yuv4mpegpipe", "-", | |
| 12990 | + ]) | |
| 12991 | + .stdin(Stdio::null()) | |
| 12992 | + .stdout(Stdio::piped()) | |
| 12993 | + .stderr(Stdio::piped()) | |
| 12994 | + .output() | |
| 12995 | + .expect("ffmpeg failed to run"); | |
| 12996 | + assert!( | |
| 12997 | + y4m.status.success(), | |
| 12998 | + "ffmpeg fixture: {}", | |
| 12999 | + String::from_utf8_lossy(&y4m.stderr) | |
| 13000 | + ); | |
| 13001 | + let args: Vec<&str> = vec![ | |
| 13002 | + "--codec=av1", | |
| 13003 | + "--passes=1", | |
| 13004 | + "--end-usage=q", | |
| 13005 | + "--cq-level=45", | |
| 13006 | + "--cpu-used=0", | |
| 13007 | + "--threads=1", | |
| 13008 | + "--row-mt=0", | |
| 13009 | + "--sb-size=64", | |
| 13010 | + "--enable-rect-partitions=1", | |
| 13011 | + "--enable-ab-partitions=0", | |
| 13012 | + "--enable-1to4-partitions=1", | |
| 13013 | + "--min-partition-size=16", | |
| 13014 | + "--max-partition-size=64", | |
| 13015 | + "--enable-restoration=0", | |
| 13016 | + "--enable-palette=0", | |
| 13017 | + "--deltaq-mode=0", | |
| 13018 | + "--enable-filter-intra=0", | |
| 13019 | + "--enable-cfl-intra=0", | |
| 13020 | + "--enable-intrabc=0", | |
| 13021 | + "--enable-tx-size-search=0", | |
| 13022 | + "--obu", | |
| 13023 | + "-o", | |
| 13024 | + "-", | |
| 13025 | + "-", | |
| 13026 | + ]; | |
| 13027 | + let mut child = Command::new(aomenc_path()) | |
| 13028 | + .args(&args) | |
| 13029 | + .stdin(Stdio::piped()) | |
| 13030 | + .stdout(Stdio::piped()) | |
| 13031 | + .stderr(Stdio::piped()) | |
| 13032 | + .spawn() | |
| 13033 | + .expect("aomenc failed to start"); | |
| 13034 | + child | |
| 13035 | + .stdin | |
| 13036 | + .take() | |
| 13037 | + .expect("aomenc stdin") | |
| 13038 | + .write_all(&y4m.stdout) | |
| 13039 | + .expect("writing y4m to aomenc"); | |
| 13040 | + let out = child.wait_with_output().expect("aomenc failed to run"); | |
| 13041 | + assert!( | |
| 13042 | + out.status.success(), | |
| 13043 | + "aomenc refused the fixture: {}", | |
| 13044 | + String::from_utf8_lossy(&out.stderr) | |
| 13045 | + ); | |
| 13046 | + let stream = out.stdout; | |
| 13047 | + let before = ( | |
| 13048 | + crate::decode::sb_rect4_horz_hits(), | |
| 13049 | + crate::decode::sb_rect4_vert_hits(), | |
| 13050 | + ); | |
| 13051 | + let frames = match decode_stream(&stream) { | |
| 13052 | + Err(e) => { | |
| 13053 | + let msg = e.to_string(); | |
| 13054 | + assert!( | |
| 13055 | + msg.contains("unsupported"), | |
| 13056 | + "{NAME} failed outright, not a named refusal (seed {seed}): {msg}" | |
| 13057 | + ); | |
| 13058 | + named_refusals += 1; | |
| 13059 | + eprintln!("seed {seed} refusal: {msg}"); | |
| 13060 | + continue; | |
| 13061 | + } | |
| 13062 | + Ok(frames) => frames, | |
| 13063 | + }; | |
| 13064 | + let (horz, vert) = ( | |
| 13065 | + crate::decode::sb_rect4_horz_hits() - before.0, | |
| 13066 | + crate::decode::sb_rect4_vert_hits() - before.1, | |
| 13067 | + ); | |
| 13068 | + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count); | |
| 13069 | + assert_eq!(frames.len(), frame_count); | |
| 13070 | + let mismatched = frames | |
| 13071 | + .iter() | |
| 13072 | + .zip(&ffmpeg_frames) | |
| 13073 | + .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v); | |
| 13074 | + if horz + vert == 0 { | |
| 13075 | + // Out of this gate's territory: aomenc's RD picked no 1:4 | |
| 13076 | + // partition at all for this seed, so the attempt can neither | |
| 13077 | + // prove nor disprove the arms under test. NOT silently | |
| 13078 | + // dropped -- counted and printed, and a mismatch here is | |
| 13079 | + // reported as a defect of another lane's shape (r1 found | |
| 13080 | + // one: seed 55 of this very recipe decodes 3944 wrong luma | |
| 13081 | + // samples with zero 1:4 blocks in the stream, first at | |
| 13082 | + // (154, 59), inside the 64x32 `PARTITION_HORZ` superblock at | |
| 13083 | + // (128, 64) -- see lanes/tx64x16-r1.report.md). Selecting on | |
| 13084 | + // "the stream contains the feature", never on "the stream | |
| 13085 | + // decoded correctly", is what keeps this from being survivor | |
| 13086 | + // bias. | |
| 13087 | + out_of_scope += 1; | |
| 13088 | + if mismatched { | |
| 13089 | + out_of_scope_mismatch += 1; | |
| 13090 | + eprintln!( | |
| 13091 | + "{NAME}: seed {seed} MISMATCHES with zero 1:4 blocks -- a pre-existing \ | |
| 13092 | + defect of another shape, not this gate's arms" | |
| 13093 | + ); | |
| 13094 | + } | |
| 13095 | + continue; | |
| 13096 | + } | |
| 13097 | + if mismatched { | |
| 13098 | + if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") { | |
| 13099 | + std::fs::write(&path, &stream).expect("writing pinned stream"); | |
| 13100 | + eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}"); | |
| 13101 | + } | |
| 13102 | + } | |
| 13103 | + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { | |
| 13104 | + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})"); | |
| 13105 | + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})"); | |
| 13106 | + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})"); | |
| 13107 | + } | |
| 13108 | + horz_proved += horz; | |
| 13109 | + vert_proved += vert; | |
| 13110 | + matched += 1; | |
| 13111 | + } | |
| 13112 | + assert!( | |
| 13113 | + matched > 0, | |
| 13114 | + "{NAME}: every attempt refused; the gate never decoded a stream" | |
| 13115 | + ); | |
| 13116 | + assert!( | |
| 13117 | + horz_proved > 0 && vert_proved > 0, | |
| 13118 | + "{NAME}: a 1:4 arm never fired inside a pixel-exact attempt \ | |
| 13119 | + (horz={horz_proved}, vert={vert_proved}, {matched} matches, {named_refusals} \ | |
| 13120 | + refusals out of {n_attempts}) -- gate proved nothing this run" | |
| 13121 | + ); | |
| 13122 | + eprintln!( | |
| 13123 | + "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of \ | |
| 13124 | + {n_attempts}, horz_4 strips={horz_proved}, vert_4 strips={vert_proved}, \ | |
| 13125 | + {out_of_scope} attempts carried no 1:4 block ({out_of_scope_mismatch} of them \ | |
| 13126 | + mismatched -- other lanes' shapes)" | |
| 13127 | + ); | |
| 13128 | + } | |
| 12936 | 13129 | } |
lanes/tx64x16-r1.report.mdadded+118 -0
| @@ -0,0 +1,118 @@ | ||
| 1 | +# lane-tx64x16 r1 — the 1:4 pair at 64x64 (TX_64X16 / TX_16X64) | |
| 2 | + | |
| 3 | +Branch `lane-tx64x16`, worktree `edith_codecs-tx64x16`, off main `dc5553f`. | |
| 4 | + | |
| 5 | +## STATUS: INCOMPLETE — gate RED. The refusal is narrowed in the code but NOT | |
| 6 | +proven: a real `PARTITION_VERT_4` stream with coefficients still mismatches. | |
| 7 | +Do not merge as is. | |
| 8 | + | |
| 9 | +## Premises re-measured (charter carried two stale ones) | |
| 10 | + | |
| 11 | +- "the refusal string now names the 1:4 pair" — FALSE at `dc5553f`. It read | |
| 12 | + *"a superblock-level partition type other than NONE or SPLIT"* | |
| 13 | + (`refusal_inventory.rs:48`) while `decode.rs` already coded HORZ/VERT; the AB | |
| 14 | + arms part32-r5 reports are NOT on main. Command: | |
| 15 | + `grep -n "64" crates/ec-av1/src/refusal_inventory.rs`. | |
| 16 | +- "requires the transform primitives (TX_64X16 / TX_16X64 …)" — FALSE. They | |
| 17 | + already exist: `inverse_transform_2d_typed_wh` (transform.rs:817) is generic | |
| 18 | + in (w,h), already zeroes everything past the low 32 on a 64-length axis | |
| 19 | + (`transform.rs:842`), already gets the rect scale right (fires only at | |
| 20 | + log2 ratio 1, i.e. never for 4:1 — `transform.rs:837`, and its comment | |
| 21 | + already names 16x64/64x16), and `row_shift_wh` (transform.rs:288) already | |
| 22 | + carries `(16,64)|(64,16) => 2` and `(8,32)|(32,8) => 2`, both verified | |
| 23 | + against `av1_inv_txfm_shift_ls` / `inv_shift_64x16` == `{-2,-4}` | |
| 24 | + (`~/.cache/aom-oracle/src/av1/common/av1_inv_txfm2d.c:150`). Dequant is | |
| 25 | + area-keyed (`dq_denom_area`), and `av1_get_tx_scale` is too (1024 pels → 1). | |
| 26 | + Nothing was owed here; the real work was entropy wiring + partition wiring. | |
| 27 | + | |
| 28 | +## What changed | |
| 29 | + | |
| 30 | +- `crates/ec-av1/src/decode.rs` | |
| 31 | + - `SCAN_32X8` / `SCAN_8X32` (new, ~line 1650): row-major transcriptions of | |
| 32 | + libaom `default_scan_32x8` / `default_scan_8x32`, converted with | |
| 33 | + `row*w+col = (p % h)*w + (p / h)` from libaom's COLUMN-major `p`. The rule | |
| 34 | + was validated by reproducing this repo's existing `SCAN_16X8` byte for byte | |
| 35 | + from `default_scan_16x8` before generating anything new — and libaom's | |
| 36 | + `default_scan_16x8` literal is byte-identical to this repo's `SCAN_8X16`, | |
| 37 | + i.e. a naive copy installs the transpose (class | |
| 38 | + reference-layout-not-spec). | |
| 39 | + - `decode_block_rect64`: luma corner generalised from a hardcoded 32x32 to | |
| 40 | + `(bw.min(32), bh.min(32))`, reading 32x16/16x32 through `read_coeffs_rect` | |
| 41 | + with `SCAN_32X16`/`SCAN_16X32` and `TxbSet::LumaRect32x16`; chroma set/scan | |
| 42 | + picked per shape, 32x8/8x32 reading `TxbSet::Chroma16` with the new scans. | |
| 43 | + Why no new CDF tables are owed, all read out of the oracle source: | |
| 44 | + `av1_get_adjusted_tx_size` maps TX_64X16→TX_32X16, TX_16X64→TX_16X32 | |
| 45 | + (`blockd.h:1361`); `av1_scan_orders` gives TX_64X16 `default_scan_32x16` | |
| 46 | + ("tx32's scan order is used", `scan.c`); `get_txsize_entropy_ctx` is 3 for | |
| 47 | + both TX_64X16 and TX_32X16 and 2 for both TX_32X8 and TX_16X16; | |
| 48 | + `txsize_log2_minus4` is 5 for TX_64X16 *and* TX_32X16, 4 for TX_32X8 *and* | |
| 49 | + TX_16X16 (`common_data.h:346`) so the eob alphabet matches too; and | |
| 50 | + `av1_nz_map_ctx_offset[TX_64X16]` is literally | |
| 51 | + `av1_nz_map_ctx_offset_32x16` (`txb_common.c:340`) — which is what | |
| 52 | + `base_ctx_rect(32,16)` computes, since both raw and coded dims are w>h. | |
| 53 | + - `PARTITION_HORZ_4`/`PARTITION_VERT_4` (8/9) wired at the superblock level: | |
| 54 | + four strips, `quarter_step` = 1 SUB unit, with libaom's `i > 0` frame-edge | |
| 55 | + break. | |
| 56 | + - New per-orientation hit counters `sb_rect4_horz_hits()` / | |
| 57 | + `sb_rect4_vert_hits()`. | |
| 58 | +- `crates/ec-av1/src/refusal_inventory.rs`: SB-level string narrowed to | |
| 59 | + "a superblock-level HORZ_A/HORZ_B/VERT_A/VERT_B partition (… codes NONE, | |
| 60 | + SPLIT, HORZ, VERT and the 1:4 pair at 64x64)". | |
| 61 | +- `crates/ec-av1/src/stream.rs`: new gate | |
| 62 | + `a_real_aomenc_stream_with_a_superblock_level_1to4_partition_decodes_pixel_exact`. | |
| 63 | +- `crates/ec-av1/fixtures/tx64x16-vert4-mismatch-seed73.obu`: the failing | |
| 64 | + stream, pinned. | |
| 65 | + | |
| 66 | +## Gate | |
| 67 | + | |
| 68 | +`cargo test -p ec-av1 --lib -- --exact stream::tests::a_real_aomenc_stream_with_a_superblock_level_1to4_partition_decodes_pixel_exact` | |
| 69 | +(`EC_TX64X16_GATE_ATTEMPTS`, default 40). aomenc recipe = the sbpart gate's, | |
| 70 | +with `--enable-1to4-partitions=1` and `--min-partition-size=16`; odd attempts | |
| 71 | +render the generator rotated 90 degrees (`transpose=1`) because aomenc picks | |
| 72 | +VERT_4 on this content and essentially never HORZ_4, and the two arms are a | |
| 73 | +transposed pair. Attempts whose decode fired zero 1:4 strips are counted and | |
| 74 | +printed, never asserted on — selection is on "the stream contains the | |
| 75 | +feature", never on "the stream decoded correctly". | |
| 76 | + | |
| 77 | +RESULT: **FAIL**. `seed 73` (a stream with four real 16x64 `PARTITION_VERT_4` | |
| 78 | +strips at mi(16,16..28)) mismatches ffmpeg: 10754 wrong luma samples, first at | |
| 79 | +(64, 56) — one row band ABOVE the strips, i.e. across the y=64 deblock edge. | |
| 80 | +An earlier 13-attempt run (before the transpose arm) had VERT_4 fire 4 strips | |
| 81 | +and decode PIXEL-EXACT, so the skip/low-energy case works and the coded case | |
| 82 | +does not. | |
| 83 | + | |
| 84 | +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` | |
| 85 | +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 | |
| 86 | + | |
| 87 | +## Open, with dispositions | |
| 88 | + | |
| 89 | +- **fix-now (r2)**: the coded-16x64 mismatch above. Not yet root-caused. | |
| 90 | + Ruled out by reading the oracle source, NOT by experiment: shift chain | |
| 91 | + (`inv_shift_64x16`/`inv_shift_16x64` = {-2,-4} = our `row_shift_wh` 2), rect | |
| 92 | + scale (4:1 gets none), dequant denominator (area 1024 → 2), eob alphabet | |
| 93 | + (512), CDF set, scan choice, nz-map offset table. Untested suspects, in | |
| 94 | + order: (1) the deblock grid for a 1:4 strip | |
| 95 | + (`fill_lf_grid_rect(.., tx_w=16, tx_h=64, 0)`) — the first diffs are on the | |
| 96 | + OTHER side of the edge; (2) 16x64 intra prediction edge reach; (3) the | |
| 97 | + chroma 8x32 plane. First move should be a prefilt dump | |
| 98 | + (`EC_AV1_PREFILT_DUMP`) to split "reconstruction wrong" from "deblock | |
| 99 | + wrong" — the diff band starting above the block is exactly the tell that | |
| 100 | + cost lane-tiny a round. | |
| 101 | +- **deferred(a green 64-level gate)**: the 32x32-level 1:4 arms. They ARE | |
| 102 | + requested by this recipe — `a 32x32 partition type this decoder does not | |
| 103 | + code (value=9)` appears in the sweep — and need TX_32X8/TX_8X32 luma | |
| 104 | + (`TxbSet::Luma16` exactly: entropy ctx 2, eob 256) plus 16x4/4x16 chroma | |
| 105 | + (`TxbSet::Chroma8`: ctx 1, eob 64) and two more scans. Same shape of work, | |
| 106 | + not started. | |
| 107 | +- **flagged, not this lane's shape (pre-existing)**: with | |
| 108 | + `--min-partition-size=16`, seed 55 of this recipe decodes 3944 wrong luma | |
| 109 | + samples with ZERO 1:4 blocks in the stream (trace: SB(1,0) SPLIT with a | |
| 110 | + 32x32 `PARTITION_HORZ`, SB(1,2) a 64x32 `PARTITION_HORZ`), first diff at | |
| 111 | + (154, 59). My diff cannot reach that stream (every path it touches needs a | |
| 112 | + 16-with-64 dimension pair), so it is a pre-existing defect of the 32x16 / | |
| 113 | + 64x32 strip shapes exposed by a recipe the existing sbpart gate | |
| 114 | + (`--min-partition-size=32`) never uses. Stream: rerun the gate with | |
| 115 | + `EC_AV1_GATE_DUMP` at `EC_TX64X16_GATE_ATTEMPTS=14`. | |
| 116 | +- **accepted**: `palette_bsize_ctx_wh` has no rect caller at all | |
| 117 | + (`read_intra_mode_rect` never reads a palette symbol), so 64x16/16x64 need | |
| 118 | + no entry there; a screen-content rect strip is a different lane's hole. |