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) ->
1180 }1180 }
1181 let group = dec.symbol(eob_pt) + 1;1181 let group = dec.symbol(eob_pt) + 1;
1182 if trace {1182 if trace {
1183- eprintln!("TRACE eob_pt value={group}");1183+ eprintln!("TRACE eob_pt value={group} rng={}", dec.debug_state().0);
1184 }1184 }
1185 let bits = OFFSET_BITS[group];1185 let bits = OFFSET_BITS[group];
1186 let mut offset = 0u32;1186 let mut offset = 0u32;
@@ -3216,6 +3216,10 @@ fn decode_block_rect64(
3216 // grid (see this function's own doc comment).3216 // grid (see this function's own doc comment).
3217 let scan32 = default_scan(TX32);3217 let scan32 = default_scan(TX32);
3218 let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode);3218 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+ }
3219 let (luma_corner, luma_tx_type) = read_coeffs(3223 let (luma_corner, luma_tx_type) = read_coeffs(
3220 dec,3224 dec,
3221 &mut luma_coding,3225 &mut luma_coding,
@@ -3224,6 +3228,10 @@ fn decode_block_rect64(
3224 dc_sign_ctx(around[0].2),3228 dc_sign_ctx(around[0].2),
3225 TxType::DctDct,3229 TxType::DctDct,
3226 )?;3230 )?;
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+ }
3227 let mut luma_levels = vec![0i32; bw * bh];3235 let mut luma_levels = vec![0i32; bw * bh];
3228 for row in 0..32 {3236 for row in 0..32 {
3229 luma_levels[row * bw..][..32].copy_from_slice(&luma_corner[row * 32..][..32]);3237 luma_levels[row * bw..][..32].copy_from_slice(&luma_corner[row * 32..][..32]);
@@ -3255,6 +3263,10 @@ fn decode_block_rect64(
3255 let chroma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 };3263 let chroma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 };
3256 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);3264 let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1);
3257 let mut u_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode);3265 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+ }
3258 let (u_levels, u_tx_type) = read_coeffs_rect(3270 let (u_levels, u_tx_type) = read_coeffs_rect(
3259 dec,3271 dec,
3260 &mut u_coding,3272 &mut u_coding,
@@ -3265,6 +3277,10 @@ fn decode_block_rect64(
3265 dc_sign_ctx(around[1].2),3277 dc_sign_ctx(around[1].2),
3266 TxType::DctDct,3278 TxType::DctDct,
3267 )?;3279 )?;
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+ }
3268 let u_residual = dequant_and_inverse_typed_wh(3284 let u_residual = dequant_and_inverse_typed_wh(
3269 &u_levels,3285 &u_levels,
3270 chroma_w,3286 chroma_w,
@@ -3288,6 +3304,10 @@ fn decode_block_rect64(
3288 );3304 );
3289 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);3305 let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1);
3290 let mut v_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode);3306 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+ }
3291 let (v_levels, v_tx_type) = read_coeffs_rect(3311 let (v_levels, v_tx_type) = read_coeffs_rect(
3292 dec,3312 dec,
3293 &mut v_coding,3313 &mut v_coding,
@@ -3298,6 +3318,10 @@ fn decode_block_rect64(
3298 dc_sign_ctx(around[2].2),3318 dc_sign_ctx(around[2].2),
3299 TxType::DctDct,3319 TxType::DctDct,
3300 )?;3320 )?;
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+ }
3301 let v_residual = dequant_and_inverse_typed_wh(3325 let v_residual = dequant_and_inverse_typed_wh(
3302 &v_levels,3326 &v_levels,
3303 chroma_w,3327 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)
563 open(path, "w").write(s)563 open(path, "w").write(s)
564 print("intra mode-info per-symbol ladder instrumented")564 print("intra mode-info per-symbol ladder instrumented")
565 PYS565 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