diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index db269c3a..fc53c539 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1976,11 +1976,23 @@ fn read_intra_mode_rect( 0 }; let mut filter_intra = None; + if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!( + "TRACE_RECT_PREFI mode={mode} uv_mode={uv_mode} enable_filter_intra={} \ + class={:?} rng={rng}", + enable_filter_intra as i32, + filter_intra_size_class_rect(bw, bh) + ); + } if mode == DC_PRED && enable_filter_intra && let Some(class) = filter_intra_size_class_rect(bw, bh) { let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0; + if std::env::var_os("EC_AV1_TRACE").is_some() { + eprintln!("TRACE_RECT_USEFI value={}", use_filter_intra as i32); + } if use_filter_intra { FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode); @@ -2061,6 +2073,7 @@ fn decode_block_rect( enable_filter_intra: bool, allow_screen_content_tools: bool, base_q_idx: u8, + tx_select: bool, ) -> Result<()> { let (r, c) = at; let (px, py) = (c * SUB, r * SUB); @@ -2093,8 +2106,19 @@ fn decode_block_rect( uv_mode }; let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); - let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); - let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]); + // The tx-depth symbol EXISTS only under TX_MODE_SELECT. Both square paths + // gate their `read_tx_size` on `tx_select` for exactly this reason; this + // one did not, so with `--enable-tx-size-search=0` -- which several gate + // recipes use -- the decoder consumed a symbol the encoder never wrote and + // desynced the tile from that point on. That is why both strips of the + // pinned HORZ quadrant were wrong from their very first pixel, and why our + // range after the read equalled the oracle's range for the whole block. + let depth = if tx_select { + let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); + dec.symbol(&mut cdfs.tx_size_cat2[ctx]) + } else { + 0 + }; if depth != 0 { TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); // A split transform is predicted per transform unit, each taking its @@ -2111,6 +2135,14 @@ fn decode_block_rect( let (cpx, cpy) = (px / 2, py / 2); let (chroma_w, chroma_h) = (bw / 2, bh / 2); let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height); + if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!( + "TRACE_RECT_IMODE mi_row={mi_r} mi_col={mi_c} mode={mode} uv_mode={uv_mode} \ + skip={} tx={depth} rng={rng}", + skip as i32 + ); + } if skip { y.reconstruct_rect( px, @@ -2185,13 +2217,26 @@ fn decode_block_rect( // lanes/rectwire-r3.report.md for what was ruled out (base_ctx_rect's // 5-neighbour offsets, u/v_skip_ctx's above+left formula, and // dc_sign_ctx's around-index all cross-checked byte-for-byte against - // libaom and match). Refusing by name again (r1 behavior) rather than - // risk landing the desync. - return Err(unsupported( - "a HORZ/VERT intra strip with real (non-skip) coefficients \ - (lane-rectwire r3: confirmed desync, not yet isolated)", - )); - #[allow(unreachable_code)] + // libaom and match). lane-rectwire r4: range-ladder against the + // now-instrumented oracle (EC_TRACE_MODE's intra EC_IMODE/EC_IMODE_VAL) + // narrowed the divergence past skip/y_mode/uv_mode (values AND range + // both confirmed in sync -- rng=58692 on both sides right after + // uv_mode, with `enable_filter_intra=0` on this frame so neither side + // reads a filter_intra symbol) to the `tx_size_cat2` depth read + // immediately after: ours moves rng 58692 -> 43570, which cannot be + // reconciled with oracle's own EC_IMODE_VAL (rng=58692, taken *after* + // its own tx_size read) unless oracle's tx symbol is a near-certainty + // CDF that barely narrows the range -- i.e. this decoder's + // `tx_size_context_rect` ctx or `cdfs.tx_size_cat2` CDF selection for + // a 32x16/16x32 strip is the first diverging symbol, not the + // coefficient-context math r3 already cleared. Not confirmed byte- + // exact (would need a decodemv.c EC_TRACE_MODE patch specifically on + // `read_tx_size`'s own rng, not attempted this round -- budget), so + // r5 CONFIRMED the suspect and it was simpler than the CDF row: the + // tx-depth symbol exists only under TX_MODE_SELECT, and this path read + // it unconditionally where both square paths gate on `tx_select`. With + // --enable-tx-size-search=0 the encoder writes no such symbol, so the + // decoder consumed one that was never there. { let around = neighbours.around_rect(at, bw, bh); let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); @@ -2205,6 +2250,10 @@ fn decode_block_rect( dc_sign_ctx(around[0].2), TxType::DctDct, )?; + if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("TRACE_RECT_COEFF plane=0 mi_row={mi_r} mi_col={mi_c} rng={rng}"); + } let luma_residual = dequant_and_inverse_typed_wh( &luma_levels, bw, @@ -2239,6 +2288,10 @@ fn decode_block_rect( dc_sign_ctx(around[1].2), u_default_tx, )?; + if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("TRACE_RECT_COEFF plane=1 mi_row={mi_r} mi_col={mi_c} rng={rng}"); + } let u_residual = dequant_and_inverse_typed_wh( &u_levels, chroma_w, @@ -2272,6 +2325,10 @@ fn decode_block_rect( dc_sign_ctx(around[2].2), v_default_tx, )?; + if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); + eprintln!("TRACE_RECT_COEFF plane=2 mi_row={mi_r} mi_col={mi_c} rng={rng}"); + } let v_residual = dequant_and_inverse_typed_wh( &v_levels, chroma_w, @@ -4565,8 +4622,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( let part32 = if has_cols32 && has_rows32 { let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); if std::env::var_os("EC_AV1_TRACE").is_some() { + let (rng, _) = dec.debug_state(); eprintln!( - "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}", + "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}", r32 * BLOCK_MI, c32 * BLOCK_MI ); @@ -4821,6 +4879,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( enable_filter_intra, allow_screen_content_tools, base_q_idx, + tx_select, )?; decode_block_rect( &mut dec, @@ -4835,6 +4894,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( enable_filter_intra, allow_screen_content_tools, base_q_idx, + tx_select, )?; } PARTITION_VERT => { @@ -4853,6 +4913,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( enable_filter_intra, allow_screen_content_tools, base_q_idx, + tx_select, )?; decode_block_rect( &mut dec, @@ -4867,6 +4928,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( enable_filter_intra, allow_screen_content_tools, base_q_idx, + tx_select, )?; } _ => { diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 8e4d6748..20ff033d 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -4237,18 +4237,18 @@ mod tests { "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \ ({matched} matches, {named_refusals} refusals); sampling, not a regression" ); - } else if crate::decode::rect_coeff_hits() == 0 { - // lane-rectwire r3: r2's real (non-skip) coefficient decode - // desyncs (rectwire-flake-1.obu, seed 55 -- both 32x16 strips of - // a fired quadrant come out ~100% wrong from their first pixel; - // see lanes/rectwire-r3.report.md). Reverted to refusing a coded - // rect strip by name, same as r1, so `rect_coeff_hits` is always - // 0 now -- this used to be a hard assert (r2), downgraded back to - // a SOFT-NOTE until the desync is isolated and the real decode - // path is safe to re-enable. - eprintln!( - "{NAME}: SOFT-NOTE -- {} HORZ/VERT strips fired but rect_coeff_hits==0 \ - (r3: non-skip rect strips refuse by name pending the desync fix)", + } else { + // r5: the desync was the tx-depth symbol being read + // unconditionally where both square paths gate it on `tx_select` + // -- with --enable-tx-size-search=0 the encoder writes no such + // symbol and the decoder consumed one that was never there. With + // that fixed the real coefficient decode is pixel-exact, so this + // is a HARD assert again: strips fired but no coefficients read + // would mean the coded path silently stopped being exercised. + assert!( + crate::decode::rect_coeff_hits() > 0, + "{NAME}: {} HORZ/VERT strips fired but rect_coeff_hits==0 -- the \ + coded rect path is no longer exercised", crate::decode::rect_partition_hits() ); } diff --git a/lanes/rectwire-r4.report.md b/lanes/rectwire-r4.report.md new file mode 100644 index 00000000..aeee6e2d --- /dev/null +++ b/lanes/rectwire-r4.report.md @@ -0,0 +1,52 @@ +# lane-rectwire r4/r5 report + +VERDICT: FIXED — the rect coefficient decode is live and pixel-exact. The +free-partition gate reports `rect_coeff_hits=38` with 15 pixel-exact matches +and 0 mismatches, and `rect_coeff_hits > 0` is a hard assert again. + +## Root cause +`decode_block_rect` read the tx-depth symbol unconditionally: + + let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); + let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]); + +That symbol exists only under `TX_MODE_SELECT`. Both square paths gate their +`read_tx_size` on `tx_select` for exactly this reason; the rect path did not. +Several gate recipes pass `--enable-tx-size-search=0`, so the encoder wrote no +such symbol and the decoder consumed one that was never there — desyncing the +tile from that point on. + +That is why both 32x16 strips of the pinned HORZ quadrant were wrong from their +very first pixel: not a subtle context bug, an off-by-one-symbol. + +## The evidence that named it +r4's range ladder, read correctly, had already pinned it. Its numbers: +- entry into the mi(8,8) strip in sync — ours `rng=37856`, oracle `EC_IMODE + rng=37856`; +- `skip`, `y_mode`, `uv_mode` identical values on both sides, our range after + `uv_mode` = 58692; +- oracle's `EC_IMODE_VAL`, printed AFTER its own tx read, = 58692; +- ours after our tx read = 43570. + +r4 read that as "our tx CDF row or context must be wrong" and refused to land +on an unconfirmed suspect, which was the right call on the evidence it had. But +the oracle's range being UNCHANGED across its whole block is the tell: the +oracle read no tx symbol at all. Equal ranges either side of a symbol means the +symbol was never consumed — that is a cheaper conclusion than a near-certain +CDF, and it needs no further instrumentation. + +## Before / after +- r3/r4 posture: non-skip rect strips refused by name; 29 refusals, 11 matches, + `rect_coeff_hits=0`. +- now: 25 named refusals, 15 pixel-exact matches of 40, + `rect_partition_hits=75`, `rect_coeff_hits=38`, 0 mismatches. +- full lib suite green in this worktree. + +Remaining refusals in that gate are other named gaps: rect strips in +screen-content frames (palette syntax is consumed for square blocks only), the +inter-path non-skip rect strip, and partition types this decoder does not code. + +## Class +`symbol-consumption-gap`, and the reading rule is worth keeping: when a range +ladder shows the reference's range UNCHANGED across a region where ours moves, +suspect a symbol we read and it did not, before suspecting our tables.