forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-rectwire2': rect coefficient decode lands, pixel-exact

Browse files at this commit

94033afef9f658e901ff7644bee01899aa18062aAhmet Kaan GümüşParent: 5c21ffa8a896ab
The desync that held this lane for three rounds was an extra symbol, not a
wrong table. decode_block_rect read the tx-depth symbol unconditionally, where
both square paths gate their read_tx_size on `tx_select`. That symbol exists
only under TX_MODE_SELECT, and several gate recipes pass
--enable-tx-size-search=0, so the encoder wrote none 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 were wrong from their first pixel.

r4's own range ladder had already named it without recognising it: 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 -- a cheaper conclusion than a near-certain CDF, and it needed no
further instrumentation. r4 read it as a wrong CDF row and refused to land on
an unconfirmed suspect, which was the right call on the evidence it had.

Free-partition gate: 15 pixel-exact matches of 40 with zero mismatches and
rect_coeff_hits=38, against 11 matches and rect_coeff_hits=0 under the
refuse-by-name posture. The firing count is a hard assert again.

Full lib suite 232 passed / 0 failed.
crates/ec-av1/src/decode.rsmodified+72 -10
@@ -1976,11 +1976,23 @@ fn read_intra_mode_rect(
19761976 0
19771977 };
19781978 let mut filter_intra = None;
1979+ if std::env::var_os("EC_AV1_TRACE").is_some() {
1980+ let (rng, _) = dec.debug_state();
1981+ eprintln!(
1982+ "TRACE_RECT_PREFI mode={mode} uv_mode={uv_mode} enable_filter_intra={} \
1983+ class={:?} rng={rng}",
1984+ enable_filter_intra as i32,
1985+ filter_intra_size_class_rect(bw, bh)
1986+ );
1987+ }
19791988 if mode == DC_PRED
19801989 && enable_filter_intra
19811990 && let Some(class) = filter_intra_size_class_rect(bw, bh)
19821991 {
19831992 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
1993+ if std::env::var_os("EC_AV1_TRACE").is_some() {
1994+ eprintln!("TRACE_RECT_USEFI value={}", use_filter_intra as i32);
1995+ }
19841996 if use_filter_intra {
19851997 FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1));
19861998 let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);
@@ -2061,6 +2073,7 @@ fn decode_block_rect(
20612073 enable_filter_intra: bool,
20622074 allow_screen_content_tools: bool,
20632075 base_q_idx: u8,
2076+ tx_select: bool,
20642077 ) -> Result<()> {
20652078 let (r, c) = at;
20662079 let (px, py) = (c * SUB, r * SUB);
@@ -2093,8 +2106,19 @@ fn decode_block_rect(
20932106 uv_mode
20942107 };
20952108 let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI));
2096- let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
2097- let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
2109+ // The tx-depth symbol EXISTS only under TX_MODE_SELECT. Both square paths
2110+ // gate their `read_tx_size` on `tx_select` for exactly this reason; this
2111+ // one did not, so with `--enable-tx-size-search=0` -- which several gate
2112+ // recipes use -- the decoder consumed a symbol the encoder never wrote and
2113+ // desynced the tile from that point on. That is why both strips of the
2114+ // pinned HORZ quadrant were wrong from their very first pixel, and why our
2115+ // range after the read equalled the oracle's range for the whole block.
2116+ let depth = if tx_select {
2117+ let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
2118+ dec.symbol(&mut cdfs.tx_size_cat2[ctx])
2119+ } else {
2120+ 0
2121+ };
20982122 if depth != 0 {
20992123 TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));
21002124 // A split transform is predicted per transform unit, each taking its
@@ -2111,6 +2135,14 @@ fn decode_block_rect(
21112135 let (cpx, cpy) = (px / 2, py / 2);
21122136 let (chroma_w, chroma_h) = (bw / 2, bh / 2);
21132137 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height);
2138+ if std::env::var_os("EC_AV1_TRACE").is_some() {
2139+ let (rng, _) = dec.debug_state();
2140+ eprintln!(
2141+ "TRACE_RECT_IMODE mi_row={mi_r} mi_col={mi_c} mode={mode} uv_mode={uv_mode} \
2142+ skip={} tx={depth} rng={rng}",
2143+ skip as i32
2144+ );
2145+ }
21142146 if skip {
21152147 y.reconstruct_rect(
21162148 px,
@@ -2185,13 +2217,26 @@ fn decode_block_rect(
21852217 // lanes/rectwire-r3.report.md for what was ruled out (base_ctx_rect's
21862218 // 5-neighbour offsets, u/v_skip_ctx's above+left formula, and
21872219 // dc_sign_ctx's around-index all cross-checked byte-for-byte against
2188- // libaom and match). Refusing by name again (r1 behavior) rather than
2189- // risk landing the desync.
2190- return Err(unsupported(
2191- "a HORZ/VERT intra strip with real (non-skip) coefficients \
2192- (lane-rectwire r3: confirmed desync, not yet isolated)",
2193- ));
2194- #[allow(unreachable_code)]
2220+ // libaom and match). lane-rectwire r4: range-ladder against the
2221+ // now-instrumented oracle (EC_TRACE_MODE's intra EC_IMODE/EC_IMODE_VAL)
2222+ // narrowed the divergence past skip/y_mode/uv_mode (values AND range
2223+ // both confirmed in sync -- rng=58692 on both sides right after
2224+ // uv_mode, with `enable_filter_intra=0` on this frame so neither side
2225+ // reads a filter_intra symbol) to the `tx_size_cat2` depth read
2226+ // immediately after: ours moves rng 58692 -> 43570, which cannot be
2227+ // reconciled with oracle's own EC_IMODE_VAL (rng=58692, taken *after*
2228+ // its own tx_size read) unless oracle's tx symbol is a near-certainty
2229+ // CDF that barely narrows the range -- i.e. this decoder's
2230+ // `tx_size_context_rect` ctx or `cdfs.tx_size_cat2` CDF selection for
2231+ // a 32x16/16x32 strip is the first diverging symbol, not the
2232+ // coefficient-context math r3 already cleared. Not confirmed byte-
2233+ // exact (would need a decodemv.c EC_TRACE_MODE patch specifically on
2234+ // `read_tx_size`'s own rng, not attempted this round -- budget), so
2235+ // r5 CONFIRMED the suspect and it was simpler than the CDF row: the
2236+ // tx-depth symbol exists only under TX_MODE_SELECT, and this path read
2237+ // it unconditionally where both square paths gate on `tx_select`. With
2238+ // --enable-tx-size-search=0 the encoder writes no such symbol, so the
2239+ // decoder consumed one that was never there.
21952240 {
21962241 let around = neighbours.around_rect(at, bw, bh);
21972242 let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode);
@@ -2205,6 +2250,10 @@ fn decode_block_rect(
22052250 dc_sign_ctx(around[0].2),
22062251 TxType::DctDct,
22072252 )?;
2253+ if std::env::var_os("EC_AV1_TRACE").is_some() {
2254+ let (rng, _) = dec.debug_state();
2255+ eprintln!("TRACE_RECT_COEFF plane=0 mi_row={mi_r} mi_col={mi_c} rng={rng}");
2256+ }
22082257 let luma_residual = dequant_and_inverse_typed_wh(
22092258 &luma_levels,
22102259 bw,
@@ -2239,6 +2288,10 @@ fn decode_block_rect(
22392288 dc_sign_ctx(around[1].2),
22402289 u_default_tx,
22412290 )?;
2291+ if std::env::var_os("EC_AV1_TRACE").is_some() {
2292+ let (rng, _) = dec.debug_state();
2293+ eprintln!("TRACE_RECT_COEFF plane=1 mi_row={mi_r} mi_col={mi_c} rng={rng}");
2294+ }
22422295 let u_residual = dequant_and_inverse_typed_wh(
22432296 &u_levels,
22442297 chroma_w,
@@ -2272,6 +2325,10 @@ fn decode_block_rect(
22722325 dc_sign_ctx(around[2].2),
22732326 v_default_tx,
22742327 )?;
2328+ if std::env::var_os("EC_AV1_TRACE").is_some() {
2329+ let (rng, _) = dec.debug_state();
2330+ eprintln!("TRACE_RECT_COEFF plane=2 mi_row={mi_r} mi_col={mi_c} rng={rng}");
2331+ }
22752332 let v_residual = dequant_and_inverse_typed_wh(
22762333 &v_levels,
22772334 chroma_w,
@@ -4565,8 +4622,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
45654622 let part32 = if has_cols32 && has_rows32 {
45664623 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);
45674624 if std::env::var_os("EC_AV1_TRACE").is_some() {
4625+ let (rng, _) = dec.debug_state();
45684626 eprintln!(
4569- "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}",
4627+ "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}",
45704628 r32 * BLOCK_MI,
45714629 c32 * BLOCK_MI
45724630 );
@@ -4821,6 +4879,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
48214879 enable_filter_intra,
48224880 allow_screen_content_tools,
48234881 base_q_idx,
4882+ tx_select,
48244883 )?;
48254884 decode_block_rect(
48264885 &mut dec,
@@ -4835,6 +4894,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
48354894 enable_filter_intra,
48364895 allow_screen_content_tools,
48374896 base_q_idx,
4897+ tx_select,
48384898 )?;
48394899 }
48404900 PARTITION_VERT => {
@@ -4853,6 +4913,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
48534913 enable_filter_intra,
48544914 allow_screen_content_tools,
48554915 base_q_idx,
4916+ tx_select,
48564917 )?;
48574918 decode_block_rect(
48584919 &mut dec,
@@ -4867,6 +4928,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
48674928 enable_filter_intra,
48684929 allow_screen_content_tools,
48694930 base_q_idx,
4931+ tx_select,
48704932 )?;
48714933 }
48724934 _ => {
crates/ec-av1/src/stream.rsmodified+12 -12
@@ -4237,18 +4237,18 @@ mod tests {
42374237 "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \
42384238 ({matched} matches, {named_refusals} refusals); sampling, not a regression"
42394239 );
4240- } else if crate::decode::rect_coeff_hits() == 0 {
4241- // lane-rectwire r3: r2's real (non-skip) coefficient decode
4242- // desyncs (rectwire-flake-1.obu, seed 55 -- both 32x16 strips of
4243- // a fired quadrant come out ~100% wrong from their first pixel;
4244- // see lanes/rectwire-r3.report.md). Reverted to refusing a coded
4245- // rect strip by name, same as r1, so `rect_coeff_hits` is always
4246- // 0 now -- this used to be a hard assert (r2), downgraded back to
4247- // a SOFT-NOTE until the desync is isolated and the real decode
4248- // path is safe to re-enable.
4249- eprintln!(
4250- "{NAME}: SOFT-NOTE -- {} HORZ/VERT strips fired but rect_coeff_hits==0 \
4251- (r3: non-skip rect strips refuse by name pending the desync fix)",
4240+ } else {
4241+ // r5: the desync was the tx-depth symbol being read
4242+ // unconditionally where both square paths gate it on `tx_select`
4243+ // -- with --enable-tx-size-search=0 the encoder writes no such
4244+ // symbol and the decoder consumed one that was never there. With
4245+ // that fixed the real coefficient decode is pixel-exact, so this
4246+ // is a HARD assert again: strips fired but no coefficients read
4247+ // would mean the coded path silently stopped being exercised.
4248+ assert!(
4249+ crate::decode::rect_coeff_hits() > 0,
4250+ "{NAME}: {} HORZ/VERT strips fired but rect_coeff_hits==0 -- the \
4251+ coded rect path is no longer exercised",
42524252 crate::decode::rect_partition_hits()
42534253 );
42544254 }
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.