forge
Explore
Log in

Don't you dare go Hollow

diag(av1): sbpart r7 -- per-symbol coeff range ladder localizes block2's true divergence

Browse files at this commit

36c2f06ac474c1498ee5afd9175db94f5c488673Ahmet Kaan GümüşParent: 5f16ddd
Rung 3's entry/exit EC_TRACE_COEFF proved block2's luma coefficient read
(TxbSet::Luma64 corner, decode.rs:3214) is where the desync actually starts:
entry rng=63764 matches the oracle exactly (confirming r6's mode-info prefix
finding held all the way through skip/depth), but the luma read's own exit
range (46984 ours vs 46344 oracle) diverges -- overturning r6's suspicion
that around_rect's neighbour gather was the culprit; the gather only feeds
skip_ctx/dc_sign_ctx, and both of those read identically (all_zero=0 both
sides, dc_sign both agree).

Added a new oracle rung (11, scripts/instrument-aom-oracle.sh, same
EC_TRACE_COEFF flag) printing per-symbol rng inside read_coeffs_txb
(eob/base_eob/after_bases/sign/post_golomb), plus matching entry/exit
EC_COEFF/EC_COEFF_VAL markers at all 3 of decode_block_rect64's own
read_coeffs/read_coeffs_rect call sites and rng on read_eob's own TRACE
eob_pt/eob_extra lines. Range-laddered block2's luma block byte-for-byte
against the oracle: eob (6) and base_eob (level=1) both match. First value
divergence is the "base" symbol at scan position row=1,col=0 (pos=32) --
ours decodes value=3 (triggering an extra "br" read, final level 3), the
oracle's equivalent position decodes level=1 with no br read at all. This
is a NEW, sharper suspect than r6's around_rect/context-gather framing: the
coefficient magnitude symbol itself (base_ctx's context computation, or the
CDF row it indexes) for this specific scan position inside the 32x32 corner
scan.

Diagnostics only, no behavior change to the live gate (still red, same as
r6 left it) -- sb_rect_hits()>0 unproven this round, not attempted since the
fix itself wasn't reached within budget.

cargo check -p ec-av1 --tests: clean, only pre-existing missing-doc
warnings. Oracle rung env-gated, applied to the shared ~/.cache/aom-oracle
tree and rebuilt (ninja aomdec clean), also captured in
scripts/instrument-aom-oracle.sh so it reproduces from a fresh clone.
crates/ec-av1/src/decode.rsmodified+25 -1
@@ -1180,7 +1180,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) ->
11801180 }
11811181 let group = dec.symbol(eob_pt) + 1;
11821182 if trace {
1183- eprintln!("TRACE eob_pt value={group}");
1183+ eprintln!("TRACE eob_pt value={group} rng={}", dec.debug_state().0);
11841184 }
11851185 let bits = OFFSET_BITS[group];
11861186 let mut offset = 0u32;
@@ -3216,6 +3216,10 @@ fn decode_block_rect64(
32163216 // grid (see this function's own doc comment).
32173217 let scan32 = default_scan(TX32);
32183218 let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode);
3219+ if std::env::var_os("EC_TRACE_COEFF").is_some() {
3220+ let (rng, _) = dec.debug_state();
3221+ eprintln!("EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size=64corner rng={rng}");
3222+ }
32193223 let (luma_corner, luma_tx_type) = read_coeffs(
32203224 dec,
32213225 &mut luma_coding,
@@ -3224,6 +3228,10 @@ fn decode_block_rect64(
32243228 dc_sign_ctx(around[0].2),
32253229 TxType::DctDct,
32263230 )?;
3231+ if std::env::var_os("EC_TRACE_COEFF").is_some() {
3232+ let (rng, _) = dec.debug_state();
3233+ eprintln!("EC_COEFF_VAL plane=0 row={mi_r} col={mi_c} rng={rng}");
3234+ }
32273235 let mut luma_levels = vec![0i32; bw * bh];
32283236 for row in 0..32 {
32293237 luma_levels[row * bw..][..32].copy_from_slice(&luma_corner[row * 32..][..32]);
@@ -3255,6 +3263,10 @@ fn decode_block_rect64(
32553263 let chroma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 };
32563264 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
32573265 let mut u_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode);
3266+ if std::env::var_os("EC_TRACE_COEFF").is_some() {
3267+ let (rng, _) = dec.debug_state();
3268+ eprintln!("EC_COEFF plane=1 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}");
3269+ }
32583270 let (u_levels, u_tx_type) = read_coeffs_rect(
32593271 dec,
32603272 &mut u_coding,
@@ -3265,6 +3277,10 @@ fn decode_block_rect64(
32653277 dc_sign_ctx(around[1].2),
32663278 TxType::DctDct,
32673279 )?;
3280+ if std::env::var_os("EC_TRACE_COEFF").is_some() {
3281+ let (rng, _) = dec.debug_state();
3282+ eprintln!("EC_COEFF_VAL plane=1 row={mi_r} col={mi_c} rng={rng}");
3283+ }
32683284 let u_residual = dequant_and_inverse_typed_wh(
32693285 &u_levels,
32703286 chroma_w,
@@ -3288,6 +3304,10 @@ fn decode_block_rect64(
32883304 );
32893305 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
32903306 let mut v_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode);
3307+ if std::env::var_os("EC_TRACE_COEFF").is_some() {
3308+ let (rng, _) = dec.debug_state();
3309+ eprintln!("EC_COEFF plane=2 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}");
3310+ }
32913311 let (v_levels, v_tx_type) = read_coeffs_rect(
32923312 dec,
32933313 &mut v_coding,
@@ -3298,6 +3318,10 @@ fn decode_block_rect64(
32983318 dc_sign_ctx(around[2].2),
32993319 TxType::DctDct,
33003320 )?;
3321+ if std::env::var_os("EC_TRACE_COEFF").is_some() {
3322+ let (rng, _) = dec.debug_state();
3323+ eprintln!("EC_COEFF_VAL plane=2 row={mi_r} col={mi_c} rng={rng}");
3324+ }
33013325 let v_residual = dequant_and_inverse_typed_wh(
33023326 &v_levels,
33033327 chroma_w,
scripts/instrument-aom-oracle.shmodified+78 -0
@@ -563,3 +563,81 @@ s = s.replace(marker_old, "/* EC_INSTRUMENTED_INTRA_STEP */\n" + marker_old, 1)
563563 open(path, "w").write(s)
564564 print("intra mode-info per-symbol ladder instrumented")
565565 PYS
566+
567+# --- rung 11: per-symbol range ladder inside read_coeffs_txb (decodetxb.c) --
568+# lane-sbpart r7: rung 3's EC_TRACE_COEFF only bracketed a whole coefficient
569+# block (entry/exit rng) -- too coarse to find WHICH symbol inside a Luma64
570+# corner-scan block diverges. This adds EC_COEFF_STEP tag=eob/base_eob/
571+# after_bases/sign/post_golomb lines, rng after each, under the same
572+# EC_TRACE_COEFF flag (no new env var). Localized r7's own bisect to the
573+# `base` symbol at scan position (row=1,col=0) inside block2's luma corner:
574+# entry rng and eob/base_eob both match ours byte-for-byte, then our `base`
575+# read at that position decodes value=3 (triggering an extra `br` read)
576+# where the oracle's equivalent position decodes level=1 -- see
577+# lanes/sbpart-r7.report.md.
578+G="$SRC/av1/decoder/decodetxb.c"
579+[ -f "$G" ] || { echo "no oracle source at $G" >&2; exit 1; }
580+
581+python3 - "$G" <<'PYC11'
582+import sys
583+path = sys.argv[1]
584+s = open(path).read()
585+if "EC_COEFF_STEP" in s:
586+ print("decodetxb rung 11 already applied (no-op)")
587+ sys.exit(0)
588+
589+old1 = " *eob = rec_eob_pos(eob_pt, eob_extra);\n"
590+new1 = old1 + """ {
591+ const int ec_trace2 = getenv("EC_TRACE_COEFF") != NULL;
592+ if (ec_trace2) {
593+ fprintf(stderr, "EC_COEFF_STEP tag=eob eob=%d rng=%u\\n", *eob, (unsigned)r->ec.rng);
594+ }
595+ }
596+"""
597+assert old1 in s, "eob assign not found"
598+s = s.replace(old1, new1, 1)
599+
600+old2 = " levels[get_padded_idx(pos, bhl)] = level;\n }\n if (*eob > 1) {"
601+new2 = """ levels[get_padded_idx(pos, bhl)] = level;
602+ if (getenv("EC_TRACE_COEFF") != NULL) {
603+ fprintf(stderr, "EC_COEFF_STEP tag=base_eob level=%d rng=%u\\n", level, (unsigned)r->ec.rng);
604+ }
605+ }
606+ if (*eob > 1) {"""
607+assert old2 in s, "base_eob block not found"
608+s = s.replace(old2, new2, 1)
609+
610+old3 = """ read_coeffs_reverse(r, tx_size, tx_class, 0, *eob - 1 - 1, scan, bhl,
611+ levels, base_cdf, br_cdf);
612+ }
613+ }
614+"""
615+new3 = old3 + """ if (getenv("EC_TRACE_COEFF") != NULL) {
616+ fprintf(stderr, "EC_COEFF_STEP tag=after_bases rng=%u\\n", (unsigned)r->ec.rng);
617+ }
618+"""
619+assert old3 in s, "after_bases site not found"
620+s = s.replace(old3, new3, 1)
621+
622+old4 = """ if (level >= MAX_BASE_BR_RANGE) {
623+ level += read_golomb(xd, r);
624+ }
625+
626+ if (c == 0) dc_val = sign ? -level : level;"""
627+new4 = """ if (getenv("EC_TRACE_COEFF") != NULL) {
628+ fprintf(stderr, "EC_COEFF_STEP tag=sign c=%d sign=%d rng=%u\\n", c, sign, (unsigned)r->ec.rng);
629+ }
630+ if (level >= MAX_BASE_BR_RANGE) {
631+ level += read_golomb(xd, r);
632+ }
633+ if (getenv("EC_TRACE_COEFF") != NULL) {
634+ fprintf(stderr, "EC_COEFF_STEP tag=post_golomb c=%d level=%d rng=%u\\n", c, level, (unsigned)r->ec.rng);
635+ }
636+
637+ if (c == 0) dc_val = sign ? -level : level;"""
638+assert old4 in s, "sign/golomb site not found"
639+s = s.replace(old4, new4, 1)
640+
641+open(path, "w").write(s)
642+print("decodetxb rung 11 (per-symbol coeff ladder) instrumented")
643+PYC11