forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-txselect': inter TX_MODE_SELECT var-tx (txfm_split tree, TXFM_CTX_INIT=64, per-leaf residual), eob_pt class-1 rows above 8x8; gates 8/10-bit green (verifier PASS, 269/0/23); fmt-only churn dropped, main's uv_tx_grid chroma deblock kept

Browse files at this commit

4463654cc511f63da2a7b2f1012f50c2f3c03457Ahmet Kaan GümüşParent: f9e482f5ec0940
crates/ec-av1/src/cdf.rsmodified+82 -0
@@ -25,6 +25,33 @@ pub const PARTITION_W64: [[u16; 11]; 4] = [
25 25
26 /// `Default_Skip_Cdf` (spec 9.4): indexed by how many of the blocks above26 /// `Default_Skip_Cdf` (spec 9.4): indexed by how many of the blocks above
27 /// and left were skipped.27 /// and left were skipped.
28+/// `default_txfm_partition_cdf` (entropymode.c): an inter block's
29+/// `txfm_split` flag (spec 5.11.17 `read_var_tx_size`), indexed by
30+/// `txfm_partition_context` -- `category * 3 + above + left`, 21 contexts.
31+pub const TXFM_PARTITION: [[u16; 3]; 21] = [
32+ [28581, 32768, 0],
33+ [23846, 32768, 0],
34+ [20847, 32768, 0],
35+ [24315, 32768, 0],
36+ [18196, 32768, 0],
37+ [12133, 32768, 0],
38+ [18791, 32768, 0],
39+ [10887, 32768, 0],
40+ [11005, 32768, 0],
41+ [27179, 32768, 0],
42+ [20004, 32768, 0],
43+ [11281, 32768, 0],
44+ [26549, 32768, 0],
45+ [19308, 32768, 0],
46+ [14224, 32768, 0],
47+ [28015, 32768, 0],
48+ [21546, 32768, 0],
49+ [14400, 32768, 0],
50+ [28165, 32768, 0],
51+ [22401, 32768, 0],
52+ [16088, 32768, 0],
53+];
54+
28 pub const SKIP: [[u16; 3]; 3] = [[31671, 32768, 0], [16515, 32768, 0], [4576, 32768, 0]];55 pub const SKIP: [[u16; 3]; 3] = [[31671, 32768, 0], [16515, 32768, 0], [4576, 32768, 0]];
29 56
30 /// `Default_Intra_Frame_Y_Mode_Cdf` (spec 9.4): the thirteen luma intra57 /// `Default_Intra_Frame_Y_Mode_Cdf` (spec 9.4): the thirteen luma intra
@@ -1429,6 +1456,20 @@ pub const INTER_TX_TYPE_SET2_16: [u16; 13] = [
1429 770, 2421, 5225, 12907, 15819, 18927, 21561, 24089, 26595, 28526, 30529, 32768, 0,1456 770, 2421, 5225, 12907, 15819, 18927, 21561, 24089, 26595, 28526, 30529, 32768, 0,
1430 ];1457 ];
1431 1458
1459+/// `Default_Inter_Ext_Tx_Cdf`'s `TX_SET_INTER_1` (`EXT_TX_SET_ALL16`) row for
1460+/// `TX_4X4` (lane-txselect): the sixteen-symbol transform type of an
1461+/// `is_inter` 4x4 luma transform when `reduced_tx_set == 0` (libaom
1462+/// `entropymode.c` `default_inter_ext_tx_cdf[1][TX_4X4]`).
1463+pub const INTER_TX_TYPE_SET1_4: [u16; 17] = [
1464+ 4458, 5560, 7695, 9709, 13330, 14789, 17537, 20266, 21504, 22848, 23934, 25474, 27727, 28915,
1465+ 30631, 32768, 0,
1466+];
1467+
1468+/// `Default_Inter_Ext_Tx_Cdf`'s `TX_SET_INTER_3` (`EXT_TX_SET_DCT_IDTX`) row
1469+/// for `TX_4X4` (lane-txselect), the reduced two-symbol counterpart of
1470+/// [`INTER_TX_TYPE_SET1_4`] (`default_inter_ext_tx_cdf[3][TX_4X4]`).
1471+pub const INTER_TX_TYPE_SET3_4: [u16; 3] = [16384, 32768, 0];
1472+
1432 /// `Default_Inter_Ext_Tx_Cdf`'s `TX_SET_INTER_1` (`EXT_TX_SET_ALL16`) row for1473 /// `Default_Inter_Ext_Tx_Cdf`'s `TX_SET_INTER_1` (`EXT_TX_SET_ALL16`) row for
1433 /// `TX_8X8` (lane-cdffwd2): the full sixteen-symbol transform type of an1474 /// `TX_8X8` (lane-cdffwd2): the full sixteen-symbol transform type of an
1434 /// `is_inter` 8x8 luma transform when `reduced_tx_set == 0`1475 /// `is_inter` 8x8 luma transform when `reduced_tx_set == 0`
@@ -5044,3 +5085,44 @@ pub const INTRA_TX_TYPE_SET1_4: [[u16; 8]; 13] = [
5044 [277, 4369, 5255, 8905, 16465, 22271, 32768, 0],5085 [277, 4369, 5255, 8905, 16465, 22271, 32768, 0],
5045 [3409, 5436, 10599, 15599, 19687, 24040, 32768, 0],5086 [3409, 5436, 10599, 15599, 19687, 24040, 32768, 0],
5046 ];5087 ];
5088+
5089+/// The `TX_CLASS_HORIZ`/`TX_CLASS_VERT` siblings of [`EOB_PT_256_LUMA`],
5090+/// [`EOB_PT_256_CHROMA`], [`EOB_PT_64_CHROMA`] and [`EOB_PT_16_CHROMA`]
5091+/// (`av1_default_eob_multi{256,64,16}_cdfs[q][plane][1]`, `token_cdfs.h`) --
5092+/// lane-txselect r2: the class dimension libaom keeps on *every* eob_pt
5093+/// table. Only 4x4/8x8 luma carried it here, so the first `V_DCT`/`H_DCT`
5094+/// 16x16 luma TU (a var-tx leaf of a 32x32 inter block, `EXT_TX_SET_
5095+/// DTT9_IDTX_1DDCT`) read the 2D table and desynced at its `eob`. 32-point
5096+/// and larger transforms need no sibling: their tx sets (`DCT_IDTX`,
5097+/// `DCTONLY`) hold no 1D type.
5098+pub const EOB_PT_256_LUMA_CLASS1_Q0: [u16; 10] =
5099+ [998, 1850, 2998, 5604, 17341, 19888, 22899, 25583, 32768, 0];
5100+pub const EOB_PT_256_LUMA_CLASS1_Q1: [u16; 10] =
5101+ [399, 1019, 1749, 3038, 10444, 15546, 22739, 27294, 32768, 0];
5102+pub const EOB_PT_256_LUMA_CLASS1: [u16; 10] =
5103+ [1084, 2358, 3488, 5122, 11483, 18103, 26023, 29799, 32768, 0];
5104+pub const EOB_PT_256_LUMA_CLASS1_Q3: [u16; 10] =
5105+ [2453, 4474, 6307, 8777, 16474, 22975, 29000, 31547, 32768, 0];
5106+
5107+pub const EOB_PT_256_CHROMA_CLASS1_Q0: [u16; 10] =
5108+ [2203, 4130, 7435, 10739, 20652, 23681, 25609, 27261, 32768, 0];
5109+pub const EOB_PT_256_CHROMA_CLASS1_Q1: [u16; 10] =
5110+ [1674, 3252, 5734, 10159, 22397, 23802, 24821, 30940, 32768, 0];
5111+pub const EOB_PT_256_CHROMA_CLASS1: [u16; 10] =
5112+ [6571, 9610, 15516, 21826, 29092, 30829, 31842, 32708, 32768, 0];
5113+pub const EOB_PT_256_CHROMA_CLASS1_Q3: [u16; 10] =
5114+ [9998, 17661, 25178, 28097, 31308, 32038, 32403, 32695, 32768, 0];
5115+
5116+pub const EOB_PT_64_CHROMA_CLASS1_Q0: [u16; 8] =
5117+ [1563, 2700, 4876, 10911, 14706, 22480, 32768, 0];
5118+pub const EOB_PT_64_CHROMA_CLASS1_Q1: [u16; 8] =
5119+ [1923, 3127, 5867, 9703, 14277, 27100, 32768, 0];
5120+pub const EOB_PT_64_CHROMA_CLASS1: [u16; 8] =
5121+ [4034, 6290, 10235, 14982, 21214, 28491, 32768, 0];
5122+pub const EOB_PT_64_CHROMA_CLASS1_Q3: [u16; 8] =
5123+ [8726, 12378, 19409, 26450, 30038, 32462, 32768, 0];
5124+
5125+pub const EOB_PT_16_CHROMA_CLASS1_Q0: [u16; 6] = [1904, 3354, 7763, 14647, 32768, 0];
5126+pub const EOB_PT_16_CHROMA_CLASS1_Q1: [u16; 6] = [2497, 4096, 8866, 16993, 32768, 0];
5127+pub const EOB_PT_16_CHROMA_CLASS1: [u16; 6] = [3192, 5032, 10297, 19755, 32768, 0];
5128+pub const EOB_PT_16_CHROMA_CLASS1_Q3: [u16; 6] = [7297, 10767, 19273, 28194, 32768, 0];
crates/ec-av1/src/cdf_state.rsmodified+98 -6
@@ -71,6 +71,16 @@ pub(crate) enum TxbSet {
71 /// `is_inter` block has no writer path yet, so this crate has no71 /// `is_inter` block has no writer path yet, so this crate has no
72 /// `Luma4Inter` counterpart to [`Luma8Inter`](TxbSet::Luma8Inter).72 /// `Luma4Inter` counterpart to [`Luma8Inter`](TxbSet::Luma8Inter).
73 Luma4,73 Luma4,
74+ /// The 4x4 luma transform of an `is_inter` block whose `TxMode::Select`
75+ /// var-tx tree splits an 8x8 unit all the way down (lane-txselect): the
76+ /// same coefficient tables [`Luma4`](TxbSet::Luma4) reads (libaom's
77+ /// coefficient CDFs are keyed by plane type, not intra/inter), with the
78+ /// inter `tx_type` set in place of the intra one.
79+ Luma4Inter,
80+ /// [`Luma4Inter`](TxbSet::Luma4Inter)'s `reduced_tx_set: false`
81+ /// counterpart -- the sixteen-symbol `EXT_TX_SET_ALL16` table
82+ /// ([`crate::cdf::INTER_TX_TYPE_SET1_4`]).
83+ Luma4InterSet1,
74 /// [`Luma4`](TxbSet::Luma4)'s `reduced_tx_set: false` counterpart, same84 /// [`Luma4`](TxbSet::Luma4)'s `reduced_tx_set: false` counterpart, same
75 /// split as [`Luma8Set1`](TxbSet::Luma8Set1).85 /// split as [`Luma8Set1`](TxbSet::Luma8Set1).
76 Luma4Set1,86 Luma4Set1,
@@ -158,6 +168,10 @@ pub(crate) struct Cdfs {
158 /// The partition symbol of a 32x32 block.168 /// The partition symbol of a 32x32 block.
159 pub partition_w32: [[u16; 11]; 4],169 pub partition_w32: [[u16; 11]; 4],
160 /// Whether a block carries no residual at all.170 /// Whether a block carries no residual at all.
171+ /// `txfm_partition_cdf`: an inter block's `txfm_split` flag under
172+ /// `TxMode::Select` (lane-txselect, spec 5.11.17), indexed by
173+ /// `txfm_partition_context` -- see [`cdf::TXFM_PARTITION`].
174+ pub txfm_partition: [[u16; 3]; 21],
161 pub skip: [[u16; 3]; 3],175 pub skip: [[u16; 3]; 3],
162 /// The luma mode of a key frame's block, under the two neighbours' modes.176 /// The luma mode of a key frame's block, under the two neighbours' modes.
163 pub kf_y_mode: [[[u16; 14]; 5]; 5],177 pub kf_y_mode: [[[u16; 14]; 5]; 5],
@@ -200,6 +214,17 @@ pub(crate) struct Cdfs {
200 pub eob_pt_16_luma_class1: [u16; 6],214 pub eob_pt_16_luma_class1: [u16; 6],
201 /// `eob_pt_64_luma`'s class-1 sibling (r5), see `eob_pt_16_luma_class1`.215 /// `eob_pt_64_luma`'s class-1 sibling (r5), see `eob_pt_16_luma_class1`.
202 pub eob_pt_64_luma_class1: [u16; 8],216 pub eob_pt_64_luma_class1: [u16; 8],
217+ /// `eob_pt_256_luma`'s class-1 sibling (lane-txselect r2): a 16x16 luma
218+ /// TU reaches `V_DCT`/`H_DCT` through the inter tx set
219+ /// `EXT_TX_SET_DTT9_IDTX_1DDCT`, and libaom keeps the eob class
220+ /// dimension at every size.
221+ pub eob_pt_256_luma_class1: [u16; 10],
222+ /// The chroma class-1 siblings (lane-txselect r2): an *inter* block's
223+ /// chroma TU inherits its luma unit's `tx_type`, so 1D classes reach
224+ /// chroma too.
225+ pub eob_pt_256_chroma_class1: [u16; 10],
226+ pub eob_pt_64_chroma_class1: [u16; 8],
227+ pub eob_pt_16_chroma_class1: [u16; 6],
203 /// The end-of-block offset bit of a 16x16 luma transform.228 /// The end-of-block offset bit of a 16x16 luma transform.
204 pub eob_extra_luma_16: [[u16; 3]; 9],229 pub eob_extra_luma_16: [[u16; 3]; 9],
205 /// The same, for an 8x8 luma transform.230 /// The same, for an 8x8 luma transform.
@@ -342,6 +367,11 @@ pub(crate) struct Cdfs {
342 /// (lane-cdffwd2): the sixteen-symbol `EXT_TX_SET_ALL16` row, not367 /// (lane-cdffwd2): the sixteen-symbol `EXT_TX_SET_ALL16` row, not
343 /// indexed by mode.368 /// indexed by mode.
344 pub inter_tx_type_8_set1: [u16; 17],369 pub inter_tx_type_8_set1: [u16; 17],
370+ /// The 4x4 counterparts of [`Self::inter_tx_type_8`]/
371+ /// [`Self::inter_tx_type_8_set1`] (lane-txselect).
372+ pub inter_tx_type_4: [u16; 3],
373+ /// See [`Self::inter_tx_type_4`].
374+ pub inter_tx_type_4_set1: [u16; 17],
345 /// The DC sign of a chroma coefficient, shared by both chroma sets.375 /// The DC sign of a chroma coefficient, shared by both chroma sets.
346 pub dc_sign_chroma: [[u16; 3]; 3],376 pub dc_sign_chroma: [[u16; 3]; 3],
347 /// Whether an inter frame's block is coded as intra.377 /// Whether an inter frame's block is coded as intra.
@@ -583,6 +613,7 @@ impl Cdfs {
583 pub(crate) fn reset_counts(&mut self) {613 pub(crate) fn reset_counts(&mut self) {
584 reset2(&mut self.partition_w64);614 reset2(&mut self.partition_w64);
585 reset2(&mut self.partition_w32);615 reset2(&mut self.partition_w32);
616+ reset2(&mut self.txfm_partition);
586 reset2(&mut self.skip);617 reset2(&mut self.skip);
587 reset3(&mut self.kf_y_mode);618 reset3(&mut self.kf_y_mode);
588 reset2(&mut self.uv_mode_no_cfl);619 reset2(&mut self.uv_mode_no_cfl);
@@ -602,6 +633,10 @@ impl Cdfs {
602 reset1(&mut self.eob_pt_16_luma);633 reset1(&mut self.eob_pt_16_luma);
603 reset1(&mut self.eob_pt_16_luma_class1);634 reset1(&mut self.eob_pt_16_luma_class1);
604 reset1(&mut self.eob_pt_64_luma_class1);635 reset1(&mut self.eob_pt_64_luma_class1);
636+ reset1(&mut self.eob_pt_256_luma_class1);
637+ reset1(&mut self.eob_pt_256_chroma_class1);
638+ reset1(&mut self.eob_pt_64_chroma_class1);
639+ reset1(&mut self.eob_pt_16_chroma_class1);
605 reset2(&mut self.eob_extra_luma_16);640 reset2(&mut self.eob_extra_luma_16);
606 reset2(&mut self.eob_extra_luma_8);641 reset2(&mut self.eob_extra_luma_8);
607 reset2(&mut self.eob_extra_luma_4);642 reset2(&mut self.eob_extra_luma_4);
@@ -660,6 +695,8 @@ impl Cdfs {
660 reset1(&mut self.inter_tx_type_8);695 reset1(&mut self.inter_tx_type_8);
661 reset1(&mut self.inter_tx_type_16_set2);696 reset1(&mut self.inter_tx_type_16_set2);
662 reset1(&mut self.inter_tx_type_8_set1);697 reset1(&mut self.inter_tx_type_8_set1);
698+ reset1(&mut self.inter_tx_type_4);
699+ reset1(&mut self.inter_tx_type_4_set1);
663 reset2(&mut self.dc_sign_chroma);700 reset2(&mut self.dc_sign_chroma);
664 reset2(&mut self.intra_inter);701 reset2(&mut self.intra_inter);
665 reset3(&mut self.single_ref);702 reset3(&mut self.single_ref);
@@ -821,6 +858,34 @@ impl Cdfs {
821 cdf::EOB_PT_64_LUMA_CLASS1,858 cdf::EOB_PT_64_LUMA_CLASS1,
822 cdf::EOB_PT_64_LUMA_CLASS1_Q3,859 cdf::EOB_PT_64_LUMA_CLASS1_Q3,
823 ),860 ),
861+ eob_pt_256_luma_class1: pick(
862+ q_ctx,
863+ cdf::EOB_PT_256_LUMA_CLASS1_Q0,
864+ cdf::EOB_PT_256_LUMA_CLASS1_Q1,
865+ cdf::EOB_PT_256_LUMA_CLASS1,
866+ cdf::EOB_PT_256_LUMA_CLASS1_Q3,
867+ ),
868+ eob_pt_256_chroma_class1: pick(
869+ q_ctx,
870+ cdf::EOB_PT_256_CHROMA_CLASS1_Q0,
871+ cdf::EOB_PT_256_CHROMA_CLASS1_Q1,
872+ cdf::EOB_PT_256_CHROMA_CLASS1,
873+ cdf::EOB_PT_256_CHROMA_CLASS1_Q3,
874+ ),
875+ eob_pt_64_chroma_class1: pick(
876+ q_ctx,
877+ cdf::EOB_PT_64_CHROMA_CLASS1_Q0,
878+ cdf::EOB_PT_64_CHROMA_CLASS1_Q1,
879+ cdf::EOB_PT_64_CHROMA_CLASS1,
880+ cdf::EOB_PT_64_CHROMA_CLASS1_Q3,
881+ ),
882+ eob_pt_16_chroma_class1: pick(
883+ q_ctx,
884+ cdf::EOB_PT_16_CHROMA_CLASS1_Q0,
885+ cdf::EOB_PT_16_CHROMA_CLASS1_Q1,
886+ cdf::EOB_PT_16_CHROMA_CLASS1,
887+ cdf::EOB_PT_16_CHROMA_CLASS1_Q3,
888+ ),
824 eob_extra_luma_16: pick(889 eob_extra_luma_16: pick(
825 q_ctx,890 q_ctx,
826 cdf::EOB_EXTRA_LUMA_16_Q0,891 cdf::EOB_EXTRA_LUMA_16_Q0,
@@ -1149,6 +1214,8 @@ impl Cdfs {
1149 inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8,1214 inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8,
1150 inter_tx_type_16_set2: cdf::INTER_TX_TYPE_SET2_16,1215 inter_tx_type_16_set2: cdf::INTER_TX_TYPE_SET2_16,
1151 inter_tx_type_8_set1: cdf::INTER_TX_TYPE_SET1_8,1216 inter_tx_type_8_set1: cdf::INTER_TX_TYPE_SET1_8,
1217+ inter_tx_type_4: cdf::INTER_TX_TYPE_SET3_4,
1218+ inter_tx_type_4_set1: cdf::INTER_TX_TYPE_SET1_4,
1152 dc_sign_chroma: cdf::DC_SIGN_CHROMA,1219 dc_sign_chroma: cdf::DC_SIGN_CHROMA,
1153 intra_inter: cdf::INTRA_INTER,1220 intra_inter: cdf::INTRA_INTER,
1154 single_ref: cdf::SINGLE_REF,1221 single_ref: cdf::SINGLE_REF,
@@ -1158,6 +1225,7 @@ impl Cdfs {
1158 uni_comp_ref: cdf::UNI_COMP_REF,1225 uni_comp_ref: cdf::UNI_COMP_REF,
1159 comp_ref: cdf::COMP_REF,1226 comp_ref: cdf::COMP_REF,
1160 comp_bwdref: cdf::COMP_BWDREF,1227 comp_bwdref: cdf::COMP_BWDREF,
1228+ txfm_partition: cdf::TXFM_PARTITION,
1161 skip_mode: cdf::SKIP_MODE,1229 skip_mode: cdf::SKIP_MODE,
1162 obmc: cdf::OBMC,1230 obmc: cdf::OBMC,
1163 motion_mode: cdf::MOTION_MODE,1231 motion_mode: cdf::MOTION_MODE,
@@ -1263,7 +1331,7 @@ impl Cdfs {
1263 br: &mut self.br_luma_16,1331 br: &mut self.br_luma_16,
1264 dc_sign: &mut self.dc_sign_luma,1332 dc_sign: &mut self.dc_sign_luma,
1265 tx_type: Some(self.intra_tx_type_16[mode].as_mut_slice()),1333 tx_type: Some(self.intra_tx_type_16[mode].as_mut_slice()),
1266- eob_pt_class1: None,1334+ eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1),
1267 },1335 },
1268 TxbSet::Luma16Inter => TxbTables {1336 TxbSet::Luma16Inter => TxbTables {
1269 side: 16,1337 side: 16,
@@ -1275,7 +1343,7 @@ impl Cdfs {
1275 br: &mut self.br_luma_16,1343 br: &mut self.br_luma_16,
1276 dc_sign: &mut self.dc_sign_luma,1344 dc_sign: &mut self.dc_sign_luma,
1277 tx_type: Some(self.inter_tx_type_16.as_mut_slice()),1345 tx_type: Some(self.inter_tx_type_16.as_mut_slice()),
1278- eob_pt_class1: None,1346+ eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1),
1279 },1347 },
1280 TxbSet::Luma16InterSet1 => TxbTables {1348 TxbSet::Luma16InterSet1 => TxbTables {
1281 side: 16,1349 side: 16,
@@ -1287,7 +1355,7 @@ impl Cdfs {
1287 br: &mut self.br_luma_16,1355 br: &mut self.br_luma_16,
1288 dc_sign: &mut self.dc_sign_luma,1356 dc_sign: &mut self.dc_sign_luma,
1289 tx_type: Some(self.inter_tx_type_16_set2.as_mut_slice()),1357 tx_type: Some(self.inter_tx_type_16_set2.as_mut_slice()),
1290- eob_pt_class1: None,1358+ eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1),
1291 },1359 },
1292 TxbSet::Luma8 => TxbTables {1360 TxbSet::Luma8 => TxbTables {
1293 side: 8,1361 side: 8,
@@ -1325,6 +1393,30 @@ impl Cdfs {
1325 tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()),1393 tx_type: Some(self.intra_tx_type_4[mode].as_mut_slice()),
1326 eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1),1394 eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1),
1327 },1395 },
1396+ TxbSet::Luma4Inter => TxbTables {
1397+ side: 4,
1398+ txb_skip: &mut self.txb_skip_luma_4,
1399+ eob_pt: &mut self.eob_pt_16_luma,
1400+ eob_extra: &mut self.eob_extra_luma_4,
1401+ base: &mut self.base_luma_4,
1402+ base_eob: &mut self.base_eob_luma_4,
1403+ br: &mut self.br_luma_4,
1404+ dc_sign: &mut self.dc_sign_luma,
1405+ tx_type: Some(self.inter_tx_type_4.as_mut_slice()),
1406+ eob_pt_class1: None,
1407+ },
1408+ TxbSet::Luma4InterSet1 => TxbTables {
1409+ side: 4,
1410+ txb_skip: &mut self.txb_skip_luma_4,
1411+ eob_pt: &mut self.eob_pt_16_luma,
1412+ eob_extra: &mut self.eob_extra_luma_4,
1413+ base: &mut self.base_luma_4,
1414+ base_eob: &mut self.base_eob_luma_4,
1415+ br: &mut self.br_luma_4,
1416+ dc_sign: &mut self.dc_sign_luma,
1417+ tx_type: Some(self.inter_tx_type_4_set1.as_mut_slice()),
1418+ eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1),
1419+ },
1328 TxbSet::Luma4Set1 => TxbTables {1420 TxbSet::Luma4Set1 => TxbTables {
1329 side: 4,1421 side: 4,
1330 txb_skip: &mut self.txb_skip_luma_4,1422 txb_skip: &mut self.txb_skip_luma_4,
@@ -1371,7 +1463,7 @@ impl Cdfs {
1371 br: &mut self.br_chroma_8,1463 br: &mut self.br_chroma_8,
1372 dc_sign: &mut self.dc_sign_chroma,1464 dc_sign: &mut self.dc_sign_chroma,
1373 tx_type: None,1465 tx_type: None,
1374- eob_pt_class1: None,1466+ eob_pt_class1: Some(&mut self.eob_pt_64_chroma_class1),
1375 },1467 },
1376 TxbSet::Chroma4 => TxbTables {1468 TxbSet::Chroma4 => TxbTables {
1377 side: 4,1469 side: 4,
@@ -1383,7 +1475,7 @@ impl Cdfs {
1383 br: &mut self.br_chroma_4,1475 br: &mut self.br_chroma_4,
1384 dc_sign: &mut self.dc_sign_chroma,1476 dc_sign: &mut self.dc_sign_chroma,
1385 tx_type: None,1477 tx_type: None,
1386- eob_pt_class1: None,1478+ eob_pt_class1: Some(&mut self.eob_pt_16_chroma_class1),
1387 },1479 },
1388 TxbSet::Chroma16 => TxbTables {1480 TxbSet::Chroma16 => TxbTables {
1389 side: 16,1481 side: 16,
@@ -1395,7 +1487,7 @@ impl Cdfs {
1395 br: &mut self.br_chroma_16,1487 br: &mut self.br_chroma_16,
1396 dc_sign: &mut self.dc_sign_chroma,1488 dc_sign: &mut self.dc_sign_chroma,
1397 tx_type: None,1489 tx_type: None,
1398- eob_pt_class1: None,1490+ eob_pt_class1: Some(&mut self.eob_pt_256_chroma_class1),
1399 },1491 },
1400 TxbSet::Chroma32 => TxbTables {1492 TxbSet::Chroma32 => TxbTables {
1401 side: 32,1493 side: 32,
crates/ec-av1/src/decode.rsmodified+737 -73
@@ -759,6 +759,38 @@ pub(crate) fn tx_depth_hits() -> usize {
759 TX_DEPTH_HITS.with(|c| c.get())759 TX_DEPTH_HITS.with(|c| c.get())
760 }760 }
761 761
762+// lane-txselect: how many `txfm_split` symbols an inter frame's var-tx tree
763+// read, and how many of those actually took the split, on the current thread
764+// -- the same before/after counter pattern as [`TX_DEPTH_HITS`], proving a
765+// stream exercised spec 5.11.17's `read_var_tx_size` rather than every block
766+// coincidentally coding one whole-block transform.
767+thread_local! {
768+ static TXFM_SPLIT_READS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
769+ static TXFM_SPLIT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
770+ // This frame's own `tx_mode == TxMode::Select` and `reduced_tx_set` bits,
771+ // set once per inter tile by [`decode_inter_frame_tile_with_cdfs`] --
772+ // `decode_inter_block` already carries forty parameters and both are
773+ // frame-constant.
774+ static TX_SELECT_INTER: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
775+ static REDUCED_TX_SET_INTER: std::cell::Cell<bool> = const { std::cell::Cell::new(true) };
776+}
777+
778+/// Current value of [`TXFM_SPLIT_READS`].
779+pub(crate) fn txfm_split_reads() -> usize {
780+ TXFM_SPLIT_READS.with(|c| c.get())
781+}
782+
783+/// Current value of [`TXFM_SPLIT_HITS`].
784+pub(crate) fn txfm_split_hits() -> usize {
785+ TXFM_SPLIT_HITS.with(|c| c.get())
786+}
787+
788+/// Sets the current thread's [`TX_SELECT_INTER`]/[`REDUCED_TX_SET_INTER`].
789+pub(crate) fn set_inter_tx_mode(tx_select: bool, reduced_tx_set: bool) {
790+ TX_SELECT_INTER.with(|c| c.set(tx_select));
791+ REDUCED_TX_SET_INTER.with(|c| c.set(reduced_tx_set));
792+}
793+
762 // How many `partition_w16` reads (a 16x16 block's own partition symbol, key794 // How many `partition_w16` reads (a 16x16 block's own partition symbol, key
763 // intra-frame path) resolved to `PARTITION_VERT_B` -- lane-rect16 r1: a795 // intra-frame path) resolved to `PARTITION_VERT_B` -- lane-rect16 r1: a
764 // plain default-settings aomenc run over lavfi mandelbrot hits this arm on796 // plain default-settings aomenc run over lavfi mandelbrot hits this arm on
@@ -2393,6 +2425,16 @@ struct Neighbours {
2393 /// `left_skip`.2425 /// `left_skip`.
2394 above_skip: Vec<bool>,2426 above_skip: Vec<bool>,
2395 left_skip: Vec<bool>,2427 left_skip: Vec<bool>,
2428+ /// libaom's `above_txfm_context`/`left_txfm_context` (`TXFM_CONTEXT`), at
2429+ /// 4x4 mi granularity: the transform *width* (above) / *height* (left) in
2430+ /// pixels last written over each unit by `set_txfm_ctxs`/
2431+ /// `txfm_partition_update`, which is what an inter block's `txfm_split`
2432+ /// symbol reads its context from (lane-txselect, spec 5.11.17).
2433+ /// [`TXFM_CTX_INIT`] until a block writes one; a fresh full-height `left`
2434+ /// array is exactly libaom's per-superblock-row reset, since each mi row
2435+ /// is only ever visited inside one superblock row.
2436+ above_txfm: Vec<u8>,
2437+ left_txfm: Vec<u8>,
2396 /// Whether the block above/left of this column/row coded `skip_mode`2438 /// Whether the block above/left of this column/row coded `skip_mode`
2397 /// (spec 5.11.23) -- `av1_get_skip_mode_context`'s own neighbour lookup,2439 /// (spec 5.11.23) -- `av1_get_skip_mode_context`'s own neighbour lookup,
2398 /// lane-av1comp round 14.2440 /// lane-av1comp round 14.
@@ -2523,6 +2565,8 @@ impl Neighbours {
2523 left_side: vec![SB; rows],2565 left_side: vec![SB; rows],
2524 above_side_mi: vec![SB; cols * (SUB / MI)],2566 above_side_mi: vec![SB; cols * (SUB / MI)],
2525 left_side_mi: vec![SB; rows * (SUB / MI)],2567 left_side_mi: vec![SB; rows * (SUB / MI)],
2568+ above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)],
2569+ left_txfm: vec![TXFM_CTX_INIT; rows * (SUB / MI)],
2526 // lane-inter8 r2: mi(4px)-granular, not [`SUB`]-granular -- an2570 // lane-inter8 r2: mi(4px)-granular, not [`SUB`]-granular -- an
2527 // 8x8 inter leaf's left neighbour is the OTHER leaf row of the2571 // 8x8 inter leaf's left neighbour is the OTHER leaf row of the
2528 // 16x16 block beside it, which a SUB-grid slot cannot name2572 // 16x16 block beside it, which a SUB-grid slot cannot name
@@ -5890,7 +5934,7 @@ fn decode_block(
5890 // 5.11.40); `coeff_tx_side` is the actual coded coefficient grid's side,5934 // 5.11.40); `coeff_tx_side` is the actual coded coefficient grid's side,
5891 // which only differs from it at that one corner case.5935 // which only differs from it at that one corner case.
5892 let (logical_tx, coeff_tx_side) = if tx_select {5936 let (logical_tx, coeff_tx_side) = if tx_select {
5893- let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side);5937+ let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None);
5894 (resolved, if resolved == 64 { 32 } else { resolved })5938 (resolved, if resolved == 64 { 32 } else { resolved })
5895 } else {5939 } else {
5896 (side, luma_tx)5940 (side, luma_tx)
@@ -6325,7 +6369,7 @@ fn decode_leaf8(
6325 // transform units, same raster-order per-TU pattern `decode_block`'s6369 // transform units, same raster-order per-TU pattern `decode_block`'s
6326 // multi-TU branch runs).6370 // multi-TU branch runs).
6327 let resolved = if tx_select {6371 let resolved = if tx_select {
6328- read_tx_size(dec, cdfs, neighbours, leaf_mi, 8)6372+ read_tx_size(dec, cdfs, neighbours, leaf_mi, 8, None)
6329 } else {6373 } else {
6330 86374 8
6331 };6375 };
@@ -6842,6 +6886,33 @@ fn tx_size_context(n: &Neighbours, (mi_r, mi_c): (usize, usize), own_side: usize
6842 usize::from(above) + usize::from(left)6886 usize::from(above) + usize::from(left)
6843 }6887 }
6844 6888
6889+/// `get_tx_size_context` as libaom actually writes it (`pred_common.h:342`),
6890+/// for a block inside an INTER frame: the two `TXFM_CONTEXT` arrays
6891+/// ([`Neighbours::above_txfm`]/[`Neighbours::left_txfm`], which only the
6892+/// inter path maintains), except that an *inter* neighbour contributes its
6893+/// own BLOCK size rather than its transform size -- the two differ the moment
6894+/// a neighbour's var-tx tree splits. [`tx_size_context`]'s deblock-grid
6895+/// approximation coincides with this only while every neighbour codes one
6896+/// whole-block transform, which is exactly what `TxMode::Select` ends.
6897+fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize), side: usize) -> usize {
6898+ let has_above = mi_r > n.tile_row0_mi;
6899+ let has_left = mi_c > n.tile_col0_mi;
6900+ let mut above = usize::from(n.above_txfm[mi_c]) >= side;
6901+ let mut left = usize::from(n.left_txfm[mi_r]) >= side;
6902+ if has_above && n.above_inter[mi_c / (SUB / MI)] {
6903+ above = n.above_side_mi[mi_c] >= side;
6904+ }
6905+ if has_left && n.left_inter[mi_r / (SUB / MI)] {
6906+ left = n.left_side_mi[mi_r] >= side;
6907+ }
6908+ match (has_above, has_left) {
6909+ (true, true) => usize::from(above) + usize::from(left),
6910+ (true, false) => usize::from(above),
6911+ (false, true) => usize::from(left),
6912+ (false, false) => 0,
6913+ }
6914+}
6915+
6845 /// `read_tx_size`/`read_selected_tx_size` (spec 5.11.16): under6916 /// `read_tx_size`/`read_selected_tx_size` (spec 5.11.16): under
6846 /// `TxMode::Select`, an intra block's `tx_depth` symbol, resolved straight to6917 /// `TxMode::Select`, an intra block's `tx_depth` symbol, resolved straight to
6847 /// the transform's own side in pixels (`side >> depth`) -- this decoder's6918 /// the transform's own side in pixels (`side >> depth`) -- this decoder's
@@ -6853,8 +6924,12 @@ fn read_tx_size(
6853 n: &Neighbours,6924 n: &Neighbours,
6854 at_mi: (usize, usize),6925 at_mi: (usize, usize),
6855 side: usize,6926 side: usize,
6927+ // lane-txselect: `get_tx_size_context`'s real context, for the callers
6928+ // that have one -- see [`tx_size_context_txfm`]. `None` keeps the
6929+ // key-frame path's own deblock-grid approximation.
6930+ ctx_override: Option<usize>,
6856 ) -> usize {6931 ) -> usize {
6857- let ctx = tx_size_context(n, at_mi, side);6932+ let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, side));
6858 let depth = match side {6933 let depth = match side {
6859 8 => {6934 8 => {
6860 dec.symbol(&mut cdfs.tx_size_cat0[ctx])6935 dec.symbol(&mut cdfs.tx_size_cat0[ctx])
@@ -6883,6 +6958,349 @@ fn read_tx_size(
6883 side >> depth6958 side >> depth
6884 }6959 }
6885 6960
6961+/// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's
6962+/// `txfm_split` context -- a category from the block's own largest square
6963+/// transform and whether this unit already sits below it, times three, plus
6964+/// the two neighbour terms (whether the transform last written above/left of
6965+/// this unit is narrower/shorter than the unit itself).
6966+fn txfm_partition_ctx(above_px: u8, left_px: u8, blk_max_px: usize, tx_px: usize) -> usize {
6967+ let above = usize::from(usize::from(above_px) < tx_px);
6968+ let left = usize::from(usize::from(left_px) < tx_px);
6969+ // `get_sqr_tx_size(max(block_size_wide, block_size_high))`, capped at the
6970+ // largest transform (`TX_64X64`); `TX_4X4`..`TX_64X64` index as
6971+ // `log2(px) - 2`.
6972+ let max_tx = blk_max_px.min(64);
6973+ let max_idx = max_tx.trailing_zeros() as usize - 2;
6974+ let category = usize::from(tx_px != max_tx && max_tx > 8) + (4 - max_idx) * 2;
6975+ category * 3 + above + left
6976+}
6977+
6978+/// `txfm_partition_update` (libaom `av1_common_int.h`): once a var-tx unit
6979+/// resolves, every mi cell its *parent* unit (`txb_px`) spans records the
6980+/// resolved transform's own size.
6981+fn txfm_partition_update(
6982+ n: &mut Neighbours,
6983+ (mi_r, mi_c): (usize, usize),
6984+ tx_px: usize,
6985+ txb_px: usize,
6986+) {
6987+ for i in 0..txb_px / MI {
6988+ if let Some(cell) = n.left_txfm.get_mut(mi_r + i) {
6989+ *cell = tx_px as u8;
6990+ }
6991+ if let Some(cell) = n.above_txfm.get_mut(mi_c + i) {
6992+ *cell = tx_px as u8;
6993+ }
6994+ }
6995+}
6996+
6997+/// `set_txfm_ctxs` (libaom `av1_common_int.h`): the non-var-tx write of the
6998+/// same contexts -- a skipped *inter* block records its own block size rather
6999+/// than its transform size.
7000+fn set_txfm_ctxs(
7001+ n: &mut Neighbours,
7002+ (mi_r, mi_c): (usize, usize),
7003+ tx_px: usize,
7004+ w_mi: usize,
7005+ h_mi: usize,
7006+ skip_inter: bool,
7007+) {
7008+ let bw = if skip_inter { w_mi * MI } else { tx_px };
7009+ let bh = if skip_inter { h_mi * MI } else { tx_px };
7010+ for i in 0..w_mi {
7011+ if let Some(cell) = n.above_txfm.get_mut(mi_c + i) {
7012+ *cell = bw as u8;
7013+ }
7014+ }
7015+ for i in 0..h_mi {
7016+ if let Some(cell) = n.left_txfm.get_mut(mi_r + i) {
7017+ *cell = bh as u8;
7018+ }
7019+ }
7020+}
7021+
7022+/// The value libaom initialises both transform contexts to -- NOT zero:
7023+/// `av1_zero_above_context` memsets the txfm row to
7024+/// `tx_size_wide[TX_SIZES_LARGEST]` and `av1_zero_left_context` does the same
7025+/// with `tx_size_high[TX_SIZES_LARGEST]` (`av1_common_int.h`), i.e. 64
7026+/// pixels, so an unwritten neighbour reads as the *widest* possible
7027+/// transform, not the narrowest.
7028+const TXFM_CTX_INIT: u8 = 64;
7029+
7030+/// libaom's `MAX_VARTX_DEPTH`: an inter block's transform tree halves at most
7031+/// twice below its own largest transform.
7032+const MAX_VARTX_DEPTH: usize = 2;
7033+
7034+/// `read_var_tx_size` (spec 5.11.17, libaom `decodeframe.c`
7035+/// `read_tx_size_vartx`): the recursive `txfm_split` tree of one
7036+/// max-transform-sized unit of an inter block, collecting the resolved leaf
7037+/// transform units into `out` as `(row offset, col offset, side)` in mi units
7038+/// -- exactly the order `decode_reconstruct_tx` later reads their
7039+/// coefficients in. `blk_row`/`blk_col` are mi offsets inside the block;
7040+/// `max_w_mi`/`max_h_mi` clip it to the true frame edge (`max_block_wide`/
7041+/// `max_block_high`).
7042+#[allow(clippy::too_many_arguments)]
7043+fn read_var_tx_size(
7044+ dec: &mut SymbolDecoder,
7045+ cdfs: &mut Cdfs,
7046+ n: &mut Neighbours,
7047+ at_mi: (usize, usize),
7048+ blk_max_px: usize,
7049+ (max_w_mi, max_h_mi): (usize, usize),
7050+ tx_px: usize,
7051+ depth: usize,
7052+ blk_row: usize,
7053+ blk_col: usize,
7054+ out: &mut Vec<(usize, usize, usize)>,
7055+) {
7056+ if blk_row >= max_h_mi || blk_col >= max_w_mi {
7057+ return;
7058+ }
7059+ let unit = (at_mi.0 + blk_row, at_mi.1 + blk_col);
7060+ if depth == MAX_VARTX_DEPTH {
7061+ out.push((blk_row, blk_col, tx_px));
7062+ txfm_partition_update(n, unit, tx_px, tx_px);
7063+ return;
7064+ }
7065+ let ctx = txfm_partition_ctx(n.above_txfm[unit.1], n.left_txfm[unit.0], blk_max_px, tx_px);
7066+ let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;
7067+ TXFM_SPLIT_READS.with(|c| c.set(c.get() + 1));
7068+ if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {
7069+ let (rng, _) = dec.debug_state();
7070+ eprintln!(
7071+ "EC_ISTEP mi_row={} mi_col={} name=txfm_split val={} ctx={ctx} rng={rng}",
7072+ unit.0,
7073+ unit.1,
7074+ u8::from(split)
7075+ );
7076+ }
7077+ if !split {
7078+ out.push((blk_row, blk_col, tx_px));
7079+ txfm_partition_update(n, unit, tx_px, tx_px);
7080+ return;
7081+ }
7082+ TXFM_SPLIT_HITS.with(|c| c.set(c.get() + 1));
7083+ let sub = tx_px / 2;
7084+ if sub == 4 {
7085+ // libaom's `sub_txs == TX_4X4` early return: the whole 8x8 unit is
7086+ // marked 4x4 (four transform units, raster order) without recursing.
7087+ for row in 0..2 {
7088+ for col in 0..2 {
7089+ if blk_row + row < max_h_mi && blk_col + col < max_w_mi {
7090+ out.push((blk_row + row, blk_col + col, 4));
7091+ }
7092+ }
7093+ }
7094+ txfm_partition_update(n, unit, 4, tx_px);
7095+ return;
7096+ }
7097+ for row in (0..tx_px / MI).step_by(sub / MI) {
7098+ for col in (0..tx_px / MI).step_by(sub / MI) {
7099+ read_var_tx_size(
7100+ dec,
7101+ cdfs,
7102+ n,
7103+ at_mi,
7104+ blk_max_px,
7105+ (max_w_mi, max_h_mi),
7106+ sub,
7107+ depth + 1,
7108+ blk_row + row,
7109+ blk_col + col,
7110+ out,
7111+ );
7112+ }
7113+ }
7114+}
7115+
7116+/// `read_block_tx_size` (libaom `decodeframe.c` `parse_decode_block`'s tx
7117+/// branch): every block of a `TxMode::Select` inter frame codes its transform
7118+/// size right after its own mode info -- an inter non-skip block through the
7119+/// recursive var-tx tree ([`read_var_tx_size`], whose leaf list this returns),
7120+/// every other block through the intra `tx_depth` symbol (a skipped inter
7121+/// block codes no symbol at all) plus a `set_txfm_ctxs` write. Returns the
7122+/// block's own resolved transform side and the leaf list, the latter only
7123+/// when the tree resolved to more than one transform unit.
7124+#[allow(clippy::too_many_arguments)]
7125+fn read_block_tx_size(
7126+ dec: &mut SymbolDecoder,
7127+ cdfs: &mut Cdfs,
7128+ n: &mut Neighbours,
7129+ at_mi: (usize, usize),
7130+ side: usize,
7131+ (mi_cols, mi_rows): (usize, usize),
7132+ is_inter: bool,
7133+ skip: bool,
7134+) -> Result<(usize, Option<Vec<(usize, usize, usize)>>)> {
7135+ if !TX_SELECT_INTER.with(std::cell::Cell::get) {
7136+ return Ok((side, None));
7137+ }
7138+ let side_mi = side / MI;
7139+ if is_inter && !skip {
7140+ let max_tx = side.min(64);
7141+ let max_w_mi = side_mi.min(mi_cols.saturating_sub(at_mi.1));
7142+ let max_h_mi = side_mi.min(mi_rows.saturating_sub(at_mi.0));
7143+ let mut leaves = Vec::new();
7144+ let step = max_tx / MI;
7145+ for row in (0..side_mi).step_by(step) {
7146+ for col in (0..side_mi).step_by(step) {
7147+ read_var_tx_size(
7148+ dec,
7149+ cdfs,
7150+ n,
7151+ at_mi,
7152+ side,
7153+ (max_w_mi, max_h_mi),
7154+ max_tx,
7155+ 0,
7156+ row,
7157+ col,
7158+ &mut leaves,
7159+ );
7160+ }
7161+ }
7162+ let single = leaves.len() == 1 && leaves[0].2 == side;
7163+ if !single && leaves.iter().any(|leaf| leaf.2 > 32) {
7164+ // Only a block wider than a superblock's own 64x64 max transform
7165+ // reaches here; this crate has no 64-point *inter* coefficient
7166+ // table set ([`inter_txbset_for`] stops at 32).
7167+ return Err(unsupported(
7168+ "an inter var-tx tree with a leaf transform larger than 32x32",
7169+ ));
7170+ }
7171+ let resolved = leaves.last().map_or(side, |l| l.2);
7172+ return Ok((resolved, (!single).then_some(leaves)));
7173+ }
7174+ let tx = if is_inter {
7175+ side.min(64)
7176+ } else {
7177+ let resolved = read_tx_size(
7178+ dec,
7179+ cdfs,
7180+ n,
7181+ at_mi,
7182+ side,
7183+ Some(tx_size_context_txfm(n, at_mi, side)),
7184+ );
7185+ if resolved != side {
7186+ // An intra block inside an inter frame whose `tx_depth` splits its
7187+ // luma transform needs the per-transform-unit intra prediction
7188+ // loop `decode_block` runs for a key frame; this path predicts the
7189+ // whole block at once, so refuse rather than mis-reconstruct.
7190+ return Err(unsupported(
7191+ "an intra block in an inter frame whose tx_depth splits its luma transform \
7192+ (round 1)",
7193+ ));
7194+ }
7195+ resolved
7196+ };
7197+ set_txfm_ctxs(n, at_mi, tx, side_mi, side_mi, skip && is_inter);
7198+ Ok((tx, None))
7199+}
7200+
7201+/// One 8x8 inter leaf's luma residual (lane-txselect): either the whole-8x8
7202+/// transform, or -- when [`read_block_tx_size`]'s var-tx tree took the single
7203+/// split a `BLOCK_8X8` can take (`split`) -- the four 4x4 transform units in
7204+/// raster order, each reading its own coefficient context off the units
7205+/// already decoded before it. Returns the block's luma grid (all-zero in the
7206+/// split case, whose reconstruction has already happened unit by unit) and
7207+/// the `tx_type` chroma inherits: `av1_get_tx_type`'s colocated luma lookup,
7208+/// which for a split block lands on the top-left unit.
7209+#[allow(clippy::too_many_arguments)]
7210+fn read_inter_luma8(
7211+ dec: &mut SymbolDecoder,
7212+ cdfs: &mut Cdfs,
7213+ neighbours: &mut Neighbours,
7214+ leaf_mi: (usize, usize),
7215+ y: &mut PlaneBuf,
7216+ px: usize,
7217+ py: usize,
7218+ pred_y: &[u16],
7219+ mode_for_tx: usize,
7220+ base_q_idx: u8,
7221+ scan8: &[u16],
7222+ scan4: &[u16],
7223+ reduced_tx_set: bool,
7224+ split: bool,
7225+) -> Result<(Vec<i32>, TxType)> {
7226+ if !split {
7227+ return read_inter_plane(
7228+ dec,
7229+ cdfs,
7230+ if reduced_tx_set {
7231+ TxbSet::Luma8Inter
7232+ } else {
7233+ TxbSet::Luma8InterSet1
7234+ },
7235+ scan8,
7236+ 0,
7237+ neighbours.around_mi(leaf_mi, 8)[0],
7238+ mode_for_tx,
7239+ y,
7240+ px,
7241+ py,
7242+ 8,
7243+ base_q_idx,
7244+ pred_y,
7245+ None,
7246+ None,
7247+ );
7248+ }
7249+ let mut first = TxType::DctDct;
7250+ for tu_row in 0..2 {
7251+ for tu_col in 0..2 {
7252+ let tu_mi = (leaf_mi.0 + tu_row, leaf_mi.1 + tu_col);
7253+ let mut tu_pred = Vec::with_capacity(16);
7254+ for rr in 0..4 {
7255+ let start = (tu_row * 4 + rr) * 8 + tu_col * 4;
7256+ tu_pred.extend_from_slice(&pred_y[start..start + 4]);
7257+ }
7258+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1);
7259+ let (tu_grid, tu_tx_type) = read_inter_plane(
7260+ dec,
7261+ cdfs,
7262+ if reduced_tx_set {
7263+ TxbSet::Luma4Inter
7264+ } else {
7265+ TxbSet::Luma4InterSet1
7266+ },
7267+ scan4,
7268+ 0,
7269+ neighbours.around_mi(tu_mi, 4)[0],
7270+ mode_for_tx,
7271+ y,
7272+ px + tu_col * 4,
7273+ py + tu_row * 4,
7274+ 4,
7275+ base_q_idx,
7276+ &tu_pred,
7277+ None,
7278+ Some(tu_skip_ctx),
7279+ )?;
7280+ if tu_row == 0 && tu_col == 0 {
7281+ first = tu_tx_type;
7282+ }
7283+ neighbours.record_mi_luma(tu_mi, 4, &tu_grid);
7284+ }
7285+ }
7286+ Ok((vec![0i32; 64], first))
7287+}
7288+
7289+/// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its
7290+/// coefficient tables from -- the inter counterpart of [`txbset_for`].
7291+fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet {
7292+ match tx_px {
7293+ 32 => TxbSet::Luma32Inter,
7294+ 16 if reduced_tx_set => TxbSet::Luma16Inter,
7295+ 16 => TxbSet::Luma16InterSet1,
7296+ 8 if reduced_tx_set => TxbSet::Luma8Inter,
7297+ 8 => TxbSet::Luma8InterSet1,
7298+ 4 if reduced_tx_set => TxbSet::Luma4Inter,
7299+ 4 => TxbSet::Luma4InterSet1,
7300+ _ => unreachable!("a var-tx leaf is never wider than a 64x64 block's 32x32 sub-transform"),
7301+ }
7302+}
7303+
6886 /// The luma coefficient scan table for a resolved transform side -- 32/16/8/4,7304 /// The luma coefficient scan table for a resolved transform side -- 32/16/8/4,
6887 /// the only four sizes a `TxMode::Select` block's coded coefficient grid7305 /// the only four sizes a `TxMode::Select` block's coded coefficient grid
6888 /// ([`read_tx_size`]'s resolved side, or 32 at the 64x64 corner case) can be.7306 /// ([`read_tx_size`]'s resolved side, or 32 at the 64x64 corner case) can be.
@@ -9420,9 +9838,15 @@ fn read_inter_plane(
9420 // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true9838 // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true
9421 // `DCT_DCT` default at 32-point+) already resolves it without help.9839 // `DCT_DCT` default at 32-point+) already resolves it without help.
9422 inherited_luma_tx_type: Option<TxType>,9840 inherited_luma_tx_type: Option<TxType>,
9841+ // lane-txselect: the luma `txb_skip_ctx` of a transform unit smaller than
9842+ // its own block (spec `get_txb_ctx_general`'s `plane_bsize != tx_size`
9843+ // branch, [`Neighbours::luma_skip_ctx`]) -- `None` for the whole-block
9844+ // transform every non-var-tx caller reads, whose plane-0 context is the
9845+ // lone-transform-unit 0.
9846+ luma_skip_ctx: Option<usize>,
9423 ) -> Result<(Vec<i32>, TxType)> {9847 ) -> Result<(Vec<i32>, TxType)> {
9424 let skip_ctx = if plane_idx == 0 {9848 let skip_ctx = if plane_idx == 0 {
9425- 09849+ luma_skip_ctx.unwrap_or(0)
9426 } else {9850 } else {
9427 usize::from(around.0) + usize::from(around.1)9851 usize::from(around.0) + usize::from(around.1)
9428 };9852 };
@@ -10633,6 +11057,12 @@ fn decode_inter_block(
10633 // common `record_inter` call below (which would otherwise stamp the11057 // common `record_inter` call below (which would otherwise stamp the
10634 // single-ref ALTREF-special-case default over it).11058 // single-ref ALTREF-special-case default over it).
10635 let mut compound_ctx: Option<(i8, u8, u8)> = None;11059 let mut compound_ctx: Option<(i8, u8, u8)> = None;
11060+ // lane-txselect: `read_block_tx_size`'s leaf transform units (spec
11061+ // 5.11.17), `Some` only when this block's var-tx tree resolved to more
11062+ // than one luma transform -- read back by the residual loop, the
11063+ // coefficient-context write-back and the loop-filter grid fill below.
11064+ let mut vartx_leaves: Option<Vec<(usize, usize, usize)>> = None;
11065+ let at_mi = (r * (SUB / MI), c * (SUB / MI));
10636 if is_inter {11066 if is_inter {
10637 let above_nbr = has_above.then(|| NeighbourRef {11067 let above_nbr = has_above.then(|| NeighbourRef {
10638 is_inter: above_inter,11068 is_inter: above_inter,
@@ -11377,6 +11807,17 @@ fn decode_inter_block(
11377 mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v);11807 mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v);
11378 }11808 }
11379 11809
11810+ vartx_leaves = read_block_tx_size(
11811+ dec,
11812+ cdfs,
11813+ neighbours,
11814+ at_mi,
11815+ side,
11816+ (mi_cols as usize, mi_rows as usize),
11817+ true,
11818+ skip,
11819+ )?
11820+ .1;
11380 if skip {11821 if skip {
11381 y.reconstruct_mc_rect(11822 y.reconstruct_mc_rect(
11382 px,11823 px,
@@ -11411,22 +11852,70 @@ fn decode_inter_block(
11411 } else {11852 } else {
11412 let around = neighbours.around(at, side);11853 let around = neighbours.around(at, side);
11413 let luma_tx_type;11854 let luma_tx_type;
11414- (luma_grid, luma_tx_type) = read_inter_plane(11855+ if let Some(leaves) = vartx_leaves.clone() {
11415- dec,11856+ // spec 5.11.17's transform tree, leaf by leaf in the order
11416- cdfs,11857+ // `read_var_tx_size` coded it: each unit reads its own
11417- luma_set_inter,11858+ // coefficients against the neighbour magnitudes the
11418- scan_luma,11859+ // earlier units already wrote, and reconstructs over its
11419- 0,11860+ // own slice of the block's motion-compensated predictor.
11420- around[0],11861+ let reduced = REDUCED_TX_SET_INTER.with(std::cell::Cell::get);
11421- mode_for_tx,11862+ let mut first_tx_type = TxType::DctDct;
11422- y,11863+ for (idx, &(row, col, tx_px)) in leaves.iter().enumerate() {
11423- px,11864+ let tu_mi = (at_mi.0 + row, at_mi.1 + col);
11424- py,11865+ let (tu_px, tu_py) = (px + col * MI, py + row * MI);
11425- side,11866+ let mut tu_pred = Vec::with_capacity(tx_px * tx_px);
11426- base_q_idx,11867+ for rr in 0..tx_px {
11427- &pred_y,11868+ let start = (row * MI + rr) * side + col * MI;
11428- None,11869+ tu_pred.extend_from_slice(&pred_y[start..start + tx_px]);
11429- )?;11870+ }
11871+ let scan = default_scan(tx_px);
11872+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI);
11873+ let (tu_grid, tu_tx_type) = read_inter_plane(
11874+ dec,
11875+ cdfs,
11876+ inter_txbset_for(tx_px, reduced),
11877+ &scan,
11878+ 0,
11879+ neighbours.around_mi(tu_mi, tx_px)[0],
11880+ mode_for_tx,
11881+ y,
11882+ tu_px,
11883+ tu_py,
11884+ tx_px,
11885+ base_q_idx,
11886+ &tu_pred,
11887+ None,
11888+ Some(tu_skip_ctx),
11889+ )?;
11890+ if idx == 0 {
11891+ first_tx_type = tu_tx_type;
11892+ }
11893+ neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid);
11894+ }
11895+ // `av1_get_tx_type`'s chroma lookup scales the chroma
11896+ // position back to luma, so an inter block's chroma
11897+ // inherits the *first* (top-left) luma unit's coded type.
11898+ luma_tx_type = first_tx_type;
11899+ luma_grid = vec![0i32; side * side];
11900+ } else {
11901+ (luma_grid, luma_tx_type) = read_inter_plane(
11902+ dec,
11903+ cdfs,
11904+ luma_set_inter,
11905+ scan_luma,
11906+ 0,
11907+ around[0],
11908+ mode_for_tx,
11909+ y,
11910+ px,
11911+ py,
11912+ side,
11913+ base_q_idx,
11914+ &pred_y,
11915+ None,
11916+ None,
11917+ )?;
11918+ }
11430 u_grid = read_inter_plane(11919 u_grid = read_inter_plane(
11431 dec,11920 dec,
11432 cdfs,11921 cdfs,
@@ -11442,6 +11931,7 @@ fn decode_inter_block(
11442 base_q_idx,11931 base_q_idx,
11443 &pred_u,11932 &pred_u,
11444 Some(luma_tx_type),11933 Some(luma_tx_type),
11934+ None,
11445 )?11935 )?
11446 .0;11936 .0;
11447 v_grid = read_inter_plane(11937 v_grid = read_inter_plane(
@@ -11459,6 +11949,7 @@ fn decode_inter_block(
11459 base_q_idx,11949 base_q_idx,
11460 &pred_v,11950 &pred_v,
11461 Some(luma_tx_type),11951 Some(luma_tx_type),
11952+ None,
11462 )?11953 )?
11463 .0;11954 .0;
11464 }11955 }
@@ -12076,6 +12567,17 @@ fn decode_inter_block(
12076 interintra_blend(v, cpx, cpy, chroma_side, ii, wedge_mask, &mut pred_v);12567 interintra_blend(v, cpx, cpy, chroma_side, ii, wedge_mask, &mut pred_v);
12077 }12568 }
12078 12569
12570+ vartx_leaves = read_block_tx_size(
12571+ dec,
12572+ cdfs,
12573+ neighbours,
12574+ at_mi,
12575+ side,
12576+ (mi_cols as usize, mi_rows as usize),
12577+ true,
12578+ skip,
12579+ )?
12580+ .1;
12079 if skip {12581 if skip {
12080 y.reconstruct_mc_rect(12582 y.reconstruct_mc_rect(
12081 px,12583 px,
@@ -12110,22 +12612,70 @@ fn decode_inter_block(
12110 } else {12612 } else {
12111 let around = neighbours.around(at, side);12613 let around = neighbours.around(at, side);
12112 let luma_tx_type;12614 let luma_tx_type;
12113- (luma_grid, luma_tx_type) = read_inter_plane(12615+ if let Some(leaves) = vartx_leaves.clone() {
12114- dec,12616+ // spec 5.11.17's transform tree, leaf by leaf in the order
12115- cdfs,12617+ // `read_var_tx_size` coded it: each unit reads its own
12116- luma_set_inter,12618+ // coefficients against the neighbour magnitudes the
12117- scan_luma,12619+ // earlier units already wrote, and reconstructs over its
12118- 0,12620+ // own slice of the block's motion-compensated predictor.
12119- around[0],12621+ let reduced = REDUCED_TX_SET_INTER.with(std::cell::Cell::get);
12120- mode_for_tx,12622+ let mut first_tx_type = TxType::DctDct;
12121- y,12623+ for (idx, &(row, col, tx_px)) in leaves.iter().enumerate() {
12122- px,12624+ let tu_mi = (at_mi.0 + row, at_mi.1 + col);
12123- py,12625+ let (tu_px, tu_py) = (px + col * MI, py + row * MI);
12124- side,12626+ let mut tu_pred = Vec::with_capacity(tx_px * tx_px);
12125- base_q_idx,12627+ for rr in 0..tx_px {
12126- &pred_y,12628+ let start = (row * MI + rr) * side + col * MI;
12127- None,12629+ tu_pred.extend_from_slice(&pred_y[start..start + tx_px]);
12128- )?;12630+ }
12631+ let scan = default_scan(tx_px);
12632+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, tx_px / MI);
12633+ let (tu_grid, tu_tx_type) = read_inter_plane(
12634+ dec,
12635+ cdfs,
12636+ inter_txbset_for(tx_px, reduced),
12637+ &scan,
12638+ 0,
12639+ neighbours.around_mi(tu_mi, tx_px)[0],
12640+ mode_for_tx,
12641+ y,
12642+ tu_px,
12643+ tu_py,
12644+ tx_px,
12645+ base_q_idx,
12646+ &tu_pred,
12647+ None,
12648+ Some(tu_skip_ctx),
12649+ )?;
12650+ if idx == 0 {
12651+ first_tx_type = tu_tx_type;
12652+ }
12653+ neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid);
12654+ }
12655+ // `av1_get_tx_type`'s chroma lookup scales the chroma
12656+ // position back to luma, so an inter block's chroma
12657+ // inherits the *first* (top-left) luma unit's coded type.
12658+ luma_tx_type = first_tx_type;
12659+ luma_grid = vec![0i32; side * side];
12660+ } else {
12661+ (luma_grid, luma_tx_type) = read_inter_plane(
12662+ dec,
12663+ cdfs,
12664+ luma_set_inter,
12665+ scan_luma,
12666+ 0,
12667+ around[0],
12668+ mode_for_tx,
12669+ y,
12670+ px,
12671+ py,
12672+ side,
12673+ base_q_idx,
12674+ &pred_y,
12675+ None,
12676+ None,
12677+ )?;
12678+ }
12129 u_grid = read_inter_plane(12679 u_grid = read_inter_plane(
12130 dec,12680 dec,
12131 cdfs,12681 cdfs,
@@ -12141,6 +12691,7 @@ fn decode_inter_block(
12141 base_q_idx,12691 base_q_idx,
12142 &pred_u,12692 &pred_u,
12143 Some(luma_tx_type),12693 Some(luma_tx_type),
12694+ None,
12144 )?12695 )?
12145 .0;12696 .0;
12146 v_grid = read_inter_plane(12697 v_grid = read_inter_plane(
@@ -12158,6 +12709,7 @@ fn decode_inter_block(
12158 base_q_idx,12709 base_q_idx,
12159 &pred_v,12710 &pred_v,
12160 Some(luma_tx_type),12711 Some(luma_tx_type),
12712+ None,
12161 )?12713 )?
12162 .0;12714 .0;
12163 }12715 }
@@ -12266,6 +12818,16 @@ fn decode_inter_block(
12266 }12818 }
12267 }12819 }
12268 12820
12821+ read_block_tx_size(
12822+ dec,
12823+ cdfs,
12824+ neighbours,
12825+ at_mi,
12826+ side,
12827+ (mi_cols as usize, mi_rows as usize),
12828+ false,
12829+ skip,
12830+ )?;
12269 let reach = Reach::of(side, px, py, y.width, y.height);12831 let reach = Reach::of(side, px, py, y.width, y.height);
12270 if skip {12832 if skip {
12271 y.reconstruct(12833 y.reconstruct(
@@ -12391,14 +12953,22 @@ fn decode_inter_block(
12391 r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().012953 r * SUB_MI as usize, c * SUB_MI as usize, dec.debug_bitpos(), dec.debug_state().0
12392 );12954 );
12393 }12955 }
12394- neighbours.record_rect(12956+ if vartx_leaves.is_some() {
12395- at,12957+ // Plane 0 is already correct per transform unit
12396- write_w,12958+ // ([`Neighbours::record_mi_luma`] above); this writes everything else
12397- write_h,12959+ // [`Neighbours::record_rect`] would (a var-tx block is always square,
12398- mode_for_tx,12960+ // so `write_w == write_h == side`).
12399- uv_predict_mode,12961+ neighbours.record_split_luma(at, side, mode_for_tx, uv_predict_mode, [&u_grid, &v_grid]);
12400- &[luma_grid, u_grid, v_grid],12962+ } else {
12401- );12963+ neighbours.record_rect(
12964+ at,
12965+ write_w,
12966+ write_h,
12967+ mode_for_tx,
12968+ uv_predict_mode,
12969+ &[luma_grid, u_grid, v_grid],
12970+ );
12971+ }
12402 neighbours.record_inter_rect(12972 neighbours.record_inter_rect(
12403 at,12973 at,
12404 write_w,12974 write_w,
@@ -12435,6 +13005,25 @@ fn decode_inter_block(
12435 ref_frame_for_lf13005 ref_frame_for_lf
12436 },13006 },
12437 );13007 );
13008+ // lane-txselect: a var-tx block's deblock edges follow its own transform
13009+ // units, not the block. Chroma still reads `tx_h_grid / 2` (the block's
13010+ // uv transform is not split) -- a known corner-cut of this round.
13011+ if let Some(leaves) = &vartx_leaves {
13012+ for &(row, col, tx_px) in leaves {
13013+ neighbours.fill_lf_grid_rect(
13014+ (at_mi.0 + row, at_mi.1 + col),
13015+ tx_px / MI,
13016+ tx_px / MI,
13017+ tx_px as u8,
13018+ tx_px as u8,
13019+ if globalmv_for_lf {
13020+ -ref_frame_for_lf
13021+ } else {
13022+ ref_frame_for_lf
13023+ },
13024+ );
13025+ }
13026+ }
12438 Ok(())13027 Ok(())
12439 }13028 }
12440 13029
@@ -12552,6 +13141,11 @@ fn decode_inter_block8(
12552 13141
12553 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);13142 let (px, py) = (leaf_mi.1 * MI, leaf_mi.0 * MI);
12554 let (cpx, cpy) = (px / 2, py / 2);13143 let (cpx, cpy) = (px / 2, py / 2);
13144+ // lane-txselect: whether this leaf's `TxMode::Select` var-tx tree took
13145+ // the one split a `BLOCK_8X8` can take (`read_block_tx_size` below) --
13146+ // read back by the luma residual read and the tail's neighbour/loop-filter
13147+ // bookkeeping. Always `false` outside a `TxMode::Select` inter frame.
13148+ let mut split8 = false;
12555 const SIDE: usize = 8;13149 const SIDE: usize = 8;
12556 const CHROMA_SIDE: usize = 4;13150 const CHROMA_SIDE: usize = 4;
12557 13151
@@ -13001,6 +13595,18 @@ fn decode_inter_block8(
13001 mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v);13595 mc::combine_compound(&inter0_v, &inter1_v, fwd_offset, bck_offset, &mut pred_v);
13002 }13596 }
13003 13597
13598+ split8 = read_block_tx_size(
13599+ dec,
13600+ cdfs,
13601+ neighbours,
13602+ leaf_mi,
13603+ SIDE,
13604+ (mi_cols as usize, mi_rows as usize),
13605+ true,
13606+ skip,
13607+ )?
13608+ .1
13609+ .is_some();
13004 if skip {13610 if skip {
13005 y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]);13611 y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]);
13006 u.reconstruct_mc(13612 u.reconstruct_mc(
@@ -13022,27 +13628,23 @@ fn decode_inter_block8(
13022 v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];13628 v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
13023 } else {13629 } else {
13024 let around = neighbours.around_mi(leaf_mi, 8);13630 let around = neighbours.around_mi(leaf_mi, 8);
13025- let luma_tx_type;13631+ let (grid8, luma_tx_type) = read_inter_luma8(
13026- (luma_grid, luma_tx_type) = read_inter_plane(
13027 dec,13632 dec,
13028 cdfs,13633 cdfs,
13029- if reduced_tx_set {13634+ neighbours,
13030- TxbSet::Luma8Inter13635+ leaf_mi,
13031- } else {
13032- TxbSet::Luma8InterSet1
13033- },
13034- scan8,
13035- 0,
13036- around[0],
13037- mode_for_tx,
13038 y,13636 y,
13039 px,13637 px,
13040 py,13638 py,
13041- SIDE,
13042- base_q_idx,
13043 &pred_y,13639 &pred_y,
13044- None,13640+ mode_for_tx,
13641+ base_q_idx,
13642+ scan8,
13643+ scan4,
13644+ reduced_tx_set,
13645+ split8,
13045 )?;13646 )?;
13647+ luma_grid = grid8;
13046 u_grid = read_inter_plane(13648 u_grid = read_inter_plane(
13047 dec,13649 dec,
13048 cdfs,13650 cdfs,
@@ -13058,6 +13660,7 @@ fn decode_inter_block8(
13058 base_q_idx,13660 base_q_idx,
13059 &pred_u,13661 &pred_u,
13060 Some(luma_tx_type),13662 Some(luma_tx_type),
13663+ None,
13061 )?13664 )?
13062 .0;13665 .0;
13063 v_grid = read_inter_plane(13666 v_grid = read_inter_plane(
@@ -13075,6 +13678,7 @@ fn decode_inter_block8(
13075 base_q_idx,13678 base_q_idx,
13076 &pred_v,13679 &pred_v,
13077 Some(luma_tx_type),13680 Some(luma_tx_type),
13681+ None,
13078 )?13682 )?
13079 .0;13683 .0;
13080 }13684 }
@@ -13350,6 +13954,18 @@ fn decode_inter_block8(
13350 interintra_blend(v, cpx, cpy, CHROMA_SIDE, ii, wedge_mask, &mut pred_v);13954 interintra_blend(v, cpx, cpy, CHROMA_SIDE, ii, wedge_mask, &mut pred_v);
13351 }13955 }
13352 13956
13957+ split8 = read_block_tx_size(
13958+ dec,
13959+ cdfs,
13960+ neighbours,
13961+ leaf_mi,
13962+ SIDE,
13963+ (mi_cols as usize, mi_rows as usize),
13964+ true,
13965+ skip,
13966+ )?
13967+ .1
13968+ .is_some();
13353 if skip {13969 if skip {
13354 y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]);13970 y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]);
13355 u.reconstruct_mc(13971 u.reconstruct_mc(
@@ -13371,27 +13987,23 @@ fn decode_inter_block8(
13371 v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];13987 v_grid = vec![0i32; CHROMA_SIDE * CHROMA_SIDE];
13372 } else {13988 } else {
13373 let around = neighbours.around_mi(leaf_mi, 8);13989 let around = neighbours.around_mi(leaf_mi, 8);
13374- let luma_tx_type;13990+ let (grid8, luma_tx_type) = read_inter_luma8(
13375- (luma_grid, luma_tx_type) = read_inter_plane(
13376 dec,13991 dec,
13377 cdfs,13992 cdfs,
13378- if reduced_tx_set {13993+ neighbours,
13379- TxbSet::Luma8Inter13994+ leaf_mi,
13380- } else {
13381- TxbSet::Luma8InterSet1
13382- },
13383- scan8,
13384- 0,
13385- around[0],
13386- mode_for_tx,
13387 y,13995 y,
13388 px,13996 px,
13389 py,13997 py,
13390- SIDE,
13391- base_q_idx,
13392 &pred_y,13998 &pred_y,
13393- None,13999+ mode_for_tx,
14000+ base_q_idx,
14001+ scan8,
14002+ scan4,
14003+ reduced_tx_set,
14004+ split8,
13394 )?;14005 )?;
14006+ luma_grid = grid8;
13395 u_grid = read_inter_plane(14007 u_grid = read_inter_plane(
13396 dec,14008 dec,
13397 cdfs,14009 cdfs,
@@ -13407,6 +14019,7 @@ fn decode_inter_block8(
13407 base_q_idx,14019 base_q_idx,
13408 &pred_u,14020 &pred_u,
13409 Some(luma_tx_type),14021 Some(luma_tx_type),
14022+ None,
13410 )?14023 )?
13411 .0;14024 .0;
13412 v_grid = read_inter_plane(14025 v_grid = read_inter_plane(
@@ -13424,6 +14037,7 @@ fn decode_inter_block8(
13424 base_q_idx,14037 base_q_idx,
13425 &pred_v,14038 &pred_v,
13426 Some(luma_tx_type),14039 Some(luma_tx_type),
14040+ None,
13427 )?14041 )?
13428 .0;14042 .0;
13429 }14043 }
@@ -13488,6 +14102,16 @@ fn decode_inter_block8(
13488 }14102 }
13489 }14103 }
13490 14104
14105+ read_block_tx_size(
14106+ dec,
14107+ cdfs,
14108+ neighbours,
14109+ leaf_mi,
14110+ SIDE,
14111+ (mi_cols as usize, mi_rows as usize),
14112+ false,
14113+ skip,
14114+ )?;
13491 let reach = Reach::of(SIDE, px, py, y.width, y.height);14115 let reach = Reach::of(SIDE, px, py, y.width, y.height);
13492 if skip {14116 if skip {
13493 y.reconstruct(14117 y.reconstruct(
@@ -13599,8 +14223,38 @@ fn decode_inter_block8(
13599 )?;14223 )?;
13600 }14224 }
13601 }14225 }
14226+ // lane-txselect: a split leaf's plane-0 neighbour context is per 4x4
14227+ // transform unit (written by `record_mi_luma` inside `read_inter_luma8`),
14228+ // but `record_mi` rewrites all three planes of these cells at once -- so
14229+ // save plane 0 across it, exactly as `record_split_luma` leaves plane 0
14230+ // alone at the bigger block sizes.
14231+ let saved_luma_ctx = split8.then(|| {
14232+ (
14233+ [
14234+ neighbours.left[leaf_mi.0][0],
14235+ neighbours.left[leaf_mi.0 + 1][0],
14236+ ],
14237+ [
14238+ neighbours.above[leaf_mi.1][0],
14239+ neighbours.above[leaf_mi.1 + 1][0],
14240+ ],
14241+ )
14242+ });
13602 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);14243 neighbours.record_mi(leaf_mi, 8, &[luma_grid, u_grid, v_grid]);
13603- neighbours.fill_lf_grid(leaf_mi, 2, 8, if is_inter { LAST_FRAME } else { 0 });14244+ if let Some((left, above)) = saved_luma_ctx {
14245+ for (cell, state) in left.into_iter().enumerate() {
14246+ neighbours.left[leaf_mi.0 + cell][0] = state;
14247+ }
14248+ for (cell, state) in above.into_iter().enumerate() {
14249+ neighbours.above[leaf_mi.1 + cell][0] = state;
14250+ }
14251+ }
14252+ neighbours.fill_lf_grid(
14253+ leaf_mi,
14254+ 2,
14255+ if split8 { 4 } else { 8 },
14256+ if is_inter { LAST_FRAME } else { 0 },
14257+ );
13604 Ok((skip, is_inter, skip_mode, compound_ctx8, leaf_refs))14258 Ok((skip, is_inter, skip_mode, compound_ctx8, leaf_refs))
13605 }14259 }
13606 14260
@@ -13671,6 +14325,9 @@ pub fn decode_inter_frame_tile(
13671 false,14325 false,
13672 [0; 2],14326 [0; 2],
13673 true,14327 true,
14328+ // `tx_select`: this raw entry point decodes this crate's own encoder's
14329+ // streams, which always write `TxMode::Largest`.
14330+ false,
13674 false,14331 false,
13675 false,14332 false,
13676 false,14333 false,
@@ -13737,6 +14394,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
13737 // `Set1` coefficient tables at 16x16/8x8 rather than the reduced14394 // `Set1` coefficient tables at 16x16/8x8 rather than the reduced
13738 // 2-symbol ones -- see [`TxbSet::Luma16InterSet1`]/[`TxbSet::Luma8InterSet1`]).14395 // 2-symbol ones -- see [`TxbSet::Luma16InterSet1`]/[`TxbSet::Luma8InterSet1`]).
13739 reduced_tx_set: bool,14396 reduced_tx_set: bool,
14397+ // lane-txselect: this frame header's own `tx_mode == TxMode::Select`
14398+ // bit (spec 5.9.14). Together with `reduced_tx_set` it is stashed in a
14399+ // thread-local by [`set_inter_tx_mode`] rather than threaded through
14400+ // `decode_inter_block`'s forty parameters -- both are frame-constant, and
14401+ // only [`read_block_tx_size`]/the var-tx residual loop read them.
14402+ tx_select: bool,
13740 // lane-motionmode round 1/3: this frame header's own `is_motion_mode_switchable`/14403 // lane-motionmode round 1/3: this frame header's own `is_motion_mode_switchable`/
13741 // `allow_warped_motion` bits, threaded to every `decode_inter_block`/14404 // `allow_warped_motion` bits, threaded to every `decode_inter_block`/
13742 // `decode_inter_block8` call below (spec 5.11.24's `read_motion_mode`).14405 // `decode_inter_block8` call below (spec 5.11.24's `read_motion_mode`).
@@ -13753,6 +14416,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
13753 // param -- only `q_present`/`q_res` are read.14416 // param -- only `q_present`/`q_res` are read.
13754 delta: DeltaParams,14417 delta: DeltaParams,
13755 ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> {14418 ) -> Result<(Picture, Cdfs, crate::motion_field::MotionField)> {
14419+ set_inter_tx_mode(tx_select, reduced_tx_set);
13756 let tpl_frame = tpl_field.map(|field| TplFrameArgs {14420 let tpl_frame = tpl_field.map(|field| TplFrameArgs {
13757 field,14421 field,
13758 order_hint_bits,14422 order_hint_bits,
crates/ec-av1/src/refusal_inventory.rsmodified+2 -1
@@ -64,7 +64,8 @@ const REFUSALS: &[&str] = &[
64 "a reference picture whose height does not match this frame's own true size",64 "a reference picture whose height does not match this frame's own true size",
65 "a show_existing_frame header naming an empty reference slot",65 "a show_existing_frame header naming an empty reference slot",
66 "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): av1_find_projection/the affine warp filter are not ported, only motion_mode_allowed's alphabet choice is",66 "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): av1_find_projection/the affine warp filter are not ported, only motion_mode_allowed's alphabet choice is",
67- "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)",67+ "an inter var-tx tree with a leaf transform larger than 32x32",
68+ "an intra block in an inter frame whose tx_depth splits its luma transform (round 1)",
68 "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)",69 "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)",
69 "an inter frame with no key frame before it",70 "an inter frame with no key frame before it",
70 "an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path recurses a superblock only as SPLIT)",71 "an inter SB-level partition type other than NONE or SPLIT (this decoder's inter tile path recurses a superblock only as SPLIT)",
crates/ec-av1/src/stream.rsmodified+247 -18
@@ -225,24 +225,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
225 // now read (`maybe_read_cdef_idx` in decode.rs) and threaded into225 // now read (`maybe_read_cdef_idx` in decode.rs) and threaded into
226 // [`crate::decode::apply_cdef`]'s per-superblock strength lookup, so226 // [`crate::decode::apply_cdef`]'s per-superblock strength lookup, so
227 // a `cdef_bits > 0` stream no longer needs this refusal.227 // a `cdef_bits > 0` stream no longer needs this refusal.
228- // An intra frame's `decode_key_frame_tile*` now reads `tx_depth`228+ // Both frame types now read their transform size under
229- // under `TxMode::Select` (lane-av1txsel, spec 5.11.16): the key-frame229+ // `TxMode::Select`: an intra frame's `decode_key_frame_tile*` reads
230- // decode path threads `tx_select` through `decode_block`/230+ // `tx_depth` (lane-av1txsel, spec 5.11.16), and an inter frame's
231- // `decode_leaf8`, and refuses on its own (a named `unsupported`, not231+ // `decode_inter_block`/`decode_inter_block8` read the recursive
232- // a silent desync) the one case it still cannot code -- a resolved232+ // `txfm_split` var-tx tree (lane-txselect, spec 5.11.17) -- so the
233- // 4x4 luma transform, which has no coefficient tables here. This233+ // blanket inter-frame refusal that used to stand here is gone. What
234- // refusal is narrowed to what genuinely still has no reader at all:234+ // remains refused is named at its own site in `read_block_tx_size`.
235- // `decode_inter_frame`'s inter path never threads `tx_select`
236- // through its own block loop, so an inter frame under
237- // `TxMode::Select` still desyncs the same way the comment above used
238- // to describe for every frame -- lane-av1real r3's
239- // luma-near-flat-vs-ffmpeg-gradient bug.
240- if header.tx_mode == TxMode::Select && header.frame_type != FrameType::Key {
241- return Err(Error::unsupported(
242- "AV1 decode_stream",
243- "an inter frame using TxMode::Select (this decoder's inter path never reads a tx_depth symbol, so it desyncs after the first block's mode)",
244- ));
245- }
246 // lane-av1real r11's blindness-audit sweep (`read_intra_frame_mode_info`,235 // lane-av1real r11's blindness-audit sweep (`read_intra_frame_mode_info`,
247 // libaom decodemv.c): three more per-block/per-SB symbols this crate236 // libaom decodemv.c): three more per-block/per-SB symbols this crate
248 // never reads at all, each gated by a header field this decoder237 // never reads at all, each gated by a header field this decoder
@@ -679,6 +668,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
679 header.skip_mode_present,668 header.skip_mode_present,
680 header.skip_mode_frame,669 header.skip_mode_frame,
681 header.reduced_tx_set,670 header.reduced_tx_set,
671+ header.tx_mode == TxMode::Select,
682 header.is_motion_mode_switchable,672 header.is_motion_mode_switchable,
683 header.allow_warped_motion,673 header.allow_warped_motion,
684 header.allow_screen_content_tools,674 header.allow_screen_content_tools,
@@ -3423,6 +3413,245 @@ mod tests {
3423 );3413 );
3424 }3414 }
3425 3415
3416+ /// lane-txselect's decisive gate: a real aomenc INTER sequence WITHOUT
3417+ /// `--enable-tx-size-search=0`, the flag every other inter recipe in this
3418+ /// file pins off precisely to keep the stream on `TxMode::Largest`.
3419+ /// Dropped, aomenc takes its own default (`TX_MODE_SELECT` -- which is
3420+ /// what both of the user's real films use), and an inter block's
3421+ /// transform size is then the recursive `txfm_split` tree of spec
3422+ /// 5.11.17 rather than one whole-block transform. A stream that decoded
3423+ /// pixel-exact while every `txfm_split` symbol resolved to "no split"
3424+ /// would prove nothing (it is `TxMode::Largest` by another name), so this
3425+ /// gate hard-asserts BOTH counters: at least one `txfm_split` symbol read
3426+ /// AND at least one split actually taken. Exhausting every attempt is a
3427+ /// FAILURE, not a SKIP -- an unfired gate is a vacuous gate.
3428+ #[test]
3429+ fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact() {
3430+ tx_select_inter_gate(8);
3431+ }
3432+
3433+ /// The 10-bit arm of the gate above (lane-txselect r2): both of the
3434+ /// user's films are `yuv420p10le` and var-tx is exactly the tool they
3435+ /// use, so an 8-bit-only proof would not reach them. Same recipe plus
3436+ /// `-b 10 --input-bit-depth=10`.
3437+ #[test]
3438+ fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact_10bit() {
3439+ tx_select_inter_gate(10);
3440+ }
3441+
3442+ fn tx_select_inter_gate(bit_depth: u32) {
3443+ if !have_ffmpeg() {
3444+ eprintln!(
3445+ "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no ffmpeg"
3446+ );
3447+ return;
3448+ }
3449+ if !have_aomenc() {
3450+ eprintln!(
3451+ "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no aomenc at {}",
3452+ aomenc_path().display()
3453+ );
3454+ return;
3455+ }
3456+ let (width, height, frame_count) = (64usize, 64usize, 4usize);
3457+ let mut refusals = Vec::new();
3458+ for attempt in 0..40u32 {
3459+ let seed = 42 + attempt;
3460+ // Detail is what makes aomenc's RD prefer a split transform; a
3461+ // flat gradient resolves every `txfm_split` to 0. `mandelbrot`'s
3462+ // fractal boundary is the same source the sibling intra tx-select
3463+ // gate uses, at a different `start_scale` per attempt.
3464+ let source = format!(
3465+ "mandelbrot=size=64x64:start_scale={}:rate=25",
3466+ 5.0 - f64::from(attempt) * 0.06
3467+ );
3468+ let y4m = Command::new("ffmpeg")
3469+ .args([
3470+ "-v",
3471+ "error",
3472+ "-f",
3473+ "lavfi",
3474+ "-i",
3475+ &source,
3476+ // Desaturated chroma: `uv_mode` stays DC_PRED, so the
3477+ // still-refused directional-chroma gap never fires and
3478+ // luma detail alone drives the transform split.
3479+ "-vf",
3480+ "hue=s=0",
3481+ "-pix_fmt",
3482+ if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" },
3483+ // y4m carries no official 10-bit tag; ffmpeg writes one
3484+ // only under `-strict -1` (a no-op at 8 bit).
3485+ "-strict",
3486+ "-1",
3487+ "-t",
3488+ "0.16",
3489+ "-f",
3490+ "yuv4mpegpipe",
3491+ "-strict",
3492+ "-1",
3493+ "-",
3494+ ])
3495+ .stdin(Stdio::null())
3496+ .stdout(Stdio::piped())
3497+ .stderr(Stdio::piped())
3498+ .output()
3499+ .expect("ffmpeg failed to run");
3500+ assert!(
3501+ y4m.status.success(),
3502+ "ffmpeg fixture: {}",
3503+ String::from_utf8_lossy(&y4m.stderr)
3504+ );
3505+ let depth_args: &[&str] = if bit_depth == 10 {
3506+ &["-b", "10", "--input-bit-depth=10"]
3507+ } else {
3508+ &[]
3509+ };
3510+ let mut child = Command::new(aomenc_path())
3511+ .args(depth_args)
3512+ .args([
3513+ "--codec=av1",
3514+ "--passes=1",
3515+ "--end-usage=q",
3516+ "--cq-level=55",
3517+ "--cpu-used=0",
3518+ "--lag-in-frames=0",
3519+ "--auto-alt-ref=0",
3520+ "--kf-max-dist=1000",
3521+ "--threads=1",
3522+ "--row-mt=0",
3523+ "--enable-order-hint=0",
3524+ "--enable-warped-motion=0",
3525+ "--enable-obmc=0",
3526+ "--enable-masked-comp=0",
3527+ "--enable-interintra-comp=0",
3528+ "--enable-dist-wtd-comp=0",
3529+ "--enable-diff-wtd-comp=0",
3530+ "--enable-onesided-comp=0",
3531+ "--enable-interintra-wedge=0",
3532+ "--enable-smooth-interintra=0",
3533+ "--enable-rect-partitions=0",
3534+ "--enable-ab-partitions=0",
3535+ "--enable-1to4-partitions=0",
3536+ "--enable-filter-intra=0",
3537+ "--enable-smooth-intra=0",
3538+ "--enable-paeth-intra=0",
3539+ "--enable-directional-intra=0",
3540+ "--enable-angle-delta=0",
3541+ // DELIBERATELY ABSENT: --enable-tx-size-search=0.
3542+ "--enable-cdef=0",
3543+ "--enable-restoration=0",
3544+ "--max-partition-size=32",
3545+ // Sub-16 inter partitions are a separate named refusal
3546+ // (this decoder codes no inter block below 16x16 through
3547+ // the square path this gate drives), and detailed content
3548+ // makes aomenc's RD reach for them on nearly every seed.
3549+ "--min-partition-size=16",
3550+ "--enable-palette=0",
3551+ "--enable-intrabc=0",
3552+ "--enable-cfl-intra=0",
3553+ "--enable-ref-frame-mvs=0",
3554+ "--obu",
3555+ "-o",
3556+ "-",
3557+ "-",
3558+ ])
3559+ .stdin(Stdio::piped())
3560+ .stdout(Stdio::piped())
3561+ .stderr(Stdio::piped())
3562+ .spawn()
3563+ .expect("aomenc failed to start");
3564+ child
3565+ .stdin
3566+ .take()
3567+ .expect("aomenc stdin")
3568+ .write_all(&y4m.stdout)
3569+ .expect("writing y4m to aomenc");
3570+ let out = child.wait_with_output().expect("aomenc failed to run");
3571+ assert!(
3572+ out.status.success(),
3573+ "aomenc refused the fixture: {}",
3574+ String::from_utf8_lossy(&out.stderr)
3575+ );
3576+ let stream = out.stdout;
3577+ let (reads_before, hits_before) =
3578+ (decode::txfm_split_reads(), decode::txfm_split_hits());
3579+ let frames = match decode_stream(&stream) {
3580+ Ok(frames) => frames,
3581+ Err(e) => {
3582+ let msg = e.to_string();
3583+ assert!(
3584+ msg.contains("unsupported"),
3585+ "tx-select inter decode failed outright (seed {seed}): {msg}"
3586+ );
3587+ refusals.push(format!("seed {seed}: {msg}"));
3588+ continue;
3589+ }
3590+ };
3591+ let (reads, hits) = (
3592+ decode::txfm_split_reads() - reads_before,
3593+ decode::txfm_split_hits() - hits_before,
3594+ );
3595+ if hits == 0 {
3596+ refusals.push(format!(
3597+ "seed {seed}: decoded, but no block took a txfm_split ({reads} symbols read)"
3598+ ));
3599+ continue;
3600+ }
3601+ let ffmpeg_frames = if bit_depth == 10 {
3602+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
3603+ } else {
3604+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
3605+ };
3606+ assert_eq!(frames.len(), frame_count);
3607+ eprintln!(
3608+ "txselect gate {bit_depth}-bit seed={seed}: txfm_split reads={reads} splits taken={hits}"
3609+ );
3610+ // Name the first differing sample before the assert fires: a
3611+ // 64x64 plane's `assert_eq!` output is 4096 numbers, useless for
3612+ // locating a desync.
3613+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3614+ for (plane, (g, w)) in [
3615+ ("Y", (&got.y, &want.y)),
3616+ ("U", (&got.u, &want.u)),
3617+ ("V", (&got.v, &want.v)),
3618+ ] {
3619+ let stride = if plane == "Y" { width } else { width / 2 };
3620+ if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) {
3621+ eprintln!(
3622+ "txselect gate seed={seed}: frame {i} {plane} first diff at \
3623+ ({}, {}) got {} want {} ({} samples differ)",
3624+ at % stride,
3625+ at / stride,
3626+ g[at],
3627+ w[at],
3628+ g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(),
3629+ );
3630+ let coords: Vec<String> = g
3631+ .iter()
3632+ .zip(w.iter())
3633+ .enumerate()
3634+ .filter(|(_, (a, b))| a != b)
3635+ .take(12)
3636+ .map(|(k, (a, b))| format!("({},{})={a}/{b}", k % stride, k / stride))
3637+ .collect();
3638+ eprintln!("txselect gate seed={seed}: frame {i} {plane} diffs {coords:?}");
3639+ }
3640+ }
3641+ }
3642+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3643+ assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})");
3644+ assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})");
3645+ assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})");
3646+ }
3647+ return;
3648+ }
3649+ panic!(
3650+ "tx_select_inter_gate({bit_depth}) never observed a taken txfm_split:\n{}",
3651+ refusals.join("\n")
3652+ );
3653+ }
3654+
3426 /// lane-chroma r2 stage 1: a real aomenc key frame with3655 /// lane-chroma r2 stage 1: a real aomenc key frame with
3427 /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`)3656 /// `--enable-smooth-intra=1` (opposite of every sibling recipe's `=0`)
3428 /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still-3657 /// and `--enable-paeth-intra=0` -- paeth chroma stays off so the still-
lanes/txselect-r1.report.mdadded+128 -0
@@ -0,0 +1,128 @@
1+# lane-txselect r1 — inter var-tx (`TxMode::Select`), spec 5.11.17
2+
3+Branch `lane-txselect`, commit `138c558` (on top of the orchestrator's WIP
4+snapshot `16d83e4`, itself off main `3808cf8`).
5+
6+## What changed
7+
8+- `crates/ec-av1/src/decode.rs`
9+ - `read_block_tx_size` / `read_var_tx_size` / `txfm_partition_ctx` /
10+ `txfm_partition_update` / `set_txfm_ctxs` — the recursive `txfm_split`
11+ tree, max square transform down to `MAX_VARTX_DEPTH = 2`, ported against
12+ `av1/decoder/decodeframe.c:1029-1090` and `av1/common/av1_common_int.h`
13+ (WIP snapshot; verified line by line against the oracle source this round).
14+ - `TXFM_CTX_INIT = 64` (`decode.rs`, next to `MAX_VARTX_DEPTH`) — **root
15+ cause of the first gate failure this round**. The WIP initialised
16+ `Neighbours::above_txfm`/`left_txfm` to 0 with a comment claiming that is
17+ "libaom's own tile-start value". It is not:
18+ `av1_common_int.h:1624` memsets the above txfm row to
19+ `tx_size_wide[TX_SIZES_LARGEST]` and `:1632` the left buffer to
20+ `tx_size_high[TX_SIZES_LARGEST]` — 64. An unwritten neighbour reads as the
21+ *widest* transform, so every frame-edge block took the wrong
22+ `txfm_partition` context.
23+ - `read_inter_luma8` + `split8` in `decode_inter_block8` — the 8x8 inter
24+ leaf now reads its own `txfm_split` symbol (a `BLOCK_8X8` does signal one)
25+ and, when it splits, decodes four 4x4 units, keeping plane-0 neighbour
26+ context per unit across the tail `record_mi`. All three of that function's
27+ branches (compound, single-ref, intra-in-inter) now call
28+ `read_block_tx_size`; without this an 8x8 inter block under `Select`
29+ desynced at its first coefficient.
30+ - two narrow refusals at their own site: a var-tx leaf larger than 32x32 (no
31+ 64-point *inter* coefficient tables here) and an intra block in an inter
32+ frame whose `tx_depth` splits (that path predicts the whole block at once).
33+- `crates/ec-av1/src/cdf.rs`, `cdf_state.rs` (WIP): `TXFM_PARTITION` (21
34+ contexts) in the table set, adaptation and the per-frame counter reset;
35+ `Luma4Inter`/`Luma4InterSet1` coefficient sets.
36+- `crates/ec-av1/src/stream.rs`
37+ - the blanket refusal *"an inter frame using TxMode::Select …"* is deleted,
38+ and `tx_mode == TxMode::Select` is threaded into
39+ `decode_inter_frame_tile_with_cdfs` (new `tx_select` param → thread-local
40+ `set_inter_tx_mode`).
41+ - new gate `a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact`.
42+- `crates/ec-av1/src/refusal_inventory.rs`: −1 blanket refusal, +2 narrow ones.
43+ `gate_coverage.rs` needs no change: it derives only `--enable-*` tool flags,
44+ and `--enable-tx-size-search` is *present* (as `=0`) in the sibling gates, so
45+ the tool was never on its `NEVER_EXERCISED` list.
46+
47+## How the existing inter gates restricted tx-mode
48+
49+`--enable-tx-size-search=0` — it appears **39** times in `stream.rs`
50+(`grep -c '"--enable-tx-size-search=0"'`), i.e. every inter gate. That flag is
51+exactly what pins a stream to `TxMode::Largest`. The new gate is the same
52+recipe as `a_real_aomenc_inter_sequence_with_cdf_forwarding_decodes_pixel_exact`
53+with that flag DELIBERATELY ABSENT (plus `--min-partition-size=16`, because
54+detailed content otherwise makes aomenc pick sub-16 inter partitions — a
55+separate, already-named refusal, hit on 30+ of 40 seeds).
56+
57+## Gate result — RED, honestly
58+
59+```
60+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-txselect EC_AV1_REQUIRE_AOMENC=1 \
61+ cargo test -p ec-av1 --lib a_real_aomenc_inter_sequence_with_tx_select
62+```
63+
64+EVIDENCE: cargo test stderr (seed 43) | aomenc default tx-mode, 4-frame 64x64
65+mandelbrot inter sequence, decode_stream vs ffmpeg per frame |
66+`txfm_split reads=22 splits taken=8`; frame 0 (key) and frame 1 (first inter
67+frame, var-tx active) pixel-exact on Y/U/V; frame 2 Y first differs at (59,14)
68+`got 143 want 144`, 1774/4096 samples; frame 3 differs from (0,0).
69+
70+So: the var-tx read + per-TU residual path is real and correct for a whole key
71+frame and a whole inter frame, and the gate fires (8 splits actually taken).
72+It does not yet pass. **No refusal should be considered "proven lifted" on this
73+evidence** — the branch is not merge-ready.
74+
75+Before the `TXFM_CTX_INIT` fix the same gate failed at frame 2 (32,0) with
76+3209/4096 samples differing; after it, the first divergence moved to (59,14)
77+with 1774 — the fix is a real advance, not a reshuffle.
78+
79+## Residue
80+
81+- fix-now (next round, blocks the merge): frame 2 divergence. Shape: rows 0..13
82+ of frame 2 match everywhere; the first differing samples are on rows 14/15
83+ (x 34..62) with deltas of 1..3, then the error spreads to 43% of the frame.
84+ That is a late-in-block divergence inside the second/third 16x16..32x32
85+ block of the top block row, not a whole-frame desync from symbol 0.
86+ Next step is the ledger's blessed rung, not more reasoning: instrumented
87+ `aomdec` range ladder (`EC_TRACE=1`) vs our `EC_TRACE_MODE_STEP` on frame 2
88+ only, comparing msac RANGE element by element (never `tell()`), starting at
89+ the first block of frame 2. Prime suspects, in order: (1) `txfm_partition`
90+ CDF *adaptation* forwarded into frame 2 (frame 1 is clean, frame 2 is the
91+ first frame that inherits an adapted copy — the "CDF counter not reset"
92+ class, though `reset_counts` does list it); (2) `tx_size_context` for an
93+ intra block in an inter frame, which still reads the deblock `tx_grid`
94+ instead of libaom's `above_txfm_context`/`left_txfm_context` with the
95+ `is_inter_block` → block-size override (`pred_common.h:342-371`) — a known,
96+ unported divergence introduced the moment inter neighbours carry split
97+ transforms; (3) the deblock tx grid written per var-tx leaf.
98+- deferred(the frame-2 fix): 10-bit gate — his films are `yuv420p10le` and
99+ 10-bit is a separate standing refusal (`Picture` planes are `Vec<u8>`), so a
100+ 10-bit tx-select gate would prove nothing this round.
101+- deferred(the frame-2 fix): film probe (`decode_probe` on 0.4 s of each film)
102+ — pointless until the 8-bit gate is green.
103+- accepted (documented corner-cut, in the code): a var-tx block's chroma
104+ deblock edges read `tx_h_grid / 2`, i.e. they follow the luma leaves even
105+ though the block's uv transform is not split.
106+
107+## Suite totals
108+
109+```
110+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-txselect cargo test -p ec-av1 --lib
111+test result: FAILED. 267 passed; 1 failed; 23 ignored; 0 measured; 0 filtered out;
112+finished in 1146.75s
113+```
114+
115+The single failure is this lane's own new gate
116+(`a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact`), red for the
117+frame-2 reason above. No pre-existing test regressed: the same 267 pass with the
118+blanket `TxMode::Select` inter refusal removed.
119+
120+Measured at `138c558`. Two commits landed after it:
121+- `ecc71ec` — this report only, no code.
122+- `3c174b6` — `tx_size_context_txfm`, reachable from exactly one call site
123+ (`read_block_tx_size`'s intra branch, new code this lane); `read_tx_size`'s
124+ new `ctx_override` is `None` at both pre-existing key-frame call sites
125+ (`decode.rs:4934`, `:5346`), so it cannot move any of the 267. Re-verified
126+ after it: the gate (still red, byte-identical failure), plus
127+ `refusal_inventory` + `gate_coverage` (5 passed, 0 failed). The full 1146 s
128+ suite was NOT re-run at `3c174b6`.
lanes/txselect-r2.report.mdadded+114 -0
@@ -0,0 +1,114 @@
1+# lane-txselect r2 — the frame-2 divergence: a missing eob_pt class dimension
2+
3+Branch `lane-txselect`, on top of `fb6b74f` (r1's report commit, off main `3808cf8`).
4+
5+## Root cause
6+
7+`read_eob` picks between the 2D and the `TX_CLASS_HORIZ`/`TX_CLASS_VERT`
8+eob_pt CDF (`decode.rs:1384`, libaom `decodetxb.c:200`
9+`eob_multi_ctx = (tx_class == TX_CLASS_2D) ? 0 : 1`). Only the 4x4 and 8x8
10+LUMA sets ever carried a class-1 sibling (`eob_pt_16_luma_class1`,
11+`eob_pt_64_luma_class1`, added by lane-av1tx4 r5); every other `TxbSet` had
12+`eob_pt_class1: None`, so a 1D-class TU silently read (and adapted) the
13+class-0 table. Instance of [[cdf-row-held-constant]] / the class dimension
14+half of [[table-indexed-by-raw-size]].
15+
16+`TxMode::Select` is what made it reachable: a 32x32 inter block's var-tx
17+leaf is a **16x16** luma TU, whose inter tx set is
18+`EXT_TX_SET_DTT9_IDTX_1DDCT` — the only 16x16 set holding `V_DCT`/`H_DCT`.
19+(16x16 intra reads `TX_SET_INTRA_2`, all-2D; 32x32 and up read
20+`DCT_IDTX`/`DCTONLY`, also all-2D — so 16x16 inter is exactly the hole.)
21+
22+Sweep of the same shape: every reachable size now carries its sibling —
23+`eob_pt_256_luma_class1` plus the three chroma ones
24+(`eob_pt_256/64/16_chroma_class1`; an *inter* block's chroma TU inherits its
25+luma unit's `tx_type`, so 1D classes reach chroma too). 32-point and larger
26+need none, by their tx sets.
27+
28+## What changed
29+
30+- `crates/ec-av1/src/cdf.rs` (EOF): `EOB_PT_256_LUMA_CLASS1*`,
31+ `EOB_PT_256_CHROMA_CLASS1*`, `EOB_PT_64_CHROMA_CLASS1*`,
32+ `EOB_PT_16_CHROMA_CLASS1*` — `av1_default_eob_multi{256,64,16}_cdfs[q][plane][1]`,
33+ `token_cdfs.h:773/811/851`, all four q-contexts.
34+- `crates/ec-av1/src/cdf_state.rs`: the four fields, their `pick(q_ctx, …)`
35+ defaults, their lines in the per-frame counter reset (class
36+ [[cdf-counter-not-reset]]), and `eob_pt_class1: Some(…)` on
37+ `Luma16`/`Luma16Inter`/`Luma16InterSet1`/`Chroma16`/`Chroma8`/`Chroma4`.
38+- `crates/ec-av1/src/stream.rs`: the gate body becomes
39+ `tx_select_inter_gate(bit_depth)` with two `#[test]` arms — the existing
40+ 8-bit one and a new `…_decodes_pixel_exact_10bit` (`-b 10
41+ --input-bit-depth=10`, `yuv420p10le` fixture under `-strict -1`, compared
42+ through `ffmpeg_decode_sequence_10bit`).
43+
44+No refusal string changed this round (r1 lifted the blanket
45+`TxMode::Select` one; it is now actually proven).
46+
47+## Method (what found it, in order)
48+
49+1. Pinned the r1 failing stream: seed-43 recipe → `s43.obu`,
50+ sha256 `d0ba79bbdd34317fa3864c824026e0b905dea0d9add540e646281a1ae23e3d57`.
51+2. `EC_AV1_PREFILT_DUMP` ours vs instrumented aomdec: frame 2 already
52+ differed BEFORE the loop filter (1721 luma samples, chroma clean) — so
53+ not the deblock tx grid, which was r1's leading suspect.
54+3. `EC_TRACE_MODE_STEP` matched everywhere (it only instruments the intra
55+ path); `EC_TRACE_COEFF` on both, compared by msac RANGE: the first
56+ divergent element is the **`eob` of the 16x16 luma var-tx leaf at
57+ mi (4,8)** of the 32x32 block at mi (0,8) — entry `rng=42600`
58+ (`all_zero`) and `rng=33264` (`tx_type`) identical, then ref
59+ `eob=248 rng=65032` vs ours `eob=247 rng=56584`.
60+4. `EC_EOBPT_DUMP` on aomdec gave `tx_size=2 eob_multi_size=4 txs_ctx=2`;
61+ ours read `tx_type value=1 len=13` = `V_DCT` (class VERT) yet took the
62+ class-0 CDF. `eob_pt_class1: None` on `Luma16InterSet1` was the line.
63+
64+## Gate — GREEN, both arms
65+
66+```
67+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-txselect EC_AV1_REQUIRE_AOMENC=1 \
68+ cargo test -p ec-av1 --lib a_real_aomenc_inter_sequence_with_tx_select -- --nocapture
69+```
70+
71+EVIDENCE: cargo test stderr | 4-frame 64x64 mandelbrot inter sequence, aomenc
72+default tx-mode (`--enable-tx-size-search` deliberately absent), decode_stream
73+vs ffmpeg per frame, 8-bit and 10-bit arms | `txselect gate 8-bit seed=42:
74+txfm_split reads=22 splits taken=3`, `txselect gate 10-bit seed=42:
75+txfm_split reads=25 splits taken=6`, `test result: ok. 2 passed; 0 failed`.
76+
77+EVIDENCE: /tmp/…/scratchpad/{ref,ours}.f0..f3 | `EC_AV1_PREFILT_DUMP` on
78+instrumented aomdec and on `decode_probe s43.obu` (r1's own failing seed-43
79+stream) | `cmp -l` 0 differing bytes on all four frames' Y+U+V pre-filter
80+planes (was 0 / 0 / 1721 / 3647 before the fix).
81+
82+10-bit note: the 10-bit arm passes, so this lane owes lane-hbdinter nothing.
83+
84+## Suite
85+
86+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (full, this branch):
87+**269 passed / 0 failed / 23 ignored**, 877.86s. The earlier run of the same
88+command before the 10-bit arm was added was
89+**268 passed / 0 failed / 23 ignored** (r1: 267/1/23, the one failure being
90+this lane's gate).
91+
92+## Film probe (0.4 s, `-c:v copy -f obu`)
93+
94+- ReelC: `REFUSED: unsupported: AV1 tile (a 32x32 partition type this decoder
95+ does not code (value=4))`
96+- ReelB: `REFUSED: unsupported: AV1 tile (a partition below 8x8 (this
97+ decoder codes no leaf smaller than 8x8))`
98+
99+Both are other lanes' refusals, reached in the first tile's partition tree —
100+strictly upstream of anything this round touched, so the "before" value is
101+identical by construction (not separately rebuilt: `deferred(nothing)` —
102+measuring it would mean a second full build of `fb6b74f` for a string that
103+cannot move).
104+
105+## Residue
106+
107+- accepted (documented corner-cut, unchanged from r1, `decode.rs:11447`): a
108+ var-tx block's **chroma** deblock edges follow `tx_h_grid / 2`, i.e. the
109+ luma leaves, though the block's uv transform is not split. Ceiling: a
110+ chroma deblock edge at a luma-only transform seam. Not observable in this
111+ gate (`--enable-cdef=0`, and both arms are chroma-exact through 4 frames);
112+ upgrade path = a per-plane tx grid, not a scalar.
113+- accepted: the two narrow refusals r1 added stay (a var-tx leaf >32x32; an
114+ intra block in an inter frame whose `tx_depth` splits).