From 8a896ab9affaeded176713d3e50ca06dd995c383 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Sun, 30 Aug 2026 10:27:05 +0300 Subject: [PATCH] fix(av1): gate the rect strip's tx-depth read on tx_select The tx-depth symbol exists only under TX_MODE_SELECT. Both square paths gate their read_tx_size on `tx_select`; decode_block_rect read it unconditionally. 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 -- which is why both 32x16 strips of the pinned quadrant came out wrong from their very first pixel. r4's own range ladder had already named it without realising: the oracle's range was UNCHANGED across its whole block (58692 either side) while ours moved 58692 -> 43570. Equal ranges either side of a symbol mean the symbol was never consumed. r4 read it as a wrong CDF row and refused to land on an unconfirmed suspect, which was right on the evidence it had. With the read gated, the real coefficient decode is pixel-exact: the free-partition gate reports rect_coeff_hits=38 and 15 pixel-exact matches of 40 with zero mismatches, where the refuse-by-name posture gave 11 matches and rect_coeff_hits=0. The hard assert on the firing count is restored. Full lib suite 231 passed / 0 failed in this worktree. --- crates/ec-av1/src/decode.rs | 33 ++++++++++++++++------- crates/ec-av1/src/stream.rs | 24 ++++++++--------- lanes/rectwire-r4.report.md | 52 +++++++++++++++++++++++++++++++++++++ 3 files changed, 87 insertions(+), 22 deletions(-) create mode 100644 lanes/rectwire-r4.report.md diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index a2ff3c53..abe0c55f 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1997,6 +1997,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); @@ -2029,8 +2030,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.fetch_add(1, std::sync::atomic::Ordering::Relaxed); // A split transform is predicted per transform unit, each taking its @@ -2144,14 +2156,11 @@ fn decode_block_rect( // 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 - // still refusing by name rather than risk landing a partial fix on a - // named-but-unconfirmed suspect. - return Err(unsupported( - "a HORZ/VERT intra strip with real (non-skip) coefficients \ - (lane-rectwire r4: divergence narrowed to the tx_size_cat2 depth \ - read, not yet byte-confirmed)", - )); - #[allow(unreachable_code)] + // 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); @@ -4794,6 +4803,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, @@ -4808,6 +4818,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( enable_filter_intra, allow_screen_content_tools, base_q_idx, + tx_select, )?; } PARTITION_VERT => { @@ -4826,6 +4837,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, @@ -4840,6 +4852,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 533bf9b7..83d2417d 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -4185,18 +4185,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.