Gate the rect strip's tx-depth read on tx_select
Browse files at this commit8a896ab9affaeded176713d3e50ca06dd995c383Parent: 2ea3bfc- fix
- gate the rect strip's tx-depth read on tx_select
3 changed files +86 -21
- crates/ec-av1/src/decode.rs +22 -9
- crates/ec-av1/src/stream.rs +12 -12
- lanes/rectwire-r4.report.md +52 -0
crates/ec-av1/src/decode.rsmodified+22 -9
| @@ -1997,6 +1997,7 @@ fn decode_block_rect( | |||
| 1997 | enable_filter_intra: bool, | 1997 | enable_filter_intra: bool, |
| 1998 | allow_screen_content_tools: bool, | 1998 | allow_screen_content_tools: bool, |
| 1999 | base_q_idx: u8, | 1999 | base_q_idx: u8, |
| 2000 | + tx_select: bool, | ||
| 2000 | ) -> Result<()> { | 2001 | ) -> Result<()> { |
| 2001 | let (r, c) = at; | 2002 | let (r, c) = at; |
| 2002 | let (px, py) = (c * SUB, r * SUB); | 2003 | let (px, py) = (c * SUB, r * SUB); |
| @@ -2029,8 +2030,19 @@ fn decode_block_rect( | |||
| 2029 | uv_mode | 2030 | uv_mode |
| 2030 | }; | 2031 | }; |
| 2031 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); | 2032 | let (mi_r, mi_c) = (r * (SUB / MI), c * (SUB / MI)); |
| 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 { | ||
| 2032 | let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); | 2041 | let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh); |
| 2033 | - let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]); | 2042 | + dec.symbol(&mut cdfs.tx_size_cat2[ctx]) |
| 2043 | + } else { | ||
| 2044 | + 0 | ||
| 2045 | + }; | ||
| 2034 | if depth != 0 { | 2046 | if depth != 0 { |
| 2035 | TX_DEPTH_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 2047 | TX_DEPTH_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 2036 | // A split transform is predicted per transform unit, each taking its | 2048 | // A split transform is predicted per transform unit, each taking its |
| @@ -2144,14 +2156,11 @@ fn decode_block_rect( | |||
| 2144 | // coefficient-context math r3 already cleared. Not confirmed byte- | 2156 | // coefficient-context math r3 already cleared. Not confirmed byte- |
| 2145 | // exact (would need a decodemv.c EC_TRACE_MODE patch specifically on | 2157 | // exact (would need a decodemv.c EC_TRACE_MODE patch specifically on |
| 2146 | // `read_tx_size`'s own rng, not attempted this round -- budget), so | 2158 | // `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 | 2159 | + // r5 CONFIRMED the suspect and it was simpler than the CDF row: the |
| 2148 | - // named-but-unconfirmed suspect. | 2160 | + // tx-depth symbol exists only under TX_MODE_SELECT, and this path read |
| 2149 | - return Err(unsupported( | 2161 | + // it unconditionally where both square paths gate on `tx_select`. With |
| 2150 | - "a HORZ/VERT intra strip with real (non-skip) coefficients \ | 2162 | + // --enable-tx-size-search=0 the encoder writes no such symbol, so the |
| 2151 | - (lane-rectwire r4: divergence narrowed to the tx_size_cat2 depth \ | 2163 | + // decoder consumed one that was never there. |
| 2152 | - read, not yet byte-confirmed)", | ||
| 2153 | - )); | ||
| 2154 | - #[allow(unreachable_code)] | ||
| 2155 | { | 2164 | { |
| 2156 | let around = neighbours.around_rect(at, bw, bh); | 2165 | let around = neighbours.around_rect(at, bw, bh); |
| 2157 | let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); | 2166 | let mut luma_coding = cdfs.txb(TxbSet::LumaRect32x16, mode); |
| @@ -4794,6 +4803,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4794 | enable_filter_intra, | 4803 | enable_filter_intra, |
| 4795 | allow_screen_content_tools, | 4804 | allow_screen_content_tools, |
| 4796 | base_q_idx, | 4805 | base_q_idx, |
| 4806 | + tx_select, | ||
| 4797 | )?; | 4807 | )?; |
| 4798 | decode_block_rect( | 4808 | decode_block_rect( |
| 4799 | &mut dec, | 4809 | &mut dec, |
| @@ -4808,6 +4818,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4808 | enable_filter_intra, | 4818 | enable_filter_intra, |
| 4809 | allow_screen_content_tools, | 4819 | allow_screen_content_tools, |
| 4810 | base_q_idx, | 4820 | base_q_idx, |
| 4821 | + tx_select, | ||
| 4811 | )?; | 4822 | )?; |
| 4812 | } | 4823 | } |
| 4813 | PARTITION_VERT => { | 4824 | PARTITION_VERT => { |
| @@ -4826,6 +4837,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4826 | enable_filter_intra, | 4837 | enable_filter_intra, |
| 4827 | allow_screen_content_tools, | 4838 | allow_screen_content_tools, |
| 4828 | base_q_idx, | 4839 | base_q_idx, |
| 4840 | + tx_select, | ||
| 4829 | )?; | 4841 | )?; |
| 4830 | decode_block_rect( | 4842 | decode_block_rect( |
| 4831 | &mut dec, | 4843 | &mut dec, |
| @@ -4840,6 +4852,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( | |||
| 4840 | enable_filter_intra, | 4852 | enable_filter_intra, |
| 4841 | allow_screen_content_tools, | 4853 | allow_screen_content_tools, |
| 4842 | base_q_idx, | 4854 | base_q_idx, |
| 4855 | + tx_select, | ||
| 4843 | )?; | 4856 | )?; |
| 4844 | } | 4857 | } |
| 4845 | _ => { | 4858 | _ => { |
crates/ec-av1/src/stream.rsmodified+12 -12
| @@ -4185,18 +4185,18 @@ mod tests { | |||
| 4185 | "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \ | 4185 | "{NAME}: SOFT-NOTE -- zero HORZ/VERT strips fired this run \ |
| 4186 | ({matched} matches, {named_refusals} refusals); sampling, not a regression" | 4186 | ({matched} matches, {named_refusals} refusals); sampling, not a regression" |
| 4187 | ); | 4187 | ); |
| 4188 | - } else if crate::decode::rect_coeff_hits() == 0 { | 4188 | + } else { |
| 4189 | - // lane-rectwire r3: r2's real (non-skip) coefficient decode | 4189 | + // r5: the desync was the tx-depth symbol being read |
| 4190 | - // desyncs (rectwire-flake-1.obu, seed 55 -- both 32x16 strips of | 4190 | + // unconditionally where both square paths gate it on `tx_select` |
| 4191 | - // a fired quadrant come out ~100% wrong from their first pixel; | 4191 | + // -- with --enable-tx-size-search=0 the encoder writes no such |
| 4192 | - // see lanes/rectwire-r3.report.md). Reverted to refusing a coded | 4192 | + // symbol and the decoder consumed one that was never there. With |
| 4193 | - // rect strip by name, same as r1, so `rect_coeff_hits` is always | 4193 | + // that fixed the real coefficient decode is pixel-exact, so this |
| 4194 | - // 0 now -- this used to be a hard assert (r2), downgraded back to | 4194 | + // is a HARD assert again: strips fired but no coefficients read |
| 4195 | - // a SOFT-NOTE until the desync is isolated and the real decode | 4195 | + // would mean the coded path silently stopped being exercised. |
| 4196 | - // path is safe to re-enable. | 4196 | + assert!( |
| 4197 | - eprintln!( | 4197 | + crate::decode::rect_coeff_hits() > 0, |
| 4198 | - "{NAME}: SOFT-NOTE -- {} HORZ/VERT strips fired but rect_coeff_hits==0 \ | 4198 | + "{NAME}: {} HORZ/VERT strips fired but rect_coeff_hits==0 -- the \ |
| 4199 | - (r3: non-skip rect strips refuse by name pending the desync fix)", | 4199 | + coded rect path is no longer exercised", |
| 4200 | crate::decode::rect_partition_hits() | 4200 | crate::decode::rect_partition_hits() |
| 4201 | ); | 4201 | ); |
| 4202 | } | 4202 | } |
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. | ||