forge
Explore
Log in

Don't you dare go Hollow

Merge main 06d856d into lane-palette2

Browse files at this commit

2b5b4fad80f0dfd9eccc053655eb44f42bade1caAhmet Kaan GümüşParent: e0183b24463654
decode.rs reconstruct_rect: keep the lane's PALETTE_PRED override wrapper, with
main's EC_DEBUG_EDGES trace moved inside the else after edges_rect.
refusal_inventory: main's list minus the screen-content palette string (this
lane lifted it), plus the lane's two palette strings; main's 1:4 SB string kept.

27 changed files +6711 -575

crates/ec-av1/src/cdf.rsmodified+138 -21
@@ -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
@@ -266,18 +293,36 @@ pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [
266 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0,293 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0,
267 ];294 ];
268 295
269-/// `av1_default_eob_multi512_cdfs[*][1][*]` (`token_cdfs.h:874-901`,296+/// `av1_default_eob_multi512_cdfs[2][1][0]` (`token_cdfs.h:874-901`,
270-/// lane-sbpart): the end-of-block group of a CHROMA transform with 512 coded297+/// lane-part32 r4): the end-of-block group of a CHROMA transform with 512
271-/// positions -- what a 32x16/16x32 chroma transform has (the chroma plane of298+/// coded positions -- what a 32x16/16x32 chroma transform has (the chroma
272-/// an intra `PARTITION_HORZ`/`VERT` 64x32/32x64 superblock strip, whose luma299+/// plane of an intra `PARTITION_HORZ`/`VERT` 64x32/32x64 superblock strip,
273-/// coefficients truncate to the 64x64-superblock's own 32x32 corner-scan300+/// whose luma coefficients truncate to the 64x64-superblock's own 32x32
274-/// (`TxbSet::Luma64`) but whose *chroma* plane, at 32x16, is small enough301+/// corner-scan (`TxbSet::Luma64`) but whose *chroma* plane, at 32x16, is
275-/// that no truncation applies). Unlike every other `EOB_PT_*` table here,302+/// small enough that no truncation applies).
276-/// libaom's default is the exact same flat distribution at all four303+///
277-/// q-contexts and both `eob_multi_size` selectors (`token_cdfs.h` rows), so304+/// lane-sbpart originally transcribed the `[1][1]` row -- the
278-/// one constant covers every q-context -- no `_Q0`/`_Q1`/`_Q3` siblings.305+/// `TX_CLASS_HORIZ`/`VERT` (1D) sibling, whose default IS the flat
306+/// `3277, 6554, ...` ramp at every q-context -- and wrote that flatness into
307+/// this comment as a property of the whole table. The 2D row this decoder
308+/// actually reads is q-dependent like every other `EOB_PT_*` family, so a
309+/// real `--cq-level=45` stream (q-context 3) read the wrong CDF and desynced
310+/// the tile at the first 32x16 chroma transform of the first SB-level
311+/// HORZ/VERT strip.
279 pub const EOB_PT_512_CHROMA: [u16; 11] = [312 pub const EOB_PT_512_CHROMA: [u16; 11] = [
280- 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0,313+ 12015, 14769, 19588, 22052, 24222, 25812, 27300, 29219, 32114, 32768, 0,
314+];
315+/// [`EOB_PT_512_CHROMA`], q-context 0 (`base_q_idx` 0..=20).
316+pub const EOB_PT_512_CHROMA_Q0: [u16; 11] = [
317+ 5095, 6446, 9996, 13354, 16017, 17986, 20919, 26129, 29140, 32768, 0,
318+];
319+/// [`EOB_PT_512_CHROMA`], q-context 1 (`base_q_idx` 21..=60).
320+pub const EOB_PT_512_CHROMA_Q1: [u16; 11] = [
321+ 7265, 9979, 15819, 19250, 21780, 23846, 26478, 28396, 31811, 32768, 0,
322+];
323+/// [`EOB_PT_512_CHROMA`], q-context 3 (`base_q_idx` 121..=255).
324+pub const EOB_PT_512_CHROMA_Q3: [u16; 11] = [
325+ 21093, 23043, 25742, 27658, 29097, 29716, 30073, 30820, 31956, 32768, 0,
281 ];326 ];
282 327
283 /// `Default_Dc_Sign_Cdf[2][0]` (spec 9.4): the sign of a luma DC coefficient,328 /// `Default_Dc_Sign_Cdf[2][0]` (spec 9.4): the sign of a luma DC coefficient,
@@ -783,22 +828,39 @@ pub const NZ_MAP_CTX_OFFSET_32: [[u8; 5]; 5] = [
783 /// indexes this position table by the raw, un-adjusted `tx_size` -- lane-sbpart828 /// indexes this position table by the raw, un-adjusted `tx_size` -- lane-sbpart
784 /// r8 root cause) is genuinely rectangular, not square. Distinct from829 /// r8 root cause) is genuinely rectangular, not square. Distinct from
785 /// [`NZ_MAP_CTX_OFFSET_32`] starting at `(row=1, col=0)`.830 /// [`NZ_MAP_CTX_OFFSET_32`] starting at `(row=1, col=0)`.
831+// lane-part32 r3: this table was TRANSPOSED (row/col swapped) as landed by
832+// lane-sbpart r8 -- caught by tracing a real aomenc pin against a patched
833+// aomdec (added per-symbol `EC_TRACE_COEFF` ctx prints to
834+// `read_coeffs_reverse{,_2d}` in `~/.cache/aom-oracle`), which showed our own
835+// `(row=2, col=0)` reading ctx-offset 11 where the real decoder's equivalent
836+// position read 6. Re-derived straight from libaom's own generating
837+// comment in `get_nz_map_ctx_from_stats` (`txb_common.h:199-210`): for
838+// `width < height` (this table, `TX_32X64`), ctx is `11 +` for `row < 2`
839+// *regardless of col* -- the old table instead special-cased `col < 2`,
840+// which is the `width > height` (`TX_64X32`) branch. Confirmed against the
841+// real `av1_nz_map_ctx_offset_32x64`/`_64x32` C arrays in
842+// `av1/common/txb_common.c`, decoded through libaom's own col-major
843+// `pos = col*32+row` raster (same convention [`SCAN_32X16`]'s doc comment
844+// already documents this decoder transcribes out of).
786 pub const NZ_MAP_CTX_OFFSET_32X64: [[u8; 5]; 5] = [845 pub const NZ_MAP_CTX_OFFSET_32X64: [[u8; 5]; 5] = [
787- [0, 11, 6, 6, 21],846+ [0, 11, 11, 11, 11],
788- [11, 11, 6, 21, 21],847+ [11, 11, 11, 11, 11],
789- [11, 11, 21, 21, 21],848+ [6, 6, 21, 21, 21],
790- [11, 11, 21, 21, 21],849+ [6, 21, 21, 21, 21],
791- [11, 11, 21, 21, 21],850+ [21, 21, 21, 21, 21],
792 ];851 ];
793 852
794 /// [`NZ_MAP_CTX_OFFSET_32X64`]'s `TX_64X32` counterpart (libaom853 /// [`NZ_MAP_CTX_OFFSET_32X64`]'s `TX_64X32` counterpart (libaom
795 /// `av1_nz_map_ctx_offset_64x32`): a `PARTITION_HORZ` strip's luma corner.854 /// `av1_nz_map_ctx_offset_64x32`): a `PARTITION_HORZ` strip's luma corner.
855+/// `width > height` here, so the `col < 2` branch (offset 16) fires
856+/// regardless of row -- transpose of [`NZ_MAP_CTX_OFFSET_32X64`]'s `row < 2`
857+/// branch, same r3 fix (see that table's doc comment).
796 pub const NZ_MAP_CTX_OFFSET_64X32: [[u8; 5]; 5] = [858 pub const NZ_MAP_CTX_OFFSET_64X32: [[u8; 5]; 5] = [
797- [0, 16, 16, 16, 16],859+ [0, 16, 6, 6, 21],
798- [16, 16, 16, 16, 16],860+ [16, 16, 6, 21, 21],
799- [6, 6, 21, 21, 21],861+ [16, 16, 21, 21, 21],
800- [6, 21, 21, 21, 21],862+ [16, 16, 21, 21, 21],
801- [21, 21, 21, 21, 21],863+ [16, 16, 21, 21, 21],
802 ];864 ];
803 865
804 /// `Default_Txb_Skip_Cdf[2][2][7..10]` (spec 9.4): the all-zero flag of a866 /// `Default_Txb_Skip_Cdf[2][2][7..10]` (spec 9.4): the all-zero flag of a
@@ -1394,6 +1456,20 @@ pub const INTER_TX_TYPE_SET2_16: [u16; 13] = [
1394 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,
1395 ];1457 ];
1396 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+
1397 /// `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
1398 /// `TX_8X8` (lane-cdffwd2): the full sixteen-symbol transform type of an1474 /// `TX_8X8` (lane-cdffwd2): the full sixteen-symbol transform type of an
1399 /// `is_inter` 8x8 luma transform when `reduced_tx_set == 0`1475 /// `is_inter` 8x8 luma transform when `reduced_tx_set == 0`
@@ -5009,3 +5085,44 @@ pub const INTRA_TX_TYPE_SET1_4: [[u16; 8]; 13] = [
5009 [277, 4369, 5255, 8905, 16465, 22271, 32768, 0],5085 [277, 4369, 5255, 8905, 16465, 22271, 32768, 0],
5010 [3409, 5436, 10599, 15599, 19687, 24040, 32768, 0],5086 [3409, 5436, 10599, 15599, 19687, 24040, 32768, 0],
5011 ];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+105 -9
@@ -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,
@@ -1026,9 +1091,13 @@ impl Cdfs {
1026 cdf::EOB_PT_128_CHROMA,1091 cdf::EOB_PT_128_CHROMA,
1027 cdf::EOB_PT_128_CHROMA_Q3,1092 cdf::EOB_PT_128_CHROMA_Q3,
1028 ),1093 ),
1029- // Flat default at every q-context (see the constant's own doc1094+ eob_pt_512_chroma: pick(
1030- // comment) -- no `pick()` needed.1095+ q_ctx,
1031- eob_pt_512_chroma: cdf::EOB_PT_512_CHROMA,1096+ cdf::EOB_PT_512_CHROMA_Q0,
1097+ cdf::EOB_PT_512_CHROMA_Q1,
1098+ cdf::EOB_PT_512_CHROMA,
1099+ cdf::EOB_PT_512_CHROMA_Q3,
1100+ ),
1032 eob_extra_luma_32: pick(1101 eob_extra_luma_32: pick(
1033 q_ctx,1102 q_ctx,
1034 cdf::EOB_EXTRA_LUMA_32_Q0,1103 cdf::EOB_EXTRA_LUMA_32_Q0,
@@ -1145,6 +1214,8 @@ impl Cdfs {
1145 inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8,1214 inter_tx_type_8: cdf::INTER_TX_TYPE_SET3_8,
1146 inter_tx_type_16_set2: cdf::INTER_TX_TYPE_SET2_16,1215 inter_tx_type_16_set2: cdf::INTER_TX_TYPE_SET2_16,
1147 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,
1148 dc_sign_chroma: cdf::DC_SIGN_CHROMA,1219 dc_sign_chroma: cdf::DC_SIGN_CHROMA,
1149 intra_inter: cdf::INTRA_INTER,1220 intra_inter: cdf::INTRA_INTER,
1150 single_ref: cdf::SINGLE_REF,1221 single_ref: cdf::SINGLE_REF,
@@ -1154,6 +1225,7 @@ impl Cdfs {
1154 uni_comp_ref: cdf::UNI_COMP_REF,1225 uni_comp_ref: cdf::UNI_COMP_REF,
1155 comp_ref: cdf::COMP_REF,1226 comp_ref: cdf::COMP_REF,
1156 comp_bwdref: cdf::COMP_BWDREF,1227 comp_bwdref: cdf::COMP_BWDREF,
1228+ txfm_partition: cdf::TXFM_PARTITION,
1157 skip_mode: cdf::SKIP_MODE,1229 skip_mode: cdf::SKIP_MODE,
1158 obmc: cdf::OBMC,1230 obmc: cdf::OBMC,
1159 motion_mode: cdf::MOTION_MODE,1231 motion_mode: cdf::MOTION_MODE,
@@ -1259,7 +1331,7 @@ impl Cdfs {
1259 br: &mut self.br_luma_16,1331 br: &mut self.br_luma_16,
1260 dc_sign: &mut self.dc_sign_luma,1332 dc_sign: &mut self.dc_sign_luma,
1261 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()),
1262- eob_pt_class1: None,1334+ eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1),
1263 },1335 },
1264 TxbSet::Luma16Inter => TxbTables {1336 TxbSet::Luma16Inter => TxbTables {
1265 side: 16,1337 side: 16,
@@ -1271,7 +1343,7 @@ impl Cdfs {
1271 br: &mut self.br_luma_16,1343 br: &mut self.br_luma_16,
1272 dc_sign: &mut self.dc_sign_luma,1344 dc_sign: &mut self.dc_sign_luma,
1273 tx_type: Some(self.inter_tx_type_16.as_mut_slice()),1345 tx_type: Some(self.inter_tx_type_16.as_mut_slice()),
1274- eob_pt_class1: None,1346+ eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1),
1275 },1347 },
1276 TxbSet::Luma16InterSet1 => TxbTables {1348 TxbSet::Luma16InterSet1 => TxbTables {
1277 side: 16,1349 side: 16,
@@ -1283,7 +1355,7 @@ impl Cdfs {
1283 br: &mut self.br_luma_16,1355 br: &mut self.br_luma_16,
1284 dc_sign: &mut self.dc_sign_luma,1356 dc_sign: &mut self.dc_sign_luma,
1285 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()),
1286- eob_pt_class1: None,1358+ eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1),
1287 },1359 },
1288 TxbSet::Luma8 => TxbTables {1360 TxbSet::Luma8 => TxbTables {
1289 side: 8,1361 side: 8,
@@ -1321,6 +1393,30 @@ impl Cdfs {
1321 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()),
1322 eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1),1394 eob_pt_class1: Some(&mut self.eob_pt_16_luma_class1),
1323 },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+ },
1324 TxbSet::Luma4Set1 => TxbTables {1420 TxbSet::Luma4Set1 => TxbTables {
1325 side: 4,1421 side: 4,
1326 txb_skip: &mut self.txb_skip_luma_4,1422 txb_skip: &mut self.txb_skip_luma_4,
@@ -1367,7 +1463,7 @@ impl Cdfs {
1367 br: &mut self.br_chroma_8,1463 br: &mut self.br_chroma_8,
1368 dc_sign: &mut self.dc_sign_chroma,1464 dc_sign: &mut self.dc_sign_chroma,
1369 tx_type: None,1465 tx_type: None,
1370- eob_pt_class1: None,1466+ eob_pt_class1: Some(&mut self.eob_pt_64_chroma_class1),
1371 },1467 },
1372 TxbSet::Chroma4 => TxbTables {1468 TxbSet::Chroma4 => TxbTables {
1373 side: 4,1469 side: 4,
@@ -1379,7 +1475,7 @@ impl Cdfs {
1379 br: &mut self.br_chroma_4,1475 br: &mut self.br_chroma_4,
1380 dc_sign: &mut self.dc_sign_chroma,1476 dc_sign: &mut self.dc_sign_chroma,
1381 tx_type: None,1477 tx_type: None,
1382- eob_pt_class1: None,1478+ eob_pt_class1: Some(&mut self.eob_pt_16_chroma_class1),
1383 },1479 },
1384 TxbSet::Chroma16 => TxbTables {1480 TxbSet::Chroma16 => TxbTables {
1385 side: 16,1481 side: 16,
@@ -1391,7 +1487,7 @@ impl Cdfs {
1391 br: &mut self.br_chroma_16,1487 br: &mut self.br_chroma_16,
1392 dc_sign: &mut self.dc_sign_chroma,1488 dc_sign: &mut self.dc_sign_chroma,
1393 tx_type: None,1489 tx_type: None,
1394- eob_pt_class1: None,1490+ eob_pt_class1: Some(&mut self.eob_pt_256_chroma_class1),
1395 },1491 },
1396 TxbSet::Chroma32 => TxbTables {1492 TxbSet::Chroma32 => TxbTables {
1397 side: 32,1493 side: 32,
crates/ec-av1/src/decode.rsmodified+2044 -279

Diff too large; view file

@@ -737,11 +737,60 @@ thread_local! {
737 const { std::cell::Cell::new(0) };737 const { std::cell::Cell::new(0) };
738 }738 }
739 739
740+// How many plain SQUARE intra blocks (lane-sqchroma r1) resolved a luma
741+// transform smaller than their own side (`tx_depth != 0`) while coding a
742+// chroma prediction other than `DC_PRED` -- the pair the square path's chroma
743+// only exercises with aomenc's tx-size search left ON (its default), which
744+// every older recipe in this file pins off. Counted at the block, so a stream
745+// where RD happened to give every split-transform block a DC chroma mode
746+// reads as zero rather than silently passing for free.
747+thread_local! {
748+ static SQ_CHROMA_TX_HITS: std::cell::Cell<usize> =
749+ const { std::cell::Cell::new(0) };
750+}
751+
752+/// Current value of [`SQ_CHROMA_TX_HITS`].
753+pub(crate) fn sq_chroma_tx_hits() -> usize {
754+ SQ_CHROMA_TX_HITS.with(|c| c.get())
755+}
756+
740 /// Current value of [`TX_DEPTH_HITS`].757 /// Current value of [`TX_DEPTH_HITS`].
741 pub(crate) fn tx_depth_hits() -> usize {758 pub(crate) fn tx_depth_hits() -> usize {
742 TX_DEPTH_HITS.with(|c| c.get())759 TX_DEPTH_HITS.with(|c| c.get())
743 }760 }
744 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+
745 // 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
746 // intra-frame path) resolved to `PARTITION_VERT_B` -- lane-rect16 r1: a795 // intra-frame path) resolved to `PARTITION_VERT_B` -- lane-rect16 r1: a
747 // plain default-settings aomenc run over lavfi mandelbrot hits this arm on796 // plain default-settings aomenc run over lavfi mandelbrot hits this arm on
@@ -790,6 +839,22 @@ pub(crate) fn rect_split_tx_hits() -> usize {
790 RECT_SPLIT_TX_HITS.with(|c| c.get())839 RECT_SPLIT_TX_HITS.with(|c| c.get())
791 }840 }
792 841
842+// The subset of [`RECT_SPLIT_TX_HITS`] that is BOTH superblock-level (one
843+// side 64) AND split past the first depth, i.e. tiled more than one unit in
844+// each axis -- the only shape with a transform unit that has neighbours on
845+// two sides inside its own strip (`row_off > 0 && col_off > 0`), and the one
846+// no gate fired before lane-rectsplit r2 (the shared counter above also
847+// counts 32x32-level and depth-1 strips, so it cannot prove this case).
848+thread_local! {
849+ static RECT_SPLIT_SB_INTERIOR_TU_HITS: std::cell::Cell<usize> =
850+ const { std::cell::Cell::new(0) };
851+}
852+
853+/// Current value of [`RECT_SPLIT_SB_INTERIOR_TU_HITS`].
854+pub(crate) fn rect_split_sb_interior_tu_hits() -> usize {
855+ RECT_SPLIT_SB_INTERIOR_TU_HITS.with(|c| c.get())
856+}
857+
793 // How many HORZ/VERT intra strips actually predicted with filter intra858 // How many HORZ/VERT intra strips actually predicted with filter intra
794 // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name859 // (lane-rectsplit r1) -- the case `decode_block_rect` refused by name
795 // ("this decoder predicts square-only") until `predict_filter_intra` took860 // ("this decoder predicts square-only") until `predict_filter_intra` took
@@ -1098,6 +1163,21 @@ pub(crate) fn warp_selected_hits() -> usize {
1098 WARP_SELECTED_HITS.with(|c| c.get())1163 WARP_SELECTED_HITS.with(|c| c.get())
1099 }1164 }
1100 1165
1166+// lane-cwarp r1: how many COMPOUND_REFERENCE blocks had at least one
1167+// reference predicted through the per-ref GLOBAL warp (`av1_warp_plane`
1168+// into the compound intermediate) rather than translationally -- the
1169+// gate's proof that a `GLOBAL_GLOBALMV` block under a ROTZOOM/AFFINE model
1170+// really reached [`crate::warp::warp_affine_compound`].
1171+thread_local! {
1172+ static COMPOUND_WARP_HITS: std::cell::Cell<usize> =
1173+ const { std::cell::Cell::new(0) };
1174+}
1175+
1176+/// Current value of [`COMPOUND_WARP_HITS`].
1177+pub(crate) fn compound_warp_hits() -> usize {
1178+ COMPOUND_WARP_HITS.with(|c| c.get())
1179+}
1180+
1101 // How many blocks decoded `interintra == 1` with the non-wedge blended1181 // How many blocks decoded `interintra == 1` with the non-wedge blended
1102 // prediction applied (lane-interintra r1) -- the gate's proof that a1182 // prediction applied (lane-interintra r1) -- the gate's proof that a
1103 // stream actually exercised interintra.1183 // stream actually exercised interintra.
@@ -1190,6 +1270,33 @@ pub(crate) fn rect_partition_hits() -> usize {
1190 RECT_PARTITION_HITS.with(|c| c.get())1270 RECT_PARTITION_HITS.with(|c| c.get())
1191 }1271 }
1192 1272
1273+// lane-inter8 r1: how many superblocks an inter tile coded as a single
1274+// whole-SB `PARTITION_NONE` 64x64 inter block (the case aomenc picks for
1275+// static content, previously a named refusal).
1276+thread_local! {
1277+ static INTER_SB_NONE_HITS: std::cell::Cell<usize> =
1278+ const { std::cell::Cell::new(0) };
1279+}
1280+
1281+/// Current value of [`INTER_SB_NONE_HITS`].
1282+pub(crate) fn inter_sb_none_hits() -> usize {
1283+ INTER_SB_NONE_HITS.with(|c| c.get())
1284+}
1285+
1286+// lane-inter8 r1: how many INTERIOR (not frame-edge-straddling) 16x16 inter
1287+// blocks coded a real `PARTITION_SPLIT` into four 8x8 leaves -- the straddle
1288+// path has always run that loop, so only this counter proves the newly-lifted
1289+// alphabet value fired.
1290+thread_local! {
1291+ static INTER_SUB16_SPLIT_HITS: std::cell::Cell<usize> =
1292+ const { std::cell::Cell::new(0) };
1293+}
1294+
1295+/// Current value of [`INTER_SUB16_SPLIT_HITS`].
1296+pub(crate) fn inter_sub16_split_hits() -> usize {
1297+ INTER_SUB16_SPLIT_HITS.with(|c| c.get())
1298+}
1299+
1193 // lane-rectwire r2: how many `PARTITION_HORZ`/`VERT` strips actually decoded1300 // lane-rectwire r2: how many `PARTITION_HORZ`/`VERT` strips actually decoded
1194 // real (non-skip) coefficients through [`read_coeffs_rect`] -- proves the1301 // real (non-skip) coefficients through [`read_coeffs_rect`] -- proves the
1195 // rect coefficient reader itself fired, not just the strip-level partition1302 // rect coefficient reader itself fired, not just the strip-level partition
@@ -1218,6 +1325,29 @@ pub(crate) fn sb_rect_hits() -> usize {
1218 SB_RECT_HITS.with(|c| c.get())1325 SB_RECT_HITS.with(|c| c.get())
1219 }1326 }
1220 1327
1328+// lane-part32 r4: how many superblock-level AB blocks (`PARTITION_HORZ_A`/
1329+// `_B`/`VERT_A`/`_B` at 64x64 -- two 32x32 squares plus one 64x32/32x64
1330+// strip) fired. Real aomenc picks these at 64 even with
1331+// `--enable-ab-partitions=0` (lane-sbpart r2's own measurement), so this is
1332+// the counter the gate hard-asserts.
1333+thread_local! {
1334+ static SB_AB_HITS: std::cell::Cell<[usize; 4]> =
1335+ const { std::cell::Cell::new([0; 4]) };
1336+}
1337+
1338+/// Current value of [`SB_AB_HITS`], summed over the four arms.
1339+pub(crate) fn sb_ab_hits() -> usize {
1340+ SB_AB_HITS.with(|c| c.get().iter().sum())
1341+}
1342+
1343+/// [`SB_AB_HITS`] split per arm, in `PARTITION_HORZ_A`, `_HORZ_B`,
1344+/// `_VERT_A`, `_VERT_B` order -- what the gate hard-asserts arm by arm, so a
1345+/// run where aomenc's RD only ever picked (say) `HORZ_A` cannot pass off as
1346+/// proof of all four.
1347+pub(crate) fn sb_ab_hits_by_arm() -> [usize; 4] {
1348+ SB_AB_HITS.with(std::cell::Cell::get)
1349+}
1350+
1221 // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane1351 // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane
1222 // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the1352 // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the
1223 // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not1353 // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not
@@ -1247,6 +1377,38 @@ pub(crate) fn partab_hits() -> usize {
1247 PARTAB_HITS.with(|c| c.get())1377 PARTAB_HITS.with(|c| c.get())
1248 }1378 }
1249 1379
1380+// lane-part32 r1: how many 32x32 quadrants decoded each INTRA AB/4-way arm,
1381+// one counter per arm rather than one shared total -- the gate hard-asserts
1382+// each of these individually nonzero so a recipe that only ever fires
1383+// HORZ_A can't silently stand in for the whole set.
1384+thread_local! {
1385+ static INTRA_HORZ_A_HITS: std::cell::Cell<usize> =
1386+ const { std::cell::Cell::new(0) };
1387+ static INTRA_HORZ_B_HITS: std::cell::Cell<usize> =
1388+ const { std::cell::Cell::new(0) };
1389+ static INTRA_VERT_A_HITS: std::cell::Cell<usize> =
1390+ const { std::cell::Cell::new(0) };
1391+ static INTRA_VERT_B_HITS: std::cell::Cell<usize> =
1392+ const { std::cell::Cell::new(0) };
1393+}
1394+
1395+/// Current value of [`INTRA_HORZ_A_HITS`].
1396+pub(crate) fn intra_horz_a_hits() -> usize {
1397+ INTRA_HORZ_A_HITS.with(|c| c.get())
1398+}
1399+/// Current value of [`INTRA_HORZ_B_HITS`].
1400+pub(crate) fn intra_horz_b_hits() -> usize {
1401+ INTRA_HORZ_B_HITS.with(|c| c.get())
1402+}
1403+/// Current value of [`INTRA_VERT_A_HITS`].
1404+pub(crate) fn intra_vert_a_hits() -> usize {
1405+ INTRA_VERT_A_HITS.with(|c| c.get())
1406+}
1407+/// Current value of [`INTRA_VERT_B_HITS`].
1408+pub(crate) fn intra_vert_b_hits() -> usize {
1409+ INTRA_VERT_B_HITS.with(|c| c.get())
1410+}
1411+
1250 // How many [`read_inter_compound_mode`] reads actually happened1412 // How many [`read_inter_compound_mode`] reads actually happened
1251 // (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own1413 // (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own
1252 // `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound1414 // `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound
@@ -1280,6 +1442,12 @@ pub(crate) fn tmv_hits() -> usize {
1280 crate::mvstack::tmv_hits()1442 crate::mvstack::tmv_hits()
1281 }1443 }
1282 1444
1445+/// Current value of [`crate::mc::inter_pred_hits`] -- inter predictions
1446+/// produced on this thread, the 10-bit inter gate's firing proof.
1447+pub(crate) fn inter_pred_hits() -> usize {
1448+ crate::mc::inter_pred_hits()
1449+}
1450+
1283 /// Everything [`decode_inter_block`] needs to fold temporal MV candidates1451 /// Everything [`decode_inter_block`] needs to fold temporal MV candidates
1284 /// (spec 7.10.2.8), threaded down from [`decode_inter_frame_tile_with_cdfs`]:1452 /// (spec 7.10.2.8), threaded down from [`decode_inter_frame_tile_with_cdfs`]:
1285 /// the current frame's own projected field ([`crate::motion_field::setup_motion_field`]'s1453 /// the current frame's own projected field ([`crate::motion_field::setup_motion_field`]'s
@@ -1575,11 +1743,32 @@ fn base_ctx(
1575 // (lane-sbpart r8 root cause: `(row=1, col=0)` reads ctx 2 under the1743 // (lane-sbpart r8 root cause: `(row=1, col=0)` reads ctx 2 under the
1576 // square table vs the real ctx 13 the rect table gives).1744 // square table vs the real ctx 13 the rect table gives).
1577 TxClass::TwoD => {1745 TxClass::TwoD => {
1746+ // OPEN (lane-rectsplit r3, measured): the two rect
1747+ // transcriptions in [`cdf`] are packed `[col][row]` -- libaom's
1748+ // `av1_nz_map_ctx_offset_32x64` is a FLAT 1024-entry array whose
1749+ // `coeff_idx` is COLUMN-major with stride 32 (`TX_CLASS_HORIZ`
1750+ // reads its column back as `coeff_idx >> bhl`), and entries
1751+ // 0..5 / 32..35 match the generating rule (txb_common.h:199-209)
1752+ // only under `flat[col * 32 + row]`;
1753+ // `nz_map_ctx_offset_tables_match_the_rect_rule` pins that.
1754+ // Yet reading `[col][row]` here BREAKS
1755+ // `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`
1756+ // (seed 43) while `[row][col]` breaks the split-transform SB gate
1757+ // (seed 50); swapping the shape test as well fails BOTH ways. So
1758+ // this read is not the defect -- our (row, col) here come from a
1759+ // square 32x32-corner scan whose orientation relative to libaom's
1760+ // column-major `coeff_idx` is what is really unproven, and each
1761+ // "fix" only moves which rare corner position desyncs. Left at
1762+ // the r1 reading, the one every merged gate is green under.
1763+ // `EC_NZOFF_DUMP=1` prints every rect-shaped read.
1578 let table = match rect_shape {1764 let table = match rect_shape {
1579 Some((w, h)) if w < h => &cdf::NZ_MAP_CTX_OFFSET_32X64,1765 Some((w, h)) if w < h => &cdf::NZ_MAP_CTX_OFFSET_32X64,
1580 Some((w, h)) if w > h => &cdf::NZ_MAP_CTX_OFFSET_64X32,1766 Some((w, h)) if w > h => &cdf::NZ_MAP_CTX_OFFSET_64X32,
1581 _ => &cdf::NZ_MAP_CTX_OFFSET_32,1767 _ => &cdf::NZ_MAP_CTX_OFFSET_32,
1582 };1768 };
1769+ if std::env::var_os("EC_NZOFF_DUMP").is_some() {
1770+ eprintln!("NZOFF side={side} shape={rect_shape:?} row={row} col={col}");
1771+ }
1583 ctx + table[row.min(4)][col.min(4)] as usize1772 ctx + table[row.min(4)][col.min(4)] as usize
1584 }1773 }
1585 TxClass::Horiz => ctx + nz_map_ctx_offset_1d(col.min(31)),1774 TxClass::Horiz => ctx + nz_map_ctx_offset_1d(col.min(31)),
@@ -1798,7 +1987,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) ->
1798 (TxClass::TwoD, _) | (_, None) => coding.eob_pt,1987 (TxClass::TwoD, _) | (_, None) => coding.eob_pt,
1799 (_, Some(class1)) => class1,1988 (_, Some(class1)) => class1,
1800 };1989 };
1801- if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() && eob_pt.len() == 12 {1990+ if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {
1802 let (range, value) = dec.debug_state();1991 let (range, value) = dec.debug_state();
1803 eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?} range={range} value={value}");1992 eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?} range={range} value={value}");
1804 }1993 }
@@ -2075,8 +2264,16 @@ fn read_coeffs_rect(
2075 sign_ctx: usize,2264 sign_ctx: usize,
2076 default_tx_type: TxType,2265 default_tx_type: TxType,
2077 ) -> Result<(Vec<i32>, TxType)> {2266 ) -> Result<(Vec<i32>, TxType)> {
2267+ let ec_trace_coeff = std::env::var_os("EC_TRACE_COEFF").is_some();
2078 let mut grid = vec![0i32; w * h];2268 let mut grid = vec![0i32; w * h];
2079 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;2269 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
2270+ if ec_trace_coeff {
2271+ let (rng, _) = dec.debug_state();
2272+ eprintln!(
2273+ "EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero={} rng={rng}",
2274+ all_zero as i32
2275+ );
2276+ }
2080 if all_zero {2277 if all_zero {
2081 return Ok((grid, TxType::DctDct));2278 return Ok((grid, TxType::DctDct));
2082 }2279 }
@@ -2092,16 +2289,35 @@ fn read_coeffs_rect(
2092 ));2289 ));
2093 }2290 }
2094 let eob = read_eob(dec, coding, TxClass::TwoD);2291 let eob = read_eob(dec, coding, TxClass::TwoD);
2292+ if ec_trace_coeff {
2293+ let (rng, _) = dec.debug_state();
2294+ eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={rng}");
2295+ }
2095 let mut levels = vec![0i32; w * h];2296 let mut levels = vec![0i32; w * h];
2096 for scan_idx in (0..eob).rev() {2297 for scan_idx in (0..eob).rev() {
2097 let pos = scan[scan_idx] as usize;2298 let pos = scan[scan_idx] as usize;
2098 let (row, col) = (pos / w, pos % w);2299 let (row, col) = (pos / w, pos % w);
2099 let level = if scan_idx == eob - 1 {2300 let level = if scan_idx == eob - 1 {
2100 let ctx = eob_coeff_ctx(scan_idx, w * h);2301 let ctx = eob_coeff_ctx(scan_idx, w * h);
2101- dec.symbol(&mut coding.base_eob[ctx]) as i32 + 12302+ let l = dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1;
2303+ if ec_trace_coeff {
2304+ let (rng, _) = dec.debug_state();
2305+ eprintln!(
2306+ "EC_COEFF_STEP tag=base_eob c={scan_idx} pos={pos} ctx={ctx} level={} rng={rng}",
2307+ l - 1
2308+ );
2309+ }
2310+ l
2102 } else {2311 } else {
2103 let ctx = base_ctx_rect(&levels, w, h, row, col);2312 let ctx = base_ctx_rect(&levels, w, h, row, col);
2104- dec.symbol(&mut coding.base[ctx]) as i322313+ let l = dec.symbol(&mut coding.base[ctx]) as i32;
2314+ if ec_trace_coeff {
2315+ let (rng, _) = dec.debug_state();
2316+ eprintln!(
2317+ "EC_COEFF_STEP tag=base c={scan_idx} pos={pos} ctx={ctx} level={l} rng={rng}"
2318+ );
2319+ }
2320+ l
2105 };2321 };
2106 let level = if level > NUM_BASE_LEVELS {2322 let level = if level > NUM_BASE_LEVELS {
2107 let ctx = br_ctx_rect(&levels, w, h, row, col);2323 let ctx = br_ctx_rect(&levels, w, h, row, col);
@@ -2109,6 +2325,12 @@ fn read_coeffs_rect(
2109 let mut sent = 0;2325 let mut sent = 0;
2110 loop {2326 loop {
2111 let k = dec.symbol(&mut coding.br[ctx]) as i32;2327 let k = dec.symbol(&mut coding.br[ctx]) as i32;
2328+ if ec_trace_coeff {
2329+ let (rng, _) = dec.debug_state();
2330+ eprintln!(
2331+ "EC_COEFF_STEP tag=br c={scan_idx} pos={pos} ctx={ctx} k={k} rng={rng}"
2332+ );
2333+ }
2112 level += k;2334 level += k;
2113 sent += BR_STEP;2335 sent += BR_STEP;
2114 if k < BR_STEP || sent >= COEFF_BASE_RANGE {2336 if k < BR_STEP || sent >= COEFF_BASE_RANGE {
@@ -2121,6 +2343,10 @@ fn read_coeffs_rect(
2121 };2343 };
2122 levels[pos] = level;2344 levels[pos] = level;
2123 }2345 }
2346+ if ec_trace_coeff {
2347+ let (rng, _) = dec.debug_state();
2348+ eprintln!("EC_COEFF_STEP tag=after_bases rng={rng}");
2349+ }
2124 for &pos in &scan[..eob] {2350 for &pos in &scan[..eob] {
2125 let level = levels[pos as usize];2351 let level = levels[pos as usize];
2126 if level == 0 {2352 if level == 0 {
@@ -2220,6 +2446,16 @@ struct Neighbours {
2220 /// `left_skip`.2446 /// `left_skip`.
2221 above_skip: Vec<bool>,2447 above_skip: Vec<bool>,
2222 left_skip: Vec<bool>,2448 left_skip: Vec<bool>,
2449+ /// libaom's `above_txfm_context`/`left_txfm_context` (`TXFM_CONTEXT`), at
2450+ /// 4x4 mi granularity: the transform *width* (above) / *height* (left) in
2451+ /// pixels last written over each unit by `set_txfm_ctxs`/
2452+ /// `txfm_partition_update`, which is what an inter block's `txfm_split`
2453+ /// symbol reads its context from (lane-txselect, spec 5.11.17).
2454+ /// [`TXFM_CTX_INIT`] until a block writes one; a fresh full-height `left`
2455+ /// array is exactly libaom's per-superblock-row reset, since each mi row
2456+ /// is only ever visited inside one superblock row.
2457+ above_txfm: Vec<u8>,
2458+ left_txfm: Vec<u8>,
2223 /// Whether the block above/left of this column/row coded `skip_mode`2459 /// Whether the block above/left of this column/row coded `skip_mode`
2224 /// (spec 5.11.23) -- `av1_get_skip_mode_context`'s own neighbour lookup,2460 /// (spec 5.11.23) -- `av1_get_skip_mode_context`'s own neighbour lookup,
2225 /// lane-av1comp round 14.2461 /// lane-av1comp round 14.
@@ -2350,22 +2586,28 @@ impl Neighbours {
2350 left_side: vec![SB; rows],2586 left_side: vec![SB; rows],
2351 above_side_mi: vec![SB; cols * (SUB / MI)],2587 above_side_mi: vec![SB; cols * (SUB / MI)],
2352 left_side_mi: vec![SB; rows * (SUB / MI)],2588 left_side_mi: vec![SB; rows * (SUB / MI)],
2353- above_skip: vec![false; cols],2589+ above_txfm: vec![TXFM_CTX_INIT; cols * (SUB / MI)],
2354- left_skip: vec![false; rows],2590+ left_txfm: vec![TXFM_CTX_INIT; rows * (SUB / MI)],
2355- above_skip_mode: vec![false; cols],2591+ // lane-inter8 r2: mi(4px)-granular, not [`SUB`]-granular -- an
2356- left_skip_mode: vec![false; rows],2592+ // 8x8 inter leaf's left neighbour is the OTHER leaf row of the
2357- above_inter: vec![false; cols],2593+ // 16x16 block beside it, which a SUB-grid slot cannot name
2358- left_inter: vec![false; rows],2594+ // (class context-read-from-one-cell).
2359- above_ref: vec![-1; cols],2595+ above_skip: vec![false; cols * (SUB / MI)],
2360- left_ref: vec![-1; rows],2596+ left_skip: vec![false; rows * (SUB / MI)],
2361- above_ref1: vec![None; cols],2597+ above_skip_mode: vec![false; cols * (SUB / MI)],
2362- left_ref1: vec![None; rows],2598+ left_skip_mode: vec![false; rows * (SUB / MI)],
2363- above_comp_group_idx: vec![0; cols],2599+ above_inter: vec![false; cols * (SUB / MI)],
2364- left_comp_group_idx: vec![0; rows],2600+ left_inter: vec![false; rows * (SUB / MI)],
2365- above_compound_idx: vec![0; cols],2601+ above_ref: vec![-1; cols * (SUB / MI)],
2366- left_compound_idx: vec![0; rows],2602+ left_ref: vec![-1; rows * (SUB / MI)],
2367- above_filter: vec![[3u8; 2]; cols],2603+ above_ref1: vec![None; cols * (SUB / MI)],
2368- left_filter: vec![[3u8; 2]; rows],2604+ left_ref1: vec![None; rows * (SUB / MI)],
2605+ above_comp_group_idx: vec![0; cols * (SUB / MI)],
2606+ left_comp_group_idx: vec![0; rows * (SUB / MI)],
2607+ above_compound_idx: vec![0; cols * (SUB / MI)],
2608+ left_compound_idx: vec![0; rows * (SUB / MI)],
2609+ above_filter: vec![[3u8; 2]; cols * (SUB / MI)],
2610+ left_filter: vec![[3u8; 2]; rows * (SUB / MI)],
2369 mi_cols,2611 mi_cols,
2370 mi_rows,2612 mi_rows,
2371 skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],2613 skip_grid: vec![false; cols * (SUB / MI) * rows * (SUB / MI)],
@@ -2413,6 +2655,11 @@ impl Neighbours {
2413 for i in sc0.min(sc1)..sc1 {2655 for i in sc0.min(sc1)..sc1 {
2414 self.above_mode[i] = DC_PRED;2656 self.above_mode[i] = DC_PRED;
2415 self.above_side[i] = SB;2657 self.above_side[i] = SB;
2658+ }
2659+ // lane-inter8 r2: the inter bands are mi-granular, so they reset over
2660+ // the tile's own mi column span directly.
2661+ let mend = col1_mi.min(self.above_skip.len());
2662+ for i in col0_mi.min(mend)..mend {
2416 self.above_skip[i] = false;2663 self.above_skip[i] = false;
2417 self.above_skip_mode[i] = false;2664 self.above_skip_mode[i] = false;
2418 self.above_inter[i] = false;2665 self.above_inter[i] = false;
@@ -2780,8 +3027,37 @@ impl Neighbours {
2780 skip_mode: bool,3027 skip_mode: bool,
2781 ) {3028 ) {
2782 let (r, c) = at;3029 let (r, c) = at;
3030+ self.record_inter_rect_mi(
3031+ (r * (SUB / MI), c * (SUB / MI)),
3032+ w_sub / MI,
3033+ h_sub / MI,
3034+ skip,
3035+ is_inter,
3036+ ref_frame,
3037+ filter,
3038+ skip_mode,
3039+ );
3040+ }
3041+
3042+ /// [`Self::record_inter_rect`] in mi (4px) units -- lane-inter8 r2: an
3043+ /// 8x8 leaf covers 2x2 mi, half a [`SUB`] cell in each direction, so the
3044+ /// side bands are written (and read) per mi. Every [`SUB`]-unit caller
3045+ /// routes through the wrapper above.
3046+ #[allow(clippy::too_many_arguments)]
3047+ fn record_inter_rect_mi(
3048+ &mut self,
3049+ at_mi: (usize, usize),
3050+ w_mi: usize,
3051+ h_mi: usize,
3052+ skip: bool,
3053+ is_inter: bool,
3054+ ref_frame: i8,
3055+ filter: [u8; 2],
3056+ skip_mode: bool,
3057+ ) {
3058+ let (r, c) = at_mi;
2783 let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;3059 let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;
2784- for cell in 0..w_sub / SUB {3060+ for cell in 0..w_mi {
2785 self.above_skip[c + cell] = skip;3061 self.above_skip[c + cell] = skip;
2786 self.above_skip_mode[c + cell] = skip_mode;3062 self.above_skip_mode[c + cell] = skip_mode;
2787 self.above_inter[c + cell] = is_inter;3063 self.above_inter[c + cell] = is_inter;
@@ -2799,7 +3075,7 @@ impl Neighbours {
2799 self.above_compound_idx[c + cell] = u8::from(altref);3075 self.above_compound_idx[c + cell] = u8::from(altref);
2800 self.above_filter[c + cell] = filter;3076 self.above_filter[c + cell] = filter;
2801 }3077 }
2802- for cell in 0..h_sub / SUB {3078+ for cell in 0..h_mi {
2803 self.left_skip[r + cell] = skip;3079 self.left_skip[r + cell] = skip;
2804 self.left_skip_mode[r + cell] = skip_mode;3080 self.left_skip_mode[r + cell] = skip_mode;
2805 self.left_inter[r + cell] = is_inter;3081 self.left_inter[r + cell] = is_inter;
@@ -2845,12 +3121,34 @@ impl Neighbours {
2845 compound_idx: u8,3121 compound_idx: u8,
2846 ) {3122 ) {
2847 let (r, c) = at;3123 let (r, c) = at;
2848- for cell in 0..w_sub / SUB {3124+ self.record_compound_ctx_rect_mi(
3125+ (r * (SUB / MI), c * (SUB / MI)),
3126+ w_sub / MI,
3127+ h_sub / MI,
3128+ ref1,
3129+ comp_group_idx,
3130+ compound_idx,
3131+ );
3132+ }
3133+
3134+ /// [`Self::record_compound_ctx_rect`] in mi units (lane-inter8 r2, see
3135+ /// [`Self::record_inter_rect_mi`]).
3136+ fn record_compound_ctx_rect_mi(
3137+ &mut self,
3138+ at_mi: (usize, usize),
3139+ w_mi: usize,
3140+ h_mi: usize,
3141+ ref1: i8,
3142+ comp_group_idx: u8,
3143+ compound_idx: u8,
3144+ ) {
3145+ let (r, c) = at_mi;
3146+ for cell in 0..w_mi {
2849 self.above_ref1[c + cell] = Some(ref1);3147 self.above_ref1[c + cell] = Some(ref1);
2850 self.above_comp_group_idx[c + cell] = comp_group_idx;3148 self.above_comp_group_idx[c + cell] = comp_group_idx;
2851 self.above_compound_idx[c + cell] = compound_idx;3149 self.above_compound_idx[c + cell] = compound_idx;
2852 }3150 }
2853- for cell in 0..h_sub / SUB {3151+ for cell in 0..h_mi {
2854 self.left_ref1[r + cell] = Some(ref1);3152 self.left_ref1[r + cell] = Some(ref1);
2855 self.left_comp_group_idx[r + cell] = comp_group_idx;3153 self.left_comp_group_idx[r + cell] = comp_group_idx;
2856 self.left_compound_idx[r + cell] = compound_idx;3154 self.left_compound_idx[r + cell] = compound_idx;
@@ -3815,12 +4113,22 @@ fn decode_rect_split(
3815 (16, 32) => Some((TxbSet::ChromaRect32x16, &SCAN_16X32[..])),4113 (16, 32) => Some((TxbSet::ChromaRect32x16, &SCAN_16X32[..])),
3816 _ => None,4114 _ => None,
3817 };4115 };
4116+ // lane-rectsplit r2 (verifier finding): with both callers wired
4117+ // (`decode_block_rect`'s 32x16/16x32 and `decode_block_rect64`'s
4118+ // 64x32/32x64) every shape that reaches here has a table above, so this
4119+ // arm is UNREACHABLE today. It stays as the shape guard for the next
4120+ // caller -- a new strip size would otherwise hit the `expect` below and
4121+ // panic instead of refusing by name -- and so stays in
4122+ // `refusal_inventory::REFUSALS`.
3818 if !m.skip && chroma.is_none() {4123 if !m.skip && chroma.is_none() {
3819 return Err(unsupported(4124 return Err(unsupported(
3820 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",4125 "a coded HORZ/VERT strip whose chroma transform has no rect coefficient tables here",
3821 ));4126 ));
3822 }4127 }
3823 RECT_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));4128 RECT_SPLIT_TX_HITS.with(|c| c.set(c.get() + 1));
4129+ if bw.max(bh) == 64 && bw / tx > 1 && bh / tx > 1 {
4130+ RECT_SPLIT_SB_INTERIOR_TU_HITS.with(|c| c.set(c.get() + 1));
4131+ }
3824 // LUMA: `bw/tx` x `bh/tx` square transform units, raster order.4132 // LUMA: `bw/tx` x `bh/tx` square transform units, raster order.
3825 let luma_set = txbset_for(tx, reduced_tx_set);4133 let luma_set = txbset_for(tx, reduced_tx_set);
3826 let luma_scan = default_scan(tx);4134 let luma_scan = default_scan(tx);
@@ -4106,6 +4414,13 @@ fn decode_block_rect(
4106 // [`decode_rect_split`]. `depth_to_tx_size` of a 2:1 strip is square4414 // [`decode_rect_split`]. `depth_to_tx_size` of a 2:1 strip is square
4107 // from the first step on, so `bw.min(bh) >> (depth - 1)` names it.4415 // from the first step on, so `bw.min(bh) >> (depth - 1)` names it.
4108 let tx = bw.min(bh) >> (depth - 1);4416 let tx = bw.min(bh) >> (depth - 1);
4417+ if std::env::var_os("EC_SBPART_DUMP64").is_some() {
4418+ eprintln!(
4419+ "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \
4420+ depth={depth} tx={tx} mode={mode} uv={uv_predict_mode} skip={skip} \
4421+ angle_y={angle_delta_y}"
4422+ );
4423+ }
4109 let modes = RectStripModes {4424 let modes = RectStripModes {
4110 skip,4425 skip,
4111 mode,4426 mode,
@@ -4711,18 +5026,16 @@ fn decode_block_rect64(
4711 };5026 };
4712 if depth != 0 {5027 if depth != 0 {
4713 TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));5028 TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));
4714- // lane-rectsplit r1: [`decode_rect_split`] handles this shape too5029+ // lane-rectsplit r1/r3: [`decode_rect_split`] handles this shape too
4715- // (`sub_tx_size_map[TX_64X32]` is `TX_32X32`, so a depth-1 unit here5030+ // and the per-unit port is wired here, but the gate
4716- // is a plain square 32x32) and its 32x32-level sibling arm in
4717- // [`decode_block_rect`] is gated pixel-exact -- but at the SUPERBLOCK
4718- // level the gate
4719 // (`a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact`,5031 // (`a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact`,
4720- // `#[ignore]`d with its measurement) still comes out ONE sample off5032+ // `#[ignore]`d with its measurement) is still RED at seed 50 (luma
4721- // (seed 50, luma (171,56) ours 147 vs ffmpeg 148, inside a 64x325033+ // (171,56), ours 147 vs ffmpeg 148). r2 believed the cause was a
4722- // strip whose transform resolved to depth 2 / TX_16X16). A refusal5034+ // transposed `av1_nz_map_ctx_offset` read; r3 measured that
4723- // this lane could not lift is not a refusal it may silently ship5035+ // transposing it turns THIS gate green and the merged SB-level
4724- // wrong pixels past, so the named refusal stays until that gate is5036+ // HORZ/VERT partition gate RED (seed 43), so the cause is still
4725- // green.5037+ // open. A refusal this lane cannot lift is not one it may ship wrong
5038+ // pixels past.
4726 return Err(unsupported(5039 return Err(unsupported(
4727 "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \5040 "a superblock-level HORZ/VERT strip with a split transform (per-unit rect \
4728 prediction is not ported)",5041 prediction is not ported)",
@@ -5562,6 +5875,15 @@ impl PlaneBuf {
5562 buf5875 buf
5563 } else {5876 } else {
5564 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);5877 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);
5878+ if std::env::var_os("EC_DEBUG_EDGES").is_some() {
5879+ eprintln!(
5880+ "EDGES x={x} y={y} bw={bw} bh={bh} mode={mode} above={:?} left_len={:?} left0={:?} corner={corner:?} tx0={} ty0={} truew={} trueh={}",
5881+ above.as_ref().map(|a| (a.len(), a[0])),
5882+ left.as_ref().map(|l| l.len()),
5883+ left.as_ref().map(|l| l[0]),
5884+ self.tile_x0, self.tile_y0, self.true_width, self.true_height
5885+ );
5886+ }
5565 let mut prediction = vec![0u16; bw * bh];5887 let mut prediction = vec![0u16; bw * bh];
5566 if let Some(fi_mode) = filter_intra {5888 if let Some(fi_mode) = filter_intra {
5567 crate::intra::predict_filter_intra(5889 crate::intra::predict_filter_intra(
@@ -5906,11 +6228,14 @@ fn decode_block(
5906 // 5.11.40); `coeff_tx_side` is the actual coded coefficient grid's side,6228 // 5.11.40); `coeff_tx_side` is the actual coded coefficient grid's side,
5907 // which only differs from it at that one corner case.6229 // which only differs from it at that one corner case.
5908 let (logical_tx, coeff_tx_side) = if tx_select {6230 let (logical_tx, coeff_tx_side) = if tx_select {
5909- let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side);6231+ let resolved = read_tx_size(dec, cdfs, neighbours, (mi_r, mi_c), side, None);
5910 (resolved, if resolved == 64 { 32 } else { resolved })6232 (resolved, if resolved == 64 { 32 } else { resolved })
5911 } else {6233 } else {
5912 (side, luma_tx)6234 (side, luma_tx)
5913 };6235 };
6236+ if tx_select && logical_tx < side && uv_mode != DC_PRED {
6237+ SQ_CHROMA_TX_HITS.with(|c| c.set(c.get() + 1));
6238+ }
5914 let luma_set = if tx_select {6239 let luma_set = if tx_select {
5915 txbset_for(logical_tx, reduced_tx_set)6240 txbset_for(logical_tx, reduced_tx_set)
5916 } else {6241 } else {
@@ -6351,7 +6676,7 @@ fn decode_leaf8(
6351 // transform units, same raster-order per-TU pattern `decode_block`'s6676 // transform units, same raster-order per-TU pattern `decode_block`'s
6352 // multi-TU branch runs).6677 // multi-TU branch runs).
6353 let resolved = if tx_select {6678 let resolved = if tx_select {
6354- read_tx_size(dec, cdfs, neighbours, leaf_mi, 8)6679+ read_tx_size(dec, cdfs, neighbours, leaf_mi, 8, None)
6355 } else {6680 } else {
6356 86681 8
6357 };6682 };
@@ -6830,6 +7155,11 @@ fn apply_deblock(
6830 frame_width: usize,7155 frame_width: usize,
6831 frame_height: usize,7156 frame_height: usize,
6832 ) {7157 ) {
7158+ // lane-part32 r2 debug rung, env-gated: bisecting a widespread pixel
7159+ // mismatch between the raw reconstruction and post-filter output.
7160+ if std::env::var_os("EC_AV1_DEBUG_SKIP_DEBLOCK").is_some() {
7161+ return;
7162+ }
6833 if lf.level[0] != 0 || lf.level[1] != 0 {7163 if lf.level[0] != 0 || lf.level[1] != 0 {
6834 deblock_plane(y, 0, lf, n, frame_width, frame_height);7164 deblock_plane(y, 0, lf, n, frame_width, frame_height);
6835 }7165 }
@@ -6879,6 +7209,33 @@ fn tx_size_context(n: &Neighbours, (mi_r, mi_c): (usize, usize), own_side: usize
6879 usize::from(above) + usize::from(left)7209 usize::from(above) + usize::from(left)
6880 }7210 }
6881 7211
7212+/// `get_tx_size_context` as libaom actually writes it (`pred_common.h:342`),
7213+/// for a block inside an INTER frame: the two `TXFM_CONTEXT` arrays
7214+/// ([`Neighbours::above_txfm`]/[`Neighbours::left_txfm`], which only the
7215+/// inter path maintains), except that an *inter* neighbour contributes its
7216+/// own BLOCK size rather than its transform size -- the two differ the moment
7217+/// a neighbour's var-tx tree splits. [`tx_size_context`]'s deblock-grid
7218+/// approximation coincides with this only while every neighbour codes one
7219+/// whole-block transform, which is exactly what `TxMode::Select` ends.
7220+fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize), side: usize) -> usize {
7221+ let has_above = mi_r > n.tile_row0_mi;
7222+ let has_left = mi_c > n.tile_col0_mi;
7223+ let mut above = usize::from(n.above_txfm[mi_c]) >= side;
7224+ let mut left = usize::from(n.left_txfm[mi_r]) >= side;
7225+ if has_above && n.above_inter[mi_c / (SUB / MI)] {
7226+ above = n.above_side_mi[mi_c] >= side;
7227+ }
7228+ if has_left && n.left_inter[mi_r / (SUB / MI)] {
7229+ left = n.left_side_mi[mi_r] >= side;
7230+ }
7231+ match (has_above, has_left) {
7232+ (true, true) => usize::from(above) + usize::from(left),
7233+ (true, false) => usize::from(above),
7234+ (false, true) => usize::from(left),
7235+ (false, false) => 0,
7236+ }
7237+}
7238+
6882 /// `read_tx_size`/`read_selected_tx_size` (spec 5.11.16): under7239 /// `read_tx_size`/`read_selected_tx_size` (spec 5.11.16): under
6883 /// `TxMode::Select`, an intra block's `tx_depth` symbol, resolved straight to7240 /// `TxMode::Select`, an intra block's `tx_depth` symbol, resolved straight to
6884 /// the transform's own side in pixels (`side >> depth`) -- this decoder's7241 /// the transform's own side in pixels (`side >> depth`) -- this decoder's
@@ -6890,8 +7247,12 @@ fn read_tx_size(
6890 n: &Neighbours,7247 n: &Neighbours,
6891 at_mi: (usize, usize),7248 at_mi: (usize, usize),
6892 side: usize,7249 side: usize,
7250+ // lane-txselect: `get_tx_size_context`'s real context, for the callers
7251+ // that have one -- see [`tx_size_context_txfm`]. `None` keeps the
7252+ // key-frame path's own deblock-grid approximation.
7253+ ctx_override: Option<usize>,
6893 ) -> usize {7254 ) -> usize {
6894- let ctx = tx_size_context(n, at_mi, side);7255+ let ctx = ctx_override.unwrap_or_else(|| tx_size_context(n, at_mi, side));
6895 let depth = match side {7256 let depth = match side {
6896 8 => {7257 8 => {
6897 dec.symbol(&mut cdfs.tx_size_cat0[ctx])7258 dec.symbol(&mut cdfs.tx_size_cat0[ctx])
@@ -6920,86 +7281,429 @@ fn read_tx_size(
6920 side >> depth7281 side >> depth
6921 }7282 }
6922 7283
6923-/// The luma coefficient scan table for a resolved transform side -- 32/16/8/4,7284+/// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's
6924-/// the only four sizes a `TxMode::Select` block's coded coefficient grid7285+/// `txfm_split` context -- a category from the block's own largest square
6925-/// ([`read_tx_size`]'s resolved side, or 32 at the 64x64 corner case) can be.7286+/// transform and whether this unit already sits below it, times three, plus
6926-fn scan_for<'a>(7287+/// the two neighbour terms (whether the transform last written above/left of
7288+/// this unit is narrower/shorter than the unit itself).
7289+fn txfm_partition_ctx(above_px: u8, left_px: u8, blk_max_px: usize, tx_px: usize) -> usize {
7290+ let above = usize::from(usize::from(above_px) < tx_px);
7291+ let left = usize::from(usize::from(left_px) < tx_px);
7292+ // `get_sqr_tx_size(max(block_size_wide, block_size_high))`, capped at the
7293+ // largest transform (`TX_64X64`); `TX_4X4`..`TX_64X64` index as
7294+ // `log2(px) - 2`.
7295+ let max_tx = blk_max_px.min(64);
7296+ let max_idx = max_tx.trailing_zeros() as usize - 2;
7297+ let category = usize::from(tx_px != max_tx && max_tx > 8) + (4 - max_idx) * 2;
7298+ category * 3 + above + left
7299+}
7300+
7301+/// `txfm_partition_update` (libaom `av1_common_int.h`): once a var-tx unit
7302+/// resolves, every mi cell its *parent* unit (`txb_px`) spans records the
7303+/// resolved transform's own size.
7304+fn txfm_partition_update(
7305+ n: &mut Neighbours,
7306+ (mi_r, mi_c): (usize, usize),
6927 tx_px: usize,7307 tx_px: usize,
6928- scan32: &'a [u16],7308+ txb_px: usize,
6929- scan16: &'a [u16],7309+) {
6930- scan8: &'a [u16],7310+ for i in 0..txb_px / MI {
6931- scan4: &'a [u16],7311+ if let Some(cell) = n.left_txfm.get_mut(mi_r + i) {
6932-) -> &'a [u16] {7312+ *cell = tx_px as u8;
6933- match tx_px {
6934- 32 => scan32,
6935- 16 => scan16,
6936- 8 => scan8,
6937- 4 => scan4,
6938- _ => unreachable!("read_tx_size never resolves the coefficient grid to anything else"),
6939 }7313 }
7314+ if let Some(cell) = n.above_txfm.get_mut(mi_c + i) {
7315+ *cell = tx_px as u8;
6940 }7316 }
6941-
6942-/// The [`TxbSet`] a resolved luma transform side reads its coefficient tables
6943-/// from -- 64 is only ever the 64x64-block, depth-0, corner-scanned case
6944-/// ([`TxbSet::Luma64`]); every other resolved side maps to its own matching
6945-/// set. `get_tx_set` (spec 5.11.48) only splits on `reduced_tx_set` at
6946-/// `TX_8X8`/`TX_4X4`: an intra `TX_16X16` always reads `TX_SET_INTRA_2`
6947-/// regardless of the flag (`av1_get_ext_tx_set_type`'s
6948-/// `tx_size_sqr == TX_16X16` branch ignores `use_reduced_set` once it is past
6949-/// the `TX_32X32`/reduced-set checks), so only the 8x8 and 4x4 cases have a
6950-/// second table ([`TxbSet::Luma8Set1`]/[`TxbSet::Luma4Set1`]).
6951-/// [`txbset_for`], for a block libaom's `is_inter_block` calls inter -- which
6952-/// an intrabc block is (`blockd.h:373`), so its `tx_type` comes off the
6953-/// inter `ext_tx` sets, never the mode-indexed intra ones.
6954-fn txbset_for_inter(tx_px: usize, reduced_tx_set: bool) -> TxbSet {
6955- match tx_px {
6956- 64 => TxbSet::Luma64,
6957- 32 => TxbSet::Luma32Inter,
6958- 16 if reduced_tx_set => TxbSet::Luma16Inter,
6959- 16 => TxbSet::Luma16InterSet1,
6960- 8 if reduced_tx_set => TxbSet::Luma8Inter,
6961- 8 => TxbSet::Luma8InterSet1,
6962- _ => TxbSet::Luma64,
6963 }7317 }
6964 }7318 }
6965 7319
6966-fn txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet {7320+/// `set_txfm_ctxs` (libaom `av1_common_int.h`): the non-var-tx write of the
6967- match tx_px {7321+/// same contexts -- a skipped *inter* block records its own block size rather
6968- 64 => TxbSet::Luma64,7322+/// than its transform size.
6969- 32 => TxbSet::Luma32,7323+fn set_txfm_ctxs(
6970- 16 => TxbSet::Luma16,7324+ n: &mut Neighbours,
6971- 8 if reduced_tx_set => TxbSet::Luma8,7325+ (mi_r, mi_c): (usize, usize),
6972- 8 => TxbSet::Luma8Set1,7326+ tx_px: usize,
6973- 4 if reduced_tx_set => TxbSet::Luma4,7327+ w_mi: usize,
6974- 4 => TxbSet::Luma4Set1,7328+ h_mi: usize,
6975- _ => unreachable!("read_tx_size never resolves a block's own side to anything else"),7329+ skip_inter: bool,
7330+) {
7331+ let bw = if skip_inter { w_mi * MI } else { tx_px };
7332+ let bh = if skip_inter { h_mi * MI } else { tx_px };
7333+ for i in 0..w_mi {
7334+ if let Some(cell) = n.above_txfm.get_mut(mi_c + i) {
7335+ *cell = bw as u8;
7336+ }
7337+ }
7338+ for i in 0..h_mi {
7339+ if let Some(cell) = n.left_txfm.get_mut(mi_r + i) {
7340+ *cell = bh as u8;
7341+ }
6976 }7342 }
6977 }7343 }
6978 7344
6979-/// `tx_size_wide_unit_log2`/`tx_size_high_unit_log2`: `log2(px / 4)`, the7345+/// The value libaom initialises both transform contexts to -- NOT zero:
6980-/// index [`tx_dim_to_filter_length`] and the chroma 4-vs-6 choice key on.7346+/// `av1_zero_above_context` memsets the txfm row to
6981-fn unit_log2(px: u32) -> i32 {7347+/// `tx_size_wide[TX_SIZES_LARGEST]` and `av1_zero_left_context` does the same
6982- if px == 0 {7348+/// with `tx_size_high[TX_SIZES_LARGEST]` (`av1_common_int.h`), i.e. 64
6983- 07349+/// pixels, so an unwritten neighbour reads as the *widest* possible
6984- } else {7350+/// transform, not the narrowest.
6985- px.trailing_zeros() as i32 - 27351+const TXFM_CTX_INIT: u8 = 64;
7352+
7353+/// libaom's `MAX_VARTX_DEPTH`: an inter block's transform tree halves at most
7354+/// twice below its own largest transform.
7355+const MAX_VARTX_DEPTH: usize = 2;
7356+
7357+/// `read_var_tx_size` (spec 5.11.17, libaom `decodeframe.c`
7358+/// `read_tx_size_vartx`): the recursive `txfm_split` tree of one
7359+/// max-transform-sized unit of an inter block, collecting the resolved leaf
7360+/// transform units into `out` as `(row offset, col offset, side)` in mi units
7361+/// -- exactly the order `decode_reconstruct_tx` later reads their
7362+/// coefficients in. `blk_row`/`blk_col` are mi offsets inside the block;
7363+/// `max_w_mi`/`max_h_mi` clip it to the true frame edge (`max_block_wide`/
7364+/// `max_block_high`).
7365+#[allow(clippy::too_many_arguments)]
7366+fn read_var_tx_size(
7367+ dec: &mut SymbolDecoder,
7368+ cdfs: &mut Cdfs,
7369+ n: &mut Neighbours,
7370+ at_mi: (usize, usize),
7371+ blk_max_px: usize,
7372+ (max_w_mi, max_h_mi): (usize, usize),
7373+ tx_px: usize,
7374+ depth: usize,
7375+ blk_row: usize,
7376+ blk_col: usize,
7377+ out: &mut Vec<(usize, usize, usize)>,
7378+) {
7379+ if blk_row >= max_h_mi || blk_col >= max_w_mi {
7380+ return;
7381+ }
7382+ let unit = (at_mi.0 + blk_row, at_mi.1 + blk_col);
7383+ if depth == MAX_VARTX_DEPTH {
7384+ out.push((blk_row, blk_col, tx_px));
7385+ txfm_partition_update(n, unit, tx_px, tx_px);
7386+ return;
7387+ }
7388+ let ctx = txfm_partition_ctx(n.above_txfm[unit.1], n.left_txfm[unit.0], blk_max_px, tx_px);
7389+ let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;
7390+ TXFM_SPLIT_READS.with(|c| c.set(c.get() + 1));
7391+ if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {
7392+ let (rng, _) = dec.debug_state();
7393+ eprintln!(
7394+ "EC_ISTEP mi_row={} mi_col={} name=txfm_split val={} ctx={ctx} rng={rng}",
7395+ unit.0,
7396+ unit.1,
7397+ u8::from(split)
7398+ );
7399+ }
7400+ if !split {
7401+ out.push((blk_row, blk_col, tx_px));
7402+ txfm_partition_update(n, unit, tx_px, tx_px);
7403+ return;
7404+ }
7405+ TXFM_SPLIT_HITS.with(|c| c.set(c.get() + 1));
7406+ let sub = tx_px / 2;
7407+ if sub == 4 {
7408+ // libaom's `sub_txs == TX_4X4` early return: the whole 8x8 unit is
7409+ // marked 4x4 (four transform units, raster order) without recursing.
7410+ for row in 0..2 {
7411+ for col in 0..2 {
7412+ if blk_row + row < max_h_mi && blk_col + col < max_w_mi {
7413+ out.push((blk_row + row, blk_col + col, 4));
7414+ }
7415+ }
7416+ }
7417+ txfm_partition_update(n, unit, 4, tx_px);
7418+ return;
7419+ }
7420+ for row in (0..tx_px / MI).step_by(sub / MI) {
7421+ for col in (0..tx_px / MI).step_by(sub / MI) {
7422+ read_var_tx_size(
7423+ dec,
7424+ cdfs,
7425+ n,
7426+ at_mi,
7427+ blk_max_px,
7428+ (max_w_mi, max_h_mi),
7429+ sub,
7430+ depth + 1,
7431+ blk_row + row,
7432+ blk_col + col,
7433+ out,
7434+ );
7435+ }
6986 }7436 }
6987 }7437 }
6988 7438
6989-/// spec 7.14.4's `get_filter_level`: `ref_deltas` is indexed by the block's7439+/// `read_block_tx_size` (libaom `decodeframe.c` `parse_decode_block`'s tx
6990-/// reference frame, `mode_deltas` by `mode_lf_lut[mode]` -- `0` for7440+/// branch): every block of a `TxMode::Select` inter frame codes its transform
6991-/// `GLOBALMV`, `1` for `NEARESTMV`/`NEARMV`/`NEWMV` (intra gets no mode7441+/// size right after its own mode info -- an inter non-skip block through the
6992-/// delta). `ref_frame` here is [`Neighbours::ref_grid`]'s packed cell:7442+/// recursive var-tx tree ([`read_var_tx_size`], whose leaf list this returns),
6993-/// magnitude = reference (`0` = intra), sign = `GLOBALMV` (lane-av1golden2:7443+/// every other block through the intra `tx_depth` symbol (a skipped inter
6994-/// the flat `mode_deltas[1]` this used before was a `LAST_FRAME`-reachable7444+/// block codes no symbol at all) plus a `set_txfm_ctxs` write. Returns the
6995-/// wrong delta on every `GLOBALMV` block, masked while any `GOLDEN_FRAME`7445+/// block's own resolved transform side and the leaf list, the latter only
6996-/// block anywhere aborted the whole stream's decode before comparison).7446+/// when the tree resolved to more than one transform unit.
6997-fn lf_level(7447+#[allow(clippy::too_many_arguments)]
6998- lf: &LoopFilterParams,7448+fn read_block_tx_size(
6999- plane_idx: usize,7449+ dec: &mut SymbolDecoder,
7000- dir: usize,7450+ cdfs: &mut Cdfs,
7001- ref_frame: i8,7451+ n: &mut Neighbours,
7002- delta_lf: i32,7452+ at_mi: (usize, usize),
7453+ side: usize,
7454+ (mi_cols, mi_rows): (usize, usize),
7455+ is_inter: bool,
7456+ skip: bool,
7457+) -> Result<(usize, Option<Vec<(usize, usize, usize)>>)> {
7458+ if !TX_SELECT_INTER.with(std::cell::Cell::get) {
7459+ return Ok((side, None));
7460+ }
7461+ let side_mi = side / MI;
7462+ if is_inter && !skip {
7463+ let max_tx = side.min(64);
7464+ let max_w_mi = side_mi.min(mi_cols.saturating_sub(at_mi.1));
7465+ let max_h_mi = side_mi.min(mi_rows.saturating_sub(at_mi.0));
7466+ let mut leaves = Vec::new();
7467+ let step = max_tx / MI;
7468+ for row in (0..side_mi).step_by(step) {
7469+ for col in (0..side_mi).step_by(step) {
7470+ read_var_tx_size(
7471+ dec,
7472+ cdfs,
7473+ n,
7474+ at_mi,
7475+ side,
7476+ (max_w_mi, max_h_mi),
7477+ max_tx,
7478+ 0,
7479+ row,
7480+ col,
7481+ &mut leaves,
7482+ );
7483+ }
7484+ }
7485+ let single = leaves.len() == 1 && leaves[0].2 == side;
7486+ if !single && leaves.iter().any(|leaf| leaf.2 > 32) {
7487+ // Only a block wider than a superblock's own 64x64 max transform
7488+ // reaches here; this crate has no 64-point *inter* coefficient
7489+ // table set ([`inter_txbset_for`] stops at 32).
7490+ return Err(unsupported(
7491+ "an inter var-tx tree with a leaf transform larger than 32x32",
7492+ ));
7493+ }
7494+ let resolved = leaves.last().map_or(side, |l| l.2);
7495+ return Ok((resolved, (!single).then_some(leaves)));
7496+ }
7497+ let tx = if is_inter {
7498+ side.min(64)
7499+ } else {
7500+ let resolved = read_tx_size(
7501+ dec,
7502+ cdfs,
7503+ n,
7504+ at_mi,
7505+ side,
7506+ Some(tx_size_context_txfm(n, at_mi, side)),
7507+ );
7508+ if resolved != side {
7509+ // An intra block inside an inter frame whose `tx_depth` splits its
7510+ // luma transform needs the per-transform-unit intra prediction
7511+ // loop `decode_block` runs for a key frame; this path predicts the
7512+ // whole block at once, so refuse rather than mis-reconstruct.
7513+ return Err(unsupported(
7514+ "an intra block in an inter frame whose tx_depth splits its luma transform \
7515+ (round 1)",
7516+ ));
7517+ }
7518+ resolved
7519+ };
7520+ set_txfm_ctxs(n, at_mi, tx, side_mi, side_mi, skip && is_inter);
7521+ Ok((tx, None))
7522+}
7523+
7524+/// One 8x8 inter leaf's luma residual (lane-txselect): either the whole-8x8
7525+/// transform, or -- when [`read_block_tx_size`]'s var-tx tree took the single
7526+/// split a `BLOCK_8X8` can take (`split`) -- the four 4x4 transform units in
7527+/// raster order, each reading its own coefficient context off the units
7528+/// already decoded before it. Returns the block's luma grid (all-zero in the
7529+/// split case, whose reconstruction has already happened unit by unit) and
7530+/// the `tx_type` chroma inherits: `av1_get_tx_type`'s colocated luma lookup,
7531+/// which for a split block lands on the top-left unit.
7532+#[allow(clippy::too_many_arguments)]
7533+fn read_inter_luma8(
7534+ dec: &mut SymbolDecoder,
7535+ cdfs: &mut Cdfs,
7536+ neighbours: &mut Neighbours,
7537+ leaf_mi: (usize, usize),
7538+ y: &mut PlaneBuf,
7539+ px: usize,
7540+ py: usize,
7541+ pred_y: &[u16],
7542+ mode_for_tx: usize,
7543+ base_q_idx: u8,
7544+ scan8: &[u16],
7545+ scan4: &[u16],
7546+ reduced_tx_set: bool,
7547+ split: bool,
7548+) -> Result<(Vec<i32>, TxType)> {
7549+ if !split {
7550+ return read_inter_plane(
7551+ dec,
7552+ cdfs,
7553+ if reduced_tx_set {
7554+ TxbSet::Luma8Inter
7555+ } else {
7556+ TxbSet::Luma8InterSet1
7557+ },
7558+ scan8,
7559+ 0,
7560+ neighbours.around_mi(leaf_mi, 8)[0],
7561+ mode_for_tx,
7562+ y,
7563+ px,
7564+ py,
7565+ 8,
7566+ base_q_idx,
7567+ pred_y,
7568+ None,
7569+ None,
7570+ );
7571+ }
7572+ let mut first = TxType::DctDct;
7573+ for tu_row in 0..2 {
7574+ for tu_col in 0..2 {
7575+ let tu_mi = (leaf_mi.0 + tu_row, leaf_mi.1 + tu_col);
7576+ let mut tu_pred = Vec::with_capacity(16);
7577+ for rr in 0..4 {
7578+ let start = (tu_row * 4 + rr) * 8 + tu_col * 4;
7579+ tu_pred.extend_from_slice(&pred_y[start..start + 4]);
7580+ }
7581+ let tu_skip_ctx = neighbours.luma_skip_ctx(tu_mi, 1);
7582+ let (tu_grid, tu_tx_type) = read_inter_plane(
7583+ dec,
7584+ cdfs,
7585+ if reduced_tx_set {
7586+ TxbSet::Luma4Inter
7587+ } else {
7588+ TxbSet::Luma4InterSet1
7589+ },
7590+ scan4,
7591+ 0,
7592+ neighbours.around_mi(tu_mi, 4)[0],
7593+ mode_for_tx,
7594+ y,
7595+ px + tu_col * 4,
7596+ py + tu_row * 4,
7597+ 4,
7598+ base_q_idx,
7599+ &tu_pred,
7600+ None,
7601+ Some(tu_skip_ctx),
7602+ )?;
7603+ if tu_row == 0 && tu_col == 0 {
7604+ first = tu_tx_type;
7605+ }
7606+ neighbours.record_mi_luma(tu_mi, 4, &tu_grid);
7607+ }
7608+ }
7609+ Ok((vec![0i32; 64], first))
7610+}
7611+
7612+/// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its
7613+/// coefficient tables from -- the inter counterpart of [`txbset_for`].
7614+fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet {
7615+ match tx_px {
7616+ 32 => TxbSet::Luma32Inter,
7617+ 16 if reduced_tx_set => TxbSet::Luma16Inter,
7618+ 16 => TxbSet::Luma16InterSet1,
7619+ 8 if reduced_tx_set => TxbSet::Luma8Inter,
7620+ 8 => TxbSet::Luma8InterSet1,
7621+ 4 if reduced_tx_set => TxbSet::Luma4Inter,
7622+ 4 => TxbSet::Luma4InterSet1,
7623+ _ => unreachable!("a var-tx leaf is never wider than a 64x64 block's 32x32 sub-transform"),
7624+ }
7625+}
7626+
7627+/// The luma coefficient scan table for a resolved transform side -- 32/16/8/4,
7628+/// the only four sizes a `TxMode::Select` block's coded coefficient grid
7629+/// ([`read_tx_size`]'s resolved side, or 32 at the 64x64 corner case) can be.
7630+fn scan_for<'a>(
7631+ tx_px: usize,
7632+ scan32: &'a [u16],
7633+ scan16: &'a [u16],
7634+ scan8: &'a [u16],
7635+ scan4: &'a [u16],
7636+) -> &'a [u16] {
7637+ match tx_px {
7638+ 32 => scan32,
7639+ 16 => scan16,
7640+ 8 => scan8,
7641+ 4 => scan4,
7642+ _ => unreachable!("read_tx_size never resolves the coefficient grid to anything else"),
7643+ }
7644+}
7645+
7646+/// The [`TxbSet`] a resolved luma transform side reads its coefficient tables
7647+/// from -- 64 is only ever the 64x64-block, depth-0, corner-scanned case
7648+/// ([`TxbSet::Luma64`]); every other resolved side maps to its own matching
7649+/// set. `get_tx_set` (spec 5.11.48) only splits on `reduced_tx_set` at
7650+/// `TX_8X8`/`TX_4X4`: an intra `TX_16X16` always reads `TX_SET_INTRA_2`
7651+/// regardless of the flag (`av1_get_ext_tx_set_type`'s
7652+/// `tx_size_sqr == TX_16X16` branch ignores `use_reduced_set` once it is past
7653+/// the `TX_32X32`/reduced-set checks), so only the 8x8 and 4x4 cases have a
7654+/// second table ([`TxbSet::Luma8Set1`]/[`TxbSet::Luma4Set1`]).
7655+/// [`txbset_for`], for a block libaom's `is_inter_block` calls inter -- which
7656+/// an intrabc block is (`blockd.h:373`), so its `tx_type` comes off the
7657+/// inter `ext_tx` sets, never the mode-indexed intra ones.
7658+fn txbset_for_inter(tx_px: usize, reduced_tx_set: bool) -> TxbSet {
7659+ match tx_px {
7660+ 64 => TxbSet::Luma64,
7661+ 32 => TxbSet::Luma32Inter,
7662+ 16 if reduced_tx_set => TxbSet::Luma16Inter,
7663+ 16 => TxbSet::Luma16InterSet1,
7664+ 8 if reduced_tx_set => TxbSet::Luma8Inter,
7665+ 8 => TxbSet::Luma8InterSet1,
7666+ _ => TxbSet::Luma64,
7667+ }
7668+}
7669+
7670+fn txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet {
7671+ match tx_px {
7672+ 64 => TxbSet::Luma64,
7673+ 32 => TxbSet::Luma32,
7674+ 16 => TxbSet::Luma16,
7675+ 8 if reduced_tx_set => TxbSet::Luma8,
7676+ 8 => TxbSet::Luma8Set1,
7677+ 4 if reduced_tx_set => TxbSet::Luma4,
7678+ 4 => TxbSet::Luma4Set1,
7679+ _ => unreachable!("read_tx_size never resolves a block's own side to anything else"),
7680+ }
7681+}
7682+
7683+/// `tx_size_wide_unit_log2`/`tx_size_high_unit_log2`: `log2(px / 4)`, the
7684+/// index [`tx_dim_to_filter_length`] and the chroma 4-vs-6 choice key on.
7685+fn unit_log2(px: u32) -> i32 {
7686+ if px == 0 {
7687+ 0
7688+ } else {
7689+ px.trailing_zeros() as i32 - 2
7690+ }
7691+}
7692+
7693+/// spec 7.14.4's `get_filter_level`: `ref_deltas` is indexed by the block's
7694+/// reference frame, `mode_deltas` by `mode_lf_lut[mode]` -- `0` for
7695+/// `GLOBALMV`, `1` for `NEARESTMV`/`NEARMV`/`NEWMV` (intra gets no mode
7696+/// delta). `ref_frame` here is [`Neighbours::ref_grid`]'s packed cell:
7697+/// magnitude = reference (`0` = intra), sign = `GLOBALMV` (lane-av1golden2:
7698+/// the flat `mode_deltas[1]` this used before was a `LAST_FRAME`-reachable
7699+/// wrong delta on every `GLOBALMV` block, masked while any `GOLDEN_FRAME`
7700+/// block anywhere aborted the whole stream's decode before comparison).
7701+fn lf_level(
7702+ lf: &LoopFilterParams,
7703+ plane_idx: usize,
7704+ dir: usize,
7705+ ref_frame: i8,
7706+ delta_lf: i32,
7003 segment_id: u8,7707 segment_id: u8,
7004 ) -> i32 {7708 ) -> i32 {
7005 let base = i32::from(if plane_idx == 0 {7709 let base = i32::from(if plane_idx == 0 {
@@ -7478,6 +8182,10 @@ fn apply_cdef(
7478 cdef: &CdefParams,8182 cdef: &CdefParams,
7479 skip_grid: &Neighbours,8183 skip_grid: &Neighbours,
7480 ) {8184 ) {
8185+ // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling.
8186+ if std::env::var_os("EC_AV1_DEBUG_SKIP_CDEF").is_some() {
8187+ return;
8188+ }
7481 // `cdef.bits == 0` still means "no filtering at all" whenever the single8189 // `cdef.bits == 0` still means "no filtering at all" whenever the single
7482 // (index 0) strength pair is all-zero -- the fast path every existing8190 // (index 0) strength pair is all-zero -- the fast path every existing
7483 // gate stream takes. A `bits > 0` frame can still be all-zero-strength8191 // gate stream takes. A `bits > 0` frame can still be all-zero-strength
@@ -8119,6 +8827,18 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
8119 }8827 }
8120 if part16 == PARTITION_VERT_B {8828 if part16 == PARTITION_VERT_B {
8121 VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1));8829 VERT_B_INTRA_HITS.with(|c| c.set(c.get() + 1));
8830+ // lane-part32 r6: same availability
8831+ // defect r5 fixed one level up --
8832+ // the TR/BR 8x8 squares below are
8833+ // visited out of raster order, so
8834+ // they need libaom's
8835+ // `has_tr_vert_*`/`has_bl_vert_*`
8836+ // tables (the left 8x16 rect goes
8837+ // through `Reach::of_rect`, which
8838+ // the guard deliberately does not
8839+ // affect).
8840+ let _vert_ab =
8841+ crate::encode::Reach::vert_ab_partition();
8122 // Left rect: 8x16, real8842 // Left rect: 8x16, real
8123 // `decode_block_rect`, sat at the8843 // `decode_block_rect`, sat at the
8124 // 16x16 parent's own origin (no8844 // 16x16 parent's own origin (no
@@ -8447,7 +9167,268 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
8447 &mut v,9167 &mut v,
8448 enable_filter_intra,9168 enable_filter_intra,
8449 allow_screen_content_tools,9169 allow_screen_content_tools,
8450- base_q_idx,9170+ base_q_idx,
9171+ tx_select,
9172+ reduced_tx_set,
9173+ )?;
9174+ decode_block_rect(
9175+ &mut dec,
9176+ &mut cdfs,
9177+ &mut neighbours,
9178+ (at32.0 + 1, at32.1),
9179+ 32,
9180+ 16,
9181+ &mut y,
9182+ &mut u,
9183+ &mut v,
9184+ enable_filter_intra,
9185+ allow_screen_content_tools,
9186+ base_q_idx,
9187+ tx_select,
9188+ reduced_tx_set,
9189+ )?;
9190+ }
9191+ PARTITION_VERT => {
9192+ // lane-intradisp r1: mirror of PARTITION_HORZ
9193+ // above with width/height swapped.
9194+ decode_block_rect(
9195+ &mut dec,
9196+ &mut cdfs,
9197+ &mut neighbours,
9198+ at32,
9199+ 16,
9200+ 32,
9201+ &mut y,
9202+ &mut u,
9203+ &mut v,
9204+ enable_filter_intra,
9205+ allow_screen_content_tools,
9206+ base_q_idx,
9207+ tx_select,
9208+ reduced_tx_set,
9209+ )?;
9210+ decode_block_rect(
9211+ &mut dec,
9212+ &mut cdfs,
9213+ &mut neighbours,
9214+ (at32.0, at32.1 + 1),
9215+ 16,
9216+ 32,
9217+ &mut y,
9218+ &mut u,
9219+ &mut v,
9220+ enable_filter_intra,
9221+ allow_screen_content_tools,
9222+ base_q_idx,
9223+ tx_select,
9224+ reduced_tx_set,
9225+ )?;
9226+ }
9227+ PARTITION_HORZ_A => {
9228+ // lane-part32 r1: two 16x16 squares on top +
9229+ // a true 32x16 strip below (mirrors
9230+ // decode_inter_block's cd6cb6d HORZ_A: TL,
9231+ // TR, bottom strip).
9232+ INTRA_HORZ_A_HITS.with(|c| c.set(c.get() + 1));
9233+ decode_block(
9234+ &mut dec,
9235+ &mut cdfs,
9236+ &mut neighbours,
9237+ at32,
9238+ SUB,
9239+ TxbSet::Luma16,
9240+ TxbSet::Chroma8,
9241+ TX16,
9242+ TX8,
9243+ (&scan16, &scan8),
9244+ true,
9245+ &mut y,
9246+ &mut u,
9247+ &mut v,
9248+ base_q_idx,
9249+ enable_filter_intra,
9250+ allow_screen_content_tools,
9251+ allow_intrabc,
9252+ &scan32,
9253+ &scan16,
9254+ &scan8,
9255+ &scan4,
9256+ tx_select,
9257+ reduced_tx_set,
9258+ )?;
9259+ decode_block(
9260+ &mut dec,
9261+ &mut cdfs,
9262+ &mut neighbours,
9263+ (at32.0, at32.1 + 1),
9264+ SUB,
9265+ TxbSet::Luma16,
9266+ TxbSet::Chroma8,
9267+ TX16,
9268+ TX8,
9269+ (&scan16, &scan8),
9270+ true,
9271+ &mut y,
9272+ &mut u,
9273+ &mut v,
9274+ base_q_idx,
9275+ enable_filter_intra,
9276+ allow_screen_content_tools,
9277+ allow_intrabc,
9278+ &scan32,
9279+ &scan16,
9280+ &scan8,
9281+ &scan4,
9282+ tx_select,
9283+ reduced_tx_set,
9284+ )?;
9285+ decode_block_rect(
9286+ &mut dec,
9287+ &mut cdfs,
9288+ &mut neighbours,
9289+ (at32.0 + 1, at32.1),
9290+ 32,
9291+ 16,
9292+ &mut y,
9293+ &mut u,
9294+ &mut v,
9295+ enable_filter_intra,
9296+ allow_screen_content_tools,
9297+ base_q_idx,
9298+ tx_select,
9299+ reduced_tx_set,
9300+ )?;
9301+ }
9302+ PARTITION_HORZ_B => {
9303+ // lane-part32 r1: a true 32x16 strip on top +
9304+ // two 16x16 squares below (mirrors HORZ_A
9305+ // with the strip/squares order flipped, same
9306+ // shape as libaom decode_partition's HORZ_B).
9307+ INTRA_HORZ_B_HITS.with(|c| c.set(c.get() + 1));
9308+ decode_block_rect(
9309+ &mut dec,
9310+ &mut cdfs,
9311+ &mut neighbours,
9312+ at32,
9313+ 32,
9314+ 16,
9315+ &mut y,
9316+ &mut u,
9317+ &mut v,
9318+ enable_filter_intra,
9319+ allow_screen_content_tools,
9320+ base_q_idx,
9321+ tx_select,
9322+ reduced_tx_set,
9323+ )?;
9324+ decode_block(
9325+ &mut dec,
9326+ &mut cdfs,
9327+ &mut neighbours,
9328+ (at32.0 + 1, at32.1),
9329+ SUB,
9330+ TxbSet::Luma16,
9331+ TxbSet::Chroma8,
9332+ TX16,
9333+ TX8,
9334+ (&scan16, &scan8),
9335+ true,
9336+ &mut y,
9337+ &mut u,
9338+ &mut v,
9339+ base_q_idx,
9340+ enable_filter_intra,
9341+ allow_screen_content_tools,
9342+ allow_intrabc,
9343+ &scan32,
9344+ &scan16,
9345+ &scan8,
9346+ &scan4,
9347+ tx_select,
9348+ reduced_tx_set,
9349+ )?;
9350+ decode_block(
9351+ &mut dec,
9352+ &mut cdfs,
9353+ &mut neighbours,
9354+ (at32.0 + 1, at32.1 + 1),
9355+ SUB,
9356+ TxbSet::Luma16,
9357+ TxbSet::Chroma8,
9358+ TX16,
9359+ TX8,
9360+ (&scan16, &scan8),
9361+ true,
9362+ &mut y,
9363+ &mut u,
9364+ &mut v,
9365+ base_q_idx,
9366+ enable_filter_intra,
9367+ allow_screen_content_tools,
9368+ allow_intrabc,
9369+ &scan32,
9370+ &scan16,
9371+ &scan8,
9372+ &scan4,
9373+ tx_select,
9374+ reduced_tx_set,
9375+ )?;
9376+ }
9377+ PARTITION_VERT_A => {
9378+ // lane-part32 r1: mirror of HORZ_A with
9379+ // width/height swapped (TL, BL, right 16x32
9380+ // strip).
9381+ INTRA_VERT_A_HITS.with(|c| c.set(c.get() + 1));
9382+ let _vert_ab = crate::encode::Reach::vert_ab_partition();
9383+ decode_block(
9384+ &mut dec,
9385+ &mut cdfs,
9386+ &mut neighbours,
9387+ at32,
9388+ SUB,
9389+ TxbSet::Luma16,
9390+ TxbSet::Chroma8,
9391+ TX16,
9392+ TX8,
9393+ (&scan16, &scan8),
9394+ true,
9395+ &mut y,
9396+ &mut u,
9397+ &mut v,
9398+ base_q_idx,
9399+ enable_filter_intra,
9400+ allow_screen_content_tools,
9401+ allow_intrabc,
9402+ &scan32,
9403+ &scan16,
9404+ &scan8,
9405+ &scan4,
9406+ tx_select,
9407+ reduced_tx_set,
9408+ )?;
9409+ decode_block(
9410+ &mut dec,
9411+ &mut cdfs,
9412+ &mut neighbours,
9413+ (at32.0 + 1, at32.1),
9414+ SUB,
9415+ TxbSet::Luma16,
9416+ TxbSet::Chroma8,
9417+ TX16,
9418+ TX8,
9419+ (&scan16, &scan8),
9420+ true,
9421+ &mut y,
9422+ &mut u,
9423+ &mut v,
9424+ base_q_idx,
9425+ enable_filter_intra,
9426+ allow_screen_content_tools,
9427+ allow_intrabc,
9428+ &scan32,
9429+ &scan16,
9430+ &scan8,
9431+ &scan4,
8451 tx_select,9432 tx_select,
8452 reduced_tx_set,9433 reduced_tx_set,
8453 )?;9434 )?;
@@ -8455,9 +9436,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
8455 &mut dec,9436 &mut dec,
8456 &mut cdfs,9437 &mut cdfs,
8457 &mut neighbours,9438 &mut neighbours,
8458- (at32.0 + 1, at32.1),9439+ (at32.0, at32.1 + 1),
8459- 32,
8460 16,9440 16,
9441+ 32,
8461 &mut y,9442 &mut y,
8462 &mut u,9443 &mut u,
8463 &mut v,9444 &mut v,
@@ -8468,9 +9449,13 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
8468 reduced_tx_set,9449 reduced_tx_set,
8469 )?;9450 )?;
8470 }9451 }
8471- PARTITION_VERT => {9452+ PARTITION_VERT_B => {
8472- // lane-intradisp r1: mirror of PARTITION_HORZ9453+ // lane-part32 r1: a true 16x32 strip on the
8473- // above with width/height swapped.9454+ // left + two 16x16 squares on the right
9455+ // (libaom decode_partition VERT_B: left
9456+ // strip, TR, BR).
9457+ INTRA_VERT_B_HITS.with(|c| c.set(c.get() + 1));
9458+ let _vert_ab = crate::encode::Reach::vert_ab_partition();
8474 decode_block_rect(9459 decode_block_rect(
8475 &mut dec,9460 &mut dec,
8476 &mut cdfs,9461 &mut cdfs,
@@ -8487,19 +9472,55 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
8487 tx_select,9472 tx_select,
8488 reduced_tx_set,9473 reduced_tx_set,
8489 )?;9474 )?;
8490- decode_block_rect(9475+ decode_block(
8491 &mut dec,9476 &mut dec,
8492 &mut cdfs,9477 &mut cdfs,
8493 &mut neighbours,9478 &mut neighbours,
8494 (at32.0, at32.1 + 1),9479 (at32.0, at32.1 + 1),
8495- 16,9480+ SUB,
8496- 32,9481+ TxbSet::Luma16,
9482+ TxbSet::Chroma8,
9483+ TX16,
9484+ TX8,
9485+ (&scan16, &scan8),
9486+ true,
8497 &mut y,9487 &mut y,
8498 &mut u,9488 &mut u,
8499 &mut v,9489 &mut v,
9490+ base_q_idx,
8500 enable_filter_intra,9491 enable_filter_intra,
8501 allow_screen_content_tools,9492 allow_screen_content_tools,
9493+ allow_intrabc,
9494+ &scan32,
9495+ &scan16,
9496+ &scan8,
9497+ &scan4,
9498+ tx_select,
9499+ reduced_tx_set,
9500+ )?;
9501+ decode_block(
9502+ &mut dec,
9503+ &mut cdfs,
9504+ &mut neighbours,
9505+ (at32.0 + 1, at32.1 + 1),
9506+ SUB,
9507+ TxbSet::Luma16,
9508+ TxbSet::Chroma8,
9509+ TX16,
9510+ TX8,
9511+ (&scan16, &scan8),
9512+ true,
9513+ &mut y,
9514+ &mut u,
9515+ &mut v,
8502 base_q_idx,9516 base_q_idx,
9517+ enable_filter_intra,
9518+ allow_screen_content_tools,
9519+ allow_intrabc,
9520+ &scan32,
9521+ &scan16,
9522+ &scan8,
9523+ &scan4,
8503 tx_select,9524 tx_select,
8504 reduced_tx_set,9525 reduced_tx_set,
8505 )?;9526 )?;
@@ -8583,10 +9604,103 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
8583 reduced_tx_set,9604 reduced_tx_set,
8584 )?;9605 )?;
8585 }9606 }
9607+ PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => {
9608+ // lane-part32 r4: the four superblock-level AB arms, each
9609+ // two 32x32 squares plus one 64x32/32x64 strip, in
9610+ // libaom's own `decode_partition` order (decodeframe.c:
9611+ // HORZ_A = TL, TR, bottom strip; HORZ_B = top strip, BL,
9612+ // BR; VERT_A = TL, BL, right strip; VERT_B = left strip,
9613+ // TR, BR). The pieces are exactly the ones already proven
9614+ // by the `PARTITION_NONE`-under-SPLIT (32x32 square) and
9615+ // `PARTITION_HORZ`/`VERT` (rect64 strip) arms above.
9616+ SB_AB_HITS.with(|c| {
9617+ let mut h = c.get();
9618+ h[part - PARTITION_HORZ_A] += 1;
9619+ c.set(h);
9620+ });
9621+ // lane-part32 r5: only the two VERTICAL arms reorder the
9622+ // square sub-blocks (TL, BL, TR, BR), so only they switch
9623+ // libaom's `has_tr`/`has_bl` tables.
9624+ let _vert_ab = (part == PARTITION_VERT_A || part == PARTITION_VERT_B)
9625+ .then(crate::encode::Reach::vert_ab_partition);
9626+ macro_rules! square32 {
9627+ ($at:expr) => {
9628+ decode_block(
9629+ &mut dec,
9630+ &mut cdfs,
9631+ &mut neighbours,
9632+ $at,
9633+ BLOCK,
9634+ TxbSet::Luma32,
9635+ TxbSet::Chroma16,
9636+ TX32,
9637+ TX16,
9638+ (&scan32, &scan16),
9639+ true,
9640+ &mut y,
9641+ &mut u,
9642+ &mut v,
9643+ base_q_idx,
9644+ enable_filter_intra,
9645+ allow_screen_content_tools,
9646+ allow_intrabc,
9647+ &scan32,
9648+ &scan16,
9649+ &scan8,
9650+ &scan4,
9651+ tx_select,
9652+ reduced_tx_set,
9653+ )?
9654+ };
9655+ }
9656+ macro_rules! strip64 {
9657+ ($at:expr, $bw:expr, $bh:expr) => {
9658+ decode_block_rect64(
9659+ &mut dec,
9660+ &mut cdfs,
9661+ &mut neighbours,
9662+ $at,
9663+ $bw,
9664+ $bh,
9665+ &mut y,
9666+ &mut u,
9667+ &mut v,
9668+ enable_filter_intra,
9669+ allow_screen_content_tools,
9670+ base_q_idx,
9671+ tx_select,
9672+ reduced_tx_set,
9673+ )?
9674+ };
9675+ }
9676+ let (br, bc) = (at.0 + 2, at.1 + 2);
9677+ match part {
9678+ PARTITION_HORZ_A => {
9679+ square32!(at);
9680+ square32!((at.0, bc));
9681+ strip64!((br, at.1), 64, 32);
9682+ }
9683+ PARTITION_HORZ_B => {
9684+ strip64!(at, 64, 32);
9685+ square32!((br, at.1));
9686+ square32!((br, bc));
9687+ }
9688+ PARTITION_VERT_A => {
9689+ square32!(at);
9690+ square32!((br, at.1));
9691+ strip64!((at.0, bc), 32, 64);
9692+ }
9693+ _ => {
9694+ strip64!(at, 32, 64);
9695+ square32!((at.0, bc));
9696+ square32!((br, bc));
9697+ }
9698+ }
9699+ }
8586 _ => {9700 _ => {
8587 return Err(unsupported(9701 return Err(unsupported(
8588- "a superblock-level partition type other than NONE or SPLIT (this \9702+ "a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, \
8589- decoder's intra tile path codes only those two at 64x64)",9703+ four 64x16/16x64 strips)",
8590 ));9704 ));
8591 }9705 }
8592 }9706 }
@@ -9047,9 +10161,15 @@ fn read_inter_plane(
9047 // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true10161 // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true
9048 // `DCT_DCT` default at 32-point+) already resolves it without help.10162 // `DCT_DCT` default at 32-point+) already resolves it without help.
9049 inherited_luma_tx_type: Option<TxType>,10163 inherited_luma_tx_type: Option<TxType>,
10164+ // lane-txselect: the luma `txb_skip_ctx` of a transform unit smaller than
10165+ // its own block (spec `get_txb_ctx_general`'s `plane_bsize != tx_size`
10166+ // branch, [`Neighbours::luma_skip_ctx`]) -- `None` for the whole-block
10167+ // transform every non-var-tx caller reads, whose plane-0 context is the
10168+ // lone-transform-unit 0.
10169+ luma_skip_ctx: Option<usize>,
9050 ) -> Result<(Vec<i32>, TxType)> {10170 ) -> Result<(Vec<i32>, TxType)> {
9051 let skip_ctx = if plane_idx == 0 {10171 let skip_ctx = if plane_idx == 0 {
9052- 010172+ luma_skip_ctx.unwrap_or(0)
9053 } else {10173 } else {
9054 usize::from(around.0) + usize::from(around.1)10174 usize::from(around.0) + usize::from(around.1)
9055 };10175 };
@@ -9067,6 +10187,23 @@ fn read_inter_plane(
9067 default_tx_type,10187 default_tx_type,
9068 None,10188 None,
9069 )?;10189 )?;
10190+ // lane-inter8 r1: a 64-point transform covers the whole 64x64 area but
10191+ // codes only its top-left 32x32 of frequencies (spec 5.11.40) -- the
10192+ // caller hands the 32-point `scan` there, and the coded corner goes into
10193+ // the top-left of the true `side`-sized grid before dequantization
10194+ // (dqDenom is keyed by the true size, not the corner's), mirroring
10195+ // [`read_plane`]'s own `tx_side != side` branch. Every other transform
10196+ // this decoder codes has `tx_side == side`, so this is inert below 64.
10197+ let tx_side = side.min(32);
10198+ let grid = if tx_side == side {
10199+ grid
10200+ } else {
10201+ let mut full = vec![0i32; side * side];
10202+ for row in 0..tx_side {
10203+ full[row * side..][..tx_side].copy_from_slice(&grid[row * tx_side..][..tx_side]);
10204+ }
10205+ full
10206+ };
9070 let (dc_delta, ac_delta) = plane_q_delta(plane_idx);10207 let (dc_delta, ac_delta) = plane_q_delta(plane_idx);
9071 let residual = dequant_and_inverse_typed(&grid, side, bit_depth(), block_q_idx(), dc_delta, ac_delta, tx_type);10208 let residual = dequant_and_inverse_typed(&grid, side, bit_depth(), block_q_idx(), dc_delta, ac_delta, tx_type);
9072 plane.reconstruct_mc(x, y, side, prediction, &residual);10209 plane.reconstruct_mc(x, y, side, prediction, &residual);
@@ -9415,6 +10552,11 @@ fn num_proj_ref(
9415 /// decoder's own overlap sizes ever produce (luma 8/16/32, chroma 4/8/16)10552 /// decoder's own overlap sizes ever produce (luma 8/16/32, chroma 4/8/16)
9416 /// are transcribed.10553 /// are transcribed.
9417 fn obmc_mask(len: usize) -> &'static [u8] {10554 fn obmc_mask(len: usize) -> &'static [u8] {
10555+ // lane-inter8 r1: `obmc_mask_2` (`reconinter.c` 753) -- reached by the
10556+ // LEFT pass of an 8x8 block's chroma plane (overlap 4 luma columns, 2
10557+ // chroma), which only became live once 8x8 inter leaves stopped being
10558+ // refused.
10559+ const M2: [u8; 2] = [45, 64];
9418 const M4: [u8; 4] = [39, 50, 59, 64];10560 const M4: [u8; 4] = [39, 50, 59, 64];
9419 const M8: [u8; 8] = [36, 42, 48, 53, 57, 61, 64, 64];10561 const M8: [u8; 8] = [36, 42, 48, 53, 57, 61, 64, 64];
9420 const M16: [u8; 16] = [10562 const M16: [u8; 16] = [
@@ -9425,6 +10567,7 @@ fn obmc_mask(len: usize) -> &'static [u8] {
9425 61, 62, 64, 64, 64, 64, 64, 64, 64, 64,10567 61, 62, 64, 64, 64, 64, 64, 64, 64, 64,
9426 ];10568 ];
9427 match len {10569 match len {
10570+ 2 => &M2,
9428 4 => &M4,10571 4 => &M4,
9429 8 => &M8,10572 8 => &M8,
9430 16 => &M16,10573 16 => &M16,
@@ -9658,6 +10801,7 @@ fn obmc_blend(
9658 };10801 };
9659 let overlap_above = write_h / 2;10802 let overlap_above = write_h / 2;
9660 let overlap_left = write_w / 2;10803 let overlap_left = write_w / 2;
10804+ let skip_chroma_above = matches!((write_w, write_h), (8, 8) | (16, 8) | (8, 16));
9661 10805
9662 for (off4, span4, nb) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4))10806 for (off4, span4, nb) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4))
9663 {10807 {
@@ -9667,23 +10811,31 @@ fn obmc_blend(
9667 // divide back down to that column.10811 // divide back down to that column.
9668 let (h_kind, v_kind) = neighbour_filter(10812 let (h_kind, v_kind) = neighbour_filter(
9669 interp_fixed,10813 interp_fixed,
9670- neighbours.above_filter[(mi_col + off4) / SUB_MI as usize],10814+ neighbours.above_filter[mi_col + off4],
9671 );10815 );
9672 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;10816 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
9673 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);10817 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
9674 let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind);10818 let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind);
9675 obmc_blend_v(pred_y, side, ox, 0, bw, bh, &tmp_y);10819 obmc_blend_v(pred_y, side, ox, 0, bw, bh, &tmp_y);
10820+ // lane-inter8 r1: `av1_skip_u4x4_pred_in_obmc` (`reconinter.c` 820,
10821+ // `DISABLE_CHROMA_U8X8_OBMC == 0` -- "one-sided obmc"): when the
10822+ // chroma plane's own block size is BLOCK_4X4/8X4/4X8 (a 8x8, 16x8 or
10823+ // 8x16 luma block at 4:2:0), the ABOVE pass skips chroma entirely
10824+ // while the LEFT pass still blends it. Blending chroma here as well
10825+ // would both mis-predict every 8x8 leaf and ask for an overlap of 2.
10826+ if !skip_chroma_above {
9676 let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);10827 let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);
9677 let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind);10828 let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind);
9678 obmc_blend_v(pred_u, chroma_side, cox, 0, cbw, cbh, &tmp_u);10829 obmc_blend_v(pred_u, chroma_side, cox, 0, cbw, cbh, &tmp_u);
9679 let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind);10830 let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind);
9680 obmc_blend_v(pred_v, chroma_side, cox, 0, cbw, cbh, &tmp_v);10831 obmc_blend_v(pred_v, chroma_side, cox, 0, cbw, cbh, &tmp_v);
9681 }10832 }
10833+ }
9682 10834
9683 for (off4, span4, nb) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) {10835 for (off4, span4, nb) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) {
9684 let (h_kind, v_kind) = neighbour_filter(10836 let (h_kind, v_kind) = neighbour_filter(
9685 interp_fixed,10837 interp_fixed,
9686- neighbours.left_filter[(mi_row + off4) / SUB_MI as usize],10838+ neighbours.left_filter[mi_row + off4],
9687 );10839 );
9688 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;10840 let (ny, nu, nv) = ref_planes(nb.ref_frame, ref_y, ref_u, ref_v, other_refs)?;
9689 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);10841 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
@@ -9724,10 +10876,17 @@ fn is_uni_comp_ref(ref0: i8, ref1: i8) -> bool {
9724 /// `get_comp_group_idx_context` (libaom `pred_common.h`): sums the10876 /// `get_comp_group_idx_context` (libaom `pred_common.h`): sums the
9725 /// above/left neighbour contributions [`Neighbours::record_inter`]/10877 /// above/left neighbour contributions [`Neighbours::record_inter`]/
9726 /// [`Neighbours::record_compound_ctx`] already precomputed, clamped to 5.10878 /// [`Neighbours::record_compound_ctx`] already precomputed, clamped to 5.
9727-fn get_comp_group_idx_context(neighbours: &Neighbours, at: (usize, usize), side: usize) -> usize {10879+/// lane-inter8 r2: `at_mi` is the block's own top-left in 4x4 mi units --
10880+/// an 8x8 leaf used to pass its enclosing 16x16's corner here, so all four
10881+/// leaves read the same neighbour cell (class context-read-from-one-cell).
10882+fn get_comp_group_idx_context(
10883+ neighbours: &Neighbours,
10884+ at_mi: (usize, usize),
10885+ side: usize,
10886+) -> usize {
9728 let _ = side;10887 let _ = side;
9729- let (r, c) = at;10888+ let (rmi, cmi) = at_mi;
9730- (neighbours.above_comp_group_idx[c] as usize + neighbours.left_comp_group_idx[r] as usize)10889+ (neighbours.above_comp_group_idx[cmi] as usize + neighbours.left_comp_group_idx[rmi] as usize)
9731 .min(5)10890 .min(5)
9732 }10891 }
9733 10892
@@ -9739,7 +10898,7 @@ fn get_comp_group_idx_context(neighbours: &Neighbours, at: (usize, usize), side:
9739 #[allow(clippy::too_many_arguments)]10898 #[allow(clippy::too_many_arguments)]
9740 fn get_comp_index_context(10899 fn get_comp_index_context(
9741 neighbours: &Neighbours,10900 neighbours: &Neighbours,
9742- at: (usize, usize),10901+ at_mi: (usize, usize),
9743 side: usize,10902 side: usize,
9744 order_hint_bits: u32,10903 order_hint_bits: u32,
9745 cur_order_hint: u32,10904 cur_order_hint: u32,
@@ -9747,7 +10906,7 @@ fn get_comp_index_context(
9747 ref1_order_hint: u32,10906 ref1_order_hint: u32,
9748 ) -> usize {10907 ) -> usize {
9749 let _ = side;10908 let _ = side;
9750- let (r, c) = at;10909+ let (rmi, cmi) = at_mi;
9751 let fwd =10910 let fwd =
9752 crate::motion_field::get_relative_dist(order_hint_bits, ref1_order_hint, cur_order_hint)10911 crate::motion_field::get_relative_dist(order_hint_bits, ref1_order_hint, cur_order_hint)
9753 .abs();10912 .abs();
@@ -9755,8 +10914,8 @@ fn get_comp_index_context(
9755 crate::motion_field::get_relative_dist(order_hint_bits, cur_order_hint, ref0_order_hint)10914 crate::motion_field::get_relative_dist(order_hint_bits, cur_order_hint, ref0_order_hint)
9756 .abs();10915 .abs();
9757 let offset = usize::from(fwd == bck);10916 let offset = usize::from(fwd == bck);
9758- neighbours.above_compound_idx[c] as usize10917+ neighbours.above_compound_idx[cmi] as usize
9759- + neighbours.left_compound_idx[r] as usize10918+ + neighbours.left_compound_idx[rmi] as usize
9760 + 3 * offset10919 + 3 * offset
9761 }10920 }
9762 10921
@@ -10130,6 +11289,11 @@ fn decode_inter_block(
10130 frame_width: usize,11289 frame_width: usize,
10131 ) -> Result<()> {11290 ) -> Result<()> {
10132 let (r, c) = at;11291 let (r, c) = at;
11292+ // lane-inter8 r2: the inter side bands are mi-granular; this block's own
11293+ // above/left neighbour is the mi cell at its top-left corner (libaom
11294+ // `above_mbmi` = mi(mi_row - 1, mi_col)), so a SUB-aligned block reads
11295+ // exactly what it read before.
11296+ let (rmi, cmi) = (r * (SUB / MI), c * (SUB / MI));
10133 let (px, py) = (c * SUB, r * SUB);11297 let (px, py) = (c * SUB, r * SUB);
10134 let (cpx, cpy) = (px / 2, py / 2);11298 let (cpx, cpy) = (px / 2, py / 2);
10135 let chroma_side = side / 2;11299 let chroma_side = side / 2;
@@ -10142,7 +11306,7 @@ fn decode_inter_block(
10142 );11306 );
10143 }11307 }
10144 let skip_mode_ctx =11308 let skip_mode_ctx =
10145- usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]);11309+ usize::from(neighbours.above_skip_mode[cmi]) + usize::from(neighbours.left_skip_mode[rmi]);
10146 // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read11310 // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read
10147 // MSAC tell so it can be diffed against an equivalent hook in libaom's11311 // MSAC tell so it can be diffed against an equivalent hook in libaom's
10148 // own `read_skip_mode`/`av1_get_skip_mode_context`.11312 // own `read_skip_mode`/`av1_get_skip_mode_context`.
@@ -10168,7 +11332,7 @@ fn decode_inter_block(
10168 SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));11332 SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
10169 }11333 }
10170 11334
10171- let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]);11335+ let skip_ctx = usize::from(neighbours.above_skip[cmi]) + usize::from(neighbours.left_skip[rmi]);
10172 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;11336 let skip = skip_mode || dec.symbol(&mut cdfs.skip[skip_ctx]) == 1;
10173 inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, skip, false);11337 inter_segment_id(dec, cdfs, seg_mi_r, seg_mi_c, seg_w_mi, seg_h_mi, skip, false);
10174 maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip);11338 maybe_read_cdef_idx(dec, r * SUB_MI as usize, c * SUB_MI as usize, skip);
@@ -10187,9 +11351,17 @@ fn decode_inter_block(
10187 r > neighbours.tile_row0_mi / (SUB / MI),11351 r > neighbours.tile_row0_mi / (SUB / MI),
10188 c > neighbours.tile_col0_mi / (SUB / MI),11352 c > neighbours.tile_col0_mi / (SUB / MI),
10189 );11353 );
10190- let (above_inter, left_inter) = (neighbours.above_inter[c], neighbours.left_inter[r]);11354+ let (above_inter, left_inter) = (neighbours.above_inter[cmi], neighbours.left_inter[rmi]);
10191 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);11355 let ii_ctx = intra_inter_ctx(has_above, has_left, above_inter, left_inter);
10192 let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;11356 let is_inter = skip_mode || dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
11357+ if std::env::var_os("EC_TRACE_MODE").is_some() {
11358+ eprintln!(
11359+ "EC_MODE mi_row={} mi_col={} rng={}",
11360+ r * SUB_MI as usize,
11361+ c * SUB_MI as usize,
11362+ dec.debug_state().0
11363+ );
11364+ }
10193 if std::env::var_os("EC_AV1_TELL").is_some() {11365 if std::env::var_os("EC_AV1_TELL").is_some() {
10194 eprintln!(11366 eprintln!(
10195 "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}",11367 "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}",
@@ -10208,28 +11380,34 @@ fn decode_inter_block(
10208 // common `record_inter` call below (which would otherwise stamp the11380 // common `record_inter` call below (which would otherwise stamp the
10209 // single-ref ALTREF-special-case default over it).11381 // single-ref ALTREF-special-case default over it).
10210 let mut compound_ctx: Option<(i8, u8, u8)> = None;11382 let mut compound_ctx: Option<(i8, u8, u8)> = None;
11383+ // lane-txselect: `read_block_tx_size`'s leaf transform units (spec
11384+ // 5.11.17), `Some` only when this block's var-tx tree resolved to more
11385+ // than one luma transform -- read back by the residual loop, the
11386+ // coefficient-context write-back and the loop-filter grid fill below.
11387+ let mut vartx_leaves: Option<Vec<(usize, usize, usize)>> = None;
11388+ let at_mi = (r * (SUB / MI), c * (SUB / MI));
10211 if is_inter {11389 if is_inter {
10212 let above_nbr = has_above.then(|| NeighbourRef {11390 let above_nbr = has_above.then(|| NeighbourRef {
10213 is_inter: above_inter,11391 is_inter: above_inter,
10214 ref0: if above_inter {11392 ref0: if above_inter {
10215- neighbours.above_ref[c]11393+ neighbours.above_ref[cmi]
10216 } else {11394 } else {
10217 011395 0
10218 },11396 },
10219- ref1: neighbours.above_ref1[c],11397+ ref1: neighbours.above_ref1[cmi],
10220- uni: neighbours.above_ref1[c]11398+ uni: neighbours.above_ref1[cmi]
10221- .is_some_and(|r1| is_uni_comp_ref(neighbours.above_ref[c], r1)),11399+ .is_some_and(|r1| is_uni_comp_ref(neighbours.above_ref[cmi], r1)),
10222 });11400 });
10223 let left_nbr = has_left.then(|| NeighbourRef {11401 let left_nbr = has_left.then(|| NeighbourRef {
10224 is_inter: left_inter,11402 is_inter: left_inter,
10225 ref0: if left_inter {11403 ref0: if left_inter {
10226- neighbours.left_ref[r]11404+ neighbours.left_ref[rmi]
10227 } else {11405 } else {
10228 011406 0
10229 },11407 },
10230- ref1: neighbours.left_ref1[r],11408+ ref1: neighbours.left_ref1[rmi],
10231- uni: neighbours.left_ref1[r]11409+ uni: neighbours.left_ref1[rmi]
10232- .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[r], r1)),11410+ .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[rmi], r1)),
10233 });11411 });
10234 if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {11412 if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
10235 eprintln!(11413 eprintln!(
@@ -10248,8 +11426,8 @@ fn decode_inter_block(
10248 cdfs,11426 cdfs,
10249 above_nbr,11427 above_nbr,
10250 left_nbr,11428 left_nbr,
10251- neighbours.above_ref[c],11429+ neighbours.above_ref[cmi],
10252- neighbours.left_ref[r],11430+ neighbours.left_ref[rmi],
10253 )11431 )
10254 };11432 };
10255 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);11433 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);
@@ -10318,6 +11496,45 @@ fn decode_inter_block(
10318 && global_motion[(ref1 - LAST_FRAME) as usize].model != ec_av1_syntax::WarpModel::Translation;11496 && global_motion[(ref1 - LAST_FRAME) as usize].model != ec_av1_syntax::WarpModel::Translation;
10319 let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?;11497 let (py0, pu0, pv0) = ref_planes(ref0, ref_y, ref_u, ref_v, other_refs)?;
10320 let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?;11498 let (py1, pu1, pv1) = ref_planes(ref1, ref_y, ref_u, ref_v, other_refs)?;
11499+ // lane-cwarp r1: `is_global_mv_block` (blockd.h:421-429) is
11500+ // PER REFERENCE SLOT -- mode GLOBAL_GLOBALMV, block >= 8x8, and
11501+ // THAT slot's own gm model > TRANSLATION. `bw4`/`bh4` come from
11502+ // the write extent below, so recompute the size bound from
11503+ // `side` here (the block's own size, what libaom's `bsize`
11504+ // is).
11505+ let is_global_mv0 = is_globalmv
11506+ && side >= 8
11507+ && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1;
11508+ let is_global_mv1 = is_globalmv
11509+ && side >= 8
11510+ && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1;
11511+ // libaom `av1_init_warp_params` + `allow_warp`'s
11512+ // `global_warp_allowed` branch, run once per reference for a
11513+ // compound block exactly as for a single-ref one (reconinter.c
11514+ // `build_inter_predictors_8x8_and_bigger` loops over `ref` and
11515+ // calls `av1_init_warp_params` inside the loop) -- WARPED_CAUSAL
11516+ // never reaches here (spec 5.11.27 / libaom `read_motion_mode`:
11517+ // `has_second_ref` returns SIMPLE_TRANSLATION), so the local-warp
11518+ // arm of `allow_warp` is dead on this path and only the global
11519+ // one applies. `force_integer_mv` short-circuits
11520+ // `av1_init_warp_params` before `allow_warp`.
11521+ let compound_warp = |ref_frame: i8, eligible: bool| {
11522+ if eligible
11523+ && !force_integer_mv
11524+ && !global_motion[(ref_frame - LAST_FRAME) as usize].invalid
11525+ {
11526+ crate::warp::global_warp_params(
11527+ global_motion[(ref_frame - LAST_FRAME) as usize].params,
11528+ )
11529+ } else {
11530+ None
11531+ }
11532+ };
11533+ let warp0 = compound_warp(ref0, is_global_mv0);
11534+ let warp1 = compound_warp(ref1, is_global_mv1);
11535+ if warp0.is_some() || warp1.is_some() {
11536+ COMPOUND_WARP_HITS.with(|c| c.set(c.get() + 1));
11537+ }
10321 // spec `get_ref_filter_type`: matches when EITHER of the11538 // spec `get_ref_filter_type`: matches when EITHER of the
10322 // neighbour's two references equals this block's own ref0 --11539 // neighbour's two references equals this block's own ref0 --
10323 // `above_ref1`/`left_ref1` is the neighbour's real second11540 // `above_ref1`/`left_ref1` is the neighbour's real second
@@ -10326,17 +11543,17 @@ fn decode_inter_block(
10326 // real filter match down to the "no neighbour" sentinel11543 // real filter match down to the "no neighbour" sentinel
10327 // whenever the shared reference sits in the neighbour's SECOND11544 // whenever the shared reference sits in the neighbour's SECOND
10328 // slot (lane-av1idx r2).11545 // slot (lane-av1idx r2).
10329- let above_filter_ctx = if neighbours.above_ref[c] == ref011546+ let above_filter_ctx = if neighbours.above_ref[cmi] == ref0
10330- || neighbours.above_ref1[c] == Some(ref0)11547+ || neighbours.above_ref1[cmi] == Some(ref0)
10331 {11548 {
10332- neighbours.above_filter[c]11549+ neighbours.above_filter[cmi]
10333 } else {11550 } else {
10334 [3, 3]11551 [3, 3]
10335 };11552 };
10336- let left_filter_ctx = if neighbours.left_ref[r] == ref011553+ let left_filter_ctx = if neighbours.left_ref[rmi] == ref0
10337- || neighbours.left_ref1[r] == Some(ref0)11554+ || neighbours.left_ref1[rmi] == Some(ref0)
10338 {11555 {
10339- neighbours.left_filter[r]11556+ neighbours.left_filter[rmi]
10340 } else {11557 } else {
10341 [3, 3]11558 [3, 3]
10342 };11559 };
@@ -10368,12 +11585,8 @@ fn decode_inter_block(
10368 // own gm model > TRANSLATION (IDENTITY excluded11585 // own gm model > TRANSLATION (IDENTITY excluded
10369 // too -- the two-predicate trap, distinct from11586 // too -- the two-predicate trap, distinct from
10370 // `gm_nontrans` above which allows IDENTITY).11587 // `gm_nontrans` above which allows IDENTITY).
10371- is_global_mv0: is_globalmv11588+ is_global_mv0,
10372- && bw4.min(bh4) >= 211589+ is_global_mv1,
10373- && global_motion[(ref0 - LAST_FRAME) as usize].model as u8 > 1,
10374- is_global_mv1: is_globalmv
10375- && bw4.min(bh4) >= 2
10376- && global_motion[(ref1 - LAST_FRAME) as usize].model as u8 > 1,
10377 },11590 },
10378 );11591 );
10379 }11592 }
@@ -10386,7 +11599,7 @@ fn decode_inter_block(
10386 // there), so the gate reduces to the sequence header bit; kept11599 // there), so the gate reduces to the sequence header bit; kept
10387 // as an explicit call so a future smaller block size is not11600 // as an explicit call so a future smaller block size is not
10388 // silently wrong (libaom `reconinter.h::is_any_masked_compound_used`).11601 // silently wrong (libaom `reconinter.h::is_any_masked_compound_used`).
10389- let group_ctx = get_comp_group_idx_context(neighbours, at, side);11602+ let group_ctx = get_comp_group_idx_context(neighbours, (rmi, cmi), side);
10390 let comp_group_idx = if !skip_mode11603 let comp_group_idx = if !skip_mode
10391 && enable_masked_compound11604 && enable_masked_compound
10392 && is_any_masked_compound_used_here(side)11605 && is_any_masked_compound_used_here(side)
@@ -10414,7 +11627,17 @@ fn decode_inter_block(
10414 8 => 3,11627 8 => 3,
10415 16 => 6,11628 16 => 6,
10416 32 => 9,11629 32 => 9,
10417- _ => unreachable!("decode_inter_block leaf side is 8/16/32"),11630+ // lane-inter8 r1: `av1_is_wedge_used` is false at 64x64
11631+ // (`av1_wedge_params_lookup[BLOCK_64X64].wedge_types ==
11632+ // 0`), so a real encoder writes NO `compound_type` symbol
11633+ // there -- COMPOUND_DIFFWTD is inferred. Reading one
11634+ // would desync, so refuse by name rather than guess the
11635+ // inferred-DIFFWTD blend this round.
11636+ _ => {
11637+ return Err(unsupported(
11638+ "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)",
11639+ ))
11640+ }
10418 };11641 };
10419 let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]);11642 let compound_type = dec.symbol(&mut cdfs.compound_type[wedge_bsize]);
10420 if compound_type == 0 {11643 if compound_type == 0 {
@@ -10640,7 +11863,7 @@ fn decode_inter_block(
10640 {11863 {
10641 let idx_ctx = get_comp_index_context(11864 let idx_ctx = get_comp_index_context(
10642 neighbours,11865 neighbours,
10643- at,11866+ (rmi, cmi),
10644 side,11867 side,
10645 order_hint_bits,11868 order_hint_bits,
10646 order_hint,11869 order_hint,
@@ -10716,6 +11939,16 @@ fn decode_inter_block(
10716 v_filter,11939 v_filter,
10717 &mut inter0_y,11940 &mut inter0_y,
10718 );11941 );
11942+ // lane-cwarp r1: this reference's own GLOBAL warp replaces the
11943+ // translational tap (libaom `av1_warp_plane` with
11944+ // `conv_params->is_compound`); the blend below is unchanged.
11945+ if let Some(wp) = &warp0 {
11946+ crate::warp::warp_affine_compound(
11947+ wp, &py0.data, py0.true_width as i32, py0.true_height as i32,
11948+ py0.width as i32, &mut inter0_y, px as i32, py as i32, side as i32,
11949+ side as i32, side as i32, 0, 0,
11950+ );
11951+ }
10719 let mut inter1_y = vec![0i32; side * side];11952 let mut inter1_y = vec![0i32; side * side];
10720 mc::predict_compound_intermediate(11953 mc::predict_compound_intermediate(
10721 &py1.data,11954 &py1.data,
@@ -10730,6 +11963,16 @@ fn decode_inter_block(
10730 v_filter,11963 v_filter,
10731 &mut inter1_y,11964 &mut inter1_y,
10732 );11965 );
11966+ // lane-cwarp r1: this reference's own GLOBAL warp replaces the
crates/ec-av1/src/encode.rsmodified+111 -2
@@ -1043,6 +1043,59 @@ const HAS_BOTTOM_LEFT: [&[u8]; 3] = [
1043 ],1043 ],
1044 ];1044 ];
1045 1045
1046+/// `has_tr_vert_*` (libaom `reconintra.c`, `has_tr_vert_tables`), indexed by
1047+/// [`Reach::table`] exactly like [`HAS_TOP_RIGHT`]: inside a
1048+/// `PARTITION_VERT_A`/`_B` the square sub-blocks are visited TL, BL, TR, BR
1049+/// rather than in raster order, so the bottom-left square's top-right
1050+/// neighbour is the partition's own right-hand rectangle -- not yet decoded.
1051+/// libaom switches tables on the partition type (`get_has_tr_table`); the
1052+/// ordinary table says 1 where this one says 0 (32x32 at row 1 col 0:
1053+/// `95` bit 4 = 1 vs `15` bit 4 = 0), which is exactly the case
1054+/// lane-part32 r5 caught reading undecoded samples.
1055+const HAS_TOP_RIGHT_VERT: [&[u8]; 3] = [
1056+ // has_tr_vert_16x16
1057+ &[255, 0, 119, 0, 127, 0, 119, 0],
1058+ // has_tr_vert_32x32
1059+ &[15, 7],
1060+ // has_tr_vert_8x8
1061+ &[
1062+ 255, 255, 0, 0, 119, 119, 0, 0, 127, 127, 0, 0, 119, 119, 0, 0, 255, 127, 0, 0, 119, 119,
1063+ 0, 0, 127, 127, 0, 0, 119, 119, 0, 0,
1064+ ],
1065+];
1066+
1067+/// [`HAS_TOP_RIGHT_VERT`]'s sibling, `has_bl_vert_tables`.
1068+const HAS_BOTTOM_LEFT_VERT: [&[u8]; 3] = [
1069+ // has_bl_vert_16x16
1070+ &[254, 16, 254, 0, 254, 16, 254, 0],
1071+ // has_bl_vert_32x32
1072+ &[14, 14],
1073+ // has_bl_vert_8x8
1074+ &[
1075+ 254, 255, 16, 17, 254, 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0, 254, 255, 16, 17, 254,
1076+ 255, 0, 1, 254, 255, 16, 17, 254, 255, 0, 0,
1077+ ],
1078+];
1079+
1080+thread_local! {
1081+ /// Set for the duration of a `PARTITION_VERT_A`/`_B`'s own sub-blocks
1082+ /// (see [`Reach::vert_ab_partition`]) -- libaom carries the partition
1083+ /// type down into `has_top_right`/`has_bottom_left` as an argument, and
1084+ /// threading one bool through this crate's already twenty-argument
1085+ /// `decode_block` would touch every call site instead of the two arms
1086+ /// that need it.
1087+ static VERT_AB_PARTITION: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
1088+}
1089+
1090+/// Restores [`VERT_AB_PARTITION`] to what it was when the guard was made.
1091+pub(crate) struct VertAbGuard(bool);
1092+
1093+impl Drop for VertAbGuard {
1094+ fn drop(&mut self) {
1095+ VERT_AB_PARTITION.with(|c| c.set(self.0));
1096+ }
1097+}
1098+
1046 /// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp1099 /// `has_tr_32x16`/`has_tr_16x32` (libaom `reconintra.c`) -- lane-intradisp
1047 /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x321100 /// r1: the two rect strips PARTITION_HORZ/VERT ever produce at the 32x32
1048 /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is1101 /// level, transcribed verbatim (not derived): `[0]` is 32-wide, `[1]` is
@@ -1113,6 +1166,15 @@ impl Reach {
1113 Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8))1166 Self::bit(table, (row * Self::table_stride(bw) + col) % (table.len() * 8))
1114 }1167 }
1115 1168
1169+ /// Marks every [`Reach::of`] made until the returned guard drops as being
1170+ /// inside a `PARTITION_VERT_A`/`_B` (libaom's `get_has_tr_table` /
1171+ /// `get_has_bl_table` partition argument). Rectangular sub-blocks are
1172+ /// unaffected: libaom's own comment says vertical rectangles keep their
1173+ /// non-vert table, which is what [`Reach::of_rect`] already reads.
1174+ pub(crate) fn vert_ab_partition() -> VertAbGuard {
1175+ VertAbGuard(VERT_AB_PARTITION.with(|c| c.replace(true)))
1176+ }
1177+
1116 /// Neither, which is all a mode that reads no further than its own edges1178 /// Neither, which is all a mode that reads no further than its own edges
1117 /// needs.1179 /// needs.
1118 pub(crate) fn none() -> Self {1180 pub(crate) fn none() -> Self {
@@ -1145,7 +1207,11 @@ impl Reach {
1145 // reference pixels), never a stream desync (Reach never gates a1207 // reference pixels), never a stream desync (Reach never gates a
1146 // symbol read). Ceiling: transcribe `has_tr_4x4`/`has_bl_4x4`1208 // symbol read). Ceiling: transcribe `has_tr_4x4`/`has_bl_4x4`
1147 // verbatim and give TX4 its own `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` row.1209 // verbatim and give TX4 its own `HAS_TOP_RIGHT`/`HAS_BOTTOM_LEFT` row.
1148- let table = HAS_TOP_RIGHT[Self::table(side)];1210+ let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) {
1211+ HAS_TOP_RIGHT_VERT[Self::table(side)]
1212+ } else {
1213+ HAS_TOP_RIGHT[Self::table(side)]
1214+ };
1149 Self::bit(1215 Self::bit(
1150 table,1216 table,
1151 (row * Self::table_stride(side) + col) % (table.len() * 8),1217 (row * Self::table_stride(side) + col) % (table.len() * 8),
@@ -1165,7 +1231,11 @@ impl Reach {
1165 return false;1231 return false;
1166 }1232 }
1167 // corner-cut: see `top_right`'s note -- same clamp, same ceiling.1233 // corner-cut: see `top_right`'s note -- same clamp, same ceiling.
1168- let table = HAS_BOTTOM_LEFT[Self::table(side)];1234+ let table = if VERT_AB_PARTITION.with(std::cell::Cell::get) {
1235+ HAS_BOTTOM_LEFT_VERT[Self::table(side)]
1236+ } else {
1237+ HAS_BOTTOM_LEFT[Self::table(side)]
1238+ };
1169 Self::bit(1239 Self::bit(
1170 table,1240 table,
1171 (row * Self::table_stride(side) + col) % (table.len() * 8),1241 (row * Self::table_stride(side) + col) % (table.len() * 8),
@@ -3494,6 +3564,45 @@ mod tests {
3494 }3564 }
3495 }3565 }
3496 3566
3567+ /// lane-part32 r6: inside a `PARTITION_VERT_A`/`_B` the 8x8 squares are
3568+ /// visited TL, BL, TR, BR, so the TR square (even 8x8 row, odd 8x8
3569+ /// column inside the superblock) may read the below-left samples the
3570+ /// raster table forbids: `has_bl_8x8` is 0 at exactly those 16 slots
3571+ /// where `has_bl_vert_8x8` is 1. Pinned here because no aomenc recipe
3572+ /// swept in r6 produced a decodable 16x16-level VERT_B stream (every
3573+ /// stream that partitions that small first hits the still-refused
3574+ /// HORZ_A/HORZ_B/VERT_A-below-16 or coded-rect-strip-below-16 arms).
3575+ #[test]
3576+ fn vert_ab_partition_flips_below_left_for_the_top_right_8x8() {
3577+ let (width, height) = (SUPERBLOCK * 3, SUPERBLOCK * 3);
3578+ // Interior superblock, so neither the frame edge nor the col == 0 /
3579+ // last-row early returns answer instead of the table.
3580+ let (sb_x, sb_y) = (SUPERBLOCK, SUPERBLOCK);
3581+ let mut flipped = 0;
3582+ for row in 0..8 {
3583+ for col in 1..8 {
3584+ let (x, y) = (sb_x + col * 8, sb_y + row * 8);
3585+ let raster = Reach::of(8, x, y, width, height).below_left;
3586+ let vert = {
3587+ let _guard = Reach::vert_ab_partition();
3588+ Reach::of(8, x, y, width, height).below_left
3589+ };
3590+ // The TR square of a VERT_A/_B sits at an even row, odd
3591+ // column; every other slot must be untouched by the guard.
3592+ if row % 2 == 0 && col % 2 == 1 {
3593+ assert!(!raster, "raster below_left at row={row} col={col}");
3594+ assert!(vert, "vert below_left at row={row} col={col}");
3595+ flipped += 1;
3596+ } else {
3597+ assert_eq!(raster, vert, "guard moved row={row} col={col}");
3598+ }
3599+ }
3600+ }
3601+ assert_eq!(flipped, 4 * 4, "expected the 16 8x8 TR slots to flip");
3602+ // The guard is scoped: it must not leak past its own block.
3603+ assert!(!Reach::of(8, sb_x + 8, sb_y, width, height).below_left);
3604+ }
3605+
3497 /// An odd width or height is refused by name, not by however the padder3606 /// An odd width or height is refused by name, not by however the padder
3498 /// or the block coder would happen to fail on it.3607 /// or the block coder would happen to fail on it.
3499 #[test]3608 #[test]
crates/ec-av1/src/gate_coverage.rsmodified+302 -19
@@ -39,39 +39,219 @@ const NEVER_EXERCISED: &[(&str, &str)] = &[
39 // lane could produce sits under TX_MODE_SELECT, whose inter var-tx39 // lane could produce sits under TX_MODE_SELECT, whose inter var-tx
40 // partition tree is unread -- so no stream reconstructs one end to end40 // partition tree is unread -- so no stream reconstructs one end to end
41 // yet and this entry stays.41 // yet and this entry stays.
42- ("enable-intrabc", "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree"),42+ (
43+ "enable-intrabc",
44+ "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree",
45+ ),
46+];
47+
48+/// The `--enable-*` tools this decoder cares about, whether or not any gate
49+/// names one. A flag no gate mentions is *defaulted*, i.e. unknown, and by the
50+/// rule above unknown is not coverage -- so the universe is fixed here rather
51+/// than derived from the gate source, which would silently shrink to whatever
52+/// the gates happen to spell.
53+#[cfg(test)]
54+const TOOL_UNIVERSE: &[&str] = &[
55+ "enable-1to4-partitions",
56+ "enable-ab-partitions",
57+ "enable-angle-delta",
58+ "enable-cdef",
59+ "enable-cfl-intra",
60+ "enable-dist-wtd-comp",
61+ "enable-dual-filter",
62+ "enable-filter-intra",
63+ "enable-flip-idtx",
64+ "enable-global-motion",
65+ "enable-interintra-comp",
66+ "enable-intra-edge-filter",
67+ "enable-intrabc",
68+ "enable-masked-comp",
69+ "enable-obmc",
70+ "enable-order-hint",
71+ "enable-paeth-intra",
72+ "enable-palette",
73+ "enable-rect-partitions",
74+ "enable-rect-tx",
75+ "enable-ref-frame-mvs",
76+ "enable-restoration",
77+ "enable-smooth-intra",
78+ "enable-superres",
79+ "enable-tx64",
80+ "enable-warped-motion",
81+];
82+
83+/// Coverage is per (tool x bit depth), not per tool.
84+///
85+/// lane-hbdinter found two 10-bit-only defects (SGR box sums unscaled, Wiener
86+/// clamp pinned at the 8-bit bound) that survived the "10-bit bit-exact"
87+/// milestone because every 10-bit gate passed `--enable-restoration=0`:
88+/// `enable-restoration` is positively exercised -- at 8 bits only. A tool the
89+/// 8-bit gates cover says nothing about the high-bit-depth path through the
90+/// same code, so the two lists below are pinned separately.
91+///
92+/// Each entry is `(flag, why)`. A gate that passes `--enable-<tool>=1` at that
93+/// depth retires the entry, and this test fails until it is deleted.
94+#[cfg(test)]
95+const NEVER_EXERCISED_8BIT: &[(&str, &str)] = &[
96+ (
97+ "enable-1to4-partitions",
98+ "off in 42 gates, on in none: PARTITION_HORZ_4/VERT_4 at 64x64 needs TX_64X16 luma plus 32x8 chroma scans (lane-part32 r5)",
99+ ),
100+ (
101+ "enable-angle-delta",
102+ "off in 36 gates, on in none: the directional-intra gates pin it off to isolate the base modes",
103+ ),
104+ (
105+ "enable-cfl-intra",
106+ "off in 41 gates, on in none: chroma-from-luma prediction is unimplemented",
107+ ),
108+ (
109+ "enable-dist-wtd-comp",
110+ "off in 11 gates, on in none: distance-weighted compound is unimplemented",
111+ ),
112+ (
113+ "enable-dual-filter",
114+ "never spelled by any gate, so defaulted = unknown; no stream is proven to carry per-direction interp filters",
115+ ),
116+ (
117+ "enable-flip-idtx",
118+ "never spelled; the flip/identity transform types are unproven by a real stream",
119+ ),
120+ (
121+ "enable-global-motion",
122+ "off in 5 gates, on in none at 8 bits; lane-gm owns the global-warp prediction that is still missing",
123+ ),
124+ (
125+ "enable-intrabc",
126+ "the block vector is decoded and predicted from, but every real stream's intrabc block needs the unread inter var-tx transform tree",
127+ ),
128+ (
129+ "enable-rect-tx",
130+ "never spelled; rect transforms reach the decoder only through partition shape, never through a gate that names the tool",
131+ ),
132+ (
133+ "enable-ref-frame-mvs",
134+ "off in 27 gates, on in none: temporal MV projection is unimplemented",
135+ ),
136+ (
137+ "enable-superres",
138+ "never spelled: the three superres gates drive `--superres-mode=1` instead, so the tool IS exercised but not under this flag -- retire this entry only by renaming the check, not by assuming coverage",
139+ ),
140+ (
141+ "enable-tx64",
142+ "never spelled; TX_64X64 appears only where aomenc's default picks it, which is unknown per stream",
143+ ),
144+];
145+
146+#[cfg(test)]
147+const NEVER_EXERCISED_10BIT: &[(&str, &str)] = &[
148+ // Only 4 of the 45 real-aomenc gates encode at 10 bits, and they pin the
149+ // pixel filters and the intra tool set off. Every entry the 8-bit list
150+ // carries is a hole here too. lane-hbdgates r1 closed six of the seven
151+ // 8-bit-only entries with real 10-bit gates (filter-intra, smooth-intra,
152+ // paeth-intra, intra-edge-filter, rect-partitions, ab-partitions); its
153+ // seventh, the 10-bit LR gate, was `#[ignore]`d on that branch and passes
154+ // un-ignored on main, which carries the fix.
155+ // `enable-restoration` LEFT this list on 2026-09-01: lane-hbdinter's
156+ // 10-bit inter gate passes `--enable-restoration=1` and asserts a real
157+ // Wiener/SGR unit fired, which is what caught the two defects (SGR box
158+ // sums never brought back to the 8-bit scale, Wiener clamp at the wrong
159+ // bound). `enable-dist-wtd-comp` and `enable-global-motion` left it the
160+ // same day for the same reason: lane-cwarp's 10-bit compound global-warp
161+ // gate passes `=1` for both.
162+ (
163+ "enable-1to4-partitions",
164+ "hole at both depths, see the 8-bit list",
165+ ),
166+ (
167+ "enable-angle-delta",
168+ "hole at both depths, see the 8-bit list",
169+ ),
170+ (
171+ "enable-cfl-intra",
172+ "hole at both depths, see the 8-bit list",
173+ ),
174+ (
175+ "enable-dual-filter",
176+ "hole at both depths, see the 8-bit list",
177+ ),
178+ (
179+ "enable-flip-idtx",
180+ "hole at both depths, see the 8-bit list",
181+ ),
182+ ("enable-intrabc", "hole at both depths, see the 8-bit list"),
183+ ("enable-rect-tx", "hole at both depths, see the 8-bit list"),
184+ (
185+ "enable-ref-frame-mvs",
186+ "hole at both depths, see the 8-bit list",
187+ ),
188+ (
189+ "enable-superres",
190+ "the 10-bit superres gate drives `--superres-mode=1`, not this flag; see the 8-bit entry",
191+ ),
192+ ("enable-tx64", "hole at both depths, see the 8-bit list"),
43 ];193 ];
44 194
45 #[cfg(test)]195 #[cfg(test)]
46 mod tests {196 mod tests {
47- use super::NEVER_EXERCISED;197+ use super::{NEVER_EXERCISED, NEVER_EXERCISED_8BIT, NEVER_EXERCISED_10BIT, TOOL_UNIVERSE};
48 use std::collections::{BTreeMap, BTreeSet};198 use std::collections::{BTreeMap, BTreeSet};
49 199
50- /// `--enable-*` settings per real-aomenc gate, derived from the gate200+ /// Bodies of the real-aomenc gates: a `fn` body carrying the shared
51- /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`.201+ /// `--passes=1` every one of them passes. Split on the attribute that
52- fn tool_settings() -> (usize, BTreeMap<String, (usize, usize, usize)>) {202+ /// opens a test.
203+ fn gate_bodies() -> Vec<&'static str> {
53 let src = include_str!("stream.rs");204 let src = include_str!("stream.rs");
54- // A real-aomenc gate is a `fn` body carrying the shared `--passes=1`
55- // every one of them passes. Split on the attribute that opens a test.
56 let gates: Vec<&str> = src205 let gates: Vec<&str> = src
57 .split("\n #[")206 .split("\n #[")
58- .filter(|body| body.contains("\"--passes=1\""))207+ // lane-hbdgates r1: an `#[ignore]`d gate exercises nothing, so it
208+ // must not close a hole. Its body is the segment that opens with
209+ // the ignore attribute.
210+ .filter(|body| !body.starts_with("ignore"))
211+ // lane-hbdgates r1: gates that build their stream through the
212+ // shared 10-bit helpers spell `--passes=1` there, not inline.
213+ .filter(|body| {
214+ body.contains("\"--passes=1\"")
215+ || body.contains("ten_bit_tool_gate(")
216+ || body.contains("encode_10bit_gradients")
217+ })
59 .collect();218 .collect();
60- assert!(gates.len() >= 20, "expected the real-aomenc gates, found {}", gates.len());219+ assert!(
220+ gates.len() >= 20,
221+ "expected the real-aomenc gates, found {}",
222+ gates.len()
223+ );
224+ gates
225+ }
61 226
62- let mut per_tool: BTreeMap<String, (usize, usize, usize)> = BTreeMap::new();227+ /// `--enable-<flag>=<value>` settings spelled inside one gate body.
63- let mut names: BTreeSet<String> = BTreeSet::new();228+ fn flags_in(gate: &str) -> BTreeMap<String, char> {
64- let mut seen: Vec<BTreeMap<String, char>> = Vec::new();
65- for gate in &gates {
66 let mut here = BTreeMap::new();229 let mut here = BTreeMap::new();
67 for (i, _) in gate.match_indices("\"--enable-") {230 for (i, _) in gate.match_indices("\"--enable-") {
68 let rest = &gate[i + 3..];231 let rest = &gate[i + 3..];
69 let Some(end) = rest.find('"') else { continue };232 let Some(end) = rest.find('"') else { continue };
70- let Some((flag, value)) = rest[..end].split_once('=') else { continue };233+ let Some((flag, value)) = rest[..end].split_once('=') else {
71- let Some(value) = value.chars().next() else { continue };234+ continue;
72- names.insert(flag.to_owned());235+ };
236+ let Some(value) = value.chars().next() else {
237+ continue;
238+ };
73 here.insert(flag.to_owned(), value);239 here.insert(flag.to_owned(), value);
74 }240 }
241+ here
242+ }
243+
244+ /// `--enable-*` settings per real-aomenc gate, derived from the gate
245+ /// source: `flag -> (turned off in N gates, turned on in N, defaulted in N)`.
246+ fn tool_settings() -> (usize, BTreeMap<String, (usize, usize, usize)>) {
247+ let gates = gate_bodies();
248+
249+ let mut per_tool: BTreeMap<String, (usize, usize, usize)> = BTreeMap::new();
250+ let mut names: BTreeSet<String> = BTreeSet::new();
251+ let mut seen: Vec<BTreeMap<String, char>> = Vec::new();
252+ for gate in &gates {
253+ let here = flags_in(gate);
254+ names.extend(here.keys().cloned());
75 seen.push(here);255 seen.push(here);
76 }256 }
77 for name in names {257 for name in names {
@@ -126,10 +306,113 @@ mod tests {
126 #[test]306 #[test]
127 fn tool_settings_reads_whole_flags() {307 fn tool_settings_reads_whole_flags() {
128 let (gate_count, per_tool) = tool_settings();308 let (gate_count, per_tool) = tool_settings();
129- assert!(per_tool.contains_key("enable-cdef"), "expected --enable-cdef among the gate flags");309+ assert!(
310+ per_tool.contains_key("enable-cdef"),
311+ "expected --enable-cdef among the gate flags"
312+ );
130 for (name, &(off, on, defaulted)) in &per_tool {313 for (name, &(off, on, defaulted)) in &per_tool {
131- assert!(!name.is_empty() && !name.contains(['"', '=']), "malformed flag {name:?}");314+ assert!(
132- assert_eq!(off + on + defaulted, gate_count, "{name} counts do not cover every gate");315+ !name.is_empty() && !name.contains(['"', '=']),
316+ "malformed flag {name:?}"
317+ );
318+ assert_eq!(
319+ off + on + defaulted,
320+ gate_count,
321+ "{name} counts do not cover every gate"
322+ );
323+ }
324+ }
325+
326+ /// A gate encodes at 10 bits when its recipe says so: the shared 10-bit
327+ /// helper, an explicit `--bit-depth=10`/`--input-bit-depth=10`, or a
328+ /// `yuv420p10le` fixture handed to aomenc. Everything else is aomenc's
329+ /// 8-bit default.
330+ fn is_ten_bit(body: &str) -> bool {
331+ body.contains("encode_10bit_gradients")
332+ || body.contains("ten_bit_tool_gate(")
333+ || body.contains("--bit-depth=10")
334+ || body.contains("--input-bit-depth=10")
335+ || body.contains("yuv420p10le")
336+ }
337+
338+ /// Flags a gate positively enables (`=1`), at gates of the given depth.
339+ fn enabled_at(ten_bit: bool) -> BTreeSet<String> {
340+ let mut on = BTreeSet::new();
341+ for gate in gate_bodies() {
342+ if is_ten_bit(gate) != ten_bit {
343+ continue;
344+ }
345+ for (flag, value) in flags_in(gate) {
346+ if value == '1' {
347+ on.insert(flag);
348+ }
349+ }
350+ }
351+ on
352+ }
353+
354+ /// The tools of [`TOOL_UNIVERSE`] that no gate of this depth enables.
355+ fn never_exercised_at(ten_bit: bool) -> BTreeSet<&'static str> {
356+ let on = enabled_at(ten_bit);
357+ TOOL_UNIVERSE
358+ .iter()
359+ .copied()
360+ .filter(|t| !on.contains(*t))
361+ .collect()
362+ }
363+
364+ fn check_depth(ten_bit: bool, listed: &[(&str, &str)]) {
365+ let derived = never_exercised_at(ten_bit);
366+ let listed: BTreeSet<&str> = listed.iter().map(|&(flag, _)| flag).collect();
367+ let depth = if ten_bit { "10-bit" } else { "8-bit" };
368+ let unlisted: Vec<&&str> = derived.difference(&listed).collect();
369+ assert!(
370+ unlisted.is_empty(),
371+ "no {depth} gate passes `=1` for {unlisted:?}, so no real {depth} stream exercises \
372+ them -- enable the tool in a {depth} gate that asserts it fired, or list it"
373+ );
374+ let stale: Vec<&&str> = listed.difference(&derived).collect();
375+ assert!(
376+ stale.is_empty(),
377+ "the {depth} list still names {stale:?}, but a {depth} gate now passes `=1` for them \
378+ -- delete those entries, the coverage hole is closed"
379+ );
380+ }
381+
382+ #[test]
383+ fn never_exercised_8bit_matches_the_gate_recipes() {
384+ check_depth(false, NEVER_EXERCISED_8BIT);
385+ }
386+
387+ #[test]
388+ fn never_exercised_10bit_matches_the_gate_recipes() {
389+ check_depth(true, NEVER_EXERCISED_10BIT);
390+ }
391+
392+ /// `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` prints both
393+ /// lists, so the per-depth holes can be read without opening this file.
394+ #[test]
395+ fn print_never_exercised_per_bit_depth() {
396+ let ten: Vec<&str> = gate_bodies()
397+ .into_iter()
398+ .filter(|b| is_ten_bit(b))
399+ .collect();
400+ let total = gate_bodies().len();
401+ println!(
402+ "gate_coverage: {} real-aomenc gates, {} of them 10-bit",
403+ total,
404+ ten.len()
405+ );
406+ for (label, ten_bit) in [("8BIT", false), ("10BIT", true)] {
407+ let holes = never_exercised_at(ten_bit);
408+ println!(
409+ "NEVER_EXERCISED_{label} ({} of {}):",
410+ holes.len(),
411+ TOOL_UNIVERSE.len()
412+ );
413+ for flag in &holes {
414+ println!(" --{flag}");
415+ }
133 }416 }
134 }417 }
135 }418 }
crates/ec-av1/src/intra.rsmodified+34 -0
@@ -235,6 +235,32 @@ impl Edges {
235 /// # Panics235 /// # Panics
236 /// Panics on a mode this module does not predict, or when `dst` is not236 /// Panics on a mode this module does not predict, or when `dst` is not
237 /// `bw * bh` long.237 /// `bw * bh` long.
238+// lane-hbdgates r1: per-tool firing counters for the 10-bit gates. Each tool
239+// the coverage table tracks needs its OWN counter -- `smooth_uv_hits` lumps
240+// SMOOTH..=PAETH together, so a paeth-only stream would have "proved" smooth
241+// intra ([[gate-blind-to-feature]]).
242+thread_local! {
243+ static SMOOTH_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
244+ static PAETH_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
245+ static EDGE_FILTER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
246+}
247+
248+/// How many blocks were predicted with SMOOTH/SMOOTH_V/SMOOTH_H on this thread.
249+pub(crate) fn smooth_pred_hits() -> usize {
250+ SMOOTH_PRED_HITS.with(|c| c.get())
251+}
252+
253+/// How many blocks were predicted with PAETH_PRED on this thread.
254+pub(crate) fn paeth_pred_hits() -> usize {
255+ PAETH_PRED_HITS.with(|c| c.get())
256+}
257+
258+/// How many directional edges [`filter_intra_edge`] actually smoothed
259+/// (strength != 0) on this thread -- the `--enable-intra-edge-filter` proof.
260+pub(crate) fn intra_edge_filter_hits() -> usize {
261+ EDGE_FILTER_HITS.with(|c| c.get())
262+}
263+
238 #[allow(clippy::too_many_arguments)]264 #[allow(clippy::too_many_arguments)]
239 pub fn predict(265 pub fn predict(
240 mode: u8,266 mode: u8,
@@ -249,6 +275,13 @@ pub fn predict(
249 dst: &mut [u16],275 dst: &mut [u16],
250 ) {276 ) {
251 assert_eq!(dst.len(), bw * bh, "the destination is the block");277 assert_eq!(dst.len(), bw * bh, "the destination is the block");
278+ match mode {
279+ SMOOTH_PRED | SMOOTH_V_PRED | SMOOTH_H_PRED => {
280+ SMOOTH_PRED_HITS.with(|c| c.set(c.get() + 1));
281+ }
282+ PAETH_PRED => PAETH_PRED_HITS.with(|c| c.set(c.get() + 1)),
283+ _ => {}
284+ }
252 let edges = Edges::build(above, left, corner, bw, bh);285 let edges = Edges::build(above, left, corner, bw, bh);
253 let is_directional = matches!(286 let is_directional = matches!(
254 mode,287 mode,
@@ -410,6 +443,7 @@ fn filter_intra_edge(buf: &mut [i32], strength: i32) {
410 if strength == 0 {443 if strength == 0 {
411 return;444 return;
412 }445 }
446+ EDGE_FILTER_HITS.with(|c| c.set(c.get() + 1));
413 const KERNEL: [[i32; 5]; 3] = [[0, 4, 8, 4, 0], [0, 5, 6, 5, 0], [2, 4, 4, 4, 2]];447 const KERNEL: [[i32; 5]; 3] = [[0, 4, 8, 4, 0], [0, 5, 6, 5, 0], [2, 4, 4, 4, 2]];
414 let filt = usize::try_from(strength - 1).expect("a filter strength is never negative");448 let filt = usize::try_from(strength - 1).expect("a filter strength is never negative");
415 let sz = buf.len() as i32;449 let sz = buf.len() as i32;
crates/ec-av1/src/mc.rsmodified+33 -2
@@ -333,6 +333,7 @@ pub fn predict_with_filters(
333 ) {333 ) {
334 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");334 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");
335 assert!(!reference.is_empty(), "a reference plane has samples");335 assert!(!reference.is_empty(), "a reference plane has samples");
336+ INTER_PRED_HITS.with(|c| c.set(c.get() + 1));
336 337
337 #[cfg(test)]338 #[cfg(test)]
338 let stage_t = std::time::Instant::now();339 let stage_t = std::time::Instant::now();
@@ -441,6 +442,20 @@ pub fn predict_scaled_hits() -> usize {
441 PREDICT_SCALED_HITS.with(|c| c.get())442 PREDICT_SCALED_HITS.with(|c| c.get())
442 }443 }
443 444
445+thread_local! {
446+ /// lane-hbdinter: how many inter predictions this thread has produced
447+ /// (single-reference, scaled, and the compound intermediate entry). The
448+ /// 10-bit inter gate hard-asserts this moved, so a stream that coded
449+ /// only intra blocks cannot pass it by construction (class
450+ /// `gate-blind-to-feature`).
451+ static INTER_PRED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
452+}
453+
454+/// Current value of [`INTER_PRED_HITS`].
455+pub fn inter_pred_hits() -> usize {
456+ INTER_PRED_HITS.with(|c| c.get())
457+}
458+
444 fn round_pow2_64(value: i64, shift: u32) -> i64 {459 fn round_pow2_64(value: i64, shift: u32) -> i64 {
445 if shift == 0 {460 if shift == 0 {
446 value461 value
@@ -492,6 +507,7 @@ pub fn predict_scaled(
492 ) {507 ) {
493 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");508 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");
494 assert!(!reference.is_empty(), "a reference plane has samples");509 assert!(!reference.is_empty(), "a reference plane has samples");
510+ INTER_PRED_HITS.with(|c| c.set(c.get() + 1));
495 PREDICT_SCALED_HITS.with(|c| c.set(c.get() + 1));511 PREDICT_SCALED_HITS.with(|c| c.set(c.get() + 1));
496 512
497 let y0 = y_q4.div_euclid(16);513 let y0 = y_q4.div_euclid(16);
@@ -594,6 +610,7 @@ pub fn predict_compound_intermediate(
594 ) {610 ) {
595 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");611 assert_eq!(dst.len(), block_w * block_h, "the destination is the block");
596 assert!(!reference.is_empty(), "a reference plane has samples");612 assert!(!reference.is_empty(), "a reference plane has samples");
613+ INTER_PRED_HITS.with(|c| c.set(c.get() + 1));
597 614
598 let x0 = x_q4.div_euclid(16);615 let x0 = x_q4.div_euclid(16);
599 let xfrac = x_q4.rem_euclid(16) as usize;616 let xfrac = x_q4.rem_euclid(16) as usize;
@@ -655,8 +672,16 @@ pub fn combine_compound(
655 assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");672 assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");
656 assert_eq!(dst.len(), pred0.len(), "the destination is the block");673 assert_eq!(dst.len(), pred0.len(), "the destination is the block");
657 for i in 0..dst.len() {674 for i in 0..dst.len() {
675+ // libaom (`av1_highbd_dist_wtd_convolve_2d_c`, and its lowbd twin)
676+ // applies the two shifts SEPARATELY: a truncating `>>
677+ // DIST_PRECISION_BITS` on the weighted sum, then `ROUND_POWER_OF_TWO`
678+ // by `round_bits == INTER_POST_ROUND`. Folding them into one
679+ // `Round2(sum, 8)` is NOT the same function -- it rounds up one LSB
680+ // whenever `(sum >> 4) + 8` is one below a multiple of 16 and the
681+ // dropped low 4 bits are non-zero.
658 let sum = pred0[i] * fwd_weight + pred1[i] * bck_weight;682 let sum = pred0[i] * fwd_weight + pred1[i] * bck_weight;
659- dst[i] = round2(sum, INTER_POST_ROUND + DIST_PRECISION_BITS).clamp(0, crate::decode::sample_max()) as u16;683+ dst[i] = round2(sum >> DIST_PRECISION_BITS, INTER_POST_ROUND)
684+ .clamp(0, crate::decode::sample_max()) as u16;
660 }685 }
661 }686 }
662 687
@@ -673,8 +698,14 @@ pub fn combine_compound(
673 pub fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8]) {698 pub fn diffwtd_mask(pred0: &[i32], pred1: &[i32], inv: bool, mask: &mut [u8]) {
674 assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");699 assert_eq!(pred0.len(), pred1.len(), "both refs predict the same block");
675 assert_eq!(mask.len(), pred0.len(), "one mask byte per pixel");700 assert_eq!(mask.len(), pred0.len(), "one mask byte per pixel");
701+ // libaom `diffwtd_mask_d16` (`reconinter.c:307`): `round = 2*FILTER_BITS
702+ // - round_0 - round_1 + (bd - 8)`, i.e. INTER_POST_ROUND plus the
703+ // bit-depth headroom the CONV_BUF domain carries at 10/12-bit. `round_0`
704+ // and `round_1` themselves only move at 12-bit (`convolve.h:83`'s
705+ // `intbufrange > 16`), so the whole bit-depth dependence here is `bd - 8`.
706+ let round = INTER_POST_ROUND + u32::from(crate::decode::bit_depth()).saturating_sub(8);
676 for i in 0..mask.len() {707 for i in 0..mask.len() {
677- let diff = round2((pred0[i] - pred1[i]).abs(), INTER_POST_ROUND);708+ let diff = round2((pred0[i] - pred1[i]).abs(), round);
678 let m = (38 + diff / 16).clamp(0, 64);709 let m = (38 + diff / 16).clamp(0, 64);
679 mask[i] = if inv { (64 - m) as u8 } else { m as u8 };710 mask[i] = if inv { (64 - m) as u8 } else { m as u8 };
680 }711 }
crates/ec-av1/src/refusal_inventory.rsmodified+7 -4
@@ -47,12 +47,13 @@ const REFUSALS: &[&str] = &[
47 "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)",47 "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)",
48 "a tx_type symbol outside its CDF's own set: {t}",48 "a tx_type symbol outside its CDF's own set: {t}",
49 "an INTER 32x32 partition type this decoder does not code (value={part32})",49 "an INTER 32x32 partition type this decoder does not code (value={part32})",
50- "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)",50+ "a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, four 64x16/16x64 strips)",
51 "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)",51 "a palette block on a HORZ/VERT intra strip below 16x16 (reconstruction not ported)",
52 "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)",52 "a palette block with a real transform on a superblock-level HORZ/VERT strip (corner-cropped luma coefficients not ported for palette)",
53 "a block that actually uses a palette (UV) -- reconstruction is out of scope",53 "a block that actually uses a palette (UV) -- reconstruction is out of scope",
54 "a block that actually uses a palette (Y) -- reconstruction is out of scope",54 "a block that actually uses a palette (Y) -- reconstruction is out of scope",
55 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",55 "an intrabc block under TxMode::Select (its transform size is coded by the inter var-tx partition tree, which this decoder never reads)",
56+ "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
56 "a frame OBU with no tile group",57 "a frame OBU with no tile group",
57 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",58 "a frame naming primary_ref_frame at a reference slot with no saved CDF state",
58 "a frame with no mode-info grid",59 "a frame with no mode-info grid",
@@ -63,11 +64,13 @@ const REFUSALS: &[&str] = &[
63 "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",
64 "a show_existing_frame header naming an empty reference slot",65 "a show_existing_frame header naming an empty reference slot",
65 "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",
66- "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)",
67 "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)",
68 "an inter frame with no key frame before it",70 "an inter frame with no key frame before it",
69- "an inter SB-level partition type other than SPLIT (this decoder's inter tile path only recurses a superblock 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)",
70- "an inter partition below 16x16 (8x8 and smaller inter blocks are not coded yet)",72+ "a masked compound 64x64 inter block (compound_type is inferred, not coded, at this size)",
73+ "an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)",
71 "an intra mode this decoder does not code (round 2)",74 "an intra mode this decoder does not code (round 2)",
72 "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",75 "an intra-coded HORZ/VERT strip needs rectangular intra prediction this decoder does not code yet",
73 "filter intra on a HORZ/VERT strip (this decoder predicts square-only)",76 "filter intra on a HORZ/VERT strip (this decoder predicts square-only)",
crates/ec-av1/src/restoration.rsmodified+26 -3
@@ -529,6 +529,9 @@ fn apply_wiener_stripe(
529 if w == 0 || h == 0 {529 if w == 0 || h == 0 {
530 return;530 return;
531 }531 }
532+ let bd = i64::from(crate::decode::bit_depth());
533+ let wiener_bias = 1i64 << (bd + 3);
534+ let wiener_limit = 1i64 << (bd + 5);
532 let rows = h + 6;535 let rows = h + 6;
533 let mut inter = vec![0i32; rows * w];536 let mut inter = vec![0i32; rows * w];
534 for r in 0..rows {537 for r in 0..rows {
@@ -541,8 +544,20 @@ fn apply_wiener_stripe(
541 sum += tap as i64544 sum += tap as i64
542 * lr_sample(cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, x) as i64;545 * lr_sample(cdef, deblocked, stride, plane_w, plane_h, v_start, v_end, row, x) as i64;
543 }546 }
544- // `WIENER_CLAMP_LIMIT(round0=3, bd=8) - 1`.547+ // libaom's `highbd_convolve_add_src_horiz_hip` clamps its
545- inter[r * w + c] = round2(sum, 3).clamp(0, 8191) as i32;548+ // *biased* intermediate to `[0, WIENER_CLAMP_LIMIT(3, bd) - 1]`
549+ // (`convolve.h:43`, `(1 << (bd + 1 + FILTER_BITS - round0))`).
550+ // Its bias over this crate's unbiased sum is exactly
551+ // `(1 << (bd + FILTER_BITS - 1)) >> round0 == 1 << (bd + 3)`
552+ // (the `rounding` term of that function, the rest cancelling
553+ // against `WienerInfo`'s derived centre tap as the doc comment
554+ // above derives), so the same clamp in *this* domain is the
555+ // bound shifted down by that bias. At 8-bit neither end is ever
556+ // reached by real content, which is why the old fixed `[0, 8191]`
557+ // survived every 8-bit gate; at 10-bit the upper end is
558+ // `128 * 1023 >> 3 == 16368`, well past `8191`, so a fixed
559+ // 8-bit limit silently truncated most 10-bit Wiener pixels.
560+ inter[r * w + c] = round2(sum, 3).clamp(-wiener_bias, wiener_limit - 1 - wiener_bias) as i32;
546 }561 }
547 }562 }
548 for r in 0..h {563 for r in 0..h {
@@ -646,7 +661,15 @@ fn compute_ab(
646 b += px;661 b += px;
647 }662 }
648 }663 }
649- let p = if a * n < b * b { 0 } else { a * n - b * b };664+ // libaom `restoration.c:660` -- the box sums are brought back
665+ // to the 8-bit scale before `p` is formed (`a` is a sum of
666+ // squares, so it loses twice the shift `b` does); `B[k]` below
667+ // keeps the RAW `b`, only `p` uses the scaled pair. At 8-bit
668+ // both shifts are 0, which is why this was invisible until now.
669+ let bd_shift = u32::from(crate::decode::bit_depth()).saturating_sub(8);
670+ let a_s = round2(a, 2 * bd_shift);
671+ let b_s = round2(b, bd_shift);
672+ let p = if a_s * n < b_s * b_s { 0 } else { a_s * n - b_s * b_s };
650 let z = round2(p * s as i64, SGRPROJ_MTABLE_BITS).clamp(0, 255) as usize;673 let z = round2(p * s as i64, SGRPROJ_MTABLE_BITS).clamp(0, 255) as usize;
651 let a_val = SGR_X_BY_XPLUS1[z];674 let a_val = SGR_X_BY_XPLUS1[z];
652 let b_val = round2(675 let b_val = round2(
crates/ec-av1/src/stream.rsmodified+2216 -220

Diff too large; view file

@@ -30,6 +30,30 @@ use crate::decode::{
30 };30 };
31 use crate::encode::Picture;31 use crate::encode::Picture;
32 32
33+/// lane-hidden r1: where `EC_AV1_FINAL_DUMP`'s per-frame dump goes for the
34+/// current thread, overriding the environment variable. Every ffmpeg/aomdec
35+/// pixel gate in this repo compares SHOWN frames only (class
36+/// gate-blind-to-hidden-frames), so the hidden alt-ref frames a real aomenc
37+/// stream carries were never compared at all; the gate that does compare
38+/// them needs a dump path that cannot race a sibling test's decode on
39+/// another thread, which a process-global env var cannot give.
40+thread_local! {
41+ static FINAL_DUMP_PREFIX: std::cell::RefCell<Option<String>> =
42+ const { std::cell::RefCell::new(None) };
43+}
44+
45+/// Sets (or with `None` clears) this thread's `EC_AV1_FINAL_DUMP` prefix.
46+#[allow(dead_code)]
47+pub(crate) fn set_final_dump_prefix(prefix: Option<String>) {
48+ FINAL_DUMP_PREFIX.with(|c| *c.borrow_mut() = prefix);
49+}
50+
51+fn final_dump_prefix() -> Option<String> {
52+ FINAL_DUMP_PREFIX
53+ .with(|c| c.borrow().clone())
54+ .or_else(|| std::env::var("EC_AV1_FINAL_DUMP").ok())
55+}
56+
33 /// Decode every frame in a raw AV1 OBU stream, in coding order.57 /// Decode every frame in a raw AV1 OBU stream, in coding order.
34 ///58 ///
35 /// A key frame becomes the reference for the inter frames that follow it,59 /// A key frame becomes the reference for the inter frames that follow it,
@@ -46,6 +70,7 @@ use crate::encode::Picture;
46 /// crate's tile decoders do not reconstruct (see their own docs), or when an70 /// crate's tile decoders do not reconstruct (see their own docs), or when an
47 /// inter frame appears before any key frame has supplied a reference.71 /// inter frame appears before any key frame has supplied a reference.
48 pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {72 pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
73+ let final_dump = final_dump_prefix();
49 let mut parser = Av1Parser::new();74 let mut parser = Av1Parser::new();
50 let mut pictures = Vec::new();75 let mut pictures = Vec::new();
51 let mut pictures_decoded: usize = 0;76 let mut pictures_decoded: usize = 0;
@@ -200,24 +225,13 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
200 // now read (`maybe_read_cdef_idx` in decode.rs) and threaded into225 // now read (`maybe_read_cdef_idx` in decode.rs) and threaded into
201 // [`crate::decode::apply_cdef`]'s per-superblock strength lookup, so226 // [`crate::decode::apply_cdef`]'s per-superblock strength lookup, so
202 // a `cdef_bits > 0` stream no longer needs this refusal.227 // a `cdef_bits > 0` stream no longer needs this refusal.
203- // An intra frame's `decode_key_frame_tile*` now reads `tx_depth`228+ // Both frame types now read their transform size under
204- // under `TxMode::Select` (lane-av1txsel, spec 5.11.16): the key-frame229+ // `TxMode::Select`: an intra frame's `decode_key_frame_tile*` reads
205- // decode path threads `tx_select` through `decode_block`/230+ // `tx_depth` (lane-av1txsel, spec 5.11.16), and an inter frame's
206- // `decode_leaf8`, and refuses on its own (a named `unsupported`, not231+ // `decode_inter_block`/`decode_inter_block8` read the recursive
207- // 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
208- // 4x4 luma transform, which has no coefficient tables here. This233+ // blanket inter-frame refusal that used to stand here is gone. What
209- // 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`.
210- // `decode_inter_frame`'s inter path never threads `tx_select`
211- // through its own block loop, so an inter frame under
212- // `TxMode::Select` still desyncs the same way the comment above used
213- // to describe for every frame -- lane-av1real r3's
214- // luma-near-flat-vs-ffmpeg-gradient bug.
215- if header.tx_mode == TxMode::Select && header.frame_type != FrameType::Key {
216- return Err(Error::unsupported(
217- "AV1 decode_stream",
218- "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)",
219- ));
220- }
221 // 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`,
222 // libaom decodemv.c): three more per-block/per-SB symbols this crate236 // libaom decodemv.c): three more per-block/per-SB symbols this crate
223 // never reads at all, each gated by a header field this decoder237 // never reads at all, each gated by a header field this decoder
@@ -461,6 +475,19 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
461 let bit_depth = parser475 let bit_depth = parser
462 .sequence_header()476 .sequence_header()
463 .map_or(8, |seq| seq.color_config.bit_depth);477 .map_or(8, |seq| seq.color_config.bit_depth);
478+ // lane-bd12: the sequence-header parser accepts `twelve_bit`, but every
479+ // rounding shift below is written for 8/10-bit only -- `warp.rs`'s
480+ // `REDUCE_BITS_HORIZ` is a hard 3 where libaom uses
481+ // `round_0 + max(bd + FILTER_BITS - round_0 - 14, 0)` (5 at bd 12), the
482+ // MC `round_0`/`round_1` change at 12-bit (libaom convolve.h:83), the
483+ // Wiener rounding bits change, and neither CDEF nor film grain has a
484+ // 12-bit path. Refuse by name rather than decode silently wrong pixels.
485+ if bit_depth == 12 {
486+ return Err(Error::unsupported(
487+ "AV1 decode_stream",
488+ "a bit depth of 12 (this decoder is gated at 8 and 10 only: warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)",
489+ ));
490+ }
464 crate::decode::set_bit_depth(bit_depth);491 crate::decode::set_bit_depth(bit_depth);
465 // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits.492 // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits.
466 let enable_masked_compound = parser493 let enable_masked_compound = parser
@@ -641,6 +668,7 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
641 header.skip_mode_present,668 header.skip_mode_present,
642 header.skip_mode_frame,669 header.skip_mode_frame,
643 header.reduced_tx_set,670 header.reduced_tx_set,
671+ header.tx_mode == TxMode::Select,
644 header.is_motion_mode_switchable,672 header.is_motion_mode_switchable,
645 header.allow_warped_motion,673 header.allow_warped_motion,
646 header.allow_screen_content_tools,674 header.allow_screen_content_tools,
@@ -722,6 +750,30 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
722 let _ = f.write_all(&narrow(&picture.v));750 let _ = f.write_all(&narrow(&picture.v));
723 }751 }
724 }752 }
753+ // lane-hidden r1: the frame exactly as it is about to be stored into
754+ // the reference slots -- after deblock/CDEF/LR/superres, in DECODE
755+ // order, hidden (`show_frame == 0`) alt-ref frames included, and
756+ // bit-depth correct (8-bit as u8, 10/12-bit as u16 LE) unlike the
757+ // u8-narrowing diagnostic dumps above. Matches the instrumented
758+ // aomdec's own `EC_AV1_FINAL_DUMP` rung byte for byte
759+ // (scripts/instrument-aom-oracle.sh rung 12), which is what makes a
760+ // hidden frame's pixels comparable at all.
761+ if let Some(prefix) = &final_dump {
762+ use std::io::Write;
763+ if let Ok(mut f) = std::fs::File::create(format!("{prefix}.f{pictures_decoded}")) {
764+ let mut buf = Vec::new();
765+ for plane in [&picture.y, &picture.u, &picture.v] {
766+ if bit_depth == 8 {
767+ buf.extend(plane.iter().map(|&s| s as u8));
768+ } else {
769+ for &s in plane {
770+ buf.extend_from_slice(&s.to_le_bytes());
771+ }
772+ }
773+ }
774+ let _ = f.write_all(&buf);
775+ }
776+ }
725 pictures_decoded += 1;777 pictures_decoded += 1;
726 let decoded_seg_map = decode::take_segment_ids();778 let decoded_seg_map = decode::take_segment_ids();
727 for i in 0..NUM_REF_FRAMES {779 for i in 0..NUM_REF_FRAMES {
@@ -799,6 +851,38 @@ mod tests {
799 picture851 picture
800 }852 }
801 853
854+ /// A stream whose sequence header says `twelve_bit` is refused by name
855+ /// rather than decoded with the 8/10-bit rounding shifts (`warp.rs`'s
856+ /// hard `REDUCE_BITS_HORIZ = 3`, MC/Wiener round bits, ungated CDEF and
857+ /// film grain). Reachability, not a pixel claim: the header is written at
858+ /// `seq_profile = 2` so `twelve_bit` is actually coded, and the frame's
859+ /// tile payload is never reached.
860+ #[test]
861+ fn a_twelve_bit_sequence_header_is_refused_by_name() {
862+ let picture = test_card(64, 64);
863+ let encoded = encode_key_frame(&picture, 100, 0.5).unwrap();
864+ let mut color = ec_av1_syntax::ColorConfig {
865+ bit_depth: 12,
866+ ..Default::default()
867+ };
868+ color.num_planes = 3;
869+ // Only seq_profile 2 codes the `twelve_bit` bit (spec 5.5.2).
870+ let (mut seq, header) =
871+ crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap();
872+ seq.seq_profile = 2;
873+ let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();
874+ stream.extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap());
875+
876+ let err = decode_stream(&stream).unwrap_err().to_string();
877+ assert!(
878+ err.contains(
879+ "a bit depth of 12 (this decoder is gated at 8 and 10 only: \
880+ warp/MC/wiener rounding shifts change at 12-bit and no 12-bit gate exists)"
881+ ),
882+ "expected the 12-bit refusal, got: {err}"
883+ );
884+ }
885+
802 /// `decode_stream` on a lone key frame's stream matches both the tile886 /// `decode_stream` on a lone key frame's stream matches both the tile
803 /// path (`decode_key_frame_tile` called directly on `Encoded::tile`) and887 /// path (`decode_key_frame_tile` called directly on `Encoded::tile`) and
804 /// the encoder's own reconstruction, at an even and an odd size.888 /// the encoder's own reconstruction, at an even and an odd size.
@@ -1591,6 +1675,237 @@ mod tests {
1591 present1675 present
1592 }1676 }
1593 1677
1678+ /// The instrumented `aomdec` beside the `aomenc` oracle
1679+ /// (`scripts/build-aom-oracle.sh` + `scripts/instrument-aom-oracle.sh`).
1680+ fn aomdec_path() -> std::path::PathBuf {
1681+ if let Some(p) = std::env::var_os("EC_AV1_AOMDEC") {
1682+ return std::path::PathBuf::from(p);
1683+ }
1684+ aomenc_path().with_file_name("aomdec")
1685+ }
1686+
1687+ /// Decodes `stream` with both this decoder and the instrumented oracle
1688+ /// `aomdec`, and compares EVERY decoded frame in DECODE order --
1689+ /// including the hidden (`show_frame == 0`) alt-ref frames no other gate
1690+ /// in this repo can see, because `decode_stream` only pushes shown
1691+ /// frames and `ffmpeg -f obu ... rawvideo` only emits shown frames
1692+ /// (class gate-blind-to-hidden-frames: a hidden frame's defect surfaces
1693+ /// only as drift on some later shown frame, if at all).
1694+ ///
1695+ /// Both sides write the final, post-deblock/CDEF/LR/superres frame as it
1696+ /// is stored into the reference buffer (`EC_AV1_FINAL_DUMP`, ours in
1697+ /// `decode_stream`, the oracle's in rung 12 of
1698+ /// `scripts/instrument-aom-oracle.sh`), 8-bit as u8 / high bitdepth as
1699+ /// u16 LE. Returns `(frames_decoded, hidden_frames)`.
1700+ fn decode_all_frames_vs_oracle(stream: &[u8], name: &str) -> (usize, usize) {
1701+ let dir = std::env::temp_dir().join(format!("ec-av1-{name}-{}", std::process::id()));
1702+ let _ = std::fs::remove_dir_all(&dir);
1703+ std::fs::create_dir_all(&dir).expect("scratch dir");
1704+ let obu = dir.join("in.obu");
1705+ std::fs::write(&obu, stream).expect("writing the stream");
1706+ let aom_prefix = dir.join("aom");
1707+ let out = Command::new(aomdec_path())
1708+ .args(["--codec=av1", "-o"])
1709+ .arg(dir.join("out.y4m"))
1710+ .arg(&obu)
1711+ .env("EC_AV1_FINAL_DUMP", &aom_prefix)
1712+ .stdin(Stdio::null())
1713+ .stdout(Stdio::piped())
1714+ .stderr(Stdio::piped())
1715+ .output()
1716+ .expect("aomdec failed to run");
1717+ assert!(
1718+ out.status.success(),
1719+ "{name}: the oracle aomdec refused the stream: {}",
1720+ String::from_utf8_lossy(&out.stderr)
1721+ );
1722+ let count_dumps = |prefix: &std::path::Path| -> usize {
1723+ let mut n = 0usize;
1724+ while std::path::PathBuf::from(format!("{}.f{n}", prefix.display())).is_file() {
1725+ n += 1;
1726+ }
1727+ n
1728+ };
1729+ let oracle_frames = count_dumps(&aom_prefix);
1730+ assert!(
1731+ oracle_frames > 0,
1732+ "{name}: the oracle wrote no EC_AV1_FINAL_DUMP frames -- rung 12 of \
1733+ scripts/instrument-aom-oracle.sh is missing from {}",
1734+ aomdec_path().display()
1735+ );
1736+ let ours_prefix = dir.join("ours");
1737+ set_final_dump_prefix(Some(ours_prefix.display().to_string()));
1738+ let decoded = decode_stream(stream);
1739+ set_final_dump_prefix(None);
1740+ let shown = decoded
1741+ .unwrap_or_else(|e| panic!("{name}: this decoder refused the stream: {e}"))
1742+ .len();
1743+ let our_frames = count_dumps(&ours_prefix);
1744+ assert_eq!(
1745+ our_frames, oracle_frames,
1746+ "{name}: decoded {our_frames} frames in decode order, the oracle decoded \
1747+ {oracle_frames}"
1748+ );
1749+ for i in 0..oracle_frames {
1750+ let want =
1751+ std::fs::read(format!("{}.f{i}", aom_prefix.display())).expect("oracle dump");
1752+ let got = std::fs::read(format!("{}.f{i}", ours_prefix.display())).expect("our dump");
1753+ assert_eq!(
1754+ got.len(),
1755+ want.len(),
1756+ "{name}: decode-order frame {i} is {} bytes, the oracle's is {}",
1757+ got.len(),
1758+ want.len()
1759+ );
1760+ if let Some(at) = got.iter().zip(&want).position(|(a, b)| a != b) {
1761+ let differing = got.iter().zip(&want).filter(|(a, b)| a != b).count();
1762+ panic!(
1763+ "{name}: decode-order frame {i} of {oracle_frames} ({shown} shown, {} \
1764+ hidden) differs from the oracle at byte {at} (ours {} vs {}), {differing} \
1765+ bytes differ -- stream pinned at {}",
1766+ oracle_frames - shown,
1767+ got[at],
1768+ want[at],
1769+ obu.display()
1770+ );
1771+ }
1772+ }
1773+ let hidden = oracle_frames - shown;
1774+ let _ = std::fs::remove_dir_all(&dir);
1775+ (oracle_frames, hidden)
1776+ }
1777+
1778+ /// The repo's first hidden-frame pixel gate. Every other aomenc gate
1779+ /// here compares `decode_stream`'s output against `ffmpeg -f obu`, and
1780+ /// both sides emit SHOWN frames only -- so an alt-ref frame that is
1781+ /// decoded, stored into a reference slot and never displayed was, until
1782+ /// this gate, never compared to anything (class
1783+ /// gate-blind-to-hidden-frames). His films are aomenc-encoded with the
1784+ /// default `--lag-in-frames`, so they are full of exactly these frames.
1785+ ///
1786+ /// `--auto-alt-ref=1 --lag-in-frames=25` on moving content makes aomenc
1787+ /// build alt-refs; `--arnr-maxframes=0` is load-bearing -- with libaom's
1788+ /// temporal filter on, this fixture's alt-ref candidates get filtered
1789+ /// away and the encoder emits ZERO hidden frames (measured: 0 hidden
1790+ /// with the filter on, 3 with it off), which would have made the gate
1791+ /// vacuous. The `hidden >= 2` assertion is hard, on both bit depths, so
1792+ /// a recipe that stops producing hidden frames fails rather than skips.
1793+ #[test]
1794+ fn a_real_aomenc_altref_sequence_hidden_frames_decode_pixel_exact() {
1795+ const NAME: &str = "a_real_aomenc_altref_sequence_hidden_frames_decode_pixel_exact";
1796+ let _gate_lock = lock_gate_counters();
1797+ if !have_ffmpeg() {
1798+ eprintln!("SKIP {NAME}: no ffmpeg");
1799+ return;
1800+ }
1801+ if !have_aomenc() {
1802+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
1803+ return;
1804+ }
1805+ for bit_depth in [8u32, 10u32] {
1806+ let (width, height, frames) = (64usize, 64usize, 40usize);
1807+ let duration = frames as f64 / 25.0;
1808+ let source = format!("testsrc2=size={width}x{height}:duration={duration}:rate=25");
1809+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
1810+ let y4m = Command::new("ffmpeg")
1811+ .args([
1812+ "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(),
1813+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
1814+ ])
1815+ .stdin(Stdio::null())
1816+ .stdout(Stdio::piped())
1817+ .stderr(Stdio::piped())
1818+ .output()
1819+ .expect("ffmpeg failed to run");
1820+ assert!(
1821+ y4m.status.success(),
1822+ "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}",
1823+ String::from_utf8_lossy(&y4m.stderr)
1824+ );
1825+ let depth_arg = format!("--bit-depth={bit_depth}");
1826+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
1827+ let mut child = Command::new(aomenc_path())
1828+ .args([
1829+ "--codec=av1",
1830+ "--passes=1",
1831+ "--end-usage=q",
1832+ "--cq-level=45",
1833+ "--cpu-used=0",
1834+ "--threads=1",
1835+ "--row-mt=0",
1836+ "--kf-max-dist=1000",
1837+ "--enable-order-hint=1",
1838+ "--auto-alt-ref=1",
1839+ "--lag-in-frames=25",
1840+ "--arnr-maxframes=0",
1841+ &depth_arg,
1842+ &input_depth_arg,
1843+ // The same tool set every sibling inter gate pins -- the
1844+ // open capability gaps (rect/AB partitions, warped/OBMC,
1845+ // masked compound, palette, ...) are other lanes' work;
1846+ // this gate is about hidden frames, not about them.
1847+ "--enable-warped-motion=0",
1848+ "--enable-obmc=0",
1849+ "--enable-masked-comp=0",
1850+ "--enable-interintra-comp=0",
1851+ "--enable-onesided-comp=0",
1852+ "--enable-interintra-wedge=0",
1853+ "--enable-smooth-interintra=0",
1854+ "--enable-rect-partitions=0",
1855+ "--enable-ab-partitions=0",
1856+ "--enable-1to4-partitions=0",
1857+ "--enable-filter-intra=0",
1858+ "--enable-smooth-intra=0",
1859+ "--enable-paeth-intra=0",
1860+ "--enable-directional-intra=0",
1861+ "--enable-angle-delta=0",
1862+ "--enable-tx-size-search=0",
1863+ "--enable-cdef=0",
1864+ "--enable-restoration=0",
1865+ "--max-partition-size=32",
1866+ "--min-partition-size=32",
1867+ "--enable-palette=0",
1868+ "--enable-intrabc=0",
1869+ "--enable-cfl-intra=0",
1870+ "--enable-ref-frame-mvs=0",
1871+ "--obu",
1872+ "-o",
1873+ "-",
1874+ "-",
1875+ ])
1876+ .stdin(Stdio::piped())
1877+ .stdout(Stdio::piped())
1878+ .stderr(Stdio::piped())
1879+ .spawn()
1880+ .expect("aomenc failed to start");
1881+ child
1882+ .stdin
1883+ .take()
1884+ .expect("aomenc stdin")
1885+ .write_all(&y4m.stdout)
1886+ .expect("writing y4m to aomenc");
1887+ let out = child.wait_with_output().expect("aomenc failed to run");
1888+ assert!(
1889+ out.status.success(),
1890+ "{NAME}: aomenc refused the {bit_depth}-bit fixture: {}",
1891+ String::from_utf8_lossy(&out.stderr)
1892+ );
1893+ let stream = out.stdout;
1894+ let (total, hidden) =
1895+ decode_all_frames_vs_oracle(&stream, &format!("altref-hidden-{bit_depth}bit"));
1896+ assert!(
1897+ hidden >= 2,
1898+ "{NAME}: the {bit_depth}-bit recipe produced only {hidden} hidden frame(s) of \
1899+ {total} decoded -- the gate would be vacuous (class \
1900+ gate-blind-to-hidden-frames)"
1901+ );
1902+ eprintln!(
1903+ "{NAME} {bit_depth}-bit: {total} frames decoded, {hidden} hidden, all \
1904+ pixel-exact vs the oracle in decode order"
1905+ );
1906+ }
1907+ }
1908+
1594 /// A real `aomenc` filter-intra fixture: every other intra mode disabled1909 /// A real `aomenc` filter-intra fixture: every other intra mode disabled
1595 /// (smooth/paeth/directional/angle-delta) and1910 /// (smooth/paeth/directional/angle-delta) and
1596 /// `--max-partition-size=32` (past which `av1_filter_intra_allowed_bsize`'s1911 /// `--max-partition-size=32` (past which `av1_filter_intra_allowed_bsize`'s
@@ -1982,19 +2297,16 @@ mod tests {
1982 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (10-bit)");2297 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (10-bit)");
1983 }2298 }
1984 2299
1985- /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --film-grain-test=1`2300+ /// The 10-bit *inter* counterpart of the gate above: a real `aomenc`
1986- /// stream, decoded pixel-exact against ffmpeg's own 10-bit decode of the2301+ /// `yuv420p10le` sequence whose non-key frames are plain forward
1987- /// identical bytes (ffmpeg synthesizes grain by default -- no2302+ /// single-`LAST_FRAME` P frames (same `--lag-in-frames=0
1988- /// grain-disable flag is passed anywhere in this file). Proves the2303+ /// --auto-alt-ref=0 --error-resilient=1` shape as the 8-bit inter gate),
1989- /// bit-depth-generic grain path (`film_grain.rs`'s `grain_range`,2304+ /// decoded pixel-exact on every frame. 10-bit intra was proven exact by
1990- /// `scale_lut`, the `<< (bit_depth - 8)` offsets/legal ranges) rather2305+ /// lane-hbd; inter reconstruction at `bit_depth == 10` was never gated.
1991- /// than the old `bit_depth != 8` refusal. HARD-asserts both the parsed
1992- /// `bit_depth == 10` and `film_grain::grain_hits() > 0`, so neither a
1993- /// silent 8-bit fallback nor a stream aomenc emitted without
1994- /// `apply_grain` can make it pass vacuously.
1995 #[test]2306 #[test]
1996- fn a_real_aomenc_10bit_film_grain_stream_decodes_pixel_exact() {2307+ fn a_real_aomenc_10bit_inter_sequence_decodes_pixel_exact() {
1997- const NAME: &str = "a_real_aomenc_10bit_film_grain_stream_decodes_pixel_exact";2308+ const NAME: &str = "a_real_aomenc_10bit_inter_sequence_decodes_pixel_exact";
2309+ let _gate_lock = lock_gate_counters();
1998 if !have_ffmpeg() {2310 if !have_ffmpeg() {
1999 eprintln!("SKIP {NAME}: no ffmpeg");2311 eprintln!("SKIP {NAME}: no ffmpeg");
2000 return;2312 return;
@@ -2003,18 +2315,204 @@ mod tests {
2003 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());2315 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2004 return;2316 return;
2005 }2317 }
2006- let (width, height) = (64usize, 64usize);2318+ let (width, height, frame_count) = (128usize, 64usize, 16usize);
2007- let stream = encode_10bit_gradients(2319+ let y4m = Command::new("ffmpeg")
2008- NAME,2320+ .args([
2009- width,2321+ "-v",
2010- height,2322+ "error",
2011- 1,2323+ "-f",
2012- &["--film-grain-test=1", "--limit=1"],2324+ "lavfi",
2325+ "-i",
2326+ &gradients_source(42, width, height, "duration=0.64:rate=25"),
2327+ "-pix_fmt",
2328+ "yuv420p10le",
2329+ "-strict",
2330+ "-1",
2331+ "-t",
2332+ "0.64",
2333+ "-f",
2334+ "yuv4mpegpipe",
2335+ "-",
2336+ ])
2337+ .stdin(Stdio::null())
2338+ .stdout(Stdio::piped())
2339+ .stderr(Stdio::piped())
2340+ .output()
2341+ .expect("ffmpeg failed to run");
2342+ assert!(
2343+ y4m.status.success(),
2344+ "ffmpeg failed to render the 10-bit fixture: {}",
2345+ String::from_utf8_lossy(&y4m.stderr)
2013 );2346 );
2014- assert_eq!(2347+ let mut child = Command::new(aomenc_path())
2015- parsed_bit_depth(&stream),2348+ .args([
2016- 10,2349+ "--codec=av1",
2017- "{NAME}: aomenc did not actually write a 10-bit sequence header"2350+ "--passes=1",
2351+ "--end-usage=q",
2352+ "--cq-level=15",
2353+ "--cpu-used=0",
2354+ "--threads=1",
2355+ "--row-mt=0",
2356+ "--sb-size=64",
2357+ "--input-bit-depth=10",
2358+ "--bit-depth=10",
2359+ "--lag-in-frames=0",
2360+ "--auto-alt-ref=0",
2361+ "--kf-max-dist=1000",
2362+ "--error-resilient=1",
2363+ "--aq-mode=0",
2364+ "--deltaq-mode=0",
2365+ "--enable-rect-partitions=0",
2366+ "--enable-ab-partitions=0",
2367+ "--enable-1to4-partitions=0",
2368+ "--enable-filter-intra=0",
2369+ "--enable-smooth-intra=0",
2370+ "--enable-paeth-intra=0",
2371+ "--enable-directional-intra=0",
2372+ "--enable-angle-delta=0",
2373+ "--enable-tx-size-search=0",
2374+ "--enable-cdef=1",
2375+ "--enable-restoration=1",
2376+ "--min-partition-size=16",
2377+ "--max-partition-size=32",
2378+ "--enable-palette=0",
2379+ "--enable-intrabc=0",
2380+ "--enable-cfl-intra=0",
2381+ "--enable-ref-frame-mvs=0",
2382+ "--obu",
2383+ "-o",
2384+ "-",
2385+ "-",
2386+ ])
2387+ .stdin(Stdio::piped())
2388+ .stdout(Stdio::piped())
2389+ .stderr(Stdio::piped())
2390+ .spawn()
2391+ .expect("aomenc failed to start");
2392+ child
2393+ .stdin
2394+ .take()
2395+ .expect("aomenc stdin")
2396+ .write_all(&y4m.stdout)
2397+ .expect("writing y4m to aomenc");
2398+ let out = child.wait_with_output().expect("aomenc failed to run");
2399+ assert!(
2400+ out.status.success(),
2401+ "aomenc refused the 10-bit fixture: {}",
2402+ String::from_utf8_lossy(&out.stderr)
2403+ );
2404+ let stream = out.stdout;
2405+ if let Ok(dump) = std::env::var("EC_AV1_GATE_DUMP") {
2406+ std::fs::write(dump, &stream).expect("dump stream");
2407+ }
2408+ let mut probe = Av1Parser::new();
2409+ let mut pos = 0usize;
2410+ while pos < stream.len() && probe.sequence_header().is_none() {
2411+ let obu = probe.parse_obu(&stream[pos..]).unwrap();
2412+ pos += obu.total_size;
2413+ }
2414+ assert_eq!(
2415+ probe
2416+ .sequence_header()
2417+ .expect("stream has a sequence header OBU")
2418+ .color_config
2419+ .bit_depth,
2420+ 10,
2421+ "{NAME}: aomenc did not actually write a 10-bit sequence header"
2422+ );
2423+ let before_deblock = decode::deblock_hits();
2424+ let before_inter = decode::inter_pred_hits();
2425+ let before_lr = crate::restoration::wiener_hits()
2426+ + crate::restoration::sgrproj_hits()
2427+ + crate::restoration::switchable_hits();
2428+ let frames = match decode_stream(&stream) {
2429+ Ok(frames) => frames,
2430+ Err(e) => panic!("{NAME}: decode_stream refused a real 10-bit inter stream: {e}"),
2431+ };
2432+ assert!(
2433+ decode::inter_pred_hits() > before_inter,
2434+ "{NAME}: no inter-predicted block decoded -- the gate proves nothing"
2435+ );
2436+ assert!(
2437+ decode::deblock_hits() > before_deblock,
2438+ "{NAME}: no deblocking edge fired -- raise cq-level"
2439+ );
2440+ // Loop restoration is where the 10-bit inter/intra defect lived
2441+ // (lane-hbdinter r1: the self-guided box sums were never brought back
2442+ // to the 8-bit scale, `restoration.c:660`); a recipe whose RD happened
2443+ // to pick RESTORE_NONE would pass while proving nothing.
2444+ assert!(
2445+ crate::restoration::wiener_hits()
2446+ + crate::restoration::sgrproj_hits()
2447+ + crate::restoration::switchable_hits()
2448+ > before_lr,
2449+ "{NAME}: no loop-restoration unit decoded a real filter -- lower cq-level"
2450+ );
2451+ eprintln!(
2452+ "{NAME}: inter_pred {} deblock {} cdef_idx {} wiener {} sgrproj {}",
2453+ decode::inter_pred_hits() - before_inter,
2454+ decode::deblock_hits() - before_deblock,
2455+ decode::cdef_idx_hits(),
2456+ crate::restoration::wiener_hits(),
2457+ crate::restoration::sgrproj_hits(),
2458+ );
2459+ assert_eq!(frames.len(), frame_count);
2460+ let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count);
2461+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
2462+ if got.y != want.y || got.u != want.u || got.v != want.v {
2463+ let pin = std::env::temp_dir().join("ec-av1-10bit-inter-gate-fail.obu");
2464+ let _ = std::fs::write(&pin, &stream);
2465+ let first = |a: &Vec<u16>, b: &Vec<u16>| {
2466+ a.iter()
2467+ .zip(b)
2468+ .enumerate()
2469+ .find(|(_, (x, y))| x != y)
2470+ .map(|(k, (x, y))| (k, *x, *y))
2471+ };
2472+ panic!(
2473+ "{NAME}: frame {i} mismatch vs ffmpeg -- Y {:?} U {:?} V {:?}; stream pinned at {}",
2474+ first(&got.y, &want.y),
2475+ first(&got.u, &want.u),
2476+ first(&got.v, &want.v),
2477+ pin.display()
2478+ );
2479+ }
2480+ }
2481+ }
2482+
2483+ /// lane-hbd10 r1: a real `aomenc --bit-depth=10 --film-grain-test=1`
2484+ /// stream, decoded pixel-exact against ffmpeg's own 10-bit decode of the
2485+ /// identical bytes (ffmpeg synthesizes grain by default -- no
2486+ /// grain-disable flag is passed anywhere in this file). Proves the
2487+ /// bit-depth-generic grain path (`film_grain.rs`'s `grain_range`,
2488+ /// `scale_lut`, the `<< (bit_depth - 8)` offsets/legal ranges) rather
2489+ /// than the old `bit_depth != 8` refusal. HARD-asserts both the parsed
2490+ /// `bit_depth == 10` and `film_grain::grain_hits() > 0`, so neither a
2491+ /// silent 8-bit fallback nor a stream aomenc emitted without
2492+ /// `apply_grain` can make it pass vacuously.
2493+ #[test]
2494+ fn a_real_aomenc_10bit_film_grain_stream_decodes_pixel_exact() {
2495+ const NAME: &str = "a_real_aomenc_10bit_film_grain_stream_decodes_pixel_exact";
2496+ if !have_ffmpeg() {
2497+ eprintln!("SKIP {NAME}: no ffmpeg");
2498+ return;
2499+ }
2500+ if !have_aomenc() {
2501+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2502+ return;
2503+ }
2504+ let (width, height) = (64usize, 64usize);
2505+ let stream = encode_10bit_gradients(
2506+ NAME,
2507+ width,
2508+ height,
2509+ 1,
2510+ &["--film-grain-test=1", "--limit=1"],
2511+ );
2512+ assert_eq!(
2513+ parsed_bit_depth(&stream),
2514+ 10,
2515+ "{NAME}: aomenc did not actually write a 10-bit sequence header"
2018 );2516 );
2019 let mut probe = Av1Parser::new();2517 let mut probe = Av1Parser::new();
2020 let mut pos = 0usize;2518 let mut pos = 0usize;
@@ -2123,6 +2621,300 @@ mod tests {
2123 );2621 );
2124 }2622 }
2125 2623
2624+ /// lane-hbdgates r1: drive one 10-bit aomenc recipe over `seeds`, decode
2625+ /// every attempt and pixel-compare every SHOWN frame against ffmpeg's own
2626+ /// 10-bit decode of the identical bytes. Per-tool firing counters are
2627+ /// sampled PER ATTEMPT and summed only over attempts that decoded *and*
2628+ /// compared -- a stream that hit a named refusal contributes nothing
2629+ /// (class `counter-from-refused-stream`). Named refusals are tolerated
2630+ /// and reported; a pixel mismatch is a hard failure, never a SKIP.
2631+ fn ten_bit_tool_gate(
2632+ name: &str,
2633+ width: usize,
2634+ height: usize,
2635+ frames: usize,
2636+ extra: &[&str],
2637+ seeds: &[u32],
2638+ counters: &[(&str, fn() -> usize)],
2639+ ) {
2640+ fn first_diff(ours: &[u16], theirs: &[u16], width: usize) -> Option<String> {
2641+ ours.iter()
2642+ .zip(theirs.iter())
2643+ .position(|(a, b)| a != b)
2644+ .map(|i| {
2645+ format!(
2646+ "first diff at index {i} (row {}, col {}): ours {} vs ffmpeg {}",
2647+ i / width,
2648+ i % width,
2649+ ours[i],
2650+ theirs[i]
2651+ )
2652+ })
2653+ }
2654+ let mut totals = vec![0usize; counters.len()];
2655+ let mut refusals: Vec<String> = Vec::new();
2656+ let mut compared = 0usize;
2657+ for &seed in seeds {
2658+ let stream = encode_10bit_gradients_seed(name, seed, width, height, frames, extra);
2659+ assert_eq!(
2660+ parsed_bit_depth(&stream),
2661+ 10,
2662+ "{name}: aomenc did not write a 10-bit sequence header (seed {seed})"
2663+ );
2664+ let before: Vec<usize> = counters.iter().map(|(_, f)| f()).collect();
2665+ let decoded = match decode_stream(&stream) {
2666+ Ok(frames) => frames,
2667+ Err(e) => {
2668+ refusals.push(format!("seed {seed}: {e}"));
2669+ continue;
2670+ }
2671+ };
2672+ // Deltas are read BEFORE the pixel compare so a mismatch report
2673+ // says whether the tool under test actually fired on the failing
2674+ // stream (a mismatch with a zero delta is some other defect).
2675+ let deltas: Vec<usize> = counters
2676+ .iter()
2677+ .zip(before.iter())
2678+ .map(|((_, f), b)| f() - b)
2679+ .collect();
2680+ let fired: Vec<String> = counters
2681+ .iter()
2682+ .zip(deltas.iter())
2683+ .map(|((label, _), d)| format!("{label}={d}"))
2684+ .collect();
2685+ let fired = fired.join(" ");
2686+ let reference = ffmpeg_decode_sequence_10bit(&stream, width, height, decoded.len());
2687+ assert_eq!(
2688+ decoded.len(),
2689+ reference.len(),
2690+ "{name}: seed {seed}: shown-frame count vs ffmpeg"
2691+ );
2692+ for (i, (ours, theirs)) in decoded.iter().zip(reference.iter()).enumerate() {
2693+ for (plane, (a, b), w) in [
2694+ ("Y", (&ours.y, &theirs.y), width),
2695+ ("U", (&ours.u, &theirs.u), width / 2),
2696+ ("V", (&ours.v, &theirs.v), width / 2),
2697+ ] {
2698+ if let Some(d) = first_diff(a, b, w) {
2699+ panic!("{name}: seed {seed} frame {i} plane {plane}: {d} [{fired}]");
2700+ }
2701+ }
2702+ }
2703+ compared += 1;
2704+ for (i, d) in deltas.iter().enumerate() {
2705+ totals[i] += d;
2706+ }
2707+ }
2708+ assert!(
2709+ compared > 0,
2710+ "{name}: every attempt hit a named refusal:\n{}",
2711+ refusals.join("\n")
2712+ );
2713+ for (i, (label, _)) in counters.iter().enumerate() {
2714+ assert!(
2715+ totals[i] > 0,
2716+ "{name}: {compared} attempt(s) decoded pixel-exact but {label} never fired -- \
2717+ the gate would prove nothing about that tool. refusals:\n{}",
2718+ refusals.join("\n")
2719+ );
2720+ }
2721+ let summary: Vec<String> = counters
2722+ .iter()
2723+ .zip(totals.iter())
2724+ .map(|((label, _), t)| format!("{label}={t}"))
2725+ .collect();
2726+ eprintln!(
2727+ "{name}: {compared}/{} attempts pixel-exact, {}",
2728+ seeds.len(),
2729+ summary.join(" ")
2730+ );
2731+ }
2732+
2733+ /// lane-hbdgates r1: the four intra tools that had an 8-bit gate and no
2734+ /// 10-bit one (`filter-intra`, `smooth-intra`, `paeth-intra`,
2735+ /// `intra-edge-filter`) on ONE real 10-bit `aomenc` key frame, each with
2736+ /// its own hard-asserted counter. His two films are yuv420p10le, so an
2737+ /// 8-bit-only gate for these tools proves nothing about the streams that
2738+ /// matter (lane-covbd r1).
2739+ #[test]
2740+ fn a_real_aomenc_10bit_intra_tools_stream_decodes_pixel_exact() {
2741+ const NAME: &str = "a_real_aomenc_10bit_intra_tools_stream_decodes_pixel_exact";
2742+ if !have_ffmpeg() {
2743+ eprintln!("SKIP {NAME}: no ffmpeg");
2744+ return;
2745+ }
2746+ if !have_aomenc() {
2747+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2748+ return;
2749+ }
2750+ ten_bit_tool_gate(
2751+ NAME,
2752+ 64,
2753+ 64,
2754+ 1,
2755+ &[
2756+ "--limit=1",
2757+ "--kf-max-dist=0",
2758+ "--enable-filter-intra=1",
2759+ "--enable-smooth-intra=1",
2760+ "--enable-paeth-intra=1",
2761+ "--enable-intra-edge-filter=1",
2762+ "--enable-directional-intra=1",
2763+ "--enable-angle-delta=0",
2764+ "--enable-rect-partitions=0",
2765+ "--enable-ab-partitions=0",
2766+ "--enable-1to4-partitions=0",
2767+ "--enable-tx-size-search=0",
2768+ "--enable-cdef=0",
2769+ "--enable-restoration=0",
2770+ "--max-partition-size=32",
2771+ "--min-partition-size=16",
2772+ "--enable-palette=0",
2773+ "--enable-intrabc=0",
2774+ "--enable-cfl-intra=0",
2775+ "--enable-ref-frame-mvs=0",
2776+ ],
2777+ &[42, 7, 11, 23, 31, 57],
2778+ &[
2779+ ("filter_intra_hits", decode::filter_intra_hits),
2780+ ("smooth_pred_hits", crate::intra::smooth_pred_hits),
2781+ ("paeth_pred_hits", crate::intra::paeth_pred_hits),
2782+ ("intra_edge_filter_hits", crate::intra::intra_edge_filter_hits),
2783+ ],
2784+ );
2785+ }
2786+
2787+ /// lane-hbdgates r1: `--enable-restoration=1` at 10 bits. Every earlier
2788+ /// bit-depth gate ran `--enable-restoration=0`, which is exactly why two
2789+ /// high-bit-depth loop-restoration defects survived to 2026-09-01
2790+ /// (SGR box sums unscaled, Wiener clamp at the 8-bit bound). Same recipe
2791+ /// as the 8-bit LR gate, at 10 bits.
2792+ // Written `#[ignore]`d on lane-hbdgates (the branch lacked lane-hbdinter's
2793+ // 10-bit LR fix and failed at seed 42, frame 0, Y index 122: ours 351 vs
2794+ // ffmpeg 350). Un-ignored on the merge into main 2026-09-01, where the
2795+ // SGR box-sum scaling and the Wiener clamp are fixed: 16/16 attempts
2796+ // pixel-exact, lr_hits=28.
2797+ #[test]
2798+ fn a_real_aomenc_10bit_restoration_stream_decodes_pixel_exact() {
2799+ const NAME: &str = "a_real_aomenc_10bit_restoration_stream_decodes_pixel_exact";
2800+ if !have_ffmpeg() {
2801+ eprintln!("SKIP {NAME}: no ffmpeg");
2802+ return;
2803+ }
2804+ if !have_aomenc() {
2805+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2806+ return;
2807+ }
2808+ // 192x128 = 3x2 superblocks, so `read_lr` is re-entered per SB
2809+ // (the 8-bit LR gate's own trap warning); cq-level=15 because
2810+ // aomenc's RD only picks a non-RESTORE_NONE frame type at low cq.
2811+ ten_bit_tool_gate(
2812+ NAME,
2813+ 192,
2814+ 128,
2815+ 1,
2816+ &[
2817+ "--limit=1",
2818+ "--kf-max-dist=0",
2819+ "--cq-level=15",
2820+ "--enable-restoration=1",
2821+ "--enable-cdef=0",
2822+ "--enable-rect-partitions=0",
2823+ "--enable-ab-partitions=0",
2824+ "--enable-1to4-partitions=0",
2825+ "--enable-filter-intra=0",
2826+ "--enable-smooth-intra=0",
2827+ "--enable-paeth-intra=0",
2828+ "--enable-tx-size-search=0",
2829+ "--max-partition-size=32",
2830+ "--min-partition-size=16",
2831+ "--enable-palette=0",
2832+ "--enable-intrabc=0",
2833+ "--enable-cfl-intra=0",
2834+ "--enable-ref-frame-mvs=0",
2835+ ],
2836+ &LR_SEEDS,
2837+ &[("lr_hits", ten_bit_lr_hits)],
2838+ );
2839+ }
2840+
2841+ /// Seeds swept by the 10-bit LR gate (the 8-bit gate needs ~40 attempts
2842+ /// to land a non-RESTORE_NONE frame; every attempt here still has to
2843+ /// decode pixel-exact).
2844+ const LR_SEEDS: [u32; 16] = [42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57];
2845+
2846+ /// Wiener + SGR + switchable loop-restoration firings, summed.
2847+ fn ten_bit_lr_hits() -> usize {
2848+ crate::restoration::wiener_hits()
2849+ + crate::restoration::sgrproj_hits()
2850+ + crate::restoration::switchable_hits()
2851+ }
2852+
2853+ /// lane-hbdgates r1: `--enable-rect-partitions=1 --enable-ab-partitions=1`
2854+ /// at 10 bits, one intra stream, one counter per tool
2855+ /// (`rect_partition_hits`, `partab_hits`) so a stream that only fired the
2856+ /// rect arms cannot stand in for AB.
2857+ #[test]
2858+ fn a_real_aomenc_10bit_rect_and_ab_partitions_decode_pixel_exact() {
2859+ const NAME: &str = "a_real_aomenc_10bit_rect_and_ab_partitions_decode_pixel_exact";
2860+ if !have_ffmpeg() {
2861+ eprintln!("SKIP {NAME}: no ffmpeg");
2862+ return;
2863+ }
2864+ if !have_aomenc() {
2865+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
2866+ return;
2867+ }
2868+ // The 8-bit free-partition/AB recipe, verbatim, at 10 bits: AB
2869+ // splits are an INTER dispatch here (intra-frame AB is still a named
2870+ // refusal), so the stream needs alt-refs and 24 frames, not one key
2871+ // frame.
2872+ ten_bit_tool_gate(
2873+ NAME,
2874+ 64,
2875+ 64,
2876+ 24,
2877+ &[
2878+ "--cq-level=45",
2879+ "--kf-max-dist=1000",
2880+ "--auto-alt-ref=1",
2881+ "--lag-in-frames=16",
2882+ "--enable-fwd-kf=0",
2883+ "--enable-order-hint=1",
2884+ "--enable-warped-motion=1",
2885+ "--enable-obmc=1",
2886+ "--tune-content=default",
2887+ "--enable-masked-comp=0",
2888+ "--enable-interintra-comp=0",
2889+ "--enable-onesided-comp=0",
2890+ "--enable-interintra-wedge=0",
2891+ "--enable-smooth-interintra=0",
2892+ "--enable-rect-partitions=1",
2893+ "--enable-ab-partitions=1",
2894+ "--enable-1to4-partitions=0",
2895+ "--enable-filter-intra=0",
2896+ "--enable-smooth-intra=0",
2897+ "--enable-paeth-intra=0",
2898+ "--enable-directional-intra=0",
2899+ "--enable-angle-delta=0",
2900+ "--enable-tx-size-search=0",
2901+ "--enable-cdef=0",
2902+ "--enable-restoration=0",
2903+ "--max-partition-size=32",
2904+ "--min-partition-size=16",
2905+ "--enable-palette=0",
2906+ "--enable-intrabc=0",
2907+ "--enable-cfl-intra=0",
2908+ "--enable-ref-frame-mvs=0",
2909+ ],
2910+ &LR_SEEDS,
2911+ &[
2912+ ("rect_partition_hits", decode::rect_partition_hits),
2913+ ("partab_hits", decode::partab_hits),
2914+ ],
2915+ );
2916+ }
2917+
2126 /// `bit_depth` of the first sequence header in `stream`.2918 /// `bit_depth` of the first sequence header in `stream`.
2127 fn parsed_bit_depth(stream: &[u8]) -> u8 {2919 fn parsed_bit_depth(stream: &[u8]) -> u8 {
2128 let mut probe = Av1Parser::new();2920 let mut probe = Av1Parser::new();
@@ -2147,6 +2939,20 @@ mod tests {
2147 height: usize,2939 height: usize,
2148 frames: usize,2940 frames: usize,
2149 extra: &[&str],2941 extra: &[&str],
2942+ ) -> Vec<u8> {
2943+ encode_10bit_gradients_seed(name, 42, width, height, frames, extra)
2944+ }
2945+
2946+ /// As [`encode_10bit_gradients`], but with the fixture seed exposed --
2947+ /// lane-hbdgates r1 sweeps seeds so a tool that aomenc's RD declines on
2948+ /// one fixture still gets a firing stream.
2949+ fn encode_10bit_gradients_seed(
2950+ name: &str,
2951+ seed: u32,
2952+ width: usize,
2953+ height: usize,
2954+ frames: usize,
2955+ extra: &[&str],
2150 ) -> Vec<u8> {2956 ) -> Vec<u8> {
2151 let duration = frames as f64 / 25.0;2957 let duration = frames as f64 / 25.0;
2152 let y4m = Command::new("ffmpeg")2958 let y4m = Command::new("ffmpeg")
@@ -2156,7 +2962,7 @@ mod tests {
2156 "-f",2962 "-f",
2157 "lavfi",2963 "lavfi",
2158 "-i",2964 "-i",
2159- &gradients_source(42, width, height, &format!("duration={duration}:rate=25")),2965+ &gradients_source(seed, width, height, &format!("duration={duration}:rate=25")),
2160 "-pix_fmt",2966 "-pix_fmt",
2161 "yuv420p10le",2967 "yuv420p10le",
2162 "-strict",2968 "-strict",
@@ -2177,18 +2983,21 @@ mod tests {
2177 "{name}: ffmpeg failed to render the 10-bit fixture: {}",2983 "{name}: ffmpeg failed to render the 10-bit fixture: {}",
2178 String::from_utf8_lossy(&y4m.stderr)2984 String::from_utf8_lossy(&y4m.stderr)
2179 );2985 );
2180- let mut args: Vec<&str> = vec![2986+ let mut args: Vec<&str> = vec!["--codec=av1", "--passes=1", "--end-usage=q"];
2181- "--codec=av1",2987+ // lane-hbdgates r1: a caller-supplied `--cq-level` REPLACES the
2182- "--passes=1",2988+ // default rather than being appended after it -- two `--cq-level`
2183- "--end-usage=q",2989+ // flags on one aomenc line is a coin flip on which one lands.
2184- "--cq-level=30",2990+ if !extra.iter().any(|a| a.starts_with("--cq-level=")) {
2991+ args.push("--cq-level=30");
2992+ }
2993+ args.extend_from_slice(&[
2185 "--cpu-used=0",2994 "--cpu-used=0",
2186 "--threads=1",2995 "--threads=1",
2187 "--row-mt=0",2996 "--row-mt=0",
2188 "--sb-size=64",2997 "--sb-size=64",
2189 "--input-bit-depth=10",2998 "--input-bit-depth=10",
2190 "--bit-depth=10",2999 "--bit-depth=10",
2191- ];3000+ ]);
2192 args.extend_from_slice(extra);3001 args.extend_from_slice(extra);
2193 args.extend_from_slice(&["--obu", "-o", "-", "-"]);3002 args.extend_from_slice(&["--obu", "-o", "-", "-"]);
2194 let mut child = Command::new(aomenc_path())3003 let mut child = Command::new(aomenc_path())
@@ -2780,48 +3589,222 @@ mod tests {
2780 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg");3589 assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg");
2781 }3590 }
2782 3591
2783- /// As [`a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact`],3592+ /// As [`a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact`],
2784- /// but WITHOUT `--enable-tx-size-search=0` -- the one flag every other3593+ /// but WITHOUT `--enable-tx-size-search=0` -- the one flag every other
2785- /// recipe in this file pins off specifically to keep the stream on3594+ /// recipe in this file pins off specifically to keep the stream on
2786- /// `TxMode::Largest`. Dropped, aomenc's RD is free to pick3595+ /// `TxMode::Largest`. Dropped, aomenc's RD is free to pick
2787- /// `TxMode::Select` and split some blocks' luma transform below their own3596+ /// `TxMode::Select` and split some blocks' luma transform below their own
2788- /// side (spec 5.11.16), which is what this test's `tx_depth_hits()`3597+ /// side (spec 5.11.16), which is what this test's `tx_depth_hits()`
2789- /// counter proves actually happened -- a stream that resolves every3598+ /// counter proves actually happened -- a stream that resolves every
2790- /// `tx_depth` to 0 would pixel-match by construction (identical to3599+ /// `tx_depth` to 0 would pixel-match by construction (identical to
2791- /// `TxMode::Largest`) without exercising the new split-TU decode path at3600+ /// `TxMode::Largest`) without exercising the new split-TU decode path at
2792- /// all. Same multi-seed retry shape as3601+ /// all. Same multi-seed retry shape as
2793- /// [`a_real_aomenc_inter_sequence_with_cdf_forwarding_decodes_pixel_exact`]:3602+ /// [`a_real_aomenc_inter_sequence_with_cdf_forwarding_decodes_pixel_exact`]:
2794- /// aomenc's own RD is free (with tx-size search on) to also occasionally3603+ /// aomenc's own RD is free (with tx-size search on) to also occasionally
2795- /// pick `allow_screen_content_tools` on this content, a separate,3604+ /// pick `allow_screen_content_tools` on this content, a separate,
2796- /// already-named refusal -- try several seeds, and the first stream that3605+ /// already-named refusal -- try several seeds, and the first stream that
2797- /// both decodes AND actually split a transform must be pixel-exact.3606+ /// both decodes AND actually split a transform must be pixel-exact.
3607+ #[test]
3608+ fn a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact() {
3609+ if !have_ffmpeg() {
3610+ eprintln!(
3611+ "SKIP a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact: no ffmpeg"
3612+ );
3613+ return;
3614+ }
3615+ if !have_aomenc() {
3616+ eprintln!(
3617+ "SKIP a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact: no aomenc at {}",
3618+ aomenc_path().display()
3619+ );
3620+ return;
3621+ }
3622+ let (width, height) = (64usize, 64usize);
3623+ let mut refusals = Vec::new();
3624+ for attempt in 0..40u32 {
3625+ let seed = 42 + attempt;
3626+ // A flat gradient never has enough local detail for the RD
3627+ // search to prefer a split transform over the block's own full
3628+ // size -- `mandelbrot`'s fractal boundary gives every attempt
3629+ // (a different `start_scale`) sharp, varied-frequency edges.
3630+ // start_scale 5.0 is the proven first try (decodes pixel-exact
3631+ // AND reads the seven-symbol set-1 tx_type rows on TX8 TUs);
3632+ // later attempts walk down for variety when aomenc's RD flips
3633+ // elsewhere.
3634+ let source = format!(
3635+ "mandelbrot=size=64x64:start_scale={}:rate=25",
3636+ 5.0 - f64::from(attempt) * 0.06
3637+ );
3638+ let y4m = Command::new("ffmpeg")
3639+ .args([
3640+ "-v",
3641+ "error",
3642+ "-f",
3643+ "lavfi",
3644+ "-i",
3645+ &source,
3646+ // Desaturated: chroma stays flat (constant 128) so
3647+ // `uv_mode` always resolves to `DC_PRED` and this
3648+ // decoder's still-unsupported directional-chroma round-2
3649+ // gap never fires, leaving the luma detail alone to
3650+ // drive whether `TxMode::Select`'s RD splits a block.
3651+ "-vf",
3652+ "hue=s=0",
3653+ "-pix_fmt",
3654+ "yuv420p",
3655+ "-t",
3656+ "0.04",
3657+ "-f",
3658+ "yuv4mpegpipe",
3659+ "-",
3660+ ])
3661+ .stdin(Stdio::null())
3662+ .stdout(Stdio::piped())
3663+ .stderr(Stdio::piped())
3664+ .output()
3665+ .expect("ffmpeg failed to run");
3666+ assert!(
3667+ y4m.status.success(),
3668+ "ffmpeg fixture: {}",
3669+ String::from_utf8_lossy(&y4m.stderr)
3670+ );
3671+ let mut child = Command::new(aomenc_path())
3672+ .args([
3673+ "--codec=av1",
3674+ "--passes=1",
3675+ "--end-usage=q",
3676+ "--cq-level=45",
3677+ "--cpu-used=0",
3678+ "--enable-rect-partitions=0",
3679+ "--enable-ab-partitions=0",
3680+ "--enable-1to4-partitions=0",
3681+ "--enable-filter-intra=0",
3682+ // Every non-DC intra tool off: directional chroma and
3683+ // angle deltas are separate round-2 gaps, and DC-only
3684+ // residual is exactly what gives the RD search a reason
3685+ // to split a transform.
3686+ "--enable-smooth-intra=0",
3687+ "--enable-paeth-intra=0",
3688+ "--enable-directional-intra=0",
3689+ "--enable-angle-delta=0",
3690+ "--enable-cdef=0",
3691+ // Loop restoration is a named refusal (aomenc's RD picks
3692+ // Sgrproj on this kind of content) -- off in every recipe
3693+ // whose test targets a different surface.
3694+ "--enable-restoration=0",
3695+ "--max-partition-size=32",
3696+ // 16x16 blocks are what split into the TX8 TUs whose
3697+ // set-1 tx_type rows this gate exists to prove; some
3698+ // scales resolve depth 2 (TX4, a named refusal) and the
3699+ // attempt loop just moves on.
3700+ "--min-partition-size=16",
3701+ "--enable-palette=0",
3702+ "--enable-intrabc=0",
3703+ "--enable-cfl-intra=0",
3704+ // use_ref_frame_mvs (temporal MV projection) is unimplemented in mvstack;
3705+ // leaving it on silently desyncs symbols on inter frames (grainfix lesson).
3706+ "--enable-ref-frame-mvs=0",
3707+ "--obu",
3708+ "-o",
3709+ "-",
3710+ "-",
3711+ ])
3712+ .stdin(Stdio::piped())
3713+ .stdout(Stdio::piped())
3714+ .stderr(Stdio::piped())
3715+ .spawn()
3716+ .expect("aomenc failed to start");
3717+ child
3718+ .stdin
3719+ .take()
3720+ .expect("aomenc stdin")
3721+ .write_all(&y4m.stdout)
3722+ .expect("writing y4m to aomenc");
3723+ let out = child.wait_with_output().expect("aomenc failed to run");
3724+ assert!(
3725+ out.status.success(),
3726+ "aomenc refused the fixture: {}",
3727+ String::from_utf8_lossy(&out.stderr)
3728+ );
3729+ let stream = out.stdout;
3730+ let before = decode::tx_depth_hits();
3731+ let frames = match decode_stream(&stream) {
3732+ Ok(frames) => frames,
3733+ Err(e) => {
3734+ refusals.push(format!("seed {seed}: {e}"));
3735+ continue;
3736+ }
3737+ };
3738+ if decode::tx_depth_hits() == before {
3739+ refusals.push(format!(
3740+ "seed {seed}: decoded, but no block resolved a split tx_depth"
3741+ ));
3742+ continue;
3743+ }
3744+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);
3745+ assert_eq!(
3746+ frames[0].y, ffmpeg_frames[0].y,
3747+ "luma vs ffmpeg (seed {seed})"
3748+ );
3749+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})");
3750+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})");
3751+ return;
3752+ }
3753+ eprintln!(
3754+ "SKIP a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact: every attempt \
3755+ hit a named refusal or never split a transform:\n{}",
3756+ refusals.join("\n")
3757+ );
3758+ }
3759+
3760+ /// lane-txselect's decisive gate: a real aomenc INTER sequence WITHOUT
3761+ /// `--enable-tx-size-search=0`, the flag every other inter recipe in this
3762+ /// file pins off precisely to keep the stream on `TxMode::Largest`.
3763+ /// Dropped, aomenc takes its own default (`TX_MODE_SELECT` -- which is
3764+ /// what both of the user's real films use), and an inter block's
3765+ /// transform size is then the recursive `txfm_split` tree of spec
3766+ /// 5.11.17 rather than one whole-block transform. A stream that decoded
3767+ /// pixel-exact while every `txfm_split` symbol resolved to "no split"
3768+ /// would prove nothing (it is `TxMode::Largest` by another name), so this
3769+ /// gate hard-asserts BOTH counters: at least one `txfm_split` symbol read
3770+ /// AND at least one split actually taken. Exhausting every attempt is a
3771+ /// FAILURE, not a SKIP -- an unfired gate is a vacuous gate.
2798 #[test]3772 #[test]
2799- fn a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact() {3773+ fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact() {
3774+ tx_select_inter_gate(8);
3775+ }
3776+
3777+ /// The 10-bit arm of the gate above (lane-txselect r2): both of the
3778+ /// user's films are `yuv420p10le` and var-tx is exactly the tool they
3779+ /// use, so an 8-bit-only proof would not reach them. Same recipe plus
3780+ /// `-b 10 --input-bit-depth=10`.
3781+ #[test]
3782+ fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact_10bit() {
3783+ tx_select_inter_gate(10);
3784+ }
3785+
3786+ fn tx_select_inter_gate(bit_depth: u32) {
2800 if !have_ffmpeg() {3787 if !have_ffmpeg() {
2801 eprintln!(3788 eprintln!(
2802- "SKIP a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact: no ffmpeg"3789+ "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no ffmpeg"
2803 );3790 );
2804 return;3791 return;
2805 }3792 }
2806 if !have_aomenc() {3793 if !have_aomenc() {
2807 eprintln!(3794 eprintln!(
2808- "SKIP a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact: no aomenc at {}",3795+ "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no aomenc at {}",
2809 aomenc_path().display()3796 aomenc_path().display()
2810 );3797 );
2811 return;3798 return;
2812 }3799 }
2813- let (width, height) = (64usize, 64usize);3800+ let (width, height, frame_count) = (64usize, 64usize, 4usize);
2814 let mut refusals = Vec::new();3801 let mut refusals = Vec::new();
2815 for attempt in 0..40u32 {3802 for attempt in 0..40u32 {
2816 let seed = 42 + attempt;3803 let seed = 42 + attempt;
2817- // A flat gradient never has enough local detail for the RD3804+ // Detail is what makes aomenc's RD prefer a split transform; a
2818- // search to prefer a split transform over the block's own full3805+ // flat gradient resolves every `txfm_split` to 0. `mandelbrot`'s
2819- // size -- `mandelbrot`'s fractal boundary gives every attempt3806+ // fractal boundary is the same source the sibling intra tx-select
2820- // (a different `start_scale`) sharp, varied-frequency edges.3807+ // gate uses, at a different `start_scale` per attempt.
2821- // start_scale 5.0 is the proven first try (decodes pixel-exact
2822- // AND reads the seven-symbol set-1 tx_type rows on TX8 TUs);
2823- // later attempts walk down for variety when aomenc's RD flips
2824- // elsewhere.
2825 let source = format!(3808 let source = format!(
2826 "mandelbrot=size=64x64:start_scale={}:rate=25",3809 "mandelbrot=size=64x64:start_scale={}:rate=25",
2827 5.0 - f64::from(attempt) * 0.063810 5.0 - f64::from(attempt) * 0.06
@@ -2834,19 +3817,23 @@ mod tests {
2834 "lavfi",3817 "lavfi",
2835 "-i",3818 "-i",
2836 &source,3819 &source,
2837- // Desaturated: chroma stays flat (constant 128) so3820+ // Desaturated chroma: `uv_mode` stays DC_PRED, so the
2838- // `uv_mode` always resolves to `DC_PRED` and this3821+ // still-refused directional-chroma gap never fires and
2839- // decoder's still-unsupported directional-chroma round-23822+ // luma detail alone drives the transform split.
2840- // gap never fires, leaving the luma detail alone to
2841- // drive whether `TxMode::Select`'s RD splits a block.
2842 "-vf",3823 "-vf",
2843 "hue=s=0",3824 "hue=s=0",
2844 "-pix_fmt",3825 "-pix_fmt",
2845- "yuv420p",3826+ if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" },
3827+ // y4m carries no official 10-bit tag; ffmpeg writes one
3828+ // only under `-strict -1` (a no-op at 8 bit).
3829+ "-strict",
3830+ "-1",
2846 "-t",3831 "-t",
2847- "0.04",3832+ "0.16",
2848 "-f",3833 "-f",
2849 "yuv4mpegpipe",3834 "yuv4mpegpipe",
3835+ "-strict",
3836+ "-1",
2850 "-",3837 "-",
2851 ])3838 ])
2852 .stdin(Stdio::null())3839 .stdin(Stdio::null())
@@ -2859,41 +3846,54 @@ mod tests {
2859 "ffmpeg fixture: {}",3846 "ffmpeg fixture: {}",
2860 String::from_utf8_lossy(&y4m.stderr)3847 String::from_utf8_lossy(&y4m.stderr)
2861 );3848 );
3849+ let depth_args: &[&str] = if bit_depth == 10 {
3850+ &["-b", "10", "--input-bit-depth=10"]
3851+ } else {
3852+ &[]
3853+ };
2862 let mut child = Command::new(aomenc_path())3854 let mut child = Command::new(aomenc_path())
3855+ .args(depth_args)
2863 .args([3856 .args([
2864 "--codec=av1",3857 "--codec=av1",
2865 "--passes=1",3858 "--passes=1",
2866 "--end-usage=q",3859 "--end-usage=q",
2867- "--cq-level=45",3860+ "--cq-level=55",
2868 "--cpu-used=0",3861 "--cpu-used=0",
3862+ "--lag-in-frames=0",
3863+ "--auto-alt-ref=0",
3864+ "--kf-max-dist=1000",
3865+ "--threads=1",
3866+ "--row-mt=0",
3867+ "--enable-order-hint=0",
3868+ "--enable-warped-motion=0",
3869+ "--enable-obmc=0",
3870+ "--enable-masked-comp=0",
3871+ "--enable-interintra-comp=0",
3872+ "--enable-dist-wtd-comp=0",
3873+ "--enable-diff-wtd-comp=0",
3874+ "--enable-onesided-comp=0",
3875+ "--enable-interintra-wedge=0",
3876+ "--enable-smooth-interintra=0",
2869 "--enable-rect-partitions=0",3877 "--enable-rect-partitions=0",
2870 "--enable-ab-partitions=0",3878 "--enable-ab-partitions=0",
2871 "--enable-1to4-partitions=0",3879 "--enable-1to4-partitions=0",
2872 "--enable-filter-intra=0",3880 "--enable-filter-intra=0",
2873- // Every non-DC intra tool off: directional chroma and
2874- // angle deltas are separate round-2 gaps, and DC-only
2875- // residual is exactly what gives the RD search a reason
2876- // to split a transform.
2877 "--enable-smooth-intra=0",3881 "--enable-smooth-intra=0",
2878 "--enable-paeth-intra=0",3882 "--enable-paeth-intra=0",
2879 "--enable-directional-intra=0",3883 "--enable-directional-intra=0",
2880 "--enable-angle-delta=0",3884 "--enable-angle-delta=0",
3885+ // DELIBERATELY ABSENT: --enable-tx-size-search=0.
2881 "--enable-cdef=0",3886 "--enable-cdef=0",
2882- // Loop restoration is a named refusal (aomenc's RD picks
2883- // Sgrproj on this kind of content) -- off in every recipe
2884- // whose test targets a different surface.
2885 "--enable-restoration=0",3887 "--enable-restoration=0",
2886 "--max-partition-size=32",3888 "--max-partition-size=32",
2887- // 16x16 blocks are what split into the TX8 TUs whose3889+ // Sub-16 inter partitions are a separate named refusal
2888- // set-1 tx_type rows this gate exists to prove; some3890+ // (this decoder codes no inter block below 16x16 through
2889- // scales resolve depth 2 (TX4, a named refusal) and the3891+ // the square path this gate drives), and detailed content
2890- // attempt loop just moves on.3892+ // makes aomenc's RD reach for them on nearly every seed.
2891 "--min-partition-size=16",3893 "--min-partition-size=16",
2892 "--enable-palette=0",3894 "--enable-palette=0",
2893 "--enable-intrabc=0",3895 "--enable-intrabc=0",
2894 "--enable-cfl-intra=0",3896 "--enable-cfl-intra=0",
2895- // use_ref_frame_mvs (temporal MV projection) is unimplemented in mvstack;
2896- // leaving it on silently desyncs symbols on inter frames (grainfix lesson).
2897 "--enable-ref-frame-mvs=0",3897 "--enable-ref-frame-mvs=0",
2898 "--obu",3898 "--obu",
2899 "-o",3899 "-o",
@@ -2918,32 +3918,80 @@ mod tests {
2918 String::from_utf8_lossy(&out.stderr)3918 String::from_utf8_lossy(&out.stderr)
2919 );3919 );
2920 let stream = out.stdout;3920 let stream = out.stdout;
2921- let before = decode::tx_depth_hits();3921+ let (reads_before, hits_before) =
3922+ (decode::txfm_split_reads(), decode::txfm_split_hits());
2922 let frames = match decode_stream(&stream) {3923 let frames = match decode_stream(&stream) {
2923 Ok(frames) => frames,3924 Ok(frames) => frames,
2924 Err(e) => {3925 Err(e) => {
2925- refusals.push(format!("seed {seed}: {e}"));3926+ let msg = e.to_string();
3927+ assert!(
3928+ msg.contains("unsupported"),
3929+ "tx-select inter decode failed outright (seed {seed}): {msg}"
3930+ );
3931+ refusals.push(format!("seed {seed}: {msg}"));
2926 continue;3932 continue;
2927 }3933 }
2928 };3934 };
2929- if decode::tx_depth_hits() == before {3935+ let (reads, hits) = (
3936+ decode::txfm_split_reads() - reads_before,
3937+ decode::txfm_split_hits() - hits_before,
3938+ );
3939+ if hits == 0 {
2930 refusals.push(format!(3940 refusals.push(format!(
2931- "seed {seed}: decoded, but no block resolved a split tx_depth"3941+ "seed {seed}: decoded, but no block took a txfm_split ({reads} symbols read)"
2932 ));3942 ));
2933 continue;3943 continue;
2934 }3944 }
2935- let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, 1);3945+ let ffmpeg_frames = if bit_depth == 10 {
2936- assert_eq!(3946+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
2937- frames[0].y, ffmpeg_frames[0].y,3947+ } else {
2938- "luma vs ffmpeg (seed {seed})"3948+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
3949+ };
3950+ assert_eq!(frames.len(), frame_count);
3951+ eprintln!(
3952+ "txselect gate {bit_depth}-bit seed={seed}: txfm_split reads={reads} splits taken={hits}"
2939 );3953 );
2940- assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})");3954+ // Name the first differing sample before the assert fires: a
2941- assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})");3955+ // 64x64 plane's `assert_eq!` output is 4096 numbers, useless for
3956+ // locating a desync.
3957+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3958+ for (plane, (g, w)) in [
3959+ ("Y", (&got.y, &want.y)),
3960+ ("U", (&got.u, &want.u)),
3961+ ("V", (&got.v, &want.v)),
3962+ ] {
3963+ let stride = if plane == "Y" { width } else { width / 2 };
3964+ if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) {
3965+ eprintln!(
3966+ "txselect gate seed={seed}: frame {i} {plane} first diff at \
3967+ ({}, {}) got {} want {} ({} samples differ)",
3968+ at % stride,
3969+ at / stride,
3970+ g[at],
3971+ w[at],
3972+ g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(),
3973+ );
3974+ let coords: Vec<String> = g
3975+ .iter()
3976+ .zip(w.iter())
3977+ .enumerate()
3978+ .filter(|(_, (a, b))| a != b)
3979+ .take(12)
3980+ .map(|(k, (a, b))| format!("({},{})={a}/{b}", k % stride, k / stride))
3981+ .collect();
3982+ eprintln!("txselect gate seed={seed}: frame {i} {plane} diffs {coords:?}");
3983+ }
3984+ }
3985+ }
3986+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3987+ assert_eq!(got.y, want.y, "frame {i} luma vs ffmpeg (seed {seed})");
3988+ assert_eq!(got.u, want.u, "frame {i} U vs ffmpeg (seed {seed})");
3989+ assert_eq!(got.v, want.v, "frame {i} V vs ffmpeg (seed {seed})");
3990+ }
2942 return;3991 return;
2943 }3992 }
2944- eprintln!(3993+ panic!(
2945- "SKIP a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact: every attempt \3994+ "tx_select_inter_gate({bit_depth}) never observed a taken txfm_split:\n{}",
2946- hit a named refusal or never split a transform:\n{}",
2947 refusals.join("\n")3995 refusals.join("\n")
2948 );3996 );
2949 }3997 }
@@ -3356,24 +4404,293 @@ mod tests {
3356 frames[0].y, ffmpeg_frames[0].y,4404 frames[0].y, ffmpeg_frames[0].y,
3357 "luma vs ffmpeg (seed {seed})"4405 "luma vs ffmpeg (seed {seed})"
3358 );4406 );
3359- assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})");4407+ assert_eq!(frames[0].u, ffmpeg_frames[0].u, "U vs ffmpeg (seed {seed})");
3360- assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})");4408+ assert_eq!(frames[0].v, ffmpeg_frames[0].v, "V vs ffmpeg (seed {seed})");
3361- if fired_runs >= 4 {4409+ if fired_runs >= 4 {
3362- return;4410+ return;
4411+ }
4412+ }
4413+ assert!(
4414+ fired_runs > 0,
4415+ "every attempt hit a named refusal or never exercised directional chroma:\n{}",
4416+ refusals.join("\n")
4417+ );
4418+ }
4419+
4420+ /// As above, but a multi-frame inter sequence -- `--lag-in-frames=0
4421+ /// --auto-alt-ref=0` keep every non-key frame a simple forward
4422+ /// single-`LAST_FRAME` P frame (no alt-ref/backward reference this
4423+ /// decoder's inter path does not model), `--kf-max-dist` past the clip's
4424+ /// own length keeps frame 0 the only key frame.
4425+ /// lane-inter8 r1: the inter tile path's SB-level `PARTITION_NONE` -- a
4426+ /// whole 64x64 superblock coded as ONE inter block, which is what aomenc
4427+ /// picks for static content and which this decoder refused by name
4428+ /// ("an inter SB-level partition type other than SPLIT") until this
4429+ /// round. HARD-asserts [`decode::inter_sb_none_hits`] moved (the arm
4430+ /// really fired, class refusal-lifted-without-a-gate) and every frame is
4431+ /// pixel-exact vs ffmpeg; a decode error is a FAILURE here, never a SKIP
4432+ /// (class gate-skips-on-its-own-failure).
4433+ /// lane-inter8 r1: generalised so the same recipe can target a deeper
4434+ /// level of the inter partition tree -- `min_part` is aomenc's
4435+ /// `--min-partition-size`, and `hits`/`what` name the counter that proves
4436+ /// the arm under test really fired.
4437+ fn inter_sb_none_gate(
4438+ name: &str,
4439+ ten_bit: bool,
4440+ min_part: &str,
4441+ max_part: &str,
4442+ hits: fn() -> usize,
4443+ what: &str,
4444+ // lane-inter8 r3: extra aomenc flags + the frame width they need.
4445+ // `--tile-columns=1` needs a frame at least two superblocks wide or
4446+ // aomenc silently codes one tile column and the arm is vacuous.
4447+ extra: &[&str],
4448+ width: usize,
4449+ ) {
4450+ if !have_ffmpeg() {
4451+ eprintln!("SKIP {name}: no ffmpeg");
4452+ return;
4453+ }
4454+ if !have_aomenc() {
4455+ eprintln!("SKIP {name}: no aomenc at {}", aomenc_path().display());
4456+ return;
4457+ }
4458+ let (height, frame_count) = (64usize, 4usize);
4459+ // A deterministic synthetic source with real motion (a static source
4460+ // codes every inter frame as skip and never exercises the residual
4461+ // path); bounded with `-t` (class gate-loader-slurps-whole-file).
4462+ let y4m = Command::new("ffmpeg")
4463+ .args([
4464+ "-v",
4465+ "error",
4466+ "-f",
4467+ "lavfi",
4468+ "-i",
4469+ &format!("mandelbrot=size={width}x{height}:rate=25"),
4470+ "-t",
4471+ "0.16",
4472+ "-pix_fmt",
4473+ if ten_bit { "yuv420p10le" } else { "yuv420p" },
4474+ // y4m calls 10-bit unofficial (same as the 10-bit key-frame
4475+ // gate's own fixture).
4476+ "-strict",
4477+ "-1",
4478+ "-f",
4479+ "yuv4mpegpipe",
4480+ "-",
4481+ ])
4482+ .stdin(Stdio::null())
4483+ .stdout(Stdio::piped())
4484+ .stderr(Stdio::piped())
4485+ .output()
4486+ .expect("ffmpeg failed to run");
4487+ assert!(
4488+ y4m.status.success(),
4489+ "{name}: ffmpeg fixture: {}",
4490+ String::from_utf8_lossy(&y4m.stderr)
4491+ );
4492+ let mut args: Vec<String> = [
4493+ "--codec=av1",
4494+ "--passes=1",
4495+ "--end-usage=q",
4496+ "--cq-level=40",
4497+ "--cpu-used=0",
4498+ "--lag-in-frames=0",
4499+ "--auto-alt-ref=0",
4500+ "--kf-max-dist=1000",
4501+ // No cross-frame CDF forwarding in this fixture (see the
4502+ // deblocking gate's own note).
4503+ "--error-resilient=1",
4504+ // This gate targets the SB-level NONE arm only: rect/AB/1-to-4
4505+ // partitions and sub-16x16 splits stay off so a failure here
4506+ // cannot be another lane's missing arm.
4507+ "--enable-rect-partitions=0",
4508+ "--enable-ab-partitions=0",
4509+ "--enable-1to4-partitions=0",
4510+ "--enable-filter-intra=0",
4511+ "--enable-smooth-intra=0",
4512+ "--enable-paeth-intra=0",
4513+ "--enable-directional-intra=0",
4514+ "--enable-angle-delta=0",
4515+ "--enable-tx-size-search=0",
4516+ "--enable-cdef=0",
4517+ "--enable-restoration=0",
4518+ "--enable-palette=0",
4519+ "--enable-intrabc=0",
4520+ "--enable-cfl-intra=0",
4521+ "--enable-ref-frame-mvs=0",
4522+ "--obu",
4523+ "-o",
4524+ "-",
4525+ "-",
4526+ ]
4527+ .iter()
4528+ .map(|s| (*s).to_string())
4529+ .collect();
4530+ for e in extra {
4531+ args.insert(1, (*e).to_string());
4532+ }
4533+ args.insert(1, format!("--min-partition-size={min_part}"));
4534+ args.insert(1, format!("--max-partition-size={max_part}"));
4535+ if ten_bit {
4536+ args.insert(1, "--input-bit-depth=10".to_string());
4537+ args.insert(1, "--bit-depth=10".to_string());
4538+ }
4539+ let mut child = Command::new(aomenc_path())
4540+ .args(&args)
4541+ .stdin(Stdio::piped())
4542+ .stdout(Stdio::piped())
4543+ .stderr(Stdio::piped())
4544+ .spawn()
4545+ .expect("aomenc failed to start");
4546+ child
4547+ .stdin
4548+ .take()
4549+ .expect("aomenc stdin")
4550+ .write_all(&y4m.stdout)
4551+ .expect("writing y4m to aomenc");
4552+ let out = child.wait_with_output().expect("aomenc failed to run");
4553+ assert!(
4554+ out.status.success(),
4555+ "{name}: aomenc refused the fixture: {}",
4556+ String::from_utf8_lossy(&out.stderr)
4557+ );
4558+ let stream = out.stdout;
4559+ let before = hits();
4560+ let frames = match decode_stream(&stream) {
4561+ Ok(frames) => frames,
4562+ Err(e) => {
4563+ let pin = std::env::temp_dir().join(format!("{name}-refused.obu"));
4564+ let _ = std::fs::write(&pin, &stream);
4565+ panic!("{name}: decode_stream refused a real aomenc stream: {e} (pinned at {})", pin.display());
4566+ }
4567+ };
4568+ assert!(
4569+ hits() > before,
4570+ "{name}: no {what} fired -- this gate proves nothing"
4571+ );
4572+ let ffmpeg_frames = if ten_bit {
4573+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
4574+ } else {
4575+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
4576+ };
4577+ assert_eq!(frames.len(), frame_count, "{name}: frame count");
4578+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
4579+ if got.y != want.y || got.u != want.u || got.v != want.v {
4580+ let pin = std::env::temp_dir().join(format!("{name}-mismatch.obu"));
4581+ let _ = std::fs::write(&pin, &stream);
4582+ panic!("{name}: frame {i} mismatch vs ffmpeg -- stream pinned at {}", pin.display());
4583+ }
4584+ }
4585+ }
4586+
4587+ #[test]
4588+ fn a_real_aomenc_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact() {
4589+ inter_sb_none_gate(
4590+ "a_real_aomenc_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact",
4591+ false,
4592+ "32",
4593+ "64",
4594+ decode::inter_sb_none_hits,
4595+ "whole-superblock inter PARTITION_NONE",
4596+ &[],
4597+ 64,
4598+ );
4599+ }
4600+
4601+ #[test]
4602+ fn a_real_aomenc_10bit_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact() {
4603+ inter_sb_none_gate(
4604+ "a_real_aomenc_10bit_inter_sequence_with_a_whole_superblock_block_decodes_pixel_exact",
4605+ true,
4606+ "32",
4607+ "64",
4608+ decode::inter_sb_none_hits,
4609+ "whole-superblock inter PARTITION_NONE",
4610+ &[],
4611+ 64,
4612+ );
4613+ }
4614+
4615+ /// lane-inter8 r1: the same recipe with `--min-partition-size=8`, so
4616+ /// aomenc's RD may split a 16x16 inter block into four 8x8 leaves. The
4617+ /// interior (non-edge-straddling) `PARTITION_SPLIT` at the 16x16 level
4618+ /// was refused by name until this round; the straddle path always ran the
4619+ /// same loop, so only [`decode::inter_sub16_split_hits`] -- which counts
4620+ /// interior splits only -- proves the newly-lifted alphabet value fired.
4621+ // lane-inter8 r2: GREEN. The neighbour side bands are mi-granular, every
4622+ // leaf stamps its own 2x2-mi span (including the compound-return path
4623+ // that used to skip `record_mi` entirely) and the compound
4624+ // group/index contexts read the LEAF's mi cell, not its 16x16's corner.
4625+ /// lane-inter8 r3, from lane-sub8's verifier finding: the mi-granular
4626+ /// inter neighbour bands added in r2 must reset per TILE (above) and per
4627+ /// SB row (left) and guard availability tile-relative, so the same recipe
4628+ /// runs again at 128x64 with two tile columns -- a leaf on the second
4629+ /// tile's first column has no left neighbour and must not read the first
4630+ /// tile's band.
4631+ // lane-inter8 r3: RED for a reason OUTSIDE this lane -- at 128x64 (the
4632+ // narrowest frame two tile columns can exist in) aomenc codes an
4633+ // SB-level rect partition on the KEY frame despite
4634+ // --enable-rect-partitions=0, so the stream stops at "a superblock-level
4635+ // partition type other than NONE or SPLIT" (lane-sbpart's arm) before a
4636+ // single 8x8 leaf is reached. The tile-relative audit it was written for
4637+ // was done by inspection instead: every reader of the mi bands guards on
4638+ // `tile_row0_mi`/`tile_col0_mi` (no `> 0` guard exists in decode.rs),
4639+ // `start_tile` resets the above mi bands over the tile's own mi column
4640+ // span and `start_row` resets every left mi band.
4641+ #[ignore = "lane-inter8 r3: blocked by the SB-level rect-partition refusal at 128x64 (lane-sbpart's arm), not by tile context"]
4642+ #[test]
4643+ fn a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_across_tile_columns_decodes_pixel_exact()
4644+ {
4645+ inter_sb_none_gate(
4646+ "a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_across_tile_columns_decodes_pixel_exact",
4647+ false,
4648+ "8",
4649+ "16",
4650+ decode::inter_sub16_split_hits,
4651+ "interior 16x16 inter PARTITION_SPLIT into 8x8 leaves",
4652+ &["--tile-columns=1"],
4653+ 128,
4654+ );
3363 }4655 }
4656+
4657+ #[test]
4658+ fn a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact() {
4659+ inter_sb_none_gate(
4660+ "a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact",
4661+ false,
4662+ "8",
4663+ "16",
4664+ decode::inter_sub16_split_hits,
4665+ "interior 16x16 inter PARTITION_SPLIT into 8x8 leaves",
4666+ &[],
4667+ 64,
4668+ );
3364 }4669 }
3365- assert!(4670+
3366- fired_runs > 0,4671+ #[test]
3367- "every attempt hit a named refusal or never exercised directional chroma:\n{}",4672+ // lane-inter8 r2: still RED, and ignored rather than deleted -- the 8-bit
3368- refusals.join("\n")4673+ // twin above is green, this 10-bit recipe stops at "an INTER 32x32
4674+ // partition type this decoder does not code (value=9)". That is OUR
4675+ // desync, proven: `EC_TRACE=1 aomdec` on the pinned stream reads
4676+ // 16 `bsize=9 value=3` (SPLIT) partitions and never a single value=9
4677+ // anywhere (class refusal-from-own-desync; the r1 ledger line claiming
4678+ // aomenc emits PARTITION_VERT_4 despite --enable-1to4-partitions=0 is
4679+ // hereby disproven). The divergence itself is not yet bisected.
4680+ #[ignore = "lane-inter8 r2: 10-bit twin still desyncs (surfaces as a bogus 32x32 value=9 refusal); 8-bit gate is green"]
4681+ fn a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact() {
4682+ inter_sb_none_gate(
4683+ "a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact",
4684+ true,
4685+ "8",
4686+ "16",
4687+ decode::inter_sub16_split_hits,
4688+ "interior 16x16 inter PARTITION_SPLIT into 8x8 leaves",
4689+ &[],
4690+ 64,
3369 );4691 );
3370 }4692 }
3371 4693
3372- /// As above, but a multi-frame inter sequence -- `--lag-in-frames=0
3373- /// --auto-alt-ref=0` keep every non-key frame a simple forward
3374- /// single-`LAST_FRAME` P frame (no alt-ref/backward reference this
3375- /// decoder's inter path does not model), `--kf-max-dist` past the clip's
3376- /// own length keeps frame 0 the only key frame.
3377 #[test]4694 #[test]
3378 fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() {4695 fn a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact() {
3379 if !have_ffmpeg() {4696 if !have_ffmpeg() {
@@ -6343,6 +7660,207 @@ mod tests {
6343 );7660 );
6344 }7661 }
6345 7662
7663+ /// lane-cwarp r1: a real `--enable-global-motion=1 --enable-dist-wtd-comp=1`
7664+ /// stream over a rotating/zooming source, so a `GLOBAL_GLOBALMV` compound
7665+ /// block lands under a ROTZOOM/AFFINE model and each of its two references
7666+ /// is predicted through its OWN global warp
7667+ /// (`crate::warp::warp_affine_compound`, libaom `av1_warp_plane` with
7668+ /// `conv_params->is_compound`) rather than translationally. Before r1 that
7669+ /// path was SILENTLY WRONG -- no refusal named it, both taps went through
7670+ /// `mc::predict_compound_intermediate`. `compound_warp_hits() > 0` is a
7671+ /// hard assert: a run where the encoder never emitted one proves nothing.
7672+ /// A decode error or a pixel mismatch is a FAILURE, never a skip.
7673+ fn run_compound_global_warp_gate(name: &str, ten_bit: bool) {
7674+ let _gate_lock = lock_gate_counters();
7675+ assert!(have_ffmpeg(), "{name}: ffmpeg required");
7676+ assert!(have_aomenc(), "{name}: no aomenc at {}", aomenc_path().display());
7677+ let (width, height, frame_count) = (64usize, 64usize, 24usize);
7678+ let before = crate::decode::compound_warp_hits();
7679+ let mut matched = 0u32;
7680+ let mut named_refusals = 0u32;
7681+ let mut attempts = 0u32;
7682+ for cq in [32u32, 45, 55] {
7683+ for (i, rate) in [0.010f64, 0.022].iter().enumerate() {
7684+ attempts += 1;
7685+ let duration = frame_count as f64 / 25.0;
7686+ // A rotation about the frame centre plus a slow zoom is what
7687+ // aomenc's global-motion search fits a ROTZOOM/AFFINE model to;
7688+ // mandelbrot gives it real, non-flat texture to track.
7689+ let source = format!(
7690+ "mandelbrot=size={w}x{h}:rate=25:start_x={sx}:start_y=-0.4,\
7691+ rotate=a={rate}*n:ow={w}:oh={h}:c=black,scale={width}:{height}",
7692+ w = width * 2,
7693+ h = height * 2,
7694+ sx = -0.6 + 0.01 * (i as f64),
7695+ );
7696+ let pix_fmt = if ten_bit { "yuv420p10le" } else { "yuv420p" };
7697+ let y4m = Command::new("ffmpeg")
7698+ .args([
7699+ "-v", "error", "-f", "lavfi", "-i", &source, "-t",
7700+ &duration.to_string(), "-pix_fmt", pix_fmt, "-strict", "-1",
7701+ "-f", "yuv4mpegpipe", "-",
7702+ ])
7703+ .stdin(Stdio::null())
7704+ .stdout(Stdio::piped())
7705+ .stderr(Stdio::piped())
7706+ .output()
7707+ .expect("ffmpeg failed to run");
7708+ assert!(
7709+ y4m.status.success(),
7710+ "ffmpeg fixture: {}",
7711+ String::from_utf8_lossy(&y4m.stderr)
7712+ );
7713+ let cq_arg = format!("--cq-level={cq}");
7714+ let mut args: Vec<&str> = vec![
7715+ "--codec=av1",
7716+ "--passes=1",
7717+ "--end-usage=q",
7718+ &cq_arg,
7719+ "--cpu-used=0",
7720+ "--kf-max-dist=1000",
7721+ "--threads=1",
7722+ "--row-mt=0",
7723+ "--auto-alt-ref=1",
7724+ "--lag-in-frames=25",
7725+ "--enable-fwd-kf=0",
7726+ "--enable-order-hint=1",
7727+ // the two tools this gate exists for
7728+ "--enable-global-motion=1",
7729+ "--enable-dist-wtd-comp=1",
7730+ "--enable-warped-motion=1",
7731+ "--enable-obmc=1",
7732+ "--enable-masked-comp=1",
7733+ "--enable-onesided-comp=0",
7734+ "--enable-interintra-comp=1",
7735+ "--enable-interintra-wedge=0",
7736+ "--enable-smooth-interintra=1",
7737+ "--tune-content=default",
7738+ // partition/intra tools this decoder does not code yet --
7739+ // same exclusion list every compound gate carries.
7740+ "--enable-rect-partitions=0",
7741+ "--enable-ab-partitions=0",
7742+ "--enable-1to4-partitions=0",
7743+ "--enable-filter-intra=0",
7744+ "--enable-smooth-intra=0",
7745+ "--enable-paeth-intra=0",
7746+ "--enable-directional-intra=0",
7747+ "--enable-angle-delta=0",
7748+ "--enable-tx-size-search=0",
7749+ "--enable-cdef=0",
7750+ "--enable-restoration=0",
7751+ "--max-partition-size=32",
7752+ "--min-partition-size=32",
7753+ "--enable-palette=0",
7754+ "--enable-intrabc=0",
7755+ "--enable-cfl-intra=0",
7756+ "--enable-ref-frame-mvs=0",
7757+ ];
7758+ if ten_bit {
7759+ args.extend_from_slice(&["--input-bit-depth=10", "--bit-depth=10"]);
7760+ }
7761+ args.extend_from_slice(&["--obu", "-o", "-", "-"]);
7762+ let mut child = Command::new(aomenc_path())
7763+ .args(&args)
7764+ .stdin(Stdio::piped())
7765+ .stdout(Stdio::piped())
7766+ .stderr(Stdio::piped())
7767+ .spawn()
7768+ .expect("aomenc failed to start");
7769+ child
7770+ .stdin
7771+ .take()
7772+ .expect("aomenc stdin")
7773+ .write_all(&y4m.stdout)
7774+ .expect("writing y4m to aomenc");
7775+ let out = child.wait_with_output().expect("aomenc failed to run");
7776+ assert!(
7777+ out.status.success(),
7778+ "aomenc refused the fixture: {}",
7779+ String::from_utf8_lossy(&out.stderr)
7780+ );
7781+ let stream = out.stdout;
7782+ let frames = match decode_stream(&stream) {
7783+ Err(e) => {
7784+ let msg = e.to_string();
7785+ assert!(
7786+ msg.contains("unsupported"),
7787+ "{name} failed outright, not a named refusal (cq {cq}): {msg}"
7788+ );
7789+ assert!(
7790+ !msg.contains("warp"),
7791+ "{name} refused on warp (cq {cq}) -- warp decode is ported: {msg}"
7792+ );
7793+ named_refusals += 1;
7794+ eprintln!("{name} cq {cq} rate {rate} refusal: {msg}");
7795+ continue;
7796+ }
7797+ Ok(frames) => frames,
7798+ };
7799+ let want = if ten_bit {
7800+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
7801+ } else {
7802+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
7803+ };
7804+ assert_eq!(frames.len(), frame_count);
7805+ if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP")
7806+ && frames
7807+ .iter()
7808+ .zip(&want)
7809+ .any(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v)
7810+ {
7811+ std::fs::write(&path, &stream).expect("writing pinned stream");
7812+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (cq {cq}) to {path}");
7813+ }
7814+ for (i, (got, want)) in frames.iter().zip(&want).enumerate() {
7815+ assert_eq!(got.y, want.y, "{name} frame {i} luma vs ffmpeg (cq {cq})");
7816+ assert_eq!(got.u, want.u, "{name} frame {i} U vs ffmpeg (cq {cq})");
7817+ assert_eq!(got.v, want.v, "{name} frame {i} V vs ffmpeg (cq {cq})");
7818+ }
7819+ matched += 1;
7820+ }
7821+ }
7822+ let hits = crate::decode::compound_warp_hits() - before;
7823+ eprintln!(
7824+ "{name}: {matched}/{attempts} pixel-exact, {named_refusals} named refusals, \
7825+ compound_warp_hits={hits}"
7826+ );
7827+ assert!(
7828+ hits > 0,
7829+ "{name}: no compound block was predicted through a per-ref global warp \
7830+ ({matched} matches, {named_refusals} refusals of {attempts}) -- gate vacuous"
7831+ );
7832+ assert!(matched > 0, "{name}: every attempt refused -- no pixel comparison ran");
7833+ }
7834+
7835+ /// 8-bit arm of [`run_compound_global_warp_gate`].
7836+ #[test]
7837+ fn a_real_compound_global_warp_stream_decodes_pixel_exact() {
7838+ run_compound_global_warp_gate("a_real_compound_global_warp_stream_decodes_pixel_exact", false);
7839+ }
7840+
7841+ /// 10-bit arm of [`run_compound_global_warp_gate`] -- both of his films are
7842+ /// `yuv420p10le`, and `warp_affine`'s `bd` was hardcoded 8 before r1.
7843+ ///
7844+ /// IGNORED, blocked by a PRE-EXISTING 10-bit COMPOUND defect this lane did
7845+ /// not introduce and does not own. Ablation run by lane-cwarp r1 on this
7846+ /// very recipe: with `--enable-global-motion=0 --enable-warped-motion=0`
7847+ /// (no warp of any kind reachable) the 10-bit stream STILL mismatches at
7848+ /// frame 1 luma, cq 32; with `--auto-alt-ref=0 --lag-in-frames=0
7849+ /// --enable-dist-wtd-comp=0` (single-reference 10-bit inter only) the same
7850+ /// recipe is 6/6 pixel-exact. So: 10-bit single-ref inter is exact, 10-bit
7851+ /// compound is not. `mc::diffwtd_mask`'s missing `(bd - 8)` round term was
7852+ /// found and fixed while bisecting this, but is NOT the whole defect.
7853+ /// Un-ignore the moment the 10-bit compound path is fixed -- the warp
7854+ /// wiring under test here is bit-depth generic already.
7855+ #[test]
7856+ #[ignore = "blocked by a pre-existing 10-bit compound MC defect (see doc comment)"]
7857+ fn a_real_compound_global_warp_10bit_stream_decodes_pixel_exact() {
7858+ run_compound_global_warp_gate(
7859+ "a_real_compound_global_warp_10bit_stream_decodes_pixel_exact",
7860+ true,
7861+ );
7862+ }
7863+
6346 /// lane-maskcomp r2 / lane-wedge r3: `--enable-masked-comp=1` streams7864 /// lane-maskcomp r2 / lane-wedge r3: `--enable-masked-comp=1` streams
6347 /// must consume `compound_type`/`wedge_idx`/`wedge_sign`/`mask_type`7865 /// must consume `compound_type`/`wedge_idx`/`wedge_sign`/`mask_type`
6348 /// entropy-exact AND build the real blend, DIFFWTD or WEDGE --7866 /// entropy-exact AND build the real blend, DIFFWTD or WEDGE --
@@ -10179,12 +11697,147 @@ mod tests {
10179 "--enable-filter-intra=0",11697 "--enable-filter-intra=0",
10180 "--enable-cfl-intra=0",11698 "--enable-cfl-intra=0",
10181 "--enable-intrabc=0",11699 "--enable-intrabc=0",
10182- "--enable-tx-size-search=0",11700+ "--enable-tx-size-search=0",
10183- "--obu",11701+ "--obu",
10184- "-o",11702+ "-o",
10185- "-",11703+ "-",
10186- "-",11704+ "-",
11705+ ];
11706+ let mut child = Command::new(aomenc_path())
11707+ .args(&args)
11708+ .stdin(Stdio::piped())
11709+ .stdout(Stdio::piped())
11710+ .stderr(Stdio::piped())
11711+ .spawn()
11712+ .expect("aomenc failed to start");
11713+ child
11714+ .stdin
11715+ .take()
11716+ .expect("aomenc stdin")
11717+ .write_all(&y4m.stdout)
11718+ .expect("writing y4m to aomenc");
11719+ let out = child.wait_with_output().expect("aomenc failed to run");
11720+ assert!(
11721+ out.status.success(),
11722+ "aomenc refused the fixture: {}",
11723+ String::from_utf8_lossy(&out.stderr)
11724+ );
11725+ let stream = out.stdout;
11726+ let frames = match decode_stream(&stream) {
11727+ Err(e) => {
11728+ let msg = e.to_string();
11729+ assert!(
11730+ msg.contains("unsupported"),
11731+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
11732+ );
11733+ // r5: the four SB-level AB arms (`partition_w64` 4-7)
11734+ // decode since this round, so the only partition refusal
11735+ // left at 64x64 is the 1:4 pair (values 8/9, four
11736+ // 64x16/16x64 strips, whose luma TX_64X16 this decoder
11737+ // has no transform for); the refusals this loop actually
11738+ // counts on these fixtures are the pre-existing
11739+ // screen-content-palette strip one. Every refusal is
11740+ // named, so a genuine decode failure still fails the
11741+ // assert above rather than skipping.
crates/ec-av1/src/warp.rsmodified+104 -16
@@ -2,11 +2,13 @@
2 //! `av1/common/warped_motion.c`: estimate a 2x3 affine model from up to2 //! `av1/common/warped_motion.c`: estimate a 2x3 affine model from up to
3 //! `LEAST_SQUARES_SAMPLES_MAX` neighbour-block motion samples3 //! `LEAST_SQUARES_SAMPLES_MAX` neighbour-block motion samples
4 //! ([`find_projection`]), then filter the reference through it with an 8x84 //! ([`find_projection`]), then filter the reference through it with an 8x8
5-//! tiled, two-pass 8-tap warped filter ([`warp_affine`]). 8-bit,5+//! tiled, two-pass 8-tap warped filter ([`warp_affine`]). Bit-depth generic
6-//! non-compound only (this decoder's warp arm only ever reaches a6+//! (lane-cwarp: `bd` is `crate::decode::bit_depth()`, was a hardcoded 8).
7-//! single-ref, non-skip-mode block, spec `is_motion_variation_allowed_bsize`7+//! `WARPED_CAUSAL` is single-ref by construction (spec 5.11.27:
8-//! -- `conv_params->is_compound` is always false on that path, so libaom's8+//! `motion_mode` is only read when `RefFrame[1] <= INTRA_FRAME`), but GLOBAL
9-//! compound/highbd branches are dropped).9+//! warp applies per reference on a compound block too --
10+//! [`warp_affine_compound`] is that path (libaom `av1_warp_plane` with
11+//! `conv_params->is_compound`).
10 12
11 /// `WARPEDMODEL_PREC_BITS` (`av1/common/mv.h`).13 /// `WARPEDMODEL_PREC_BITS` (`av1/common/mv.h`).
12 const WARPEDMODEL_PREC_BITS: u32 = 16;14 const WARPEDMODEL_PREC_BITS: u32 = 16;
@@ -419,11 +421,13 @@ fn clip_pixel(v: i32) -> u16 {
419 v.clamp(0, crate::decode::sample_max()) as u16421 v.clamp(0, crate::decode::sample_max()) as u16
420 }422 }
421 423
422-/// `av1_warp_affine_c` (`warped_motion.c`), 8-bit, non-compound only:424+/// `av1_highbd_warp_affine_c` (`warped_motion.c`)'s non-compound branch:
423 /// filters `reference` (row-major, `stride`, true extent `width`x`height`)425 /// filters `reference` (row-major, `stride`, true extent `width`x`height`)
424 /// through `params`' affine model into `dst` (row-major, `p_stride`), an426 /// through `params`' affine model into `dst` (row-major, `p_stride`), an
425 /// `p_width`x`p_height` block whose top-left sits at `(p_col, p_row)` in the427 /// `p_width`x`p_height` block whose top-left sits at `(p_col, p_row)` in the
426-/// (possibly chroma-subsampled) plane `dst` belongs to.428+/// (possibly chroma-subsampled) plane `dst` belongs to. Bit depth comes from
429+/// the stream (`crate::decode::bit_depth`), the same thread-local
430+/// [`clip_pixel`] already clamps against -- libaom's `bd` parameter.
427 #[allow(clippy::too_many_arguments)]431 #[allow(clippy::too_many_arguments)]
428 pub fn warp_affine(432 pub fn warp_affine(
429 params: &WarpParams,433 params: &WarpParams,
@@ -439,6 +443,91 @@ pub fn warp_affine(
439 p_stride: i32,443 p_stride: i32,
440 subsampling_x: i32,444 subsampling_x: i32,
441 subsampling_y: i32,445 subsampling_y: i32,
446+) {
447+ let bd = i32::from(crate::decode::bit_depth());
448+ // `reduce_bits_vert`, non-compound: `2 * FILTER_BITS - round_0`.
449+ let reduce_bits_vert = 2 * FILTER_BITS - REDUCE_BITS_HORIZ;
450+ warp_inner(
451+ params, reference, width, height, stride, p_col, p_row, p_width, p_height,
452+ subsampling_x, subsampling_y, bd, reduce_bits_vert,
453+ |row, col, sum| {
454+ dst[row * p_stride as usize + col] =
455+ clip_pixel(sum - (1 << (bd - 1)) - (1 << bd));
456+ },
457+ );
458+}
459+
460+/// lane-cwarp: `av1_highbd_warp_affine_c`'s `conv_params->is_compound`
461+/// branch (`do_average == 0`, i.e. "write the CONV_BUF entry"): identical
462+/// filter, but the vertical pass rounds by `conv_params->round_1`
463+/// (`COMPOUND_ROUND1_BITS == 7`, [`mc::predict_compound_intermediate`]'s
464+/// `INTER_ROUND_1_COMPOUND`) instead of `2*FILTER_BITS - round_0`, and the
465+/// result stays in the compound intermediate domain rather than becoming a
466+/// pixel. libaom keeps a constant bias in its CONV_BUF (the
467+/// `1 << offset_bits_horiz` / `1 << offset_bits_vert` terms, which survive
468+/// both roundings exactly because both exceed their shift) and subtracts
469+/// `(1 << (offset_bits - round_1)) + (1 << (offset_bits - round_1 - 1))`
470+/// at the blend; this crate's intermediates are UNBIASED (see
471+/// [`mc::diffwtd_mask`]'s derivation), so the identical constant --
472+/// `(1 << (bd + 4)) + (1 << (bd + 3))` -- is removed here instead, making
473+/// the output directly interchangeable with
474+/// [`mc::predict_compound_intermediate`]'s for
475+/// [`mc::combine_compound`]/[`mc::blend_masked_compound`].
476+#[allow(clippy::too_many_arguments)]
477+pub fn warp_affine_compound(
478+ params: &WarpParams,
479+ reference: &[u16],
480+ width: i32,
481+ height: i32,
482+ stride: i32,
483+ dst: &mut [i32],
484+ p_col: i32,
485+ p_row: i32,
486+ p_width: i32,
487+ p_height: i32,
488+ p_stride: i32,
489+ subsampling_x: i32,
490+ subsampling_y: i32,
491+) {
492+ let bd = i32::from(crate::decode::bit_depth());
493+ let bias = (1 << (bd + 4)) + (1 << (bd + 3));
494+ warp_inner(
495+ params, reference, width, height, stride, p_col, p_row, p_width, p_height,
496+ subsampling_x, subsampling_y, bd, COMPOUND_ROUND1_BITS,
497+ |row, col, sum| {
498+ dst[row * p_stride as usize + col] = sum - bias;
499+ },
500+ );
501+}
502+
503+/// `conv_params->round_0` (`ROUND0_BITS`), the warp filter's horizontal
504+/// rounding -- `InterRound0`, bit-depth independent for 8/10-bit content
505+/// (libaom only raises it at `bd == 12`, which this decoder refuses).
506+const REDUCE_BITS_HORIZ: i32 = 3;
507+/// `COMPOUND_ROUND1_BITS` (`convolve.h`): `conv_params->round_1` when
508+/// `is_compound`.
509+const COMPOUND_ROUND1_BITS: i32 = 7;
510+
511+/// The shared body of [`warp_affine`]/[`warp_affine_compound`]
512+/// (`av1_highbd_warp_affine_c`): everything up to and including the
513+/// vertical `ROUND_POWER_OF_TWO(sum, reduce_bits_vert)`, with `store`
514+/// receiving `(row, col, sum)` in block-local coordinates.
515+#[allow(clippy::too_many_arguments)]
516+fn warp_inner(
517+ params: &WarpParams,
518+ reference: &[u16],
519+ width: i32,
520+ height: i32,
521+ stride: i32,
522+ p_col: i32,
523+ p_row: i32,
524+ p_width: i32,
525+ p_height: i32,
526+ subsampling_x: i32,
527+ subsampling_y: i32,
528+ bd: i32,
529+ reduce_bits_vert: i32,
530+ mut store: impl FnMut(usize, usize, i32),
442 ) {531 ) {
443 let mat = &params.wmmat;532 let mat = &params.wmmat;
444 let (alpha, beta, gamma, delta) = (533 let (alpha, beta, gamma, delta) = (
@@ -447,11 +536,9 @@ pub fn warp_affine(
447 params.gamma as i64,536 params.gamma as i64,
448 params.delta as i64,537 params.delta as i64,
449 );538 );
450- const BD: i32 = 8;539+ let reduce_bits_horiz = REDUCE_BITS_HORIZ;
451- let reduce_bits_horiz = 3; // conv_params->round_0, non-compound 8-bit (InterRound0)540+ let offset_bits_horiz = bd + FILTER_BITS - 1;
452- let reduce_bits_vert = 2 * FILTER_BITS - reduce_bits_horiz; // InterRound1541+ let offset_bits_vert = bd + 2 * FILTER_BITS - reduce_bits_horiz;
453- let offset_bits_horiz = BD + FILTER_BITS - 1;
454- let offset_bits_vert = BD + 2 * FILTER_BITS - reduce_bits_horiz;
455 542
456 let mut i = p_row;543 let mut i = p_row;
457 while i < p_row + p_height {544 while i < p_row + p_height {
@@ -509,10 +596,11 @@ pub fn warp_affine(
509 sum += tmp[(k + m + 4) as usize][(l + 4) as usize] * coeffs[m as usize] as i32;596 sum += tmp[(k + m + 4) as usize][(l + 4) as usize] * coeffs[m as usize] as i32;
510 }597 }
511 sum = round2(sum as i64, reduce_bits_vert as u32) as i32;598 sum = round2(sum as i64, reduce_bits_vert as u32) as i32;
512- let out_row = (i - p_row + k + 4) as usize;599+ store(
513- let out_col = (j - p_col + l + 4) as usize;600+ (i - p_row + k + 4) as usize,
514- dst[out_row * p_stride as usize + out_col] =601+ (j - p_col + l + 4) as usize,
515- clip_pixel(sum - (1 << (BD - 1)) - (1 << BD));602+ sum,
603+ );
516 sy += gamma;604 sy += gamma;
517 l += 1;605 l += 1;
518 }606 }
lanes/covbd-r1.report.mdadded+86 -0
@@ -0,0 +1,86 @@
1+# lane-covbd r1 — gate coverage per (tool x bit depth)
2+
3+## What changed
4+- `crates/ec-av1/src/gate_coverage.rs`
5+ - `TOOL_UNIVERSE` (26 `--enable-*` flags, fixed in source, not derived): the flags the
6+ decoder cares about, so a flag *no* gate spells still counts as a hole (defaulted =
7+ unknown, the pre-existing rule).
8+ - `NEVER_EXERCISED_8BIT` (12 entries) / `NEVER_EXERCISED_10BIT` (19 entries), each
9+ `(flag, why)`.
10+ - tests `never_exercised_8bit_matches_the_gate_recipes` /
11+ `never_exercised_10bit_matches_the_gate_recipes`: negative check (every listed entry
12+ really has no `=1` at that depth) and positive check (a flag that a gate of that depth
13+ now enables must be deleted from the list — the test fails until it is).
14+ - `is_ten_bit(body)`: a gate is 10-bit if its recipe contains `encode_10bit_gradients`,
15+ `--bit-depth=10`, `--input-bit-depth=10`, or a `yuv420p10le` fixture (that is how the
16+ existing 10-bit gates spell it, stream.rs:1905/1934/2141/9001).
17+ - `gate_bodies()` / `flags_in()` factored out of `tool_settings()`; the original
18+ `NEVER_EXERCISED` list and its test are untouched.
19+ - `print_never_exercised_per_bit_depth`: the orchestrator helper.
20+- No gate recipe touched; `stream.rs` unchanged.
21+
22+## Finding
23+45 real-aomenc gates, **4 of them 10-bit**. Seven tools are positively enabled at 8 bits and
24+by no 10-bit gate: `restoration`, `cdef`-adjacent intra set (`filter-intra`,
25+`intra-edge-filter`, `paeth-intra`, `smooth-intra`), `rect-partitions`, `ab-partitions`.
26+`enable-restoration` is the instance that cost two hbd defects (SGR box sums unscaled,
27+Wiener clamp at the 8-bit bound, lane-hbdinter 2026-09-01).
28+
29+Caveat recorded in the list itself: `enable-superres` is a *flag-spelling* hole, not a real
30+one — the three superres gates drive `--superres-mode=1` (one of them 10-bit).
31+
32+## Printed lists (verbatim)
33+```
34+gate_coverage: 45 real-aomenc gates, 4 of them 10-bit
35+NEVER_EXERCISED_8BIT (12 of 26):
36+ --enable-1to4-partitions
37+ --enable-angle-delta
38+ --enable-cfl-intra
39+ --enable-dist-wtd-comp
40+ --enable-dual-filter
41+ --enable-flip-idtx
42+ --enable-global-motion
43+ --enable-intrabc
44+ --enable-rect-tx
45+ --enable-ref-frame-mvs
46+ --enable-superres
47+ --enable-tx64
48+NEVER_EXERCISED_10BIT (19 of 26):
49+ --enable-1to4-partitions
50+ --enable-ab-partitions
51+ --enable-angle-delta
52+ --enable-cfl-intra
53+ --enable-dist-wtd-comp
54+ --enable-dual-filter
55+ --enable-filter-intra
56+ --enable-flip-idtx
57+ --enable-global-motion
58+ --enable-intra-edge-filter
59+ --enable-intrabc
60+ --enable-paeth-intra
61+ --enable-rect-partitions
62+ --enable-rect-tx
63+ --enable-ref-frame-mvs
64+ --enable-restoration
65+ --enable-smooth-intra
66+ --enable-superres
67+ --enable-tx64
68+```
69+
70+## Gates / tests
71+- `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` -> 5 passed, 0 failed.
72+- `cargo test -p ec-av1 --lib refusal_inventory` -> 3 passed, 0 failed.
73+- `cargo check -p ec-av1` -> clean (118 pre-existing missing-doc warnings).
74+- EVIDENCE: crates/ec-av1/src/gate_coverage.rs | cargo test -p ec-av1 --lib gate_coverage -- --nocapture | 5/5 pass, 45 gates parsed, 4 ten-bit, 12/19 holes printed above
75+
76+## Refusals lifted
77+None — this lane is instrumentation only, no decode behaviour changed.
78+
79+## Residue
80+- accepted: `enable-superres` and `enable-cdef`-style aliasing. Tools driven by a non
81+ `--enable-*` flag (`--superres-mode=1`) read as holes. Fix is an alias map, one line per
82+ alias, when a second case appears.
83+- deferred: closing any 10-bit hole — other lanes own gate authoring; this lane was
84+ chartered not to write gates. What unblocks it: a 10-bit gate passing `=1` for the tool.
85+- accepted: `cargo fmt -p ec-av1` reformatted 18 unrelated files; reverted, only
86+ gate_coverage.rs is in the commit.
lanes/cwarp-r1.report.mdadded+98 -0
@@ -0,0 +1,98 @@
1+# lane-cwarp r1 -- per-reference GLOBAL warp on compound blocks
2+
3+VERDICT: DONE for the 8-bit path (new hard gate green, 37 real compound-warp
4+blocks). 10-bit arm is written but `#[ignore]`d, blocked by a PRE-EXISTING
5+10-bit *compound* MC defect this lane isolated but does not own.
6+
7+## Defect (charter premise re-measured, held)
8+`decode_inter_block`'s COMPOUND_REFERENCE branch predicted BOTH taps
9+translationally through `mc::predict_compound_intermediate`. libaom runs
10+`av1_init_warp_params` inside its per-reference loop
11+(`reconinter.c build_inter_predictors_8x8_and_bigger`), so each reference of a
12+`GLOBAL_GLOBALMV` block whose own gm model is > TRANSLATION is filtered through
13+`av1_warp_plane` into the compound intermediate. No refusal named this: the
14+pixels were silently wrong. Confirmed live -- the new gate hits 37 such blocks
15+in 6 real aomenc streams.
16+
17+`WARPED_CAUSAL` on a compound block: confirmed impossible, left alone.
18+libaom `decodemv.c read_motion_mode` -> `motion_mode_allowed` returns
19+SIMPLE_TRANSLATION for `has_second_ref(mbmi)`; spec 5.11.27 the same. So only
20+the GLOBAL arm of `allow_warp` is live on the compound path.
21+
22+## Changed
23+- `crates/ec-av1/src/warp.rs`
24+ - `warp_affine` split into a shared `warp_inner` + a store closure; the old
25+ hardcoded `const BD: i32 = 8` is now `crate::decode::bit_depth()` (the same
26+ thread-local `clip_pixel`/`sample_max` already use, so no call site moved).
27+ `REDUCE_BITS_HORIZ`/`COMPOUND_ROUND1_BITS` named from libaom's
28+ `conv_params->round_0`/`COMPOUND_ROUND1_BITS`.
29+ NOTE for lane-hbdinter: this is the whole of the warp bit-depth change --
30+ one `bd` local and two offset expressions, no signature change.
31+ - new `warp_affine_compound`: `av1_highbd_warp_affine_c`'s
32+ `conv_params->is_compound && !do_average` branch -- vertical pass rounds by
33+ `round_1 == 7` and the output stays in the compound intermediate domain.
34+ libaom's CONV_BUF carries a constant bias that its blend subtracts
35+ (`(1 << (offset_bits - round_1)) + (1 << (offset_bits - round_1 - 1))`);
36+ this crate's intermediates are unbiased, so exactly that constant --
37+ `(1 << (bd+4)) + (1 << (bd+3))` -- is removed here, making the output
38+ interchangeable with `mc::predict_compound_intermediate`'s for
39+ `combine_compound`/`blend_masked_compound`. Both offset terms survive their
40+ roundings exactly (each exceeds its shift), so bias removal is bit-exact,
41+ not an approximation.
42+- `crates/ec-av1/src/decode.rs`
43+ - compound branch: `is_global_mv0`/`is_global_mv1` hoisted out of the MiGrid
44+ stamp (and their size bound corrected from `bw4.min(bh4) >= 2`, which used
45+ the frame-CLIPPED write extent, to `side >= 8`, libaom's unclipped `bsize`
46+ -- differs only for a block whose visible extent is 4px);
47+ `compound_warp(ref, eligible)` builds each ref's `global_warp_params`
48+ (skipped on `force_integer_mv` or `gm.invalid`, mirroring
49+ `av1_init_warp_params` + `allow_warp`), and each of the six
50+ `predict_compound_intermediate` outputs is replaced by
51+ `warp_affine_compound` when that ref warps. Chroma is gated on
52+ `chroma_side >= 8` -- `av1_init_warp_params` returns early on
53+ `block_width < 8`, and that is the PLANE's block, so an 8x8 luma block's
54+ 4x4 chroma stays translational.
55+ - new `COMPOUND_WARP_HITS` counter + `compound_warp_hits()`.
56+- `crates/ec-av1/src/mc.rs` -- `diffwtd_mask`'s round is
57+ `2*FILTER_BITS - round_0 - round_1 + (bd - 8)` (libaom `diffwtd_mask_d16`,
58+ reconinter.c:306); the `(bd - 8)` term was missing (this function's own doc
59+ comment already named it), so every 10-bit DIFFWTD mask was 4x too coarse.
60+ Found while bisecting the 10-bit failure. 8-bit unaffected (`bd-8 == 0`).
61+ UNGATED: the only 10-bit compound gate is the ignored one below.
62+- `crates/ec-av1/src/stream.rs` -- `run_compound_global_warp_gate` + the two
63+ gates below. No refusal string existed for this defect, so none is lifted;
64+ `refusal_inventory.rs`/`gate_coverage.rs` needed no change (both green).
65+
66+## Gate
67+`a_real_compound_global_warp_stream_decodes_pixel_exact` (8-bit): rotating
68+mandelbrot (`rotate=a=RATE*n` over a 2x source, scaled to 64x64), 24 frames,
69+`--enable-global-motion=1 --enable-dist-wtd-comp=1 --lag-in-frames=25
70+--auto-alt-ref=1 --enable-warped-motion=1 --enable-masked-comp=1`, 3 cq x 2
71+rotation rates. Hard-asserts `compound_warp_hits() > 0` and `matched > 0`; a
72+decode error or a pixel mismatch is a panic, never a skip.
73+
74+EVIDENCE: cargo test -p ec-av1 --release --lib -- a_real_compound_global_warp --nocapture (EC_AV1_REQUIRE_AOMENC=1) | 6 real aomenc encodes, every display frame's Y/U/V vs ffmpeg | `6/6 pixel-exact, 0 named refusals, compound_warp_hits=37`
75+
76+EVIDENCE: same command with `--enable-global-motion=0 --enable-warped-motion=0` and, separately, `--auto-alt-ref=0 --lag-in-frames=0 --enable-dist-wtd-comp=0` (10-bit arm) | 2 ablation runs | warp-free 10-bit compound FAILS at frame 1 luma cq 32; 10-bit single-ref inter is 6/6 pixel-exact -> the residual is 10-bit COMPOUND, not warp
77+
78+EVIDENCE: cargo test -p ec-av1 --release --lib (EC_AV1_REQUIRE_AOMENC=1) | whole ec-av1 lib suite | **271 passed, 0 failed, 23 ignored**, 312s
79+
80+Hidden frames: the gate encodes with `--auto-alt-ref=1 --lag-in-frames=25`, so
81+hidden alt-refs exist and every shown frame that references them is compared;
82+a wrong hidden-frame reconstruction propagates into those. There is no
83+decode-order oracle compare here (the repo's `EC_AV1_DECODE_ORDER_DUMP` rung is
84+8-bit-only and manual) -- same standard as the other compound gates.
85+
86+## Residue
87+- deferred(the 10-bit compound MC defect): `a_real_compound_global_warp_10bit_stream_decodes_pixel_exact`
88+ is `#[ignore]`d with the ablation in its doc comment. Unblocked by whoever
89+ owns 10-bit compound MC; un-ignore it then -- the warp path under it is
90+ already bit-depth generic.
91+- flagged (same defect shape, NOT fixed): `decode_inter_block8`'s compound
92+ branch (decode.rs ~10969-11072 on this branch) has the identical
93+ translational-only compound prediction. For an 8x8 leaf the luma block is
94+ exactly 8x8, so libaom WOULD warp luma there (chroma 4x4 would not). Not
95+ wired this round: the 8x8 leaf's own gates are the subject of lane-gmaffine
96+ and a change here would land untested.
97+- accepted: `mc::diffwtd_mask`'s `(bd - 8)` fix is source-verified against
98+ libaom but has no green 10-bit gate behind it yet (see above).
lanes/hbdgates-r1.report.mdadded+82 -0
@@ -0,0 +1,82 @@
1+# lane-hbdgates r1 — 10-bit gates for the seven 8-bit-only tools
2+
3+His two films are yuv420p10le, so an 8-bit-only gate proves nothing about the streams that
4+matter. lane-covbd r1 named seven tools positively enabled by an 8-bit gate and by no 10-bit
5+gate. Six are now closed with real-aomenc 10-bit gates; the seventh (restoration) has its
6+gate written and it FAILS on a real 10-bit defect.
7+
8+## Result table
9+
10+| tool | gate | result | first diff |
11+|---|---|---|---|
12+| filter-intra | `a_real_aomenc_10bit_intra_tools_stream_decodes_pixel_exact` | PASS, 6/6 attempts pixel-exact, `filter_intra_hits=2` | — |
13+| smooth-intra | same gate | PASS, `smooth_pred_hits=16` | — |
14+| paeth-intra | same gate | PASS, `paeth_pred_hits=3` | — |
15+| intra-edge-filter | same gate | PASS, `intra_edge_filter_hits=22` | — |
16+| rect-partitions | `a_real_aomenc_10bit_rect_and_ab_partitions_decode_pixel_exact` | PASS, 12/16 attempts pixel-exact (4 named refusals), `rect_partition_hits=32` | — |
17+| ab-partitions | same gate | PASS, `partab_hits=4` | — |
18+| restoration | `a_real_aomenc_10bit_restoration_stream_decodes_pixel_exact` | **FAIL — `#[ignore]`d, real 10-bit LR defect** | seed 42, frame 0, plane Y, index 122 (row 0, col 122): ours **351** vs ffmpeg **350**, on a stream where `lr_hits=2` |
19+
20+## What changed
21+- `crates/ec-av1/src/intra.rs`
22+ - `smooth_pred_hits()` / `paeth_pred_hits()` (counted at the top of `predict`) and
23+ `intra_edge_filter_hits()` (counted inside `filter_intra_edge`, strength != 0).
24+ Separate counters per tool on purpose: the pre-existing `smooth_uv_hits` lumps
25+ SMOOTH..=PAETH together, so a paeth-only stream would have "proved" smooth intra
26+ ([[gate-blind-to-feature]]).
27+- `crates/ec-av1/src/stream.rs`
28+ - `ten_bit_tool_gate(name, w, h, frames, extra, seeds, counters)`: drives one 10-bit
29+ aomenc recipe over a seed sweep, decodes each attempt, pixel-compares EVERY shown
30+ frame against ffmpeg's own 10-bit decode, and sums each tool counter **per attempt,
31+ only over attempts that decoded and compared** (class `counter-from-refused-stream`).
32+ Named decode refusals are tolerated and reported; a pixel mismatch panics with
33+ plane + first-diff index + both values + the per-attempt firing deltas; no SKIP path.
34+ - `encode_10bit_gradients_seed(...)`: the existing helper with the fixture seed exposed;
35+ `encode_10bit_gradients` now delegates with seed 42 (all three prior call sites
36+ unchanged). A caller-supplied `--cq-level` now REPLACES the built-in `--cq-level=30`
37+ instead of being appended after it (two `--cq-level` on one aomenc line is a coin flip).
38+ - the three gates above.
39+- `crates/ec-av1/src/gate_coverage.rs`
40+ - `gate_bodies()` now (a) drops `#[ignore]`d gates — an ignored gate exercises nothing and
41+ must not close a hole — and (b) recognises gates that spell `--passes=1` inside the
42+ shared 10-bit helpers (`ten_bit_tool_gate` / `encode_10bit_gradients`); `is_ten_bit`
43+ likewise. 45 -> 49 gates parsed, 4 -> 7 of them 10-bit.
44+ - six entries deleted from `NEVER_EXERCISED_10BIT` (filter-intra, smooth-intra,
45+ paeth-intra, intra-edge-filter, rect-partitions, ab-partitions); `enable-restoration`
46+ kept with the failing-gate reason inline. 19 -> 13 holes.
47+
48+## Gate commands + results
49+- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- --nocapture --test-threads=1 10bit_intra_tools`
50+ -> `6/6 attempts pixel-exact, filter_intra_hits=2 smooth_pred_hits=16 paeth_pred_hits=3 intra_edge_filter_hits=22`
51+- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- --nocapture --test-threads=1 rect_and_ab`
52+ -> `12/16 attempts pixel-exact, rect_partition_hits=32 partab_hits=4`
53+- `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -- --nocapture --test-threads=1 10bit_restoration`
54+ (run with the `#[ignore]` overridden) -> FAIL, message above.
55+- `cargo test -p ec-av1 --lib gate_coverage -- --nocapture` -> 5 passed, 0 failed;
56+ `gate_coverage: 49 real-aomenc gates, 7 of them 10-bit`, `NEVER_EXERCISED_10BIT (13 of 26)`.
57+
58+EVIDENCE: crates/ec-av1/src/stream.rs (3 new gates) | EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib | intra-tools 6/6 pixel-exact (4 counters non-zero), rect+ab 12/16 pixel-exact (rect=32 partab=4), 10-bit LR gate fails Y[122] 351 vs 350 with lr_hits=2
59+
60+## Refusals lifted
61+None — this lane authors gates only; no decode behaviour changed. The rect/ab gate's 4
62+non-matching attempts are named refusals reported by the gate, not silenced.
63+
64+## Residue
65+- **fix-now (follow-on lane): the 10-bit loop-restoration defect.** Pinned recipe:
66+ `encode_10bit_gradients_seed(name, 42, 192, 128, 1, ...)` with `--cq-level=15
67+ --enable-restoration=1 --enable-cdef=0` (full list in the gate). `lr_hits=2` on the
68+ failing stream, so the LR filters ran; the mismatch is one LSB at 10 bits on the very
69+ first row, the shape of an unscaled box sum / an 8-bit clamp bound. Un-ignore the gate
70+ with the fix; do NOT weaken it. lane-hbdinter reports fixes of that shape on its own
71+ branch — if that merges first, re-run this gate before assuming the defect is still open.
72+- accepted: `enable-angle-delta`, `enable-cfl-intra`, `enable-1to4-partitions`,
73+ `enable-rect-tx`, `enable-tx64`, `enable-flip-idtx`, `enable-global-motion`,
74+ `enable-intrabc`, `enable-dist-wtd-comp`, `enable-dual-filter`, `enable-ref-frame-mvs`,
75+ `enable-superres` remain 10-bit holes — they are holes at 8 bits too (or flag-spelling
76+ aliases), so they belong to the lanes that gate them at all, not to this one.
77+
78+## Suite totals
79+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (lane worktree, commit 6adca66 state)
80+-> **279 passed; 0 failed; 24 ignored**, 1640s. The 24 ignored include this lane's
81+`a_real_aomenc_10bit_restoration_stream_decodes_pixel_exact` (the failing 10-bit LR gate)
82+and 23 pre-existing ignores.
lanes/hbdinter-r1.report.mdadded+143 -0
@@ -0,0 +1,143 @@
1+# lane-hbdinter round 1 report
2+
3+Branch `lane-hbdinter`, worktree `edith_codecs-hbdinter`, off main `3808cf8`.
4+Commit `d6b5912`.
5+
6+## Premise re-measured (charter said: 10-bit stream mismatches at frame 2)
7+
8+NOT reproduced as stated. Built the 10-bit counterpart of the 8-bit inter
9+gate (`a_real_aomenc_inter_sequence_with_deblocking_decodes_pixel_exact`'s
10+recipe + `--input-bit-depth=10 --bit-depth=10 --aq-mode=0 --deltaq-mode=0`):
11+
12+- 64x64, 4 frames, cq 55: **all 4 frames pixel-exact** (first run).
13+- 128x64, 16 frames (the charter's geometry), cq 55: **all 16 exact** once
14+ `--min-partition-size=16` keeps aomenc out of the pre-existing
15+ "an inter partition below 16x16" refusal (which is a different lane).
16+
17+So with that tool set 10-bit inter reconstruction was already exact. The
18+real defect only appears once **loop restoration** is enabled (cq-level=15,
19+`--enable-restoration=1`, the LR gate's own recipe), and it is NOT
20+inter-specific: the first mismatch is on **frame 0, the key frame**.
21+lane-hbd's 10-bit gate never saw it because its recipe leaves LR off.
22+
23+EVIDENCE: /tmp/ec-av1-10bit-inter-gate-fail.obu | cargo test -p ec-av1 --lib a_real_aomenc_10bit_inter_sequence_decodes_pixel_exact (compute_ab scaling reverted) | frame 0 V plane, sample 52: ours 289, ffmpeg 288
24+
25+## What changed (all four verified line-for-line against ~/.cache/aom-oracle/src)
26+
27+1. `crates/ec-av1/src/restoration.rs:~649` `compute_ab` -- box sums are now
28+ scaled back to the 8-bit range before `p` is formed
29+ (`a = Round2(A, 2*(bd-8))`, `b = Round2(B, bd-8)`, libaom
30+ `restoration.c:660-662`; `B[k]` keeps the RAW sum, as libaom does).
31+ **This is the site the gate attributes the mismatch to.**
32+2. `crates/ec-av1/src/restoration.rs:~545` `apply_wiener_stripe` -- the
33+ horizontal intermediate clamp was the fixed `[0, 8191]`
34+ (`WIENER_CLAMP_LIMIT(3, bd=8) - 1`, `convolve.h:43`) expressed in this
35+ crate's *unbiased* domain. Now `[-(1<<(bd+3)), (1<<(bd+5)) - 1 - (1<<(bd+3))]`,
36+ the libaom bound shifted by libaom's own `1 << (bd + 3)` bias (the
37+ `rounding` term of `highbd_convolve_add_src_horiz_hip`; the rest cancels
38+ against `WienerInfo`'s derived centre tap, as the existing doc comment
39+ derives). At 8-bit neither end is reachable -- that is why every 8-bit
40+ gate passed; at 10-bit the unbiased maximum is `128*1023 >> 3 == 16368`,
41+ so most Wiener intermediates were silently truncated at 8191.
42+3. `crates/ec-av1/src/mc.rs` `diffwtd_mask` -- round is
43+ `INTER_POST_ROUND + (bd - 8)` (libaom `reconinter.c:307`), was the
44+ constant 4.
45+4. `crates/ec-av1/src/warp.rs:450` `warp_affine` -- `const BD: i32 = 8`
46+ replaced by `decode::bit_depth()` in `offset_bits_horiz`,
47+ `offset_bits_vert` and the final `sum - (1<<(bd-1)) - (1<<bd)`
48+ (`av1_warp_affine_c`). Tip from lane-gmaffine, confirmed at the source.
49+
50+Ruled out, at the source, no change needed: non-compound and compound
51+sub-pel MC rounding. libaom only moves `round_0`/`round_1` when
52+`bd + FILTER_BITS - round_0 + 2 > 16` (`convolve.h:83`), i.e. 12-bit only;
53+10-bit keeps 3/11 (single) and 3/7 (compound). `aom_highbd_blend_a64_d16_mask_c`'s
54+`round_bits` is likewise bit-depth-independent, so `blend_masked_compound`
55+is correct as written.
56+
57+New counter: `mc::inter_pred_hits` (incremented in `predict_with_filters`,
58+`predict_scaled`, `predict_compound_intermediate`), re-exported as
59+`decode::inter_pred_hits`.
60+
61+## Gate
62+
63+`a_real_aomenc_10bit_inter_sequence_decodes_pixel_exact` (crates/ec-av1/src/stream.rs).
64+Real aomenc, `yuv420p10le`, 128x64, 16 frames, `--lag-in-frames=0
65+--auto-alt-ref=0 --kf-max-dist=1000 --error-resilient=1 --aq-mode=0
66+--deltaq-mode=0 --enable-restoration=1 --enable-cdef=1 --cq-level=15`,
67+sequence header asserted `bit_depth == 10`, all 16 frames compared against
68+ffmpeg's own `yuv420p10le` decode, hard-asserting three firing counters
69+(inter predictions, deblock edges, a non-`RESTORE_NONE` LR filter). Decode
70+errors and mismatches panic; nothing turns into SKIP.
71+
72+```
73+EC_AV1_REQUIRE_AOMENC=1 CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hbdinter \
74+ cargo test -p ec-av1 --lib -j3 a_real_aomenc_10bit_inter_sequence_decodes_pixel_exact -- --nocapture
75+```
76+
77+EVIDENCE: /tmp/claude-.../scratchpad/hbdinter-suite.log | the command above, with the fix | "inter_pred 759 deblock 2592 cdef_idx 0 wiener 1 sgrproj 3", test result: ok. 1 passed
78+
79+## Test totals
80+
81+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3`:
82+**268 passed, 0 failed, 23 ignored, 0 filtered out, 664.37s.**
83+
84+EVIDENCE: scratchpad/hbdinter-suite.log | cargo test -p ec-av1 --lib -j3 | test result: ok. 268 passed; 0 failed; 23 ignored
85+
86+## Refusals
87+
88+None lifted this round -- these were silent wrong-pixel defects behind
89+already-permitted code paths, not refusals. `refusal_inventory.rs` and
90+`gate_coverage.rs` unchanged and green in the suite above.
91+
92+## Film check
93+
94+`cargo run -p ec-av1 --example decode_probe` on the 3s extracts already in
95+this worktree (`fixtures/hbd-r5/{reelb,reelc}.obu`):
96+
97+- ReelB: `REFUSED: unsupported: AV1 tile (a partition below 8x8 ...)`
98+- ReelC: `REFUSED: unsupported: AV1 tile (a 32x32 partition type this decoder does not code (value=4))`
99+
100+Unchanged from lane-hbd r5 -- both films still stop at partition-coverage
101+refusals that sit *before* any of the four fixed sites, so no frontier
102+movement is claimable from this lane. The fixes matter for what happens
103+after those two lanes land.
104+
105+## Residue
106+
107+- deferred: 10-bit gate for masked compound (`diffwtd_mask`) — needs a real
108+ aomenc `--enable-masked-comp=1` 10-bit stream that actually lands a
109+ DIFFWTD block; the 8-bit masked-compound gate exists, its 10-bit twin does
110+ not — unblocked by cloning that gate's recipe at `--bit-depth=10`.
111+- deferred: 10-bit gate for warp/global motion (`warp.rs` bd) — same shape;
112+ lane-gmaffine owns the warp gates, this fix should be re-verified there
113+ once its 10-bit stream exists.
114+- deferred: 10-bit gate proving the Wiener clamp bound specifically — the
115+ gate's stream fired Wiener once and the mismatch it catches is attributed
116+ to `compute_ab` (ablated separately); the clamp fix is source-verified
117+ against `convolve.h:43` but not attributed by a failing-then-passing
118+ pixel — unblocked by a fixture whose LR RD picks `RESTORE_WIENER` at
119+ 10-bit (higher-detail content than `gradients`).
120+- FIXED after the first commit (`mc.rs` `combine_compound`, commit below):
121+ it folded libaom's truncating `>> DIST_PRECISION_BITS` and the following
122+ `Round2(.., INTER_POST_ROUND)` into one `Round2(.., 8)`. Those are not the
123+ same function -- the folded form rounds one LSB up whenever
124+ `(sum >> 4) + 8` sits one below a multiple of 16 with non-zero dropped
125+ low bits. Bit-depth independent (the CONV_BUF `round_offset` cancels
126+ exactly in this crate's unbiased domain, derived from
127+ `av1_highbd_dist_wtd_convolve_2d_c`), so it is a rare off-by-one at ANY
128+ depth. Flagged by lane-cwarp's measurement that 10-bit *compound* still
129+ mismatches frame 1 luma while single-ref is 6/6 exact -- this is my best
130+ candidate for that, but I did not have lane-cwarp's fixture, so it is
131+ UNVERIFIED against their mismatch. All 16 compound tests (incl. the two
132+ real-aomenc 8-bit compound/masked-compound gates) stay green with it:
133+ `cargo test -p ec-av1 --lib -j3 compound` -> 16 passed, 0 failed, 73.58s.
134+
135+## Overlap with lane-cwarp
136+
137+lane-cwarp commit `04fc3ce` (worktree `edith_codecs-cwarp`) carries the same
138+two fixes I derived independently here: `mc.rs` `diffwtd_mask`'s missing
139+`(bd - 8)` and `warp.rs`'s `const BD = 8`. Semantically identical, textually
140+different (my hunks carry different comments) -- **expect a conflict in
141+`mc.rs` and `warp.rs` when both branches merge; either side's hunk is
142+correct, keep one.** The LR (`compute_ab`, Wiener clamp) and
143+`combine_compound` fixes are unique to this branch.
lanes/hidden-r1.report.mdadded+72 -0
@@ -0,0 +1,72 @@
1+# lane-hidden r1 — a direct hidden-frame (alt-ref) pixel oracle + gate
2+
3+## Premise, re-measured
4+Charter premise (ledger `constraint|ec-av1 decode_stream pushes a picture only under
5+header.show_frame`) confirmed at HEAD dc5553f: `crates/ec-av1/src/stream.rs` pushes into
6+`pictures` only inside `if header.show_frame`, and every pixel gate compares against
7+`ffmpeg -f obu ... rawvideo` / `aomdec -o y4m`, both shown-frames-only. So no hidden
8+(`show_frame == 0`) alt-ref frame's pixels were compared anywhere in the repo.
9+
10+## What changed
11+- `scripts/instrument-aom-oracle.sh` (rung 12, appended): `EC_AV1_FINAL_DUMP=<prefix>` in the
12+ instrumented `aomdec` → `<prefix>.f<N>`, one file per DECODED frame (decode order, hidden
13+ frames included), written in `decode_frame` after CDEF + superres + loop restoration and
14+ before the `!pbi->dcb.corrupted` block — i.e. the frame exactly as stored into the reference
15+ buffer. Y then U then V, crop-sized rows (post-superres `y_crop_width`), 8-bit as u8 and
16+ high bitdepth as u16 LE via `CONVERT_TO_SHORTPTR` (bit-depth correct; the other dumps in
17+ this repo narrow u16→u8 and silently truncate 10-bit).
18+- `crates/ec-av1/src/stream.rs`: matching `EC_AV1_FINAL_DUMP` at the ref-slot store site
19+ (immediately before `pictures_decoded += 1;`, so post-deblock/CDEF/LR/superres, decode
20+ order, hidden frames included), same byte layout, `bit_depth == 8` → u8 else u16 LE. The
21+ prefix comes from a thread-local (`set_final_dump_prefix`) falling back to the env var, so
22+ a gate's dump cannot be polluted by a sibling test decoding on another thread.
23+- `crates/ec-av1/src/stream.rs` tests: `aomdec_path()`, helper
24+ `decode_all_frames_vs_oracle(stream, name) -> (frames, hidden)` (runs both dumps, asserts
25+ equal frame counts, compares every decode-order frame byte for byte, reports first
26+ differing byte + count and pins the stream on failure), and the gate
27+ `a_real_aomenc_altref_sequence_hidden_frames_decode_pixel_exact`.
28+
29+## Gate
30+`a_real_aomenc_altref_sequence_hidden_frames_decode_pixel_exact` — 64x64 testsrc2, 40 frames,
31+`--auto-alt-ref=1 --lag-in-frames=25 --arnr-maxframes=0 --kf-max-dist=1000` plus the tool set
32+the sibling inter gates pin; run for 8-bit and 10-bit. Hard `assert!(hidden >= 2)` (no skip),
33+hard per-frame byte equality incl. hidden frames, `decode_stream` error = failure not skip.
34+
35+`--arnr-maxframes=0` is load-bearing and was measured, not assumed: with libaom's temporal
36+alt-ref filter at its default the same recipe emits **0 hidden frames** (the gate would be
37+vacuous); with it off, 3.
38+
39+ cd /home/user/Documents/Code/Rust/edith_codecs-hidden
40+ export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-hidden
41+ EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \
42+ a_real_aomenc_altref_sequence_hidden -- --nocapture
43+
44+EVIDENCE: /tmp/.../t_arnr.f* + t10.f* (oracle dumps), gate stdout | aomenc --auto-alt-ref=1 --lag-in-frames=25 --arnr-maxframes=0, aomdec EC_AV1_FINAL_DUMP, decode_stream EC_AV1_FINAL_DUMP, byte compare | 8-bit: 43 frames decoded, 3 hidden, all pixel-exact; 10-bit: 43 frames decoded, 3 hidden, all pixel-exact
45+EVIDENCE: oracle rung proof | `EC_AV1_FINAL_DUMP=$PWD/fin aomdec -o out.y4m alt.obu` on a default-settings aomenc stream | dumps=31 vs shown=30 → the rung emits the hidden frame the y4m output does not; 8-bit f0 = 6144 B = 64x64x1.5, 10-bit f0 = 12288 B = 2 bytes/sample
46+EVIDENCE: recipe-vacuity measurement | same recipe with/without --arnr-maxframes=0 | hidden 0 → 3
47+
48+## Refusals
49+None lifted (`refusal_inventory.rs` / `gate_coverage.rs` untouched) — this lane adds an
50+instrument and a gate, it does not widen decode capability.
51+
52+## (d) Which existing gates carry hidden frames
53+Static scan of the 52 encoder-driven gates in stream.rs: **15 pre-existing gates pass
54+`--auto-alt-ref=1`** (1 with `--lag-in-frames=0`, so no alt-ref is possible there):
55+reference_select, compound_references, obmc, obmc_8x8, warped_motion, interintra,
56+interintra_wedge, free_partitions, ab_partitions, masked_compound, cdef,
57+an_altref_reference, delta_q_and_delta_lf, gradients_with_cdef (lag=25), and
58+a_golden_reference (lag=0 → none). Measured proxy for that recipe shape (the reference-select
59+arg list, 20 frames at lag=16, testsrc2 rather than each gate's own `gradients_source` seed):
60+**1 hidden frame per stream, decoded by us and compared by nothing**. The 40-frame variant of
61+the same recipe produced 0 (libaom's temporal filter absorbs the candidates), so the count is
62+content- and length-dependent — a per-gate sweep with each gate's own fixture is the honest
63+way to size it.
64+
65+- deferred: sweeping `decode_all_frames_vs_oracle` over the 14 alt-ref-capable existing gate
66+ recipes — cheap per gate but 14 recipe transcriptions and 14 encodes; unblocked by an
67+ orchestrator decision (the helper it needs now exists and is one call per gate).
68+- accepted: the gate's fixture is `testsrc2` (deterministic lavfi source, no seed) rather
69+ than `gradients_source` (whose seed lavfi ignores — memory `seeded-fixture-not-reproducible`).
70+
71+## Suite
72+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (scoped, per charter): **273 passed, 0 failed, 22 ignored, 0 filtered**, 1060.84s (branch lane-hidden @ 25b7222).
lanes/inter8-r1.report.mdadded+87 -0
@@ -0,0 +1,87 @@
1+# lane-inter8 r1 -- inter partition tree: the 16x16 level and its 8x8 leaves
2+
3+Branch `lane-inter8`, off main `3808cf8` (resumed from the orchestrator's WIP
4+snapshot `a5430ec`). **NOT merge-ready**: the round's gate is RED and `#[ignore]`d
5+with its reason (see "Open residue"). Nothing here has been merged to main.
6+
7+## What changed
8+
9+- `crates/ec-av1/src/decode.rs` (inter tile loop, ~12345): the interior (non
10+ edge-straddling) 16x16 partition symbol is now read as the real alphabet and
11+ `PARTITION_SPLIT` recurses into four 8x8 inter leaves (previously: refused by
12+ name). Refusal narrowed to
13+ `"an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)"`.
14+ Counter `INTER_SUB16_SPLIT_HITS` / `inter_sub16_split_hits()` counts *interior*
15+ splits only -- the straddle path always ran that same loop, so only an interior
16+ count proves the newly-lifted alphabet value fired. (from the WIP snapshot)
17+- `decode.rs` `obmc_blend`: `av1_skip_u4x4_pred_in_obmc` -- the ABOVE pass skips
18+ chroma when the chroma block is 4x4/8x4/4x8 (8x8, 16x8, 8x16 luma at 4:2:0);
19+ `obmc_mask_2` added. (from the WIP snapshot)
20+- `decode.rs` `decode_inter_block8` (8x8 leaf), THIS round, three real defects,
21+ each one moving the aomdec range ladder strictly later:
22+ 1. the leaf built its `comp_mode` / compound-ref contexts from a FABRICATED
23+ neighbour (`ref0 = LAST_FRAME` if inter, `ref1 = None`, `uni = false`).
24+ `av1_get_reference_mode_context` asks whether a neighbour is COMPOUND, so
25+ with real LAST+GOLDEN compound neighbours the leaf picked the wrong CDF row
26+ and read single-ref where aomdec read compound `NEAR_NEWMV` (mi 4,14).
27+ Now uses `neighbours.above_ref/above_ref1/left_ref/left_ref1` with the same
28+ `is_uni_comp_ref` logic as `decode_inter_block` one level up.
29+ 2. the sibling-leaf override was a single `prev_leaf` (the previously decoded
30+ leaf). The bottom-LEFT leaf's ABOVE neighbour is leaf 0, never leaf 1, so
31+ one of the four leaves always read a stale neighbour -- class
32+ `context-read-from-one-cell`. Now a `prev_leaves` slice, matched by
33+ coordinate, and each leaf hands back its own resolved `(ref0, ref1)`.
34+ 3. both leaf mv stacks were built with `NO_SIGN_BIAS` / `NO_GM_MV` while the
35+ 16x16 path passed the frame's real tables; `assign_compound_mv` got
36+ `((0,0),(0,0))` for the gm mvs. Now threaded (`sign_bias_table`,
37+ `global_motion` params + a leaf-local `build_gm_mv_table`). Alignment with
38+ the proven path; it did NOT move this fixture's ladder (identity gm here).
39+- `decode.rs`: `EC_MODE mi_row=.. mi_col=.. rng=..` traces under `EC_TRACE_MODE`
40+ in both `decode_inter_block` and `decode_inter_block8`, byte-format-identical
41+ to the oracle's rung-4 `EC_MODE`, plus `EC_LEAFMODE` (compound mode / stack
42+ size / ctxs) and a `TRACE partition_w16` line under `EC_AV1_TRACE`. These are
43+ the instruments the round was actually decided with.
44+- `crates/ec-av1/src/stream.rs`: `inter_sb_none_gate` generalised to take
45+ `min_part` / `max_part` (aomenc `--min/--max-partition-size`) and the counter
46+ + label that proves the arm under test fired, so one recipe can target any
47+ level of the inter partition tree. Two new gates
48+ (`a_real_aomenc_[10bit_]inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact`,
49+ `min=8 max=16`) assert `inter_sub16_split_hits` moved and every frame is
50+ pixel-exact -- currently `#[ignore]`d, RED.
51+
52+## Gate + evidence
53+
54+Command (from the worktree, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-inter8`,
55+`EC_AV1_REQUIRE_AOMENC=1`):
56+
57+ cargo test -p ec-av1 --lib -- --ignored an_8x8_leaf_split
58+
59+EVIDENCE: /tmp/a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact-refused.obu | aomenc mandelbrot 64x64 4 frames, cq40 cpu0 --min-partition-size=8 --max-partition-size=16, rect/AB/1to4 off; decoded by ours (EC_TRACE_MODE) and by the instrumented aomdec (EC_TRACE_MODE) | partition symbol stream agrees 118/118 (size,ctx,value) vs aomdec EC_PART; inter mode-info range ladder agreed 41/57 before this round's fixes and 42/57 after, first divergence moved from block mi=(4,14) to mi=(6,12)
60+EVIDENCE: /tmp/ours_mode4.txt vs /tmp/orc_mode.txt | same stream, EC_MODE ladders diffed line for line | ours "EC_MODE mi_row=6 mi_col=14 rng=33349" vs oracle "rng=36254" -- entropy divergence inside block (6,12); before the fixes the stream refused outright ("a partition below 8x8"), it now decodes 4 frames without a refusal but is NOT pixel-exact
61+
62+## Refusals
63+
64+- narrowed: "an inter partition below 16x16 (8x8 and smaller inter blocks are not
65+ coded yet)" -> "... other than SPLIT (16x8/8x16 rect inter leaves are not coded
66+ yet)". **This narrowing is NOT yet backed by a green gate** -- honest status,
67+ and the reason this branch must not merge as-is.
68+- untouched: SB-level non-NONE/SPLIT, the 32x32 alphabet refusal (`value=9`,
69+ `PARTITION_VERT_4`, which aomenc emitted at 32x32 even with
70+ `--enable-1to4-partitions=0` -- same shape as lane-sbpart r2's AB-at-64 note),
71+ the 16x16 true-edge rectangular-transform one, the 8x8 chroma-mode one.
72+
73+## Open residue
74+
75+- fix-now (next round): `Neighbours`' `above_*`/`left_*` arrays are 16x16
76+ granular. Leaf (6,12)'s LEFT neighbour must be leaf (6,10) of the previous
77+ 16x16 block, but both leaf rows of a 16x16 share one array slot, so one of
78+ them is always wrong. Making those arrays mi-granular (or adding a per-mi
79+ side band for skip/inter/ref0/ref1) is the next slice, and it is what
80+ un-ignores the two gates above.
81+- deferred(the above): 8x8 HORZ/VERT -> 8x4/4x8 leaves, rect inter MC/transforms
82+ at 16x8/8x16 (lane-rectx owns the transform half), AB/1-to-4 at 64/32/16, and
83+ the aggregate per-type-per-level hit-counter gate the charter asks for. None
84+ of these were started this round.
85+- deferred(unknown): the 10-bit variant of the same recipe stopped at
86+ "a reference frame other than LAST_FRAME (round 2)" at `--min-partition-size=8
87+ --max-partition-size=64` before the max was clamped to 16; not re-measured.
lanes/inter8-r2.report.mdadded+88 -0
@@ -0,0 +1,88 @@
1+# lane-inter8 r2 -- mi-granular inter neighbour bands; the 8-bit 8x8-split gate is GREEN
2+
3+Branch `lane-inter8`, commit `ae69b25` on top of r1's `b2231a9` (off main `3808cf8`,
4+not rebased -- the orchestrator merges).
5+
6+## What changed (`crates/ec-av1/src/decode.rs`, `crates/ec-av1/src/stream.rs`)
7+
8+1. **`Neighbours`' inter side bands are mi(4px)-granular** (`decode.rs` ~1910 `new`,
9+ ~1975 `start_tile`, `record_inter_rect` -> new `record_inter_rect_mi` ~2300,
10+ `record_compound_ctx_rect` -> `record_compound_ctx_rect_mi` ~2389; every reader
11+ now indexes `[cmi]`/`[rmi]`). Fields: `above/left_skip`, `_skip_mode`, `_inter`,
12+ `_ref`, `_ref1`, `_comp_group_idx`, `_compound_idx`, `_filter`. The SUB-unit
13+ wrappers stay, so every 16x16+ caller reads exactly what it read before (a
14+ SUB-aligned block's mi corner is libaom's `above_mbmi = mi(mi_row-1, mi_col)`).
15+ r1's `prev_leaves` sibling-override is deleted: each leaf stamps its own 2x2-mi
16+ span in the caller loop (`decode.rs` ~12664) right after it decodes, so a leaf's
17+ left neighbour can now be the *previous 16x16 block's* bottom leaf.
18+2. **The compound arm of `decode_inter_block8` returned before its own
19+ `record_mi`/`fill_lf_grid`** (`decode.rs` ~11353). The single-ref arm falls
20+ through to them at the end of the function; the compound arm did not. Every leaf
21+ of the gate's stream is compound (LAST+ALTREF), so a split 16x16 left
22+ `above_side_mi` at 16 and the *next* block's coefficient level state and lf grid
23+ describing whatever block was there before. Consequence: the 16x16 at mi(8,12)
24+ computed partition ctx **0** where aomdec had **1** and read `PARTITION_NONE`
25+ where the stream coded `PARTITION_SPLIT`.
26+3. **`get_comp_group_idx_context` / `get_comp_index_context` took the leaf's
27+ ENCLOSING 16x16 corner** (`outer_at`). Both now take mi coordinates
28+ (`decode.rs` ~8558/~8572) and the leaf passes `leaf_mi`; `decode_inter_block`
29+ passes its own `(rmi, cmi)`. This was the last divergence (block mi(8,14)).
30+4. `tpl_frame` threaded into the leaf's two mv stacks (`decode_inter_block8` new
31+ last param + `comp_tpl`/`tpl` builds mirroring `decode_inter_block`). Alignment
32+ only -- **it did not move this stream's ladder** (no `use_ref_frame_mvs` here);
33+ kept because passing `None` while the level above passes the field is a real
34+ parsed-then-discarded gap.
35+
36+All three of 1-3 are class `context-read-from-one-cell`.
37+
38+## Gate
39+
40+ cd <worktree>; export CARGO_TARGET_DIR=$HOME/.cache/cargo-target-inter8 EC_AV1_REQUIRE_AOMENC=1
41+ cargo test -p ec-av1 --lib -- an_8x8_leaf_split
42+
43+`a_real_aomenc_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact` **ok**
44+(un-ignored). It hard-asserts `decode::inter_sub16_split_hits` advanced (interior
45+16x16 `PARTITION_SPLIT` fired) and every one of the 4 frames pixel-exact vs ffmpeg;
46+a refusal or a mismatch panics, it never SKIPs.
47+
48+EVIDENCE: /tmp/r2-fix.obu (aomenc mandelbrot 64x64 4 frames cq40 cpu0 --min-partition-size=8 --max-partition-size=16, rect/AB/1to4 off) | ours EC_TRACE_MODE vs instrumented aomdec EC_TRACE_MODE, `EC_MODE` ladders diffed line for line | inter mode-info range ladder 42/57 (r1) -> 48/57 (bands mi-granular) -> 50/57 (compound-arm record) -> **57/57**, and the gate decodes 4/4 frames pixel-exact
49+EVIDENCE: /tmp/orc_r2.txt (aomdec EC_TRACE=1 EC_TRACE_MODE=1 on the same stream) | `EC_PART mi_row=8 mi_col=12 bsize=6 ctx=5 rng=38329` / `EC_PART_VAL ... value=3` vs our `TRACE partition_w16 mi=(8,12) ctx=0 value=0` before fix 2 | partition context 0 vs 1 at the block below a split 16x16 -- the stale `above_side_mi`
50+EVIDENCE: /tmp/orc10.txt (aomdec EC_TRACE=1 on the 10-bit pinned stream) | `grep EC_PART_VAL | uniq -c` | 16 `bsize=9 value=3`, **zero** `value=9` anywhere in the stream
51+
52+## Test totals
53+
54+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` -> **270 passed, 0 failed,
55+24 ignored** (1100 s). `refusal_inventory` and `gate_coverage` green; neither
56+needed an edit -- r1 already listed the narrowed string, and no gate recipe flag
57+changed.
58+
59+## Refusals
60+
61+- No new narrowing this round. r1's narrowing
62+ `"an inter partition below 16x16 other than SPLIT (16x8/8x16 rect inter leaves are not coded yet)"`
63+ is now **backed by a green gate** (it was not at r1), which is what this round owed.
64+- Disproved, not a refusal change: the r1 ledger dead-end
65+ `"aomenc emits PARTITION_VERT_4 (value=9) at 32x32 even with --enable-1to4-partitions=0"`
66+ is wrong. `EC_TRACE=1 aomdec` on the very stream that produced it reads no
67+ `value=9` at any bsize. Class `refusal-from-own-desync`.
68+
69+## Open residue
70+
71+- fix-now(next round): the **10-bit twin** `a_real_aomenc_10bit_inter_sequence_with_an_8x8_leaf_split_decodes_pixel_exact`
72+ stays `#[ignore]`d with the corrected reason. It refuses with "an INTER 32x32
73+ partition type this decoder does not code (value=9)", which the oracle trace above
74+ proves is our own desync, not the encoder. Not bisected: start by diffing the
75+ `EC_MODE` ladder of `/tmp/a_real_aomenc_10bit_..._-refused.obu` against
76+ `EC_TRACE_MODE=1 aomdec`, exactly as this round did for 8-bit.
77+- deferred(lane-gmaffine merge): the per-leaf stamp records `[3, 3]` ("no info") for
78+ the leaf's interp filter, as r1's whole-16x16 stamp did. lane-gmaffine `65ef3f5`
79+ makes `decode_inter_block8` read and hand back its real filter symbols; at merge,
80+ that value goes into the `record_inter_rect_mi(leaf_mi, 2, 2, ..., [3, 3], ...)`
81+ call at `decode.rs` ~12664. **Merge warning**: lane-gmaffine rewrites large parts
82+ of the same `decode_inter_block8` (GLOBALMV/WARPED_CAUSAL/non-LAST refs/interp
83+ filter); this branch's leaf edits are the neighbour/context plumbing only, but the
84+ two WILL conflict textually in that function.
85+- deferred(unstarted): 8x8 HORZ/VERT -> 8x4/4x8 leaves, rect inter leaves at
86+ 16x8/8x16, AB/1-to-4 at every level, and the per-type-per-level aggregate
87+ hit-counter gate.
88+- accepted: `tpl_frame` in the leaf stacks is unmeasured on this stream (item 4).
lanes/part32-r1.report.mdadded+117 -0
@@ -0,0 +1,117 @@
1+# lane-part32 r1 report
2+
3+## What landed
4+
5+`crates/ec-av1/src/decode.rs`: the INTRA 32x32 dispatch (key-frame tile path,
6+the one that previously hit `"a 32x32 partition type this decoder does not
7+code (value={part32})"`) now handles `PARTITION_HORZ_A` (4), `PARTITION_HORZ_B`
8+(5), `PARTITION_VERT_A` (6), `PARTITION_VERT_B` (7) -- mirrors cd6cb6d's INTER
9+AB arms exactly, using `decode_block` (square 16x16, `TxbSet::Luma16`/
10+`Chroma8`) for the two square sub-blocks and `decode_block_rect` (32x16 or
11+16x32) for the strip. The catch-all refusal is unchanged text but now only
12+reached for `PARTITION_HORZ_4`/`PARTITION_VERT_4` (values 8/9) -- narrowed by
13+construction, not by editing the string (still pinned as-is in
14+`refusal_inventory.rs`, no change needed there since the text is identical).
15+
16+Four new thread-local hit counters (`intra_horz_a_hits`/`intra_horz_b_hits`/
17+`intra_vert_a_hits`/`intra_vert_b_hits`), one per arm, mirroring
18+`PARTAB_HITS`'s pattern but split so a recipe that only ever fires one arm
19+can't hide behind a shared total.
20+
21+## Gate
22+
23+`crates/ec-av1/src/stream.rs::a_real_aomenc_intra_stream_with_ab_partitions_decodes_pixel_exact`
24+-- single key frame, 64x64, `mandelbrot` content (same recipe shape as the
25+existing `a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact`),
26+`--min-partition-size=16 --max-partition-size=32` (same bound lane-partab used
27+to stay below the still-unlanded SB(64)-level AB territory), 40 attempts.
28+Forbids the four `value={4,5,6,7}` intra refusal strings once reached, hard-
29+asserts all four per-arm counters > 0.
30+
31+**PASSES**, `EC_AV1_REQUIRE_AOMENC=1` included:
32+
33+```
34+a_real_aomenc_intra_stream_with_ab_partitions_decodes_pixel_exact:
35+0 named refusals, 40 pixel-exact matches out of 40,
36+horz_a=34 horz_b=45 vert_a=15 vert_b=18
37+```
38+
39+EVIDENCE: `cargo test -p ec-av1 --lib a_real_aomenc_intra_stream_with_ab_partitions_decodes_pixel_exact -- --nocapture`
40+(with and without `EC_AV1_REQUIRE_AOMENC=1`) | both runs above | 40/40 pixel-exact, all 4 counters nonzero.
41+
42+## Suite: NOT fully green -- one PRE-EXISTING failure exposed, out of this
43+## lane's scope
44+
45+`cargo test -p ec-av1 --lib`: **264 passed, 1 failed** (19 ignored), 208s.
46+
47+Failure: `stream::tests::a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`,
48+seed 42, first luma mismatch at (row=0, col=91), inside superblock (0,1)'s
49+`PARTITION_VERT`-at-64 arm (`decode_block_rect64`, lane-sbpart territory --
50+mode=DC_PRED, all_zero=1, off by one: got=80 want=81).
51+
52+Root-cause isolation done this round:
53+- Confirmed with `git checkout 21a71ec -- decode.rs stream.rs` (temporary,
54+ reverted) that this exact seed/recipe/byte-for-byte stream **already
55+ refused** on main at `"a 32x32 partition type this decoder does not code
56+ (value=4)"` -- inside superblock (1,1), which decodes strictly *after*
57+ superblock (0,1) in tile order. Entropy decoding is causal: nothing this
58+ lane touched can change how SB(0,1) is decoded, since SB(0,1) is decoded
59+ and its pixels finalized before the stream ever reaches the part32 AB
60+ symbol this lane added.
61+- This is the "refusal hides a defect" class already in the ledger
62+ (`refusal-hides-a-defect.md`): the sbpart gate's `matched > 0` assertion
63+ only ever checked pixels on attempts that decoded *end to end*; every
64+ attempt that hit a downstream refusal (including this exact seed, before
65+ this lane) never had its earlier SB(0,1) pixels compared at all. Lifting
66+ the part32 refusal let decode run to completion for seed 42, and the
67+ frame-level pixel compare then found a pre-existing `decode_block_rect64`
68+ defect for the first time.
69+- Not investigated further (turn budget): whatever's wrong in the
70+ 32x64/64x32 rect-64 corner-truncated intra path is `decode_block_rect64`'s
71+ own bug, unrelated to `decode_block`/`decode_block_rect` (this lane's
72+ functions) and to the AB dispatch. It belongs to lane-sbpart, not
73+ lane-part32.
74+
75+Per this repo's own rule ("Landing red ON THE LANE is fine -- I do the merges
76+to main and I never merge red"), HEAD is committed red with this failure
77+named. **Do not merge without either (a) fixing `decode_block_rect64`'s
78+DC-prediction/edge bug (a lane-sbpart-shaped charter, not part32's) or (b) an
79+explicit call that this newly-exposed defect is acceptable to carry
80+forward.**
81+
82+`cargo check --workspace --all-targets`: clean.
83+
84+## ReelC extract
85+
86+Cut `fixtures/part32/reelc-extract.obu` (gitignored) via
87+`ffmpeg -ss 600 -t 2 -c:v copy -an -f obu -bsf:v extract_extradata` from
88+`~/Videos/Films/reelc.mkv`.
89+`cargo run -p ec-av1 --example decode_probe -- fixtures/part32/reelc-extract.obu`:
90+
91+```
92+REFUSED: unsupported: AV1 decode_stream (a stream whose bit depth is not 8
93+(this decoder reconstructs into 8-bit planes))
94+```
95+
96+No longer stops at the part32 refusal (charter's predicted outcome: ReelC is
97+10-bit and hits the bit-depth wall first, per `his-av1-library-is-10-bit.md`).
98+
99+EVIDENCE: `cargo run -p ec-av1 --example decode_probe -- fixtures/part32/reelc-extract.obu`
100+| ran against a real 2s ReelC extract at ~10min mark | output above.
101+
102+## HEAD
103+
104+`69eeb6e` -- "wip(part32): intra 32x32 AB arms (HORZ_A/HORZ_B/VERT_A/VERT_B)
105+decode, gated 40/40 pixel-exact, all 4 hit counters fire"
106+
107+## Open
108+
109+- `HORZ_4`/`VERT_4` (values 8/9) not attempted this round; refusal still
110+ names them (unmodified string, now only reachable for those two values).
111+ Not reached by any gate recipe tried, reachability unknown.
112+- The `decode_block_rect64` DC-prediction/edge defect above is the actual
113+ blocker for a fully green suite. It is NOT part32's code and needs its own
114+ lane/charter (lane-sbpart shaped) to isolate and fix.
115+- `--cq-level=45`/`--enable-tx-size-search=0` etc kept identical to
116+ lane-partab's proven recipe; not swept for a lower-cq/higher-fidelity
117+ variant.
lanes/part32-r2.report.mdadded+107 -0
@@ -0,0 +1,107 @@
1+# lane-part32 round 2
2+
3+## State: NOT DONE, red, committed (4bff66c)
4+
5+Charter: fix decode_block_rect64's pre-existing pixel mismatch exposed by
6+round 1's refusal lift.
7+
8+## True mismatch geometry (measured on THIS tree, not inherited)
9+
10+Reproduced live: `cargo test -p ec-av1 --lib
11+a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`
12+-> 266 passed, 1 failed, matches the trial-merge count I was handed.
13+
14+Pinned the mismatching seed-42 stream via `EC_AV1_GATE_DUMP`, added an
15+`#[ignore]`d debug test (`debug_part32_r2_sbpart_pin_mismatch_geometry`,
16+`stream.rs`) that decodes it and prints exact per-pixel diffs.
17+
18+- Full-frame post-filter comparison against ffmpeg: 17873/24576 luma pixels
19+ differ, spanning the entire frame past x=91,y=0. This is NOT a single
20+ off-by-one -- it's a cascade: once one block's pixels are wrong, every
21+ block that intra-predicts from it downstream inherits and compounds the
22+ error, eventually corrupting nearly all of SB row 1 (y>=64).
23+- Root of the cascade, isolated via aom-oracle's `EC_AV1_PREFILT_DUMP` rung
24+ (pre-loop-filter ground truth) plus two new env-gated bypasses
25+ (`EC_AV1_DEBUG_SKIP_DEBLOCK`/`_CDEF`, off by default) on our side: our own
26+ PRE-FILTER reconstruction matches the oracle's pre-filter output exactly
27+ through SB(1,0)'s first VERT-64 sub-block (mi_c=16..23, all-zero DC,
28+ correct). The very first wrong pixel is (96,0) -- the first pixel of the
29+ SECOND VERT-64 sub-block (mi_c=24..31, real coefficients, eob_nonzero=true):
30+ oracle=81, ours=76.
31+
32+## Entropy layer: DIVERGES, inside this exact block
33+
34+Compared msac RANGE (never `tell()`) against the aom-oracle's `EC_TRACE_COEFF`
35+rung, element by element:
36+- Ranges agree exactly up through `rng=63764` at the entry to this block's
37+ luma coefficient read (`EC_COEFF plane=0 ... tx_size=64corner/11
38+ rng=63764` on both sides).
39+- Both sides read `eob=6` (agreement).
40+- The oracle's per-step trace assigns nonzero level=1 at scan indices
41+ 0, 1, 2, 4, 5 (skipping 3). Ours (`scan32 = default_scan(TX32)`, a plain
42+ square 32x32 scan) walks physical positions (0,0)(0,1)(1,0)(2,0)(1,1)(0,2)
43+ for the same six scan indices -- a different position-to-index mapping
44+ than whatever the oracle used.
45+- Post-block range: ours=37896, oracle=46344. Diverged.
46+
47+Conclusion: this is a genuine in-block entropy desync (wrong scan table),
48+not a post-processing (deblock/CDEF, both proven innocent by disabling them)
49+and not a dequant/reconstruction-only bug.
50+
51+## Root cause (identified, not yet fixed)
52+
53+`decode_block_rect64` (crates/ec-av1/src/decode.rs:3559) reads the luma
54+corner with `scan32 = default_scan(TX32)` -- the square TX_32X32 scan --
55+for BOTH genuine square 64x64 blocks and truncated-corner VERT-64/HORZ-64
56+strips (bw=32,bh=64 or bw=64,bh=32). The function's own doc comment already
57+documents an analogous, already-fixed asymmetry for the nz_map *context*
58+table (`NZ_MAP_CTX_OFFSET_32X64`/`_64X32`, lane-sbpart r8) but the *scan
59+order itself* was never given the same treatment. AV1 spec names a distinct
60+Default_Scan_32x64/64x32 table (libaom `av1_scan_orders[TX_32X64]` /
61+`[TX_64X32]`), and this decoder does not have it.
62+
63+Same shape as this repo's existing `table-indexed-by-raw-size` and
64+`scan-weights-cross-axis` ledger classes.
65+
66+## Fix NOT landed this round
67+
68+Turn budget spent entirely on localization (per charter's own step-2
69+instruction, "if ranges diverge, that's decisive"). Porting a correct
70+1024-entry SCAN_32X64/SCAN_64X32 table from libaom and wiring it in at the
71+`decode_block_rect64` call site (mirroring how `chroma_scan` already
72+branches on `bw == 64` a few lines below) is the next round's whole job --
73+should be mechanical once the table exists, but deriving/verifying a new
74+1024-entry table safely needs its own round, not the tail end of this one.
75+
76+## Gates
77+
78+- Part32's own AB gate (round 1's):
79+ `a_real_aomenc_intra_stream_with_ab_partitions_decodes_pixel_exact` --
80+ not re-run this round (untouched by this round's changes; round 1 already
81+ proved it 40/40 and this round made zero changes to part32's own code
82+ paths).
83+- Target gate
84+ (`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`):
85+ still RED, root cause pinned, fix not landed.
86+- `cargo check --workspace --all-targets`: clean.
87+- Full `cargo test -p ec-av1 --lib` NOT re-run this round after the debug
88+ additions (both are `#[ignore]`d / env-gated no-ops by default; the only
89+ change to non-test code is the two early-return guards in
90+ `apply_deblock`/`apply_cdef`, both env-gated and off by default -- zero
91+ behavior change verified by the identical `cargo check` above).
92+
93+## rect64q contradiction: explained
94+
95+lane-rect64q's own reproduction (row0 col91=81, matching ffmpeg, no
96+mismatch) used a stream from ITS OWN worktree, which did not have this
97+lane's AB arms and so took a genuinely different aomenc encode (different
98+partition decisions entirely) -- not a contradiction of this round's
99+finding, a different stream. This round's own pinned stream, decoded fresh
100+on this tree, reproduces the failure deterministically and traces to a real,
101+narrow, named defect (wrong scan table for TX_32X64/TX_64X32 corner-truncated
102+luma).
103+
104+## HEAD
105+
106+`4bff66c` -- "wip(part32): pin decode_block_rect64's block2 defect to a
107+scan-table mismatch"
lanes/part32-r5.report.mdadded+137 -0
@@ -0,0 +1,137 @@
1+# lane-part32 r5 — SB-level AB partitions at 64x64, proven arm by arm
2+
3+Branch `lane-part32`, commit `fd1a2eb` on top of r4's WIP snapshot `25cac7d`
4+(itself rebased on main `3808cf8`).
5+
6+## What r4 actually left (verified, not assumed)
7+
8+r4's last words claimed SB-level HORZ/VERT 64 was green. It was not: with
9+`EC_AV1_REQUIRE_AOMENC=1` both
10+`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`
11+and its new `..._ab_partition_...` sibling FAILED on seed 63 (luma mismatch,
12+`test result: FAILED. 0 passed; 2 failed`). r4's two real fixes —
13+`EOB_PT_512_CHROMA` q-context split (`cdf.rs:269`, `cdf_state.rs:1013`) and
14+the four AB arms in `decode.rs` — were correct but incomplete.
15+
16+## Root cause found and fixed this round
17+
18+`PARTITION_VERT_A`/`_B` visit their square sub-blocks **TL, BL, TR, BR**, not
19+in raster order, so the bottom-left square's top-right neighbour is the
20+partition's own right-hand rectangle — not yet decoded. libaom switches
21+`has_top_right`/`has_bottom_left` onto `has_tr_vert_*`/`has_bl_vert_*` for
22+exactly these two partition types (`reconintra.c` `get_has_tr_table`,
23+`get_has_bl_table`). This crate's `Reach` carried only the raster tables:
24+for the BL 32x32 (blk_row_in_sb=1, blk_col_in_sb=0, bit index 4)
25+`has_tr_32x32[0]=95` bit 4 = **1** while `has_tr_vert_32x32[0]=15` bit 4 = **0**.
26+One availability bit → 4683 wrong luma pixels.
27+
28+Failure chain on the pinned stream: BL square predicts (V_PRED, angle_delta=2)
29+off never-written above-right samples → its right columns decay
30+(150,150,150 → 130,93,39 at x=157..159) → the 32x64 strip to its right
31+DC-predicts off that corrupted left column and comes out flat **107** instead
32+of ~149 → the next superblock row's V_PRED copies 107 down the whole frame.
33+
34+Decisive evidence that this was reconstruction, not entropy: instrumented
35+`aomdec` (`EC_TRACE=1 EC_TRACE_MODE=1`) agrees with us on every symbol —
36+`EC_PART_VAL mi_row=0 mi_col=32 value=6` (VERT_A), every `EC_IMODE_VAL`
37+mode/uv_mode, and the msac **range** at `mi_row=0 mi_col=40` is `53240` in
38+both decoders (ours: `TRACE_RECT_PREFI ... rng=53240`).
39+
40+## Files changed
41+
42+- `crates/ec-av1/src/encode.rs:1049` — `HAS_TOP_RIGHT_VERT` /
43+ `HAS_BOTTOM_LEFT_VERT` transcribed verbatim from libaom
44+ (`has_tr_vert_8x8/16x16/32x32`, `has_bl_vert_*`), a `VERT_AB_PARTITION`
45+ thread-local + `VertAbGuard`, `Reach::vert_ab_partition()`, and the table
46+ pick inside `top_right`/`bottom_left`. Rect sub-blocks deliberately keep
47+ the non-vert tables (libaom's own comment) — `Reach::of_rect` untouched.
48+- `crates/ec-av1/src/decode.rs:7535,7610` — the 32x32-level intra VERT_A/VERT_B
49+ arms take the guard (same defect one level down, swept in the same round).
50+- `crates/ec-av1/src/decode.rs:7766` — the SB-level AB arm takes it only for
51+ the two vertical arms.
52+- `crates/ec-av1/src/decode.rs:13432,13595` — the two inter AB VERT arms take
53+ it too (class sweep; inter intra-mode blocks read the same `Reach`).
54+- `crates/ec-av1/src/decode.rs:767,772` — `SB_AB_HITS` is now `[usize; 4]`,
55+ incremented by arm, with `sb_ab_hits_by_arm()`.
56+- `crates/ec-av1/src/stream.rs:9665` — the AB gate hard-asserts **each** of
57+ HORZ_A/HORZ_B/VERT_A/VERT_B fired, not just the sum.
58+- `crates/ec-av1/src/stream.rs:9467,9628` — both gates' stale r2 comment
59+ ("AB-at-64 is a different, unlanded capability") replaced with the r5 truth.
60+- `crates/ec-av1/src/refusal_inventory.rs:50` — (r4) the refusal is now
61+ narrowed to the 1:4 pair only. `gate_coverage.rs` needed no edit:
62+ `--enable-ab-partitions=1` is now positively exercised and the flag was
63+ never on `NEVER_EXERCISED`; both its tests are green in the run below.
64+
65+## Gates
66+
67+```
68+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-part32 EC_AV1_REQUIRE_AOMENC=1 \
69+ cargo test -p ec-av1 --lib -- --test-threads=1 --nocapture superblock_level
70+```
71+`test result: ok. 2 passed; 0 failed; 1 ignored` (was 0 passed; 2 failed).
72+
73+EVIDENCE: /tmp/.../scratchpad/r5gate.txt, r5ab.txt | 40 real-aomenc streams per gate, `--sb-size=64 --enable-rect-partitions=1 --enable-ab-partitions=1`, seeds 42..81, decoded and compared to ffmpeg | ab gate 37 pixel-exact / 3 named refusals, `sb_ab_hits=13 arms(HORZ_A,HORZ_B,VERT_A,VERT_B)=[2, 5, 3, 3]`; horz/vert gate 37 pixel-exact, `sb_rect_hits=61`
74+
75+EVIDENCE: /tmp/.../scratchpad/r5full.txt | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` | `test result: ok. 269 passed; 0 failed; 24 ignored; 0 measured` in 1094s
76+
77+EVIDENCE: /tmp/.../scratchpad/pre63o.f0 vs our63_nf.y | oracle `EC_AV1_PREFILT_DUMP` vs ours with deblock+CDEF disabled, on the pinned seed-63 stream (pre-fix) | 4683 luma samples differ, bbox x=[151,191] y=[0,127]; post-fix the gate is pixel-exact
78+
79+## Refusal lifted
80+
81+`"a superblock-level partition type other than NONE or SPLIT (this decoder's
82+intra tile path codes only those two at 64x64)"` → replaced by
83+`"a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, four
84+64x16/16x64 strips)"`. HORZ/VERT/HORZ_A/HORZ_B/VERT_A/VERT_B at 64x64 are all
85+now real-stream-proven.
86+
87+## Film check
88+
89+`ffmpeg -t 0.4 -i ReelC...mkv -c:v copy -f obu reelc_r5.obu` (418 B), then
90+`cargo run -p ec-av1 --example decode_probe -- reelc_r5.obu`:
91+
92+```
93+REFUSED: unsupported: AV1 tile (filter intra on a HORZ/VERT strip (this decoder predicts square-only))
94+```
95+
96+ReelC reaches an SB-level HORZ/VERT strip and now stops on filter-intra-on-a-strip.
97+deferred: the matching "before" probe on main `3808cf8` — not re-measured this
98+round (would need a full rebuild of a second target dir at the turn ceiling);
99+unblocked by any lane that already has a main-based build of `decode_probe`.
100+
101+## Coordinator's two facts, answered
102+
103+1. **rectsplit seed 50 / `decode_block_rect64` split-transform residual** — NOT
104+ fixed here; my change never runs for a HORZ/VERT strip (the guard is set
105+ only under VERT_A/_B, and rect blocks go through `Reach::of_rect`, which is
106+ untouched). But the hypothesis is now concrete and shares this round's
107+ class: `decode.rs:5099` and `decode.rs:5425` compute per-TU availability as
108+ `Reach::of(logical_tx, tu_px, tu_py, ...)` — i.e. they treat the transform
109+ unit as if it were a *block at frame coordinates* and consult the
110+ superblock-position table. libaom does not: in `has_top_right`, when
111+ `row_off > 0` it never reaches a table at all, it returns
112+ `col_off + tx_size_wide_unit < plane_bw_unit` — purely block-relative. For
113+ a depth-2 TX_16X16 inside a 64x32 strip that is exactly the sub-TU at
114+ `row_off > 0` case. That is where I would look first for the (171,56)
115+ 147-vs-148 sample. `rectsplit` keeps ownership.
116+2. **scaledref's masked Golomb defect at seed 67** — appears RESOLVED on this
117+ branch. Both r5 gate runs cover seeds 42..81; the only refusals were seeds
118+ 45/46/59 (screen-content palette strip), and seed 67 decoded **pixel-exact
119+ against ffmpeg**, which is stronger than "no Golomb refusal". Most likely
120+ killed by r4's `EOB_PT_512_CHROMA` q-context fix, with this round's
121+ availability fix removing the seed-63 sibling. scaledref should re-run with
122+ the raised cap after merge; if it still reproduces, the cause is elsewhere.
123+
124+## Residue
125+
126+- fix-now(next lane): `PARTITION_HORZ_4`/`VERT_4` at 64x64 — still refused by
127+ name. Not attempted: `decode_block_rect64` is hardwired to 64x32/32x64
128+ (`TxbSet::Luma64` + `TX32` scan for luma, `ChromaRect32x16` + `SCAN_32X16/
129+ 16X32` for chroma, `decode.rs:3846-3990`); a 64x16 strip needs a real
130+ TX_64X16 luma transform plus 32x8 chroma scans/EOB tables, which is a
131+ transform-primitive lane, not a partition-wiring one.
132+- accepted: `Reach::table(64)` maps to the 16x16 table row (pre-existing);
133+ harmless because a 64x64 block in a 64 superblock always takes the
134+ `row == 0` early return before any table is read.
135+- accepted: the per-TU `Reach::of` shape described above is left to rectsplit
136+ rather than fixed blind here, since every gate on this branch is green and a
137+ speculative change to it would risk them.
lanes/part32-r6.report.mdadded+89 -0
@@ -0,0 +1,89 @@
1+# lane-part32 r6 — the 16x16-level VERT_B arm was the one AB site r5 missed
2+
3+Branch `lane-part32`, on top of r5 `02dbbd6`.
4+
5+## Class sweep: every VERT_A/VERT_B site in decode.rs
6+
7+`grep -n "PARTITION_VERT_A\|PARTITION_VERT_B" crates/ec-av1/src/decode.rs`, all
8+levels, intra and inter:
9+
10+| site | level | path | guard at r5 |
11+|---|---|---|---|
12+| `decode.rs:7008` | 16 | intra VERT_B (8x16 rect + TR/BR 8x8 `decode_leaf8`) | **MISSING — fixed this round** |
13+| `decode.rs:7538/7612` | 32 | intra VERT_A / VERT_B | present (r5) |
14+| `decode.rs:7779` | 64 (SB) | AB arm, vert arms only | present (r5) |
15+| `decode.rs:13445/13606` | 32 | inter VERT_A / VERT_B | present (r5) |
16+
17+No other site exists: the 16-level inter path has no AB arms (they are refused by
18+name, "a HORZ_A/HORZ_B/VERT_A partition below 16x16"), and 8-level partitions
19+below that are SPLIT-only. So one missed site, now guarded — the class is closed
20+for VERT_A/_B.
21+
22+The verifier's computation is confirmed exactly (checked bit by bit against the
23+transcribed tables in `encode.rs`): `has_bl_8x8` reads **0** where
24+`has_bl_vert_8x8` reads **1** at all 16 even-8x8-row / odd-8x8-column slots of a
25+superblock — that slot is precisely the TR square of a VERT_A/_B — so the TR
26+square's `below_left` was wrongly false for the bottom-left-reading directional
27+modes (angle > 180: `D203_PRED`, `D157_PRED` with a positive angle delta).
28+Mirror-image for `has_tr_8x8` vs `has_tr_vert_8x8` (1 -> 0) at odd-row /
29+even-column slots, which VERT_A/_B never visit at 8x8 (no BL square in either).
30+
31+## Files changed
32+
33+- `crates/ec-av1/src/decode.rs:7010` — the intra 16-level `PARTITION_VERT_B` arm
34+ takes `crate::encode::Reach::vert_ab_partition()` for the whole arm; the left
35+ 8x16 rect is unaffected by design (`Reach::of_rect`, libaom's own comment says
36+ vertical rectangles keep the non-vert table), the two `decode_leaf8` squares
37+ now read the vert tables.
38+- `crates/ec-av1/src/encode.rs:3565` — `vert_ab_partition_flips_below_left_for_the_top_right_8x8`,
39+ a table pin next to the existing libaom-availability test: all 16 TR slots flip
40+ `below_left` false -> true under the guard, every other slot is untouched, and
41+ the guard does not leak past its scope.
42+
43+## Gate: attempted, could not be built — the fix stays source-verified
44+
45+The charter's stream gate (a real-aomenc 16-level VERT_B, directional modes on,
46+decoded and compared pixel-exact) was written and run, and it cannot fire on this
47+aomenc build. Bounded sweep, all with
48+`--min-partition-size=8 --max-partition-size=16 --enable-rect-partitions=1
49+--enable-1to4-partitions=0 --enable-directional-intra=1 --enable-angle-delta=1
50+--cpu-used=0 --kf-max-dist=0 --passes=1`, 64x64 grey mandelbrot key frames:
51+
52+| recipe | attempts | decoded | refusals |
53+|---|---|---|---|
54+| cq=45, `--enable-ab-partitions=1` | 40 | 0 | 40 (below-16 HORZ_A/HORZ_B/VERT_A, or a coded non-skip rect strip below 16) |
55+| cq=45, ab={0,1} | 10 + 10 | 0 | 8 AB-below-16 + 2 coded-rect-strip, each |
56+| cq=63, ab={0,1} | 40 + 10 | all | none — but `partition_w16` never resolves to VERT_B (value=7): the frame stays at 16x16 NONE |
57+| cq={55,57,60}, mandelbrot / testsrc2 / cellauto | 12 | 3 | same two below-16 refusals |
58+
59+`EC_AV1_TRACE=1` `partition_w16` value histogram over every decoded stream: 0
60+occurrences of value=7 at any quality that decodes. Every stream that partitions
61+small enough to *reach* a 16-level VERT_B hits one of the two still-refused
62+below-16 capabilities first (HORZ_A/HORZ_B/VERT_A-below-16, coded rect strip
63+below-16), which abort the tile before the VERT_B arm. Writing a gate that
64+decodes only cq=63 streams would have been vacuous
65+(`gate-blind-to-feature`), so the sweep gate was **removed** rather than
66+committed green, and the pin above carries the fix instead.
67+
68+EVIDENCE: /tmp/.../scratchpad (r6 sweep, shell loop above) | 40+40+20+12 real aomenc encodes, `EC_AV1_TRACE=1 decode_probe` on each | 0 streams with `partition_w16 value=7`; at cq=45 40/40 refused with the two named below-16 refusals, at cq=63 50/50 decoded with 0 VERT_B
69+
70+EVIDENCE: `cargo test -p ec-av1 --lib -- vert_ab_partition_flips` | table pin of the guard at all 64 8x8 slots of an interior superblock | `test result: ok. 1 passed`; 16 TR slots flip false->true, 48 unchanged
71+
72+EVIDENCE: /tmp/.../scratchpad/r6full.txt | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` | `test result: ok. 270 passed; 0 failed; 24 ignored; 0 measured` in 1585s (269 before this round's new pin)
73+
74+## Refusals
75+
76+None lifted or added this round (the two below-16 refusals above are other
77+lanes'). `refusal_inventory` and `gate_coverage` unchanged and green in the run
78+above.
79+
80+## Residue
81+
82+- deferred(a lane that ports HORZ_A/HORZ_B/VERT_A below 16x16, or the coded
83+ non-skip rect strip below 16x16): the pixel-exact stream gate for the 16-level
84+ VERT_B arm. Both refusals fire before the arm on every recipe swept; once
85+ either lands, re-run the sweep in this report and the gate becomes writable
86+ as-is.
87+- accepted: the fix is source-verified + table-pinned, not stream-proven. It is a
88+ one-bit availability change of exactly the shape r5 proved by pixel comparison
89+ one level up (4683 wrong luma samples there).
lanes/rectsplit-r2.report.mdadded+89 -0
@@ -0,0 +1,89 @@
1+# lane-rectsplit r2 (gates run and reported by r3) — SB-level split-transform strips: r2's root cause DISPROVED
2+
3+Branch `lane-rectsplit` off main `3808cf8` (r1 `3627fe9` already merged). r2 was capped
4+before running any gate; its work is WIP `bf53652`. This round ran the gates, found that
5+r2's fix regresses a merged gate, and reverted the unsafe half.
6+
7+## Headline
8+
9+r2 claimed the root cause of r1's RED gate (b) was a transposed `av1_nz_map_ctx_offset`
10+read (`base_ctx`, `[row][col]` -> `[col][row]`). **Measured: that change turns gate (b)
11+green (20/20) and turns the MERGED gate
12+`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact` RED
13+(seed 43 luma mismatch).** All four index/shape combinations were run:
14+
15+| base_ctx TwoD rect read | SB HORZ/VERT partition gate (merged) | split-tx SB gate (b) |
16+| --- | --- | --- |
17+| `table(shape)[row][col]` (r1, shipped) | ok | FAILED (seed 50) |
18+| `table(shape)[col][row]` (r2's "fix") | FAILED (seed 43) | ok |
19+| `table(swap)[row][col]` | FAILED | FAILED |
20+| `table(swap)[col][row]` | FAILED | FAILED |
21+
22+So the offset read is NOT the defect: each variant only moves which rare corner position
23+desyncs. What is genuinely established (checked against the oracle source, not another
24+transcription): `av1_nz_map_ctx_offset_32x64` is a FLAT 1024-entry array whose `coeff_idx`
25+is COLUMN-major with stride 32 — entries 0..4 = 0,11,6,6,21 and 32..34 = 11,11,6 match
26+`txb_common.h:199-209`'s generating rule only as `flat[col * 32 + row]` — so the `cdf.rs`
27+5x5 transcriptions are `[col][row]`, while `base_ctx` indexes them `[row][col]` and is
28+green that way. The unproven quantity is therefore the ORIENTATION of `(row, col)` coming
29+out of the square 32x32-corner scan (`pos / side`, `pos % side` at `decode.rs:1583`)
30+relative to libaom's column-major `coeff_idx` — the `scan-weights-cross-axis` /
31+`reference-layout-not-spec` class. That is the next round's bisection.
32+
33+## State shipped on this branch (`89d4d59` + this commit)
34+
35+KEPT from r2's WIP:
36+- `stream.rs` gates (a)/(b)/(c): per-attempt counter sampling — a feature-hit delta is
37+ folded in only after that attempt decoded AND pixel-compared, so hits from a stream that
38+ later refuses can no longer make a gate pass vacuously (ledger dead-end). Gate (b) also
39+ asserts the new `decode::rect_split_sb_interior_tu_hits` (`bw.max(bh)==64 && bw/tx>1 &&
40+ bh/tx>1` = SB-level AND tx depth >= 2), which is what the verifier asked for.
41+- Mismatch reporting: mismatching-sample count + bbox.
42+- `decode.rs:3248`: the chroma-shape refusal is documented UNREACHABLE with both callers
43+ wired and KEPT as the shape guard (without it a new strip size panics on `expect`
44+ instead of refusing by name); it stays in `refusal_inventory::REFUSALS`.
45+- Gate (c)'s stale "competitors disabled" comment replaced by the measured reason they
46+ cannot be (competitors off -> 0 rect strips; `--cq-level=25` is what fires filter intra).
47+- `decode::tests::nz_map_ctx_offset_tables_match_the_rect_rule` — pins the `[col][row]`
48+ packing of both rect tables against `base_ctx_rect`'s independently-written rule. It is
49+ TRUE about the transcription and deliberately contradicts `base_ctx`'s read; that
50+ contradiction is the open defect, spelled out in `base_ctx`'s comment.
51+- `examples/decode_probe.rs` raw-I420 dump (2nd arg); `EC_NZOFF_DUMP=1` prints every
52+ rect-shaped nz_map read; `EC_SBPART_DUMP64=1` prints split-tx strips.
53+
54+REVERTED by r3 (unsafe):
55+- `base_ctx` back to the r1 `[row][col]` read (`decode.rs:1162` comment now records the
56+ four-way measurement instead of r2's claim).
57+- `decode_block_rect64` refusal "a superblock-level HORZ/VERT strip with a split transform
58+ (per-unit rect prediction is not ported)" RESTORED, re-added to `refusal_inventory.rs`.
59+- Gate (b) `#[ignore]`d again with the r3 reason.
60+
61+## Refusals lifted this round: NONE.
62+
63+## Evidence
64+
65+EVIDENCE: `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3 -- ...split_transform... ...superblock_level_horz_vert_partition... filter_intra_on_a_horz refusal_inventory gate_coverage nz_map_ctx_offset` on lane-rectsplit @ r3 final | 3 aomenc gates + the merged SB partition gate + inventory/coverage/table tests | 9 passed, 0 failed, 1 ignored (gate b), 53.77s
66+EVIDENCE: same command with `table[col][row]` (r2's WIP `bf53652`) | same gates | gate (b) ok (20/20 pixel-exact, SB-interior-TU delta=7), merged SB HORZ/VERT partition gate FAILED seed 43 — the regression that forced the revert
67+EVIDENCE: full `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib -j3` at r2's WIP state | whole crate lib | **270 passed, 1 failed, 23 ignored**, 1566.70s — the 1 failure is that merged gate. NOT re-run after the revert (turn cap): the reverted state restores r1's behaviour for every path plus one new unit test and one re-ignored gate, so 270 passed / 0 failed / 24 ignored is EXPECTED, not measured.
68+
69+## Film check (both films, 0.4s extracts)
70+
71+```
72+ffmpeg -v error -t 0.4 -i "<reelc.mkv>" -c:v copy -f obu reelc.obu # 418 bytes
73+ffmpeg -v error -t 0.4 -i "<reelb.mkv>" -c:v copy -f obu hg.obu # 1817 bytes
74+decode_probe reelc.obu -> REFUSED: AV1 tile (a 32x32 partition type this decoder does not code (value=4))
75+decode_probe hg.obu -> REFUSED: AV1 tile (a partition below 8x8 (this decoder codes no leaf smaller than 8x8))
76+```
77+
78+EVIDENCE: scratchpad `reelc.obu` (418 B) / `hg.obu` (1817 B) | `ffmpeg -t 0.4 -c:v copy -f obu` then `cargo run -p ec-av1 --example decode_probe` on this branch | neither film stops at a refusal this lane owns
79+
80+## Residue
81+
82+- fix-now(next round): the (row, col) orientation of the square 32x32-corner coefficient
83+ reader vs libaom's column-major `coeff_idx`. Repro both directions: seed 50 of gate (b)
84+ (`--ignored`) and seed 43 of the SB HORZ/VERT partition gate. Decisive instrument: msac
85+ RANGE ladder vs instrumented aomdec at the first differing coefficient of the 64x32 strip
86+ (r1 located it at luma (171,56), mi=(8,32)); `EC_NZOFF_DUMP=1` lists every candidate read.
87+- deferred(a below-16x16 strip gate — lane-sub8's territory): the `decode_leaf_rect` strip
88+ refusals.
89+- deferred(lane-sub8 / the 32x32 AB-partition arm): both films' first 0.4s.
lanes/sqchroma-r1.report.mdadded+90 -0
@@ -0,0 +1,90 @@
1+# lane-sqchroma r1 — the chartered square-path chroma defect does not reproduce
2+
3+## Verdict
4+
5+The charter's premise is FALSE at HEAD (f31a2c5). A plain SQUARE-partition intra key
6+frame with real chroma and aomenc's tx-size search left ON decodes **pixel-exact**, in
7+every recipe I could build around the chartered one, 8-bit and 10-bit. Nothing was
8+fixed because nothing was broken; what shipped is the missing gate that pins the
9+capability, and the removal of the stale `hue=s=0` guard the (wrong) premise put into
10+two live rect gates.
11+
12+## Reproduction attempt (the chartered recipe, exactly)
13+
14+`gradients_source(seed, 192x128, duration=0.04:rate=25)` -> `yuv420p` (NO `hue=s=0`) ->
15+aomenc `--cpu-used=0 --threads=1 --row-mt=0 --sb-size=64 --enable-rect-partitions=0
16+--enable-ab-partitions=0 --enable-1to4-partitions=0 --min-partition-size=16
17+--max-partition-size=32 --enable-restoration=0 --enable-palette=0 --deltaq-mode=0
18+--enable-filter-intra=0 --enable-cfl-intra=0 --enable-intrabc=0` (no
19+`--enable-tx-size-search=0`), decoded by `examples/decode_probe` and diffed plane by
20+plane against `ffmpeg -i s.obu -pix_fmt yuv420p -f rawvideo`.
21+
22+- seeds 42..61 at cq 45: 20/20 exact (Y=0 U=0 V=0 mismatching bytes).
23+- seeds 42..61 at cq 20: 20/20 exact.
24+- seed 42 (the charter's named seed) traced: `tx_depth != 0` fires 6 times, `uv_mode`
25+ takes values 0/1/2/5/11 -- the exact "luma tx_depth>0 with a non-DC uv_mode" pairing
26+ the defect was attributed to. Seed 55: 10 depth hits, uv_modes 0/2/7/12. Still exact.
27+- harder content, same square recipe, cq 12 and 32: `testsrc2`, `mandelbrot`,
28+ `smptebars`, `rgbtestsrc` -- 8/8 exact (streams up to 4 KB, i.e. real chroma residual).
29+- with `--enable-cfl-intra=1 --enable-filter-intra=1` (the CFL-under-split-luma
30+ candidate the charter names): testsrc2 + mandelbrot at cq 12/32, 4/4 exact.
31+- free partition tree (no min/max pin) + CFL: 5/6 exact, 1 named refusal
32+ (`HORZ_A/HORZ_B/VERT_A below 16x16` -- an unrelated, already-named refusal).
33+
34+So no divergence to localise: no EC_AV1_PREFILT_DUMP split, no EC_TRACE_COEFF ladder,
35+no lane-sub8 cherry-pick needed (`decode_block` already computes `smooth_neighbor_uv`
36+from `above_uv_mode`/`left_uv_mode` at decode.rs:5696 -- the square >=16 path never
37+passed `false`; only the leaf8/split4 paths did, and lane-sub8 r5 fixed those).
38+
39+Most likely origin of the premise: it was measured on the pre-merge lane-rectsplit
40+branch, not on main-with-everything-merged (main f31a2c5 carries lane-tiny, lane-seg,
41+lane-intrabc and the rectsplit merge itself), and it was recorded as fact in a comment
42+rather than re-checked. Class: my-charters-shipped-stale-premises.
43+
44+## What changed
45+
46+- `crates/ec-av1/src/decode.rs:735` — new `SQ_CHROMA_TX_HITS` counter + `sq_chroma_tx_hits()`;
47+ bumped at `decode.rs:5638` in `decode_block` when `tx_select && logical_tx < side &&
48+ uv_mode != DC_PRED` (square block whose luma transform split under a non-DC chroma mode).
49+- `crates/ec-av1/src/stream.rs:9924` — new gate
50+ `a_real_aomenc_intra_stream_with_tx_size_search_and_chroma_decodes_pixel_exact`.
51+- `crates/ec-av1/src/stream.rs` (3 sites) — `-vf hue=s=0` dropped from the two live rect
52+ gates and the ignored SB-strip gate; the stale "PRE-EXISTING square-path chroma defect"
53+ comments replaced with what was actually measured. Both live gates stay green with real
54+ chroma, so those gates now cover chroma too.
55+
56+## Gate
57+
58+`a_real_aomenc_intra_stream_with_tx_size_search_and_chroma_decodes_pixel_exact`:
59+square partitions only, tx-size search at aomenc's default (ON), real chroma, 10 8-bit
60+attempts (seeds 42..51, cq alternating 20/40) plus one 10-bit stream (`--bit-depth=10`,
61+sequence-header `bit_depth == 10` asserted before any pixel compare). Hits counted only
62+over attempts that decoded AND pixel-compared; `firing > 0` hard-asserted; a non-refusal
63+decode error or any pixel mismatch FAILS, only a missing tool SKIPs.
64+
65+```
66+CARGO_TARGET_DIR=$HOME/.cache/cargo-target-sqchroma EC_AV1_REQUIRE_AOMENC=1 \
67+ cargo test -p ec-av1 --lib a_real_aomenc_intra_stream_with_tx_size_search_and_chroma -- --nocapture
68+```
69+
70+EVIDENCE: gate stderr | 10 8-bit aomenc streams + 1 10-bit, decoded and diffed vs ffmpeg | `11 pixel-exact decodes (0 named refusals out of 10 8-bit attempts), split-tx-with-chroma blocks: 23 (10-bit stream: 2)` — test ok
71+EVIDENCE: scratchpad sweep.sh/src2.sh output | 40 gradient streams (seeds 42..61 at cq 45 and cq 20) + 12 testsrc2/mandelbrot/smptebars/rgbtestsrc streams, square-only recipe, decode_probe vs ffmpeg rawvideo | every plane Y=0 U=0 V=0 mismatching bytes
72+EVIDENCE: rectsplit gates with the hue filter removed | `cargo test -p ec-av1 --lib split_transform_horz_vert filter_intra_on_a_horz_vert_strip` | both ok (16 decoded seeds, split-tx delta 3; 30 matches, filter_intra_rect delta 9)
73+
74+## Suite
75+
76+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (worktree, target-sqchroma): **275 passed, 0 failed, 23 ignored** in 1647s.
77+
78+## Refusals
79+
80+None lifted (none were in the way -- the path already decodes). `refusal_inventory` and
81+`gate_coverage` untouched and green.
82+
83+## Residue
84+
85+- accepted: the charter's localisation plan (PREFILT dump, chroma tx_type derivation,
86+ CFL-under-split-luma, chroma edge-filter type) was not executed -- there is no
87+ divergence to localise. The tx_type/CFL rules were therefore NOT re-audited against
88+ libaom this round; if a real square chroma defect turns up later it is unexamined ground.
89+- deferred(rectsplit r2): `a_real_aomenc_stream_with_a_split_transform_superblock_strip_decodes_pixel_exact`
90+ stays `#[ignore]`d (measured RED on luma, seed 50) -- untouched by this lane beyond its comment.
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).
scripts/instrument-aom-oracle.shmodified+64 -0
@@ -641,3 +641,67 @@ s = s.replace(old4, new4, 1)
641 open(path, "w").write(s)641 open(path, "w").write(s)
642 print("decodetxb rung 11 (per-symbol coeff ladder) instrumented")642 print("decodetxb rung 11 (per-symbol coeff ladder) instrumented")
643 PYC11643 PYC11
644+
645+# --- rung 12: FINAL reconstruction dump (lane-hidden r1) ----------------
646+# EC_AV1_FINAL_DUMP=<prefix> -> <prefix>.f<N> per DECODED frame (decode order,
647+# hidden alt-ref frames included), written after CDEF + superres + loop
648+# restoration have all run, i.e. exactly the frame as it is stored into the
649+# reference buffer. Y then U then V, crop-sized rows (post-superres
650+# y_crop_width), 8-bit as u8 and high bitdepth as u16 LE -- bit-depth
651+# correct, unlike the u8-narrowing debug dumps.
652+#
653+# Rungs 1/6 (pre-filter / post-deblock) stop before CDEF+LR+superres, and
654+# every ffmpeg/aomdec pixel gate in this repo compares SHOWN frames only
655+# (class gate-blind-to-hidden-frames), so before this rung no instrument in
656+# the repo could compare a hidden frame's final pixels at all.
657+python3 - "$F" <<'PYF'
658+import sys
659+path = sys.argv[1]
660+s = open(path).read()
661+if "EC_INSTRUMENTED_FINAL" in s:
662+ print("final dump already instrumented (no-op)")
663+ sys.exit(0)
664+
665+anchor = """ if (!pbi->dcb.corrupted) {
666+ if (cm->features.refresh_frame_context == REFRESH_FRAME_CONTEXT_BACKWARD) {"""
667+dump = """ /* EC_INSTRUMENTED_FINAL */
668+ {
669+ const char *ec_dump = getenv("EC_AV1_FINAL_DUMP");
670+ if (ec_dump) {
671+ static int ec_final_idx = 0;
672+ char ec_path[1024];
673+ snprintf(ec_path, sizeof(ec_path), "%s.f%d", ec_dump, ec_final_idx++);
674+ FILE *ec_f = fopen(ec_path, "wb");
675+ if (ec_f) {
676+ const YV12_BUFFER_CONFIG *ec_b = &cm->cur_frame->buf;
677+ const int ec_hbd = (ec_b->flags & YV12_FLAG_HIGHBITDEPTH) != 0;
678+ const uint8_t *const ec_p8[3] = { ec_b->y_buffer, ec_b->u_buffer,
679+ ec_b->v_buffer };
680+ const int ec_st[3] = { ec_b->y_stride, ec_b->uv_stride,
681+ ec_b->uv_stride };
682+ const int ec_w[3] = { ec_b->y_crop_width, ec_b->uv_crop_width,
683+ ec_b->uv_crop_width };
684+ const int ec_h[3] = { ec_b->y_crop_height, ec_b->uv_crop_height,
685+ ec_b->uv_crop_height };
686+ for (int ec_pl = 0; ec_pl < (num_planes > 1 ? 3 : 1); ++ec_pl) {
687+ for (int ec_r = 0; ec_r < ec_h[ec_pl]; ++ec_r) {
688+ if (ec_hbd) {
689+ const uint16_t *ec_s = CONVERT_TO_SHORTPTR(ec_p8[ec_pl]);
690+ fwrite(ec_s + (size_t)ec_r * ec_st[ec_pl], 2, ec_w[ec_pl], ec_f);
691+ } else {
692+ fwrite(ec_p8[ec_pl] + (size_t)ec_r * ec_st[ec_pl], 1,
693+ ec_w[ec_pl], ec_f);
694+ }
695+ }
696+ }
697+ fclose(ec_f);
698+ }
699+ }
700+ }
701+
702+"""
703+assert anchor in s, "final dump anchor moved"
704+s = s.replace(anchor, dump + anchor, 1)
705+open(path, "w").write(s)
706+print("final dump instrumented")
707+PYF