diff --git a/crates/ec-av1/examples/decode_probe.rs b/crates/ec-av1/examples/decode_probe.rs index ab64eea2..6111ef4f 100644 --- a/crates/ec-av1/examples/decode_probe.rs +++ b/crates/ec-av1/examples/decode_probe.rs @@ -36,6 +36,10 @@ 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() + ); 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 dda6b17d..45803b64 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1509,6 +1509,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 @@ -2002,8 +2032,9 @@ thread_local! { } /// Current value of [`CHROMA422_SQUARE_HITS`]. -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates -pub(crate) fn chroma422_square_hits() -> usize { +// 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()) } @@ -16648,6 +16679,24 @@ fn decode_block( _ => (TxbSet::Chroma4, scan4), }; (luma_set, set, luma_tx, tx, (scans.0, scan)) + } else if ss_x(fctx) == 1 && ss_y(fctx) == 0 { + // lane-av1-422b: 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 + // (`av1_get_adjusted_tx_size` only ever shrinks): 4 -> TX_4X4 (the + // 2x4 plane rounds up to BLOCK_4X4), 8 -> TX_4X4 (BLOCK_4X8), + // 16 -> TX_8X8 (BLOCK_8X16), 32 -> TX_16X16, 64 -> TX_32X32 + // (BLOCK_32X64), 128 -> TX_32X32 (BLOCK_64X128 adjusts TX_64X64 + // down). The units stay square; the UNIT GRID is (side/2)/tx wide + // by side/tx tall -- never square above a 4x4 luma block. + let tx = if side >= 64 { 32 } else { (side / 2).max(4) }; + let (set, scan): (TxbSet, &[u16]) = match tx { + 32 => (TxbSet::Chroma32, scan32), + 16 => (TxbSet::Chroma16, scan16), + 8 => (TxbSet::Chroma8, scan8), + _ => (TxbSet::Chroma4, scan4), + }; + (luma_set, set, luma_tx, tx, (scans.0, scan)) } else { (luma_set, chroma_set, luma_tx, chroma_tx, scans) }; @@ -16773,6 +16822,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 @@ -16787,17 +16839,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_y(fctx)), - chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut ub, 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_y(fctx)), - chroma_side, chroma_side, mc::InterpFilterKind::Bilinear, &mut vb, fctx, + chroma_side, chroma_height, mc::InterpFilterKind::Bilinear, &mut vb, fctx, ); (yb, ub, vb) }); @@ -16942,16 +16994,23 @@ 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 << ss_y` tall. + let cn_cols = (chroma_side / chroma_tx).max(1); + let cn_rows = (chroma_height / chroma_tx).max(1); + let luma_span_x = chroma_tx << ss_x(fctx); + let luma_span_y = chroma_tx << 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, ) }; @@ -17037,8 +17096,13 @@ 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. + let cn_cols = (chroma_side / chroma_tx).max(1); + let cn_rows = (chroma_height / chroma_tx).max(1); + let luma_span_x = chroma_tx << ss_x(fctx); + let luma_span_y = chroma_tx << ss_y(fctx); + let (u_grid, v_grid, chroma_units) = if cn_rows == 1 && cn_cols == 1 { if let Some((ub, _)) = &palette_uv_bufs { set_palette_pred(ub.clone(), fctx); } @@ -17099,24 +17163,25 @@ fn decode_block( } 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 = + 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, @@ -17146,16 +17211,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; @@ -17166,9 +17236,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 @@ -17178,7 +17248,10 @@ 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); + let cn_cols = (chroma_side / chroma_tx).max(1); + let cn_rows = (chroma_height / chroma_tx).max(1); + let luma_span_x = chroma_tx << ss_x(fctx); + let luma_span_y = chroma_tx << 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 @@ -17190,9 +17263,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 @@ -17218,7 +17292,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 @@ -17352,8 +17426,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 @@ -17384,20 +17458,21 @@ fn decode_block( 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 << ss_y` tall -- at 4:2:2 a rect twice as wide + // as it is tall). 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 = 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, ) }; @@ -17423,22 +17498,27 @@ fn decode_block( }), None, chroma_ctx_offset, smooth_neighbor_uv, fctx, )?; - if cn > 1 { + 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]; } @@ -17455,9 +17535,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 @@ -26319,7 +26399,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}"); } @@ -26395,7 +26481,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!( @@ -26481,7 +26573,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}", @@ -26805,8 +26903,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}" 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.