diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d2dee2b7..d005ebc6 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -9981,6 +9981,7 @@ fn read_intra_mode_rect( // `palette_uv` even on a chroma-reference strip. Fold the plane count // into the same `has_chroma` this reader already gates on. let has_chroma = has_chroma && !mono(fctx); + crate::msac::SymbolDecoder::set_symr_mi(mi_r as i64, mi_c as i64); let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); if ec_istep { // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line @@ -16581,6 +16582,7 @@ fn read_intra_mode( // shape the oracle's own `ec_read_intra_frame_mode_info_impl` prints // under `EC_TRACE_MODE_STEP`) so a range ladder can be diffed line for // line against the instrumented aomdec, not just `tell()`. + crate::msac::SymbolDecoder::set_symr_mi(mi_r as i64, mi_c as i64); let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); if ec_istep { // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line @@ -20330,6 +20332,7 @@ fn read_intra_mode_sub8( let has_chroma = has_chroma && !mono(fctx); let trace = crate::envflags::env_flag!("EC_AV1_TRACE"); let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); + crate::msac::SymbolDecoder::set_symr_mi(mi_r as i64, mi_c as i64); if ec_istep { eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0); } diff --git a/crates/ec-av1/src/msac.rs b/crates/ec-av1/src/msac.rs index c0e66234..c127ed01 100644 --- a/crates/ec-av1/src/msac.rs +++ b/crates/ec-av1/src/msac.rs @@ -321,6 +321,16 @@ impl Drop for SymbolDecoder<'_> { } } +thread_local! { + /// The `(mi_row, mi_col)` the enclosing block reader is inside, for the + /// `EC_SYMR` trace. A symbol read carries no mi of its own, so without it + /// the per-read stream can only be located by correlating it against a + /// SEPARATE trace -- and that correlation is what mis-attributed reads in + /// rounds 22 and 23. Set by the mode readers at entry; `(-1,-1)` outside. + pub(crate) static SYMR_MI: std::cell::Cell<(i64, i64)> = + const { std::cell::Cell::new((-1, -1)) }; +} + impl<'a> SymbolDecoder<'a> { /// `init_symbol` (spec 8.2.2). #[must_use] @@ -397,6 +407,10 @@ impl<'a> SymbolDecoder<'a> { /// `decode_symbol` (spec 8.2.6), with the adaptation of 8.3.2. /// + pub(crate) fn set_symr_mi(mi_r: i64, mi_c: i64) { + SYMR_MI.with(|c| c.set((mi_r, mi_c))); + } + /// `EC_SYMR=1` dumps every symbol read's PRE state (before the read and /// before the adaptation) together with the symbol and the post-read /// range, so a divergence against a reference decoder can be bisected @@ -431,7 +445,9 @@ impl<'a> SymbolDecoder<'a> { } if symr { eprintln!( - "EC_SYMR pre=({},{},{}) cdf0={} n={} s={} post_rng={}", + "EC_SYMR mi=({},{}) pre=({},{},{}) cdf0={} n={} s={} post_rng={}", + SYMR_MI.with(std::cell::Cell::get).0, + SYMR_MI.with(std::cell::Cell::get).1, pre_value, pre_range, pre_bit,