forge
Explore
Log in

Don't you dare go Hollow

Eob_pt CDF kept no TX_CLASS_HORIZ/VERT row above 8x8 -- a V_DCT 16x16 var-tx leaf read the 2D table and desynced

Browse files at this commit

5ec09409a507fe40c3c4e1aa432b56d012167eb8Ahmet Kaan GümüşParent: af0f3fc
  • fix
    • eob_pt CDF kept no TX_CLASS_HORIZ/VERT row above 8x8 -- a V_DCT 16x16 var-tx leaf read the 2D table and desynced
Show full message
fix(av1): eob_pt CDF kept no TX_CLASS_HORIZ/VERT row above 8x8 -- a V_DCT 16x16 var-tx leaf read the 2D table and desynced

libaom picks eob_multi_ctx = (tx_class == TX_CLASS_2D) ? 0 : 1 at EVERY
eob_pt table size (decodetxb.c:200); this crate carried the class-1 sibling
only for 4x4 and 8x8 luma. TxMode::Select made the hole reachable: a 32x32
inter block's var-tx leaf is a 16x16 luma TU, whose inter tx set
EXT_TX_SET_DTT9_IDTX_1DDCT is the only 16x16 set holding V_DCT/H_DCT.

Adds eob_pt_256_luma_class1 and the three chroma siblings (an inter block's
chroma TU inherits its luma unit's tx_type, so 1D classes reach chroma too),
their defaults from av1_default_eob_multi{256,64,16}_cdfs[q][plane][1], and
their per-frame counter resets. 32-point and larger need none (DCT_IDTX /
DCTONLY hold no 1D type).

Found by msac range ladder vs instrumented aomdec on r1's failing seed-43
stream: first divergent element is the eob of the 16x16 leaf at mi (4,8),
ref eob=248 rng=65032 vs ours eob=247 rng=56584 with identical all_zero and
tx_type ranges. All four frames of that stream are now pre-filter bit-exact.

Gate a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact is
green and gains a 10-bit arm (-b 10 --input-bit-depth=10); suite 269 passed
/ 0 failed / 23 ignored.
crates/ec-av1/src/cdf.rsmodified+41 -0
@@ -5032,3 +5032,44 @@ pub const INTRA_TX_TYPE_SET1_4: [[u16; 8]; 13] = [
50325032 [277, 4369, 5255, 8905, 16465, 22271, 32768, 0],
50335033 [3409, 5436, 10599, 15599, 19687, 24040, 32768, 0],
50345034 ];
5035+
5036+/// The `TX_CLASS_HORIZ`/`TX_CLASS_VERT` siblings of [`EOB_PT_256_LUMA`],
5037+/// [`EOB_PT_256_CHROMA`], [`EOB_PT_64_CHROMA`] and [`EOB_PT_16_CHROMA`]
5038+/// (`av1_default_eob_multi{256,64,16}_cdfs[q][plane][1]`, `token_cdfs.h`) --
5039+/// lane-txselect r2: the class dimension libaom keeps on *every* eob_pt
5040+/// table. Only 4x4/8x8 luma carried it here, so the first `V_DCT`/`H_DCT`
5041+/// 16x16 luma TU (a var-tx leaf of a 32x32 inter block, `EXT_TX_SET_
5042+/// DTT9_IDTX_1DDCT`) read the 2D table and desynced at its `eob`. 32-point
5043+/// and larger transforms need no sibling: their tx sets (`DCT_IDTX`,
5044+/// `DCTONLY`) hold no 1D type.
5045+pub const EOB_PT_256_LUMA_CLASS1_Q0: [u16; 10] =
5046+ [998, 1850, 2998, 5604, 17341, 19888, 22899, 25583, 32768, 0];
5047+pub const EOB_PT_256_LUMA_CLASS1_Q1: [u16; 10] =
5048+ [399, 1019, 1749, 3038, 10444, 15546, 22739, 27294, 32768, 0];
5049+pub const EOB_PT_256_LUMA_CLASS1: [u16; 10] =
5050+ [1084, 2358, 3488, 5122, 11483, 18103, 26023, 29799, 32768, 0];
5051+pub const EOB_PT_256_LUMA_CLASS1_Q3: [u16; 10] =
5052+ [2453, 4474, 6307, 8777, 16474, 22975, 29000, 31547, 32768, 0];
5053+
5054+pub const EOB_PT_256_CHROMA_CLASS1_Q0: [u16; 10] =
5055+ [2203, 4130, 7435, 10739, 20652, 23681, 25609, 27261, 32768, 0];
5056+pub const EOB_PT_256_CHROMA_CLASS1_Q1: [u16; 10] =
5057+ [1674, 3252, 5734, 10159, 22397, 23802, 24821, 30940, 32768, 0];
5058+pub const EOB_PT_256_CHROMA_CLASS1: [u16; 10] =
5059+ [6571, 9610, 15516, 21826, 29092, 30829, 31842, 32708, 32768, 0];
5060+pub const EOB_PT_256_CHROMA_CLASS1_Q3: [u16; 10] =
5061+ [9998, 17661, 25178, 28097, 31308, 32038, 32403, 32695, 32768, 0];
5062+
5063+pub const EOB_PT_64_CHROMA_CLASS1_Q0: [u16; 8] =
5064+ [1563, 2700, 4876, 10911, 14706, 22480, 32768, 0];
5065+pub const EOB_PT_64_CHROMA_CLASS1_Q1: [u16; 8] =
5066+ [1923, 3127, 5867, 9703, 14277, 27100, 32768, 0];
5067+pub const EOB_PT_64_CHROMA_CLASS1: [u16; 8] =
5068+ [4034, 6290, 10235, 14982, 21214, 28491, 32768, 0];
5069+pub const EOB_PT_64_CHROMA_CLASS1_Q3: [u16; 8] =
5070+ [8726, 12378, 19409, 26450, 30038, 32462, 32768, 0];
5071+
5072+pub const EOB_PT_16_CHROMA_CLASS1_Q0: [u16; 6] = [1904, 3354, 7763, 14647, 32768, 0];
5073+pub const EOB_PT_16_CHROMA_CLASS1_Q1: [u16; 6] = [2497, 4096, 8866, 16993, 32768, 0];
5074+pub const EOB_PT_16_CHROMA_CLASS1: [u16; 6] = [3192, 5032, 10297, 19755, 32768, 0];
5075+pub const EOB_PT_16_CHROMA_CLASS1_Q3: [u16; 6] = [7297, 10767, 19273, 28194, 32768, 0];
crates/ec-av1/src/cdf_state.rsmodified+49 -6
@@ -214,6 +214,17 @@ pub(crate) struct Cdfs {
214214 pub eob_pt_16_luma_class1: [u16; 6],
215215 /// `eob_pt_64_luma`'s class-1 sibling (r5), see `eob_pt_16_luma_class1`.
216216 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],
217228 /// The end-of-block offset bit of a 16x16 luma transform.
218229 pub eob_extra_luma_16: [[u16; 3]; 9],
219230 /// The same, for an 8x8 luma transform.
@@ -612,6 +623,10 @@ impl Cdfs {
612623 reset1(&mut self.eob_pt_16_luma);
613624 reset1(&mut self.eob_pt_16_luma_class1);
614625 reset1(&mut self.eob_pt_64_luma_class1);
626+ reset1(&mut self.eob_pt_256_luma_class1);
627+ reset1(&mut self.eob_pt_256_chroma_class1);
628+ reset1(&mut self.eob_pt_64_chroma_class1);
629+ reset1(&mut self.eob_pt_16_chroma_class1);
615630 reset2(&mut self.eob_extra_luma_16);
616631 reset2(&mut self.eob_extra_luma_8);
617632 reset2(&mut self.eob_extra_luma_4);
@@ -827,6 +842,34 @@ impl Cdfs {
827842 cdf::EOB_PT_64_LUMA_CLASS1,
828843 cdf::EOB_PT_64_LUMA_CLASS1_Q3,
829844 ),
845+ eob_pt_256_luma_class1: pick(
846+ q_ctx,
847+ cdf::EOB_PT_256_LUMA_CLASS1_Q0,
848+ cdf::EOB_PT_256_LUMA_CLASS1_Q1,
849+ cdf::EOB_PT_256_LUMA_CLASS1,
850+ cdf::EOB_PT_256_LUMA_CLASS1_Q3,
851+ ),
852+ eob_pt_256_chroma_class1: pick(
853+ q_ctx,
854+ cdf::EOB_PT_256_CHROMA_CLASS1_Q0,
855+ cdf::EOB_PT_256_CHROMA_CLASS1_Q1,
856+ cdf::EOB_PT_256_CHROMA_CLASS1,
857+ cdf::EOB_PT_256_CHROMA_CLASS1_Q3,
858+ ),
859+ eob_pt_64_chroma_class1: pick(
860+ q_ctx,
861+ cdf::EOB_PT_64_CHROMA_CLASS1_Q0,
862+ cdf::EOB_PT_64_CHROMA_CLASS1_Q1,
863+ cdf::EOB_PT_64_CHROMA_CLASS1,
864+ cdf::EOB_PT_64_CHROMA_CLASS1_Q3,
865+ ),
866+ eob_pt_16_chroma_class1: pick(
867+ q_ctx,
868+ cdf::EOB_PT_16_CHROMA_CLASS1_Q0,
869+ cdf::EOB_PT_16_CHROMA_CLASS1_Q1,
870+ cdf::EOB_PT_16_CHROMA_CLASS1,
871+ cdf::EOB_PT_16_CHROMA_CLASS1_Q3,
872+ ),
830873 eob_extra_luma_16: pick(
831874 q_ctx,
832875 cdf::EOB_EXTRA_LUMA_16_Q0,
@@ -1264,7 +1307,7 @@ impl Cdfs {
12641307 br: &mut self.br_luma_16,
12651308 dc_sign: &mut self.dc_sign_luma,
12661309 tx_type: Some(self.intra_tx_type_16[mode].as_mut_slice()),
1267- eob_pt_class1: None,
1310+ eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1),
12681311 },
12691312 TxbSet::Luma16Inter => TxbTables {
12701313 side: 16,
@@ -1276,7 +1319,7 @@ impl Cdfs {
12761319 br: &mut self.br_luma_16,
12771320 dc_sign: &mut self.dc_sign_luma,
12781321 tx_type: Some(self.inter_tx_type_16.as_mut_slice()),
1279- eob_pt_class1: None,
1322+ eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1),
12801323 },
12811324 TxbSet::Luma16InterSet1 => TxbTables {
12821325 side: 16,
@@ -1288,7 +1331,7 @@ impl Cdfs {
12881331 br: &mut self.br_luma_16,
12891332 dc_sign: &mut self.dc_sign_luma,
12901333 tx_type: Some(self.inter_tx_type_16_set2.as_mut_slice()),
1291- eob_pt_class1: None,
1334+ eob_pt_class1: Some(&mut self.eob_pt_256_luma_class1),
12921335 },
12931336 TxbSet::Luma8 => TxbTables {
12941337 side: 8,
@@ -1396,7 +1439,7 @@ impl Cdfs {
13961439 br: &mut self.br_chroma_8,
13971440 dc_sign: &mut self.dc_sign_chroma,
13981441 tx_type: None,
1399- eob_pt_class1: None,
1442+ eob_pt_class1: Some(&mut self.eob_pt_64_chroma_class1),
14001443 },
14011444 TxbSet::Chroma4 => TxbTables {
14021445 side: 4,
@@ -1408,7 +1451,7 @@ impl Cdfs {
14081451 br: &mut self.br_chroma_4,
14091452 dc_sign: &mut self.dc_sign_chroma,
14101453 tx_type: None,
1411- eob_pt_class1: None,
1454+ eob_pt_class1: Some(&mut self.eob_pt_16_chroma_class1),
14121455 },
14131456 TxbSet::Chroma16 => TxbTables {
14141457 side: 16,
@@ -1420,7 +1463,7 @@ impl Cdfs {
14201463 br: &mut self.br_chroma_16,
14211464 dc_sign: &mut self.dc_sign_chroma,
14221465 tx_type: None,
1423- eob_pt_class1: None,
1466+ eob_pt_class1: Some(&mut self.eob_pt_256_chroma_class1),
14241467 },
14251468 TxbSet::Chroma32 => TxbTables {
14261469 side: 32,
crates/ec-av1/src/stream.rsmodified+35 -5
@@ -2366,6 +2366,19 @@ mod tests {
23662366 /// FAILURE, not a SKIP -- an unfired gate is a vacuous gate.
23672367 #[test]
23682368 fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact() {
2369+ tx_select_inter_gate(8);
2370+ }
2371+
2372+ /// The 10-bit arm of the gate above (lane-txselect r2): both of the
2373+ /// user's films are `yuv420p10le` and var-tx is exactly the tool they
2374+ /// use, so an 8-bit-only proof would not reach them. Same recipe plus
2375+ /// `-b 10 --input-bit-depth=10`.
2376+ #[test]
2377+ fn a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact_10bit() {
2378+ tx_select_inter_gate(10);
2379+ }
2380+
2381+ fn tx_select_inter_gate(bit_depth: u32) {
23692382 if !have_ffmpeg() {
23702383 eprintln!(
23712384 "SKIP a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact: no ffmpeg"
@@ -2405,11 +2418,17 @@ mod tests {
24052418 "-vf",
24062419 "hue=s=0",
24072420 "-pix_fmt",
2408- "yuv420p",
2421+ if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" },
2422+ // y4m carries no official 10-bit tag; ffmpeg writes one
2423+ // only under `-strict -1` (a no-op at 8 bit).
2424+ "-strict",
2425+ "-1",
24092426 "-t",
24102427 "0.16",
24112428 "-f",
24122429 "yuv4mpegpipe",
2430+ "-strict",
2431+ "-1",
24132432 "-",
24142433 ])
24152434 .stdin(Stdio::null())
@@ -2422,7 +2441,13 @@ mod tests {
24222441 "ffmpeg fixture: {}",
24232442 String::from_utf8_lossy(&y4m.stderr)
24242443 );
2444+ let depth_args: &[&str] = if bit_depth == 10 {
2445+ &["-b", "10", "--input-bit-depth=10"]
2446+ } else {
2447+ &[]
2448+ };
24252449 let mut child = Command::new(aomenc_path())
2450+ .args(depth_args)
24262451 .args([
24272452 "--codec=av1",
24282453 "--passes=1",
@@ -2512,9 +2537,15 @@ mod tests {
25122537 ));
25132538 continue;
25142539 }
2515- let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
2540+ let ffmpeg_frames = if bit_depth == 10 {
2541+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
2542+ } else {
2543+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
2544+ };
25162545 assert_eq!(frames.len(), frame_count);
2517- eprintln!("txselect gate seed={seed}: txfm_split reads={reads} splits taken={hits}");
2546+ eprintln!(
2547+ "txselect gate {bit_depth}-bit seed={seed}: txfm_split reads={reads} splits taken={hits}"
2548+ );
25182549 // Name the first differing sample before the assert fires: a
25192550 // 64x64 plane's `assert_eq!` output is 4096 numbers, useless for
25202551 // locating a desync.
@@ -2555,8 +2586,7 @@ mod tests {
25552586 return;
25562587 }
25572588 panic!(
2558- "a_real_aomenc_inter_sequence_with_tx_select_decodes_pixel_exact never observed a \
2559- taken txfm_split:\n{}",
2589+ "tx_select_inter_gate({bit_depth}) never observed a taken txfm_split:\n{}",
25602590 refusals.join("\n")
25612591 );
25622592 }
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).