diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index d825f43b..ae93f329 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1180,7 +1180,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) -> } let group = dec.symbol(eob_pt) + 1; if trace { - eprintln!("TRACE eob_pt value={group}"); + eprintln!("TRACE eob_pt value={group} rng={}", dec.debug_state().0); } let bits = OFFSET_BITS[group]; let mut offset = 0u32; @@ -3216,6 +3216,10 @@ fn decode_block_rect64( // grid (see this function's own doc comment). let scan32 = default_scan(TX32); let mut luma_coding = cdfs.txb(TxbSet::Luma64, mode); + if std::env::var_os("EC_TRACE_COEFF").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("EC_COEFF plane=0 row={mi_r} col={mi_c} tx_size=64corner rng={rng}"); + } let (luma_corner, luma_tx_type) = read_coeffs( dec, &mut luma_coding, @@ -3224,6 +3228,10 @@ fn decode_block_rect64( dc_sign_ctx(around[0].2), TxType::DctDct, )?; + if std::env::var_os("EC_TRACE_COEFF").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("EC_COEFF_VAL plane=0 row={mi_r} col={mi_c} rng={rng}"); + } let mut luma_levels = vec![0i32; bw * bh]; for row in 0..32 { luma_levels[row * bw..][..32].copy_from_slice(&luma_corner[row * 32..][..32]); @@ -3255,6 +3263,10 @@ fn decode_block_rect64( let chroma_scan: &[u16] = if bw == 64 { &SCAN_32X16 } else { &SCAN_16X32 }; let u_skip_ctx = usize::from(around[1].0) + usize::from(around[1].1); let mut u_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode); + if std::env::var_os("EC_TRACE_COEFF").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("EC_COEFF plane=1 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); + } let (u_levels, u_tx_type) = read_coeffs_rect( dec, &mut u_coding, @@ -3265,6 +3277,10 @@ fn decode_block_rect64( dc_sign_ctx(around[1].2), TxType::DctDct, )?; + if std::env::var_os("EC_TRACE_COEFF").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("EC_COEFF_VAL plane=1 row={mi_r} col={mi_c} rng={rng}"); + } let u_residual = dequant_and_inverse_typed_wh( &u_levels, chroma_w, @@ -3288,6 +3304,10 @@ fn decode_block_rect64( ); let v_skip_ctx = usize::from(around[2].0) + usize::from(around[2].1); let mut v_coding = cdfs.txb(TxbSet::ChromaRect32x16, uv_predict_mode); + if std::env::var_os("EC_TRACE_COEFF").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("EC_COEFF plane=2 row={mi_r} col={mi_c} tx_size=rect32x16 rng={rng}"); + } let (v_levels, v_tx_type) = read_coeffs_rect( dec, &mut v_coding, @@ -3298,6 +3318,10 @@ fn decode_block_rect64( dc_sign_ctx(around[2].2), TxType::DctDct, )?; + if std::env::var_os("EC_TRACE_COEFF").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("EC_COEFF_VAL plane=2 row={mi_r} col={mi_c} rng={rng}"); + } let v_residual = dequant_and_inverse_typed_wh( &v_levels, chroma_w, diff --git a/scripts/instrument-aom-oracle.sh b/scripts/instrument-aom-oracle.sh index 0231c009..ebbb3651 100755 --- a/scripts/instrument-aom-oracle.sh +++ b/scripts/instrument-aom-oracle.sh @@ -563,3 +563,81 @@ s = s.replace(marker_old, "/* EC_INSTRUMENTED_INTRA_STEP */\n" + marker_old, 1) open(path, "w").write(s) print("intra mode-info per-symbol ladder instrumented") PYS + +# --- rung 11: per-symbol range ladder inside read_coeffs_txb (decodetxb.c) -- +# lane-sbpart r7: rung 3's EC_TRACE_COEFF only bracketed a whole coefficient +# block (entry/exit rng) -- too coarse to find WHICH symbol inside a Luma64 +# corner-scan block diverges. This adds EC_COEFF_STEP tag=eob/base_eob/ +# after_bases/sign/post_golomb lines, rng after each, under the same +# EC_TRACE_COEFF flag (no new env var). Localized r7's own bisect to the +# `base` symbol at scan position (row=1,col=0) inside block2's luma corner: +# entry rng and eob/base_eob both match ours byte-for-byte, then our `base` +# read at that position decodes value=3 (triggering an extra `br` read) +# where the oracle's equivalent position decodes level=1 -- see +# lanes/sbpart-r7.report.md. +G="$SRC/av1/decoder/decodetxb.c" +[ -f "$G" ] || { echo "no oracle source at $G" >&2; exit 1; } + +python3 - "$G" <<'PYC11' +import sys +path = sys.argv[1] +s = open(path).read() +if "EC_COEFF_STEP" in s: + print("decodetxb rung 11 already applied (no-op)") + sys.exit(0) + +old1 = " *eob = rec_eob_pos(eob_pt, eob_extra);\n" +new1 = old1 + """ { + const int ec_trace2 = getenv("EC_TRACE_COEFF") != NULL; + if (ec_trace2) { + fprintf(stderr, "EC_COEFF_STEP tag=eob eob=%d rng=%u\\n", *eob, (unsigned)r->ec.rng); + } + } +""" +assert old1 in s, "eob assign not found" +s = s.replace(old1, new1, 1) + +old2 = " levels[get_padded_idx(pos, bhl)] = level;\n }\n if (*eob > 1) {" +new2 = """ levels[get_padded_idx(pos, bhl)] = level; + if (getenv("EC_TRACE_COEFF") != NULL) { + fprintf(stderr, "EC_COEFF_STEP tag=base_eob level=%d rng=%u\\n", level, (unsigned)r->ec.rng); + } + } + if (*eob > 1) {""" +assert old2 in s, "base_eob block not found" +s = s.replace(old2, new2, 1) + +old3 = """ read_coeffs_reverse(r, tx_size, tx_class, 0, *eob - 1 - 1, scan, bhl, + levels, base_cdf, br_cdf); + } + } +""" +new3 = old3 + """ if (getenv("EC_TRACE_COEFF") != NULL) { + fprintf(stderr, "EC_COEFF_STEP tag=after_bases rng=%u\\n", (unsigned)r->ec.rng); + } +""" +assert old3 in s, "after_bases site not found" +s = s.replace(old3, new3, 1) + +old4 = """ if (level >= MAX_BASE_BR_RANGE) { + level += read_golomb(xd, r); + } + + if (c == 0) dc_val = sign ? -level : level;""" +new4 = """ if (getenv("EC_TRACE_COEFF") != NULL) { + fprintf(stderr, "EC_COEFF_STEP tag=sign c=%d sign=%d rng=%u\\n", c, sign, (unsigned)r->ec.rng); + } + if (level >= MAX_BASE_BR_RANGE) { + level += read_golomb(xd, r); + } + if (getenv("EC_TRACE_COEFF") != NULL) { + fprintf(stderr, "EC_COEFF_STEP tag=post_golomb c=%d level=%d rng=%u\\n", c, level, (unsigned)r->ec.rng); + } + + if (c == 0) dc_val = sign ? -level : level;""" +assert old4 in s, "sign/golomb site not found" +s = s.replace(old4, new4, 1) + +open(path, "w").write(s) +print("decodetxb rung 11 (per-symbol coeff ladder) instrumented") +PYC11