forge
Explore
Log in

Don't you dare go Hollow

wip(av1): root-cause cdfflake-stream-seed45 pin -- reduced_tx_set=false inter tx_type gap

Browse files at this commit

dcd3febfee102a5bedf87d8542be7a14c0573543Ahmet Kaan GümüşParent: 9cd7fd0
Bisected the pinned frame-2 mismatch (cdfflake-stream-seed45.bin, 359/4096
luma px, worst delta 6, right-edge block). Added scratch instrumentation
(env-gated, zero behavior change): scratch_dump_prefilt in decode.rs
(EC_AV1_PREFILT_DUMP_OURS, mirrors the instrumented aomdec's own
EC_AV1_PREFILT_DUMP) and an EC_RNG per-symbol trace in msac.rs
(SymbolDecoder::symbol_fixed), matching libaom's aom_dsp/entdec.c format
exactly (rng_before/rng_after/nsyms/symbol, shared global counter).

Verdict: PIXEL-PATH, not entropy garbage-cascade in the usual sense --
pre-deblock buffers already differ (497/4096 luma mismatches at frame 2,
rows 48-63 cols 32-63, exactly the mi(12,8)/mi(12,12) 16x16x2 region),
proving the defect is in reconstruction, but the root symbol-level cause
IS a real entropy divergence: gdb-bisected via `EC_RNG` + a conditional
breakpoint on od_ec_decode_cdf_q15 in the instrumented aomdec build to
n=787, which resolves (backtrace) to av1_read_tx_type ->
decodetxb.c:read_coeffs_txb, nsyms=12 -- libaom's EXT_TX_SET_DTT4_IDTX_1DDCT,
selected by av1_get_ext_tx_set_type(TX_16X16, is_inter=1,
use_reduced_set=0) (blockd.h:1097, av1_ext_tx_set_lookup[1][1]). Our
decoder read a 2-symbol table (nsyms=2) at the same point instead.

Root cause: cdf_state.rs's TxbSet::Luma16Inter (and Luma8Inter) are
hardcoded to the *reduced_tx_set=true* 2-symbol EXT_TX_SET_DCT_IDTX table
only (doc comments there already say so explicitly); this crate's own
writer always emits reduced_tx_set=true so the gap never showed up on a
round-trip test. A real aomenc stream with reduced_tx_set=false (this
pin) hits an inter 16x16 block whose tx_type this decoder cannot read at
all -- it silently misreads a binary CDF where the real bitstream encoded
a 12-way EXT_TX_SET_DTT4_IDTX_1DDCT symbol, desyncing the rest of the
frame's own coefficient reads (491 more luma reads through the tile) and
poisoning the CDFs forwarded into frame 3.

Same-shape sibling gaps found by reading av1_get_ext_tx_set_type
(NOT yet fixed, name only): 8x8 inter + reduced_tx_set=false wants
EXT_TX_SET_ALL16 (16-symbol), also unimplemented (Luma8Inter is likewise
reduced-only per its own doc comment). 32x32+/64x64 inter are fine
(EXT_TX_SET_DCT_IDTX unconditionally regardless of reduced_tx_set, per
blockd.h:1101-1102) -- Luma32Inter's existing 2-symbol table is already
correct there.

NOT fixed this round (budget): needs a new TxbSet::Luma16InterSet1
(12-symbol CDF, transcribed from libaom entropymode.c
default_inter_ext_tx_cdf[EXT_TX_SET_DTT4_IDTX_1DDCT][TX_16X16], + the
EXT_TX_SET_DTT4_IDTX_1DDCT symbol->TxType mapping from
av1_ext_tx_used/inter table), wired into decode_inter_block's TxbSet
selection (currently hardcoded to TxbSet::Luma16Inter at every call site,
e.g. decode.rs:6484) gated on `!reduced_tx_set`, and the same for
TxbSet::Luma8InterSet1 (16-symbol EXT_TX_SET_ALL16). Dying words: pull
default_inter_ext_tx_cdf's 16x16-DTT4_IDTX_1DDCT row (12 probs) and the
matching tx_type index table from
/tmp/libaom-src/av1/common/av1_entropymode.c +
av1/common/enums.h(EXT_TX_SET_DTT4_IDTX_1DDCT symbol order), add the two
TxbSet variants + a reduced_tx_set-gated select at every `16 =>` /
`8 if reduced_tx_set` dispatch site feeding an inter block, then rerun
scratch_isolate_pinned_mismatch on cdfflake-stream-seed45.bin to confirm
4/4 frames byte-exact, then remove scratch_dump_prefilt/EC_RNG (or leave
as documented scratch, orchestrator's call), then the cdf-forwarding gate
5x + full ec-av1 --lib suite 3x.
crates/ec-av1/src/decode.rsmodified+26 -0
@@ -2485,6 +2485,30 @@ fn cdef_filter_block(
24852485 /// size. `cdef_bits == 0` is this crate's only supported case so far (see the
24862486 /// refusal in `stream.rs`), so every 64x64 filter block always uses index 0's
24872487 /// strengths -- no per-block `cdef_idx` selection is implemented yet.
2488+/// bisect scratch (lane-cdffwd2): dump this frame's Y/U/V exactly the way
2489+/// the instrumented `aomdec` build's `EC_AV1_PREFILT_DUMP` does (raw
2490+/// `true_width`x`true_height` bytes per plane, decode order, one file per
2491+/// frame index), gated on env so it is zero-cost/zero-behavior off. Called
2492+/// from both the key-frame and inter-frame tile decoders so the frame index
2493+/// lines up with aomdec's own (which dumps unconditionally every frame).
2494+fn scratch_dump_prefilt(y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {
2495+ let Some(base) = std::env::var_os("EC_AV1_PREFILT_DUMP_OURS") else {
2496+ return;
2497+ };
2498+ use std::sync::atomic::{AtomicUsize, Ordering};
2499+ static IDX: AtomicUsize = AtomicUsize::new(0);
2500+ let idx = IDX.fetch_add(1, Ordering::SeqCst);
2501+ let path = format!("{}.f{}", base.to_string_lossy(), idx);
2502+ let mut out = Vec::new();
2503+ for plane in [y, u, v] {
2504+ for row in 0..plane.true_height {
2505+ let start = row * plane.width;
2506+ out.extend_from_slice(&plane.data[start..start + plane.true_width]);
2507+ }
2508+ }
2509+ let _ = std::fs::write(path, out);
2510+}
2511+
24882512 /// Spec 7.14: the in-loop deblocking filter, applied once per frame after
24892513 /// tile reconstruction and before [`apply_cdef`]. Uniform-level path only --
24902514 /// `stream.rs` already refuses `delta_lf_present`/segmentation upstream, so
@@ -3588,6 +3612,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
35883612 }
35893613 }
35903614
3615+ scratch_dump_prefilt(&y, &u, &v);
35913616 apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours);
35923617 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
35933618
@@ -6589,6 +6614,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
65896614 }
65906615 }
65916616
6617+ scratch_dump_prefilt(&y, &u, &v);
65926618 apply_deblock(&mut y, &mut u, &mut v, loop_filter, &neighbours);
65936619 apply_cdef(&mut y, &mut u, &mut v, cdef, &neighbours);
65946620
crates/ec-av1/src/msac.rsmodified+12 -0
@@ -303,6 +303,9 @@ impl<'a> SymbolDecoder<'a> {
303303 let mut cur = self.range;
304304 let mut prev;
305305 let mut symbol = 0;
306+ // bisect scratch (lane-cdffwd2): rng_before, matching libaom
307+ // entdec.c's own EC_RNG trace field of the same name.
308+ let rng_before = self.range;
306309 loop {
307310 prev = cur;
308311 let f = u32::from(CDF_TOP - cdf[symbol]);
@@ -315,6 +318,15 @@ impl<'a> SymbolDecoder<'a> {
315318 }
316319 self.range = prev - cur;
317320 self.value -= cur;
321+ if std::env::var_os("EC_RNG").is_some() {
322+ use std::sync::atomic::{AtomicU64, Ordering};
323+ static N: AtomicU64 = AtomicU64::new(0);
324+ let n = N.fetch_add(1, Ordering::SeqCst);
325+ eprintln!(
326+ "EC_RNG n={n} rng_before={rng_before} rng_after={} nsyms={nsyms} symbol={symbol}",
327+ self.range
328+ );
329+ }
318330
319331 // Renormalise back into `[2^15, 2^16)`, the same shift the encoder
320332 // applied when it narrowed to this symbol.