Merge branch 'lane-rectwire2': rect coefficient decode lands, pixel-exact
Browse files at this commit3 changed files +136 -22
- crates/ec-av1/src/decode.rs +72 -10
- crates/ec-av1/src/stream.rs +12 -12
- lanes/rectwire-r4.report.md +52 -0
crates/ec-av1/src/decode.rsmodified+72 -10
| @@ -1976,11 +1976,23 @@ fn read_intra_mode_rect( | ||
| 1976 | 1976 | 0 |
| 1977 | 1977 | }; |
| 1978 | 1978 | 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 | + } | |
| 1979 | 1988 | if mode == DC_PRED |
| 1980 | 1989 | && enable_filter_intra |
| 1981 | 1990 | && let Some(class) = filter_intra_size_class_rect(bw, bh) |
| 1982 | 1991 | { |
| 1983 | 1992 | 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 | + } | |
| 1984 | 1996 | if use_filter_intra { |
| 1985 | 1997 | FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1)); |
| 1986 | 1998 | let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode); |
| @@ -2061,6 +2073,7 @@ fn decode_block_rect( | ||
| 2061 | 2073 | enable_filter_intra: bool, |
| 2062 | 2074 | allow_screen_content_tools: bool, |
| 2063 | 2075 | base_q_idx: u8, |
| 2076 | + tx_select: bool, | |
| 2064 | 2077 | ) -> Result<()> { |
| 2065 | 2078 | let (r, c) = at; |
| 2066 | 2079 | let (px, py) = (c * SUB, r * SUB); |
| @@ -2093,8 +2106,19 @@ fn decode_block_rect( | ||
| 2093 | 2106 | uv_mode |
| 2094 | 2107 | }; |
| 2095 | 2108 | 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 | + }; | |
| 2098 | 2122 | if depth != 0 { |
| 2099 | 2123 | TX_DEPTH_HITS.with(|c| c.set(c.get() + 1)); |
| 2100 | 2124 | // A split transform is predicted per transform unit, each taking its |
| @@ -2111,6 +2135,14 @@ fn decode_block_rect( | ||
| 2111 | 2135 | let (cpx, cpy) = (px / 2, py / 2); |
| 2112 | 2136 | let (chroma_w, chroma_h) = (bw / 2, bh / 2); |
| 2113 | 2137 | 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 | + } | |
| 2114 | 2146 | if skip { |
| 2115 | 2147 | y.reconstruct_rect( |
| 2116 | 2148 | px, |
| @@ -2185,13 +2217,26 @@ fn decode_block_rect( | ||
| 2185 | 2217 | // lanes/rectwire-r3.report.md for what was ruled out (base_ctx_rect's |
| 2186 | 2218 | // 5-neighbour offsets, u/v_skip_ctx's above+left formula, and |
| 2187 | 2219 | // 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. | |
| 2195 | 2240 | { |
| 2196 | 2241 | let around = neighbours.around_rect(at, bw, bh); |
| 2197 | 2242 | let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); |
| @@ -2205,6 +2250,10 @@ fn decode_block_rect( | ||
| 2205 | 2250 | dc_sign_ctx(around[0].2), |
| 2206 | 2251 | TxType::DctDct, |
| 2207 | 2252 | )?; |
| 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 | + } | |
| 2208 | 2257 | let luma_residual = dequant_and_inverse_typed_wh( |
| 2209 | 2258 | &luma_levels, |
| 2210 | 2259 | bw, |
| @@ -2239,6 +2288,10 @@ fn decode_block_rect( | ||
| 2239 | 2288 | dc_sign_ctx(around[1].2), |
| 2240 | 2289 | u_default_tx, |
| 2241 | 2290 | )?; |
| 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 | + } | |
| 2242 | 2295 | let u_residual = dequant_and_inverse_typed_wh( |
| 2243 | 2296 | &u_levels, |
| 2244 | 2297 | chroma_w, |
| @@ -2272,6 +2325,10 @@ fn decode_block_rect( | ||
| 2272 | 2325 | dc_sign_ctx(around[2].2), |
| 2273 | 2326 | v_default_tx, |
| 2274 | 2327 | )?; |
| 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 | + } | |
| 2275 | 2332 | let v_residual = dequant_and_inverse_typed_wh( |
| 2276 | 2333 | &v_levels, |
| 2277 | 2334 | chroma_w, |
| @@ -4565,8 +4622,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 4565 | 4622 | let part32 = if has_cols32 && has_rows32 { |
| 4566 | 4623 | let p = dec.symbol(&mut cdfs.partition_w32[ctx32]); |
| 4567 | 4624 | if std::env::var_os("EC_AV1_TRACE").is_some() { |
| 4625 | + let (rng, _) = dec.debug_state(); | |
| 4568 | 4626 | eprintln!( |
| 4569 | - "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}", | |
| 4627 | + "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}", | |
| 4570 | 4628 | r32 * BLOCK_MI, |
| 4571 | 4629 | c32 * BLOCK_MI |
| 4572 | 4630 | ); |
| @@ -4821,6 +4879,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 4821 | 4879 | enable_filter_intra, |
| 4822 | 4880 | allow_screen_content_tools, |
| 4823 | 4881 | base_q_idx, |
| 4882 | + tx_select, | |
| 4824 | 4883 | )?; |
| 4825 | 4884 | decode_block_rect( |
| 4826 | 4885 | &mut dec, |
| @@ -4835,6 +4894,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 4835 | 4894 | enable_filter_intra, |
| 4836 | 4895 | allow_screen_content_tools, |
| 4837 | 4896 | base_q_idx, |
| 4897 | + tx_select, | |
| 4838 | 4898 | )?; |
| 4839 | 4899 | } |
| 4840 | 4900 | PARTITION_VERT => { |
| @@ -4853,6 +4913,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 4853 | 4913 | enable_filter_intra, |
| 4854 | 4914 | allow_screen_content_tools, |
| 4855 | 4915 | base_q_idx, |
| 4916 | + tx_select, | |
| 4856 | 4917 | )?; |
| 4857 | 4918 | decode_block_rect( |
| 4858 | 4919 | &mut dec, |
| @@ -4867,6 +4928,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | ||
| 4867 | 4928 | enable_filter_intra, |
| 4868 | 4929 | allow_screen_content_tools, |
| 4869 | 4930 | base_q_idx, |
| 4931 | + tx_select, | |
| 4870 | 4932 | )?; |
| 4871 | 4933 | } |
| 4872 | 4934 | _ => { |
crates/ec-av1/src/stream.rsmodified+12 -12
| @@ -4237,18 +4237,18 @@ mod tests { | ||
| 4237 | 4237 | "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \ |
| 4238 | 4238 | ({matched} matches, {named_refusals} refusals); sampling, not a regression" |
| 4239 | 4239 | ); |
| 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", | |
| 4252 | 4252 | crate::decode::rect_partition_hits() |
| 4253 | 4253 | ); |
| 4254 | 4254 | } |
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. |