diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index 8dd17bdb..a6f8fa03 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -36,6 +36,16 @@ fn main() { } let (sc, dp) = ec_av1::decode::reelc_chroma_counters(); println!("reelc_chroma: skip_cfl={sc} dir_1to4_pairs={dp}"); + println!( + "chroma422_square: {}", + ec_av1::decode::chroma422_square_hits() + ); + println!("chroma422_rect: {}", ec_av1::decode::chroma422_rect_hits()); + println!("chroma422_sub8: {}", ec_av1::decode::chroma422_sub8_hits()); + println!( + "chroma422_chunk: {}", + ec_av1::decode::chroma422_chunk_hits() + ); let (h, v, c) = ec_av1::stream::rect4_32_counters(); println!("rect4_32: horz={h} vert={v} coded={c}"); println!( diff --git a/crates/ec-av1/src/cdf.rs b/crates/ec-av1/src/cdf.rs index 2949967d..cf782582 100644 --- a/crates/ec-av1/src/cdf.rs +++ b/crates/ec-av1/src/cdf.rs @@ -290,21 +290,16 @@ pub const EOB_PT_512_LUMA_Q3: [u16; 11] = [ /// coded positions -- what a true 16x8/8x16 rectangular transform has /// (`txsize_log2_minus4` = 3), distinct from [`EOB_PT_256_CHROMA`]'s /// 256-position group a *square* 16x16 reads. -pub const EOB_PT_128_CHROMA: [u16; 9] = [ - 13627, 16246, 20173, 24429, 27948, 30415, 31863, 32768, 0, -]; +pub const EOB_PT_128_CHROMA: [u16; 9] = [13627, 16246, 20173, 24429, 27948, 30415, 31863, 32768, 0]; /// [`EOB_PT_128_CHROMA`], q-context 0. -pub const EOB_PT_128_CHROMA_Q0: [u16; 9] = [ - 5245, 7456, 12880, 15852, 20033, 23932, 27608, 32768, 0, -]; +pub const EOB_PT_128_CHROMA_Q0: [u16; 9] = + [5245, 7456, 12880, 15852, 20033, 23932, 27608, 32768, 0]; /// [`EOB_PT_128_CHROMA`], q-context 1. -pub const EOB_PT_128_CHROMA_Q1: [u16; 9] = [ - 8045, 11200, 15497, 19595, 23948, 27408, 30938, 32768, 0, -]; +pub const EOB_PT_128_CHROMA_Q1: [u16; 9] = + [8045, 11200, 15497, 19595, 23948, 27408, 30938, 32768, 0]; /// [`EOB_PT_128_CHROMA`], q-context 3. -pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [ - 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0, -]; +pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = + [24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0]; /// `av1_default_eob_multi128_cdfs[2][0][0]` (`token_cdfs.h:830-849`, /// lane-rectx): the end-of-block group of a LUMA transform with 128 coded @@ -313,21 +308,13 @@ pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [ /// 32x16/16x32), distinct from [`EOB_PT_256_LUMA`]'s 256-position group a /// *square* 16x16 reads. Read straight from the plane-0 half of the same /// `token_cdfs.h` table [`EOB_PT_128_CHROMA`] reads its plane-1 half from. -pub const EOB_PT_128_LUMA: [u16; 9] = [ - 1366, 1738, 2527, 5016, 9355, 15797, 24643, 32768, 0, -]; +pub const EOB_PT_128_LUMA: [u16; 9] = [1366, 1738, 2527, 5016, 9355, 15797, 24643, 32768, 0]; /// [`EOB_PT_128_LUMA`], q-context 0. -pub const EOB_PT_128_LUMA_Q0: [u16; 9] = [ - 219, 482, 1140, 2091, 3680, 6028, 12586, 32768, 0, -]; +pub const EOB_PT_128_LUMA_Q0: [u16; 9] = [219, 482, 1140, 2091, 3680, 6028, 12586, 32768, 0]; /// [`EOB_PT_128_LUMA`], q-context 1. -pub const EOB_PT_128_LUMA_Q1: [u16; 9] = [ - 685, 933, 1488, 2714, 4766, 8562, 19254, 32768, 0, -]; +pub const EOB_PT_128_LUMA_Q1: [u16; 9] = [685, 933, 1488, 2714, 4766, 8562, 19254, 32768, 0]; /// [`EOB_PT_128_LUMA`], q-context 3. -pub const EOB_PT_128_LUMA_Q3: [u16; 9] = [ - 3472, 4885, 7489, 12481, 18517, 24536, 29635, 32768, 0, -]; +pub const EOB_PT_128_LUMA_Q3: [u16; 9] = [3472, 4885, 7489, 12481, 18517, 24536, 29635, 32768, 0]; /// `av1_default_eob_multi32_cdfs[2][1][0]` (`token_cdfs.h:792-808`, /// lane-rectx): the end-of-block group of a CHROMA transform with 32 coded @@ -1824,20 +1811,20 @@ pub const WEDGE_IDX: [[u16; 17]; 22] = [ 29629, 32768, 0, ], [ - 2779, 3738, 4683, 7213, 7775, 8017, 8655, 14357, 17939, 21332, 24520, 27470, 29456, - 30529, 31656, 32768, 0, + 2779, 3738, 4683, 7213, 7775, 8017, 8655, 14357, 17939, 21332, 24520, 27470, 29456, 30529, + 31656, 32768, 0, ], [ 1684, 3625, 5675, 7108, 9302, 11274, 14429, 17144, 19163, 20961, 22884, 24471, 26719, 28714, 30877, 32768, 0, ], [ - 1142, 3491, 6277, 7314, 8089, 8355, 9023, 13624, 15369, 16730, 18114, 19313, 22521, - 26012, 29550, 32768, 0, + 1142, 3491, 6277, 7314, 8089, 8355, 9023, 13624, 15369, 16730, 18114, 19313, 22521, 26012, + 29550, 32768, 0, ], [ - 2742, 4195, 5727, 8035, 8980, 9336, 10146, 14124, 17270, 20533, 23434, 25972, 27944, - 29570, 31416, 32768, 0, + 2742, 4195, 5727, 8035, 8980, 9336, 10146, 14124, 17270, 20533, 23434, 25972, 27944, 29570, + 31416, 32768, 0, ], [ 1727, 3948, 6101, 7796, 9841, 12344, 15766, 18944, 20638, 22038, 23963, 25311, 26988, @@ -1880,8 +1867,8 @@ pub const WEDGE_IDX: [[u16; 17]; 22] = [ 30911, 32768, 0, ], [ - 1135, 1322, 1493, 2635, 2696, 2737, 2770, 21016, 22935, 25057, 27251, 29173, 30089, - 30960, 31933, 32768, 0, + 1135, 1322, 1493, 2635, 2696, 2737, 2770, 21016, 22935, 25057, 27251, 29173, 30089, 30960, + 31933, 32768, 0, ], [ 2048, 4096, 6144, 8192, 10240, 12288, 14336, 16384, 18432, 20480, 22528, 24576, 26624, @@ -3179,6 +3166,19 @@ pub const TXB_SKIP_CHROMA_8_Q3: [[u16; 3]; 3] = /// TXB_SKIP_CHROMA_16, q-context 3: the same table as [`TXB_SKIP_CHROMA_16`], for `base_q_idx` 121..=255. pub const TXB_SKIP_CHROMA_16_Q3: [[u16; 3]; 3] = [[3440, 32768, 0], [13117, 32768, 0], [22702, 32768, 0]]; + +/// `av1_default_txb_skip_cdfs[q][TX_8X8][10..13]` (token_cdfs.h): the chroma +/// `+10` rows of an 8x8 transform. libaom leaves every q-context at the +/// neutral 16384 -- its own encoder never codes an 8x8 chroma transform under +/// a larger plane block (4:2:0/4:4:4 always match plane to transform at this +/// size) -- but `get_txb_ctx`'s `+10` arm reaches them the moment a 4:2:2 +/// frame's 16x16 luma block reads its plane's 8x16 half as two TX_8X8 units +/// (lane-av1-422b; aomdec seeds and adapts the same neutral rows). +pub const TXB_SKIP_CHROMA_8_BIG: [[u16; 3]; 3] = [[16384, 32768, 0]; 3]; +/// `av1_default_txb_skip_cdfs[q][TX_16X16][10..13]` (token_cdfs.h): the same +/// neutral `+10` rows at 16x16 (libaom encoder-unreachable, 4:2:2-reachable +/// through a 32x32 luma block's 16x32 plane -- lane-av1-422b). +pub const TXB_SKIP_CHROMA_16_BIG: [[u16; 3]; 3] = [[16384, 32768, 0]; 3]; /// TXB_SKIP_CHROMA_32, q-context 3: the same table as [`TXB_SKIP_CHROMA_32`], for `base_q_idx` 121..=255. pub const TXB_SKIP_CHROMA_32_Q3: [[u16; 3]; 3] = [[4656, 32768, 0], [16074, 32768, 0], [24704, 32768, 0]]; @@ -3188,13 +3188,17 @@ pub const TXB_SKIP_CHROMA_32_Q3: [[u16; 3]; 3] = /// LARGER than the transform (`get_txb_ctx`), which in AV1 happens only for a /// 128x128 block's four TX_32X32 chroma units -- the offset-7 rows above are /// every other case (lane-sb128b r3). -pub const TXB_SKIP_CHROMA_32_BIG_Q0: [[u16; 3]; 3] = [[146, 32768, 0], [5132, 32768, 0], [31657, 32768, 0]]; +pub const TXB_SKIP_CHROMA_32_BIG_Q0: [[u16; 3]; 3] = + [[146, 32768, 0], [5132, 32768, 0], [31657, 32768, 0]]; /// Default CDF table `TXB_SKIP_CHROMA_32_BIG_Q1` (AV1 spec 9.4 initial probabilities). -pub const TXB_SKIP_CHROMA_32_BIG_Q1: [[u16; 3]; 3] = [[641, 32768, 0], [22265, 32768, 0], [31452, 32768, 0]]; +pub const TXB_SKIP_CHROMA_32_BIG_Q1: [[u16; 3]; 3] = + [[641, 32768, 0], [22265, 32768, 0], [31452, 32768, 0]]; /// Default CDF table `TXB_SKIP_CHROMA_32_BIG` (AV1 spec 9.4 initial probabilities). -pub const TXB_SKIP_CHROMA_32_BIG: [[u16; 3]; 3] = [[3082, 32768, 0], [20982, 32768, 0], [29443, 32768, 0]]; +pub const TXB_SKIP_CHROMA_32_BIG: [[u16; 3]; 3] = + [[3082, 32768, 0], [20982, 32768, 0], [29443, 32768, 0]]; /// Default CDF table `TXB_SKIP_CHROMA_32_BIG_Q3` (AV1 spec 9.4 initial probabilities). -pub const TXB_SKIP_CHROMA_32_BIG_Q3: [[u16; 3]; 3] = [[1806, 32768, 0], [14645, 32768, 0], [25336, 32768, 0]]; +pub const TXB_SKIP_CHROMA_32_BIG_Q3: [[u16; 3]; 3] = + [[1806, 32768, 0], [14645, 32768, 0], [25336, 32768, 0]]; /// EOB_EXTRA_LUMA_16, q-context 3: the same table as [`EOB_EXTRA_LUMA_16`], for `base_q_idx` 121..=255. pub const EOB_EXTRA_LUMA_16_Q3: [[u16; 3]; 9] = [ [19941, 32768, 0], @@ -5374,27 +5378,28 @@ pub const EOB_PT_256_LUMA_CLASS1_Q3: [u16; 10] = [2453, 4474, 6307, 8777, 16474, 22975, 29000, 31547, 32768, 0]; /// Default CDF table `EOB_PT_256_CHROMA_CLASS1_Q0` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_256_CHROMA_CLASS1_Q0: [u16; 10] = - [2203, 4130, 7435, 10739, 20652, 23681, 25609, 27261, 32768, 0]; +pub const EOB_PT_256_CHROMA_CLASS1_Q0: [u16; 10] = [ + 2203, 4130, 7435, 10739, 20652, 23681, 25609, 27261, 32768, 0, +]; /// Default CDF table `EOB_PT_256_CHROMA_CLASS1_Q1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_256_CHROMA_CLASS1_Q1: [u16; 10] = - [1674, 3252, 5734, 10159, 22397, 23802, 24821, 30940, 32768, 0]; +pub const EOB_PT_256_CHROMA_CLASS1_Q1: [u16; 10] = [ + 1674, 3252, 5734, 10159, 22397, 23802, 24821, 30940, 32768, 0, +]; /// Default CDF table `EOB_PT_256_CHROMA_CLASS1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_256_CHROMA_CLASS1: [u16; 10] = - [6571, 9610, 15516, 21826, 29092, 30829, 31842, 32708, 32768, 0]; +pub const EOB_PT_256_CHROMA_CLASS1: [u16; 10] = [ + 6571, 9610, 15516, 21826, 29092, 30829, 31842, 32708, 32768, 0, +]; /// Default CDF table `EOB_PT_256_CHROMA_CLASS1_Q3` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_256_CHROMA_CLASS1_Q3: [u16; 10] = - [9998, 17661, 25178, 28097, 31308, 32038, 32403, 32695, 32768, 0]; +pub const EOB_PT_256_CHROMA_CLASS1_Q3: [u16; 10] = [ + 9998, 17661, 25178, 28097, 31308, 32038, 32403, 32695, 32768, 0, +]; /// Default CDF table `EOB_PT_64_CHROMA_CLASS1_Q0` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_64_CHROMA_CLASS1_Q0: [u16; 8] = - [1563, 2700, 4876, 10911, 14706, 22480, 32768, 0]; +pub const EOB_PT_64_CHROMA_CLASS1_Q0: [u16; 8] = [1563, 2700, 4876, 10911, 14706, 22480, 32768, 0]; /// Default CDF table `EOB_PT_64_CHROMA_CLASS1_Q1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_64_CHROMA_CLASS1_Q1: [u16; 8] = - [1923, 3127, 5867, 9703, 14277, 27100, 32768, 0]; +pub const EOB_PT_64_CHROMA_CLASS1_Q1: [u16; 8] = [1923, 3127, 5867, 9703, 14277, 27100, 32768, 0]; /// Default CDF table `EOB_PT_64_CHROMA_CLASS1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_64_CHROMA_CLASS1: [u16; 8] = - [4034, 6290, 10235, 14982, 21214, 28491, 32768, 0]; +pub const EOB_PT_64_CHROMA_CLASS1: [u16; 8] = [4034, 6290, 10235, 14982, 21214, 28491, 32768, 0]; /// Default CDF table `EOB_PT_64_CHROMA_CLASS1_Q3` (AV1 spec 9.4 initial probabilities). pub const EOB_PT_64_CHROMA_CLASS1_Q3: [u16; 8] = [8726, 12378, 19409, 26450, 30038, 32462, 32768, 0]; @@ -5411,13 +5416,15 @@ pub const EOB_PT_16_CHROMA_CLASS1_Q3: [u16; 6] = [7297, 10767, 19273, 28194, 327 /// `EOB_PT_128_LUMA`'s class-1 sibling (`av1_default_eob_multi128_cdfs[q][0][1]`), /// read by a 16x8/8x16 luma transform whose inherited `tx_type` is 1D /// (`TxbSet::LumaRect16x8`) -- machine-extracted, scripts/extract-eob-class1.py. -pub const EOB_PT_128_LUMA_CLASS1_Q0: [u16; 9] = [371, 699, 1254, 4830, 9479, 12562, 17497, 32768, 0]; +pub const EOB_PT_128_LUMA_CLASS1_Q0: [u16; 9] = + [371, 699, 1254, 4830, 9479, 12562, 17497, 32768, 0]; /// Default CDF table `EOB_PT_128_LUMA_CLASS1_Q1` (AV1 spec 9.4 initial probabilities). pub const EOB_PT_128_LUMA_CLASS1_Q1: [u16; 9] = [217, 352, 618, 2303, 5261, 9969, 17472, 32768, 0]; /// Default CDF table `EOB_PT_128_LUMA_CLASS1` (AV1 spec 9.4 initial probabilities). pub const EOB_PT_128_LUMA_CLASS1: [u16; 9] = [354, 558, 944, 2760, 7287, 14037, 21779, 32768, 0]; /// Default CDF table `EOB_PT_128_LUMA_CLASS1_Q3` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_128_LUMA_CLASS1_Q3: [u16; 9] = [886, 1731, 3271, 8469, 15569, 22126, 28383, 32768, 0]; +pub const EOB_PT_128_LUMA_CLASS1_Q3: [u16; 9] = + [886, 1731, 3271, 8469, 15569, 22126, 28383, 32768, 0]; /// `EOB_PT_32_CHROMA`'s class-1 sibling (`av1_default_eob_multi32_cdfs[q][1][1]`), /// read by an 8x4/4x8 chroma transform under a 1D luma `tx_type` @@ -5431,47 +5438,82 @@ pub const EOB_PT_32_CHROMA_CLASS1: [u16; 7] = [3542, 5502, 10415, 16760, 25644, pub const EOB_PT_32_CHROMA_CLASS1_Q3: [u16; 7] = [7699, 10897, 20891, 26926, 31628, 32768, 0]; /// `EOB_PT_128_CHROMA`'s class-1 sibling (`av1_default_eob_multi128_cdfs[q][1][1]`). -pub const EOB_PT_128_CHROMA_CLASS1_Q0: [u16; 9] = [2054, 3472, 5869, 14232, 18242, 20590, 26752, 32768, 0]; +pub const EOB_PT_128_CHROMA_CLASS1_Q0: [u16; 9] = + [2054, 3472, 5869, 14232, 18242, 20590, 26752, 32768, 0]; /// Default CDF table `EOB_PT_128_CHROMA_CLASS1_Q1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_128_CHROMA_CLASS1_Q1: [u16; 9] = [2310, 4160, 7471, 14997, 17931, 20768, 30240, 32768, 0]; +pub const EOB_PT_128_CHROMA_CLASS1_Q1: [u16; 9] = + [2310, 4160, 7471, 14997, 17931, 20768, 30240, 32768, 0]; /// Default CDF table `EOB_PT_128_CHROMA_CLASS1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_128_CHROMA_CLASS1: [u16; 9] = [6275, 9889, 14769, 23164, 27988, 30493, 32272, 32768, 0]; +pub const EOB_PT_128_CHROMA_CLASS1: [u16; 9] = + [6275, 9889, 14769, 23164, 27988, 30493, 32272, 32768, 0]; /// Default CDF table `EOB_PT_128_CHROMA_CLASS1_Q3` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_128_CHROMA_CLASS1_Q3: [u16; 9] = [9165, 13282, 21150, 30286, 31894, 32571, 32712, 32768, 0]; +pub const EOB_PT_128_CHROMA_CLASS1_Q3: [u16; 9] = + [9165, 13282, 21150, 30286, 31894, 32571, 32712, 32768, 0]; /// `EOB_PT_512_LUMA`'s class-1 sibling (`av1_default_eob_multi512_cdfs[q][0][1]`). -pub const EOB_PT_512_LUMA_CLASS1_Q0: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_LUMA_CLASS1_Q0: [u16; 11] = [ + 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, +]; /// Default CDF table `EOB_PT_512_LUMA_CLASS1_Q1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_512_LUMA_CLASS1_Q1: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_LUMA_CLASS1_Q1: [u16; 11] = [ + 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, +]; /// Default CDF table `EOB_PT_512_LUMA_CLASS1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_512_LUMA_CLASS1: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_LUMA_CLASS1: [u16; 11] = [ + 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, +]; /// Default CDF table `EOB_PT_512_LUMA_CLASS1_Q3` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_512_LUMA_CLASS1_Q3: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_LUMA_CLASS1_Q3: [u16; 11] = [ + 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, +]; /// `EOB_PT_512_CHROMA`'s class-1 sibling (`av1_default_eob_multi512_cdfs[q][1][1]`). -pub const EOB_PT_512_CHROMA_CLASS1_Q0: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_CHROMA_CLASS1_Q0: [u16; 11] = [ + 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, +]; /// Default CDF table `EOB_PT_512_CHROMA_CLASS1_Q1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_512_CHROMA_CLASS1_Q1: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_CHROMA_CLASS1_Q1: [u16; 11] = [ + 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, +]; /// Default CDF table `EOB_PT_512_CHROMA_CLASS1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_512_CHROMA_CLASS1: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_CHROMA_CLASS1: [u16; 11] = [ + 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, +]; /// Default CDF table `EOB_PT_512_CHROMA_CLASS1_Q3` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_512_CHROMA_CLASS1_Q3: [u16; 11] = [3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0]; +pub const EOB_PT_512_CHROMA_CLASS1_Q3: [u16; 11] = [ + 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0, +]; /// `EOB_PT_1024_LUMA`'s class-1 sibling (`av1_default_eob_multi1024_cdfs[q][0][1]`). -pub const EOB_PT_1024_LUMA_CLASS1_Q0: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_LUMA_CLASS1_Q0: [u16; 12] = [ + 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0, +]; /// Default CDF table `EOB_PT_1024_LUMA_CLASS1_Q1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_1024_LUMA_CLASS1_Q1: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_LUMA_CLASS1_Q1: [u16; 12] = [ + 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0, +]; /// Default CDF table `EOB_PT_1024_LUMA_CLASS1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_1024_LUMA_CLASS1: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_LUMA_CLASS1: [u16; 12] = [ + 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0, +]; /// Default CDF table `EOB_PT_1024_LUMA_CLASS1_Q3` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_1024_LUMA_CLASS1_Q3: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_LUMA_CLASS1_Q3: [u16; 12] = [ + 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0, +]; /// `EOB_PT_1024_CHROMA`'s class-1 sibling (`av1_default_eob_multi1024_cdfs[q][1][1]`). -pub const EOB_PT_1024_CHROMA_CLASS1_Q0: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_CHROMA_CLASS1_Q0: [u16; 12] = [ + 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0, +]; /// Default CDF table `EOB_PT_1024_CHROMA_CLASS1_Q1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_1024_CHROMA_CLASS1_Q1: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_CHROMA_CLASS1_Q1: [u16; 12] = [ + 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0, +]; /// Default CDF table `EOB_PT_1024_CHROMA_CLASS1` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_1024_CHROMA_CLASS1: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; +pub const EOB_PT_1024_CHROMA_CLASS1: [u16; 12] = [ + 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0, +]; /// Default CDF table `EOB_PT_1024_CHROMA_CLASS1_Q3` (AV1 spec 9.4 initial probabilities). -pub const EOB_PT_1024_CHROMA_CLASS1_Q3: [u16; 12] = [2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0]; - +pub const EOB_PT_1024_CHROMA_CLASS1_Q3: [u16; 12] = [ + 2979, 5958, 8937, 11916, 14895, 17873, 20852, 23831, 26810, 29789, 32768, 0, +]; diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index 27c3e006..d43d1588 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -400,7 +400,7 @@ pub(crate) struct Cdfs { /// The same, for a 4x4 luma transform (lane-av1tx4). pub txb_skip_luma_4: [[u16; 3]; 7], /// The all-zero flag of an 8x8 chroma transform. - pub txb_skip_chroma_8: [[u16; 3]; 3], + pub txb_skip_chroma_8: [[u16; 3]; 6], /// The all-zero flag of a 4x4 chroma transform. /// lane-lossless: SIX rows, like [`Self::txb_skip_chroma_32`] -- the last /// three are `get_txb_ctx`'s `+10` rows (chroma plane block bigger than @@ -500,7 +500,7 @@ pub(crate) struct Cdfs { /// The same, for a 64x64 luma transform. pub txb_skip_luma_64: [[u16; 3]; 7], /// The all-zero flag of a 16x16 chroma transform. - pub txb_skip_chroma_16: [[u16; 3]; 3], + pub txb_skip_chroma_16: [[u16; 3]; 6], /// The all-zero flag of a 32x32 chroma transform. /// SIX contexts, not three: rows 0..3 are libaom's `txb_skip_ctx` 7..9 /// (chroma transform == its plane block) and rows 3..6 its 10..12 (plane @@ -828,9 +828,7 @@ fn reset3(a: &mut [[[u16; N]; M] /// [`reset3`] for a table whose ALPHABET grows with its first index: the /// palette colour-index CDFs are `[u16; 9]` rows read as `[..=n]` with /// `n = idx + 2`, so their symbol counter sits at index `n`, not `N - 1`. -fn reset_var_alphabet( - a: &mut [[[u16; N]; M]; K], -) { +fn reset_var_alphabet(a: &mut [[[u16; N]; M]; K]) { for (idx, rows) in a.iter_mut().enumerate() { for row in rows.iter_mut() { row[idx + 2] = 0; @@ -1067,13 +1065,27 @@ impl Cdfs { cdf::TXB_SKIP_LUMA_4_CTX, cdf::TXB_SKIP_LUMA_4_Q3_CTX, ), - txb_skip_chroma_8: pick( - q_ctx, - cdf::TXB_SKIP_CHROMA_8_Q0, - cdf::TXB_SKIP_CHROMA_8_Q1, - cdf::TXB_SKIP_CHROMA_8, - cdf::TXB_SKIP_CHROMA_8_Q3, - ), + txb_skip_chroma_8: { + // lane-av1-422b: rows 3..6 are the `+10` chroma rows + // (`TXB_SKIP_CHROMA_8_BIG`) -- neutral in libaom's defaults, + // reached only when the plane block is larger than an 8x8 + // transform, i.e. only at 4:2:2 today. + let small = pick( + q_ctx, + cdf::TXB_SKIP_CHROMA_8_Q0, + cdf::TXB_SKIP_CHROMA_8_Q1, + cdf::TXB_SKIP_CHROMA_8, + cdf::TXB_SKIP_CHROMA_8_Q3, + ); + [ + small[0], + small[1], + small[2], + cdf::TXB_SKIP_CHROMA_8_BIG[0], + cdf::TXB_SKIP_CHROMA_8_BIG[1], + cdf::TXB_SKIP_CHROMA_8_BIG[2], + ] + }, txb_skip_chroma_4: { let small = pick( q_ctx, @@ -1387,13 +1399,27 @@ impl Cdfs { cdf::TXB_SKIP_LUMA_64_CTX, cdf::TXB_SKIP_LUMA_64_Q3_CTX, ), - txb_skip_chroma_16: pick( - q_ctx, - cdf::TXB_SKIP_CHROMA_16_Q0, - cdf::TXB_SKIP_CHROMA_16_Q1, - cdf::TXB_SKIP_CHROMA_16, - cdf::TXB_SKIP_CHROMA_16_Q3, - ), + txb_skip_chroma_16: { + // lane-av1-422b: rows 3..6 are the `+10` chroma rows + // (`TXB_SKIP_CHROMA_16_BIG`) -- neutral in libaom's defaults, + // reached only when the plane block is larger than a 16x16 + // transform, i.e. only at 4:2:2 today. + let small = pick( + q_ctx, + cdf::TXB_SKIP_CHROMA_16_Q0, + cdf::TXB_SKIP_CHROMA_16_Q1, + cdf::TXB_SKIP_CHROMA_16, + cdf::TXB_SKIP_CHROMA_16_Q3, + ); + [ + small[0], + small[1], + small[2], + cdf::TXB_SKIP_CHROMA_16_BIG[0], + cdf::TXB_SKIP_CHROMA_16_BIG[1], + cdf::TXB_SKIP_CHROMA_16_BIG[2], + ] + }, txb_skip_chroma_32: { let small = pick( q_ctx, diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 55e381d7..1816ffbd 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1517,6 +1517,36 @@ fn tu_reach( fixed } +/// [`tu_reach`] for a unit whose LUMA footprint is a `tx_w` x `tx_h` rect +/// (lane-av1-422b: a 4:2:2 chroma unit is square in chroma pixels, but its +/// luma anchor is `(chroma_tx << ss_x, chroma_tx << ss_y)` -- at ss (1,0) +/// twice as wide as it is tall). Same predicate as [`tu_reach`]; the +/// square mismatch counter only means anything when the footprint actually +/// is square. +#[allow(clippy::too_many_arguments)] +fn tu_reach_rect( + bw: usize, + bh: usize, + col_off: usize, + row_off: usize, + tx_w: usize, + tx_h: usize, + block: Reach, + px: usize, + py: usize, + width: usize, + height: usize, fctx: &crate::decode::FrameCtx, +) -> Reach { + let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx_w, tx_h, block); + if tx_w == tx_h { + let standalone = Reach::of(tx_w, px + col_off, py + row_off, width, height, fctx); + if fixed != standalone { + hit!(SPLIT_TU_REACH_FIX_HITS); + } + } + fixed +} + // How many `uv_mode` reads resolved to `SMOOTH_PRED..=PAETH_PRED` (9..=12), // across every call on the current thread -- lane-chroma r3's own before/after // counter, proving a stream actually exercised chroma's smooth/paeth @@ -1998,6 +2028,85 @@ pub(crate) fn rect_split_chroma_shape_hits() -> [usize; 4] { RECT_SPLIT_CHROMA_SHAPE_HITS.with(|c| c.get()) } +// lane-av1-422: how many SQUARE chroma coefficient units the strip path read +// on a 4:2:2 frame (ss 1,0) -- the half-width, unhalved-height shape whose +// tables only exist because of the square rows in the chroma_tiled arm. A +// 4:2:0 or 4:4:4 frame can never increment it (their rect strips' chroma is +// itself rect), and a restored `/2 chroma height` diverts 4:2:2 squares onto +// the rect rows, so the witness gate reads 0 there and fails. +thread_local! { + static CHROMA422_SQUARE_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`CHROMA422_SQUARE_HITS`]. +// lane-av1-422b: `pub` so `examples/decode_probe.rs` can census it the way +// it does every other capability counter. +pub fn chroma422_square_hits() -> usize { + CHROMA422_SQUARE_HITS.with(|c| c.get()) +} + +// lane-av1-422f: how many RECT chroma coefficient units the square-block +// path read on a 4:2:2 frame (ss 1,0) -- TX_4X8 / TX_8X16 / TX_16X32, the +// plane block's own half-width, unhalved-height shape. A 4:2:0 or 4:4:4 +// frame never takes the rect branch (their units are square +// `chroma_tx == chroma_tx_h`), so a witness gate reading 0 here proves the +// model reverted to squares. +thread_local! { + static CHROMA422_RECT_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`CHROMA422_RECT_HITS`]. +pub fn chroma422_rect_hits() -> usize { + CHROMA422_RECT_HITS.with(|c| c.get()) +} + +// lane-av1-422g: how many PER-LEAF TX_4X4 chroma coefficient units the +// sub-8x8 split4 path read on a 4:2:2 frame (ss 1,0) -- one per even-column +// leaf per plane (`is_chroma_reference`'s `!(mi_col & ss_x)`). A 4:2:0 frame +// codes no sub-8 chroma at all and 4:4:4 goes through `sub8_leaf_chroma444`, +// so a witness gate reading 0 here proves the per-leaf 4:2:2 arm never ran. +thread_local! { + static CHROMA422_SUB8_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`CHROMA422_SUB8_HITS`]. +pub fn chroma422_sub8_hits() -> usize { + CHROMA422_SUB8_HITS.with(|c| c.get()) +} + +// lane-av1-422sub8rect: how many PER-PIECE TX_4X4 chroma coefficient units +// the INTER sub-8x8 split4 path read on a 4:2:2 frame (ss 1,0) -- one per +// non-skipped odd-column piece per plane (`is_chroma_reference`'s +// `mi_col & 0x01` at ss_x 1). 4:2:0 goes through the shared group unit and +// 4:4:4 through [`sub8_leaf_chroma444`]'s own per-piece twin, so a witness +// gate reading 0 here proves the inter 4:2:2 per-piece arm never ran. +thread_local! { + static CHROMA422_INTER_SUB8_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`CHROMA422_INTER_SUB8_HITS`]. +pub fn chroma422_inter_sub8_hits() -> usize { + CHROMA422_INTER_SUB8_HITS.with(|c| c.get()) +} + +// lane-av1-422m: how many TX_4X4 chunk units the invalid-ss-size chroma arm +// read (the 8x32 luma block whose 4:2:2 plane has no `ss_size_lookup` block). +// A 4:2:0 or 4:4:4 frame cannot increment it, so a non-zero read proves the +// chunked 4:2:2 chroma really decoded. +thread_local! { + static CHROMA422_CHUNK_HITS: std::cell::Cell = + const { std::cell::Cell::new(0) }; +} + +/// Current value of [`CHROMA422_CHUNK_HITS`]. +pub fn chroma422_chunk_hits() -> usize { + CHROMA422_CHUNK_HITS.with(|c| c.get()) +} + // How many HORZ/VERT intra strips actually predicted with filter intra // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name // ("this decoder predicts square-only") until `predict_filter_intra` took @@ -2583,7 +2692,10 @@ impl TxParams { if self.stride == 0 { return residual; } - let mut strided = vec![0i32; self.stride * self.stride]; + // lane-av1-422sub8rect: `h` rows of `stride` -- a rect unit whose + // height exceeds its (narrow) prediction stride needs the full + // stride * h; every square caller has h == stride and is unchanged. + let mut strided = vec![0i32; self.stride * self.h]; for row in 0..self.h { strided[row * self.stride..][..self.w] .copy_from_slice(&residual[row * self.w..][..self.w]); @@ -8521,6 +8633,46 @@ impl Neighbours { out } + /// [`Self::around_mi_rect`] for the CHROMA planes of a 4:2:2 frame + /// (lane-av1-422f): libaom `get_txb_ctx_general` reads its above votes + /// over `txb_w_unit` CHROMA 4-px cells, and at ss_x 1 one chroma cell + /// spans TWO luma mi columns. Both cells of a column carry the covering + /// unit's whole-unit dc sign (the same value libaom stores), so the + /// per-luma-mi sum counts each chroma column twice -- and + /// `dc_sign_ctx`'s signum flips whenever the above and left votes have + /// opposite signs with equal magnitude (measured at mi(4,4) plane 1 of + /// the t422 fixture: ours read `dc_sign_cdf[1]`, the oracle row 0). + /// Sampling every second above cell counts each chroma column once, + /// which IS libaom's sum. The left extent is unsubsquared at ss_y 0, so + /// its per-mi cells already line up one-to-one. The level booleans are + /// ORs over duplicated cells, so the sampling cannot change them. + fn around_mi_422_chroma( + &self, + (mi_r, mi_c): (usize, usize), + w: usize, + h: usize, + ) -> [(bool, bool, i32); 3] { + let (w_mi, h_mi) = (w / MI, h / MI); + let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c)); + let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r)); + let mut out = [(false, false, 0i32); 3]; + for cell in (0..above_mi).step_by(2) { + let above = &self.above[mi_c + cell]; + for (plane, o) in out.iter_mut().enumerate() { + o.0 |= above[plane].level != 0; + o.2 += dc_vote(above[plane].dc); + } + } + for cell in 0..left_mi { + let left = &self.left[mi_r + cell]; + for (plane, o) in out.iter_mut().enumerate() { + o.1 |= left[plane].level != 0; + o.2 += dc_vote(left[plane].dc); + } + } + out + } + /// [`Self::around`] with independent above (`w`)/left (`h`) extents, in /// pixels -- lane-rectwire, mirrors [`Self::record_rect`]'s asymmetric /// extent pattern for a true rectangular strip's own coefficient context. @@ -10177,7 +10329,15 @@ fn decode_rect_split( // A 4:4:4 64-axis strip's chroma plane block is larger than one adjusted // UV transform (TX_64X32 adjusts to TX_32X32). Those sizes are tiled // below; everything else still needs a single-unit table. - let chroma_tiled = matches!((chroma_w, chroma_h), (64, 32) | (32, 64) | (64, 16) | (16, 64)); + // lane-av1-422: a 4:2:2 strip's chroma plane keeps the strip's HEIGHT and + // halves only the width, so a rect luma strip codes a SQUARE chroma block + // (16x8 luma -> 8x8 chroma) -- the square rows below. At 4:2:0 and 4:4:4 a + // rect strip's chroma is itself rect, so the square rows are unreachable + // there and cannot change their results. + let chroma_tiled = matches!( + (chroma_w, chroma_h), + (64, 32) | (32, 64) | (64, 16) | (16, 64) | (32, 32) | (16, 16) | (8, 8) + ); if !m.skip { if let Some(i) = match (chroma_w, chroma_h) { (32, 8) => Some(0), @@ -10604,11 +10764,20 @@ fn decode_rect_split( (ug, vg) } else if chroma_tiled { let (uw, uh, set, scan): (usize, usize, TxbSet, &[u16]) = match (chroma_w, chroma_h) { - (64, 32) | (32, 64) => (32, 32, TxbSet::Chroma32, default_scan(32)), + (64, 32) | (32, 64) | (32, 32) => (32, 32, TxbSet::Chroma32, default_scan(32)), (64, 16) => (32, 16, TxbSet::ChromaRect32x16, &SCAN_32X16), (16, 64) => (16, 32, TxbSet::ChromaRect32x16, &SCAN_16X32), + // lane-av1-422: the 4:2:2 square chroma planes (height unhalved), + // through the square reader like every other square chroma unit. + (16, 16) => (16, 16, TxbSet::Chroma16, default_scan(16)), + (8, 8) => (8, 8, TxbSet::Chroma8, default_scan(8)), _ => unreachable!("chroma_tiled"), }; + // lane-av1-422: the witness counter, keyed to ss (1,0) so only a 4:2:2 + // frame's square chroma units count it. + if uw == uh && ss_x(fctx) == 1 && ss_y(fctx) == 0 { + hit!(CHROMA422_SQUARE_HITS); + } let (nw, nh) = (chroma_w / uw, chroma_h / uh); let bigger = chroma_w * chroma_h > uw * uh; let default_tx = TxType::DctDct; @@ -10636,6 +10805,20 @@ fn decode_rect_split( ), ) }); + // lane-av1-422kf: the palette colour map is consumed per + // unit here like every other chroma arm (`av1_visit_palette` + // feeds the whole plane block; window it to this unit). + // Without this the square chroma rows decoded a uv-palette + // strip's chroma as plain DC (class same-symbols-silent- + // prediction: the rng stayed in sync, only the prediction + // was dropped). + if let Some((ub, vb)) = &m.palette_uv { + let buf = if plane_idx == 1 { ub } else { vb }; + set_palette_pred( + palette_window(buf, chroma_w, cu_col * uw, cu_row * uh, uw, uh), + fctx, + ); + } // 32x32 does not fit read_coeffs_rect's scratch (768). The // square reader is the path every other 32x32 chroma unit uses. let levels = if uw == uh { @@ -12635,6 +12818,16 @@ fn decode_block_rect( (16, 32) => (TxbSet::ChromaRect32x16, &SCAN_16X32), (16, 8) => (TxbSet::ChromaRect16x8, &SCAN_16X8), (8, 16) => (TxbSet::ChromaRect16x8, &SCAN_8X16), + // lane-av1-422: a 4:2:2 strip halves only the width. A 32x16 + // luma strip's chroma is a 16x16 SQUARE (`TxbSet::Chroma16`, the + // set any 16x16 chroma plane reads); a 16x32 strip's chroma is + // 8x32, whose entropy set is the 16x16 one and whose DCT-only + // default follows the >=32 rule below -- the same pairing the + // (8,32) row of [`decode_rect_split`]'s chroma table proves. At + // 4:2:0 and 4:4:4 a strip's chroma is itself rect, so neither row + // is reachable there. + (16, 16) => (TxbSet::Chroma16, default_scan(16)), + (8, 32) => (TxbSet::Chroma16, &SCAN_8X32), _ => { return Err(unsupported( "a rectangular chroma transform whose size has no coefficient table", @@ -12846,7 +13039,9 @@ fn decode_block_rect( /// caller uses once, after both strips, exactly like the `VERT_B` arm next /// to it). The non-skip case (lane-rectx) reads real `TX_16X8`/`TX_8X16` /// luma coefficients (`TxbSet::LumaRect16x8`) and their `TX_8X4`/`TX_4X8` -/// chroma half (`TxbSet::ChromaRect8x4`), the two size classes one level +/// chroma half (`TxbSet::ChromaRect8x4`) at 4:2:0 -- an 8x8 *square* chroma +/// plane (`TxbSet::Chroma8` + the default scan) at 4:2:2 (lane-av1-422e: +/// half-width, unhalved height), the two size classes one level /// under [`decode_block_rect`]'s own 32x16/16x32 strip. #[allow(clippy::too_many_arguments)] fn decode_leaf_rect( @@ -13102,14 +13297,28 @@ fn decode_leaf_rect( // `use_reduced_set` branch returns `EXT_TX_SET_DTT4_IDTX` at // `tx_size_sqr_up == TX_16X16` regardless of the true, non-square // `tx_size`) and its chroma half (8x4/4x8, `TxbSet::ChromaRect8x4`). + // lane-av1-422e: a 4:2:2 strip halves only the width, so the chroma + // half of a 16x8/8x16 luma leaf is an 8x8 SQUARE (`TxbSet::Chroma8` + + // the default scan -- the pairing any 8x8 chroma plane reads). 4:2:0 + // halves both axes (8x4/4x8 rect, `TxbSet::ChromaRect8x4`); 4:4:4 + // leaves the full 16x8/8x16 rect (`TxbSet::ChromaRect16x8`). + let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; let (luma_scan, chroma_scan): (&[u16], &[u16]) = if ss_x(fctx) == 0 { if bw == 16 { (&SCAN_16X8, &SCAN_16X8) } else { (&SCAN_8X16, &SCAN_8X16) } + } else if chroma_422 { + if bw == 16 { (&SCAN_16X8, default_scan(8)) } else { (&SCAN_8X16, default_scan(8)) } } else if bw == 16 { (&SCAN_16X8, &SCAN_8X4) } else { (&SCAN_8X16, &SCAN_4X8) }; - let chroma_rect_set = if ss_x(fctx) == 0 { TxbSet::ChromaRect16x8 } else { TxbSet::ChromaRect8x4 }; + let chroma_rect_set = if ss_x(fctx) == 0 { + TxbSet::ChromaRect16x8 + } else if chroma_422 { + TxbSet::Chroma8 + } else { + TxbSet::ChromaRect8x4 + }; let around = neighbours.around_mi_rect(leaf_mi, bw, bh); let luma_set = if reduced_tx_set { TxbSet::LumaRect16x8 @@ -13478,12 +13687,43 @@ fn decode_block_rect4( // `TxbSet::Chroma16`). The caller set is closed -- this reader only // ever sees 32x8 / 8x32 luma and the sequence header admits ss 0/0 // and 1/1 only -- so the table is exhaustive. + let chroma422_rect32 = + (chroma_w, chroma_h) == (4, 32) && ss_x(fctx) == 1 && ss_y(fctx) == 0; let (chroma_set, chroma_scan): (TxbSet, &[u16]) = match (chroma_w, chroma_h) { (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]), (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]), (32, 8) => (TxbSet::Chroma16, &SCAN_32X8[..]), (8, 32) => (TxbSet::Chroma16, &SCAN_8X32[..]), - _ => unreachable!("decode_block_rect4 chroma shape set is closed"), + // lane-av1-422: a 4:2:2 1:4 strip halves only the width, so the + // landscape leaves (32x8, 16x4 luma) code their chroma as the RECT + // (16,8)/(8,4) -- the same TxbSet/scan pair the (16,8)/(8,4) rows of + // [`decode_rect_split`]'s chroma table use. + // lane-av1-422p: the PORTRAIT leaf occurs too -- the pinned + // fixture's frame 2 carries an 8x32 strip at ss(1,0), whose (4, 32) + // chroma block `ss_size_lookup[BLOCK_8X32][1][0]` marks + // BLOCK_INVALID (255, enums.h). BLOCK_INVALID does not mean + // "uncodable": `av1_get_tx_size` reads `max_txsize_rect_lookup[255]` + // OUT OF BOUNDS there, the byte at +255 in the pinned Release oracle + // is 0x05 = TX_4X8 (the `decode_token_recon_block` copy at + // 0xc0d030, objdump-measured), and `av1_get_adjusted_tx_size` has no + // TX_4X8 case. libaom HAS the transform, so the shape CHUNKS (the + // `chroma422_rect32` arm below) into FOUR stacked TX_4X8 units per + // plane (`tx_size_high_unit[TX_4X8] = 2`: blk_row 0, 2, 4, 6) + // instead of refusing; no coefficient-table row is added, because + // BLOCK_4X32 is not a table libaom has. 4:2:0 and 4:4:4 never land + // here (their 8x32 strips read (4, 16) and (8, 32)), so the row is + // 4:2:2-only. + (16, 8) => (TxbSet::ChromaRect16x8, &SCAN_16X8[..]), + (8, 4) => (TxbSet::ChromaRect8x4, &SCAN_8X4[..]), + // lane-av1-422p: the units' own set/scan -- the whole-rect read + // below never sees this row, the `chroma422_rect32` arm chunks + // first. Anything else is still a named-lane gap. + (4, 32) if ss_x(fctx) == 1 && ss_y(fctx) == 0 => { + (TxbSet::ChromaRect8x4, &SCAN_4X8[..]) + } + _ => unreachable!( + "decode_block_rect4 chroma shape set is closed: {chroma_w}x{chroma_h}" + ), }; let luma_scan: &[u16] = if bw > bh { &SCAN_32X8 } else { &SCAN_8X32 }; let (luma_levels, u_levels, v_levels) = if skip { @@ -13492,6 +13732,146 @@ fn decode_block_rect4( vec![0i32; chroma_w * chroma_h], vec![0i32; chroma_w * chroma_h], ) + } else if chroma422_rect32 { + // lane-av1-422p: the (4, 32) plane as FOUR TX_4X8 units per plane, + // plane-major (every U unit, then every V) -- the walk the pinned + // oracle's `decode_token_recon_block` makes for the BLOCK_INVALID + // plane block: TX_4X8, so stepr = `tx_size_high_unit[TX_4X8]` = 2 + // 4-px rows and stepc = 1, unit rows at chroma y 0, 8, 16, 24. + // Luma is the same single TX_8X32 rect the general arm reads. + let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); + let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x8, mode); + let (luma_levels, luma_tx_type) = read_coeffs_rect( + dec, + &mut luma_coding, + luma_scan, + bw, + bh, + 0, + dc_sign_ctx(around[0].2), + TxType::DctDct, + )?; + hit!(RECT4_COEFF_HITS); + let luma_residual = dequant_and_inverse_typed_wh( + &luma_levels, + bw, + bh, + crate::decode::bit_depth(fctx), + block_q_idx(fctx), + plane_q_delta(0, fctx).0, + plane_q_delta(0, fctx).1, + luma_tx_type, + block_iqmatrix(fctx, 0, bw, bh, luma_tx_type), + ); + if let Some(b) = &palette_y_buf { + set_palette_pred(b.clone(), fctx); + } + push_intra_rect(0, + px, + py, + bw, + bh, + mode, + angle_delta_y, + reach, + &luma_residual, + None, + filter_intra, + smooth_neighbor, fctx, + ); + // CfL parameters are computed ONCE per block over the strip's luma + // (`are_parameters_computed`) and shared by all four units, as in + // every other chunk arm. + let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); + let mut unit_grids: Vec<((usize, usize), usize, Grid)> = Vec::new(); + for (plane, buf) in [(1usize, &mut *u), (2usize, &mut *v)] { + for unit_row in 0..4usize { + let unit_mi = (mi_r + unit_row * 2, mi_c); + let unit_reach = tu_reach_rect( + bw, bh, 0, unit_row * 8, 8, 8, reach, + px, py, y.width, y.height, fctx, + ); + if let Some((ub, vb)) = &palette_uv_bufs { + let pbuf = if plane == 1 { ub } else { vb }; + set_palette_pred( + palette_window(pbuf, chroma_w, 0, unit_row * 8, 4, 8), + fctx, + ); + } + // Each unit is read and recorded IMMEDIATELY: unit row 0's + // `txb_skip_ctx` still sees the real above/left neighbour + // states, a lower unit sees this block's own upper unit's + // (libaom's per-unit `set_entropy_context`), and the lower + // unit predicts off the upper one's reconstructed samples. + let chroma_around = neighbours.around_mi_422_chroma(unit_mi, 8, 8); + let unit_grid = read_rect_chroma_unit( + dec, + cdfs, + TxbSet::ChromaRect8x4, + &SCAN_4X8, + 4, + 8, + plane, + chroma_around[plane], + uv_predict_mode, + angle_delta_uv, + unit_reach, + buf, + cpx, + cpy + unit_row * 8, + base_q_idx, + // `get_txb_ctx_general`'s chroma branch + // (txb_common.h): plane_bsize is BLOCK_INVALID (255) + // here, `num_pels_log2_lookup[255]` = 255 (the +255 + // byte of the decodetxb copy at 0xc0de70, + // objdump-measured) exceeds `BLOCK_4X8`'s 5, so the + // ctx_offset is 10 -- the port's offset-7-first + // `txb_skip_chroma_8` stores the offset-10 rows at + // rows 3..6, hence +3. + Some(3), + alpha + .zip(ac) + .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), + smooth_neighbor_uv, fctx, + )?; + neighbours.record_mi_chroma(unit_mi, 8, 8, plane, &unit_grid); + unit_grids.push((unit_mi, plane, unit_grid)); + } + } + // The whole-block stamp rewrites the chroma cells ONE state wide, + // which would erase the unit boundary the next block reads (class + // `override-slot-on-one-arm`), so it carries zero chroma grids and + // the per-unit writes replay after it. Its luma cells and side + // spans are this arm's own bookkeeping. + let zero_chroma = vec![0i32; chroma_w * chroma_h]; + neighbours.record_mi_rect( + (mi_r, mi_c), + bw, + bh, + &[&luma_levels[..], &zero_chroma[..], &zero_chroma[..]], + ); + for (unit_mi, plane, grid) in &unit_grids { + neighbours.record_mi_chroma(*unit_mi, 8, 8, *plane, grid); + } + neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); + neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx); + record_strip_palette( + neighbours, pal_at, bw, bh, pal_y_size, pal_y_colors, pal_uv_size, + pal_uv_colors, + ); + if bw > bh { + hit!(RECT4_32_HORZ_HITS); + } else { + hit!(RECT4_32_VERT_HITS); + } + // lane-frame36 r2 (same shape as `decode_block_rect64`'s split arm, + // swept this round): `set_txfm_ctxs` runs for EVERY block of an inter + // frame, so this 1:4 strip -- which is also the INTER frame's reader + // for 32x8/8x32 ([`decode_intra_rect4_in_inter`]) -- publishes its + // transform size in both TXFM_CONTEXT bands. Without it the next block + // reads the row's stale value. + txfm_partition_update_rect(neighbours, (mi_r, mi_c), (bw, bh), (bw, bh)); + return Ok((mode, uv_predict_mode)); } else { let around = neighbours.around_mi_rect((mi_r, mi_c), bw, bh); let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x8, mode); @@ -13640,38 +14020,77 @@ fn decode_block_rect4( smooth_neighbor, fctx, ); let ac = alpha.map(|_| cfl_src_rect(px, py, bw, bh)); - if let Some((ub, _)) = &palette_uv_bufs { - set_palette_pred(ub.clone(), fctx); - } - push_intra_rect(1, - cpx, - cpy, - chroma_w, - chroma_h, - uv_predict_mode, - angle_delta_uv, - reach, - &u_levels, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - smooth_neighbor_uv, fctx, - ); - if let Some((_, vb)) = &palette_uv_bufs { - set_palette_pred(vb.clone(), fctx); + if chroma422_rect32 { + // lane-av1-422p: `predict_and_reconstruct_intra_block` (decodeframe.c + // ~1000) predicts EVERY unit regardless of `skip_txfm`, so the skip + // arm walks the same four TX_4X8 units per plane -- the lower unit + // predicts off the upper one's predicted samples. No coefficients + // are coded; the tail's whole-block zero stamp below is the state + // libaom's `set_entropy_context` leaves. + for (plane, _buf) in [(1usize, &mut *u), (2usize, &mut *v)] { + for unit_row in 0..4usize { + let unit_reach = tu_reach_rect( + bw, bh, 0, unit_row * 8, 8, 8, reach, + px, py, y.width, y.height, fctx, + ); + if let Some((ub, vb)) = &palette_uv_bufs { + let pbuf = if plane == 1 { ub } else { vb }; + set_palette_pred( + palette_window(pbuf, chroma_w, 0, unit_row * 8, 4, 8), + fctx, + ); + } + push_intra_rect(plane, + cpx, + cpy + unit_row * 8, + 4, + 8, + uv_predict_mode, + angle_delta_uv, + unit_reach, + &ZERO_RESIDUAL[..4 * 8], + alpha + .zip(ac) + .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), + None, + smooth_neighbor_uv, fctx, + ); + } + } + } else { + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } + push_intra_rect(1, + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &u_levels, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + smooth_neighbor_uv, fctx, + ); + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } + push_intra_rect(2, + cpx, + cpy, + chroma_w, + chroma_h, + uv_predict_mode, + angle_delta_uv, + reach, + &v_levels, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + smooth_neighbor_uv, fctx, + ); } - push_intra_rect(2, - cpx, - cpy, - chroma_w, - chroma_h, - uv_predict_mode, - angle_delta_uv, - reach, - &v_levels, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - smooth_neighbor_uv, fctx, - ); neighbours.record_mi_rect((mi_r, mi_c), bw, bh, &[&luma_levels[..], &u_levels[..], &v_levels[..]]); neighbours.fill_skip_grid_rect((mi_r, mi_c), mi_w, mi_h, skip); neighbours.fill_lf_grid_rect((mi_r, mi_c), mi_w, mi_h, bw as u8, bh as u8, 0, fctx); @@ -13752,7 +14171,17 @@ fn decode_rect4_16( // lane-av1-444: at 4:4:4 every strip is its own chroma reference // (no mi-parity test at ss 0/0, and the strip's own chroma block is // already >= 4x4) -- there is no 4:2:0 pair to close. - let has_chroma = i % 2 == 1 || (ss_x(fctx) == 0 && ss_y(fctx) == 0); + // lane-av1-422o: the parity rule is per axis, straight out of + // `is_chroma_reference`: a HORZ 16x4 strip (1 mi tall) keeps the + // `ss_y == 0 -> every strip a reference` row rule, but a VERT 4x16 + // strip (1 mi wide) keeps the COLUMN clause `(mi_col & 1) || !(bw & + // 1) || !ss_x`, which with bw == 1 mi reduces to `mi_col odd` for + // every ss_x == 1 format -- the ODD strip closes the pair and reads + // the chroma, exactly like 4:2:0. (VERT_4 partitions start on an + // even mi_col, so `i % 2 == 1` is that clause.) + let has_chroma = i % 2 == 1 + || (horz && ss_y(fctx) == 0) + || (!horz && ss_x(fctx) == 0); let (mode, uv, _tx) = decode_rect4_16_strip( dec, cdfs, @@ -14654,6 +15083,19 @@ fn decode_rect4_16_strip( // ss 0/0, so the neighbour reads below anchor at the strip.) let (pair_mi, pw, ph) = if ss_x(fctx) == 0 && ss_y(fctx) == 0 { (lmi, bw, bh) + } else if ss_y(fctx) == 0 && horz { + // lane-av1-422: chroma height is NOT subsampled, so a HORZ + // 16x4 strip is its own chroma reference (`is_chroma_reference` + // at ss(1,0): bh == 1 mi, so the row clause reduces to + // `!ss_y`) and codes its own `ss_size_lookup[BLOCK_16X4][1][0]` + // = BLOCK_8X4 chroma block -- a valid transform, no pair. + // (lane-av1-422o: a VERTICAL 4x16 strip now falls through to + // the pair merge below -- its own chroma block + // `ss_size_lookup[BLOCK_4X16][1][0]` is BLOCK_INVALID, the + // walk proved such leaves exist, and libaom codes the pair's + // chroma from the closing strip; the chunk lives in the + // `chroma422_pair16` arm below.) + (lmi, bw, bh) } else if horz { ((lmi.0 - 1, lmi.1), 16, 8) } else { @@ -14662,6 +15104,19 @@ fn decode_rect4_16_strip( let (ppx, ppy) = (pair_mi.1 * MI, pair_mi.0 * MI); let (cpx, cpy) = (ppx >> ss_x(fctx), ppy >> ss_y(fctx)); let (cw, ch) = (pw >> ss_x(fctx), ph >> ss_y(fctx)); + // lane-av1-422o: the 4:2:2 pair's chroma of a VERT 4x16 strip + // pair: (4, 16) at ss(1,0). The bsize is still BLOCK_4X16, whose + // `ss_size_lookup[..][1][0]` is BLOCK_INVALID, so libaom's + // `av1_get_tx_size` reads `max_txsize_rect_lookup[255]` -- the + // out-of-bounds byte is TX_4X8 in the pinned Release oracle, and + // `av1_get_adjusted_tx_size` has no TX_4X8 case to adjust it. + // `decode_token_recon_block` walks unit_width = + // ROUND_POWER_OF_TWO(1, 1) = 1, unit_height = 4, with stepr = + // tx_size_high_unit[TX_4X8] = 2: TWO TX_4X8 units per plane + // (chroma rows 0..8 and 8..16), plane-major. Even the skip arm + // walks per unit: `predict_and_reconstruct_intra_block` predicts + // every unit regardless of `skip_txfm`. + let chroma422_pair16 = (cw, ch) == (4, 16) && ss_x(fctx) == 1; let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; if (V_PRED..=D67_PRED).contains(&uv_predict_mode) { hit!(RECT4_16_CHROMA_DIR_HITS); @@ -14812,6 +15267,41 @@ fn decode_rect4_16_strip( hit!(CHROMA_SKIP_CFL_HITS); } for (_buf, plane) in [(&mut *u, 1usize), (&mut *v, 2)] { + if chroma422_pair16 { + // lane-av1-422o: two TX_4X8 units, each predicted on + // its own edges (the lower one off the upper one's + // samples); no coefficients are coded, and libaom's + // `set_entropy_context` zeroed the block's own cells, + // so the pair-wide zero stamp below stays correct. + for unit_row in 0..2usize { + let unit_reach = tu_reach_rect( + pw, ph, 0, unit_row * 8, 8, 8, pair_reach, + ppx, ppy, y.width, y.height, fctx, + ); + if let Some((ub, vb)) = &palette_uv_bufs { + let pbuf = if plane == 1 { ub } else { vb }; + set_palette_pred( + palette_window(pbuf, cw, 0, unit_row * 8, 4, 8), + fctx, + ); + } + push_intra_rect(plane, + cpx, + cpy + unit_row * 8, + 4, + 8, + uv_predict_mode, + angle_delta_uv, + unit_reach, + &ZERO_RESIDUAL[..4 * 8], + alpha + .zip(ac) + .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), + None, + smooth_neighbor_uv, fctx, + ); + } + } else { if let Some((ub, vb)) = &palette_uv_bufs { set_palette_pred(if plane == 1 { ub.clone() } else { vb.clone() }, fctx); } @@ -14830,8 +15320,76 @@ fn decode_rect4_16_strip( None, smooth_neighbor_uv, fctx, ); + } } (zeros.clone(), zeros) + } else if chroma422_pair16 { + // lane-av1-422o: the pair's 4x16 chroma as TWO TX_4X8 units + // per plane, plane-major (every U unit, then every V). Each + // unit: the `ChromaRect8x4` tables (`get_txsize_entropy_ctx` + // squares TX_4X8 up to the 8x8 class), `SCAN_4X8`, and a + // `txb_skip_ctx` of above+left in the OFFSET-10 rows -- the + // offset comes from `num_pels_log2_lookup[plane_bsize] > + // num_pels_log2_lookup[BLOCK_4X8]` with plane_bsize = + // BLOCK_INVALID (255), and the byte at that table's +255 in + // the pinned Release oracle is 255 (`cmpb` against the + // `0xc0db70` copy decodetxb.c links), i.e. the bigger-plane + // arm: +3 on the offset-7-first chroma tables. No tx_type + // symbol (only y plane's is transmitted); the unit's type is + // `intra_mode_to_tx_type(UV mode)` kept by the all-16 ext-tx + // set -- [`read_rect_chroma_unit`]'s own default. CfL params + // are computed ONCE per block (`are_parameters_computed`) + // over the pair's luma, shared by both units. Each unit is + // predicted and recorded immediately, so the lower unit + // reads the upper one's coefficient context. + let ac = alpha.map(|_| cfl_src_rect(ppx, ppy, pw, ph)); + for (plane, buf) in [(1usize, &mut *u), (2usize, &mut *v)] { + for unit_row in 0..2usize { + let unit_mi = (pair_mi.0 + unit_row * 2, pair_mi.1); + let unit_reach = tu_reach_rect( + pw, ph, 0, unit_row * 8, 8, 8, pair_reach, + ppx, ppy, y.width, y.height, fctx, + ); + if let Some((ub, vb)) = &palette_uv_bufs { + let pbuf = if plane == 1 { ub } else { vb }; + set_palette_pred( + palette_window(pbuf, cw, 0, unit_row * 8, 4, 8), + fctx, + ); + } + let chroma_around = neighbours.around_mi_422_chroma(unit_mi, 8, 8); + let unit_grid = read_rect_chroma_unit( + dec, + cdfs, + TxbSet::ChromaRect8x4, + &SCAN_4X8, + 4, + 8, + plane, + chroma_around[plane], + uv_predict_mode, + angle_delta_uv, + unit_reach, + buf, + cpx, + cpy + unit_row * 8, + base_q_idx, + // lane-av1-422q: the offset-10 rows -- the same + // measured rule as the 4x32 arm (plane_bsize + // BLOCK_INVALID for the pair's BLOCK_4X16 too; + // num_pels_log2_lookup[255] = 0xff at the + // 0xc0de70 copy -> +3 on the offset-7-first + // chroma tables; see lanes/av1422q.report.md). + Some(3), + alpha + .zip(ac) + .map(|((au, av), ac)| (if plane == 1 { au } else { av }, ac)), + smooth_neighbor_uv, fctx, + )?; + neighbours.record_mi_chroma(unit_mi, 8, 8, plane, &unit_grid); + } + } + (Grid::Zero(cw * ch), Grid::Zero(cw * ch)) } else { let around = neighbours.around_mi_rect(pair_mi, pw, ph); // lane-av1-444: the strip's own 16x4 / 4x16 chroma at ss 0/0 @@ -14841,7 +15399,25 @@ fn decode_rect4_16_strip( (8, 4) => (TxbSet::ChromaRect8x4, &SCAN_8X4[..]), (4, 8) => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), (16, 4) => (TxbSet::Chroma8, &SCAN_16X4[..]), + // lane-av1-444: 4:4:4's own-strip vert chroma is (4,16) + // -- one TX_4X16. (lane-av1-422o: the 4:2:2 pair's + // (4,16) never reaches this row; `chroma422_pair16` + // intercepts it above and chunks it into TX_4X8 units.) (4, 16) => (TxbSet::Chroma8, &SCAN_4X16[..]), + // lane-av1-422: a 4:2:2 HORZ pair (16x8 luma) keeps the + // pair's height: an 8x8 SQUARE chroma block, the same + // `TxbSet::Chroma8` set any 8x8 chroma plane reads. The + // 4:2:0 pair's chroma is 8x4 and 4:4:4's is 16x4, so this + // row is unreachable there. It is also the witness arm: + // a restored `/2 chroma height` lands on (8,4) and the + // counter reads 0. + (8, 8) => { + hit!(CHROMA422_SQUARE_HITS); + (TxbSet::Chroma8, default_scan(8)) + } + // lane-av1-422o: with the `chroma422_pair16` arm above, + // the (2,16) own-strip shape and the 4:4:4 shapes are the + // only residents; anything else is a named-lane gap. _ => unreachable!("decode_rect4_16_strip chroma shape set is closed"), }; let mut planes = Vec::with_capacity(2); @@ -14906,7 +15482,11 @@ fn decode_rect4_16_strip( neighbours.record_uv_mode_mi(pair_mi.0, pair_mi.1, pw / MI, ph / MI, uv_predict_mode); // A lossless pair already stamped each TX_4X4 (`record_mi_chroma`). // The single-state rewrite below is the non-lossless TX_8X4/TX_4X8. - if !lossless_pair { + // lane-av1-422o: the chunked pair's cells are stamped PER UNIT in + // the arm above (libaom's coefficient contexts are per + // 4x4-cell); a pair-wide state would erase the unit boundary the + // next block reads. + if !lossless_pair && !chroma422_pair16 { // The chroma planes' coefficient context, over the PAIR's mi span // (`decode_leaf_rect8`'s own rule: a subsampled plane's bound is // the luma one rounded up to its 4x4 unit). @@ -15849,7 +16429,13 @@ fn read_intra_mode( (side >> ss_x(fctx), side >> ss_y(fctx)), (ss_x(fctx), ss_y(fctx)), ); - let map = decode_color_index_map(dec, cdfs, n, side >> ss_x(fctx), on, true); + // lane-av1-422d: the chroma map's extent is the PLANE BLOCK + // `(side >> ss_x) x (side >> ss_y)` -- 4x8 at ss (1,0), not the + // square call's `(side >> ss_x)`-squared (4x4), which left a + // 16-entry map for a 32-sample unit and panicked the reconstruct. + let map = decode_color_index_map_wh( + dec, cdfs, n, side >> ss_x(fctx), side >> ss_y(fctx), on, true, + ); hit!(PALETTE_UV_HITS); if trace { eprintln!( @@ -15945,6 +16531,29 @@ fn cfl_ac_ss( let avg = (sum + num_pel / 2) >> num_pel.trailing_zeros(); ac.iter_mut().for_each(|v| *v -= avg); ac + } else if ss_x == 1 && ss_y == 0 { + // lane-av1-422: `cfl_luma_subsampling_422_lbd_c` -- each chroma sample + // averages the HORIZONTAL luma pair above it, at full chroma height + // (`(a + b) >> 1` in Q3 is `(a + b) << 2`). A rect luma strip's chroma + // is square here, and the 4:2:0 rect/square helpers below would halve + // the height it must keep. + let (cw, ch) = (bw >> 1, bh); + let mut ac = vec![0i32; cw * ch]; + let mut sum = 0i32; + for row in 0..ch { + for col in 0..cw { + let (lx, ly) = (px + col * 2, py + row); + let q3 = (i32::from(y.data[ly * y.width + lx]) + + i32::from(y.data[ly * y.width + lx + 1])) + << 2; + ac[row * cw + col] = q3; + sum += q3; + } + } + let num_pel = (cw * ch) as i32; + let avg = (sum + num_pel / 2) >> num_pel.trailing_zeros(); + ac.iter_mut().for_each(|v| *v -= avg); + ac } else if bw == bh { cfl_ac_q3(y, px, py, bw) } else { @@ -16619,6 +17228,110 @@ fn read_plane( Ok(levels) } +/// [`push_intra`] when the unit is square, [`push_intra_rect`] when it is a +/// rect (lane-av1-422f): a 4:2:2 square-block chroma unit is the plane +/// block's own rect shape, and the `rect` flag selects +/// [`PlaneBuf::reconstruct_rect`]'s two-dimensional loop. +#[allow(clippy::too_many_arguments)] +fn push_intra_unit( + plane: usize, + x: usize, + y: usize, + w: usize, + h: usize, + mode: usize, + angle_delta: i32, + reach: Reach, + residual: &[i32], + cfl: Option<(i32, CflSrc)>, + filter_intra: Option, + smooth_neighbor: bool, fctx: &crate::decode::FrameCtx, +) { + if w == h { + push_intra(plane, x, y, w, mode, angle_delta, reach, residual, cfl, + filter_intra, smooth_neighbor, fctx); + } else { + push_intra_rect(plane, x, y, w, h, mode, angle_delta, reach, residual, cfl, + filter_intra, smooth_neighbor, fctx); + } +} + +/// ONE RECT chroma transform unit of a square block's uv plane +/// (lane-av1-422f) -- a 4:2:2 frame's plane block is `(side/2, side)` and +/// `av1_get_max_uv_txsize` fills it with a single rect unit below side 64 +/// (TX_4X8 / TX_8X16 / TX_16X32), which the square-shaped [`read_plane`] +/// cannot express. Same shape as [`leaf8_chroma422_unit`]'s proven read: the +/// [`TxbSet`] whose entropy class the unit squares up to, the unit-shaped +/// scan, `txb_skip_ctx` = above + left in the offset-7 rows (the unit covers +/// the plane block exactly, so no `+3` bigger-plane term -- that one lives in +/// the square multi-unit walks' `chroma_ctx_offset`), and the plane's +/// predicted mode supplies the mode-derived default `tx_type` unless an armed +/// [`INTRABC_CHROMA_TX`] slot carries the intrabc luma's own -- except at an +/// entropy class of 32x32 and up, where the spec forces `DCT_DCT` +/// ([`read_plane`]'s `side >= 32` clamp). +#[allow(clippy::too_many_arguments)] +fn read_rect_chroma_unit( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + set: TxbSet, + scan: &[u16], + w: usize, + h: usize, + plane_idx: usize, + around: (bool, bool, i32), + uv_predict_mode: usize, + angle_delta_uv: i32, + reach: Reach, + // Unread, like [`read_plane`]'s own: the borrow proves the caller holds + // the plane exclusively while the unit's coefficients are parsed. + _plane: &mut PlaneBuf<'static>, + x: usize, + y: usize, + // Signature parity with [`read_plane`]; the dequant reads its q index + // off `block_q_idx(fctx)` like every other reader here. + _base_q_idx: u8, + // lane-av1-422p: `get_txb_ctx_general`'s chroma branch + // (txb_common.h) reads `txb_skip_ctx = above + left + ctx_offset`, + // where `ctx_offset` is 10 when the plane block is bigger than the + // transform and 7 otherwise. The port stores the offset-7 rows at + // `txb_skip_chroma_8` rows 0..3 and the offset-10 rows at rows 3..6 + // (lane-av1-422b), so a unit SMALLER than its plane block passes + // `Some(3)` to reach the offset-10 rows. Every unit that IS the whole + // plane block stays `None` -- 4:2:2 plane blocks never shrink to a + // rect unit except in the chunk arms. + chroma_skip_offset: Option, + cfl: Option<(i32, CflSrc)>, + smooth_neighbor_uv: bool, fctx: &crate::decode::FrameCtx, +) -> Result { + if ss_x(fctx) == 1 && ss_y(fctx) == 0 && w != h { + hit!(CHROMA422_RECT_HITS); + } + let default_tx = if w.max(h) >= 32 { + TxType::DctDct + } else { + fctx + .intrabc_chroma_tx + .with(std::cell::Cell::get) + .unwrap_or_else(|| default_intra_tx_type(uv_predict_mode as u8)) + }; + let mut coding = cdfs.txb(set, uv_predict_mode); + let (levels, tx_type) = read_coeffs_rect( + dec, &mut coding, scan, w, h, + usize::from(around.0) + usize::from(around.1) + chroma_skip_offset.unwrap_or(0), + dc_sign_ctx(around.2), default_tx, + )?; + let residual = dequant_and_inverse_typed_wh( + &levels, w, h, crate::decode::bit_depth(fctx), block_q_idx(fctx), + plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, + tx_type, block_iqmatrix(fctx, plane_idx, w, h, tx_type), + ); + push_intra_rect( + plane_idx, x, y, w, h, uv_predict_mode, angle_delta_uv, reach, + &residual, cfl, None, smooth_neighbor_uv, fctx, + ); + Ok(levels) +} + /// Decodes one whole-block coded superblock/quadrant/leaf: its mode, then its /// three planes, reconstructing them into `y`/`u`/`v` and updating /// `neighbours`. @@ -16689,8 +17402,8 @@ fn decode_block( // rewrite (which sat above `read_intra_mode`) rides along here -- same // per-frame `ss_x`/`ss_y` condition, now resolved against the block's own // segment like the lossless arm above it. - let (luma_set, chroma_set, luma_tx, chroma_tx, scans) = if lossless(fctx) { - (TxbSet::Luma4, TxbSet::Chroma4, 4, 4, (scan4, scan4)) + let (luma_set, chroma_set, luma_tx, chroma_tx, chroma_tx_h, scans) = if lossless(fctx) { + (TxbSet::Luma4, TxbSet::Chroma4, 4, 4, 4, (scan4, scan4)) } else if ss_x(fctx) == 0 && ss_y(fctx) == 0 { let tx = if side >= 64 { 32 } else { side }; let (set, scan): (TxbSet, &[u16]) = match tx { @@ -16699,9 +17412,39 @@ fn decode_block( 8 => (TxbSet::Chroma8, scan8), _ => (TxbSet::Chroma4, scan4), }; - (luma_set, set, luma_tx, tx, (scans.0, scan)) + (luma_set, set, luma_tx, tx, tx, (scans.0, scan)) + } else if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + // lane-av1-422f: the uv plane block is the (side/2, side) rect + // (`ss_size_lookup[..][1][0]`), and `av1_get_max_uv_txsize` is + // `av1_get_adjusted_tx_size(max_txsize_rect_lookup[plane_bsize])` -- + // the RECT that fills the plane block, NOT the square transform of + // the smaller side (the oracle reads ONE TX_8X16 for a 16x16 block's + // 8x16 plane where the old model read two 8x8 units): 4 -> TX_4X4 + // (the 2x4 plane rounds up to BLOCK_4X4), 8 -> TX_4X8, 16 -> + // TX_8X16, 32 -> TX_16X32 (one unit per plane, the whole plane + // block), 64 -> TX_32X64 adjusts to TX_32X32 and 128 -> TX_64X64 + // adjusts to TX_32X32 (square units, a 1x2 / 2x4 grid). + // `chroma_tx` is the unit WIDTH, `chroma_tx_h` its HEIGHT; the + // chroma walks below read one (chroma_tx, chroma_tx_h) unit per grid + // cell and key their rect reads on `chroma_tx != chroma_tx_h`. + let (tx_w, tx_h) = match side { + 4 => (4, 4), + 8 => (4, 8), + 16 => (8, 16), + 32 => (16, 32), + // 64 and 128: TX_32X64 / TX_64X64 adjust down to TX_32X32. + _ => (32, 32), + }; + let (set, scan): (TxbSet, &[u16]) = match side { + 4 => (TxbSet::Chroma4, scan4), + 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), + 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), + 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), + _ => (TxbSet::Chroma32, scan32), + }; + (luma_set, set, luma_tx, tx_w, tx_h, (scans.0, scan)) } else { - (luma_set, chroma_set, luma_tx, chroma_tx, scans) + (luma_set, chroma_set, luma_tx, chroma_tx, chroma_tx, scans) }; let intrabc_dv = fctx.intrabc_dv.with(|c| c.take()); // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED` @@ -16825,6 +17568,9 @@ fn decode_block( let reach = Reach::of(side, px, py, y.width, y.height, fctx); let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); let chroma_side = side >> ss_x(fctx); + // lane-av1-422b: chroma extent per axis, `side` at ss_y 0 (4:2:2/4:4:4), + // `side / 2` at 4:2:0. + let chroma_height = side >> ss_y(fctx); // spec 7.11.3.4 with `use_intrabc`: the reference is the *current* // frame's own pre-loop-filter reconstruction (all loop filters are off // whenever `allow_intrabc`, frame.rs:194/210/252/272) at the full-pel @@ -16839,17 +17585,17 @@ fn decode_block( mv_to_q4(px, dv_col, 0), mv_to_q4(py, dv_row, 0), side, side, mc::InterpFilterKind::Bilinear, &mut yb, fctx, ); - let mut ub = vec![0u16; chroma_side * chroma_side]; + let mut ub = vec![0u16; chroma_side * chroma_height]; mc::predict_with_filter( &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)), - chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), + chroma_side, chroma_height, mc::InterpFilterKind::Bilinear, &mut ub, fctx, ); - let mut vb = vec![0u16; chroma_side * chroma_side]; + let mut vb = vec![0u16; chroma_side * chroma_height]; mc::predict_with_filter( &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_x(fctx)), - chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + mv_to_q4(cpx, dv_col, ss_x(fctx)), mv_to_q4(cpy, dv_row, ss_y(fctx)), + chroma_side, chroma_height, mc::InterpFilterKind::Bilinear, &mut vb, fctx, ); (yb, ub, vb) }); @@ -16994,31 +17740,41 @@ fn decode_block( ); } let ac = alpha.map(|_| cfl_src(px, py, side)); - let cn = (chroma_side / chroma_tx).max(1); - for cu_row in 0..cn { - for cu_col in 0..cn { - let luma_span = chroma_tx << ss_x(fctx); - let cu_r = if cn == 1 { + // lane-av1-422b: the chroma unit grid is `cn_cols` x `cn_rows` -- + // square at 4:2:0/4:4:4, at 4:2:2 `(side/2)/tx` units wide by + // `side/tx` tall (the plane block is (side/2, side)). A unit's LUMA + // anchor follows the per-axis shifts: `chroma_tx << ss_x` wide, + // `chroma_tx_h << ss_y` tall (lane-av1-422f: the unit itself is the + // (chroma_tx, chroma_tx_h) rect, so a 4:2:2 frame below side 64 + // reads ONE unit per plane, the whole plane block). + let cn_cols = (chroma_side / chroma_tx).max(1); + let cn_rows = (chroma_height / chroma_tx_h).max(1); + let luma_span_x = chroma_tx << ss_x(fctx); + let luma_span_y = chroma_tx_h << ss_y(fctx); + for cu_row in 0..cn_rows { + for cu_col in 0..cn_cols { + let cu_r = if cn_rows == 1 && cn_cols == 1 { reach } else { - tu_reach( + tu_reach_rect( side, side, - cu_col * luma_span, cu_row * luma_span, luma_span, + cu_col * luma_span_x, cu_row * luma_span_y, luma_span_x, luma_span_y, reach, px, py, y.width, y.height, fctx, ) }; - let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); + let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra(1, + push_intra_unit(1, cu_x, cu_y, chroma_tx, + chroma_tx_h, uv_predict_mode, angle_delta_uv, cu_r, - &ZERO_RESIDUAL[..chroma_tx * chroma_tx], + &ZERO_RESIDUAL[..chroma_tx * chroma_tx_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, @@ -17026,14 +17782,15 @@ fn decode_block( if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra(2, + push_intra_unit(2, cu_x, cu_y, chroma_tx, + chroma_tx_h, uv_predict_mode, angle_delta_uv, cu_r, - &ZERO_RESIDUAL[..chroma_tx * chroma_tx], + &ZERO_RESIDUAL[..chroma_tx * chroma_tx_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, @@ -17089,8 +17846,17 @@ fn decode_block( // TX_32X32, so a 64x64 block codes four chroma units, plane-major // (every U, then every V) — the same loop the multi-TU arm runs. // At 4:2:0 `chroma_side == chroma_tx`, so it stays one read. - let cn = (chroma_side / chroma_tx).max(1); - let (u_grid, v_grid, chroma_units) = if cn == 1 { + // lane-av1-422b: 4:2:2 never collapses to one read above a 4x4 luma + // block -- the unit grid is `(side/2)/tx` wide by `side/tx` tall. + // lane-av1-422f: `chroma_tx` is the unit WIDTH and `chroma_tx_h` its + // HEIGHT, so below side 64 a 4:2:2 frame's grid is 1x1 and the one + // unit is the plane block's own rect. + let cn_cols = (chroma_side / chroma_tx).max(1); + let cn_rows = (chroma_height / chroma_tx_h).max(1); + let luma_span_x = chroma_tx << ss_x(fctx); + let luma_span_y = chroma_tx_h << ss_y(fctx); + let (u_grid, v_grid, chroma_units) = if cn_rows == 1 && cn_cols == 1 { + if chroma_tx == chroma_tx_h { if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } @@ -17148,40 +17914,78 @@ fn decode_block( smooth_neighbor_uv, fctx, )?; (u_grid, v_grid, Vec::new()) + } else { + // lane-av1-422f: the one unit is a RECT filling the plane + // block -- the square-shaped [`read_plane`] cannot express + // it, so both planes go through [`read_rect_chroma_unit`] + // (U, then V, the same order the square arm reads). The + // chroma context reads per chroma 4-px cell (see + // [`Neighbours::around_mi_422_chroma`]). + let chroma_around = + neighbours.around_mi_422_chroma((mi_r, mi_c), side, side); + if let Some((ub, _)) = &palette_uv_bufs { + set_palette_pred(ub.clone(), fctx); + } + let u_grid = read_rect_chroma_unit( + dec, cdfs, chroma_set, scans.1, chroma_tx, chroma_tx_h, 1, + chroma_around[1], uv_predict_mode, angle_delta_uv, reach, u, + cpx, cpy, base_q_idx, None, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + smooth_neighbor_uv, fctx, + )?; + if let Some((_, vb)) = &palette_uv_bufs { + set_palette_pred(vb.clone(), fctx); + } + let v_grid = read_rect_chroma_unit( + dec, cdfs, chroma_set, scans.1, chroma_tx, chroma_tx_h, 2, + chroma_around[2], uv_predict_mode, angle_delta_uv, reach, v, + cpx, cpy, base_q_idx, None, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + smooth_neighbor_uv, fctx, + )?; + (u_grid, v_grid, Vec::new()) + } } else { let chroma_ctx_offset = Some(3); let mut u_pass: Vec = Vec::new(); - let mut units: Vec<((usize, usize), usize, Grid, Grid)> = Vec::new(); + let mut units: Vec<((usize, usize), usize, usize, Grid, Grid)> = Vec::new(); let mut last_grids = [Grid::Zero(0), Grid::Zero(0)]; for plane_pass in 1..=2usize { let mut pass_idx = 0usize; - for cu_row in 0..cn { - for cu_col in 0..cn { - let luma_span = chroma_tx << ss_x(fctx); + for cu_row in 0..cn_rows { + for cu_col in 0..cn_cols { let cu_mi = ( - mi_r + cu_row * (luma_span / MI), - mi_c + cu_col * (luma_span / MI), + mi_r + cu_row * (luma_span_y / MI), + mi_c + cu_col * (luma_span_x / MI), ); - let cu_around = neighbours.around_mi(cu_mi, luma_span); - let cu_reach = tu_reach( + let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + // lane-av1-422f: chroma-only loop; per-chroma-cell + // above votes (see [`Neighbours::around_mi_422_chroma`]). + neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y) + } else { + neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y) + }; + let cu_reach = tu_reach_rect( side, side, - cu_col * luma_span, - cu_row * luma_span, - luma_span, + cu_col * luma_span_x, + cu_row * luma_span_y, + luma_span_x, + luma_span_y, reach, px, py, y.width, y.height, fctx, ); - let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); + let (cu_x, cu_y) = + (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); if let Some((ub, vb)) = &palette_uv_bufs { let pbuf = if plane_pass == 1 { ub } else { vb }; set_palette_pred( palette_window( - pbuf, chroma_side, cu_col * chroma_tx, cu_row * chroma_tx, - chroma_tx, chroma_tx, + pbuf, chroma_side, cu_col * chroma_tx, + cu_row * chroma_tx_h, chroma_tx, chroma_tx_h, ), fctx, ); @@ -17198,16 +18002,21 @@ fn decode_block( None, chroma_ctx_offset, smooth_neighbor_uv, fctx, )?; hit!(CHROMA_SPLIT_TX_HITS); + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + hit!(CHROMA422_SQUARE_HITS); + } // Immediately, so the next unit of this block reads this // one's coefficient context. `record` below stamps one // chroma state across the whole block; the replay after // it puts the per-unit state back. - neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_pass, &cu_grid); + neighbours.record_mi_chroma( + cu_mi, luma_span_x, luma_span_y, plane_pass, &cu_grid, + ); if plane_pass == 1 { u_pass.push(cu_grid); } else { let u_grid = std::mem::replace(&mut u_pass[pass_idx], Grid::Zero(0)); - units.push((cu_mi, luma_span, u_grid.clone(), cu_grid.clone())); + units.push((cu_mi, luma_span_x, luma_span_y, u_grid.clone(), cu_grid.clone())); last_grids = [u_grid, cu_grid]; } pass_idx += 1; @@ -17218,9 +18027,9 @@ fn decode_block( }; fctx.intrabc_chroma_tx.with(|c| c.set(None)); neighbours.record(at, side, mode, uv_predict_mode, &[&luma_grid[..], &u_grid[..], &v_grid[..]]); - for (cu_mi, luma_span, u_unit, v_unit) in &chroma_units { - neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 1, u_unit); - neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 2, v_unit); + for (cu_mi, sw, sh, u_unit, v_unit) in &chroma_units { + neighbours.record_mi_chroma(*cu_mi, *sw, *sh, 1, u_unit); + neighbours.record_mi_chroma(*cu_mi, *sw, *sh, 2, v_unit); } } else { // Several luma transform units, raster order (spec @@ -17230,7 +18039,13 @@ fn decode_block( // the earlier tiles in this same block already wrote -- the same // per-TU pattern [`decode_leaf8`] already runs for an 8x8 leaf. let n_axis = side / logical_tx; - let cn = (chroma_side / chroma_tx).max(1); + // lane-av1-422f: unit width/height per axis, like walk 2 above -- + // a 4:2:2 frame below side 64 reads ONE rect unit per plane per + // chunk, the whole plane block. + let cn_cols = (chroma_side / chroma_tx).max(1); + let cn_rows = (chroma_height / chroma_tx_h).max(1); + let luma_span_x = chroma_tx << ss_x(fctx); + let luma_span_y = chroma_tx_h << ss_y(fctx); // libaom's transform-block loop is over 64x64 luma "mu" chunks // (`decode_token_recon_block`: `mu_blocks_wide/high` = // `mi_size_wide[BLOCK_64X64]`), and it codes EVERY PLANE of a chunk @@ -17242,9 +18057,10 @@ fn decode_block( let nchunk = (side / 64).max(1); // `cn > 1` means the uv plane block is larger than the uv transform, // which moves libaom's chroma `txb_skip_ctx` offset from 7 to 10. - let chroma_ctx_offset = if cn > 1 { Some(3) } else { None }; + let chroma_ctx_offset = if cn_rows * cn_cols > 1 { Some(3) } else { None }; let tpc = (n_axis / nchunk).max(1); - let cpc = (cn / nchunk).max(1); + let cpc_rows = (cn_rows / nchunk).max(1); + let cpc_cols = (cn_cols / nchunk).max(1); // The block's luma transform units, raster order inside each mu // chunk. lane-av1-ibcvtx: an intrabc block's units are the var-tx // tree's own leaf list -- mixed sizes included, exactly what libaom's @@ -17270,7 +18086,7 @@ fn decode_block( } } let mut last_grids = [Grid::Zero(0), Grid::Zero(0)]; - let mut units: Vec<((usize, usize), usize, Grid, Grid)> = Vec::new(); + let mut units: Vec<((usize, usize), usize, usize, Grid, Grid)> = Vec::new(); for ch_row in 0..nchunk { for ch_col in 0..nchunk { // lane-av1-ibcvtx: the chunk's chroma units inherit the CHROMA tx @@ -17404,8 +18220,8 @@ fn decode_block( let mut u_pass: Vec = Vec::new(); for plane_pass in 1..=2usize { let mut pass_idx = 0usize; - for cu_row in ch_row * cpc..(ch_row + 1) * cpc { - for cu_col in ch_col * cpc..(ch_col + 1) * cpc { + for cu_row in ch_row * cpc_rows..(ch_row + 1) * cpc_rows { + for cu_col in ch_col * cpc_cols..(ch_col + 1) * cpc_cols { // libaom `decode_reconstruct_tx`'s frame-edge clip // (decodeframe.c:299, `blk_row >= max_blocks_high || blk_col // >= max_blocks_wide` returns before ANY symbol is read): a @@ -17437,68 +18253,108 @@ fn decode_block( let over_w_px = over_w_mi.min(0) * (MI >> ss_x(fctx)) as i32; let over_h_px = over_h_mi.min(0) * (MI >> ss_y(fctx)) as i32; let max_units_w = ((plane_px + over_w_px) >> 2).max(0) as usize; - let max_units_h = ((plane_px + over_h_px) >> 2).max(0) as usize; - let unit = chroma_tx / 4; // TU side in 4x4 chroma units - if cu_col * unit >= max_units_w || cu_row * unit >= max_units_h { + // lane-av1-422f: the shared halved formula in the `else` counts + // the plane span in 4-px units through the 2-px-per-mi + // subsampled height, which a 4:2:2 plane does not have (ss_y + // 0) -- its span is the full luma mi count, so a keyed + // formula clips the same units libaom's `max_block_high` + // does. 4:2:0 and 4:4:4 keep the proven shared rows (at 4:2:0 + // `MI >> ss_y` is 2, the same `2 * over_h_mi.min(0)` the + // pre-ss form spelled). + let max_units_h = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + (span_mi as i32 + over_h_mi.min(0)).max(0) as usize + } else { + ((plane_px + over_h_px) >> 2).max(0) as usize + }; + let (unit_w, unit_h) = (chroma_tx / 4, chroma_tx_h / 4); + if cu_col * unit_w >= max_units_w || cu_row * unit_h >= max_units_h { hit!(CHROMA_EDGE_TU_CLIP_HITS); continue; } // The chroma context arrays are indexed in LUMA mi, so this - // unit's anchor is its own luma quadrant: `chroma_tx` chroma - // pixels span `2 * chroma_tx` luma ones. - let luma_span = chroma_tx << ss_x(fctx); + // unit's anchor is its own luma quadrant (lane-av1-422b: the + // quadrant spans `chroma_tx << ss_x` luma px wide by + // `chroma_tx_h << ss_y` tall -- at 4:2:2 below side 64 the + // one unit's quadrant is the whole block). let cu_mi = ( - mi_r + cu_row * (luma_span / MI), - mi_c + cu_col * (luma_span / MI), + mi_r + cu_row * (luma_span_y / MI), + mi_c + cu_col * (luma_span_x / MI), ); - let cu_around = neighbours.around_mi(cu_mi, luma_span); - let cu_reach = if cn == 1 { + let cu_around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + // lane-av1-422f: chroma-only loop; per-chroma-cell above + // votes (see [`Neighbours::around_mi_422_chroma`]). + neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y) + } else { + neighbours.around_mi_rect(cu_mi, luma_span_x, luma_span_y) + }; + let cu_reach = if cn_rows == 1 && cn_cols == 1 { reach } else { - tu_reach( + tu_reach_rect( side, side, - cu_col * luma_span, cu_row * luma_span, luma_span, + cu_col * luma_span_x, cu_row * luma_span_y, luma_span_x, luma_span_y, reach, px, py, y.width, y.height, fctx, ) }; - let (cu_x, cu_y) = (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx); + let (cu_x, cu_y) = + (cpx + cu_col * chroma_tx, cpy + cu_row * chroma_tx_h); if let Some((ub, vb)) = &palette_uv_bufs { let pbuf = if plane_pass == 1 { ub } else { vb }; set_palette_pred( palette_window( - pbuf, chroma_side, cu_col * chroma_tx, cu_row * chroma_tx, - chroma_tx, chroma_tx, + pbuf, chroma_side, cu_col * chroma_tx, + cu_row * chroma_tx_h, chroma_tx, chroma_tx_h, ), fctx, ); } let buf: &mut PlaneBuf<'static> = if plane_pass == 1 { &mut *u } else { &mut *v }; - let cu_grid = read_plane( - dec, cdfs, chroma_set, scans.1, plane_pass, cu_around[plane_pass], mode, - uv_predict_mode, angle_delta_uv, cu_reach, buf, cu_x, cu_y, - chroma_tx, chroma_tx, base_q_idx, - alpha.zip(ac).map(|((au, av), ac)| { - (if plane_pass == 1 { au } else { av }, ac) - }), - None, chroma_ctx_offset, smooth_neighbor_uv, fctx, - )?; - if cn > 1 { + let cu_grid = if chroma_tx == chroma_tx_h { + read_plane( + dec, cdfs, chroma_set, scans.1, plane_pass, cu_around[plane_pass], mode, + uv_predict_mode, angle_delta_uv, cu_reach, buf, cu_x, cu_y, + chroma_tx, chroma_tx, base_q_idx, + alpha.zip(ac).map(|((au, av), ac)| { + (if plane_pass == 1 { au } else { av }, ac) + }), + None, chroma_ctx_offset, smooth_neighbor_uv, fctx, + )? + } else { + // lane-av1-422f: the whole plane block as one rect unit; + // `chroma_ctx_offset` is `None` there (the unit covers + // the plane block, so the offset-7 skip rows are right). + read_rect_chroma_unit( + dec, cdfs, chroma_set, scans.1, chroma_tx, chroma_tx_h, plane_pass, + cu_around[plane_pass], uv_predict_mode, angle_delta_uv, cu_reach, buf, + cu_x, cu_y, base_q_idx, None, + alpha.zip(ac).map(|((au, av), ac)| { + (if plane_pass == 1 { au } else { av }, ac) + }), + smooth_neighbor_uv, fctx, + )? + }; + if cn_rows * cn_cols > 1 { hit!(CHROMA_SPLIT_TX_HITS); + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + hit!(CHROMA422_SQUARE_HITS); + } // Immediately, so the NEXT unit of this same block reads // this one's coefficient context (libaom's chroma // `txb_skip_ctx` for the second quadrant is 11, i.e. base // 1 from this left neighbour -- measured against aomdec). // The same writes are replayed after `record_split_luma` // below, which would otherwise clobber them whole-block. - neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_pass, &cu_grid); + neighbours.record_mi_chroma( + cu_mi, luma_span_x, luma_span_y, plane_pass, &cu_grid, + ); } if plane_pass == 1 { u_pass.push(cu_grid); } else { let u_grid = std::mem::replace(&mut u_pass[pass_idx], Grid::Zero(0)); - if cn > 1 { - units.push((cu_mi, luma_span, u_grid.clone(), cu_grid.clone())); + if cn_rows * cn_cols > 1 { + units.push((cu_mi, luma_span_x, luma_span_y, u_grid.clone(), cu_grid.clone())); } last_grids = [u_grid, cu_grid]; } @@ -17515,9 +18371,9 @@ fn decode_block( // context write; at `cn > 1` the per-unit writes above are what the // next block reads, so they run after this (last writer wins). neighbours.record_split_luma(at, side, mode, uv_predict_mode, [&last_grids[0], &last_grids[1]]); - for (cu_mi, luma_span, u_grid, v_grid) in &units { - neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 1, u_grid); - neighbours.record_mi_chroma(*cu_mi, *luma_span, *luma_span, 2, v_grid); + for (cu_mi, sw, sh, u_grid, v_grid) in &units { + neighbours.record_mi_chroma(*cu_mi, *sw, *sh, 1, u_grid); + neighbours.record_mi_chroma(*cu_mi, *sw, *sh, 2, v_grid); } } // Unconditional, `size == 0` for a non-palette block: clears any stale @@ -18221,7 +19077,16 @@ fn decode_leaf8( let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx)); // 4:4:4: this 8x8 block's chroma plane block is 8x8 (same scan as luma, // `scans.0`). 4:2:0 stays the 4x4 unit this leaf was written for. + // lane-av1-422d: 4:2:2 (ss 1/0) halves only the width, so the plane block + // is 4x8 -- ONE rect transform unit per plane (`av1_get_max_uv_txsize( + // BLOCK_8X8)` at ss (1,0) is `max_txsize_rect_lookup[BLOCK_4X8]` == + // TX_4X8): one txb_skip + one scan per plane in the + // [`TxbSet::ChromaRect8x4`] class [`decode_rect_split`] proves for the + // shape, read through [`leaf8_chroma422_unit`] in each arm below. The + // `(csz, cset, cscan)` selection keeps serving the square arms (444's + // 8x8, 420's 4x4); the rect arms branch on [`chroma_422`] instead. let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; + let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; let (csz, cset, cscan) = if chroma_444 { (8usize, TxbSet::Chroma8, scans.0) } else { @@ -18240,11 +19105,14 @@ fn decode_leaf8( 8, 8, mc::InterpFilterKind::Bilinear, &mut yb, fctx, ); // The chroma extent is THIS frame's subsampled size of the 8x8 luma - // leaf (`get_plane_block_size`): 4x4 at 4:2:0, 8x8 at 4:4:4. The - // literal 4x4 this replaces hardcoded the 4:2:0 halving -- at 4:4:4 - // the 16-sample override fed this leaf's own 8x8 chroma reconstruct, - // which indexed `prediction[16]` of a 16-sample buffer - // (len 16, index 16 at `PlaneBuf::reconstruct`). The same buffers + // leaf (`get_plane_block_size`): 4x4 at 4:2:0, 4x8 at 4:2:2, 8x8 at + // 4:4:4. The literal 4x4 this replaces hardcoded the 4:2:0 halving -- + // at 4:4:4 the 16-sample override fed this leaf's own 8x8 chroma + // reconstruct, which indexed `prediction[16]` of a 16-sample buffer + // (len 16, index 16 at `PlaneBuf::reconstruct`), and at 4:2:2 it + // covered half the leaf's 4x8 chroma plane block (lane-av1-422d's + // `if chroma_422 { (4, 8) }` arm, which the ss-derived form subsumes: + // `8 >> ss_x` is 4 and `8 >> ss_y` is 8 there). The same buffers // are windowed at stride 8 by `read_intra_chroma_lossless` (the TX4 // 4:4:4-lossless arm) and consumed whole by the TX8 and skip arms, // so all three heal with this one sizing. @@ -18347,13 +19215,36 @@ fn decode_leaf8( ); } let ac = alpha.map(|_| cfl_src(px, py, 8)); + // Three skip-arm shapes, dispatched on THIS frame's subsampling. + // lane-av1-422d: at 4:2:2 a skipped leaf still predicts its 4x8 rect + // unit per plane (CfL keeps its contribution, [`decode_block`]'s own + // skip-arm rule); no coefficient symbol exists, so the entropy + // context never enters the rect read. + if chroma_422 { + u_grid = leaf8_chroma422_unit( + dec, cdfs, (false, false, 0), uv_predict_mode, angle_delta_uv, reach, + 1, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), true, + intrabc_bufs.as_ref().map(|(_, ub, _)| ub.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone())), + u, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + v_grid = leaf8_chroma422_unit( + dec, cdfs, (false, false, 0), uv_predict_mode, angle_delta_uv, reach, + 2, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), true, + intrabc_bufs.as_ref().map(|(_, _, vb)| vb.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone())), + v, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + luma_grid = Grid::Zero(64); + } else { // 4:4:4 lossless: the leaf's chroma plane block is a 2x2 raster of // TX_4X4 units (`av1_get_tx_size`: lossless forces TX_4X4 on EVERY // plane), so a skipped leaf predicts per unit -- each from its own // edges -- like the luma `SKIP_SPLIT_TX` loop above. CfL never fires // here (`is_cfl_allowed` at lossless needs plane_bsize == 4x4; this // chroma plane block is 8x8), and intrabc/palette keep the - // whole-plane-block prediction they already run. + // whole-plane-block prediction they already run. The guard also + // requires `chroma_444`, so it can never reach the 4:2:2 arm above. let chroma_units_444 = chroma_444 && lossless(fctx) && intrabc_bufs.is_none() @@ -18441,8 +19332,22 @@ fn decode_leaf8( luma_grid = Grid::Zero(64); u_grid = Grid::Zero(csz * csz); v_grid = Grid::Zero(csz * csz); + } } else if resolved != 4 { let around = neighbours.around_mi(leaf_mi, 8); + // lane-av1-422h: the 4:2:2 chroma rect unit's `get_txb_ctx_general` + // reads its above votes over CHROMA 4-px cells -- at ss_x 1 one chroma + // cell spans TWO luma mi columns, so the per-luma-mi sum counts each + // above chroma column twice and `dc_sign_ctx`'s signum flips whenever + // the doubled sum crosses zero (the same class + // [`Neighbours::around_mi_422_chroma`] fixes for the rect readers; + // measured at mi(2,24) plane 2: ours dc_sign row 0, oracle row 2). + // The left extent is unsubsquared at ss_y 0 and stays one-to-one. + let chroma_around = if chroma_422 { + neighbours.around_mi_422_chroma(leaf_mi, 8, 8) + } else { + around + }; if let Some(buf) = &palette_y_buf { set_palette_pred(buf.clone(), fctx); } @@ -18481,6 +19386,25 @@ fn decode_leaf8( fctx.intrabc_chroma_tx.with(|c| c.set(Some(fctx.luma_tx_type.with(std::cell::Cell::get)))); } let ac = alpha.map(|_| cfl_src(px, py, 8)); + if chroma_422 { + // lane-av1-422d: ONE 4x8 rect unit per plane (`av1_get_max_uv_txsize` + // at ss (1,0) == TX_4X8), covering the plane block exactly, off the + // leaf's own 8x8-span entropy context (`chroma_tiled`'s convention). + u_grid = leaf8_chroma422_unit( + dec, cdfs, chroma_around[1], uv_predict_mode, angle_delta_uv, reach, + 1, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), false, + intrabc_bufs.as_ref().map(|(_, ub, _)| ub.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone())), + u, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + v_grid = leaf8_chroma422_unit( + dec, cdfs, chroma_around[2], uv_predict_mode, angle_delta_uv, reach, + 2, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), false, + intrabc_bufs.as_ref().map(|(_, _, vb)| vb.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone())), + v, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + } else { if let Some((_, ub, _)) = &intrabc_bufs { set_palette_pred(ub.clone(), fctx); } else if let Some((ub, _)) = &palette_uv_bufs { @@ -18535,6 +19459,7 @@ fn decode_leaf8( None, smooth_neighbor_uv, fctx, )?; + } // Disarm: `INTRABC_CHROMA_TX` is `Some` across exactly this block's // two chroma reads (`decode_block`'s own tail does the same) -- left // set, every later chroma block would inherit this luma tx_type, @@ -18644,14 +19569,38 @@ fn decode_leaf8( } } let ac = alpha.map(|_| cfl_src(px, py, 8)); - let chroma_around = neighbours.around_mi(leaf_mi, 8); + // lane-av1-422h: same ss_x-1 dc-vote sampling as the whole-leaf arm + // above -- the doubled above sum crosses zero at mi(2,24) plane 2. + let chroma_around = if chroma_422 { + neighbours.around_mi_422_chroma(leaf_mi, 8, 8) + } else { + neighbours.around_mi(leaf_mi, 8) + }; // lane-av1intrapred: the non-vacuity counter -- armed slot consulted // by this arm's chroma reads means the frame-copy + inherited-type // route ran; zero at gate time means the fixture stopped reaching it. if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { hit!(INTRABC_TX4_CHROMA_COPY_HITS); } - if chroma_444 && lossless(fctx) { + if chroma_422 { + // lane-av1-422d: the chroma unit does NOT follow the luma var-tx + // split -- `uv_txsize` is `av1_get_max_uv_txsize` of the block, + // still the one 4x8 rect unit per plane at ss (1,0). + u_grid = leaf8_chroma422_unit( + dec, cdfs, chroma_around[1], uv_predict_mode, angle_delta_uv, reach, + 1, alpha.zip(ac).map(|((au, _), ac)| (au, ac)), false, + intrabc_bufs.as_ref().map(|(_, ub, _)| ub.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(ub, _)| ub.clone())), + u, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + v_grid = leaf8_chroma422_unit( + dec, cdfs, chroma_around[2], uv_predict_mode, angle_delta_uv, reach, + 2, alpha.zip(ac).map(|((_, av), ac)| (av, ac)), false, + intrabc_bufs.as_ref().map(|(_, _, vb)| vb.clone()) + .or_else(|| palette_uv_bufs.as_ref().map(|(_, vb)| vb.clone())), + v, cpx, cpy, smooth_neighbor_uv, fctx, + )?; + } else if chroma_444 && lossless(fctx) { // 4:4:4 lossless: the leaf's chroma plane block is a 2x2 raster // of TX_4X4 units per plane, PLANE-MAJOR (`av1_get_tx_size`: // lossless forces TX_4X4 on EVERY plane) -- the same walk @@ -18823,6 +19772,77 @@ fn decode_leaf8( Ok(mode) } +/// lane-av1-422d: ONE 4:2:2 chroma transform unit of an 8x8 leaf +/// ([`decode_leaf8`]). At ss (1,0) the plane block is 4x8 and +/// `av1_get_max_uv_txsize(BLOCK_8X8)` resolves to +/// `max_txsize_rect_lookup[BLOCK_4X8]` == TX_4X8, so the WHOLE plane block is +/// a single rect unit -- one txb_skip + one scan per plane in the +/// [`TxbSet::ChromaRect8x4`] class [`decode_rect_split`] proves for the +/// shape. Mirrors [`sub8_leaf_chroma444`]'s rect arm at the leaf's halved +/// position: the entropy context is the leaf's own 8x8 luma-span +/// above/left state (the `chroma_tiled` arm's convention; no `+3` +/// plane-block-bigger term -- the unit covers the plane block exactly), the +/// CFL source is the leaf's whole 8x8 luma block, and the plane's predicted +/// mode supplies the mode-derived default `tx_type` unless an armed +/// [`INTRABC_CHROMA_TX`] slot carries the intrabc luma's own (the caller +/// arms and disarms it, exactly as it does around its square reads). +#[allow(clippy::too_many_arguments)] +fn leaf8_chroma422_unit( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + around: (bool, bool, i32), + uv_predict_mode: usize, + angle_delta_uv: i32, + reach: Reach, + plane_idx: usize, + cfl: Option<(i32, CflSrc)>, + skip: bool, + // The prediction override the square arms feed through + // `set_palette_pred`: an intrabc leaf's frame copy at the DV takes + // priority over a palette block's colour-index map. + pred_override: Option>, + // Unread, like [`read_plane`]'s own: the borrow proves the caller holds + // the plane exclusively while the unit's coefficients are parsed. + _plane: &mut PlaneBuf<'static>, + cpx: usize, + cpy: usize, + smooth_neighbor_uv: bool, fctx: &crate::decode::FrameCtx, +) -> Result { + // The unit's prediction runs whether or not a residual follows it -- a + // skipped leaf still predicts (the CfL contribution survives a skip), + // and a skipped intrabc leaf still copies the frame at its DV. + if let Some(buf) = pred_override { + set_palette_pred(buf, fctx); + } + if skip { + push_intra_rect( + plane_idx, cpx, cpy, 4, 8, uv_predict_mode, angle_delta_uv, reach, + &ZERO_RESIDUAL[..4 * 8], cfl, None, smooth_neighbor_uv, fctx, + ); + return Ok(Grid::Zero(4 * 8)); + } + let default_tx = fctx + .intrabc_chroma_tx + .with(std::cell::Cell::get) + .unwrap_or_else(|| default_intra_tx_type(uv_predict_mode as u8)); + let mut coding = cdfs.txb(TxbSet::ChromaRect8x4, uv_predict_mode); + let (levels, tx_type) = read_coeffs_rect( + dec, &mut coding, &SCAN_4X8, 4, 8, + usize::from(around.0) + usize::from(around.1), + dc_sign_ctx(around.2), default_tx, + )?; + let residual = dequant_and_inverse_typed_wh( + &levels, 4, 8, crate::decode::bit_depth(fctx), block_q_idx(fctx), + plane_q_delta(plane_idx, fctx).0, plane_q_delta(plane_idx, fctx).1, + tx_type, block_iqmatrix(fctx, plane_idx, 4, 8, tx_type), + ); + push_intra_rect( + plane_idx, cpx, cpy, 4, 8, uv_predict_mode, angle_delta_uv, reach, + &residual, cfl, None, smooth_neighbor_uv, fctx, + ); + Ok(levels) +} + /// `read_intra_frame_mode_info`'s mode-info read for one `BLOCK_4X4` leaf /// below an 8x8 partition (spec `decode_partition`'s `bSize < BLOCK_8X8` /// bottom, where no partition symbol is read at all -- `decode_block` runs @@ -19356,6 +20376,173 @@ fn grid_unit_state(grid: &Grid, bw: usize, x0: usize, y0: usize, unit_w: usize, } +/// [`sub8_leaf_chroma444`] for 4:2:2 (lane-av1-422g): an even-mi-column 4x4 +/// leaf is its plane's own chroma reference (`is_chroma_reference`'s +/// `!(mi_col & ss_x)` at ss_x 1 -- every even-column leaf, not 4:2:0's single +/// bottom-right one) and codes ONE TX_4X4 chroma unit per plane right after +/// its luma: `ss_size_lookup[BLOCK_4X4][1][0]` is BLOCK_4X4, so the (2, 4) +/// plane area rounds up to the square 4x4 read. The unit sits at the chroma +/// position (`px >> ss_x`), and its 4 chroma-px width spans TWO luma mi +/// columns, so the context reads go through +/// [`Neighbours::around_mi_422_chroma`] and the entropy stamp covers both +/// columns with the unit's whole-unit state. +#[allow(clippy::too_many_arguments)] +fn sub8_leaf_chroma422( + dec: &mut SymbolDecoder, + cdfs: &mut Cdfs, + neighbours: &mut Neighbours, + lmi: (usize, usize), + uv_mode: usize, + angle_delta_uv: i32, + alpha: Option<(i32, i32)>, + skip: bool, + intrabc_dv: Option<(i32, i32)>, + y: &PlaneBuf<'static>, + u: &mut PlaneBuf<'static>, + v: &mut PlaneBuf<'static>, + scan4: &[u16], + base_q_idx: u8, + smooth_neighbor_uv: bool, + // The owning luma leaf's own shape (`(4, 4)` for a split leaf, `(8, 4)` / + // `(4, 8)` for a rect pair's strip): libaom's `has_top_right` / + // `has_bottom_left` answer for this chroma TX_4X4 unit comes from the + // LEAF's own rect table row at the leaf's mi (`bsize` is the leaf, the + // unit covers it whole), never the standalone square-4x4 table the old + // `Reach::of(4, ..)` lookup used -- that said 1 where `has_tr_8x4` says 0 + // at mi(27,44) (the oracle's own EC_PRED prints `n_tr=0` there), so the + // D45 unit read undecoded pixels to its upper right. + leaf_shape: (usize, usize), + fctx: &crate::decode::FrameCtx, +) -> Result<(Grid, Grid)> { + let uv_predict_mode = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + // lane-av1-422kf2: libaom writes one MB_MODE_INFO per mi cell the LEAF + // covers, and `chroma_left_mbmi`/`chroma_above_mbmi` read whichever of + // those cells the next block's snap lands on -- an 8x4 strip's SM_V + // uv_mode must therefore be visible at BOTH of its mi columns, or the + // block to its right (mi (30,50): left neighbour cell (30,49)) missed the + // smooth neighbour and skipped libaom's strength-1 intra edge filter + // (class context-read-from-one-cell, the 4:2:2 sub-8 twin of the + // lane-kf900 snap fix). + neighbours.record_uv_mode_mi( + lmi.0, + lmi.1, + (leaf_shape.0 / MI).max(1), + (leaf_shape.1 / MI).max(1), + uv_predict_mode, + ); + let (px, py) = (lmi.1 * MI, lmi.0 * MI); + // lane-av1-422kf2: the unit's WRITE/PREDICTION anchor is the same floored + // chroma cell as the entropy anchor below -- libaom positions the sub-8 + // chroma plane block at `av1_setup_dst_planes`' mi-exact floor + // (`(mi_col & !1) * MI >> ss_x`), NOT at the odd leaf's own chroma x: + // the oracle's mi(18,55) TX_4X4 unit reconstructed chroma px 108..111 + // (a pure V-copy of the row above at 108..111), while the leaf's own + // chroma x is 110 -- anchoring there left px 108..109 unwritten (zeros) + // and stepped px 112..113 with the unit's right columns. + let (cpx, cpy) = (((lmi.1 & !1) * MI) >> ss_x(fctx), py >> ss_y(fctx)); + // lane-av1-422h: the entropy-context anchor is the unit's FLOOR chroma + // cell (`pd->above_entropy_context + (mi_col >> ss_x)`): an ODD-column + // leaf's 4-px unit starts at a chroma px that is NOT cell aligned, and + // both its ctx read and its ctx write live in the cell containing that + // start -- one luma mi column to the LEFT of the leaf's own. Even-column + // (cell-aligned) leaves keep their own column. The state write spans the + // anchor's two luma mi columns, so the second (odd) leaf of a split group + // overwrites exactly the cell the first one wrote, as libaom's + // `av1_set_entropy_contexts` per-TU writes do. + let ctx_mi = (lmi.0, lmi.1 & !1); + // lane-av1-422kf2: the square unit takes the leaf's OWN reach: a split + // leaf is a standalone BLOCK_4X4 (square table), a rect pair's strip is + // `of_rect` on the strip's true (8x4 / 4x8) shape -- libaom passes the + // LEAF's bsize to `has_top_right`/`has_bottom_left`, so a rect strip's + // answer comes from `has_tr_8x4`/`has_tr_4x8` at the strip's mi, not + // from a 4x4-block lookup. + let reach = if leaf_shape == (4, 4) { + Reach::of(4, px, py, y.width, y.height, fctx) + } else { + Reach::of_rect(leaf_shape.0, leaf_shape.1, px, py, y.width, y.height, fctx) + }; + let chroma_around = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); + let ac = alpha.map(|_| cfl_src_rect(px, py, 8, 4)); + let grids: (Grid, Grid) = if skip { + // A skipped chroma-reference leaf still predicts (the CfL contribution + // survives a skip); no coefficient symbol exists. + if alpha.is_some() { + hit!(CHROMA_SKIP_CFL_HITS); + hit!(SKIP_CFL_HITS); + } + push_intra(1, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx); + push_intra(2, cpx, cpy, 4, uv_predict_mode, angle_delta_uv, reach, &ZERO_RESIDUAL[..16], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx); + // The same arm-without-clear route the 4:2:0 tails count: a skipped + // leaf reads no coefficient, so an armed intrabc slot is dropped. + if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { + hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS); + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + } + (Grid::Zero(16), Grid::Zero(16)) + } else if let Some(dv) = intrabc_dv { + hit!(CHROMA422_SUB8_HITS); + // Frame copy at the DV; the residual still reads the ordinary chroma + // tables with the inherited luma `tx_type` (see the 4:2:0 tails). + let mut ub = vec![0u16; 16]; + mc::predict_with_filter( + &u.data, u.width, u.true_width, u.true_height, + mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), + 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, + ); + let mut vb = vec![0u16; 16]; + mc::predict_with_filter( + &v.data, v.width, v.true_width, v.true_height, + mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), + 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + ); + set_palette_pred(ub, fctx); + let ug = read_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED, + 0, reach, u, cpx, cpy, 4, TX4, base_q_idx, + None, None, None, smooth_neighbor_uv, fctx, + )?; + set_palette_pred(vb, fctx); + let vg = read_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED, + 0, reach, v, cpx, cpy, 4, TX4, base_q_idx, + None, None, None, smooth_neighbor_uv, fctx, + )?; + fctx.intrabc_chroma_tx.with(|c| c.set(None)); + (ug, vg) + } else { + hit!(CHROMA422_SUB8_HITS); + let ug = read_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], uv_mode, uv_predict_mode, + angle_delta_uv, reach, u, cpx, cpy, 4, TX4, base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, None, smooth_neighbor_uv, fctx, + )?; + let vg = read_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], uv_mode, uv_predict_mode, + angle_delta_uv, reach, v, cpx, cpy, 4, TX4, base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, None, smooth_neighbor_uv, fctx, + )?; + (ug, vg) + }; + // libaom `av1_set_entropy_contexts` stamps above/left PER TRANSFORM UNIT: + // the unit's own chroma span -- 1 mi row tall, TWO luma mi columns wide + // (one chroma column) -- not the 8x8 group's. + let (u_grid, v_grid) = grids; + let u_state = neighbour_state(&u_grid); + let v_state = neighbour_state(&v_grid); + if lmi.0 < neighbours.mi_rows { + neighbours.left[ctx_mi.0][1] = u_state; + neighbours.left[ctx_mi.0][2] = v_state; + } + for cell in 0..2 { + if ctx_mi.1 + cell < neighbours.mi_cols { + neighbours.above[ctx_mi.1 + cell][1] = u_state; + neighbours.above[ctx_mi.1 + cell][2] = v_state; + } + } + Ok((u_grid, v_grid)) +} + + /// Decodes a `PARTITION_SPLIT` of one 8x8 block into four `BLOCK_4X4` leaves /// (spec `decode_partition`'s recursion bottom), sharing [`decode_leaf8`]'s /// own signature so its caller's `prev_leaf`/`above_mode`/`left_mode` @@ -19413,9 +20600,14 @@ fn decode_leaf_split4( // `uv_mode` and codes its own full-resolution 4x4 chroma unit right // after its luma -- there is no shared group unit at all. let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; + // lane-av1-422g: at ss (1,0) every even-mi-column leaf is its plane's own + // chroma reference (`is_chroma_reference`'s `!(mi_col & ss_x)`) and codes + // one TX_4X4 chroma unit per plane; odd-column leaves read no chroma. + let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; // The last leaf's own `uv_predict_mode`, for the coarse above/left slots // the 4:2:0 tail fills from the group's single unit. let mut last_uv444 = DC_PRED; + let mut last_uv422 = DC_PRED; for i in 0..4usize { let (dr, dc) = (i / 2, i % 2); let lmi = (leaf_mi.0 + dr, leaf_mi.1 + dc); @@ -19433,7 +20625,18 @@ fn decode_leaf_split4( } else { leaf_modes[i - 1] }; - let has_chroma = chroma_444 || i == 3; + let has_chroma = if chroma_444 { + true + } else if chroma_422 { + // lane-av1-422h: `is_chroma_reference`'s column clause at ss_x 1 is + // `(mi_col & 1)` for a BLOCK_4X4 leaf -- the ODD-column leaf is the + // chroma reference (oracle, mi(30,42) split group: uv_mode read at + // mi(30,43) and mi(31,43) only). The even-column rule this + // replaces came from 422f's pre-partition-trace misreading. + (lmi.1 & 1) == 1 + } else { + i == 3 + }; let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8( dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, @@ -19522,6 +20725,14 @@ fn decode_leaf_split4( neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, )?; last_uv444 = DC_PRED; + } else if chroma_422 { + sub8_leaf_chroma422( + dec, cdfs, neighbours, lmi, DC_PRED, 0, None, skip, + Some(dv), y, u, v, scan4, base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (4, 4), fctx, + )?; + last_uv422 = DC_PRED; } else { last_uv = Some((DC_PRED, 0, None)); // lane-av1txbands: the group's chroma is the CHROMA-REFERENCE @@ -19587,6 +20798,16 @@ fn decode_leaf_split4( neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, )?; last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + } else if chroma_422 { + let (uv_mode, angle_delta_uv, alpha) = + chroma.expect("4:2:2 reads uv_mode on even-column leaves"); + sub8_leaf_chroma422( + dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, skip, + None, y, u, v, scan4, base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (4, 4), fctx, + )?; + last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; } else { last_uv = chroma; } @@ -19604,6 +20825,14 @@ fn decode_leaf_split4( neighbours.above_uv_mode[c] = last_uv444; neighbours.left_uv_mode[r] = last_uv444; (Grid::Zero(16), Grid::Zero(16)) + } else if chroma_422 { + // lane-av1-422g: each even-column leaf coded and reconstructed its + // own TX_4X4 chroma unit in the loop above (sub8_leaf_chroma422 + // stamped the per-leaf entropy state); only the coarse slots remain, + // filled from the group's last chroma-reference leaf (bottom-left). + neighbours.above_uv_mode[c] = last_uv422; + neighbours.left_uv_mode[r] = last_uv422; + (Grid::Zero(16), Grid::Zero(16)) } else { let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); @@ -19651,13 +20880,13 @@ fn decode_leaf_split4( let mut ub = vec![0u16; 16]; mc::predict_with_filter( &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_x(fctx)), + mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, ); let mut vb = vec![0u16; 16]; mc::predict_with_filter( &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_x(fctx)), + mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, ); let chroma_around = neighbours.around_mi(leaf_mi, 8); @@ -19715,7 +20944,8 @@ fn decode_leaf_split4( } // lane-av1-444: at 4:4:4 [`sub8_leaf_chroma444`] already stamped each // leaf's own span as it decoded; these placeholder grids carry no state. - if !chroma_444 { + // lane-av1-422g: the 4:2:2 per-leaf units stamp the same way. + if !chroma_444 && !chroma_422 { let round_up_even = |n: usize| n.div_ceil(2) * 2; let bound_h = round_up_even(neighbours.mi_rows); let bound_w = round_up_even(neighbours.mi_cols); @@ -19813,6 +21043,15 @@ fn decode_leaf_rect8( // full-resolution rect chroma unit right after its luma. let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; let mut last_uv444 = DC_PRED; + // lane-av1-422h: at ss (1,0) `is_chroma_reference` + // (av1_common_int.h:1459) resolves per strip shape -- + // `((mi_row & 1) || !(bh_mi & 1) || !ss_y) && ((mi_col & 1) || !(bw_mi & 1) || !ss_x)`: + // a HORZ pair is two BLOCK_8X4 strips at the group's even column, so + // BOTH strips are chroma references (`!(bw & 1)`); a VERT pair is two + // BLOCK_4X8 strips, and the column clause keeps only the ODD-column + // strip (i == 1, the same leaf the 4:2:0 rule reads chroma on). + let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; + let mut last_uv422 = DC_PRED; for i in 0..2usize { let lmi = if vert { (leaf_mi.0, leaf_mi.1 + i) @@ -19831,7 +21070,13 @@ fn decode_leaf_rect8( } else { neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode) }; - let has_chroma = chroma_444 || i == 1; + let has_chroma = if chroma_444 { + true + } else if chroma_422 { + !vert || i == 1 + } else { + i == 1 + }; let skip_ctx = neighbours.skip_txfm_ctx(lmi.0, lmi.1); let (skip, mode, angle_delta_y, chroma, filter_intra, intrabc) = read_intra_mode_sub8( dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, @@ -20081,6 +21326,16 @@ fn decode_leaf_rect8( neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, )?; last_uv444 = DC_PRED; + } else if chroma_422 { + // lane-av1-422h: same at ss (1,0) -- the strip's own square + // TX_4X4 chroma unit at its halved position. + sub8_leaf_chroma422( + dec, cdfs, neighbours, lmi, DC_PRED, 0, None, skip, + Some(dv), y, u, v, scan4, base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (bw, bh), fctx, + )?; + last_uv422 = DC_PRED; } else { last_uv = Some((DC_PRED, 0, None)); last_intrabc = Some(dv); @@ -20238,6 +21493,18 @@ fn decode_leaf_rect8( neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, )?; last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + } else if chroma_422 { + // lane-av1-422h: the strip's own square TX_4X4 chroma unit + // per plane right after its split luma (one per ref strip). + let (uv_mode, angle_delta_uv, alpha) = + chroma.expect("4:2:2 chroma references read uv_mode"); + sub8_leaf_chroma422( + dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, + skip, None, y, u, v, scan4, base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (bw, bh), fctx, + )?; + last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; } else { last_uv = chroma; } @@ -20327,6 +21594,21 @@ fn decode_leaf_rect8( neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), fctx, )?; last_uv444 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; + } else if chroma_422 { + // lane-av1-422h: the strip's own square TX_4X4 chroma unit + // per plane right after its luma -- libaom codes each + // BLOCK_8X4 strip's chroma under the strip itself (both + // strips of a HORZ pair are chroma references), not one + // shared group unit. + let (uv_mode, angle_delta_uv, alpha) = + chroma.expect("4:2:2 chroma references read uv_mode"); + sub8_leaf_chroma422( + dec, cdfs, neighbours, lmi, uv_mode, angle_delta_uv, alpha, + skip, None, y, u, v, scan4, base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (bw, bh), fctx, + )?; + last_uv422 = if uv_mode == UV_CFL_PRED { DC_PRED } else { uv_mode }; } else { last_uv = chroma; } @@ -20343,6 +21625,15 @@ fn decode_leaf_rect8( neighbours.above_uv_mode[c] = last_uv444; neighbours.left_uv_mode[r] = last_uv444; (Grid::Zero(16), Grid::Zero(16)) + } else if chroma_422 { + // lane-av1-422h: every chroma-reference strip coded and reconstructed + // its own chroma unit in the loop above (and stamped its own entropy + // span), so the 4:2:0 shared group unit below must not run. Only the + // coarse 16x16 slots remain: libaom's `above_uv_mode`/`left_uv_mode` + // end up holding the LAST chroma reference's mode (decode order). + neighbours.above_uv_mode[c] = last_uv422; + neighbours.left_uv_mode[r] = last_uv422; + (Grid::Zero(16), Grid::Zero(16)) } else { let (gpx, gpy) = (leaf_mi.1 * MI, leaf_mi.0 * MI); let (cpx, cpy) = (gpx >> ss_x(fctx), gpy >> ss_y(fctx)); @@ -20397,13 +21688,13 @@ fn decode_leaf_rect8( let mut ub = vec![0u16; 16]; mc::predict_with_filter( &u.data, u.width, u.true_width, u.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_x(fctx)), + mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx, ); let mut vb = vec![0u16; 16]; mc::predict_with_filter( &v.data, v.width, v.true_width, v.true_height, - mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_x(fctx)), + mv_to_q4(cpx, dv.1, ss_x(fctx)), mv_to_q4(cpy, dv.0, ss_y(fctx)), 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx, ); if leaf_skips[1] { @@ -20467,7 +21758,9 @@ fn decode_leaf_rect8( } // lane-av1-444: at 4:4:4 [`sub8_leaf_chroma444`] already stamped each // leaf's own span as it decoded; these placeholder grids carry no state. - if !chroma_444 { + // lane-av1-422h: same at ss (1,0) -- [`sub8_leaf_chroma422`] stamped each + // chroma-reference strip's own span in decode order. + if !(chroma_444 || chroma_422) { let round_up_even = |n: usize| n.div_ceil(2) * 2; let bound_h = round_up_even(neighbours.mi_rows); let bound_w = round_up_even(neighbours.mi_cols); @@ -22101,7 +23394,23 @@ fn rect_inter_chroma_set(w: usize, h: usize) -> Result { // block (`av1_get_max_uv_txsize` adjusts `TX_64X32`/`TX_32X64` to // `TX_32X32`); `get_txsize_entropy_ctx(TX_32X32)` is the 32x32 set. (32, 32) => TxbSet::Chroma32, + // lane-av1-422j: square chroma units of a 4:2:2 strip -- a 16x8 + // (8x16) luma strip's chroma plane block is 8x8 (16x16) square, and + // the square-block routing above sends it here. The sets are the + // exact `get_txsize_entropy_ctx` tables the square arms use. + (16, 16) => TxbSet::Chroma16, + (8, 8) => TxbSet::Chroma8, + (4, 4) => TxbSet::Chroma4, _ => { + // lane-av1-422l: the refusing (w, h) for the owning lane -- the + // 4:2:2 frontier stops here at (4, 32), the plane residual of an + // 8x32 luma block, which libaom itself marks BLOCK_INVALID + // (`av1_ss_size_lookup[BLOCK_8X32][1][0]`, common_data.c:38) and + // for which no TX_4X32 exists -- that chroma is coded as a + // TX_8X32-chunked merge, not a 4-px unit. + if crate::envflags::env_flag!("EC_AV1_TRACE_422") { + eprintln!("EC_422 rect_inter_chroma_set missing (w,h)=({w},{h})"); + } return Err(unsupported( "a rectangular inter chroma transform unit whose shape has no coefficient table set here", )); @@ -22155,6 +23464,11 @@ fn rect_scan(w: usize, h: usize) -> Result<&'static [u16]> { (4, 8) => &SCAN_4X8, (32, 8) => &SCAN_32X8, (8, 32) => &SCAN_8X32, + // lane-av1-422j: square units routed through the rect reader -- a + // 4:2:2 strip's square chroma plane block (8x8 under a 16x8 strip, + // 16x16 under an 8x16 one). The default 2D scan is exactly what the + // square reader uses for the same side. + (w, h) if w == h => default_scan(w), _ => { return Err(unsupported( "a rectangular transform unit whose shape has no coefficient scan table here", @@ -22416,6 +23730,29 @@ fn read_inter_rect_chroma( fctx: &crate::decode::FrameCtx, ) -> Result<(Grid, Grid, Vec<((usize, usize), usize, Grid, usize, usize)>)> { let (uw, uh) = (write_chroma_w.min(32), write_chroma_h.min(32)); + // lane-av1-422m, CORRECTED lane-av1-422n: an 8x32 luma block HAS no + // 4:2:2 plane residual block -- `av1_ss_size_lookup[BLOCK_8X32][1][0]` + // is BLOCK_INVALID (= 255, blockd.h) -- so libaom never codes its chroma + // as a (4, 32) unit, and no such coefficient set exists (no TX_4X32 + // either). The plane is still coded, CHUNKED: `decode_token_recon_block` + // (`decodeframe.c:1022`) steps the plane in `get_vartx_max_txsize` + // units, where the `BLOCK_INVALID` plane size indexes + // `max_txsize_rect_lookup` OUT OF BOUNDS and the byte read there in the + // pinned Release oracle build is TX_4X8 -- the committed + // "adjacent `vtx_tab[0]` = TX_4X4" reading was wrong (reviewer FAIL on + // e24dc84b). `decode_reconstruct_tx`'s + // `if (tx_size == plane_tx_size || plane)` never recurses for chroma, so + // every unit reads at TX_4X8: FOUR stacked 4x8 units per plane over the + // 4x32 chroma plane. The units KEEP a tx type: `av1_get_tx_type` + // (blockd.h) has no TX_4X4 early-out -- it derives from the block's + // inherited luma type reduced into the TX_4X8 ext-tx set + // (`reduce_inherited_chroma_tx_type`), exactly like every other rect + // unit here, so the 4:2:2 drop-the-type special case is gone. + let invalid_ss_plane = ss_x(fctx) == 1 + && ss_y(fctx) == 0 + && (write_chroma_w, write_chroma_h) == (4, 32); + let (uw, uh) = if invalid_ss_plane { (4, 8) } else { (uw, uh) }; + let inherit_tx_type = Some(luma_tx_type); let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh); let multi = nx * ny > 1; let set = rect_inter_chroma_set(uw, uh)?; @@ -22463,10 +23800,13 @@ fn read_inter_rect_chroma( cu_x, cu_y, cu_pred, - Some(luma_tx_type), + inherit_tx_type, multi.then_some(3), fctx, )? .0; + if invalid_ss_plane { + hit!(CHROMA422_CHUNK_HITS); + } if multi { // Immediately, so the next unit of this block reads this // one's coefficient context (libaom updates the chroma @@ -26854,7 +28194,13 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // mirroring [`crate::tile::sb_coeff_key_frame_tile`]'s own // three-way write exactly. let part = if has_cols && has_rows { + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!("EC_PART mi_row={} mi_col={} bsize=12 ctx={} tell={} rng={}", sb_r * SB_MI, sb_c * SB_MI, ctx, dec.debug_bitpos(), dec.debug_state().0); + } let p = dec.symbol(&mut cdfs.partition_w64[ctx]); + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!("EC_PART_VAL mi_row={} mi_col={} bsize=12 value={}", sb_r * SB_MI, sb_c * SB_MI, p); + } if crate::envflags::env_flag!("EC_AV1_TRACE") { eprintln!("TRACE partition_w64 ctx={ctx} value={p}"); } @@ -26930,7 +28276,13 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows), ); let part32 = if has_cols32 && has_rows32 { + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!("EC_PART mi_row={} mi_col={} bsize=9 ctx={} tell={} rng={}", r32 * BLOCK_MI, c32 * BLOCK_MI, ctx32, dec.debug_bitpos(), dec.debug_state().0); + } let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!("EC_PART_VAL mi_row={} mi_col={} bsize=9 value={}", r32 * BLOCK_MI, c32 * BLOCK_MI, p); + } if crate::envflags::env_flag!("EC_AV1_TRACE") { let (rng, _) = dec.debug_state(); eprintln!( @@ -27016,7 +28368,13 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( let at16 = (sr, sc); let ctx16 = neighbours.partition_ctx(at16, SUB); if has_cols16 && has_rows16 { + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!("EC_PART mi_row={} mi_col={} bsize=6 ctx={} tell={} rng={}", at16.0, at16.1, ctx16, dec.debug_bitpos(), dec.debug_state().0); + } let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]); + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!("EC_PART_VAL mi_row={} mi_col={} bsize=6 value={}", at16.0, at16.1, part16); + } if crate::envflags::env_flag!("EC_AV1_TRACE") { eprintln!( "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={part16}", @@ -27340,8 +28698,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( } } let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!("EC_PART mi_row={} mi_col={} bsize=3 ctx={} tell={} rng={}", leaf_mi.0, leaf_mi.1, leaf_ctx, dec.debug_bitpos(), dec.debug_state().0); + } let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]); + if crate::envflags::env_flag!("EC_TRACE") { + eprintln!("EC_PART_VAL mi_row={} mi_col={} bsize=3 value={}", leaf_mi.0, leaf_mi.1, part8); + } if crate::envflags::env_flag!("EC_AV1_TRACE") { eprintln!( "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}" @@ -30046,6 +31410,8 @@ fn interintra_blend( bw: usize, bh: usize, stride: usize, + subw: usize, + subh: usize, ii_mode: u8, wedge: Option<(&'static [u8], usize)>, pred: &mut [u16], fctx: &crate::decode::FrameCtx, @@ -30092,25 +31458,38 @@ fn interintra_blend( let m = u32::from(match wedge { // lane-wii r2: wedge-interintra mask (aom_blend_a64_mask // over the wedge codebook, intra as src0, fixed sign 0). - // Luma plane: mask rows are luma-resolution, ms == side. - // 4:2:0 chroma: 2x2 box average (reconinter.c sub8x8 -- - // subw == subh == 1). - Some((mask, ms)) if ms == stride => mask[i * stride + j], - Some((mask, ms)) => { - let t = 2 * i * ms + 2 * j; - ((u32::from(mask[t]) - + u32::from(mask[t + 1]) - + u32::from(mask[t + ms]) - + u32::from(mask[t + ms + 1]) - + 2) - >> 2) as u8 - } - None => match ii_mode { - 0 => 32, + // `(subw, subh)` are the plane's own subsampling shifts; + // the four branches mirror aom_dsp/blend-a64-mask.c's + // `subw`/`subh` pair handling exactly: luma (0, 0) reads + // the direct sample, (1, 1) the 2x2 box average + // (reconinter.c sub8x8), and 4:2:2's (1, 0) the + // `AOM_BLEND_AVG` column pair. + Some((mask, ms)) => match (subw, subh) { + (0, 0) => u32::from(mask[i * ms + j]), + (1, 1) => { + let t = 2 * i * ms + 2 * j; + (u32::from(mask[t]) + + u32::from(mask[t + 1]) + + u32::from(mask[t + ms]) + + u32::from(mask[t + ms + 1]) + + 2) + >> 2 + } + (1, 0) => { + let t = i * ms + 2 * j; + (u32::from(mask[t]) + u32::from(mask[t + 1]) + 1) >> 1 + } + (_sw, _sh) => { + let t = 2 * i * ms + j; + (u32::from(mask[t]) + u32::from(mask[t + ms]) + 1) >> 1 + } + }, + None => u32::from(match ii_mode { + 0 => 32u8, 1 => II_WEIGHTS_1D[i * scale], 2 => II_WEIGHTS_1D[j * scale], _ => II_WEIGHTS_1D[i.min(j) * scale], - }, + }), }); let idx = i * stride + j; pred[idx] = ((m * u32::from(intra[i * bw + j]) + (64 - m) * u32::from(pred[idx]) + 32) @@ -31120,7 +32499,17 @@ fn decode_inter_block( Some(s) if s.has_chroma => (s.pair_mi.1 * MI >> ss_x(fctx), s.pair_mi.0 * MI >> ss_y(fctx)), _ => (px >> ss_x(fctx), py >> ss_y(fctx)), }; - let chroma_side = side >> ss_x(fctx); + // lane-av1-422j: the chroma prediction/residual buffers are + // `chroma_side`-square and every consumer indexes them + // `row * chroma_side + col` over the WRITE rect (`write_chroma_w` x + // `write_chroma_h`). At ss (1,0) that rect is `side/2 x side` (an 8x16 + // strip's 4x16 chroma), so a `side >> ss_x` square is shorter than + // `row * chroma_side + write_chroma_w` on rows `>= side/2` -- frame 1's + // skipped VERT_B strip read `prediction[64..68]` out of the 64-sample + // buffer (reconstruct_mc_rect panic, decode.rs:29094). The enclosing + // square of the chroma rect is the max: unchanged at 4:2:0 (side/2) and + // 4:4:4 (side), so only 4:2:2 changes shape. + let chroma_side = (side >> ss_x(fctx)).max(side >> ss_y(fctx)); let (write_chroma_w, write_chroma_h) = match strip_chroma { Some(s) if s.has_chroma => { // 4:2:0: the PAIR's 8x4 / 4x8. 4:4:4: the strip's own 16x4 / @@ -32010,7 +33399,7 @@ fn decode_inter_block( }; if let Some(mask_y) = mask_y { mc::blend_masked_compound( - &inter0_y, &inter1_y, mask_y, side, side, side, false, &mut pred_y, fctx, + &inter0_y, &inter1_y, mask_y, side, side, side, 0, 0, &mut pred_y, fctx, ); } else { mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y, fctx); @@ -32074,6 +33463,13 @@ fn decode_inter_block( } let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side); if let Some(mask_y) = mask_y { + // lane-av1-422sub8rect stop-note: this fn's 4:2:2 chroma + // prediction is still the square-cut model (the owning + // parent-lane surface) -- its buffer is `chroma_side`-square + // and cannot be indexed by the subsampled-axis mask walks, + // so at ss_x != ss_y the blend keeps the direct + // luma-resolution read (the pre-port behaviour, known + // divergent there) until that surface itself is ported. mc::blend_masked_compound( &inter0_u, &inter1_u, @@ -32081,7 +33477,8 @@ fn decode_inter_block( side, chroma_side, chroma_side, - ss_x(fctx) == 1 && ss_y(fctx) == 1, + if ss_x(fctx) == ss_y(fctx) { ss_x(fctx) } else { 0 }, + if ss_x(fctx) == ss_y(fctx) { ss_y(fctx) } else { 0 }, &mut pred_u, fctx, ); } else { @@ -32146,6 +33543,13 @@ fn decode_inter_block( } let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side); if let Some(mask_y) = mask_y { + // lane-av1-422sub8rect stop-note: this fn's 4:2:2 chroma + // prediction is still the square-cut model (the owning + // parent-lane surface) -- its buffer is `chroma_side`-square + // and cannot be indexed by the subsampled-axis mask walks, + // so at ss_x != ss_y the blend keeps the direct + // luma-resolution read (the pre-port behaviour, known + // divergent there) until that surface itself is ported. mc::blend_masked_compound( &inter0_v, &inter1_v, @@ -32153,7 +33557,8 @@ fn decode_inter_block( side, chroma_side, chroma_side, - ss_x(fctx) == 1 && ss_y(fctx) == 1, + if ss_x(fctx) == ss_y(fctx) { ss_x(fctx) } else { 0 }, + if ss_x(fctx) == ss_y(fctx) { ss_y(fctx) } else { 0 }, &mut pred_v, fctx, ); } else { @@ -32595,9 +34000,19 @@ fn decode_inter_block( // whole-block record must not overwrite them with the // assembled grid (class `override-slot-on-one-arm`). mu_chroma = true; - } else if rect_tu { + } else if rect_tu + || (write_chroma_w, write_chroma_h) != (chroma_side, chroma_side) + { // One chroma read for the whole strip at 4:2:0, two // 32-capped units at 4:4:4 -- see the helper. + // lane-av1-422j: a 4:2:2 square block's chroma plane is the + // (side/2 x side) rect (a 32x32 block's 16x32), never + // `chroma_side`-square -- the square read below would pair + // a `chroma_side`-square unit with the 4:2:0 unit scan + // (one-coefficient-per-position assert in + // inverse_transform_2d_typed_wh). The rect reader codes + // the exact `av1_get_max_uv_txsize` unit (TX_16X32, + // `rect_inter_chroma_set`'s tables). (u_grid, v_grid, rect_chroma_units) = read_inter_rect_chroma( dec, cdfs, @@ -33560,14 +34975,14 @@ fn decode_inter_block( if write_w != write_h { hit!(INTERINTRA_RECT_HITS); } - interintra_blend(y, px, py, write_w, write_h, side, ii, wedge_mask, &mut pred_y, fctx); + interintra_blend(y, px, py, write_w, write_h, side, 0, 0, ii, wedge_mask, &mut pred_y, fctx); interintra_blend( - u, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ii, wedge_mask, - &mut pred_u, fctx, + u, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ss_x(fctx), + ss_y(fctx), ii, wedge_mask, &mut pred_u, fctx, ); interintra_blend( - v, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ii, wedge_mask, - &mut pred_v, fctx, + v, cpx, cpy, write_chroma_w, write_chroma_h, chroma_side, ss_x(fctx), + ss_y(fctx), ii, wedge_mask, &mut pred_v, fctx, ); } if let Some(plan) = &obmc { @@ -34097,9 +35512,16 @@ fn decode_inter_block( // whole-block record must not overwrite them with the // assembled grid (class `override-slot-on-one-arm`). mu_chroma = true; - } else if rect_tu { + } else if rect_tu + || (write_chroma_w, write_chroma_h) != (chroma_side, chroma_side) + { // One chroma read for the whole strip at 4:2:0, two // 32-capped units at 4:4:4 -- see the helper. + // lane-av1-422j: same rule as the compound arm above -- a + // 4:2:2 square block's chroma plane is the + // (side/2 x side) rect, so the rect reader takes it + // instead of pairing a `chroma_side`-square unit with the + // 4:2:0 scan. (u_grid, v_grid, rect_chroma_units) = read_inter_rect_chroma( dec, cdfs, @@ -34802,6 +36224,17 @@ fn decode_inter_block( } } } + // lane-av1-422k: the chroma PREDICTION shape is the plane block + // (`side >> ss_x`, `side >> ss_y`) -- square at 4:2:0/4:4:4, a + // (side/2, side) rect at 4:2:2. `chroma_side` (the 422j enclosing + // square of that rect) is the right size for BOOKKEEPING buffers but + // the wrong SHAPE to predict and reconstruct at: an intra-in-inter + // block's chroma prediction indexes its CFL signal and residual + // `row * chroma_w + col` over the plane block, and a 16x16 luma + // block's 8x16 chroma CFL signal is 128 samples -- predicting at the + // 16x16 square read `ac[128]` out of it (frame 1, px=192 py=96). + let chroma_w = side >> ss_x(fctx); + let chroma_h = side >> ss_y(fctx); if side > 64 { // Chroma is already coded and reconstructed per mu chunk above. luma_grid = Grid::Zero(side * side); @@ -34838,14 +36271,15 @@ fn decode_inter_block( if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra(1, + push_intra_unit(1, cpx, cpy, - chroma_side, + chroma_w, + chroma_h, uv_predict_mode, angle_delta_uv, reach, - &ZERO_RESIDUAL[..chroma_side * chroma_side], + &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, @@ -34853,21 +36287,22 @@ fn decode_inter_block( if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra(2, + push_intra_unit(2, cpx, cpy, - chroma_side, + chroma_w, + chroma_h, uv_predict_mode, angle_delta_uv, reach, - &ZERO_RESIDUAL[..chroma_side * chroma_side], + &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, ); luma_grid = Grid::Zero(side * side); - u_grid = Grid::Zero(chroma_side * chroma_side); - v_grid = Grid::Zero(chroma_side * chroma_side); + u_grid = Grid::Zero(chroma_w * chroma_h); + v_grid = Grid::Zero(chroma_w * chroma_h); } else { let around = neighbours.around_mi(at, side); if split_luma { @@ -35003,56 +36438,237 @@ fn decode_inter_block( u_grid = Grid::Own(u_acc); v_grid = Grid::Own(v_acc); } else { + // lane-av1-422k: the chroma plane block is (`chroma_w`, + // `chroma_h`) -- the square read above at 4:2:0/4:4:4, one rect + // TX_{side/2}X{side} unit through [`read_rect_chroma_unit`] at + // 4:2:2 (the key-frame path's proven set/scan rows, and the + // per-chroma-cell context read [`around_mi_422_chroma`]). + let chroma_around = if chroma_w == chroma_h { + around + } else { + neighbours.around_mi_422_chroma(at, side, side) + }; if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - u_grid = read_plane( - dec, - cdfs, - chroma_set, - scan_chroma, - 1, - around[1], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - u, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; + u_grid = if chroma_w == chroma_h { + read_plane( + dec, + cdfs, + chroma_set, + scan_chroma, + 1, + chroma_around[1], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + u, + cpx, + cpy, + chroma_side, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, fctx, + )? + } else if side == 64 { + // lane-av1-422inter: `av1_get_max_uv_txsize(BLOCK_64X64)` at + // ss (1,0) adjusts `max_txsize_rect_lookup[BLOCK_32X64]` = + // TX_32X64 down to TX_32X32 (`av1_get_adjusted_tx_size`), so + // the (side/2, side) = (32, 64) plane block codes TWO stacked + // SQUARE TX_32X32 units per plane, plane-major -- the + // key-frame path's own model (`decode_block`'s 4:2:2 + // chroma_tx table, "64 and 128: TX_32X64 / TX_64X64 adjust + // down to TX_32X32", proven byte-exact on this fixture's + // frame 0) and the twin of this function's own side>64 + // mu-chunk walk above. The whole-plane-block rect read this + // arm replaced handed [`read_coeffs_rect`] a 36x68 levels + // frame it never had (the frame-9 panic) and would have read + // a full TX_32X64 scan libaom never codes. + let cu_scan = default_scan(32); + let (cu_w, cu_h) = (32usize, 32usize); + let luma_span_x = cu_w << ss_x(fctx); + let luma_span_y = cu_h << ss_y(fctx); + let mut assembled = vec![0i32; chroma_side * chroma_side]; + for cu_row in 0..chroma_h / cu_h { + let cu_mi = (at_mi.0 + cu_row * (luma_span_y / MI), at_mi.1); + let cu_around = + neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y); + let cu_reach = tu_reach_rect( + side, + side, + 0, + cu_row * luma_span_y, + luma_span_x, + luma_span_y, + reach, + px, + py, + y.width, + y.height, fctx, + ); + let cu_grid = read_plane( + dec, + cdfs, + TxbSet::Chroma32, + &cu_scan, + 1, + cu_around[1], + mode, + uv_predict_mode, + angle_delta_uv, + cu_reach, + u, + cpx, + cpy + cu_row * cu_h, + cu_w, + cu_w, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + // The uv plane block (32x64) is larger than the unit + // (32x32): `get_txb_ctx`'s offset-10 rows, +3 on the + // `txb_skip_chroma_32` table (lane-sb128b r3). + Some(3), + smooth_neighbor_uv, fctx, + )?; + hit!(CHROMA_SPLIT_TX_HITS); + hit!(CHROMA422_SQUARE_HITS); + // Immediately, so the next unit of this plane reads this + // one's coefficient context; the whole-block record below + // re-stamps the block over these and the tail's + // `mu_chroma_units` replay puts the per-unit state back + // (lane-dpm1). + neighbours.record_mi_chroma(cu_mi, luma_span_x, luma_span_y, 1, &cu_grid); + for rr in 0..cu_h { + let start = (cu_row * cu_h + rr) * chroma_side; + assembled[start..start + cu_w] + .copy_from_slice(&cu_grid[rr * cu_w..][..cu_w]); + } + } + mu_chroma = true; + Grid::Own(assembled) + } else { + let (rect_set, rect_scan): (TxbSet, &[u16]) = match side { + 4 => (TxbSet::Chroma4, default_scan(4)), + 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), + 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), + 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), + _ => (TxbSet::Chroma32, default_scan(32)), + }; + read_rect_chroma_unit( + dec, cdfs, rect_set, rect_scan, chroma_w, chroma_h, 1, + chroma_around[1], uv_predict_mode, angle_delta_uv, reach, u, + cpx, cpy, base_q_idx, None, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + smooth_neighbor_uv, fctx, + )? + }; if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - v_grid = read_plane( - dec, - cdfs, - chroma_set, - scan_chroma, - 2, - around[2], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - v, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; + v_grid = if chroma_w == chroma_h { + read_plane( + dec, + cdfs, + chroma_set, + scan_chroma, + 2, + chroma_around[2], + mode, + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + chroma_side, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, fctx, + )? + } else if side == 64 { + // lane-av1-422inter: plane 2 of the TX_32X32-adjusted walk + // above -- same two stacked square units, plane-major (every + // U unit, then every V unit, libaom `decode_token_recon_block`'s + // per-mu-chunk plane loop). + let cu_scan = default_scan(32); + let (cu_w, cu_h) = (32usize, 32usize); + let luma_span_x = cu_w << ss_x(fctx); + let luma_span_y = cu_h << ss_y(fctx); + let mut assembled = vec![0i32; chroma_side * chroma_side]; + for cu_row in 0..chroma_h / cu_h { + let cu_mi = (at_mi.0 + cu_row * (luma_span_y / MI), at_mi.1); + let cu_around = + neighbours.around_mi_422_chroma(cu_mi, luma_span_x, luma_span_y); + let cu_reach = tu_reach_rect( + side, + side, + 0, + cu_row * luma_span_y, + luma_span_x, + luma_span_y, + reach, + px, + py, + y.width, + y.height, fctx, + ); + let cu_grid = read_plane( + dec, + cdfs, + TxbSet::Chroma32, + &cu_scan, + 2, + cu_around[2], + mode, + uv_predict_mode, + angle_delta_uv, + cu_reach, + v, + cpx, + cpy + cu_row * cu_h, + cu_w, + cu_w, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + Some(3), + smooth_neighbor_uv, fctx, + )?; + hit!(CHROMA_SPLIT_TX_HITS); + hit!(CHROMA422_SQUARE_HITS); + neighbours.record_mi_chroma(cu_mi, luma_span_x, luma_span_y, 2, &cu_grid); + for rr in 0..cu_h { + let start = (cu_row * cu_h + rr) * chroma_side; + assembled[start..start + cu_w] + .copy_from_slice(&cu_grid[rr * cu_w..][..cu_w]); + } + } + mu_chroma = true; + Grid::Own(assembled) + } else { + let (rect_set, rect_scan): (TxbSet, &[u16]) = match side { + 4 => (TxbSet::Chroma4, default_scan(4)), + 8 => (TxbSet::ChromaRect8x4, &SCAN_4X8[..]), + 16 => (TxbSet::ChromaRect16x8, &SCAN_8X16[..]), + 32 => (TxbSet::ChromaRect32x16, &SCAN_16X32[..]), + _ => (TxbSet::Chroma32, default_scan(32)), + }; + read_rect_chroma_unit( + dec, cdfs, rect_set, rect_scan, chroma_w, chroma_h, 2, + chroma_around[2], uv_predict_mode, angle_delta_uv, reach, v, + cpx, cpy, base_q_idx, None, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + smooth_neighbor_uv, fctx, + )? + }; } } } @@ -35476,6 +37092,17 @@ fn decode_inter_sub8_split4( // frame 1: plane 0,1,2 per leaf in leaf order) -- there is no shared // group unit and no 2x2-piece group prediction. let chroma_444 = ss_x(fctx) == 0 && ss_y(fctx) == 0; + // 4:2:2 (lane-av1-422sub8rect): `is_chroma_reference` for a BLOCK_4X4 + // piece at ss (1, 0) is `(mi_col & 0x01) || !(bw & 0x01) || !ss_x` + // == ODD mi_col (av1_common_int.h:1459) -- pieces 1 and 3 of the group + // are their plane's own chroma references and each codes its own + // TX_4X4 unit right after its luma, exactly the key-frame split-group + // behaviour the pinned t422 fixture's frame 0 traces (groups (18,54) + // and (30,42): U+V read on BOTH odd-column leaves) and frame 1's + // inter group at mi(12,2) repeats (U+V TX_4X4 ctx 8 on leaf (12,3) + // alone -- the bottom-right leaf was skipped, so it codes nothing). + // The 4:2:0 shared group unit never exists at 4:2:2. + let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; for i in 0..4usize { let (dr, dc) = (i / 2, i % 2); let lmi = (gr + dr, gc + dc); @@ -35528,7 +37155,9 @@ fn decode_inter_sub8_split4( } // lane-sub8intra: the `BLOCK_4X4` twin of the HORZ/VERT arm -- // same [`decode_intra_sub8_leaf`], no tx-depth symbol, chroma on - // the LAST sub-block (`is_chroma_reference` under 4:2:0). + // the chroma-reference sub-blocks (`is_chroma_reference`: the + // LAST one under 4:2:0, BOTH odd-column ones at 4:2:2, every + // one at 4:4:4). decode_intra_sub8_leaf( dec, cdfs, @@ -35537,7 +37166,7 @@ fn decode_inter_sub8_split4( group_mi, lmi, (B4, B4), - chroma_444 || i == 3, + chroma_444 || (cmi & 1 == 1 && chroma_422) || i == 3, skip, scan4, y, @@ -35909,6 +37538,150 @@ fn decode_inter_sub8_split4( neighbours.record_mi_chroma(lmi, B4, B4, 1, &ug); neighbours.record_mi_chroma(lmi, B4, B4, 2, &vg); } + // lane-av1-422sub8rect: the 4:2:2 per-piece arm. `is_chroma_reference` + // for a BLOCK_4X4 at ss (1, 0) is the odd mi_col (`av1_common_int.h` + // :1459), so THIS piece (right column of the group) is a chroma + // reference and codes its own U and V TX_4X4 units right after its + // luma -- measured on the pinned t422 fixture: frame 0 key-frame + // groups (18,54)/(30,42) read U+V on both odd-column leaves, and + // frame 1's inter group at mi(12,2) reads U+V TX_4X4 ctx 8 on leaf + // (12,3) alone (its bottom-right twin was skipped). + // + // The unit anchors at the FLOORED chroma cell + // (`av1_setup_dst_planes`' `(mi_col & !1) * MI >> ss_x`, the + // lane-av1-422kf2 rule), so the 4-px-wide square covers the group's + // whole chroma width, and the prediction walks + // `build_inter_predictors_sub8x8` (reconinter_template.inc): the + // left 2x4 half from the LEFT piece's own ref/mv/filters, the right + // 2x4 half from this piece's -- unless the left piece is intra (or + // off-frame), which makes `is_sub8x8_inter` false and predicts the + // whole 4x4 from THIS piece's own mv. A skipped reference piece + // still predicts (spec 7.11.3: `predict_inter_block_visit` runs + // before the `skip_txfm` guard) but codes no coefficients. + } else if chroma_422 && (cmi & 1) == 1 { + let (pc_ref, pc_mv, pc_hf, pc_vf) = piece[i].expect("inter piece recorded above"); + let unit_x = ((cmi & !1) * MI) >> ss_x(fctx); + let unit_y = py >> ss_y(fctx); + // `is_sub8x8_inter`'s left-neighbour probe (`mi[-1]`): the piece + // one mi to the LEFT, when it exists and is inter. + let piece_left = piece[i - 1]; + let build_c = move |_y: &mut PlaneBuf<'static>, + _u: &mut PlaneBuf<'static>, + _v: &mut PlaneBuf<'static>, + fctx: &crate::decode::FrameCtx, + out: &mut [Vec; 3]| { + let Some((pc_ref_y, sref_u, sref_v)) = ref_planes_deferred(pc_ref, refpix) else { + return; + }; + let pc_scale = mc::scale_factor(pc_ref_y.width, frame_width); + // The left piece's own reference planes + mv/filters, when it + // is an inter piece (`is_sub8x8_inter`'s `mi[-1]` probe). + let left = piece_left + .as_ref() + .map(|&(l_ref, l_mv, l_hf, l_vf)| { + (l_ref, l_mv, l_hf, l_vf) + }) + .and_then(|(l_ref, l_mv, l_hf, l_vf)| { + ref_planes_deferred(l_ref, refpix).map(|planes| { + let (lp_y, _, _) = planes; + let l_scale = mc::scale_factor(lp_y.width, frame_width); + (l_mv, l_hf, l_vf, planes, l_scale) + }) + }); + let mut pred_u = refill(std::mem::take(&mut out[1]), B4 * B4); + let mut pred_v = refill(std::mem::take(&mut out[2]), B4 * B4); + for (plane, dst) in [(sref_u, &mut pred_u), (sref_v, &mut pred_v)] { + let mut buf = vec![0u16; B4 * B4]; + // Right 2x4 half: this piece's own ref/mv/filters. + let mut half = vec![0u16; 2 * 4]; + mc::predict_maybe_scaled( + &plane.data, + plane.width, + plane.true_width, + plane.true_height, + mv_to_q4(unit_x + 2, pc_mv.1, ss_x(fctx)), + mv_to_q4(unit_y, pc_mv.0, ss_y(fctx)), + pc_scale, + 2, + 4, + pc_hf, + pc_vf, + &mut half, fctx, + ); + for row in 0..4 { + buf[row * B4 + 2..row * B4 + 4] + .copy_from_slice(&half[row * 2..row * 2 + 2]); + } + // Left 2x4 half: the LEFT piece's own mv/filters + // (sub8x8-inter); a mixed group (left piece intra or + // off-frame) predicts it from THIS piece too, which + // reduces to the whole-4x4-from-own rule. + let (l_mv, l_hf, l_vf, l_planes, l_scale) = match left { + Some((l_mv, l_hf, l_vf, l_planes, l_scale)) => { + (l_mv, l_hf, l_vf, l_planes, l_scale) + } + None => (pc_mv, pc_hf, pc_vf, (pc_ref_y, sref_u, sref_v), pc_scale), + }; + let (_, l_ref_u, _) = l_planes; + mc::predict_maybe_scaled( + &l_ref_u.data, + l_ref_u.width, + l_ref_u.true_width, + l_ref_u.true_height, + mv_to_q4(unit_x, l_mv.1, ss_x(fctx)), + mv_to_q4(unit_y, l_mv.0, ss_y(fctx)), + l_scale, + 2, + 4, + l_hf, + l_vf, + &mut half, fctx, + ); + for row in 0..4 { + buf[row * B4..row * B4 + 2].copy_from_slice(&half[row * 2..row * 2 + 2]); + } + dst.copy_from_slice(&buf); + } + out[1] = pred_u; + out[2] = pred_v; + }; + let (pred_cu, pred_cv): (Vec, Vec); + let (su, sv) = if recon_deferred(fctx) { + push_pred(fctx, build_c); + ( + Pred::Cur { plane: 1, stride: B4, off: 0 }, + Pred::Cur { plane: 2, stride: B4, off: 0 }, + ) + } else { + let mut built: [Vec; 3] = Default::default(); + build_c(y, u, v, fctx, &mut built); + let [_, bu, bv] = built; + (pred_cu, pred_cv) = (bu, bv); + (Pred::Inline(&pred_cu, B4), Pred::Inline(&pred_cv, B4)) + }; + // The unit's entropy context: one chroma cell wide, floored -- + // [`Neighbours::around_mi_422_chroma`] at the unit's own 8x4 + // luma span (the [`sub8_leaf_chroma422`] rule). + let ctx_mi = (rmi, cmi & !1); + let ca = neighbours.around_mi_422_chroma(ctx_mi, 8, 4); + if skip { + push_mc(1, unit_x, unit_y, B4, su, &ZERO_RESIDUAL[..B4 * B4], fctx); + push_mc(2, unit_x, unit_y, B4, sv, &ZERO_RESIDUAL[..B4 * B4], fctx); + neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ZERO_RESIDUAL[..B4 * B4]); + neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &ZERO_RESIDUAL[..B4 * B4]); + } else { + hit!(CHROMA422_INTER_SUB8_HITS); + let (ug, _) = read_inter_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 1, ca[1], 0, u, unit_x, unit_y, B4, + base_q_idx, su, Some(piece_tx_type), None, fctx, + )?; + let (vg, _) = read_inter_plane( + dec, cdfs, TxbSet::Chroma4, scan4, 2, ca[2], 0, v, unit_x, unit_y, B4, + base_q_idx, sv, Some(piece_tx_type), None, fctx, + )?; + neighbours.record_mi_chroma(ctx_mi, 8, 4, 1, &ug); + neighbours.record_mi_chroma(ctx_mi, 8, 4, 2, &vg); + } } neighbours.record_mode_mi(rmi, cmi, 1, 1, DC_PRED); neighbours.record_inter_rect_mi(lmi, 1, 1, skip, true, ref_frame, resolved_filter, false); @@ -35948,7 +37721,7 @@ fn decode_inter_sub8_split4( // frames mismatched ffmpeg by +-1..7 (class // `override-slot-on-one-arm`, this lane's own 10-bit film gate // regression at 1ad7e0fc; port of lane-av1-cfl's 7c6dad53). - if !chroma_444 && !intra_chroma { + if !chroma_444 && !chroma_422 && !intra_chroma { neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED); } // lane-t900 r23 (class [[new-map-ignores-tile-edge]]: a neighbour map @@ -35960,10 +37733,12 @@ fn decode_inter_sub8_split4( // 0). No sub-8x8 piece can itself be a palette (`av1_allow_palette` // needs `bsize >= BLOCK_8X8`), so the group always clears. record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); - if !chroma_444 && !intra_chroma { + if !chroma_444 && !chroma_422 && !intra_chroma { // Chroma, once for the whole group, on the last sub-block's own `skip` // flag -- prediction from all four sub-blocks (2x2 pieces), residual as - // one TX_4X4 unit per plane. + // one TX_4X4 unit per plane. lane-av1-422sub8rect: 4:2:2 never takes + // this arm -- the shared group unit does not exist at ss (1, 0); each + // odd-column piece coded its own chroma inside the loop above. // `is_sub8x8_inter` (reconinter_template.inc:54) is false as soon as ANY // mi of the group is intra: the group's 4x4 chroma is then predicted WHOLE // from the chroma-reference (last) sub-block's own mv, not in 2x2 pieces. @@ -36499,6 +38274,29 @@ fn decode_intra_sub8_leaf( // ours ctx 2 where libaom gathers 1). record_strip_palette(neighbours, (gr, gc), 8, 8, 0, [0u16; 8], 0, [0u16; 8]); if !has_chroma { + // lane-av1-422sub8rect: 4:2:2 has no shared group unit whose tail + // would stamp the mi map (`is_chroma_reference` runs per piece), so + // a non-referenced piece publishes its own cell -- libaom leaves + // `uv_mode` unset on it, `is_smooth` reads 0, i.e. DC_PRED. + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + neighbours.record_uv_mode_mi(lmi.0, lmi.1, 1, 1, DC_PRED); + } + return Ok(mode); + } + // lane-av1-422sub8rect: at 4:2:2 this (odd-column) piece is its plane's + // OWN chroma reference -- the key-frame split group's per-leaf TX_4X4 + // model, floored anchor and per-chroma-cell context included + // ([`sub8_leaf_chroma422`], measured on the pinned t422 fixture frame 0: + // groups (18,54)/(30,42) code U+V on both odd-column leaves), never a + // shared group unit. Inter frames code no intrabc, so `intrabc_dv` is + // `None` here. + if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + sub8_leaf_chroma422( + dec, cdfs, neighbours, lmi, uv_mode, 0, alpha, skip, + None, y, u, v, scan4, base_q_idx, + neighbours.smooth_uv_neighbour(lmi.0, lmi.1, r, c, fctx), + (bw, bh), fctx, + )?; return Ok(mode); } // The group's single 4x4 chroma unit, intra-predicted from THIS @@ -37696,18 +39494,30 @@ fn decode_inter_block8( // bookkeeping. Always `false` outside a `TxMode::Select` inter frame. let split8; const SIDE: usize = 8; - // lane-av1-444: this 8x8 leaf's chroma plane block is `8 >> ss` a side -- - // 4 at 4:2:0 (one TX_4X4 unit) and the full 8 at 4:4:4, where libaom - // codes ONE TX_8X8 unit (`av1_get_max_uv_txsize(BLOCK_8X8)` at ss 0/0, - // measured against aomdec's EC_COEFF on `av1-profile1-444.ivf` frame 1: - // plane=1 tx=TX_8X8 per 8x8 block, not a 4:2:0 4x4). - let chroma_side: usize = SIDE >> ss_x(fctx); - let (chroma_set, chroma_scan): (TxbSet, &[u16]) = if chroma_side == 8 { + // lane-av1-444 / lane-av1-422sub8rect: this 8x8 leaf's chroma plane block + // is `ss_size_lookup[BLOCK_8X8][ss_x][ss_y]` -- 4:2:0 BLOCK_4X4 (one + // TX_4X4 unit), 4:4:4 BLOCK_8X8 (ONE TX_8X8 unit, `av1_get_max_uv_txsize` + // at ss 0/0, measured against aomdec's EC_COEFF on `av1-profile1-444.ivf` + // frame 1), and 4:2:2 BLOCK_4X8 (ONE TX_4X8 RECT unit per plane, measured + // on the pinned t422 fixture: frame 1 mi(0,0) reads plane 1 tx_size 5 == + // TX_4X8 at rng 55168 right after the agreed luma TX_8X8 txb_skip -- the + // old `SIDE >> ss_x` square read was the first-divergence defect this + // port fixes). + let chroma_w: usize = SIDE >> ss_x(fctx); + let chroma_h: usize = SIDE >> ss_y(fctx); + let chroma_422 = ss_x(fctx) == 1 && ss_y(fctx) == 0; + let (chroma_set, chroma_scan): (TxbSet, &[u16]) = if chroma_422 { + // `get_txsize_entropy_ctx(TX_4X8)`: the rect fills its plane block, + // so the tables are the rect set and the SCAN_4X8 walk, exactly the + // pairing the key-frame BLOCK_4X8 arm (`decode_block`'s lane-av1-422f + // table) reads byte-exact. + (TxbSet::ChromaRect8x4, &SCAN_4X8[..]) + } else if chroma_w == 8 { (TxbSet::Chroma8, scan8) } else { (TxbSet::Chroma4, scan4) }; - let chroma_tx = if chroma_side == 8 { TX8 } else { TX4 }; + let chroma_tx = if chroma_w == 8 { TX8 } else { TX4 }; let (r, c) = outer_at; // lane-inter8 r2: this leaf's OWN mi cell, not the enclosing 16x16's -- @@ -38214,13 +40024,13 @@ fn decode_inter_block8( }; if let Some(mask_y) = mask_y { mc::blend_masked_compound( - &inter0_y, &inter1_y, mask_y, SIDE, SIDE, SIDE, false, &mut pred_y, fctx, + &inter0_y, &inter1_y, mask_y, SIDE, SIDE, SIDE, 0, 0, &mut pred_y, fctx, ); } else { mc::combine_compound(&inter0_y, &inter1_y, fwd_offset, bck_offset, &mut pred_y, fctx); } - let mut inter0_u = vec![0i32; chroma_side * chroma_side]; + let mut inter0_u = vec![0i32; chroma_w * chroma_h]; mc::predict_compound_intermediate( &pu0.data, pu0.width, @@ -38229,13 +40039,13 @@ fn decode_inter_block8( mv_to_q4(cpx, mv0.1, ss_x(fctx)), mv_to_q4(cpy, mv0.0, ss_x(fctx)), scale0, - chroma_side, - chroma_side, + chroma_w, + chroma_h, h_filter, v_filter, &mut inter0_u, fctx, ); - let mut inter1_u = vec![0i32; chroma_side * chroma_side]; + let mut inter1_u = vec![0i32; chroma_w * chroma_h]; mc::predict_compound_intermediate( &pu1.data, pu1.width, @@ -38244,29 +40054,30 @@ fn decode_inter_block8( mv_to_q4(cpx, mv1.1, ss_x(fctx)), mv_to_q4(cpy, mv1.0, ss_x(fctx)), scale1, - chroma_side, - chroma_side, + chroma_w, + chroma_h, h_filter, v_filter, &mut inter1_u, fctx, ); - let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side); + let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_w * chroma_h); if let Some(mask_y) = mask_y { mc::blend_masked_compound( &inter0_u, &inter1_u, mask_y, SIDE, - chroma_side, - chroma_side, - ss_x(fctx) == 1 && ss_y(fctx) == 1, + chroma_w, + chroma_h, + ss_x(fctx), +ss_y(fctx), &mut pred_u, fctx, ); } else { mc::combine_compound(&inter0_u, &inter1_u, fwd_offset, bck_offset, &mut pred_u, fctx); } - let mut inter0_v = vec![0i32; chroma_side * chroma_side]; + let mut inter0_v = vec![0i32; chroma_w * chroma_h]; mc::predict_compound_intermediate( &pv0.data, pv0.width, @@ -38275,13 +40086,13 @@ fn decode_inter_block8( mv_to_q4(cpx, mv0.1, ss_x(fctx)), mv_to_q4(cpy, mv0.0, ss_x(fctx)), scale0, - chroma_side, - chroma_side, + chroma_w, + chroma_h, h_filter, v_filter, &mut inter0_v, fctx, ); - let mut inter1_v = vec![0i32; chroma_side * chroma_side]; + let mut inter1_v = vec![0i32; chroma_w * chroma_h]; mc::predict_compound_intermediate( &pv1.data, pv1.width, @@ -38290,22 +40101,23 @@ fn decode_inter_block8( mv_to_q4(cpx, mv1.1, ss_x(fctx)), mv_to_q4(cpy, mv1.0, ss_x(fctx)), scale1, - chroma_side, - chroma_side, + chroma_w, + chroma_h, h_filter, v_filter, &mut inter1_v, fctx, ); - let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side); + let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_w * chroma_h); if let Some(mask_y) = mask_y { mc::blend_masked_compound( &inter0_v, &inter1_v, mask_y, SIDE, - chroma_side, - chroma_side, - ss_x(fctx) == 1 && ss_y(fctx) == 1, + chroma_w, + chroma_h, + ss_x(fctx), +ss_y(fctx), &mut pred_v, fctx, ); } else { @@ -38320,8 +40132,8 @@ fn decode_inter_block8( push_pred(fctx, build); ( Pred::Cur { plane: 0, stride: SIDE, off: 0 }, - Pred::Cur { plane: 1, stride: chroma_side, off: 0 }, - Pred::Cur { plane: 2, stride: chroma_side, off: 0 }, + Pred::Cur { plane: 1, stride: chroma_w, off: 0 }, + Pred::Cur { plane: 2, stride: chroma_w, off: 0 }, ) } else { let mut built: [Vec; 3] = Default::default(); @@ -38330,8 +40142,8 @@ fn decode_inter_block8( (pred_y, pred_u, pred_v) = (by, bu, bv); ( Pred::Inline(&pred_y, SIDE), - Pred::Inline(&pred_u, chroma_side), - Pred::Inline(&pred_v, chroma_side), + Pred::Inline(&pred_u, chroma_w), + Pred::Inline(&pred_v, chroma_w), ) }; split8 = read_block_tx_size( @@ -38348,25 +40160,43 @@ fn decode_inter_block8( .is_some(); if skip { push_mc(0, px, py, SIDE, sy, &ZERO_RESIDUAL[..SIDE * SIDE], fctx); - push_mc(1, + // lane-av1-422sub8rect: the plane block is the (chroma_w, + // chroma_h) rect at 4:2:2 -- the recorded write is + // stride `chroma_w`, full `chroma_h` rows. + push_mc_rect(1, cpx, cpy, - chroma_side, + chroma_w, + chroma_w, + chroma_h, su, - &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, + &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx, ); - push_mc(2, + push_mc_rect(2, cpx, cpy, - chroma_side, + chroma_w, + chroma_w, + chroma_h, sv, - &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, + &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx, ); luma_grid = Grid::Zero(SIDE * SIDE); - u_grid = Grid::Zero(chroma_side * chroma_side); - v_grid = Grid::Zero(chroma_side * chroma_side); + u_grid = Grid::Zero(chroma_w * chroma_h); + v_grid = Grid::Zero(chroma_w * chroma_h); } else { let around = neighbours.around_mi(leaf_mi, 8); + // lane-av1-422sub8rect: the 4:2:2 chroma unit is the + // TX_4X8 rect -- its `txb_skip_ctx` reads per chroma + // 4-px cell ([`Neighbours::around_mi_422_chroma`], the + // key-frame BLOCK_4X8 arm's own context walk), and the + // coefficients go through the inter rect reader with the + // inherited luma tx type. + let chroma_around = if chroma_422 { + neighbours.around_mi_422_chroma(leaf_mi, 8, 8) + } else { + around + }; let (grid8, luma_tx_type) = read_inter_luma8( dec, cdfs, @@ -38384,7 +40214,12 @@ fn decode_inter_block8( split8, fctx, )?; luma_grid = grid8; - if chroma_side == 8 && lossless(fctx) && !mono(fctx) { + // 4:4:4 lossless 8x8 inter leaf: the chroma plane block is + // the 8x8 leaf itself, read as one unit by the 444 walk + // (`chroma_w == 8` is `SIDE >> ss_x == 8`, i.e. ss_x 0). + // The 4:2:2 rect unit and the 4:2:0/4:4:4 square read are + // the `else` below, dispatched on `chroma_422`. + if chroma_w == 8 && lossless(fctx) && !mono(fctx) { let (ug, vg) = leaf8_inter_chroma_lossless( dec, cdfs, neighbours, u, v, su, sv, leaf_mi, (cpx, cpy), base_q_idx, fctx, @@ -38393,42 +40228,82 @@ fn decode_inter_block8( v_grid = vg; chroma_stamped_per_unit = true; } else { - u_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 1, - around[1], - mode_for_tx, - u, - cpx, - cpy, - chroma_side, - base_q_idx, - su, - Some(luma_tx_type), - None, fctx, - )? - .0; - v_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 2, - around[2], - mode_for_tx, - v, - cpx, - cpy, - chroma_side, - base_q_idx, - sv, - Some(luma_tx_type), - None, fctx, - )? - .0; + u_grid = if chroma_422 { + read_inter_plane_rect( + dec, + cdfs, + chroma_set, + (chroma_w, chroma_h), + chroma_w, + 1, + chroma_around[1], + mode_for_tx, + u, + cpx, + cpy, + su, + Some(luma_tx_type), + None, fctx, + )? + .0 + } else { + read_inter_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 1, + chroma_around[1], + mode_for_tx, + u, + cpx, + cpy, + chroma_w, + base_q_idx, + su, + Some(luma_tx_type), + None, fctx, + )? + .0 + }; + v_grid = if chroma_422 { + read_inter_plane_rect( + dec, + cdfs, + chroma_set, + (chroma_w, chroma_h), + chroma_w, + 2, + chroma_around[2], + mode_for_tx, + v, + cpx, + cpy, + sv, + Some(luma_tx_type), + None, fctx, + )? + .0 + } else { + read_inter_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 2, + chroma_around[2], + mode_for_tx, + v, + cpx, + cpy, + chroma_w, + base_q_idx, + sv, + Some(luma_tx_type), + None, fctx, + )? + .0 + }; } } // lane-inter8 r2: the COMPOUND leaf used to return here @@ -38942,7 +40817,7 @@ fn decode_inter_block8( SIDE, ss_x(fctx), ss_y(fctx), - chroma_side, + chroma_w, px, py, cpx, @@ -38966,15 +40841,15 @@ fn decode_inter_block8( return; }; let mut pred_y = refill(std::mem::take(&mut out[0]), SIDE * SIDE); - let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_side * chroma_side); - let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_side * chroma_side); + let mut pred_u = refill(std::mem::take(&mut out[1]), chroma_w * chroma_h); + let mut pred_v = refill(std::mem::take(&mut out[2]), chroma_w * chroma_h); // Merge of lane-gmaffine (this leaf's own switchable filters) with // lane-scaledref (spec 7.11.3.3's scaled walk): same kernels either // way, only the sample walk differs. - for (plane, x, y, dim, dst) in [ - (sref_y, px, py, SIDE, &mut pred_y), - (sref_u, cpx, cpy, chroma_side, &mut pred_u), - (sref_v, cpx, cpy, chroma_side, &mut pred_v), + for (plane, x, y, (dim_w, dim_h), dst) in [ + (sref_y, px, py, (SIDE, SIDE), &mut pred_y), + (sref_u, cpx, cpy, (chroma_w, chroma_h), &mut pred_u), + (sref_v, cpx, cpy, (chroma_w, chroma_h), &mut pred_v), ] { let luma = std::ptr::eq(plane, sref_y); if luma_scale == mc::REF_NO_SCALE { @@ -38985,8 +40860,8 @@ fn decode_inter_block8( plane.true_height, mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }), mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }), - dim, - dim, + dim_w, + dim_h, h_filter, v_filter, dst, fctx, @@ -39000,8 +40875,8 @@ fn decode_inter_block8( mv_to_q4(x, mv.1, if luma { 0 } else { ss_x(fctx) }), mv_to_q4(y, mv.0, if luma { 0 } else { ss_y(fctx) }), luma_scale, - dim, - dim, + dim_w, + dim_h, h_filter, v_filter, dst, fctx, @@ -39023,19 +40898,21 @@ fn decode_inter_block8( SIDE as i32, SIDE as i32, 0, 0, fctx, ); // `av1_init_warp_params`'s per-plane `block_width/height < 8` - // bail-out: an 8x8 leaf's chroma plane is 4x4 in 420, so it is - // predicted translationally even when the luma warps. + // bail-out: an 8x8 leaf's chroma plane block is narrower than 8 + // at any subsampled format (4:2:0 4x4, 4:2:2 4x8), so it is + // predicted translationally even when the luma warps; 4:4:4's + // 8x8 chroma warps with the luma. #[allow(clippy::absurd_extreme_comparisons)] - if chroma_side >= 8 { + if chroma_w >= 8 { crate::warp::warp_affine( params, &sref_u.data, sref_u.true_width as i32, sref_u.true_height as i32, - sref_u.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_side as i32, - chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, + sref_u.width as i32, &mut pred_u, cpx as i32, cpy as i32, chroma_w as i32, + chroma_h as i32, chroma_w as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, ); crate::warp::warp_affine( params, &sref_v.data, sref_v.true_width as i32, sref_v.true_height as i32, - sref_v.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_side as i32, - chroma_side as i32, chroma_side as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, + sref_v.width as i32, &mut pred_v, cpx as i32, cpy as i32, chroma_w as i32, + chroma_h as i32, chroma_w as i32, ss_x(fctx) as i32, ss_y(fctx) as i32, fctx, ); } } @@ -39047,12 +40924,14 @@ fn decode_inter_block8( // Non-wedge interintra blend, mutually exclusive with OBMC (the // motion_mode symbol is not read for an interintra block). if let Some(ii) = interintra_mode { - interintra_blend(y, px, py, SIDE, SIDE, SIDE, ii, wedge_mask, &mut pred_y, fctx); + interintra_blend(y, px, py, SIDE, SIDE, SIDE, 0, 0, ii, wedge_mask, &mut pred_y, fctx); interintra_blend( - u, cpx, cpy, chroma_side, chroma_side, chroma_side, ii, wedge_mask, &mut pred_u, fctx, + u, cpx, cpy, chroma_w, chroma_h, chroma_w, ss_x(fctx), ss_y(fctx), ii, wedge_mask, + &mut pred_u, fctx, ); interintra_blend( - v, cpx, cpy, chroma_side, chroma_side, chroma_side, ii, wedge_mask, &mut pred_v, fctx, + v, cpx, cpy, chroma_w, chroma_h, chroma_w, ss_x(fctx), ss_y(fctx), ii, wedge_mask, + &mut pred_v, fctx, ); } @@ -39064,8 +40943,8 @@ fn decode_inter_block8( push_pred(fctx, build); ( Pred::Cur { plane: 0, stride: SIDE, off: 0 }, - Pred::Cur { plane: 1, stride: chroma_side, off: 0 }, - Pred::Cur { plane: 2, stride: chroma_side, off: 0 }, + Pred::Cur { plane: 1, stride: chroma_w, off: 0 }, + Pred::Cur { plane: 2, stride: chroma_w, off: 0 }, ) } else { // The interintra predictor reads this block's own above/left @@ -39080,8 +40959,8 @@ fn decode_inter_block8( (pred_y, pred_u, pred_v) = (by, bu, bv); ( Pred::Inline(&pred_y, SIDE), - Pred::Inline(&pred_u, chroma_side), - Pred::Inline(&pred_v, chroma_side), + Pred::Inline(&pred_u, chroma_w), + Pred::Inline(&pred_v, chroma_w), ) }; split8 = read_block_tx_size( @@ -39098,25 +40977,43 @@ fn decode_inter_block8( .is_some(); if skip { push_mc(0, px, py, SIDE, sy, &ZERO_RESIDUAL[..SIDE * SIDE], fctx); - push_mc(1, + // lane-av1-422sub8rect: the plane block is the (chroma_w, + // chroma_h) rect at 4:2:2 -- the recorded write is stride + // `chroma_w`, full `chroma_h` rows. + push_mc_rect(1, cpx, cpy, - chroma_side, + chroma_w, + chroma_w, + chroma_h, su, - &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, + &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx, ); - push_mc(2, + push_mc_rect(2, cpx, cpy, - chroma_side, + chroma_w, + chroma_w, + chroma_h, sv, - &ZERO_RESIDUAL[..chroma_side * chroma_side], fctx, + &ZERO_RESIDUAL[..chroma_w * chroma_h], fctx, ); luma_grid = Grid::Zero(SIDE * SIDE); - u_grid = Grid::Zero(chroma_side * chroma_side); - v_grid = Grid::Zero(chroma_side * chroma_side); + u_grid = Grid::Zero(chroma_w * chroma_h); + v_grid = Grid::Zero(chroma_w * chroma_h); } else { let around = neighbours.around_mi(leaf_mi, 8); + // lane-av1-422sub8rect: the 4:2:2 chroma unit is the TX_4X8 + // rect -- its `txb_skip_ctx` reads per chroma 4-px cell + // ([`Neighbours::around_mi_422_chroma`], the key-frame + // BLOCK_4X8 arm's own context walk), and the coefficients go + // through the inter rect reader with the inherited luma tx + // type. + let chroma_around = if chroma_422 { + neighbours.around_mi_422_chroma(leaf_mi, 8, 8) + } else { + around + }; let (grid8, luma_tx_type) = read_inter_luma8( dec, cdfs, @@ -39134,7 +41031,11 @@ fn decode_inter_block8( split8, fctx, )?; luma_grid = grid8; - if chroma_side == 8 && lossless(fctx) && !mono(fctx) { + // 4:4:4 lossless 8x8 inter leaf (compound twin of the single-ref + // arm above): the chroma plane block is the 8x8 leaf itself, read + // as one unit by the 444 walk. The 4:2:2 rect unit and the + // 4:2:0/4:4:4 square read are the `else` below. + if chroma_w == 8 && lossless(fctx) && !mono(fctx) { let (ug, vg) = leaf8_inter_chroma_lossless( dec, cdfs, neighbours, u, v, su, sv, leaf_mi, (cpx, cpy), base_q_idx, fctx, @@ -39143,42 +41044,82 @@ fn decode_inter_block8( v_grid = vg; chroma_stamped_per_unit = true; } else { - u_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 1, - around[1], - mode_for_tx, - u, - cpx, - cpy, - chroma_side, - base_q_idx, - su, - Some(luma_tx_type), - None, fctx, - )? - .0; - v_grid = read_inter_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 2, - around[2], - mode_for_tx, - v, - cpx, - cpy, - chroma_side, - base_q_idx, - sv, - Some(luma_tx_type), - None, fctx, - )? - .0; + u_grid = if chroma_422 { + read_inter_plane_rect( + dec, + cdfs, + chroma_set, + (chroma_w, chroma_h), + chroma_w, + 1, + chroma_around[1], + mode_for_tx, + u, + cpx, + cpy, + su, + Some(luma_tx_type), + None, fctx, + )? + .0 + } else { + read_inter_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 1, + chroma_around[1], + mode_for_tx, + u, + cpx, + cpy, + chroma_w, + base_q_idx, + su, + Some(luma_tx_type), + None, fctx, + )? + .0 + }; + v_grid = if chroma_422 { + read_inter_plane_rect( + dec, + cdfs, + chroma_set, + (chroma_w, chroma_h), + chroma_w, + 2, + chroma_around[2], + mode_for_tx, + v, + cpx, + cpy, + sv, + Some(luma_tx_type), + None, fctx, + )? + .0 + } else { + read_inter_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 2, + chroma_around[2], + mode_for_tx, + v, + cpx, + cpy, + chroma_w, + base_q_idx, + sv, + Some(luma_tx_type), + None, fctx, + )? + .0 + }; } } } else { @@ -39401,17 +41342,17 @@ fn decode_inter_block8( PaletteY { size: n, colors, map } }); let palette_uv = palette_uv_pending.map(|(n, u_colors, v_colors)| { - // `av1_get_plane_block_size(BLOCK_8X8, 1, 1)` at the sequence's - // own subsampling: BLOCK_4X4 at 4:2:0, BLOCK_8X8 at 4:4:4 - // (`chroma_side`, lane-av1-444). + // `av1_get_plane_block_size(BLOCK_8X8, ss)` at the sequence's own + // subsampling: BLOCK_4X4 at 4:2:0, BLOCK_8X8 at 4:4:4, and at + // 4:2:2 the BLOCK_4X8 plane block (lane-av1-422sub8rect). let on = palette_onscreen_uv( (SIDE, SIDE), palette_onscreen(rmi, cmi, SIDE, SIDE, fctx), - (chroma_side, chroma_side), + (chroma_w, chroma_h), (ss_x(fctx), ss_y(fctx)), ); let map = - decode_color_index_map_wh(dec, cdfs, n, chroma_side, chroma_side, on, true); + decode_color_index_map_wh(dec, cdfs, n, chroma_w, chroma_h, on, true); hit!(PALETTE_UV_HITS); hit!(INTRA_IN_INTER_PALETTE_UV_HITS); hit_do! { @@ -39582,14 +41523,18 @@ fn decode_inter_block8( if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - push_intra(1, + // lane-av1-422sub8rect: the plane block is the (chroma_w, + // chroma_h) rect at 4:2:2 -- the recorded prediction/write uses + // the rect push. + push_intra_rect(1, cpx, cpy, - chroma_side, + chroma_w, + chroma_h, uv_predict_mode, angle_delta_uv, reach, - &ZERO_RESIDUAL[..chroma_side * chroma_side], + &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((au, _), ac)| (au, ac)), None, smooth_neighbor_uv, fctx, @@ -39597,21 +41542,22 @@ fn decode_inter_block8( if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - push_intra(2, + push_intra_rect(2, cpx, cpy, - chroma_side, + chroma_w, + chroma_h, uv_predict_mode, angle_delta_uv, reach, - &ZERO_RESIDUAL[..chroma_side * chroma_side], + &ZERO_RESIDUAL[..chroma_w * chroma_h], alpha.zip(ac).map(|((_, av), ac)| (av, ac)), None, smooth_neighbor_uv, fctx, ); luma_grid = Grid::Zero(SIDE * SIDE); - u_grid = Grid::Zero(chroma_side * chroma_side); - v_grid = Grid::Zero(chroma_side * chroma_side); + u_grid = Grid::Zero(chroma_w * chroma_h); + v_grid = Grid::Zero(chroma_w * chroma_h); } else { let around = neighbours.around_mi(leaf_mi, 8); luma_grid = if split8 { @@ -39655,7 +41601,20 @@ fn decode_inter_block8( )? }; let ac = alpha.map(|_| cfl_src(px, py, SIDE)); - if chroma_side == 8 && lossless(fctx) && !mono(fctx) { + // lane-av1-422sub8rect: at 4:2:2 the plane block is the BLOCK_4X8 + // rect and the key-frame arm's own reader applies -- one + // TX_4X8 `ChromaRect8x4` unit per plane through + // [`read_rect_chroma_unit`] with the per-chroma-cell context + // walk ([`Neighbours::around_mi_422_chroma`], the + // lane-av1-422f model this leaf's key-frame twin proves + // byte-exact). 4:2:0/4:4:4 keep the square [`read_plane`] read. + let (chroma_around_u, chroma_around_v) = if chroma_422 { + let ca = neighbours.around_mi_422_chroma(leaf_mi, 8, 8); + (ca[1], ca[2]) + } else { + (around[1], around[2]) + }; + if chroma_w == 8 && lossless(fctx) && !mono(fctx) { // lane-av1-llintra8: lossless codes TX_4X4 on EVERY plane // (`av1_get_tx_size`, blockd.h:1383), so this intra leaf's 8x8 // chroma plane block is a 2x2 raster of TX_4X4 units per @@ -39671,8 +41630,8 @@ fn decode_inter_block8( let (mut uo, mut vo) = (Vec::new(), Vec::new()); read_intra_chroma_lossless( dec, cdfs, neighbours, u, v, leaf_mi, (px, py), (cpx, cpy), - SIDE, (chroma_side, chroma_side), (0, 0), - (chroma_side, chroma_side), chroma_side, reach, + SIDE, (chroma_w, chroma_w), (0, 0), + (chroma_w, chroma_w), chroma_w, reach, (y.width, y.height), mode, uv_predict_mode, angle_delta_uv, palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])), smooth_neighbor_uv, base_q_idx, &mut uo, &mut vo, fctx, @@ -39685,53 +41644,73 @@ fn decode_inter_block8( if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } - u_grid = read_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 1, - around[1], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - u, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((au, _), ac)| (au, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; + u_grid = if chroma_422 { + read_rect_chroma_unit( + dec, cdfs, chroma_set, chroma_scan, chroma_w, chroma_h, 1, + chroma_around_u, uv_predict_mode, angle_delta_uv, reach, u, + cpx, cpy, base_q_idx, None, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + smooth_neighbor_uv, fctx, + )? + } else { + read_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 1, + chroma_around_u, + mode, + uv_predict_mode, + angle_delta_uv, + reach, + u, + cpx, + cpy, + chroma_w, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((au, _), ac)| (au, ac)), + None, + None, + smooth_neighbor_uv, fctx, + )? + }; if let Some((_, vb)) = &palette_uv_bufs { set_palette_pred(vb.clone(), fctx); } - v_grid = read_plane( - dec, - cdfs, - chroma_set, - chroma_scan, - 2, - around[2], - mode, - uv_predict_mode, - angle_delta_uv, - reach, - v, - cpx, - cpy, - chroma_side, - chroma_tx, - base_q_idx, - alpha.zip(ac).map(|((_, av), ac)| (av, ac)), - None, - None, - smooth_neighbor_uv, fctx, - )?; + v_grid = if chroma_422 { + read_rect_chroma_unit( + dec, cdfs, chroma_set, chroma_scan, chroma_w, chroma_h, 2, + chroma_around_v, uv_predict_mode, angle_delta_uv, reach, v, + cpx, cpy, base_q_idx, None, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + smooth_neighbor_uv, fctx, + )? + } else { + read_plane( + dec, + cdfs, + chroma_set, + chroma_scan, + 2, + chroma_around_v, + mode, + uv_predict_mode, + angle_delta_uv, + reach, + v, + cpx, + cpy, + chroma_w, + chroma_tx, + base_q_idx, + alpha.zip(ac).map(|((_, av), ac)| (av, ac)), + None, + None, + smooth_neighbor_uv, fctx, + )? + }; } } } @@ -41691,22 +43670,50 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( // so there is no pair: each strip codes // and predicts its own chroma from its // own motion (`prev` = None). - let strip_has_chroma = - i % 2 == 1 || (ss_x(fctx) == 0 && ss_y(fctx) == 0); - let pair_mi = if !strip_has_chroma || ss_x(fctx) == 0 { - at_mi - } else if horz { - (at_mi.0 - 1, at_mi.1) + // lane-av1-422l: a strip pairs along its + // OWN subsampled axis -- horz strips pair + // on rows (no pair once ss_y == 0: chroma + // has no row parity, every 16x4 strip is + // its own reference, exactly the intra + // strip arm's `else if ss_y(fctx) == 0`); + // vert strips pair on columns (ss_x == 0 + // => every strip self-pairs, 4:2:2 keeps + // the 4:2:0 column pairing -- a VERT_4 + // 4x16 strip's `ss_size_lookup` chroma + // at ss (1,0) is BLOCK_INVALID, so only + // the pair shape can ever be coded). + let strip_has_chroma = if horz { + i % 2 == 1 || ss_y(fctx) == 0 } else { - (at_mi.0, at_mi.1 - 1) + i % 2 == 1 || ss_x(fctx) == 0 }; + let pair_mi = + if !strip_has_chroma + || (if horz { + ss_y(fctx) == 0 + } else { + ss_x(fctx) == 0 + }) + { + at_mi + } else if horz { + (at_mi.0 - 1, at_mi.1) + } else { + (at_mi.0, at_mi.1 - 1) + }; fctx.inter_strip_chroma.with(|c| { c.set(Some(InterStripChroma { has_chroma: strip_has_chroma, horz, pair_mi, - prev: if strip_has_chroma && ss_x(fctx) == 1 { - fctx.inter_last_mc.with(std::cell::Cell::get) + prev: if strip_has_chroma + && (if horz { + ss_y(fctx) == 1 + } else { + ss_x(fctx) == 1 + }) { + fctx.inter_last_mc + .with(std::cell::Cell::get) } else { None }, diff --git a/crates/ec-av1/src/mc.rs b/crates/ec-av1/src/mc.rs index bbffbfc4..a9c96c6c 100644 --- a/crates/ec-av1/src/mc.rs +++ b/crates/ec-av1/src/mc.rs @@ -2142,8 +2142,11 @@ pub(crate) fn diffwtd_mask( /// (64-m)*pred1) >> 6` (a plain, unrounded shift, matching the C `>>` on /// `int32_t`) then one final [`round2`] by [`INTER_POST_ROUND`]. `mask` is /// always the LUMA-resolution mask (`mask_stride` == luma block width); -/// `subsampled` selects the 2x2-average chroma read (spec 7.11.3.14 / -/// libaom's `subw == 1 && subh == 1` branch) vs. the direct luma read. +/// `(subw, subh)` are the PLANE's own subsampling shifts and pick the mask +/// read exactly as aom_dsp/blend-a64-mask.c's four `subw`/`subh` branches do: +/// `(0, 0)` the direct luma sample, `(1, 1)` the 2x2 box average, +/// `(1, 0)`/`(0, 1)` the `AOM_BLEND_AVG` pair average on the subsampled axis +/// alone (4:2:2). #[allow(clippy::too_many_arguments)] pub(crate) fn blend_masked_compound( pred0: &[i32], @@ -2152,7 +2155,8 @@ pub(crate) fn blend_masked_compound( mask_stride: usize, w: usize, h: usize, - subsampled: bool, + subw: usize, + subh: usize, dst: &mut [u16], fctx: &crate::decode::FrameCtx, ) { @@ -2162,17 +2166,30 @@ pub(crate) fn blend_masked_compound( let post_round = INTER_POST_ROUND - round_delta(u32::from(crate::decode::bit_depth(fctx))); for i in 0..h { for j in 0..w { - let m = if subsampled { - let idx = (2 * i) * mask_stride + 2 * j; - round2( - i32::from(mask[idx]) - + i32::from(mask[idx + 1]) - + i32::from(mask[idx + mask_stride]) - + i32::from(mask[idx + mask_stride + 1]), - 2, - ) - } else { - i32::from(mask[i * mask_stride + j]) + let m: i32 = match (subw, subh) { + (0, 0) => i32::from(mask[i * mask_stride + j]), + (1, 1) => { + let idx = (2 * i) * mask_stride + 2 * j; + round2( + i32::from(mask[idx]) + + i32::from(mask[idx + 1]) + + i32::from(mask[idx + mask_stride]) + + i32::from(mask[idx + mask_stride + 1]), + 2, + ) + } + // aom_blend_a64_mask_c's `subw == 1 && subh == 0` branch: + // `AOM_BLEND_AVG(mask[2 * j], mask[2 * j + 1])` per row. + (1, 0) => { + let idx = i * mask_stride + 2 * j; + (i32::from(mask[idx]) + i32::from(mask[idx + 1]) + 1) >> 1 + } + // the `subw == 0 && subh == 1` branch: averaged down the + // columns instead. + (_sw, _sh) => { + let idx = (2 * i) * mask_stride + j; + (i32::from(mask[idx]) + i32::from(mask[idx + mask_stride]) + 1) >> 1 + } }; let res = (m * pred0[i * w + j] + (64 - m) * pred1[i * w + j]) >> 6; // `post_round` above: `INTER_POST_ROUND - round_delta` -- see diff --git a/lanes/av1422.report.md b/lanes/av1422.report.md new file mode 100644 index 00000000..a87b86ba --- /dev/null +++ b/lanes/av1422.report.md @@ -0,0 +1,64 @@ +# lane-av1-422 — 4:2:2 chroma behind the header refusal + +## Outcome + +STOP with the refusal in place (`stream.rs` `subsampling_x != subsampling_y`, byte-identical to main). +Not pixel-exact yet: the bypassed-refusal probe still desyncs/pantes on the census fixture +(`aomenc --profile=2`, 256x144, 16 frames, testsrc2 422 y4m). Next wrong site named below. + +Landed on this branch: the finished, provably 420/444-invariant slice of the class fix. +`cargo check -p ec-av1 --all-targets`: **0 warnings**. + +## Fixture provenance + +- `ffmpeg -f lavfi -i testsrc2=256x144:rate=30 -frames:v 16 -pix_fmt yuv422p /tmp/t422.y4m` +- `aomenc --codec=av1 --profile=2 --obu -w 256 -h 144 --passes=1 --end-usage=q --cq-level=32 --cpu-used=3 --limit=16` +- Refusal string confirmed firing on main before any edit (decode_probe on the OBU). +- Oracle decode: `$HOME/.cache/aom-oracle/build/aomdec` (I422 raw). ffmpeg 8.1.2 available; aomdec used as primary pixel oracle. + +## Class (confirmed against the aom oracle source, `~/.cache/aom-oracle/src`) + +At ss (1,0) chroma width halves, height does not. Sites assume either a single shared +`ss` for both axes or an `ss==(0,0) ? 444 : 420` two-arm split, so 422 falls into the 420 arm. +Ground truth tables: `av1_ss_size_lookup` (common_data.c:17), `is_chroma_reference` +(av1_common_int.h:1454), `av1_get_max_uv_txsize` (blockd.h:1372). + +## Fixes landed (all keyed to reachability only at ss 1,0; 420/444 arms byte-identical) + +1. `decode_rect_split` chroma: square chroma rows (8,8)/(16,16)/(32,32) routed through the + square reader via the `chroma_tiled` arm (libaom: chroma of a 16x8/32x16/64x32 luma strip + is an 8x8/16x16/32x32 square). Includes 4:2:2 CFL strip support via the same path. +2. `decode_rect4_16_strip`: (8,8) arm + 422 strips are their own chroma reference + (`ss_size_lookup[16X4][1][0]` = BLOCK_8X4, per-strip, no 4:2:0 pair merge); also fixed a + `lmi.1 - 1` underflow the 422 has_chroma change exposed. +3. `decode_leaf_rect` chroma match: (16,16) and (8,32) rows. +4. `decode_block_rect4` chroma match: (16,8) and (8,4) rows; the portrait-leaf unreachable now + names the shape. +5. `cfl_ac_ss`: `cfl_luma_subsampling_422_lbd_c` branch (horizontal luma pairs, full height, + `(a+b) << 2`), before the 4:2:0 square/rect helpers. +6. `mv_to_q4` Y axis: 8 call sites passed `ss_x(fctx)` for the row component — now `ss_y` + (sub-8x8/inter chroma MC bilinear predict sites). +7. `has_chroma` for 1:4 strip pairs (decode_rect4_16 + inter twin): `i % 2 == 1 || ss_y == 0` + (is_chroma_reference's row-parity clause drops out when ss_y=0). +8. `CHROMA422_SQUARE_HITS` counter (decode.rs): incremented only when a square chroma + coefficient unit is read on a frame with ss (1,0); a restored `/2 chroma height` diverts + 4:2:2 squares onto the rect rows and the counter reads 0. Accessor `chroma422_square_hits()`. + No gate asserts it yet — the refusal still gates all 422 decode (deferred below). + +## Next wrong site (first blocker on the fixture, in parent's order) + +`decode_block` (~line 16621 on this tree): the `ss==(0,0) ? 444 : 420` tx-size arm. Its whole +chroma section walks `cn x cn` square `chroma_tx` units; at 4:2:2 a square luma block's chroma +is (side/2, side) — a RECT plane block (e.g. 8x16 for a 16x16 block) needing rect chroma sets +and a non-square unit walk. Same open class after it: `decode_inter_block`'s square-chroma +arms (~31922/33422), `film_grain.rs` `apply_grain` (hardcoded 420 subblock halving), and the +1:4 portrait-leaf question — `ss_size_lookup[BLOCK_8X32][1][0]` is BLOCK_INVALID yet the +aomenc fixture carries 8x32 leaves that aomdec accepts, so the upstream desync (decode_block / +inter chroma) is still producing phantom partitions; that ordering must be re-checked once the +square-chroma sites land. + +## Deferred + +- Refusal lift + witness gate (`chroma422_square_hits()` + pixel-exact vs aomdec/ffmpeg): + deferred(until decode_block/inter square-chroma class lands and the probe is pixel-exact). + Refusal stays; a lifted refusal with wrong pixels is a fail. diff --git a/lanes/av1422b.report.md b/lanes/av1422b.report.md new file mode 100644 index 00000000..f89980a2 --- /dev/null +++ b/lanes/av1422b.report.md @@ -0,0 +1,90 @@ +# lane-av1-422b — decode_block square-chroma walk (4:2:2, refusal still up) + +## Outcome + +STOP with the refusal in place (`stream.rs` `subsampling_x != subsampling_y`, +byte-identical to main — restored before the commit; no bypass committed). +Not pixel-exact yet: the bypassed-refusal probe desyncs INSIDE the first +16x16 `PARTITION_HORZ_A` of frame 0, before `decode_block`'s own chroma walk +is ever reached. Next wrong site named below. + +## Landed (all keyed to reachability only at ss (1,0); 420/444 arms unchanged) + +1. `decode_block` tx-size arm: new 4:2:2 branch — the uv plane block is + `(side/2, side)` (`ss_size_lookup[..][1][0]`), so + `av1_get_max_uv_txsize` is the SQUARE transform of the smaller dimension + capped at TX_32X32: 4→TX_4X4 (2x4 rounds to BLOCK_4X4), 8→TX_4X4, + 16→TX_8X8, 32→TX_16X16, 64→TX_32X32, 128→TX_32X32 (BLOCK_64X128 adjusts + TX_64X64 down). Units stay square; the unit GRID is `(side/2)/tx` wide by + `side/tx` tall — never square above a 4x4 luma block. +2. All three chroma walks in `decode_block` (skip arm, single-luma-TU arm, + multi-TU mu-chunk arm) generalized from square `cn x cn` to + `cn_cols x cn_rows`; each unit's luma anchor split per axis + (`chroma_tx << ss_x` wide, `chroma_tx << ss_y` tall): `around_mi_rect`, + `tu_reach_rect` (new helper; keeps the square mismatch counter semantics), + `record_mi_chroma(cu_mi, span_x, span_y, ...)`, units tuples widened to + carry both spans. +3. intrabc chroma prediction buffers sized `chroma_side x chroma_height`. +4. `TxbSet::Chroma8`/`Chroma16` `txb_skip` tables widened to six rows: + rows 3..6 are `av1_default_txb_skip_cdfs[q][TX_8X8/16X16][10..13]` + (`get_txb_ctx`'s `+10` rows; neutral 16384 in libaom — its encoder never + reaches them at 4:2:0/4:4:4, a 4:2:2 plane block larger than an 8x8/16x16 + transform does). Mirrors the existing `TXB_SKIP_CHROMA_4_BIG`/ + `CHROMA_32_BIG` assembly. Unused rows are never adapted, so 420/444 CDF + adaptation is unchanged. +5. `chroma422_square_hits()` made `pub` and printed by `examples/decode_probe.rs` + (like every other capability counter) for the witness gate later. +6. `EC_PART`/`EC_PART_VAL` traces behind `EC_TRACE` at the 64/32/16/8-level + partition symbol reads, byte-format-matched to the oracle aomdec's own + trace (same instrumented-oracle pairing the file already uses elsewhere). + +## Measurement (local bypass, NOT committed) + +Fixture: `ffmpeg testsrc2 256x144 yuv422p` → `aomenc --profile=2 --obu +-w 256 -h 144 --passes=1 --end-usage=q --cq-level=32 --cpu-used=3 --limit=16` +(sha256 d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129); +oracle `aomdec --rawvideo` (I422). + +- With the refusal bypassed, `decode_block`'s new arm runs and the pre-existing + `txb_skip[3]` panic is gone (the widening in 4 fixes it). +- Desync localization via `EC_TRACE=1` partition pairing: every partition + symbol pairs rng-for-rng with the oracle through the 64→32 split and the + FIRST 16x16 (`(0,0)` value 4 = HORZ_A, rng 57096→45060→49312 identical). + The oracle's NEXT 16-level read is `(0,4)` at tell 1079; ours is the second + quadrant at tell 700 — the divergence is inside HORZ_A's own pieces: + the two 8x8 leaves (`decode_leaf8`, whose chroma at 4:2:2 is 4x8 = two TX_4X4 + units per plane) and/or the 16x8 bottom strip (`decode_rect_split`'s + `chroma_tiled` (8,8) arm — its `EC_RECTCHROMA_GAP luma=16x8 tx=8x8 + chroma=8x8` diagnostic fires right before the panic point). + +## The 8x32/32x64 leaf note, resolved against the oracle source + +`av1_ss_size_lookup[..][1][0]` (common_data.c:17): 16X4→8X4 VALID, 32X8→16X8 +VALID, 64X16→32X16 VALID, but 4X16, 8X32, 16X64 (the TALL 1:4 shapes) are +BLOCK_INVALID at 4:2:2. libaom's ENCODER disables exactly those: +`partition_search.c` (`part4_search_allowed`) requires +`get_plane_block_size(subsize, ss_x, ss_y) != BLOCK_INVALID` before a HORZ_4/ +VERT_4 may be coded. So aomenc never writes tall 1:4 leaves at 4:2:2 — the +4x16 leaf our decoder tripped on (`EC_RECTCHROMA_GAP` then the closed-shape +unreachable in `decode_rect4_16_strip`) is a phantom partition produced by the +upstream desync above, not a missing portrait block size. Nothing invented; +the shape guard stays closed. + +## Next wrong site + +`decode_rect_split`'s `chroma_tiled` square-chroma arm for 16x8 strips and +`decode_leaf8`'s 4x8 chroma (first HORZ_A pieces) — re-check those against +the oracle's `EC_COEFF` pairing before re-touching `decode_block`'s walk. + +## Gates + +- `a_real_aomenc_128x128_none_inter_blocks_coded_chroma_per_mu_chunk_decodes_ + pixel_exact` (420): PASS. +- `a_non_420_subsampled_sequence_header_is_refused_by_name` (422 refusal + + 420 control): PASS. +- 444 check: `aomenc --profile=1` testsrc2 256x144 through `decode_probe` + byte-compares IDENTICALLY at clean 5674d2c5 and with this diff (first diff + at char 50689 on both — pre-existing branch behavior against this quick + oracle recipe, not touched by this slice; the merged-main 444 gate + c3c67f17 is not on this branch yet). +- `cargo check -p ec-av1 --all-targets`: 0 warnings. diff --git a/lanes/av1422d.report.md b/lanes/av1422d.report.md new file mode 100644 index 00000000..162bca15 --- /dev/null +++ b/lanes/av1422d.report.md @@ -0,0 +1,92 @@ +# lane-av1-422d — 8x8 leaf chroma unit ported at ss (1,0); refusal stays + +## Outcome + +STOP with the 4:2:2 header refusal in place. `decode_leaf8`'s chroma walk now +ports the 4:2:2 leaf unit (ONE 4x8 rect transform unit per plane, +`TxbSet::ChromaRect8x4` + `SCAN_4X8`, one txb_skip + one scan), and every leaf8 +chroma read on the measured fixture is rng-for-rng EXACT against the oracle. +The stream still desyncs LATER, at `decode_leaf_rect`'s chroma arm (next +section), so the refusal is retained byte-identical and the probe bypass was +reverted before commit. + +## Change (all inside decode_leaf8's own chroma scope) + +- `decode_leaf8` (decode.rs): `chroma_422 = ss_x == 1 && ss_y == 0`; all three + arms (skip, single-8x8-unit, TX4) branch to `leaf8_chroma422_unit` for the + rect unit. The 4:2:0 `(4, TxbSet::Chroma4, scans.1)` selection and the 4:4:4 + arm are untouched. The chroma unit does NOT follow the luma var-tx split + (`uv_txsize` is `av1_get_max_uv_txsize` of the block, still one 4x8 unit + when luma resolves TX_4X4). The intrabc DV copy covers the whole plane block + (4x8) at ss (1,0). +- `leaf8_chroma422_unit` (new, next to `decode_leaf8`): mirrors + `sub8_leaf_chroma444`'s rect arm at the leaf's halved position — entropy + context from the leaf's own 8x8 luma-span above/left state (no `+3`, the + unit covers the plane block exactly), CFL source the leaf's whole 8x8 luma + block, mode-derived default `tx_type` unless `INTRABC_CHROMA_TX` is armed, + prediction override (intrabc DV over palette) set inside, skip predicts with + `ZERO_RESIDUAL`. +- UV palette map extent (decode.rs:15808, leaf8's mode-info reader): the map + is decoded over `(side >> ss_x, side >> ss_y)` = 4x8 via + `decode_color_index_map_wh`, not the square call's `(side >> ss_x)`-squared + 4x4 (class: plane-block extent squared a rect). At 4:2:0/4:4:4 the arguments + evaluate identically; only ss (1,0) changes. Found live: the 16-entry map + fed a 16-sample prediction override into the first 32-sample rect unit and + panicked `reconstruct_rect` (`index out of bounds: the len is 16 but the + index is 16`). + +## Measurement + +Fixture `/tmp/t422.obu`, sha256 +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` (reused +from av1422b/c by hash). Oracle `$HOME/.cache/aom-oracle/build/aomdec` +`EC_TRACE=1 EC_TRACE_MODE_STEP=1 EC_TRACE_COEFF=1`; ours `decode_probe` (debug, +private target dir) same env plus `EC_AV1_ALLOW_422_PROBE=1` (LOCAL bypass, +reverted). + +Coefficient-unit pairing (all_zero entry rng -> post rng), first HORZ_A 16x16 +of frame 0: + +- leaf (0,0): 4x luma TX_4X4 ✓, U `tx_size=5` entry 46416 -> 35360 ✓, V + entry 34824 -> 41920 ✓ (both my rect reads). +- leaf (0,2): luma TX_8X8 ✓ (post 45770 = oracle), U entry 37668 -> 33728 ✓, + V entry 60936 -> 58556 ✓. +- 16x8 strip: luma `tx_size=8` entry 59680 -> 58977 ✓. + +All four leaf8 chroma rect reads match the oracle rng-for-rng through their +full coefficient bodies (each next unit's entry rng proves the previous +body's bit consumption). + +## First remaining divergence (named next site) + +`decode_leaf_rect`'s chroma arm, decode.rs:13060-13067. For a 16x8/8x16 rect +leaf at ss (1,0) the chroma plane block is 8x8 — SQUARE +(`TxbSet::Chroma8` + `default_scan(8)` through `read_plane`, the +`chroma_tiled` (8,8) shape) — but the code picks `TxbSet::ChromaRect8x4` + +`SCAN_8X4`/`SCAN_4X8` keyed on `ss_x == 0`. Measured: the HORZ_A's 16x8 strip +(mi_row=2, mi_col=0) — oracle U/V units are `tx_size=1` (TX_8X8 class, 64- +position eob alphabet, ctx=8); ours enters the U unit's txb_skip at the same +rng 38672 and coincidentally matches that one symbol (the offset-7 row shares +`txb_skip_chroma_8`), then reads eob off the 32-position chroma-rect alphabet +(eob=27 vs oracle eob=32) and desyncs. Everything after shifts. + +## Second site behind it + +`decode_rect_split`'s chroma shape table (decode.rs:10114-10133) has no 4:2:2 +rows: a 16x64 luma strip's `(8, 64)` plane block fires +`EC_RECTCHROMA_GAP luma=16x64 tx=16x32 chroma=8x64` (decode stops at mi_row=16 +once the leaf_rect site is passed). Same class likely holds for other +unhalved-height plane blocks in that table. + +## State + +- Refusal `a chroma format of 4:2:2 (subsampling_x != subsampling_y)...` + byte-identical (bypass reverted; `git diff` shows only decode.rs). +- `decode_leaf_split4`, `sub8_leaf_chroma444`, `reconstruct_mc_rect`, the + resize header reader, decode.rs 34390-34440: untouched. +- 420 gate green: + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_pixel_exact` + + its 10-bit twin — 6/6 pixel-exact matches each, 0 refusals (the gate + exercises the skip and TX4 arms this lane restructured). +- `cargo check -p ec-av1`: 0 warnings. +- No push. diff --git a/lanes/av1422e.report.md b/lanes/av1422e.report.md new file mode 100644 index 00000000..b1565ac7 --- /dev/null +++ b/lanes/av1422e.report.md @@ -0,0 +1,84 @@ +# lane-av1-422e — leaf_rect chroma is an 8x8 square unit at ss (1,0); refusal stays + +## Outcome + +STOP with the 4:2:2 header refusal in place, byte-identical. `decode_leaf_rect`'s +chroma arm now keys on ss: at ss (1,0) a 16x8/8x16 luma leaf's chroma plane +block is an 8x8 SQUARE (`TxbSet::Chroma8` + `default_scan(8)`), and every +leaf_rect chroma read on the measured fixture is rng-for-rng EXACT against the +oracle — the av1422d desync at the HORZ_A 16x8 strip (mi(2,0)) is gone, along +with everything up to the first 16x16 square block. The stream now desyncs at +that square block's chroma (next section), so the refusal is retained and the +probe bypass was reverted before commit (`git diff` touches only decode.rs). + +## Change (decode.rs only) + +- `decode_leaf_rect` chroma arm (was decode.rs:13060-13067): the + `ss_x == 0`-keyed selection replaced by a three-way arm — `chroma_422` + (`ss_x == 1 && ss_y == 0`) picks `TxbSet::Chroma8` + `default_scan(8)` for + the 8x8 square plane block (luma scan unchanged: SCAN_16X8/SCAN_8X16); + 4:2:0 keeps `TxbSet::ChromaRect8x4` + SCAN_8X4/SCAN_4X8; 4:4:4 keeps + `TxbSet::ChromaRect16x8` + the full SCAN_16X8/SCAN_8X16. Doc comment above + `decode_leaf_rect` updated to name all three subsamplings. +- Untouched: `decode_leaf8`, `leaf8_chroma422_unit`, `sub8_leaf_chroma444`, + `decode_leaf_split4`, `reconstruct_mc_rect`, the resize header reader, + `decode.rs` 34390-34440. + +## Measurement + +Fixture `/tmp/t422.obu`, sha256 +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` (reused by +hash). Oracle `$HOME/.cache/aom-oracle/build/aomdec` +`EC_TRACE=1 EC_TRACE_MODE_STEP=1 EC_TRACE_COEFF=1`; ours `decode_probe` (debug, +private target dir) same env plus a LOCAL `EC_AV1_ALLOW_422_PROBE` bypass +env-gated at the stream.rs refusal — reverted before commit, and the refusal +was re-proven to fire without the env. + +The first leaf_rect 16x8 strips that desynced in av1422d now pair rng-for-rng +through their full luma + U + V coefficient bodies (all EC_COEFF_STEP rngs +match: all_zero, tx_type, eob, base_eob, br, sign, post_golomb), and the ISTEP +stream stays identical well past them. With that site passed, decode now +reaches the first 16x16 square intra block, mi(4,4). + +## First remaining divergence (named next site, with oracle evidence) + +The SQUARE-block path's 4:2:2 chroma model, decode.rs:16704-16721 +(lane-av1-422b's arm inside the `(luma_set, chroma_set, luma_tx, chroma_tx, +scans)` selection): it models `av1_get_max_uv_txsize` of the (side/2, side) +plane block as "the SQUARE transform of the smaller dimension" and walks a grid +of square units (side 16 -> two 8x8 units). The oracle disagrees — aom reads +`max_txsize_rect_lookup` of the PLANE block, a RECT that fills it exactly: + +- ours, mi(4,4) side=16: all_zero `side=8 ctx=5` at rng 44044 -> eob read on + the 8x8-class alphabet (eob=48) — the first of two square units. +- oracle, same block: `all_zero plane=1 bc=0 br=0 ctx=9 txs=2` at rng 36040 — + ONE unit, TX_8X16 class (16x16 entropy class), whole 8x16 plane block. + +Correct model per aom (`av1_get_max_uv_txsize` = `max_txsize_rect_lookup` +[plane_bsize], then `av1_get_adjusted_tx_size`): side 8 -> TX_4X8 +(ChromaRect8x4 + SCAN_4X8, one unit — the shape av1422d proved at leaf8); +side 16 -> TX_8X16 (ChromaRect16x8 + SCAN_8X16, one unit); side 32 -> TX_16X32 +(ChromaRect32x16 + SCAN_16X32, one unit); side 64 -> TX_32X64 adjusts to +TX_32X32, i.e. two stacked 32x32 units, which the current square walk already +produces. The fix spans the square path's three chroma walks (skip 17019-17067, +single-unit 17120-17260, chunked 17273-17553) since they thread `chroma_tx` as +both unit dims; it needs per-axis unit dims keyed to ss (1,0). That is its own +lane round — not started, no rows invented, no BLOCK_INVALID portrait shape. + +The av1422d second site (decode_rect_split's chroma table missing (8,64)) did +NOT fire this round: the square-path site above blocks first. The +decode_rect_split 16x8-strip reads (chroma 8x8 via the chroma_tiled arm) pass +the oracle rng-for-rng; the repeated `EC_RECTCHROMA_GAP luma=16x8 tx=8x8 +chroma=8x8` prints are the pre-existing diagnostic (chroma.is_none() before the +chroma_tiled fallback), not refusals. + +## State + +- Refusal `a chroma format of 4:2:2 (subsampling_x != subsampling_y)...` + byte-identical (bypass reverted; probe refuses without the env). +- `cargo check -p ec-av1` (private target dir): 0 warnings. +- 420 gates green: `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_ + tx_split_decodes_pixel_exact` + its 10-bit twin — 2/2 pass (exercises the + skip and TX4 arms restructured in av1422d; the new 422 arm is unreachable at + 420 by its ss condition). +- No push. Traces left at /tmp/ours422.txt and /tmp/oracle422.txt. diff --git a/lanes/av1422f.report.md b/lanes/av1422f.report.md new file mode 100644 index 00000000..8653cc48 --- /dev/null +++ b/lanes/av1422f.report.md @@ -0,0 +1,115 @@ +# lane-av1-422f — square-block chroma is the plane block's own rect unit; refusal stays + +## Outcome + +STOP with the 4:2:2 header refusal in place, byte-identical (probe refuses +without the env; the local bypass was reverted before commit). The +square-block path (decode.rs's `(luma_set, chroma_set, luma_tx, chroma_tx, +scans)` selection, formerly 16704-16721) now models `av1_get_max_uv_txsize` +as `av1_get_adjusted_tx_size(max_txsize_rect_lookup[plane_bsize])` — the RECT +that fills the (side/2, side) plane block — and all three chroma walks read +one `(chroma_tx, chroma_tx_h)` unit per grid cell, keyed on ss (1,0). The +av1422e first miss (mi(4,4) side 16: ours two 8x8 units, oracle one TX_8X16) +is gone, and the decode now aligns with the oracle unit-for-unit through 117 +coefficient units — every 16x16 block's U/V TX_8X16 pair, every 8x8 leaf's +U/V TX_4X8 pair, every 16x8 strip's 8x8-square chroma — with equal entry rngs +wherever ours prints them. The stream is not pixel-exact: the next divergence +is the sub-8x8 4x4-leaf chroma at 4:2:2 (TX_4X4 units, one per even-column +leaf), which lives in `decode_leaf_split4`/`decode_leaf8` — other lanes — so +the refusal is retained. + +## Change (decode.rs + decode_probe.rs only) + +- Selection arm at ss (1,0): per-axis unit dims `chroma_tx` (width) x + `chroma_tx_h` (height) — 4 -> (4,4), 8 -> (4,8), 16 -> (8,16), 32 -> + (16,32), 64/128 -> (32,32) — with the unit's TxbSet/scan: + `ChromaRect8x4`+`SCAN_4X8`, `ChromaRect16x8`+`SCAN_8X16`, + `ChromaRect32x16`+`SCAN_16X32`, `Chroma32`+scan32. The destructure gains + `chroma_tx_h`; 4:2:0/4:4:4/lossless arms carry `chroma_tx` twice, so their + walks are untouched. +- New `read_rect_chroma_unit`: one rect chroma unit via the + `read_coeffs_rect` route (the `chroma_tiled` arm's and + `leaf8_chroma422_unit`'s proven shape): `txb_skip_ctx` = above+left in the + offset-7 rows (the unit covers the plane block exactly, so no +3), the + mode-derived default `tx_type` unless `INTRABC_CHROMA_TX` is armed, the + `side >= 32` DCT_DCT clamp, `dequant_and_inverse_typed_wh` + + `push_intra_rect`. Bumps the new `CHROMA422_RECT_HITS` witness counter + (keyed ss (1,0), unit w != h). +- New `push_intra_unit`: `push_intra` when square, `push_intra_rect` when + rect — used by the skip walk. +- All three chroma walks (skip, single-TU, chunked) key on the per-axis + unit dims: `cn_rows = chroma_height / chroma_tx_h`, `luma_span_y = + chroma_tx_h << ss_y`, per-axis cu positions and palette windows. Below + side 64 a 4:2:2 frame's grid is 1x1 and the one unit is the whole plane + block. The chunked walk's edge clip computes `max_units_h` per axis at + ss (1,0) (the shared halved formula assumes a subsampled height and would + clip units libaom codes); the shared rows stay for 4:2:0/4:4:4. +- New `Neighbours::around_mi_422_chroma` for the square path's chroma context + reads: libaom `get_txb_ctx_general` sums its dc-sign votes over + `txb_w_unit` CHROMA 4-px cells, and at ss_x 1 one chroma cell spans TWO + luma mi columns — the per-luma-mi sum double-counts the above votes and + flips `dc_sign_ctx` when the above and left votes have opposite signs + (measured at mi(4,4) plane 1: ours read `dc_sign_cdf[1]`, the oracle row + 0). Sampling every second above cell counts each chroma column once, which + is exactly libaom's sum; the level booleans are ORs over duplicated cells + and cannot change. Used by the single-TU walk's rect branch and both + multi-unit loops at ss (1,0) only; 4:2:0/4:4:4 keep `around_mi_rect`. +- `examples/decode_probe.rs`: prints `chroma422_rect`. + +Untouched: `decode_leaf8`, `decode_leaf_split4`, `decode_rect4_16_strip`, +`decode_block_128rect`, `decode_rect_split`, the resize header reader, the +frame-9 filter path, and refusal_inventory.rs (the refusal string is +byte-identical; the gate stays green). + +## Measurement + +Fixture `/tmp/t422.obu`, sha256 +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` (reused by +hash, 256x144, 22 frames). Oracle `$HOME/.cache/aom-oracle/build/aomdec` +`EC_TRACE=1 EC_TRACE_MODE_STEP=1 EC_TRACE_COEFF=1`; ours `decode_probe` +(debug, `gate-counters`, private target dir) with a LOCAL +`EC_AV1_ALLOW_422_PROBE` env-gated bypass at the stream.rs refusal — +reverted before commit, and the refusal re-proven to fire without the env. + +- Unit-level: 117 consecutive units with equal ENTRY rngs (rect reads print + `entry=`; the first entry mismatch is unit #117), identical unit order and + shapes: 16x16 blocks read ONE TX_8X16 per plane (mi(4,4): U entry 44042, + all_zero ctx row 2 = libaom ctx 9, post-rng 36040, eob 3 — the av1422e + first miss, now exact), 8x8 leaves ONE TX_4X8 per plane, 16x8 strips the + 8x8 square, 8x16 strips 4x16. +- Symbol-level: the deduplicated rng trajectories match value-for-value + through the mi(8,0) leaf's V (ours state 1100), modulo four + oracle-instrumentation print gaps (sub-reads libaom's patched print does + not emit; the trajectories re-align around each). +- Counters: `chroma422_rect: 28`, `chroma422_square: 23` — 28 rect chroma + units ran on the 4:2:2 frame (a 4:2:0/4:4:4 frame cannot increment it; the + counter reads 0 under the old square model). + +## First remaining divergence (named next site, with oracle evidence) + +At the 8x8 sub8 group whose leaves sit at mi(8,10)/(8,11)/(9,10)/(9,11): the +oracle's 4x4 LEAVES at even mi columns are chroma references at 4:2:2 and +each codes a TX_4X4 chroma unit (mi(9,10) plane 1, 38 steps, after only its +own luma) — `ss_size_lookup[BLOCK_4X4][1][0]` is BLOCK_4X4, so the 2x4 plane +rounds up and reads as TX_4X4. Ours reads the leaf's second luma TX_4X4 as +all-zero where the oracle codes coefficients (oracle 16 steps, ours 1), the +first value-level divergence, and everything after is desynced; the run then +ends at `decode_rect4_16_strip`'s closed-shape panic (shape-driven, reached +by the same partition walk). Both sites live in `decode_leaf_split4` / +`decode_leaf8` / `decode_rect4_16_strip` — other lanes. The sub-8x8 4:2:2 +model needs the is_chroma_ref rule `!(mi_col & ss_x)` (every even-column +leaf, not 4:2:0's single bottom-right leaf) plus the TX_4X4 chroma shape. + +## State + +- Refusal `a chroma format of 4:2:2 (subsampling_x != subsampling_y)...` + byte-identical (bypass reverted; `git diff` touches only decode.rs and + decode_probe.rs; probe refuses without the env). +- `cargo check -p ec-av1` (private target dir + `$HOME/.cache/cargo-target-av1422f`): 0 warnings. +- 420 gates green: `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact` + its 10-bit twin — 2/2 pass (the new + arms are unreachable at 420 by their ss condition; `chroma_tx == chroma_tx_h` + on every 4:2:0/4:4:4 path). Refusal gate + `a_non_420_subsampled_sequence_header_is_refused_by_name` green. +- No push. Traces left at /tmp/ours422f.txt and /tmp/oracle422.txt. diff --git a/lanes/av1422filter.report.md b/lanes/av1422filter.report.md index 5886e4f0..65a26b68 100644 --- a/lanes/av1422filter.report.md +++ b/lanes/av1422filter.report.md @@ -69,6 +69,22 @@ ## Decision +- **444 LR follow-up (review finding 2): RED, stopped and reported.** A + 3-frame 192x160 `aomenc --profile=1 --enable-restoration=1` stream + (lr types per frame: `[Sgrproj,None,Switchable]` / `[None,None,Sgrproj]` + / `[Sgrproj,None,Switchable]`) diverges from both the instrumented aomdec + and ffmpeg on frames 0/1 (~26k samples/plane, maxabs 255) and matches + exactly on frame 2. The divergence is already fully present at + EC_AV1_PREFILT_DUMP (frame 0 pre: Y 6124 @ (0,128), U 9176 @ (160,64), + V 10196 @ (128,64)) — a pre-existing 444 RECONSTRUCTION defect, not a + loop-filter one and not this lane's regression: the parent commit + (cc3783f4, scratch worktree) measures 26673/26310/158 against the same + stream, so this lane's ss_y fix strictly improves 444 (frame 2 went to + exact, frames 0/1 shrank) but cannot pin a pixel-exact gate over a + stream whose reconstruction is still wrong. Named for the owning lane: + 444 intra reconstruction around the row-64/row-128 SB boundaries (class: + pre-existing 444 recon; loop filters exonerated — the damage exists + pre-deblock and the filter stages track it 1:1). - The header refusal STAYS unconditional in `stream.rs` — the probe bypass was local-only, applied and reverted byte-identical before the commit (`git diff` after the revert carries only the decode.rs fix); the @@ -77,9 +93,12 @@ `sub8_leaf_chroma422` (parent lane's three fixes) untouched. - The 8-bit `EC_AV1_POSTCDEF_DUMP` rung was added to the ORACLE's source tree (`$HOME/.cache/aom-oracle/src/av1/decoder/decodeframe.c`, rebuilt - with ninja), not to this repo's `scripts/instrument-aom-oracle.sh` — the - script's generator should grow the same patch if the oracle is ever - rebuilt from scratch. + with ninja) and transcribed into + `scripts/instrument-aom-oracle.sh` as rung 15 — its generator block + reproduces the hand patch byte-for-byte (verified by strip-and-replay on + the live tree; the marker `EC_INSTRUMENTED_POSTCDEF` keeps re-runs + no-op), so `build-aom-oracle.sh` + the script rebuild the full ladder + from scratch again. ## Verification diff --git a/lanes/av1422g.report.md b/lanes/av1422g.report.md new file mode 100644 index 00000000..d2ad7e67 --- /dev/null +++ b/lanes/av1422g.report.md @@ -0,0 +1,102 @@ +# lane-av1-422g — sub-8 even-column chroma-ref arm; STOP: split4 is never reached on t422 + +## Outcome + +STOP with the 4:2:2 header refusal in place, byte-identical (the local +`EC_AV1_ALLOW_422_PROBE` bypass was reverted before commit; the probe refuses +without the env — `frames_dispatched: 0`). The even-column chroma-reference +arm for ss (1,0) is in `decode_leaf_split4` per the parent's rule +(`is_chroma_ref = !(mi_col & ss_x)`, one TX_4X4 chroma unit per plane per +even-column leaf, 4:2:0 keeps its single bottom-right leaf), but it is +UNPROVEN and — the round's real finding — UNREACHABLE on this fixture: + +the frame-0 partition walk never takes an 8x8 `PARTITION_SPLIT`. An +`EC_AV1_TRACE` probe printed **zero** split8 group entries before the run +dies at `decode_rect4_16_strip`'s closed-shape panic. Our trace is +byte-identical to 422f's (modulo pid), so the divergence 422f attributed to +the mi(9,10) sub-8 chroma begins EARLIER: by the time the walk reaches the +8x8 at mi(8,10), ours reads a partition value that is not SPLIT, while the +oracle's own trace decodes four 4x4 leaves at mi(8,10)/(8,11)/(9,10)/(9,11). +Per instruction 2 the named stop line is: + + crates/ec-av1/src/decode.rs:14888 — unreachable!("decode_rect4_16_strip chroma shape set is closed") + +reached with chroma shape `(16, 64)` off a `luma=32x64 tx=16x16` strip (the +`EC_RECTCHROMA_GAP luma=32x64 tx=16x16 chroma=16x64` diagnostic prints right +before the panic; the 16 prints of `luma=16x8 → chroma=8x8` earlier are the +4:2:2 square rows downstream and are harmless). decode_rect4_16_strip was not +edited; that panic is the next lane's gate, not this one's fix. + +## Change (decode.rs + decode_probe.rs only) + +- `decode_leaf_split4`: `has_chroma` now branches per subsampling — 4:4:4 + every leaf, 4:2:2 `(lmi.1 & 1) == 0` (every even-mi-column leaf), 4:2:0 + `i == 3` unchanged. A `chroma_422` flag (ss_x 1, ss_y 0) and a + `last_uv422` coarse-slot value were added; the group tail gained a 4:2:2 + branch that only fills `above_uv_mode`/`left_uv_mode` from the group's + last chroma-reference leaf (bottom-left), and the tail's chroma state + stamp is skipped at 4:2:2 (the per-leaf units already stamped). +- New `sub8_leaf_chroma422` (beside `sub8_leaf_chroma444`): one square + TX_4X4 chroma unit per plane at the chroma position + (`px >> ss_x`, `py >> ss_y`) — `ss_size_lookup[BLOCK_4X4][1][0]` is + BLOCK_4X4, so the (2,4) plane area rounds up to the square 4x4 read — via + `read_plane`'s proven `TxbSet::Chroma4` + `TX4` route, with + `Neighbours::around_mi_422_chroma(lmi, 8, 4)` context reads (the unit's 4 + chroma-px width spans TWO luma mi columns; sampling every second above + cell counts each chroma column once), `cfl_src_rect(px, py, 8, 4)` CfL + source, skip arm (predict-only, intrabc-slot disarm counted), intrabc arm + (frame copy at the DV with the ss shifts), and per-leaf entropy stamping + (1 mi row tall, both luma mi columns of the one chroma column). +- New `CHROMA422_SUB8_HITS` witness counter, bumped only on the two + coefficient-reading arms (skip does not count); printed as + `chroma422_sub8` by `examples/decode_probe.rs`. +- Untouched: `decode_leaf8`, `decode_rect4_16_strip`, `decode_block_128rect`, + `decode_rect_split`, the 4:2:0 group tail (including its SKIP arm at + decode.rs:19169-19170 — the sibling-owned flat-DC miss), the square-block + selection arm, `stream.rs` (bypass reverted; refusal string + byte-identical), `refusal_inventory.rs`. + +## Measurement + +Fixture `/tmp/t422.obu`, sha256 +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` (reused +by hash, 256x144, 22 frames). Ours `decode_probe` (debug, gate-counters, +private target dir) with the LOCAL env bypass; oracle traces from 422f left +at /tmp/oracle422.txt. + +- **Reach probe**: with `EC_AV1_TRACE=1`, a temporary per-group print in + `decode_leaf_split4` (since removed) fired ZERO times before the panic — + split4 never runs on this stream; the arm cannot fire, and the + `chroma422_sub8` counter reads 0 for the trivial reason. +- **Trace identity**: our full run (stderr trace, 13029 lines) is + byte-identical to 422f's /tmp/ours422f.txt except the panic line's thread + id — the 422g changes do not alter the trajectory, confirming the + pre-split8 divergence. +- `cargo check -p ec-av1` (private target dir): 0 warnings. +- 420 gate green: `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact` 1/1 passed (`cargo test -p ec-av1 + --lib`); all new arms are keyed on ss (1,0), unreachable at 4:2:0/4:4:4. + +## Next divergence (restated, for the lane that owns the walk) + +The first live defect is UPSTREAM of sub-8: between the last symbol-level +match (mi(8,0) 8x8 leaf's V) and the mi(8,10) 8x8, ours mis-reads the 8x8 +partition symbol (oracle SPLITs, we do not), and the desynced walk later +lands on the 32x64 strip whose 16x64 chroma has no table row (panic above). +Two candidate sites for whoever picks this up: the partition-symbol context +feeding `partition_w8` after an 8x8 leaf run (422f's tail bookkeeping +changed side_mi/partition ctx for the following sibling), or an 8x8-leaf +chroma/context read that consumes the wrong rng count and shifts every later +partition read. Note the rect split4 sibling (the 8x16/16x8 group walker +with `bw`/`bh` args, ~decode.rs:20500) has the same 4:2:0-style chroma and +will need the same even-column treatment once the walk reaches any rect sub-8 +group at 4:2:2. + +## State + +- Refusal `a chroma format of 4:2:2 (subsampling_x != subsampling_y)...` + byte-identical; `git diff` touches only decode.rs and decode_probe.rs; + probe refuses without the env (frames_dispatched: 0). +- Committed on lane-av1-422g (5e163e94). No push. +- Traces left at /tmp/ours422g_trace.txt (EC_TRACE_COEFF run) and + /tmp/ours422g_t2.txt (EC_AV1_TRACE reach run). diff --git a/lanes/av1422h.report.md b/lanes/av1422h.report.md new file mode 100644 index 00000000..bdb39b70 --- /dev/null +++ b/lanes/av1422h.report.md @@ -0,0 +1,96 @@ +# lane-av1-422h — 4:2:2 sub-8/rect chroma model proven rng-exact to the bottom-edge SBs; refusal stays + +## Outcome + +The assignment's premise — "ours reads a non-SPLIT partition at mi(8,10)" — was +FALSE, and this round proves it with partition-level oracle traces: at mi(8,10) +both decoders read `bsize=3 ctx=0 rng=37068 → value=1` (PARTITION_HORZ). +`read_partition` in the oracle source already carried an `EC_PART` probe +(patch never enabled by the 422f/g generation recipe), so this round's traces +are the first with the walk checkpointed per partition read; pairing them +(`EC_PART` rng values, tell offset constant +14) shows the true first +divergences and lets every fix below be verified rng-for-rng. + +Four 4:2:2 chroma-model defects found and fixed (all in `decode_leaf_rect8`, +`decode_leaf8`, `decode_leaf_split4`/`sub8_leaf_chroma422`, `decode_block`): + +1. **`decode_leaf_rect8` (BLOCK_8X4/BLOCK_4X8 strips) used the 4:2:0 + `i == 1`-only chroma rule.** `is_chroma_reference` + (av1_common_int.h:1459) at ss (1,0): a HORZ pair's BLOCK_8X4 strips are + BOTH chroma references (`!(bw & 1)`), a VERT pair's BLOCK_4X8 strips keep + the odd-column leaf. Oracle evidence at the mi(8,10) HORZ pair: uv_mode + read at BOTH (8,10) and (9,10), each strip followed by its own one-TX_4X4 + chroma unit per plane. Fixed `has_chroma` to `!vert || i == 1` at 4:2:2 + and decoded each reference strip's chroma right after its luma via + `sub8_leaf_chroma422` (split path, whole-leaf path, intrabc path), with + the 4:2:0 group tail gated off at 4:2:2 and the coarse uv slots filled + from the last reference strip. The mi(8,10) pair now decodes + rng-for-rng (strip mode reads end at oracle's exact rngs 63250/33264). +2. **`decode_leaf_split4`'s 4:2:2 column parity was inverted** (422g's + `(mi_col & 1) == 0` "even-column" rule — derived by 422f from a + pre-partition-trace misreading of the (8,10) HORZ pair as a split + group). Oracle, mi(30,42) split group: uv_mode read at mi(30,43) and + mi(31,43) ONLY — the ODD columns, per the formula's column clause + `(mi_col & 1)`. Fixed to `(lmi.1 & 1) == 1`. +3. **`sub8_leaf_chroma422` anchored the odd-column leaf's ctx read/write at + the leaf's own column.** libaom anchors at the FLOOR chroma cell + (`pd->above_entropy_context + blk_col` with `blk_col = mi_col >> ss_x`): + an odd-column 4x4 leaf's unit starts at chroma px 86, whose containing + cell is luma mi col 42, so the ctx read AND the per-TU state write land + on luma mi 42,43, not 43,44. Added `ctx_mi = (lmi.0, lmi.1 & !1)`. +4. **`decode_leaf8`'s 4:2:2 chroma rect unit read its txb ctx through the + plain `around_mi`** — the 422f-class dc-vote double-count (one chroma + ctx cell spans TWO luma mi columns at ss_x 1) in the leaf8 path. + Oracle evidence at mi(2,24) plane 2: ours dc_sign row 0, oracle row 2. + Both 422 arms now read `around_mi_422_chroma(leaf_mi, 8, 8)`. + +## Measurement + +Fixture `/tmp/t422.obu` reused by hash +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` +(256x144, 22 frames). Oracle +`$HOME/.cache/aom-oracle/build/aomdec EC_TRACE=1 EC_TRACE_MODE_STEP=1 +EC_TRACE_COEFF=1 EC_PALSYN=1` (the `EC_PART` probes ship in the patched +tree's `read_partition`); ours `decode_probe` with a LOCAL +`EC_AV1_ALLOW_422_PROBE` bypass at the stream.rs refusal — REVERTED before +commit, refusal re-proven to fire by name without the env. + +- After fixes 1–3, the frame-0 partition streams pair 1:1 rng-for-rng from + the tile start through oracle #327 — tell offset constant +14 — covering + every HORZ/VERT 8x8 pair, every split4 group, the (28,44) 16x16 square + (one TX_8X16 chroma per plane, ctx row 9 = our 7-base row 2 after fix 1's + stamp anchor) and the (30,42)/(24,56) bodies. +- Fix 4 (leaf8 dc-sign sampling) was located by the same pairing: the + mi(2,24) 8x8 NONE leaf consumed the oracle's exact 13 bits but landed at + rng 53768 vs 61448; the sign phase of its V plane diverged (dcctx 0 vs 2). + +## Next divergence (named stop, for the lane that owns the partial-SB walk) + +Frame 0 now desyncs where the bottom superblock row begins: the 64x64 at +mi(32,0) hangs over the bottom edge (`has_rows=false`), and libaom READS a +gathered two-symbol partition there (`EC_PART mi_row=32 mi_col=0 bsize=12 +ctx=13 tell=19221 rng=54818` → `EC_PART_VAL value=1`, i.e. HORZ from the +`partition_gather_horz_alike` cdf, splitting the SB into two 64x32 +strips). Our walk reads NO partition symbol for that SB and dispatches +straight into a 64x32 strip walk (`EC_RECTCHROMA_GAP luma=64x32 +tx=32x32 chroma=32x32`), one symbol behind from there. Note the strip +reader's 4:2:2 chroma for a 64x32 strip (32x32 square, `ss (1,0)`) rides +the existing square arm. The `decode.rs:14888` closed-shape panic and the +`decode.rs:19169` skip arm were not touched. + +## State + +- Refusal `a chroma format of 4:2:2 (subsampling_x != subsampling_y)...` + byte-identical; `git diff` touches only `decode.rs`; the probe refuses + without `EC_AV1_ALLOW_422_PROBE` (measured this round). +- `cargo check -p ec-av1` (private target dir + `$HOME/.cache/cargo-target-av1422h`): 0 warnings. +- 420 gates green: `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact` 2/2 (both variants) and + `a_non_420_subsampled_sequence_header_is_refused_by_name` 1/1. Every + changed arm is keyed on ss (1,0); the 4:2:0/4:4:4 paths keep their + proven rows and stamps. +- Temporary EC_RECTDBG/LEAFDBG/CHROMAWALK instrumentation removed before + commit. +- No push. Traces left at /tmp/o_pal.txt (full-probe oracle), + /tmp/o_part.txt, /tmp/u_cur.txt. diff --git a/lanes/av1422i.report.md b/lanes/av1422i.report.md new file mode 100644 index 00000000..e996d364 --- /dev/null +++ b/lanes/av1422i.report.md @@ -0,0 +1,76 @@ +# lane-av1-422i — bottom-SB-row partition gather re-measured: already rng-exact at HEAD; refusal stays + +## Outcome + +The assignment's premise — "ours reads no partition symbol at the bottom 64x64 +mi(32,0)" — is FALSE at HEAD 6cdd3dae, and this round proves it with live +traces instead of the previous round's EC_PART-only dumps. The gathered +two-symbol read the assignment asks for has existed since lane-hgkf r1 +(`decode.rs:27096`, the `(true, false)` arm of the 64-level dispatch): it reads +`gather(&cdfs.partition_w64[ctx], VERT_ALIKE)` with +`VERT_ALIKE = [2, SPLIT, 4, 6, 7, 9]`, maps 0 → PARTITION_HORZ / 1 → SPLIT — +line-for-line libaom `ec_read_partition_impl` + `partition_gather_vert_alike` +(av1_common_int.h:1485, `out[0] = TOP − {VERT, SPLIT, HORZ_A, VERT_A, VERT_B, +VERT_4}`). + +Why the previous round could not see it: the `(true, false)` arm emits +`OUR_PART` under `EC_AV1_TRACE` (trace_edge, decode.rs:6068), not the oracle's +`EC_PART` format — the 422h dumps were filtered on `EC_PART`, so the read was +invisible and looked like "no symbol". + +## Measurement + +Fixture `/tmp/t422.obu` reused by hash +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` +(256x144, 22 frames, 64x64 superblocks). Probe: `decode_probe` with a LOCAL +`EC_AV1_ALLOW_422_PROBE` bypass at the stream.rs:1709 refusal — REVERTED +before commit. Ours run with `EC_TRACE=1 EC_AV1_TRACE=1` (fresh trace +/tmp/u_f0.txt); oracle o_pal.txt. + +- Context numbering: ours `partition_ctx` indexes `partition_w64` 0..15 with + the `bsl*4` term folded out — a constant −12 rename of libaom's ctx for the + 64 level (ours 0/2/2/2, 1/3/3 vs oracle 12/14/14/14, 13/15/15 at every + paired SB). Same slot, same CDF, same state; pairing confirms it. +- Bottom superblock row, frame 0 — all four gathered reads pair rng-for-rng, + pre-read rng identical: + - mi(32,0) ours 54818 / oracle 54818 (oracle ctx 13, value 1 = HORZ) + - mi(32,16) ours 41610 / oracle 41610 + - mi(32,32) ours 61472 / oracle 61472 + - mi(32,48) ours 45794 / oracle 45794 +- Interior pairing of the mi(32,0) strip continues past the gather: post + uv_mode rng 43856 on both sides (mode=12, uv_mode=12), first luma all_zero + ends at 53566 on both sides. The 64x32 strip's 4:2:2 chroma (32x32 square, + ss (1,0)) rides the square arm as documented. has_rows=false correctly + skips the second strip on both sides. +- Frame 0 therefore decodes through the bottom superblock row. The + `EC_RECTCHROMA_GAP luma=64x32 tx=32x32 chroma=32x32` lines are the + non-fatal diagnostic at decode.rs:10225, not a desync. + +## Next divergence (named stop — inter rect lane, not this lane) + +Frame 1 (first inter frame) panics at `decode.rs:29094:39` — `range end index +68 out of range for slice of length 64` — in the all-zero-residual prediction +copy: a rect inter block's `prediction[src..src + w]` reads past a 64-sample +buffer. Trigger context: mi(4,0) 64x64 inter, `partition_w16 value=7` +(VERT_B) at the 16-level, tell=542. The earlier round's decode.rs:14888 +`decode_rect4_16_strip` closed-shape stop was not reached this run (frame 0 +completes; the panic fires first). Both sites are downstream of the bottom-row +partition gather and outside this lane's ownership; decode.rs:14888 and the +decode.rs:19169 skip arm remain untouched, as do the four chroma-ref fixes. + +## State + +- No source change this round: the gather the assignment requested is already + in HEAD, so there is nothing to write without inventing a duplicate arm. + `git diff` vs 6cdd3dae touches only this report; the stream.rs probe bypass + is reverted (refusal `a chroma format of 4:2:2 (subsampling_x != + subsampling_y)...` byte-identical, unconditional). +- Refusal STAYS: the 16-frame stream is not pixel-exact (frame 1 panics), so + the delete condition (pixel-exact + 422 chroma counter) is unmet. +- 420 gates green (private target dir `$HOME/.cache/cargo-target-av1422i`): + `a_non_420_subsampled_sequence_header_is_refused_by_name` 1/1 (proves the + reverted refusal fires by name), `a_real_aomenc_stream_with_a_skipped_8x8_ + intra_leaf_whose_tx_split_decodes_pixel_exact` 2/2 (both bit depths) under + `EC_AV1_REQUIRE_AOMENC=1`. +- No push. Traces left at /tmp/u_f0.txt (ours, frame 0 bottom row + frame 1 + panic) and /tmp/o_pal.txt (oracle). diff --git a/lanes/av1422inter.report.md b/lanes/av1422inter.report.md new file mode 100644 index 00000000..9afc3ad7 --- /dev/null +++ b/lanes/av1422inter.report.md @@ -0,0 +1,134 @@ +# lane-av1-422inter — the frame-9 `read_coeffs_rect` scratch panic fixed at the +# source (the 4:2:2 intra-in-inter side-64 chroma is TWO square TX_32X32 units, +# not one 32x64 rect unit); the inter-frame divergence remeasured with the +# stage ladder and STOPPED at the sub-8x8 inter chroma class (`decode_inter_block8`) + +## Outcome + +1. REMEASURED first (pinned fixture `/tmp/t422.obu` sha256 + `d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`, + 256x144 / chroma 128x144, 16 coded frames, local `EC_AV1_ALLOW_422_PROBE` + bypass applied and reverted byte-identical after — `git diff` after the + revert carries only the decode.rs fix): reproduced the frame-9 panic + exactly as the r lane named it — `rect coeff scratch w=32 h=64 n=2448` + at [`read_coeffs_rect`]'s guard (decode.rs:7195), backtrace + `decode_inter_block` -> `read_rect_chroma_unit`; 9 frames decoded before + the abort. +2. ROOT CAUSE, and why the scratch itself stays untouched: the panic site is + `decode_inter_block`'s intra-in-inter 4:2:2 chroma arm (lane-av1-422k's + `chroma_w != chroma_h` dispatch), whose `_` side-match handed the WHOLE + uv plane block (32x64) to [`read_rect_chroma_unit`] as ONE rect unit. But + `av1_get_max_uv_txsize(BLOCK_64X64)` at ss (1,0) is + `av1_get_adjusted_tx_size(max_txsize_rect_lookup[BLOCK_32X64])` = + `av1_get_adjusted_tx_size(TX_32X64)` = **TX_32X32** — libaom codes TWO + stacked SQUARE 32x32 units per plane, plane-major (U r0, U r1, then V + r0, V r1), never a TX_32X64 coefficient read (no such scan exists in + this decoder and libaom writes none: a 64-axis codes its low-32 corner). + Lifting the scratch bound to 36x68 (the r lane's tentative "heap + fallback" sketch) would have read a full 32x64 scan and desynced on the + very first such unit. The KEY-FRAME path has carried the correct model + since lane-av1-422f (`decode_block`'s 4:2:2 chroma_tx table: "64 and + 128: TX_32X64 / TX_64X64 adjust down to TX_32X32, square units, a 1x2 / + 2x4 grid") — proven byte-exact on this fixture's frame 0. +3. FIX (the sibling 444 per-unit-walk pattern): the `side == 64` arm at + `decode_inter_block`'s intra-in-inter chroma now walks the two stacked + 32x32 square units per plane through [`read_plane`] (`TxbSet::Chroma32`, + `SCAN_32`, txb_skip ctx = above+left+3 — the offset-10 rows, the plane + block being bigger than the unit), each with its own per-chroma-cell + context read (`around_mi_422_chroma` at the unit's luma span), its own + `tu_reach_rect`, immediate `record_mi_chroma`, assembled into the + chroma_side-strided block grid, with `mu_chroma = true` so the tail's + existing `mu_chroma_units` enumeration replays the per-unit entropy + state after the whole-block record (the lane-dpm1 mechanism; its + (rows, cols, ur, uc) walk already derives exactly these two units per + plane at ss (1,0)). The 4/8/16/32 rect arms and the square + `chroma_w == chroma_h` arm are untouched — 4:2:0 and 4:4:4 are + byte-identical by construction (ss-keyed). `read_coeffs_rect` itself is + untouched: with the adjusted-tx model no caller can deliver a unit + bigger than 32x32's 36x36 levels frame, which is the invariant the + scratch sizing always stated. +4. MEASURED after the fix (16 frames decode, no panic; the probe's + `chroma422_square` counter rose 24 -> 87 across the stream, the touched + class provably firing on inter frames): frame 0 is **byte-exact vs the + instrumented aomdec at PREFILT, POSTDEBLOCK, POSTCDEF and FINAL on Y, U + and V** (0 diffs everywhere — the parent lanes' frame-0 exactness + survives). The inter frames stay divergent: per-frame stage-ladder + counts (ours padded-cropped vs oracle, both vs the same instrumented + `$HOME/.cache/aom-oracle/build` aomdec): + - frame 1: PREFILT Y 30825 / U 12624 / V 12796, first Y (0,8) 76 vs 80, + first U (0,0) 231 vs 90, first V (0,0) 164 vs 241; + - frames 1..16 all diverge from (0,0) with ~28-35k Y / ~12-17k U / + ~11-17k V per frame at PREFILT, and POSTDEBLOCK / POSTCDEF / FINAL + track the same first samples 1:1 (the loop filters introduce no new + first-diff site) — a pre-filter reconstruction class, filters + exonerated. +5. ATTRIBUTION (2-frame cut, `EC_TRACE_MODE_STEP` + `EC_TRACE_COEFF` + pairing against the oracle's own rungs): every commonly-traced mode / + skip / angle / uv_mode read of frames 0+1 agrees rng-for-rng (1326 + paired lines, 0 mismatches), and the first 873 coefficient reads + (frame 0 in full) agree — the entropy walk is in sync up to frame 1's + first coded block. The FIRST divergence is that block's own tail: at + mi (0,0) (8x8 inter leaf, NEARESTMV (0,0), coded), after the leaf's + luma TX_8X8 txb_skip bit (agreed, rng 55168) the oracle reads the + leaf's **U TX_4X8 rect chroma unit** (ctx 7 row, coded) then V — while + OURS reads a TX_4X4-SQUARE-shaped unit (`TxbSet::Chroma4`, + ctx = above+left, no offset-7 row). `decode_inter_block8`'s chroma half + models the 4:2:2 leaf chroma plane block — `ss_size_lookup + [BLOCK_8X8][1][0]` = BLOCK_4X8, one TX_4X8 rect unit per plane + (`av1_get_max_uv_txsize`) — as a `chroma_side = SIDE >> ss_x` = 4 + square: wrong coefficient set/scan/ctx rows, and the same 4x4 square + shape flows into the leaf's MC prediction, skip push and interintra + blends. Pixel witness: frame-1 U (0,0) ours=231 ~= frame-0's 225 (the + zero-mv prediction with only a square-read residue applied) vs the + oracle's 90 (the coded TX_4X8 residual applied). +6. That defect class is not a one-site edit: the leaf's whole chroma half + must move to (4,8) shapes — prediction build, skip/interintra/OBMC + pushes, the rect coefficient read (`TxbSet::ChromaRect8x4` / + `SCAN_4X8`, offset-7 ctx rows, inherited luma tx type via + [`read_inter_plane_rect`]) — and the sub8 split-group's own chroma read + (`decode_inter_sub8_split4`'s `TxbSet::Chroma4` group unit) repeats the + same square model. Per charter step 3: STOPPED and named. + +## Decision + +- The header refusal STAYS unconditional in `stream.rs` — delete condition + unmet (not pixel-exact from frame 1 on). The bypass was local-only, one + `&& std::env::var(...).is_err()` clause, reverted byte-identical before + the commit; the refusal gate re-verified firing (see Verification). +- `read_coeffs_rect` untouched (no scratch growth, no new panic path); + 4:2:0/4:4:4 arms of the touched dispatch untouched; `sub8_leaf_chroma422` + (parent lane) untouched; the 4:2:0 group-tail SKIP arm untouched. +- Next stop named for the owning lane: **`decode_inter_block8`'s 4:2:2 + chroma half** (leaf chroma plane block (4,8): one rect TX_4X8 unit per + plane through the inter rect reader, (4,8)-shaped MC prediction and skip + pushes) plus `decode_inter_sub8_split4`'s group chroma read; after that + round the stage ladder of Outcome 4 should simply be re-run — frame 0 + and the side-64 class are now proven clean, so the residual measurement + is directly attributable. + +## Verification + +- `cargo check -p ec-av1` (target `~/.cache/cargo-target-av1422inter`): + 0 warnings, 0 errors on a fresh `Checking` of the edited tree. +- Pre-fix panic reproduced on the pinned fixture (backtrace named above); + post-fix the same stream decodes 16/16 frames, frame 9 included. +- Frame-0 stage dumps vs the instrumented aomdec: PREFILT / POSTDEBLOCK / + POSTCDEF / FINAL all Y=0 U=0 V=0 (comparator: ours padded 256x160/128x160 + u8 cropped, probe FINAL u16 planes vs oracle u8 — values equal). +- `stream::tests::a_non_420_subsampled_sequence_header_is_refused_by_name`: + 1 passed, 0 failed (refusal fires again after the bypass revert). +- `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact` under `EC_AV1_REQUIRE_AOMENC=1` + (with `EC_AV1_AOMENC` pointed at the oracle build): 1 passed, 0 failed — + the 4:2:0 inter path is unchanged. +- `git status` clean except the decode.rs fix; the report is the only other + file in the commit. + +## State + +- Commit on lane-av1-422inter (no push): the side-64 per-unit chroma fix in + `decode_inter_block` + this report. +- The stage-ladder instruments live in `/tmp/i422/` (our/oracle per-stage + dumps for all 17 oracle frames, comparator + EC_ISTEP pairing scripts) — + scratch, not committed; the oracle build's rungs already carry everything + needed to regenerate them. diff --git a/lanes/av1422j.report.md b/lanes/av1422j.report.md new file mode 100644 index 00000000..0332f8d5 --- /dev/null +++ b/lanes/av1422j.report.md @@ -0,0 +1,99 @@ +# lane-av1-422j — inter chroma skip residual sized from the write rect; frame 1 decodes past the VERT_B skip strip; refusal stays + +## Outcome + +The frame-1 panic at `decode.rs:29094:39` (`range end index 68 out of range +for slice of length 64`) is fixed by sizing `decode_inter_block`'s chroma +square from the write rect instead of the block side, and the same-shape sweep +found exactly one more instance of the class, sharing the same fix. The +16-frame stream is NOT pixel-exact — the frontier moved to the intra-in-inter +chroma read, a different machinery — so the 4:2:2 header refusal STAYS +(byte-identical, unconditional; the local `EC_AV1_ALLOW_422_PROBE` bypass was +reverted before commit). + +## Root cause and fix + +`decode_inter_block` computed `chroma_side = side >> ss_x(fctx)` (old +decode.rs:31227). Every consumer indexes the chroma prediction/residual +buffers `row * chroma_side + col` over the WRITE rect +(`write_chroma_w x write_chroma_h`), and at ss (1,0) that rect is +`side/2 x side`: frame 1's skipped 16-level VERT_B strip at mi(4,0) +(8x16 luma, tell 542) has a 4x16 chroma rect, so a `side >> ss_x` = 8 square +is shorter than `row * 8 + 4` on rows >= 8 — the all-zero-residual copy read +`prediction[64..68]` out of the 64-sample buffer (reconstruct_mc_rect's +`residual.is_empty()` branch, decode.rs:29094). Fixture +`/tmp/t422.obu` sha256 +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` +reproduced it before the change and passes the block after it. + +Fix: `let chroma_side = (side >> ss_x(fctx)).max(side >> ss_y(fctx));` +(decode.rs:31237) — the enclosing square of the chroma rect. Bit-identical at +4:2:0 (`side/2`) and 4:4:4 (`side`); only 4:2:2 changes shape. + +## Same-shape sweep (ZERO_RESIDUAL slices vs forwarded w/h) + +- `decode_inter_block` skip arms, single-ref (33803..) and compound (32325..): + both chroma pushes forward `(write_chroma_w, write_chroma_h)` at stride + `chroma_side` with `ZERO_RESIDUAL[..chroma_side * chroma_side]` — healed by + the one-line fix (chroma_side >= both write dims now). The paired + `Grid::Zero(chroma_side * chroma_side)` bookkeeping matches the slices. +- Luma skip arms (`ZERO_RESIDUAL[..side * side]`, stride `side`, rect + `(write_w, write_h)` with w,h <= side): max index + `(write_h-1)*side + write_w <= side*side` — provably safe, untouched. +- Other inter-path slices audited against their forwarded dims: + `decode_block_rect4` skip arm (`side * bh` / `cside * ch` — stride*rows + sizing, safe), `decode_intrabc_rect` (11682/12024, square >= rect, safe), + 14205 (`side * bh`, safe), 37037/37187 (4:4:4-only, SIDE^2 >= rect, safe), + 37338 sub8 tail (square push, safe). `decode_inter_block8`'s chroma + `push_mc` (square) always fits its own square slice — no panic class there; + its 4:2:2 8x8-leaf chroma is a latent half-write shape, NOT this class, and + was left for its owning lane. + +## Frontier re-measure (EC_AV1_ALLOW_422_PROBE=1, local only) + +1. After the sizing fix the skip strip passes and the next stop was + `transform.rs:1150` (`one coefficient per position`, 256 vs 1024): the + square non-skip chroma arm read a `chroma_side`-SQUARE unit (32x32 after + the fix) with the caller's 4:2:0 `scan_chroma` (TX_16X16) on the 32x32 + inter block at px=0 py=0. Fix: both chroma arms route non-square chroma + rects through `read_inter_rect_chroma` + (`rect_tu || (write_chroma_w, write_chroma_h) != (chroma_side, + chroma_side)`, decode.rs:32712/34222) — a 32x32 block codes ONE TX_16X32 + chroma unit (`av1_get_max_uv_txsize` of BLOCK_16X32), exactly + `rect_inter_chroma_set`'s (16,32) row. 4:2:0/4:4:4 squares keep the square + arm (their chroma rect IS `chroma_side`-square). +2. Next stop: `rect_inter_chroma_set` refused (8,8) — a 4:2:2 HORZ_B 16x8 + strip's chroma plane block is 8x8 SQUARE and the rect reader now takes it. + Added the square rows (16,16)->Chroma16, (8,8)->Chroma8, (4,4)->Chroma4 + (decode.rs:22420) — the exact `get_txsize_entropy_ctx` tables the square + arms use; unreachable before this lane. +3. Next stop: `rect_scan` refused squares for the same units; added + `(w, h) if w == h => default_scan(w)` (decode.rs:22485). +4. Current named stop: an INTRA 16x16 block inside frame 1 (px=192 py=96) + panics in the intra-in-inter branch's chroma `read_plane` + (`exec_intra` -> `reconstruct`, index len 128 idx 128, decode.rs:3845) — + the intra chroma reader still predicts/reconstructs at square + `chroma_side` shapes. That is intra prediction machinery, not the + ZERO_RESIDUAL slice class, and reworking it means inventing chroma + shapes beyond this lane's mandate; left as the named stop for the + owning lane. + +4:2:2 chroma counters PROVE chroma units ran on the probe path: +`chroma422_square: 24`, `chroma422_rect: 96`, `chroma422_sub8: 26` — but the +stream is not pixel-exact, so the delete condition (pixel-exact + counter) is +unmet and the refusal stays. + +## State + +- Source change: `crates/ec-av1/src/decode.rs` only (chroma_side sizing, two + rect-routing conditions, square set/scan rows). `git diff` = 42 insertions, + 3 deletions. The stream.rs probe bypass is REVERTED; default refusal + re-verified firing: `REFUSED: unsupported: AV1 decode_stream (a chroma + format of 4:2:2 ...)`. +- 420 gates green (target dir `$HOME/.cache/cargo-target-av1422j`): + `a_non_420_subsampled_sequence_header_is_refused_by_name` 1/1; + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_ + pixel_exact` 2/2 (both bit depths) under `EC_AV1_REQUIRE_AOMENC=1` — a real + 420 decode gate over the shared `decode_inter_block` path, confirming the + changes are bit-neutral at 4:2:0. `cargo check -p ec-av1`: 0 warnings. +- No push. Probe traces left at /tmp/t422_probe.txt/.err. diff --git a/lanes/av1422k.report.md b/lanes/av1422k.report.md new file mode 100644 index 00000000..7dd5701c --- /dev/null +++ b/lanes/av1422k.report.md @@ -0,0 +1,79 @@ +# lane-av1-422k — intra-in-inter chroma prediction sized from the plane block; frame 1's INTRA 16x16 passes; refusal stays + +## Outcome + +The frame-1 panic at `decode.rs:3845` (`index out of bounds: the len is 128 +but the index is 128`) is fixed by sizing `decode_inter_block`'s INTRA arm's +chroma prediction/reconstruction from the 4:2:2 plane block +(`side >> ss_x`, `side >> ss_y`) instead of the enclosing square. The panic +was NOT the residual-slice class: the len-128 slice was the CfL AC SIGNAL. +The 16-frame stream is NOT pixel-exact — the frontier moved to the INTER +chroma rect-set table (a clean named refusal, different machinery) — so the +4:2:2 header refusal STAYS (re-verified firing by default; the local +`EC_AV1_ALLOW_422_PROBE` bypass was reverted before commit). + +## Root cause and fix + +Frame 1's block at px=192 py=96 is a SKIPPED 16x16 INTRA block inside the +inter frame (DC_PRED + CFL, zero residual), decoded by `decode_inter_block`'s +intra arm. That arm pushed/read chroma at the 422j enclosing square +`chroma_side = max(side >> ss_x, side >> ss_y)` = 16 for a 16x16 luma block, +but the 4:2:2 chroma plane block is 8x16: + +- The skip arm (`push_intra(1/2, cpx, cpy, chroma_side, ...)`) pushed a + SQUARE 16x16 op with `ZERO_RESIDUAL` and CFL armed. `ac = cfl_src(px, py, + side)` builds the AC signal over the LUMA 16x16, which `cfl_ac_ss` + downsamples to the true plane shape 8x16 = 128 samples. The square + `reconstruct` walked `row * 16 + col` and read `ac_q3[128]` — the panic. + (Instrumented `exec_intra`: `plane=1 x=96 y=96 bw=16 bh=16 rect=false + res_len=0 cfl=true`.) Even without the panic the square predict would have + written 8 columns of wrong chroma past the plane block. + +Fix (decode.rs, intra arm only): + +1. `let chroma_w = side >> ss_x(fctx); let chroma_h = side >> ss_y(fctx);` +2. Skip arm: `push_intra_unit(1/2, cpx, cpy, chroma_w, chroma_h, ...)` with + `ZERO_RESIDUAL[..chroma_w * chroma_h]` (routes rect to + `push_intra_rect`/`reconstruct_rect`); the neighbour write-back grids are + `Grid::Zero(chroma_w * chroma_h)`. +3. Non-skip arm: `chroma_w == chroma_h` keeps the square `read_plane` + verbatim; at 4:2:2 both planes go through `read_rect_chroma_unit` with the + key-frame path's proven set/scan rows keyed on the LUMA side (16 -> + `ChromaRect16x8` + `SCAN_8X16`, 8 -> `ChromaRect8x4`, 32 -> + `ChromaRect32x16`) and the per-chroma-cell context read + (`around_mi_422_chroma`), exactly the decode_block 422f idiom. + +Byte-identical at 4:2:0 and 4:4:4: `chroma_w == chroma_h == chroma_side` +there, so every replaced call keeps its exact arguments and +`push_intra_unit` routes to the same square `push_intra`. + +Fixture `/tmp/t422.obu` sha256 +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129` +panicked before the change and passes the block after it. + +## Frontier (EC_AV1_ALLOW_422_PROBE=1, local only, bypass since reverted) + +Next stop is a clean refusal, not a panic: +`rect_inter_chroma_set` (decode.rs:22401, refusal string at decode.rs:22429) +— "a rectangular inter chroma transform unit whose shape has no coefficient +table set here". A later inter block in frame 1 codes a chroma rect unit +whose (w, h) has no row in that table (the 422j square rows (16,16)/(8,8)/(4,4) +and the rect rows listed there are present; the new shape is none of them). +That is the inter chroma entropy-set table, not the intra prediction class +this lane owns — left as the named stop; an `EC_*` print of the refusing +(w, h) at that site is the first step for the owning lane. + +## State + +- Source change: `crates/ec-av1/src/decode.rs` only (intra-arm chroma_w/h, + skip-arm unit pushes + grid sizes, non-skip rect routing). Temporary + exec_intra/push_intra traces and the stream.rs probe bypass are REVERTED; + default refusal re-verified firing: `REFUSED: unsupported: AV1 decode_stream + (a chroma format of 4:2:2 ...)`. +- 420 gates green (target dir `$HOME/.cache/cargo-target-av1422k`): + `a_non_420_subsampled_sequence_header_is_refused_by_name` + + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_ + pixel_exact` under `EC_AV1_REQUIRE_AOMENC=1`: 3 passed, 0 failed. Real + 420 decode over the shared intra arm, confirming the change is bit-neutral + at 4:2:0. `cargo check -p ec-av1`: 0 warnings. +- No push. diff --git a/lanes/av1422kf.report.md b/lanes/av1422kf.report.md new file mode 100644 index 00000000..e6929aac --- /dev/null +++ b/lanes/av1422kf.report.md @@ -0,0 +1,82 @@ +# lane-av1-422kf — the frame-0 U (0, 23) first diff: NAMED and FIXED (one +# missing arm in [`decode_rect_split`]'s chroma_tiled walk: the uv-palette +# prediction was never set, so the square 4:2:2 chroma rows decoded a +# uv-palette strip's chroma as plain DC) + +## Outcome + +1. NAMED the sample: frame 0, plane U, row 0, col 23, ours 50 vs oracle 49. + The parent attributed the class to [`decode_rect_split`]'s own-chroma + keyframe gap; this lane localized it to the exact unit and mechanism. +2. The owning unit: chroma 8x8 at chroma px (24, 0) — the square chroma of a + 16x8 luma strip at luma px (48..63, rows 0..7) — pushed by + [`decode_rect_split`]'s chroma_tiled `(8, 8)` arm through `read_plane` + (backtrace: inline_intra ← read_plane ← decode_rect_split ← + decode_leaf_rect). +3. Entropy PROVEN in sync: pre-loop-filter frame-0 LUMA is byte-exact against + the oracle's `EC_AV1_PREFILT_DUMP`, and the U/V coefficient read of the + unit pairs with the oracle by rng at BOTH ends (ours rng0=48179 / rng1= + 64520 == the oracle's `EC_COEFF plane=1 tx_size=1 mi_row=0 mi_col=12 + rng=48179` and the following V unit's rng=64520). Same symbols, same + levels (±1 at scan c=9/10/21, libaom dequant ±63 == ac_q(8-bit, 56)=63 — + note the oracle's `pos=` fields are column-major; 3/4/6 there == raster + 24/32/48 here), so the divergence was prediction-side only. +4. The paired oracle EC_ISTEP ladder for the strip (skip/cdef/dq/mode/ + angle_y/uv_mode/angle_uv — every value and rng identical to ours) plus the + oracle's EC_PALSYN line (`y=2`) identified the mechanism: the strip is a + **uv-PALETTE block**. Our `chroma_tiled` arm — uniquely among the chroma + arms — never called `set_palette_pred`, so `read_plane` consumed no palette + prediction and reconstructed plain DC (ours flat 97 where the oracle has + the palette colour map). Class: same-symbols-silent-prediction. +5. FIX (14 lines, one arm): the chroma_tiled unit loop now sets the palette + prediction per unit per plane (`palette_window` of `m.palette_uv` to the + unit's rect), mirroring the skip/lossless/unsplit arms. 4:2:0 and 4:4:4 + untouched unless `m.palette_uv` is Some (previously broken output anyway). +6. MEASURED (pinned fixture, frame 0, single-frame cut sha256 + `3dd3f768ef553c02316848c2d3184c3765030c0a6fcb95887e4719add9ded3af` — first + OBU prefix of the pinned 22-frame t422.obu; local `EC_AV1_ALLOW_422_PROBE` + bypass, reverted byte-identical after): + - U (0, 23) now decodes **49 == oracle final 49** — the named sample is + EXACT. + - U final diffs 4491 → **1774**; V final diffs 4888 → **2165**; U + pre-filter recon diffs 3148 → **533**. + - `chroma422_square` counter = 24 on this frame (the fixed arm provably + ran; non-vacuity). +7. REMAINING class for the next lane: U pre-filter diffs now start at + (108, 72) (rows 72..79, then 104+; V first diff (48, 0)) — chroma of the + 16x8 strip at chroma (96, 72) and the 16x32 strip at (112, 64): NOT the + palette arm fixed here (both decoded with their own modes); needs its own + localization. Frame 0 is still not pixel-exact, so the + "delete the header refusal" condition stays unmet. + +## Decision + +- The named col-23 sample WAS one arm in [`decode_rect_split`] — fixed, not + punted. The frame-9 [`read_coeffs_rect`] scratch panic is untouched + (another lane's, and the single-frame cut sidesteps it). The four TX_4X8 + chunk and the Some(3) offset are untouched. `read_coeffs_rect` untouched. +- Header refusal STAYS in `stream.rs`, unconditional (no env gate in the + commit; verified firing by name without the env after revert). + +## Verification + +- `cargo check -p ec-av1` (target `~/.cache/cargo-target-av1422kf`): 0 + warnings, 0 errors. +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: + `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact`: 1 passed, 0 failed. +- `stream::tests::a_non_420_subsampled_sequence_header_is_refused_by_name`: + 1 passed, 0 failed (and the example probe refuses the fixture by name + without the env). +- `git diff` after the bypass revert carries ONLY the decode.rs fix; all + temporary EC_KF422DBG/TEMPQM probes and the local bypass are out. + +## State + +- Commit on lane-av1-422kf (no push): the chroma_tiled palette fix + this + report. +- Next stop named for the owning lane: U (108, 72) / V (48, 0) pre-filter + recon class at the (96, 72) 16x8 and (112, 64) 16x32 strips' own chroma — + same localization recipe applies (single-frame fixture + rng pairing + against `$HOME/.cache/aom-oracle/build` aomdec, `EC_AV1_ALLOW_422_PROBE` + local-only). diff --git a/lanes/av1422kf2.report.md b/lanes/av1422kf2.report.md new file mode 100644 index 00000000..2d29ba5b --- /dev/null +++ b/lanes/av1422kf2.report.md @@ -0,0 +1,97 @@ +# lane-av1-422kf2 — the remaining frame-0 class at U (108, 72) / V (48, 0): +# NAMED and FIXED — the sub-8x8 4:2:2 chroma unit decoded at the wrong +# position, wrong reach table and half-visible neighbour mode (three related +# one-index defects, all in [`sub8_leaf_chroma422`]); frame-0 PRE-FILTER +# reconstruction is now pixel-exact (Y, U and V) against the oracle's +# `EC_AV1_PREFILT_DUMP` + +## Outcome + +1. REMEASURED first (pinned fixture, single-frame cut + `/tmp/t422f0.obu` sha256 `3dd3f768ef553c02316848c2d3184c3765030c0a6fcb95887e4719add9ded3af` + — first OBU prefix of the pinned 22-frame t422.obu; the frame is + **256x144**, chroma planes 128x144; local `EC_AV1_ALLOW_422_PROBE` + bypass applied, reverted byte-identical after): at the parent's baseline + the pre-filter chroma diffs were U 533 / V 869, first U (108, 72) — + confirming the parent's sample. +2. NAMED the class at U (108, 72): the 8x8 luma block at luma (216, 72) + splits into four 4x4 leaves; 4:2:2's `is_chroma_reference` + (`av1_common_int.h:1454`) puts the chroma syntax on the ODD-column leaves + (`(mi_col & 1) || !(bw & 1) || !ss_x` — the port already read uv_mode + there, entropy in sync, luma byte-exact), but libaom ANCHORS the leaf's + TX_4X4 chroma unit at the floored chroma cell + (`(mi_col & !1) * MI >> ss_x` = chroma px 108), not at the odd leaf's own + chroma x (110). Ours reconstructed at 110: px 108..109 were never written + (zeros at exactly the parent's sample), px 112..113 got the unit's right + columns. Oracle ground truth: the mi(18,55) unit's reconstruction is a + pure V-copy of the row above AT 108..111. Fix 1: anchor `cpx` at + `(lmi.1 & !1) * MI >> ss_x`. U/V prefilt 533/869 → 477/813, first diff + moved to (96, 104). +3. The (96, 104) cluster named the next layer: an 8x4 strip's chroma unit + (mi(27,44), uv D45) read undecoded pixels to its upper right. The oracle's + own `EC_PRED` trace prints `n_tr=0` there: libaom answers + `has_top_right`/`has_bottom_left` from the LEAF's OWN rect shape + (`has_tr_8x4`/`has_tr_4x8` at the leaf's mi — bit 6 of byte 22 is 0), + while the port used the standalone square-4x4 `Reach::of(4, ..)` lookup + (same bit = 1). Fix 2: `sub8_leaf_chroma422` takes the leaf's shape and + uses `Reach::of(4, ..)` only for a BLOCK_4X4 leaf, `Reach::of_rect(8, 4)` + / `(4, 8)` for a rect pair's strip. Prefilt chroma 477/813 → 8/15. +4. The last 8/15 samples (chroma (100..103, 120..123), the H-mode unit at + mi(30,50)) named the third defect: the unit's left neighbour mi(30,48) is + an 8x4 strip with uv SMOOTH_V, but its `record_uv_mode_mi(…, 1, 1, …)` + stamped only ONE of the strip's two mi columns, so mi(30,50)'s + `chroma_left_mbmi` lookup hit an empty cell, lost the smooth neighbour and + skipped libaom's always-on strength-1 intra edge filter + (`get_intra_edge_filter_type` 1 vs our 0; prediction sums 6139/6307 vs + 6142/6312). Fix 3: record the uv mode over the leaf's whole mi footprint + (`(w_mi, h_mi)` from the leaf shape). All three fixes are inside + [`sub8_leaf_chroma422`] and its five call sites. +5. MEASURED after the three fixes: **PREFILT Y EXACT, U EXACT, V EXACT** + (byte-identical frame-0 pre-loop-filter reconstruction against the oracle + dump). FINAL dumps: U 1774 → 1236, V 2165 → 1263 — every remaining final + diff is introduced by the LOOP FILTER (pre-filter row 0 is exact; the + filter propagates damage to the top rows). Non-vacuity: + `chroma422_square` = 24, `chroma422_rect` = 96, `chroma422_sub8` = 26 on + this frame — all three touched arms provably ran. +6. REMAINING class for the next lane: the 4:2:2 LOOP FILTER. With pre-filter + recon byte-exact, the 1236/1263 final-diff samples are deblock/CDEF/LR + chroma work (the parent's V (48, 0) is this class's first final sample — + pre-filter V at row 0 is exact). Frame 0 is still not final-pixel-exact, + so the "delete the header refusal" condition stays unmet. + +## Decision + +- The palette set in 93c4dff5 is untouched (chroma422_square still 24; the + chroma_tiled arm's `set_palette_pred` intact). +- `read_coeffs_rect` untouched. The frame-9 rect scratch panic is untouched. + The 4:2:0 group-tail SKIP arm untouched. Header refusal STAYS + unconditional in `stream.rs` — verified firing by name on this very + fixture after the bypass revert, plus the named gate test. +- The bypass was local-only (`EC_AV1_ALLOW_422_PROBE` on the env, one + `&& std::env::var(…).is_err()` clause), reverted byte-identical before the + commit; `git diff` after the revert carries ONLY the decode.rs fix. + +## Verification + +- `cargo check -p ec-av1` (target `~/.cache/cargo-target-av1422kf2`): + 0 warnings, 0 errors. +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: + `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact`: 1 passed, 0 failed. +- `stream::tests::a_non_420_subsampled_sequence_header_is_refused_by_name`: + 1 passed, 0 failed. +- Stage dumps compared sample-for-sample (cropped `PREFILT_WIDE_DUMP` vs the + oracle `EC_AV1_PREFILT_DUMP`, same 73728-byte layout, 256x144 / 128x144): + post-fix Y/U/V all exact; symbol-level pairing via the oracle's + `EC_ISTEP`/`EC_PALSYN`/`EC_PRED`/`EC_PREDOUT8` rungs against our + `EC_TRACE_MODE_STEP`/`EC_PRED` traces (rng and values matched at every + step of every unit named above). + +## State + +- Commit on lane-av1-422kf2 (no push): the three sub8-422 chroma fixes + + this report. +- Next stop named for the owning lane: the 4:2:2 loop filter — deblock/CDEF + chroma extents against `$HOME/.cache/aom-oracle/build` aomdec dumps + (`EC_AV1_POSTDEBLOCK_DUMP` rungs exist on both sides); the decode-side + frame-0 recon it consumes is now proven exact. diff --git a/lanes/av1422l.report.md b/lanes/av1422l.report.md new file mode 100644 index 00000000..cc12551f --- /dev/null +++ b/lanes/av1422l.report.md @@ -0,0 +1,99 @@ +# lane-av1-422l — inter-strip pairing underflow fixed; the rect-set refusal is real and names (4, 32), which libaom marks invalid — no row added, refusal stays + +## Outcome + +Two results. + +1. The k report's frontier attribution was measured under a release build: +`at_mi.0 - 1` subtract-overflow WRAPPED silently there, so decode continued +to `rect_inter_chroma_set`. A debug build panics first — the true first stop +at 8e7238b2 was a hard underflow panic in the inter-strip chroma pairing +(`decode.rs` ~41531:42 horz `at_mi.0 - 1`, then ~41544:55 vert +`at_mi.1 - 1`), hit because `strip_has_chroma`'s `|| ss_y(fctx) == 0` +clause makes every strip chroma-bearing at 4:2:2 including strip i = 0 at +mi row/col 0. Fixed in its own commit (below); 4:2:0 and 4:4:4 are +byte-identical by construction. +2. After the fix the frontier is exactly the refusal the k report named: +`rect_inter_chroma_set` fires with (w, h) = **(4, 32)** — the 4:2:2 plane +residual of an 8x32 luma block. libaom itself marks that size invalid, so +per the lane charter NO table row is invented and the refusal stays. + +## Fix 1 (own commit): strip pairing keys on the strip's own subsampled axis + +`decode_inter_frame_tile_with_cdfs`'s 1:4 strip walk +(`PARTITION_HORZ_4`/`VERT_4`, 16x4 / 4x16 strips): + +- `strip_has_chroma`: horz keeps `i % 2 == 1 || ss_y == 0` (no chroma row + parity at ss_y == 0 — every 16x4 strip is its own reference, mirroring the + intra strip arm's `else if ss_y(fctx) == 0` at the 14700s key-frame path); + vert becomes `i % 2 == 1 || ss_x == 0` (column parity governs, 4:4:4 keeps + self-paired strips, 4:2:2 keeps the proven 4:2:0 column pairing, and an odd + strip's left neighbour always exists so `at_mi.1 - 1` cannot underflow). +- `pair_mi`: self when the strip's pair axis is not subsampled (horz && + ss_y == 0, or vert && ss_x == 0), otherwise the existing pair merge. +- `prev`: pair motion only when the strip actually pairs (horz && ss_y == 1, + vert && ss_x == 1); self-coded chroma predicts from its own motion. + +Format-by-format equivalence to the pre-lane code: 4:2:0 horz/vert and +4:4:4 horz/vert produce identical `has_chroma`/`pair_mi`/`prev` in every +branch; only 4:2:2 changes (horz self-pairs, vert pairs as at 4:2:0). + +Fail-before witness: HEAD 8e7238b2 + env-gated header bypass panics +`attempt to subtract with overflow` at the two lines above under +`EC_AV1_ALLOW_422_PROBE=1`; after the fix the same run reaches the named +refusal. Fail-after does not apply (this is a panic, not a test). + +## Fix 2: the refusing shape, named — and why no row is added + +`EC_AV1_TRACE_422` at the `_ =>` arm of `rect_inter_chroma_set` prints +`(w,h)=(4,32)` on `/tmp/t422.obu` (sha256 +`d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`, the k +report's fixture). 4x32 is the 4:2:2 plane residual of an 8x32 luma block +(write rect 8x32 -> `>> ss_x` = 4x32). Against the pinned oracle source +(`~/.cache/aom-oracle/src`): + +- `av1_ss_size_lookup[BLOCK_8X32][1][0] = BLOCK_INVALID` + (`av1/common/common_data.c:38`) — an 8x32 luma block HAS NO 4:2:2 plane + residual block. +- `TX_4X32`/`TX_32X4` do not exist: zero occurrences in + `av1/common/enums.h`; the largest 4-px-axis transform is `TX_4X16`. +- `max_txsize_rect_lookup[BLOCK_8X32] = TX_8X32` — libaom reaches that + chroma through luma-granular chunking, never as a standalone 4-px unit. + +So the ticket's escape hatch ("if libaom marks it invalid, stop and name +it") applies: adding a (4, 32) row would invent a size libaom never codes. +The owning lane's next step is modelling the 8x32-at-(1,0) chroma merge +(`get_vartx_max_txsize` / `decode_token_recon_block` chunking), not an +entropy set. The trace print stays (env-gated, `env_flag!`, zero-cost). + +## Verification + +- Counters on the probe run prove real 4:2:2 chroma units read before the + stop: `chroma422_square: 25`, `chroma422_rect: 100`, + `chroma422_sub8: 26`. +- Default refusal fires (bypass reverted): + `REFUSED: unsupported: AV1 decode_stream (a chroma format of 4:2:2 ...)`. +- 420 gates green under `EC_AV1_REQUIRE_AOMENC=1` + (target dir `~/.cache/cargo-target-av1422l`): + `a_non_420_subsampled_sequence_header_is_refused_by_name` + + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_ + pixel_exact`: 2 passed, 0 failed. +- `cargo check -p ec-av1`: 0 warnings. +- Header refusal NOT deleted (16-frame stream is not pixel-exact; it is + refused at the named (4, 32) stop). +- The k lane's intra-arm chroma prediction sizing is untouched. + +## Latent site named (not fixed, out of reach) + +`decode.rs` ~14107 (INTRABC 16x4/4x16 dense path) subtracts +`lmi.0 - 1` / `lmi.1 - 1` under `has_chroma` with no subsampled-axis key. +Unreachable at 4:2:2 today (the header refusal precedes any INTRABC +decode), so no test can exercise it; flagged for the INTRABC lane so the +pairing class lands there too when 4:2:2 INTRABC is chartered. + +## State + +- Commits on lane-av1-422l (no push): (1) strip-pairing fix, (2) the + (4, 32) trace print + this report. +- No table row added to `rect_inter_chroma_set`. The 4:2:0 group-tail + chroma SKIP arm was not touched. diff --git a/lanes/av1422m.report.md b/lanes/av1422m.report.md new file mode 100644 index 00000000..3124c007 --- /dev/null +++ b/lanes/av1422m.report.md @@ -0,0 +1,101 @@ +# lane-av1-422m — the (4, 32) refusal is replaced by libaom's TX_4X4 chunking for +# that one shape; the header refusal STAYS (the stream's next stop is a +# different class, the intra-in-inter 64x64 chroma (32, 64) panic) + +## Outcome + +1. `read_inter_rect_chroma` no longer refuses (4, 32): an 8x32 luma block's + 4:2:2 chroma plane now codes as EIGHT TX_4X4 chunks per plane, exactly the + chunking libaom's decoder performs for a plane whose `ss_size_lookup` entry + is BLOCK_INVALID. 4:2:0 and 4:4:4 are bit-identical by construction (the + arm gates on ss (1,0) AND write rect exactly (4, 32) — impossible at any + other format). +2. The header refusal is NOT deleted: with the chunking in, the 16-frame + stream decodes PAST the previously refusing block and stops at a NEW hole + owned by another lane — the intra-in-inter 64x64 chroma arm reads its whole + (32, 64) plane as ONE unit and trips the rect-coeff scratch bound. The + delete condition (16-frame pixel-exact vs aomdec) is unmet, so the refusal + stays. + +## The chunking mechanism (measured against the pinned oracle, `~/.cache/aom-oracle/src`) + +- `av1_ss_size_lookup[BLOCK_8X32][1][0] = BLOCK_INVALID` + (`av1/common/common_data.c:38`): an 8x32 luma block HAS no 4:2:2 plane + residual block; no TX_4X32 exists either. +- `decode_token_recon_block`'s inter residual loop + (`av1/decoder/decodeframe.c:1022`) still walks the plane in + `get_vartx_max_txsize` units. `get_vartx_max_txsize` + (`av1/common/blockd.h:1447`) does `max_txsize_rect_lookup[plane_bsize]` + with `plane_bsize == BLOCK_INVALID` — one element PAST the 22-entry table. + The oracle build is Release (`CMakeCache.txt`: `CMAKE_BUILD_TYPE=Release`, + asserts compiled out), and the table's adjacent neighbour in declaration + order is `vtx_tab`, whose first entry `DCT_1D = 0 = TX_4X4`. So the + chroma max tx size resolves to TX_4X4. +- `decode_reconstruct_tx` (`decodeframe.c:303`) NEVER recurses for chroma + (`if (tx_size == plane_tx_size || plane)`), so every chroma unit reads at + TX_4X4: the 4x32 plane codes as 8 stacked 4x4 coefficient units. +- Empirical proof the chunking matches the bitstream: the same fixture bytes + (sha256 `d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`) + stopped at the (4, 32) refusal before the change; after it, decode consumes + that block's chroma and reaches the LATER intra-arm panic below — entropy + stayed consistent across the chunked units. + +## The fix (scoped to the one shape) + +`read_inter_rect_chroma` (`decode.rs`): when ss is (1, 0) and the write rect +is exactly (4, 32), chunk into (4, 4) units — the existing multi-unit loop +then stamps per-unit chroma neighbour contexts, embeds into the square-stride +grid, and returns the per-unit list for the tail's re-stamp, unchanged. Each +unit reads `TxbSet::Chroma4` / `default_scan(4)` (the lane-av1-422j rows) and +inherits NO tx_type (`av1_get_tx_type` returns DCT_DCT for +`tx_size == TX_4X4`, blockd.h), so `inherit_tx_type` is `None` for these +units. + +Counter `CHROMA422_CHUNK_HITS` (+ `chroma422_chunk_hits()`, printed by +`decode_probe` as `chroma422_chunk:`): one hit per TX_4X4 chunk unit read; a +4:2:0/4:4:4 frame cannot increment it. On the current fixture the probe +panics at the later stop before `report()` prints, so the number is not yet +exercised on a full decode; the units demonstrably ran (frontier evidence +above). + +## Next stop named (NOT fixed — another shape, another lane's arm) + +`decode_inter_block`'s INTRA arm (lane-av1-422k's +`read_rect_chroma_unit` call, `decode.rs`:35166/35208) codes a 64x64 intra +block's 4:2:2 chroma plane as ONE (32, 64) unit with `TxbSet::Chroma32`: + +``` +thread 'main' panicked at crates/ec-av1/src/decode.rs:7195:9: +rect coeff scratch w=32 h=64 n=2448 +``` + +libaom chunks that plane too: the intra residual walk +(`read_coeffs_and_intra`, decodeframe.c) steps `av1_get_tx_size` units, and +`av1_get_max_uv_txsize(BLOCK_64X64, 1, 0)` = +`av1_get_adjusted_tx_size(TX_32X64)` = **TX_32X32** (`blockd.h:1361`), i.e. +two 32x32 units per plane. Lifting it means re-plumbing the k lane's +whole-plane arm into a per-unit walk (set rows, per-unit `around_mi_422_chroma` +contexts, restamp) — that is the intra 4:2:2 chroma lane's territory, and the +(4, 32) inter shape this ticket owns is done. + +## Verification + +- `cargo check -p ec-av1 --all-targets` (target dir + `~/.cache/cargo-target-av1422m`): **0 warnings**. +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_ + pixel_exact`: 1 passed, 0 failed. +- Header refusal restored byte-identical after the probe bypass + (`stream.rs` refusal block untouched); default 4:2:2 refusal fires as + before. +- Oracle decode reference for the fixture: `$HOME/.cache/aom-oracle/build/ + aomdec` → 16 shown frames (I422 y4m). +- Untouched: the 4:2:0 group-tail chroma SKIP arm, the k lane's + `read_rect_chroma_unit` arms, `rect_inter_chroma_set`'s tables (no new row; + the (4, 32) refusal arm stays for any FUTURE unchunked arrival). + +## State + +- Commit on lane-av1-422m (no push): the chunking + counter + probe print + + this report. +- No table row added. The header refusal stands. diff --git a/lanes/av1422n.report.md b/lanes/av1422n.report.md new file mode 100644 index 00000000..ad968aed --- /dev/null +++ b/lanes/av1422n.report.md @@ -0,0 +1,74 @@ +# lane-av1-422n — e24dc84b's (4, 32) chunk is corrected from eight TX_4X4 to +# FOUR TX_4X8 units; the header refusal STAYS (the stream is not pixel-exact +# and stops at the (2, 16) rect-pair chroma shape) + +## Outcome + +1. `read_inter_rect_chroma`'s invalid-ss-size arm now chunks the (4, 32) + 4:2:2 chroma plane of an 8x32 luma block into FOUR TX_4X8 units per plane + (a 1x4 grid: 4 wide, 8 tall each). The committed eight-TX_4X4 chunking + was wrong: reviewer FAIL on e24dc84b. `BLOCK_INVALID` is 255, and the + out-of-bounds byte `get_vartx_max_txsize` reads from + `max_txsize_rect_lookup` in the pinned Release oracle build is TX_4X8 — + not the "adjacent `vtx_tab[0]` = TX_4X4" the m report claimed. +2. The units KEEP a tx type: `av1_get_tx_type` (blockd.h) has no TX_4X4 + early-out, so the m lane's `inherit_tx_type = None` special case is gone. + The units derive the type from the block's luma type through + `reduce_inherited_chroma_tx_type` into the TX_4X8 ext-tx set, exactly + like every other rect unit on this path. `(4, 8)` resolves through the + existing `rect_inter_chroma_set` row `(8, 4) | (4, 8) => ChromaRect8x4`; + no table row was added, and the (4, 32) refusal arm below it stays. +3. The (32, 64) intra chroma edit made earlier this session was REVERTED + per instruction before the chunk fix; the intra arm is byte-identical to + e24dc84b. 4:2:0 paths untouched. + +## Counter (first real exercise of `CHROMA422_CHUNK_HITS`) + +With the header refusal temporarily bypassed (probe only, restored +byte-identical — see below), the fixture walks 32 TX_4X8 chunk units +(`CHROMA422_CHUNK_HITS`, instrumented per unit) before the next stop. The +m report's count never printed because the probe panicked first; with the +corrected chunking the units demonstrably run. + +## Frontier (NOT fixed — another shape, another lane's arm) + +`decode_rect4_16_strip`'s closed chroma-shape set (`decode.rs:14902`) has no +`(2, 16)` row: a 4x16 luma pair's 4:2:2 chroma plane arrives there and hits +the `unreachable!`. The probe decodes frame 1 and stops early in frame 2, +after the 32 TX_4X8 units. The (32, 64) intra scratch panic did NOT +reproduce on this walk — this stop precedes it. + +## Pixels — delete condition unmet, refusal STAYS + +- Frame 1 (keyframe): luma byte-exact vs `aomdec` (oracle: 16 shown I422 + frames); U/V diverge from chroma (23, 0) on — a pre-existing keyframe + 4:2:2 chroma gap present at e24dc84b too (frame 1 decodes through + `decode_block`, which neither `read_inter_rect_chroma` nor the intra arm + touches). +- Frames 2+ are not comparable (the frame-2 stop above). +- The 16-frame pixel-exact + counter delete condition is unmet, so the + header refusal stands untouched. + +## Verification + +- `cargo check -p ec-av1 --all-targets` (target dir + `~/.cache/cargo-target-av1422n`): **0 warnings**. +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_decodes_ + pixel_exact`: 1 passed, 0 failed. +- Probe bypass reverted: `git diff` after the run shows ONLY + `crates/ec-av1/src/decode.rs` (the chunk fix + comment rewrite); the + default 4:2:2 refusal fires as before (`REFUSED: unsupported: ... 4:2:2 + ...`). +- Oracle reference: `$HOME/.cache/aom-oracle/build/aomdec` on the fixture + (sha256 `d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`) + → 16 shown frames. +- Untouched: the (4, 32) refusal arm in `rect_inter_chroma_set`, the 4:2:0 + group-tail chroma SKIP arm, the k lane's `read_rect_chroma_unit` arms, + `decode_probe.rs` (byte-identical to e24dc84b). + +## State + +- Commit on lane-av1-422n (no push): the corrected chunking + this report. +- Next stop named for the owning lane: `decode_rect4_16_strip` chroma shape + `(2, 16)`. diff --git a/lanes/av1422o.report.md b/lanes/av1422o.report.md new file mode 100644 index 00000000..a27898ae --- /dev/null +++ b/lanes/av1422o.report.md @@ -0,0 +1,110 @@ +# lane-av1-422o — the (2, 16) stop is NAMED and dispositioned: libaom has no +# such transform; the odd strip is the chroma reference and codes the PAIR's +# (4, 16) as TWO TX_4X8 units per plane; the header refusal STAYS (the walk +# now stops in `decode_block_rect4`'s chroma shape set at 4x32) + +## Outcome + +1. Step 1 of the charter (print before adding): with the header refusal + temporarily bypassed (probe-only, restored byte-identical — see below), + the refusing shape printed as `(cw,ch)=(2,16) ss=(1,0)`. The walk's own + `(2, 16)` is the EVEN strip's own chroma — a shape libaom never codes. + The port does not chunk it; it is UNREACHABLE after the fix. +2. `decode_rect4_16`'s `has_chroma` is per axis now: a VERT 4x16 strip (1 mi + wide) keeps libaom `is_chroma_reference`'s column clause + `(mi_col & 1) || !(bw & 1) || !ss_x`, which with bw == 1 mi reduces to + `mi_col odd` at every ss_x == 1 format. The old `i % 2 == 1 || ss_y == 0` + marked even strips as chroma references at 4:2:2 — the source of the + phantom (2, 16). HORZ strips keep `i % 2 == 1 || ss_y == 0` (all four + strips are references at ss_y 0); 4:2:0 and 4:4:4 resolve to the exact + same flags as before in all four strip/format combinations. +3. `decode_rect4_16_strip`'s own-chroma arm is HORZ-only now; a VERT strip + falls through to the pair merge `((lmi.0, lmi.1 - 1), 8, 16)` — the + closing strip codes the pair's chroma at the pair's origin + (`setup_pred_plane`'s `mi_col -= 1` snap), giving (cw, ch) = (4, 16) at + ss(1,0). The old comment claiming "a conformant stream carries no such + leaf" is disproven by the fixture itself and is gone. +4. The (4, 16) at ss_x == 1 is CHUNKED the way the pinned oracle walks it + (`chroma422_pair16` arm): `ss_size_lookup[BLOCK_4X16][1][0]` is + BLOCK_INVALID (common_data.c row `{ { BLOCK_4X16, BLOCK_4X8 }, + { BLOCK_INVALID, BLOCK_4X8 } }`), so `av1_get_tx_size` reads + `max_txsize_rect_lookup[255]` — the out-of-bounds byte is TX_4X8 + (skill-measured, 0x05) and `av1_get_adjusted_tx_size` has no TX_4X8 + case. `decode_token_recon_block` then walks unit_width = + ROUND_POWER_OF_TWO(1, 1) = 1, unit_height = 4, stepr = + tx_size_high_unit[TX_4X8] = 2, stepc = 1: TWO TX_4X8 units per plane, + plane-major, the lower one predicted off the upper one's samples. The + skip arm walks the same two units (prediction runs per unit regardless + of `skip_txfm`). No coefficient-table row was added: the units ride the + existing `(4, 8) => ChromaRect8x4` entropy class via + `read_rect_chroma_unit`. +5. The chunk's `txb_skip_ctx` rides the same INVALID lookup: libaom + `get_txb_ctx_general`'s chroma branch picks the offset (7 vs 10) through + `num_pels_log2_lookup[plane_bsize] > num_pels_log2_lookup[BLOCK_4X8]` + with plane_bsize = 255. Measured, not guessed: the pinned Release + oracle's decodetxb.c code indexes the `num_pels_log2_lookup` copy at + vaddr `0xc0db70` (objdump: `cmpb $0xb,0xc0db70(%r15)` et al.), and the + byte at that offset + 255 is 255 → offset 10 → the port's + offset-7-first tables take `+3` (above + left + 3), the same shape the + square multi-unit walks already use. +6. No tx_type symbol: only y plane's is transmitted (decodetxb.c "only y + plane's tx_type is transmitted"); the intra chroma unit's type is + `intra_mode_to_tx_type(UV mode)` kept by the all-16 ext-tx set — exactly + `read_rect_chroma_unit`'s own default. CfL parameters are computed once + per block over the pair's luma (`are_parameters_computed`) and shared by + both units; the DC-pred cache is dead in this build (`use_dc_pred_cache` + never set true), so each unit predicts its own DC. + +## Counter (CHROMA422_RECT_HITS, instrumented per unit, temp print removed) + +The walk reads EIGHT chunk units — two pairs (mi (28, 44) and (32, 52)), +each plane-major: U unit row 0, U unit row 1, then V units — mi rows 2 +apart (8 px) — and the counter ticks 100 → 101 → … → 107 across them +(`chroma422_rect=107` on the last line). Delta 8 = 2 planes x 2 units x 2 +pairs. The pre-fix walk stops with the counter parked at 100. + +## Frontier (NOT fixed — another shape, another function) + +`decode_block_rect4`'s closed chroma-shape set has no `4x32` row: +`decode.rs:13550` panics `decode_block_rect4 chroma shape set is closed: +4x32` on the same probe walk after the (2, 16) fix. That function is the +VERT_4 pair reader one level up; it is NOT edited here — named for its +owning lane. + +## Pixels — delete condition unmet, refusal STAYS + +- Frame 1: no VERT_4 4:2:2 strip occurs before the old stop point, so + frame 1's decode is untouched by this diff; its luma stays byte-exact vs + `aomdec` and its U/V keep the pre-existing keyframe chroma gap from + chroma (23, 0) on (`decode_block`'s own gap, present at e24dc84b, not + this lane's function). +- The walk stops inside frame 2 at `decode_block_rect4`'s 4x32, so the + 16-frame pixel-exact + counter delete condition is unmet: the header + refusal stands untouched (verified below). + +## Verification + +- `cargo check -p ec-av1 --all-targets` (target dir + `~/.cache/cargo-target-av1422o`): **0 warnings**. +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: + `a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_whose_tx_split_ + decodes_pixel_exact`: 1 passed, 0 failed. +- Probe bypass reverted: `git diff` shows ONLY `crates/ec-av1/src/decode.rs` + (+144/−12); `stream.rs` is byte-identical and the probe without the + bypass prints `REFUSED: unsupported: AV1 decode_stream (a chroma format + of 4:2:2 ...)` as before. +- Oracle reference: `$HOME/.cache/aom-oracle/build/aomdec` on the fixture + (sha256 `d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`) + → 16 shown frames. +- Untouched: `read_inter_rect_chroma` (the four TX_4X8 (4, 32) chunk + stays), the 4:2:0 group-tail chroma SKIP arm, the k lane's + `read_rect_chroma_unit` (called, not edited), `decode_block_rect4` (the + new frontier), `decode_probe.rs`, the lossless arm (shape-generic + per-TX_4X4 walk already handles a (4, 16) pair). + +## State + +- Commit on lane-av1-422o (no push): the has_chroma parity fix, the horz + own-chroma arm, the chroma422_pair16 chunk arms, and this report. +- Next stop named for the owning lane: `decode_block_rect4` chroma shape + `4x32` (decode.rs:13550). diff --git a/lanes/av1422p.report.md b/lanes/av1422p.report.md new file mode 100644 index 00000000..eb09aca4 --- /dev/null +++ b/lanes/av1422p.report.md @@ -0,0 +1,119 @@ +# lane-av1-422p — the 4x32 chroma stop is NAMED and CHUNKED: libaom HAS the +# transform (the BLOCK_INVALID plane block reads max_txsize_rect_lookup[255] +# = TX_4X8 out of bounds), so `decode_block_rect4` walks FOUR TX_4X8 units per +# plane on the offset-10 skip rows; the whole 16-frame stream now decodes, the +# pixels are NOT exact, so the header refusal STAYS byte-identical + +## Outcome + +1. Step 1 of the charter (print before adding): with the header refusal + temporarily bypassed (probe-only, restored byte-identical), the stop + printed `EC_422P_STOP decode_block_rect4 chroma shape (4,32) luma=(8,32) + ss=(1,0)` — the portrait 1:4 leaf the av1422o report named as its + frontier, on the pinned fixture (sha256 `d3fa4beeb1309033e4a03f5ae5c4 + 31c8fa8386ba1ada088684710423c7938129`). +2. Measured, not guessed: `av1_get_tx_size` reads + `max_txsize_rect_lookup[plane_bsize]` with plane_bsize = + `ss_size_lookup[BLOCK_8X32][1][0]` = BLOCK_INVALID (255, `enums.h`). The + byte at +255 of the copy `decode_token_recon_block` actually reads + (objdump: every `movzbl 0xc0d030(%r*)` in that function) is `0x05` = + TX_4X8; `av1_get_adjusted_tx_size` has no TX_4X8 case. The decodetxb copy + of `num_pels_log2_lookup` (the `cmpb` against `0xc0db70(%r15)`, symbol at + 0xc0de70) reads `0xff` at +255, so `get_txb_ctx_general`'s chroma branch + (`txb_common.h`: `num_pels_log2_lookup[255] > num_pels_log2_lookup + [BLOCK_4X8]`) takes the offset-10 arm. Both bytes re-measured on the + pinned Release oracle this session. +3. The chunk (libaom `decode_token_recon_block` semantics: stepr = + `tx_size_high_unit[TX_4X8]` = 2 4-px rows, stepc = 1, unit_width/height + ROUND_POWER_OF_TWO down to (1, 4)): FOUR stacked TX_4X8 units per plane + (chroma rows 0, 8, 16, 24), plane-major, riding the existing + `(4, 8) => ChromaRect8x4` entropy class via [`read_rect_chroma_unit`] — + no coefficient-table row added (BLOCK_4X32 is not a table libaom has). + Each unit is read and recorded immediately: unit row 0's txb_skip_ctx + sees the real neighbour states, lower units see the block's own upper + unit's, and each unit predicts off the upper one's samples. The skip arm + walks the same units (`predict_and_reconstruct_intra_block` predicts + every unit regardless of `skip_txfm`). CfL parameters are computed once + per block over the strip's 8x32 luma and shared by all units. Luma is + the same single TX_8X32 rect the general arm reads. +4. The chunk units' `txb_skip_ctx` is `above + left + 10` + (`get_txb_ctx_general`): the port's offset-7-first `txb_skip_chroma_8` + stores the offset-10 rows at rows 3..6 (lane-av1-422b), so + [`read_rect_chroma_unit`] gained a `chroma_skip_offset: Option` + parameter (mirroring [`read_plane`]'s `chroma_ctx_offset`) and this arm + passes `Some(3)`. Every existing caller passes `None` = + behavior-identical (their rect unit IS the whole plane block, offset-7 + rows); the whole-rect read never sees the new `(4, 32)` match row. +5. 4:2:0 and 4:4:4 are on their existing paths: the chunk is gated on + `(chroma_w, chroma_h) == (4, 32)` at ss(1,0), which only an 8x32 luma + strip at 4:2:2 produces (4:2:0 reads (4, 16), 4:4:4 reads (8, 32)); the + stale "portrait leaves are unreachable / a conformant stream cannot + carry that leaf size" comment is disproven by the fixture and replaced. + +## Counter (probe, bypass env; temp print removed) + +- `rect4_32: vert=1 coded=1` — exactly one 8x32 rect4 strip in the stream, + the block that used to stop. +- Eight unit reads at mi=(24,52), plane-major (U rows 0..3, V rows 0..3), + the temp trace printing skip_ctx 3/4/5 — i.e. the offset-10 rows + (base 0..2 + 3) — and varying unit-to-unit as the block's own upper + units enter the context. +- `chroma422_rect: 172` total rect 422 chroma units across the 16 decoded + frames (CHROMA422_RECT_HITS, ticked inside [`read_rect_chroma_unit`]). +- Pre-fix walk: panics at the stop before any report; post-fix probe prints + `OK: 16 frames decoded, 256x144`. + +## Pixels — delete condition UNMET, refusal STAYS + +- Frame 0 (keyframe): luma byte-EXACT vs `aomdec --rawvideo`; U/V carry + 4491/4888 sample diffs from offset ~23 — the PRE-EXISTING keyframe chroma + gap in [`decode_rect_split`] (the live `EC_RECTCHROMA_GAP luma=16x8 + tx=8x8 chroma=8x8` diagnostics, ×21 plus one 64x32; present at e24dc84b + per the av1422o report, not this lane's function). +- Frames 1..15 diverge widely (luma included), consistent with an entropy + divergence somewhere in the inter walk — this is the first time the + stream decodes past the old stop, so there is no earlier full-stream + baseline to diff against. +- Frontier (NOT fixed — larger than this one shape; named per charter): + 1. **`decode_rect4_16_strip`'s `chroma422_pair16` chunk passes no chroma + skip offset** — it reads the offset-7 rows (txb_skip rows 0..3) where + the same measured rule (plane_bsize BLOCK_INVALID for the pair's + BLOCK_4X16 too) demands offset 10, i.e. `Some(3)`. That function is + the protected av1422o lane fix, so this lane only plumbed `None` + through the new parameter (behavior-identical) and names the defect + for its owning lane. It runs in frame 2 before the 4x32, making it + the prime suspect for the inter-frame divergence. + 2. [`decode_rect_split`]'s own-chroma gap (the EC_RECTCHROMA_GAP class + above). + 3. Our dump carries out-of-range u16 samples on frames 1 (2 samples) and + 14 (6 samples) — an unclipped-output class, unattributed. +- The header refusal stands untouched: `git diff` shows ONLY + `crates/ec-av1/src/decode.rs` (+255/−40); `stream.rs` is byte-identical + and the probe without the bypass prints `REFUSED: unsupported: AV1 + decode_stream (a chroma format of 4:2:2 ...)` as before. + +## Verification + +- `cargo check -p ec-av1 --all-targets` (target dir + `~/.cache/cargo-target-av1422p`): **0 warnings, 0 errors**. +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: + `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact`: 1 passed, 0 failed ("6 pixel-exact + matches, 0 named refusals"). +- Oracle reference: `$HOME/.cache/aom-oracle/build/aomdec` on the fixture → + 16 frames raw 4:2:2, per-frame per-plane diffed against `dump_yuv`. +- Untouched: `decode_rect4_16_strip` (mechanical `None` arg only, no + behavioral edit), `read_inter_rect_chroma` (the four TX_4X8 (4, 32) inter + chunk stays), the 4:2:0 group-tail chroma SKIP arm, `decode_probe.rs`, + the lossless arm (depth != 0 || lossless returns before the chroma + table), the landscape (16,8)/(8,4) arms, and every existing + [`read_rect_chroma_unit`] caller's decode behavior. + +## State + +- Commit on lane-av1-422p (no push): the chroma_skip_offset parameter, the + 4x32 chunk arms (skip and non-skip), the corrected portrait-leaf comment, + and this report. +- Next stop named for the owning lane: the `chroma422_pair16` offset-10 + skip rows in `decode_rect4_16_strip`, then the inter-frame walk's first + divergence against the oracle. diff --git a/lanes/av1422q.report.md b/lanes/av1422q.report.md new file mode 100644 index 00000000..dca998f1 --- /dev/null +++ b/lanes/av1422q.report.md @@ -0,0 +1,42 @@ +# lane-av1-422q — the av1422p frontier's prime suspect APPLIED: the +# `chroma422_pair16` chunk passes `Some(3)` (the offset-10 skip rows), the +# 4x32 arm and every other caller untouched, the header refusal STAYS + +## Outcome + +1. The one-argument change, nothing else: `decode_rect4_16_strip`'s + `chroma422_pair16` arm now passes `Some(3)` to [`read_rect_chroma_unit`]'s + `chroma_skip_offset` (was `None`). Same measured rule as the 4x32 arm: + the pair's plane_bsize is `ss_size_lookup[BLOCK_4X16][1][0]` = + BLOCK_INVALID too, and the decodetxb copy of `num_pels_log2_lookup` reads + `0xff` at +255 (0xc0de70), so libaom's `get_txb_ctx_general` takes the + offset-10 arm; the port's offset-7-first `txb_skip_chroma_8` holds those + rows at 3..6. The stale lane-av1-422p `None` comment (which claimed the + offset-10 question was still open) is replaced by the measured rule. +2. Untouched, byte-identical: the 4x32 arm's existing `Some(3)`, every other + [`read_rect_chroma_unit`] caller (`None`), the 4:2:0 group-tail chroma + SKIP arm, `decode_probe.rs`, `stream.rs`, and the 4:2:2 header refusal + (the charter's delete condition — 16-frame pixel-exact + a 422-unit + counter — was not claimed this session, so nothing was deleted). + +## Verification + +- `git diff`: ONLY `crates/ec-av1/src/decode.rs` — one argument + (`None` -> `Some(3)`) plus its comment (+7/−5 lines). +- `cargo check -p ec-av1` (target dir `~/.cache/cargo-target-av1422q`): + **0 warnings, 0 errors**. +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: + `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact`: 1 passed, 0 failed. +- Not exercised this session (honest gaps): the 16-frame 4:2:2 stream was + NOT re-decoded and no pixel comparison was run — this lane's scope was the + single argument; whether the offset-10 rows fix the inter-frame + divergence is the next lane's diff. + +## State + +- Commit on lane-av1-422q (no push): the `Some(3)` argument, the corrected + comment, and this report. +- Next stop named for the owning lane: re-run the 16-frame probe/bypass with + counters and diff frames 1..15 against the aomdec oracle — the av1422p + report named this arm the prime suspect for the inter-frame divergence. diff --git a/lanes/av1422r.report.md b/lanes/av1422r.report.md new file mode 100644 index 00000000..60566a39 --- /dev/null +++ b/lanes/av1422r.report.md @@ -0,0 +1,76 @@ +# lane-av1-422r — REMEASURE after the q `Some(3)`: the first remaining diff is +# STILL frame 0 plane U (0, 23) ours=50 vs oracle=49 — first of the 4491-sample +# `decode_rect_split` own-chroma keyframe gap, NOT one wrong index — the +# inter-frame divergence PERSISTS (frames 1..8 differ from (0,0)), and the walk +# now PANICS at frame 9 in [`read_coeffs_rect`] (rect coeff scratch 36×36 < +# the 4:2:2 TX_32X64 chroma unit's 36×68). Stopped and named per charter. + +## Outcome + +1. Remeasured the pinned fixture (sha256 `d3fa4beeb1309033e4a03f5ae5c431c8fa + 8386ba1ada088684710423c7938129`) at 03be6bad against + `$HOME/.cache/aom-oracle/build/aomdec --rawvideo` (16 frames, i422), probe + dump `EC_PROBE_OUT16`, local `EC_AV1_ALLOW_422_PROBE` bypass, reverted + byte-identical after (`git status` clean before the report commit). Do not + trust the p-report diff numbers blindly: re-derived per-frame per-plane + first diffs from the raw dumps this session. +2. **The first remaining diff: frame 0, plane U, row 0, col 23, ours=50, + oracle=49.** Frame 0 luma is byte-exact; frame 0 carries 4491 U + 4888 V + diffs — the counts are byte-IDENTICAL to the pre-fix p-report measurement, + as expected: frame 0 is the keyframe and the pair16/4x32 arms never run + there. The class is [`decode_rect_split`]'s own-chroma gap (the live + `EC_RECTCHROMA_GAP luma=16x8 tx=8x8 chroma=8x8` diagnostics). 4491 samples + is not one wrong index → charter step 3: STOP and name the function: + **`decode_rect_split`** (own-chroma reconstruction at ss(1,0)). +3. **The offset suspect is refuted for the inter-frame divergence**: frames + 1..8 diverge from sample (0,0) in all three planes (frame 1: Y (0,0) + ours=78 oracle=80, U (0,0) 230 vs 87, V (0,0) 165 vs 245; plane totals + over 9 frames Y=258976, U=125891, V=124050). The q lane's `Some(3)` did + not sync the inter walk. Note the U/V frame-1 offsets are consistent with + MC inheritance of the already-wrong frame-0 chroma; the Y divergence + (frame 0 Y exact) is a separate inter-path question that cannot be + localized while chroma inherits the frame-0 gap. +4. **New hard stop, frame 9**: `read_coeffs_rect` panics + `rect coeff scratch w=32 h=64 n=2448` (decode.rs:7129, panic at :7195). + The scratch bound `n <= 36*36` covers ≤32×32 units; a 64×64 luma block at + ss(1,0) has plane_bsize `ss_size_lookup[BLOCK_64X64][1][0]` = BLOCK_32X64 + (NOT invalid — unlike the p/q chunks), `max_txsize_rect_lookup` reads + TX_32X64, and (32+4)×(64+4) = 2448 exceeds the bound. Frames 9..15 are + unmeasurable until this is lifted. This shape never fired pre-fix because + the unsynced walk never reached it. +5. 4 u16 samples out of 8-bit range across frames 0..8 (the p report's + unclipped-output class, still unattributed; was 2+6 over 16 frames). + +## Decision + +- First diff is a 4491-sample class → no one-index fix exists; stopped per + charter. Functions named: [`decode_rect_split`] (owns the first diff) and + [`read_coeffs_rect`] (scratch capacity, blocks frames 9+). +- Header refusal STAYS: delete condition unmet (not pixel-exact — frame 0 + alone carries 9379 chroma diffs; no full-stream proof possible with the + frame-9 panic). `stream.rs` untouched; the bypass was local-only and is + not in the commit. + +## Verification + +- Ours: 9 complete frames dumped before the panic (147456 B/frame u16); + oracle: 16 frames i422. Stride-checked comparison (u16 elements vs bytes — + the first compare script had a byte/element stride bug; frame 0's numbers + were unaffected and frames 1..8 were re-derived at the correct stride). +- `cargo check -p ec-av1` (target `~/.cache/cargo-target-av1422r`): 0 + warnings, 0 errors. +- 420 gate green under `EC_AV1_REQUIRE_AOMENC=1`: + `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact`: 1 passed, 0 failed. +- `git status` clean after bypass revert; this commit carries ONLY this + report. + +## State + +- Commit on lane-av1-422r (no push): this report, nothing else. +- Next stop named for the owning lane: lift [`read_coeffs_rect`]'s scratch + bound for TX_32X64 (36×68 levels — likely a heap fallback like + [`read_coeffs`]'s, or a 68-row stack tier), re-run the 16-frame remeasure, + THEN take the frame 1 luma (0,0) inter divergence with frame-0 chroma + inheritance accounted for; [`decode_rect_split`]'s own-chroma gap remains + the owner of the literal first diff. diff --git a/lanes/av1422sub8rect.report.md b/lanes/av1422sub8rect.report.md new file mode 100644 index 00000000..0db02444 --- /dev/null +++ b/lanes/av1422sub8rect.report.md @@ -0,0 +1,185 @@ +# lane-av1-422sub8rect — the sub-8x8 inter 4:2:2 chroma ported to its real +# shapes (`decode_inter_block8`'s whole chroma half to the BLOCK_4X8 rect; +# `decode_inter_sub8_split4`'s group unit replaced by the per-piece +# odd-column chroma-reference model the oracle traces actually code); frame +# 0 stays byte-exact at all four stages, the 4:2:0/4:4:4 identity holds by +# ss-keying, and the inter-frame divergence is REMEASURED (reduced ~15% on +# frames 1..10, exactness NOT claimed -- other 4:2:2 classes remain) + +## Outcome + +1. ROOT-CAUSE CONFIRMATION FIRST (pinned fixture `/tmp/t422.obu` sha256 + `d3fa4beeb1309033e4a03f5ae5c431c8fa8386ba1ada088684710423c7938129`, + parent-lane instruments in `/tmp/i422/`, local `EC_AV1_ALLOW_422_PROBE` + bypass applied and reverted byte-identical after — `git diff` carries + only decode.rs/mc.rs/encode.rs changes): the oracle's frame-1 first + block (`AOMMB mi=(0,0) ... skip=0`) reads luma TX_8X8 then + `plane=1 tx_size=5 mi_row=0 mi_col=0 rng=55168` — tx_size 5 IS TX_4X8, + confirming the charter: the 8x8 inter leaf's chroma plane block is + BLOCK_4X8, one TX_4X8 rect unit per plane (`ss_size_lookup[BLOCK_8X8][1][0]`), + while ours read a TX_4X4 square. +2. SPLIT4 MODEL CORRECTED AGAINST THE ORACLE, NOT THE CHARTER'S GUESS: the + parent report assumed the split4 group codes ONE rect group unit; the + traces prove otherwise. At ss (1,0) `is_chroma_reference` for a BLOCK_4X4 + piece is `(mi_col & 0x01)` — ODD columns only (av1_common_int.h:1459) — + and every non-skipped odd-column piece codes its OWN U then V TX_4X4 + square unit right after its luma, anchored at the FLOORED chroma cell + (`(mi_col & !1) * MI >> ss_x`, the lane-av1-422kf2 rule) with + `around_mi_422_chroma`-style per-chroma-cell ctx (measured ctx 8 = + above+left+7 at frame 1's mi(12,3)): + - frame 0 key-frame groups (18,54) and (30,42): U+V read on BOTH + odd-column leaves ((18,55)+(19,55), (30,43)+(31,43)); + - frame 1 inter group at mi(12,2): U+V on leaf (12,3) ALONE — its + bottom-right twin was skipped, so it codes nothing. + The 4:2:0 shared group unit simply never exists at 4:2:2. +3. PORT (all keyed on ss, 4:2:0/4:4:4 byte-identical by construction): + - `decode_inter_block8` chroma half to per-axis shapes: `chroma_w/chroma_h`, + `(TxbSet::ChromaRect8x4, SCAN_4X8)` at 4:2:2; inter coefficient reads + through `read_inter_plane_rect` (offset-7 ctx — the unit IS the plane + block — inherited luma tx type) with `around_mi_422_chroma`; MC + prediction (single-ref, scaled, warp, compound-intermediate), the + wedge-masked blend, interintra blend, OBMC pushes and skip pushes all + (4, 8)-shaped; the intra-in-inter arm reads the key-frame arm's own + rect reader (`read_rect_chroma_unit`, ctx offset None, CfL carried); + palette UV map dims per axis. + - `decode_inter_sub8_split4`: per-piece arm added after each inter + piece's luma (odd column, ss 1,0): prediction as + `build_inter_predictors_sub8x8` — left 2x4 half from the LEFT piece's + own ref/mv/filters, right 2x4 half from this piece's; a mixed group + (left piece intra/off-frame, `is_sub8x8_inter` false) predicts the + whole 4x4 from this piece; skip pieces still predict but record zeros. + Coefficients via square `TxbSet::Chroma4` reads at the floored anchor, + per-unit `record_mi_chroma` (8x4 luma span). Intra pieces gate + `has_chroma` on the piece's own column parity and route through + [`sub8_leaf_chroma422`]; even-column intra pieces publish DC to the + uv-mode map. The 4:2:0 group tail (build, read, band stamps, DC map + stamp) is gated OFF at 4:2:2. + - Shared helpers made ss-exact (4:2:0/4:4:4 reduce to the old behaviour): + `blend_masked_compound`'s `subsampled: bool` → per-axis `(subw, subh)` + mirroring aom_dsp/blend-a64-mask.c's four branches; `interintra_blend`'s + wedge mask read likewise; `obmc_plan`/`obmc_run` take the plane ss — + chroma extents are the luma rules `>> ss` (`av1_skip_u4x4_pred_in_obmc` + keyed on the plane block, above-pass skip and left-pass blend extents), + `TxParams::strided` sized `stride * h` (identical when h == stride, as + every pre-existing caller has). The encoder's `obmc_plan` call passes + the fctx ss. + - STOP-NOTE (owning parent-lane surface, named not fixed): + `decode_inter_block`'s 4:2:2 chroma is still the square-cut model; its + chroma masked-blend keeps the pre-port direct mask read there (guarded + by `ss_x == ss_y`), because its `chroma_side`-square buffers cannot be + indexed by the subsampled-axis walks. Known-divergent, unchanged + behaviour, named for the owning lane. +4. MEASURED after the port (17-frame probe run under the reverted bypass; + comparator: ours padded 256x160/128x160 u8 cropped vs the instrumented + `$HOME/.cache/aom-oracle/build` aomdec; NOTE the probe prints REFUSED and + still exits 0 -- the committed tree stops at frame 11 with the + pre-existing "HORZ/VERT strip ... no rect coefficient tables" frontier + refusal, exactly like the reworked tree): + - frame 0: **byte-exact at PREFILT, POSTCDEF (and FINAL by the u16 + comparator) on Y, U and V — 0 diffs everywhere**, so the rect read, + the split4 per-piece model and every shared-helper change are exact on + everything frame 0 exercises (including the split groups (18,54), + (30,42) that motivated the per-piece model). + - inter frames 1..10 decode and were measured: PREFILT diffs dropped + ~15% vs the parent lane's ladder (e.g. frame 1: 30825/12624/12796 → + 22248/11733/11974; frame 8: 35014/11020/12043 → 32855/11020/12043; + per-frame values in `/tmp/i422/sub8rect/`). **Frame exactness is NOT + claimed** — frames 1..10 remain divergent: the named sub-8 sites are + fixed, but the stream carries further 4:2:2 classes the decoder still + square-cuts or gaps (probe trace: `EC_RECTCHROMA_GAP luma=16x8 + tx=16x8 chroma=8x8`, `luma=8x32 ... chroma=4x32`, i.e. `decode_inter_block`'s + own 4:2:2 chroma half), so the entropy walk desyncs again after the + first uncoded-for block. + - frames 11..16 were not reached by the probe's frame accounting this + round (11 dumped frames, decode exits 0 — the dump-index vs + show-existing accounting needs the parent-lane harness's + 1-frame-per-OBU walk); the ladder for 1..16 is the owning lane's + re-measurement once the next class lands. +5. Deferred items: (a) frames 11..16 ladder entries — unblock: rerun the + parent-lane per-OBU cut harness (`/tmp/i422/cut_frames.py`) after the + next class; (b) `decode_inter_sub8_rect2`'s 4:2:2 has_chroma gating (its + inter strips pass `i == 1` where BLOCK_4X8 needs odd-column parity) — + not one of this charter's named sites, unmeasured on the fixture so far. + +## Decision + +- The header refusal STAYS unconditional in `stream.rs`; the bypass was + local-only, applied and reverted byte-identical (0 occurrences left; + `stream::tests` green after the revert). +- 4:2:0/4:4:4 untouched by construction (ss-keyed arms); the 4:2:0 + group-tail SKIP arm untouched; `read_coeffs_rect` untouched. + +## Review rework (r2, post-review findings 1-3) + +The review correctly rejected two byte-identity claims and one +justification: + +1. **444 OBMC behaviour now UNCHANGED from the parent.** The first commit + made `obmc_plan`/`obmc_run` ss-exact (`av1_skip_u4x4_pred_in_obmc` + keyed on the plane block; chroma extents `>> ss`), which is what + reconinter.c does -- but it CHANGES 4:4:4 behaviour (the above-pass + chroma skip flips to run on square plane blocks, the blend extents + double) and is NOT byte-identical, with no 444 OBMC gate covering it. + Measured before reworking: fixture `/tmp/obmc444/obmc444.obu` sha256 + `4b5c0a473c7ca5bd460e76bb5d7fde541dc996bec45f60bfcc393eb2f11731ef` + (10-frame 128x96 4:4:4 aomenc `--enable-obmc=1 --profile=1`, 2 rect + OBMC leaves firing per the probe census), decoded parent (4e8c6073) + vs tip vs instrumented aomdec: parent and tip read IDENTICAL symbols + and differ in exactly ONE V sample (f1, (82,80)): oracle 110 == + parent, tip 111. Attribution by single-change revert builds: reverting + `TxParams::strided` alone (varB) reproduces tip exactly; reverting the + OBMC ss semantics alone (varA) reproduces the parent exactly -- so the + whole parent<->tip delta is the OBMC change, and on this fixture the + conformant variant is one sample FARTHER from aomdec, never closer. + Per the review protocol ("if worse, rework") the OBMC ss semantics are + REVERTED to the parent's 4:2:0-shaped corner-cut (luma-keyed + `skip_chroma_above`, half chroma blend extents); the 444-conformant + port stays deferred to the owning 444 lane, which can measure it on + OBMC-heavy 444 content once that lane's reconstruction class is exact + enough to gate on. `encode.rs` carries no change any more (the ss + argument is gone with the parameter). +2. **`TxParams::strided` justification corrected.** The commit text + claimed "every pre-existing caller has h == stride" -- wrong: + `read_inter_plane_rect` callers pass rect units with `h < stride` + (e.g. an 8x4 unit in an 8x8-strided plane buffer), and for those the + scratch shrinks from `stride*stride` to `stride*h`. Output identity + holds because the copy loop only ever writes `h` rows of `w <= stride` + and every consumer reads the residual through the same dense bounds -- + verified empirically (the 4:2:0 pixel-exact witness, 4:4:4 frame + equality with the parent on the obmc444 fixture, and the varB + revert experiment), not by the removed claim. The `stride * h` sizing + itself STAYS: the 4:2:2 leaf's TX_4X8 unit (stride 4, h 8) panics on + the old square sizing. +3. The t422 measurement note above also corrects the probe's exit-status + reading (REFUSED still exits 0; both the committed and reworked trees + stop at frame 11 on the pre-existing strip-chroma frontier refusal). + +Everything else in Outcome 3 (the leaf8 rect port, the split4 per-piece +model, the ss-keyed masked/interintra blends) is untouched by the rework; +frame 0 re-verified byte-exact at PREFILT/POSTCDEF after it, and both +gates re-run green post-revert. + +## Verification + +- `cargo check -p ec-av1` (target `~/.cache/cargo-target-av1422sub8rect`): + 0 warnings, 0 errors. +- `stream::tests::a_non_420_subsampled_sequence_header_is_refused_by_name`: + 1 passed — the refusal fires after the bypass revert. +- `stream::tests::a_real_aomenc_stream_with_a_skipped_8x8_intra_leaf_ + whose_tx_split_decodes_pixel_exact` under `EC_AV1_REQUIRE_AOMENC=1` + (oracle aomenc): 1 passed — the 4:2:0 inter path, including the + shared-helper ss-ifications, stays pixel-exact. +- Frame-0 stage dumps vs the instrumented aomdec: PREFILT/POSTCDEF + Y=U=V=0 (POSTDEB comparator run this round used the wrong dump-env name; + the post-deblock state is bracketed by the two exact stages). +- Hit counter added: `CHROMA422_INTER_SUB8_HITS` (per-piece inter 4:2:2 + chroma units) — reads non-zero on the fixture's frames 1+, so the new arm + provably fires. + +## State + +- Commit on lane-av1-422sub8rect (no push): the sub-8 rect port + + `TxParams::strided` sizing fix + shared ss-exact helpers + this report. +- Probe instruments regenerated under `/tmp/i422/sub8rect/` (scratch, not + committed); the oracle build's rungs already cover everything needed to + re-measure after the next class. diff --git a/scripts/instrument-aom-oracle.sh b/scripts/instrument-aom-oracle.sh index ec513d84..fddc2b7a 100755 --- a/scripts/instrument-aom-oracle.sh +++ b/scripts/instrument-aom-oracle.sh @@ -40,6 +40,13 @@ # its superres margin (lane-superres r5: hand-tracing the arithmetic # could only prove our own self-consistency, not correctness against # libaom). +# EC_AV1_POSTCDEF_DUMP= -> .f per frame, same shape as +# the POSTDEBLOCK rung (full ALIGNED-buffer rows), written right after +# the CDEF pass and before superres/LR -- splits a final-output +# mismatch into "already in CDEF" vs "introduced by loop restoration" +# without the 16-bit-only DUMP16 rungs (lane-av1422filter: on the +# pinned 4:2:2 keyframe this named the 251/259-sample CDEF chroma +# defect whose first samples were the ticket's first final samples). # EC_TRACE_MODE_STEP=1 -> per-symbol range ladder inside # ec_read_intra_frame_mode_info_impl (rung 5's renamed body): # "EC_ISTEP mi_row=.. mi_col=.. name=skip val=.. rng=.." after @@ -832,3 +839,66 @@ s = s.replace(anchor, anchor + dump, 1) open(path, "w").write(s) print("decodemv rung 14 (per-entry EC_STACK) instrumented") PYST + +# --- rung 15: post-CDEF, pre-superres 8-bit row dump (lane-av1422filter) --- +# The 8-bit mirror of rung 6 one stage later: written right after the CDEF +# pass (the `if (do_cdef) {...}` block) and before superres/LR, so a final +# chroma/luma mismatch splits into "already in CDEF" vs "introduced by +# loop restoration". The *_DUMP16 family covers this stage only in 16-bit +# builds (its 8-bit run SEGFAULTS); this rung is the 8-bit one. lane- +# av1422filter added it to the live oracle tree by hand first, then it was +# transcribed here (class: instrument that lives only in a build tree). +python3 - "$F" <<'PYC' +import sys +path = sys.argv[1] +s = open(path).read() +if "EC_INSTRUMENTED_POSTCDEF" in s: + print("postcdef dump already instrumented (no-op)") + sys.exit(0) + +anchor = """ if (do_cdef) { + if (pbi->num_workers > 1) { + av1_cdef_frame_mt(cm, &pbi->dcb.xd, pbi->cdef_worker, + pbi->tile_workers, &pbi->cdef_sync, + pbi->num_workers, av1_cdef_init_fb_row_mt, + do_extend_border_mt); + } else { + av1_cdef_frame(&pbi->common.cur_frame->buf, cm, &pbi->dcb.xd, + av1_cdef_init_fb_row); + } + } +""" +dump = """ + /* EC_INSTRUMENTED_POSTCDEF (8-bit twin of the POSTDEBLOCK rung: + * full aligned buffer, post-CDEF pre-superres/LR) */ + { + const char *ec_dump = getenv("EC_AV1_POSTCDEF_DUMP"); + if (ec_dump) { + static int ec_postcdef_idx = 0; + char ec_path[1024]; + snprintf(ec_path, sizeof(ec_path), "%s.f%d", ec_dump, + ec_postcdef_idx++); + FILE *ec_f = fopen(ec_path, "wb"); + if (ec_f) { + const YV12_BUFFER_CONFIG *ec_b = &cm->cur_frame->buf; + for (int ec_r = 0; ec_r < ec_b->y_height; ++ec_r) + fwrite(ec_b->y_buffer + ec_r * ec_b->y_stride, 1, ec_b->y_width, + ec_f); + if (num_planes > 1) { + for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r) + fwrite(ec_b->u_buffer + ec_r * ec_b->uv_stride, 1, + ec_b->uv_width, ec_f); + for (int ec_r = 0; ec_r < ec_b->uv_height; ++ec_r) + fwrite(ec_b->v_buffer + ec_r * ec_b->uv_stride, 1, + ec_b->uv_width, ec_f); + } + fclose(ec_f); + } + } + } +""" +assert anchor in s, "do_cdef block anchor moved" +s = s.replace(anchor, anchor + dump, 1) +open(path, "w").write(s) +print("postcdef dump instrumented") +PYC