forge
Explore
Log in

Don't you dare go Hollow

Gate the rect strip's tx-depth read on tx_select

Browse files at this commit

8a896ab9affaeded176713d3e50ca06dd995c383Ahmet Kaan GümüşParent: 2ea3bfc
  • fix
    • gate the rect strip's tx-depth read on tx_select
Show full message
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.rsmodified+23 -10
@@ -1997,6 +1997,7 @@ fn decode_block_rect(
19971997 enable_filter_intra: bool,
19981998 allow_screen_content_tools: bool,
19991999 base_q_idx: u8,
2000+ tx_select: bool,
20002001 ) -> Result<()> {
20012002 let (r, c) = at;
20022003 let (px, py) = (c * SUB, r * SUB);
@@ -2029,8 +2030,19 @@ fn decode_block_rect(
20292030 uv_mode
20302031 };
20312032 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
2032- let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
2033- let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
2033+ // The tx-depth symbol EXISTS only under TX_MODE_SELECT. Both square paths
2034+ // gate their `read_tx_size` on `tx_select` for exactly this reason; this
2035+ // one did not, so with `--enable-tx-size-search=0` -- which several gate
2036+ // recipes use -- the decoder consumed a symbol the encoder never wrote and
2037+ // desynced the tile from that point on. That is why both strips of the
2038+ // pinned HORZ quadrant were wrong from their very first pixel, and why our
2039+ // range after the read equalled the oracle's range for the whole block.
2040+ let depth = if tx_select {
2041+ let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
2042+ dec.symbol(&mut cdfs.tx_size_cat2[ctx])
2043+ } else {
2044+ 0
2045+ };
20342046 if depth != 0 {
20352047 TX_DEPTH_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
20362048 // A split transform is predicted per transform unit, each taking its
@@ -2144,14 +2156,11 @@ fn decode_block_rect(
21442156 // coefficient-context math r3 already cleared. Not confirmed byte-
21452157 // exact (would need a decodemv.c EC_TRACE_MODE patch specifically on
21462158 // `read_tx_size`'s own rng, not attempted this round -- budget), so
2147- // still refusing by name rather than risk landing a partial fix on a
2148- // named-but-unconfirmed suspect.
2149- return Err(unsupported(
2150- "a HORZ/VERT intra strip with real (non-skip) coefficients \
2151- (lane-rectwire r4: divergence narrowed to the tx_size_cat2 depth \
2152- read, not yet byte-confirmed)",
2153- ));
2154- #[allow(unreachable_code)]
2159+ // r5 CONFIRMED the suspect and it was simpler than the CDF row: the
2160+ // tx-depth symbol exists only under TX_MODE_SELECT, and this path read
2161+ // it unconditionally where both square paths gate on `tx_select`. With
2162+ // --enable-tx-size-search=0 the encoder writes no such symbol, so the
2163+ // decoder consumed one that was never there.
21552164 {
21562165 let around = neighbours.around_rect(at, bw, bh);
21572166 let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode);
@@ -4794,6 +4803,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
47944803 enable_filter_intra,
47954804 allow_screen_content_tools,
47964805 base_q_idx,
4806+ tx_select,
47974807 )?;
47984808 decode_block_rect(
47994809 &mut dec,
@@ -4808,6 +4818,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
48084818 enable_filter_intra,
48094819 allow_screen_content_tools,
48104820 base_q_idx,
4821+ tx_select,
48114822 )?;
48124823 }
48134824 PARTITION_VERT => {
@@ -4826,6 +4837,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
48264837 enable_filter_intra,
48274838 allow_screen_content_tools,
48284839 base_q_idx,
4840+ tx_select,
48294841 )?;
48304842 decode_block_rect(
48314843 &mut dec,
@@ -4840,6 +4852,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
48404852 enable_filter_intra,
48414853 allow_screen_content_tools,
48424854 base_q_idx,
4855+ tx_select,
48434856 )?;
48444857 }
48454858 _ => {
crates/ec-av1/src/stream.rsmodified+12 -12
@@ -4185,18 +4185,18 @@ mod tests {
41854185 "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \
41864186 ({matched} matches, {named_refusals} refusals); sampling, not a regression"
41874187 );
4188- } else if crate::decode::rect_coeff_hits() == 0 {
4189- // lane-rectwire r3: r2's real (non-skip) coefficient decode
4190- // desyncs (rectwire-flake-1.obu, seed 55 -- both 32x16 strips of
4191- // a fired quadrant come out ~100% wrong from their first pixel;
4192- // see lanes/rectwire-r3.report.md). Reverted to refusing a coded
4193- // rect strip by name, same as r1, so `rect_coeff_hits` is always
4194- // 0 now -- this used to be a hard assert (r2), downgraded back to
4195- // a SOFT-NOTE until the desync is isolated and the real decode
4196- // path is safe to re-enable.
4197- eprintln!(
4198- "{NAME}: SOFT-NOTE -- {} HORZ/VERT strips fired but rect_coeff_hits==0 \
4199- (r3: non-skip rect strips refuse by name pending the desync fix)",
4188+ } else {
4189+ // r5: the desync was the tx-depth symbol being read
4190+ // unconditionally where both square paths gate it on `tx_select`
4191+ // -- with --enable-tx-size-search=0 the encoder writes no such
4192+ // symbol and the decoder consumed one that was never there. With
4193+ // that fixed the real coefficient decode is pixel-exact, so this
4194+ // is a HARD assert again: strips fired but no coefficients read
4195+ // would mean the coded path silently stopped being exercised.
4196+ assert!(
4197+ crate::decode::rect_coeff_hits() > 0,
4198+ "{NAME}: {} HORZ/VERT strips fired but rect_coeff_hits==0 -- the \
4199+ coded rect path is no longer exercised",
42004200 crate::decode::rect_partition_hits()
42014201 );
42024202 }
lanes/rectwire-r4.report.mdadded+52 -0
@@ -0,0 +1,52 @@
1+# lane-rectwire r4/r5 report
2+
3+VERDICT: FIXED — the rect coefficient decode is live and pixel-exact. The
4+free-partition gate reports `rect_coeff_hits=38` with 15 pixel-exact matches
5+and 0 mismatches, and `rect_coeff_hits > 0` is a hard assert again.
6+
7+## Root cause
8+`decode_block_rect` read the tx-depth symbol unconditionally:
9+
10+ let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
11+ let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
12+
13+That symbol exists only under `TX_MODE_SELECT`. Both square paths gate their
14+`read_tx_size` on `tx_select` for exactly this reason; the rect path did not.
15+Several gate recipes pass `--enable-tx-size-search=0`, so the encoder wrote no
16+such symbol and the decoder consumed one that was never there — desyncing the
17+tile from that point on.
18+
19+That is why both 32x16 strips of the pinned HORZ quadrant were wrong from their
20+very first pixel: not a subtle context bug, an off-by-one-symbol.
21+
22+## The evidence that named it
23+r4's range ladder, read correctly, had already pinned it. Its numbers:
24+- entry into the mi(8,8) strip in sync — ours `rng=37856`, oracle `EC_IMODE
25+ rng=37856`;
26+- `skip`, `y_mode`, `uv_mode` identical values on both sides, our range after
27+ `uv_mode` = 58692;
28+- oracle's `EC_IMODE_VAL`, printed AFTER its own tx read, = 58692;
29+- ours after our tx read = 43570.
30+
31+r4 read that as "our tx CDF row or context must be wrong" and refused to land
32+on an unconfirmed suspect, which was the right call on the evidence it had. But
33+the oracle's range being UNCHANGED across its whole block is the tell: the
34+oracle read no tx symbol at all. Equal ranges either side of a symbol means the
35+symbol was never consumed — that is a cheaper conclusion than a near-certain
36+CDF, and it needs no further instrumentation.
37+
38+## Before / after
39+- r3/r4 posture: non-skip rect strips refused by name; 29 refusals, 11 matches,
40+ `rect_coeff_hits=0`.
41+- now: 25 named refusals, 15 pixel-exact matches of 40,
42+ `rect_partition_hits=75`, `rect_coeff_hits=38`, 0 mismatches.
43+- full lib suite green in this worktree.
44+
45+Remaining refusals in that gate are other named gaps: rect strips in
46+screen-content frames (palette syntax is consumed for square blocks only), the
47+inter-path non-skip rect strip, and partition types this decoder does not code.
48+
49+## Class
50+`symbol-consumption-gap`, and the reading rule is worth keeping: when a range
51+ladder shows the reference's range UNCHANGED across a region where ours moves,
52+suspect a symbol we read and it did not, before suspecting our tables.