Merge lane-whtshape @ f541d062 — the lossless WHT shape-total fix
Browse files at this commit5 changed files +912 -45
- crates/ec-av1/fixtures/ll444_sb64_1to4_lossless.obu +0 -0
- crates/ec-av1/src/decode.rs +214 -42
- crates/ec-av1/src/stream.rs +200 -0
- crates/ec-av1/src/transform.rs +220 -3
- lanes/whtshape.report.md +278 -0
crates/ec-av1/fixtures/ll444_sb64_1to4_lossless.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+214 -42
| @@ -2890,6 +2890,30 @@ pub(crate) fn lossless_wht_units() -> usize { | |||
| 2890 | LOSSLESS_WHT_UNITS.load(std::sync::atomic::Ordering::Relaxed) | 2890 | LOSSLESS_WHT_UNITS.load(std::sync::atomic::Ordering::Relaxed) |
| 2891 | } | 2891 | } |
| 2892 | 2892 | ||
| 2893 | +/// lane-whtshape: 4x4 Walsh-Hadamard units reconstructed as part of a LOSSLESS | ||
| 2894 | +/// transform unit that was itself NOT 4x4 -- a shape libaom cannot code. | ||
| 2895 | +/// `read_tx_mode` (`av1/decoder/decodeframe.c:140`) returns `ONLY_4X4` for a | ||
| 2896 | +/// `coded_lossless` frame before it looks at the `tx_mode` symbol, | ||
| 2897 | +/// `read_tx_size` (`:1117`) returns `TX_4X4` before it looks at a tree, | ||
| 2898 | +/// `get_vartx_max_txsize` (`av1/common/blockd.h:1447`) returns `TX_4X4` for | ||
| 2899 | +/// EVERY plane of a lossless block, and of `av1/common/idct.c`'s | ||
| 2900 | +/// `highbd_inv_txfm_add_*_c` only `highbd_inv_txfm_add_4x4_c` carries a | ||
| 2901 | +/// `lossless` branch -- every other size falls through to the IDCT, because | ||
| 2902 | +/// there is no non-4x4 lossless inverse transform to dispatch to. So one of | ||
| 2903 | +/// these is a CALLER sizing a lossless unit wrongly, not a bitstream shape; | ||
| 2904 | +/// read as a before/after delta around one decode it names the caller. Must | ||
| 2905 | +/// read 0 on a stream whose lossless unit geometry is right. Atomic: the | ||
| 2906 | +/// wavefront workers run the transform on their own threads. | ||
| 2907 | +static LOSSLESS_WHT_SPLIT_UNITS: std::sync::atomic::AtomicUsize = | ||
| 2908 | + std::sync::atomic::AtomicUsize::new(0); | ||
| 2909 | + | ||
| 2910 | +/// [`LOSSLESS_WHT_SPLIT_UNITS`] -- total over the process, read as a | ||
| 2911 | +/// before/after delta around one decode. | ||
| 2912 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 2913 | +pub(crate) fn lossless_wht_split_units() -> usize { | ||
| 2914 | + LOSSLESS_WHT_SPLIT_UNITS.load(std::sync::atomic::Ordering::Relaxed) | ||
| 2915 | +} | ||
| 2916 | + | ||
| 2893 | impl TxParams { | 2917 | impl TxParams { |
| 2894 | /// The one copy of the produce-the-residual code: the inline path calls it | 2918 | /// The one copy of the produce-the-residual code: the inline path calls it |
| 2895 | /// on the parse thread, the wavefront worker calls it on its own, so both | 2919 | /// on the parse thread, the wavefront worker calls it on its own, so both |
| @@ -2897,10 +2921,34 @@ impl TxParams { | |||
| 2897 | fn run(self, grid: &[i32]) -> Vec<i32> { | 2921 | fn run(self, grid: &[i32]) -> Vec<i32> { |
| 2898 | let residual = if self.lossless { | 2922 | let residual = if self.lossless { |
| 2899 | LOSSLESS_WHT_UNITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); | 2923 | LOSSLESS_WHT_UNITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed); |
| 2900 | - debug_assert_eq!((self.w, self.h), (4, 4)); | 2924 | + // lane-whtshape: a non-4x4 unit here is this decoder's own |
| 2901 | - debug_assert_eq!(self.tx_type, TxType::DctDct); | 2925 | + // transform-unit geometry being wrong (see |
| 2902 | - crate::transform::dequant_and_inverse_wht4x4( | 2926 | + // [`LOSSLESS_WHT_SPLIT_UNITS`] for the libaom evidence). It used |
| 2927 | + // to be stopped by a `debug_assert_eq!` that RELEASE never ran: | ||
| 2928 | + // the 4x4 WHT returned 16 values for a `w * h` block and the | ||
| 2929 | + // release build died one frame later in the strided copy with an | ||
| 2930 | + // opaque `range end index 8 out of range for slice of length 0` | ||
| 2931 | + // that never named lossless or the transform. Counted, and | ||
| 2932 | + // reconstructed as the raster of 4x4 WHT units | ||
| 2933 | + // ([`crate::transform::dequant_and_inverse_wht`]) instead: total, | ||
| 2934 | + // the same in both profiles, and the 4x4 fast path is the same | ||
| 2935 | + // single call it always was. The old | ||
| 2936 | + // `debug_assert_eq!(self.tx_type, TxType::DctDct)` is gone with | ||
| 2937 | + // it: the WHT takes no tx_type (libaom's `av1_iwht4x4_add` does | ||
| 2938 | + // not either), and `av1_get_tx_type` already answers `DCT_DCT` on | ||
| 2939 | + // every plane of a lossless block, so asserting an argument | ||
| 2940 | + // nothing reads was a debug-only panic on a value release | ||
| 2941 | + // ignores. | ||
| 2942 | + if self.w != 4 || self.h != 4 { | ||
| 2943 | + LOSSLESS_WHT_SPLIT_UNITS.fetch_add( | ||
| 2944 | + self.w.div_ceil(4) * self.h.div_ceil(4), | ||
| 2945 | + std::sync::atomic::Ordering::Relaxed, | ||
| 2946 | + ); | ||
| 2947 | + } | ||
| 2948 | + crate::transform::dequant_and_inverse_wht( | ||
| 2903 | grid, | 2949 | grid, |
| 2950 | + self.w, | ||
| 2951 | + self.h, | ||
| 2904 | self.bit_depth, | 2952 | self.bit_depth, |
| 2905 | self.q_idx, | 2953 | self.q_idx, |
| 2906 | self.dc_delta, | 2954 | self.dc_delta, |
| @@ -4634,6 +4682,17 @@ thread_local! { | |||
| 4634 | /// invisible to every gate because they only counted CODED strips. | 4682 | /// invisible to every gate because they only counted CODED strips. |
| 4635 | static INTRABC_RECT_SKIPPED_HITS: std::cell::Cell<[usize; 2]> = | 4683 | static INTRABC_RECT_SKIPPED_HITS: std::cell::Cell<[usize; 2]> = |
| 4636 | const { std::cell::Cell::new([0, 0]) }; | 4684 | const { std::cell::Cell::new([0, 0]) }; |
| 4685 | + /// lane-whtshape: LOSSLESS rect intrabc blocks whose chroma plane block | ||
| 4686 | + /// [`decode_intrabc_rect`] walked as a `(cw/4) * (ch/4)` PLANE-MAJOR | ||
| 4687 | + /// raster of TX_4X4 units -- the shape libaom's lossless geometry codes | ||
| 4688 | + /// (`read_tx_size` returns `TX_4X4` for EVERY plane of a lossless block, | ||
| 4689 | + /// `get_vartx_max_txsize` likewise, and `read_tx_mode` forced the frame's | ||
| 4690 | + /// `ONLY_4X4`) -- instead of the single rect unit, which is what put a | ||
| 4691 | + /// non-4x4 unit on the lossless Walsh-Hadamard path. EXCLUSIVE to this arm: | ||
| 4692 | + /// no other caller walks a rect intrabc block's chroma, so `>= 1` cannot | ||
| 4693 | + /// be satisfied by any older route. | ||
| 4694 | + static INTRABC_RECT_LOSSLESS_CHROMA4_HITS: std::cell::Cell<usize> = | ||
| 4695 | + const { std::cell::Cell::new(0) }; | ||
| 4637 | } | 4696 | } |
| 4638 | 4697 | ||
| 4639 | /// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed, | 4698 | /// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed, |
| @@ -4665,6 +4724,18 @@ pub(crate) fn reset_intrabc_rect_hits() { | |||
| 4665 | INTRABC_RECT_SKIPPED_HITS.with(|c| c.set([0, 0])); | 4724 | INTRABC_RECT_SKIPPED_HITS.with(|c| c.set([0, 0])); |
| 4666 | } | 4725 | } |
| 4667 | 4726 | ||
| 4727 | +/// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`]. | ||
| 4728 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 4729 | +pub fn intrabc_rect_lossless_chroma4_hits() -> usize { | ||
| 4730 | + INTRABC_RECT_LOSSLESS_CHROMA4_HITS.with(|c| c.get()) | ||
| 4731 | +} | ||
| 4732 | + | ||
| 4733 | +/// lane-whtshape: zeroes [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`]. | ||
| 4734 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 4735 | +pub(crate) fn reset_intrabc_rect_lossless_chroma4_hits() { | ||
| 4736 | + INTRABC_RECT_LOSSLESS_CHROMA4_HITS.with(|c| c.set(0)); | ||
| 4737 | +} | ||
| 4738 | + | ||
| 4668 | /// Current value of [`INTRABC_RECT_VARTX_HITS`]. | 4739 | /// Current value of [`INTRABC_RECT_VARTX_HITS`]. |
| 4669 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates | 4740 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates |
| 4670 | pub fn intrabc_rect_vartx_hits() -> usize { | 4741 | pub fn intrabc_rect_vartx_hits() -> usize { |
| @@ -13255,12 +13326,34 @@ fn decode_intrabc_rect( | |||
| 13255 | }); | 13326 | }); |
| 13256 | } | 13327 | } |
| 13257 | let (px, py) = (mi_c * MI, mi_r * MI); | 13328 | let (px, py) = (mi_c * MI, mi_r * MI); |
| 13258 | - let (cpx, cpy) = (px / 2, py / 2); | 13329 | + // lane-whtshape: a LOSSLESS block's chroma plane block is |
| 13330 | + // `bw >> ss_x` by `bh >> ss_y` at its own origin -- `av1_get_max_uv_txsize` | ||
| 13331 | + // is `ss_size_lookup[bsize]` (no halving of its own), so at 4:4:4 that is | ||
| 13332 | + // the block's OWN footprint, not the 4:2:0 halving the lossy arm hard-codes. | ||
| 13333 | + // Measured on this lane's 4:4:4 lossless witness: with the halving, a | ||
| 13334 | + // 16x8 intrabc block's chroma plane block came out 8x4 and the lossless | ||
| 13335 | + // walk below coded 2 units per plane where libaom codes 8. | ||
| 13336 | + // | ||
| 13337 | + // Scoped to `lossless` ON PURPOSE. The 4:2:0 halving is right at 4:2:0, | ||
| 13338 | + // and every pinned 4:4:4 stream that reaches this helper does so LOSSY | ||
| 13339 | + // (measured: zero pinned fixtures decode a LOSSLESS intrabc rect block), | ||
| 13340 | + // whose footprint is a separate, already-named open cell -- | ||
| 13341 | + // lanes/av1444rect.report.md's 4:4:4 intra-BC chroma. This lane must not | ||
| 13342 | + // move it, and a lossless-only split here changes no green pin either way. | ||
| 13343 | + let (cpx, cpy) = if lossless(fctx) { | ||
| 13344 | + (px >> ss_x(fctx), py >> ss_y(fctx)) | ||
| 13345 | + } else { | ||
| 13346 | + (px / 2, py / 2) | ||
| 13347 | + }; | ||
| 13259 | // `av1_get_max_uv_txsize(bw x bh)`: 4:2:0 halves the footprint and the | 13348 | // `av1_get_max_uv_txsize(bw x bh)`: 4:2:0 halves the footprint and the |
| 13260 | // halved shape's own `max_txsize_rect_lookup` entry IS that size for every | 13349 | // halved shape's own `max_txsize_rect_lookup` entry IS that size for every |
| 13261 | // shape this helper is called at, so the uv plane block is ONE unit -- | 13350 | // shape this helper is called at, so the uv plane block is ONE unit -- |
| 13262 | // the same call `decode_token_recon_block`'s own chroma loop makes. | 13351 | // the same call `decode_token_recon_block`'s own chroma loop makes. |
| 13263 | - let (cw, ch) = (bw / 2, bh / 2); | 13352 | + let (cw, ch) = if lossless(fctx) { |
| 13353 | + (bw >> ss_x(fctx), bh >> ss_y(fctx)) | ||
| 13354 | + } else { | ||
| 13355 | + (bw / 2, bh / 2) | ||
| 13356 | + }; | ||
| 13264 | // lane-av1-intrabc r2: the square stride the proven INTER path uses | 13357 | // lane-av1-intrabc r2: the square stride the proven INTER path uses |
| 13265 | // (`side`). The residual grids, the prediction windows AND | 13358 | // (`side`). The residual grids, the prediction windows AND |
| 13266 | // `TxParams::stride` are all laid out at it -- the block's own width | 13359 | // `TxParams::stride` are all laid out at it -- the block's own width |
| @@ -13350,6 +13443,10 @@ fn decode_intrabc_rect( | |||
| 13350 | let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); | 13443 | let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); |
| 13351 | let luma_tx_type: TxType; | 13444 | let luma_tx_type: TxType; |
| 13352 | let (luma_grid, u_grid, v_grid); | 13445 | let (luma_grid, u_grid, v_grid); |
| 13446 | + // lane-whtshape: the LOSSLESS chroma walk's composed plane-major grids, | ||
| 13447 | + // kept so their per-4x4 slices can be re-stamped over the whole-block | ||
| 13448 | + // record in the tail. `None` on every other arm. | ||
| 13449 | + let mut ll_chroma: Option<(Vec<i32>, Vec<i32>)> = None; | ||
| 13353 | if skip { | 13450 | if skip { |
| 13354 | // No residual syntax at all: the prediction IS the block. | 13451 | // No residual syntax at all: the prediction IS the block. |
| 13355 | // Residual stride is `side` (and `cside`), not `bw`: reconstruct_mc_rect indexes | 13452 | // Residual stride is `side` (and `cside`), not `bw`: reconstruct_mc_rect indexes |
| @@ -13572,43 +13669,95 @@ fn decode_intrabc_rect( | |||
| 13572 | around[1] = c[1]; | 13669 | around[1] = c[1]; |
| 13573 | around[2] = c[2]; | 13670 | around[2] = c[2]; |
| 13574 | } | 13671 | } |
| 13575 | - let (ug, _) = read_inter_plane_rect( | 13672 | + if lossless(fctx) { |
| 13576 | - dec, | 13673 | + // lane-whtshape: at lossless libaom codes TX_4X4 on EVERY |
| 13577 | - cdfs, | 13674 | + // plane of a block -- `read_tx_size` returns `TX_4X4` for a |
| 13578 | - rect_inter_chroma_set(cw, ch)?, | 13675 | + // lossless block before it looks at a tree, `read_tx_mode` |
| 13579 | - (cw, ch), | 13676 | + // already forced `ONLY_4X4` for the frame, and |
| 13580 | - cside, | 13677 | + // `get_vartx_max_txsize` returns `TX_4X4` for every plane |
| 13581 | - 1, | 13678 | + // -- so this block's chroma plane block is a |
| 13582 | - around[1], | 13679 | + // `(cw/4) * (ch/4)` raster of 4x4 units, PLANE-MAJOR |
| 13583 | - 0, | 13680 | + // (`decode_token_recon_block`: every U unit, then every V |
| 13584 | - u, | 13681 | + // unit), not the single rect unit the two |
| 13585 | - cpx, | 13682 | + // `read_inter_plane_rect` calls below read. That single |
| 13586 | - cpy, | 13683 | + // 8x4 unit is what reached the lossless WHT with the wrong |
| 13587 | - Pred::Inline(&pred_u, cside), | 13684 | + // shape (the `debug_assert_eq!((w, h), (4, 4))` this lane |
| 13588 | - Some(luma_tx_type), | 13685 | + // replaced). Same helper, same walk, as the inter 8x8 and |
| 13589 | - None, | 13686 | + // 128 paths. |
| 13590 | - fctx, | 13687 | + hit!(INTRABC_RECT_LOSSLESS_CHROMA4_HITS); |
| 13591 | - )?; | 13688 | + let mut uo = vec![0i32; cside * cside]; |
| 13592 | - u_grid = embed_grid_stride(&ug, cw, ch, cside); | 13689 | + let mut vo = vec![0i32; cside * cside]; |
| 13593 | - let (vg, _) = read_inter_plane_rect( | 13690 | + read_inter_chroma_lossless( |
| 13594 | - dec, | 13691 | + dec, |
| 13595 | - cdfs, | 13692 | + cdfs, |
| 13596 | - rect_inter_chroma_set(cw, ch)?, | 13693 | + neighbours, |
| 13597 | - (cw, ch), | 13694 | + u, |
| 13598 | - cside, | 13695 | + v, |
| 13599 | - 2, | 13696 | + Pred::Inline(&pred_u, cside), |
| 13600 | - around[2], | 13697 | + Pred::Inline(&pred_v, cside), |
| 13601 | - 0, | 13698 | + (mi_r, mi_c), |
| 13602 | - v, | 13699 | + (cpx, cpy), |
| 13603 | - cpx, | 13700 | + (0, 0), |
| 13604 | - cpy, | 13701 | + (cw, ch), |
| 13605 | - Pred::Inline(&pred_v, cside), | 13702 | + (cw, ch), |
| 13606 | - Some(luma_tx_type), | 13703 | + cside, |
| 13607 | - None, | 13704 | + 0, |
| 13608 | - fctx, | 13705 | + base_q_idx, |
| 13609 | - )?; | 13706 | + &mut uo, |
| 13610 | - v_grid = embed_grid_stride(&vg, cw, ch, cside); | 13707 | + &mut vo, |
| 13611 | - luma_grid = Grid::Zero(side * side); | 13708 | + fctx, |
| 13709 | + )?; | ||
| 13710 | + // The per-unit walk stamped every unit's own coefficient | ||
| 13711 | + // context, but the whole-block `record_split_luma_rect_mi` | ||
| 13712 | + // in the tail rewrites every chroma cell with ONE composed | ||
| 13713 | + // state, which drops the per-unit DC signs and levels (class | ||
| 13714 | + // `override-slot-on-one-arm` -- the same one | ||
| 13715 | + // `decode_rect_split`'s `ll_chroma_units` replay exists | ||
| 13716 | + // for). The grids are kept here and replayed AFTER that | ||
| 13717 | + // record, from the same 4x4 slices, so the same states. | ||
| 13718 | + u_grid = embed_grid_stride(&Grid::Own(uo.clone()), cw, ch, cside); | ||
| 13719 | + v_grid = embed_grid_stride(&Grid::Own(vo.clone()), cw, ch, cside); | ||
| 13720 | + ll_chroma = Some((uo, vo)); | ||
| 13721 | + luma_grid = Grid::Zero(side * side); | ||
| 13722 | + } else { | ||
| 13723 | + let (ug, _) = read_inter_plane_rect( | ||
| 13724 | + dec, | ||
| 13725 | + cdfs, | ||
| 13726 | + rect_inter_chroma_set(cw, ch)?, | ||
| 13727 | + (cw, ch), | ||
| 13728 | + cside, | ||
| 13729 | + 1, | ||
| 13730 | + around[1], | ||
| 13731 | + 0, | ||
| 13732 | + u, | ||
| 13733 | + cpx, | ||
| 13734 | + cpy, | ||
| 13735 | + Pred::Inline(&pred_u, cside), | ||
| 13736 | + Some(luma_tx_type), | ||
| 13737 | + None, | ||
| 13738 | + fctx, | ||
| 13739 | + )?; | ||
| 13740 | + u_grid = embed_grid_stride(&ug, cw, ch, cside); | ||
| 13741 | + let (vg, _) = read_inter_plane_rect( | ||
| 13742 | + dec, | ||
| 13743 | + cdfs, | ||
| 13744 | + rect_inter_chroma_set(cw, ch)?, | ||
| 13745 | + (cw, ch), | ||
| 13746 | + cside, | ||
| 13747 | + 2, | ||
| 13748 | + around[2], | ||
| 13749 | + 0, | ||
| 13750 | + v, | ||
| 13751 | + cpx, | ||
| 13752 | + cpy, | ||
| 13753 | + Pred::Inline(&pred_v, cside), | ||
| 13754 | + Some(luma_tx_type), | ||
| 13755 | + None, | ||
| 13756 | + fctx, | ||
| 13757 | + )?; | ||
| 13758 | + v_grid = embed_grid_stride(&vg, cw, ch, cside); | ||
| 13759 | + luma_grid = Grid::Zero(side * side); | ||
| 13760 | + } | ||
| 13612 | } | 13761 | } |
| 13613 | } | 13762 | } |
| 13614 | } | 13763 | } |
| @@ -13637,6 +13786,29 @@ fn decode_intrabc_rect( | |||
| 13637 | &[&luma_grid, &u_grid, &v_grid], | 13786 | &[&luma_grid, &u_grid, &v_grid], |
| 13638 | ); | 13787 | ); |
| 13639 | } | 13788 | } |
| 13789 | + // lane-whtshape: replay the LOSSLESS walk's per-4x4 chroma states over | ||
| 13790 | + // the whole-block record above, so the NEXT block reads the per-unit DC | ||
| 13791 | + // signs and levels libaom's plane-major walk left behind instead of one | ||
| 13792 | + // composed state for the whole plane block. | ||
| 13793 | + if let Some((uo, vo)) = ll_chroma { | ||
| 13794 | + for (plane_idx, comp) in [(1usize, &uo), (2, &vo)] { | ||
| 13795 | + for ur in 0..ch / 4 { | ||
| 13796 | + for uc in 0..cw / 4 { | ||
| 13797 | + let mut unit = Vec::with_capacity(16); | ||
| 13798 | + for r in 0..4 { | ||
| 13799 | + unit.extend_from_slice(&comp[(ur * 4 + r) * cside + uc * 4..][..4]); | ||
| 13800 | + } | ||
| 13801 | + neighbours.record_mi_chroma( | ||
| 13802 | + (mi_r + ur * (4 >> ss_y(fctx)), mi_c + uc * (4 >> ss_x(fctx))), | ||
| 13803 | + 4 << ss_x(fctx), | ||
| 13804 | + 4 << ss_y(fctx), | ||
| 13805 | + plane_idx, | ||
| 13806 | + &Grid::Own(unit), | ||
| 13807 | + ); | ||
| 13808 | + } | ||
| 13809 | + } | ||
| 13810 | + } | ||
| 13811 | + } | ||
| 13640 | neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]); | 13812 | neighbours.record_palette_y_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]); |
| 13641 | neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]); | 13813 | neighbours.record_palette_uv_rect((mi_r, mi_c), bw, bh, 0, [0u16; 8]); |
| 13642 | neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); | 13814 | neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip); |
crates/ec-av1/src/stream.rsmodified+200 -0
| @@ -46038,4 +46038,204 @@ pub(crate) mod tests { | |||
| 46038 | average, so this gate proves nothing about the tool" | 46038 | average, so this gate proves nothing about the tool" |
| 46039 | ); | 46039 | ); |
| 46040 | } | 46040 | } |
| 46041 | + | ||
| 46042 | + /// lane-whtshape: a LOSSLESS 4:4:4 frame whose rect intra-BC blocks used | ||
| 46043 | + /// to code their chroma plane block as ONE rect transform unit -- a shape | ||
| 46044 | + /// libaom cannot code. `read_tx_mode` (`av1/decoder/decodeframe.c:140`) | ||
| 46045 | + /// returns `ONLY_4X4` for a `coded_lossless` frame BEFORE it looks at the | ||
| 46046 | + /// `tx_mode` symbol, `read_tx_size` (`:1117`) returns `TX_4X4` before it | ||
| 46047 | + /// looks at a tree, `get_vartx_max_txsize` (`av1/common/blockd.h:1447`) | ||
| 46048 | + /// returns `TX_4X4` for EVERY plane of a lossless block, and of | ||
| 46049 | + /// `av1/common/idct.c`'s `highbd_inv_txfm_add_*_c` only the 4x4 one carries | ||
| 46050 | + /// a `lossless` branch -- the rest fall through to the IDCT, because there | ||
| 46051 | + /// is no non-4x4 lossless inverse transform to dispatch to. | ||
| 46052 | + /// | ||
| 46053 | + /// The 8x4 unit that resulted reached the lossless Walsh-Hadamard path, | ||
| 46054 | + /// where a `debug_assert_eq!` named it in DEBUG and the RELEASE build died | ||
| 46055 | + /// one frame later with an opaque `range end index 8 out of range for slice | ||
| 46056 | + /// of length 0` (measured, not assumed -- see | ||
| 46057 | + /// lanes/whtshape.report.md r1). | ||
| 46058 | + /// | ||
| 46059 | + /// The witness is `fixtures/ll444_sb64_1to4_lossless.obu` (51107 bytes, | ||
| 46060 | + /// sha256 `fdb6467987095b99c8eb51b48743691d906b2d99d069f71f1d51b1abb6d2056e`), | ||
| 46061 | + /// encoded with the instrumented oracle | ||
| 46062 | + /// (`scripts/build-aom-oracle.sh`'s `aomenc`, 4:4:4 10-bit, `--lossless=1 | ||
| 46063 | + /// --profile=1 --i444 --enable-rect-partitions=1 | ||
| 46064 | + /// --enable-1to4-partitions=1 --min-partition-size=4 --max-partition-size=64 | ||
| 46065 | + /// --sb-size=64 --tune-content=screen --enable-intrabc=1 --enable-palette=1 | ||
| 46066 | + /// --cq-level=60 --enable-tx-size-search=0 --cpu-used=0 --limit=2`) over | ||
| 46067 | + /// `ffmpeg -f lavfi -i testsrc2=size=256x256:rate=25:duration=1 -pix_fmt | ||
| 46068 | + /// yuv444p10le -f rawvideo`. 4:2:0 cannot produce the shape at all -- its | ||
| 46069 | + /// smallest lossless chroma plane block is already 4x4 -- which is why the | ||
| 46070 | + /// 4:4:4 10-bit header is asserted. | ||
| 46071 | + /// | ||
| 46072 | + /// Four assertions, each with its own failure: | ||
| 46073 | + /// | ||
| 46074 | + /// 1. the route fired: `INTRABC_RECT_LOSSLESS_CHROMA4_HITS` is EXCLUSIVE to | ||
| 46075 | + /// the per-4x4 chroma walk (no other caller walks a rect intra-BC | ||
| 46076 | + /// block's chroma), so `>= 1` cannot be satisfied by the old | ||
| 46077 | + /// single-unit read; | ||
| 46078 | + /// 2. NO non-4x4 lossless transform unit was reconstructed | ||
| 46079 | + /// (`LOSSLESS_WHT_SPLIT_UNITS` delta 0) -- the shape-total WHT entry is | ||
| 46080 | + /// not quietly papering over a caller that is still wrong; | ||
| 46081 | + /// 3. the stream DECODES both frames (before the fix the same bytes were a | ||
| 46082 | + /// RELEASE panic and a Golomb-tail refusal in DEBUG); and | ||
| 46083 | + /// 4. a PIXEL comparison against the instrumented oracle's own | ||
| 46084 | + /// `EC_AV1_FINAL_DUMP`, in DECODE order. | ||
| 46085 | + /// | ||
| 46086 | + /// **(4) is a PREFIX floor, not an exactness claim, and it says so.** | ||
| 46087 | + /// Measured against the oracle, decode-order frame 0 (the key frame) is | ||
| 46088 | + /// byte-exact on all three planes for its first 32992 of 65536 samples -- | ||
| 46089 | + /// the whole frame above row 128, plus row 128 out to column 224. The | ||
| 46090 | + /// first differing sample there is (x=224, y=128) on Y, U and V alike: the | ||
| 46091 | + /// first column PAST the 16x8 lossless intra-BC block at mi (32, 52), | ||
| 46092 | + /// whose own 16x8 luma and chroma are byte-exact -- so the fork is at the | ||
| 46093 | + /// block boundary, in the block that FOLLOWS it. Decode-order frame 1 (the | ||
| 46094 | + /// inter frame) is exact to 55008 on luma and to 9378 on chroma. Both forks | ||
| 46095 | + /// are a SEPARATE defect this lane does not own; each is named with its | ||
| 46096 | + /// measurement in lanes/whtshape.report.md r3. Asserting "our output is | ||
| 46097 | + /// wrong by exactly N" would encode those defects as expected behaviour; | ||
| 46098 | + /// the per-frame, per-plane floor is the honest form, and it only grows. | ||
| 46099 | + #[test] | ||
| 46100 | + fn a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units() { | ||
| 46101 | + const NAME: &str = "a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units"; | ||
| 46102 | + const FIXTURE: &str = "ll444_sb64_1to4_lossless.obu"; | ||
| 46103 | + const FIXTURE_LEN: usize = 51107; | ||
| 46104 | + const FIXTURE_FNV: u64 = 0x7664_6a62_ddd3_4df2; | ||
| 46105 | + const FRAMES: usize = 2; | ||
| 46106 | + const PLANE: usize = 256 * 256; | ||
| 46107 | + /// Per decode-order frame, per plane (0=Y, 1=U, 2=V), the number of | ||
| 46108 | + /// leading samples MEASURED byte-exact against the oracle's | ||
| 46109 | + /// `EC_AV1_FINAL_DUMP`; the first differing sample is exactly this | ||
| 46110 | + /// index on that plane. Key frame: the whole frame above row 128 plus | ||
| 46111 | + /// row 128 out to column 224. Inter frame: luma exact to (224, 214), | ||
| 46112 | + /// chroma diverging early at (162, 36). | ||
| 46113 | + const EXACT_PREFIX: [[usize; 3]; 2] = [[32992, 32992, 32992], [55008, 9378, 9378]]; | ||
| 46114 | + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 46115 | + .join(format!("fixtures/{FIXTURE}")); | ||
| 46116 | + let stream = read_pin(&obu, FIXTURE_LEN, FIXTURE_FNV, NAME); | ||
| 46117 | + assert_444_header(&stream, NAME, 10); | ||
| 46118 | + | ||
| 46119 | + let _guard = lock_gate_counters(); | ||
| 46120 | + crate::decode::reset_intrabc_rect_lossless_chroma4_hits(); | ||
| 46121 | + let split_before = crate::decode::lossless_wht_split_units(); | ||
| 46122 | + let wht_before = crate::decode::lossless_wht_units(); | ||
| 46123 | + let frames = decode_stream(&stream) | ||
| 46124 | + .unwrap_or_else(|e| panic!("{NAME}: the pinned witness was refused: {e}")); | ||
| 46125 | + let chroma4 = crate::decode::intrabc_rect_lossless_chroma4_hits(); | ||
| 46126 | + let split = crate::decode::lossless_wht_split_units() - split_before; | ||
| 46127 | + let wht = crate::decode::lossless_wht_units() - wht_before; | ||
| 46128 | + | ||
| 46129 | + assert!( | ||
| 46130 | + chroma4 > 0, | ||
| 46131 | + "{NAME}: no LOSSLESS rect intra-BC block walked its chroma as 4x4 units \ | ||
| 46132 | + -- the corrected route never ran, so this gate is measuring the old \ | ||
| 46133 | + single rect unit (class gate-blind-to-feature)" | ||
| 46134 | + ); | ||
| 46135 | + assert_eq!( | ||
| 46136 | + split, 0, | ||
| 46137 | + "{NAME}: {split} 4x4 WHT unit(s) were reconstructed inside a LOSSLESS \ | ||
| 46138 | + transform unit that was itself not 4x4 -- a caller is still sizing a \ | ||
| 46139 | + lossless unit wrongly and the shape-total WHT entry is hiding it" | ||
| 46140 | + ); | ||
| 46141 | + assert!( | ||
| 46142 | + wht > 0, | ||
| 46143 | + "{NAME}: no lossless WHT unit ran at all -- vacuous" | ||
| 46144 | + ); | ||
| 46145 | + assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); | ||
| 46146 | + | ||
| 46147 | + if !aomdec_path().is_file() { | ||
| 46148 | + eprintln!( | ||
| 46149 | + "{NAME}: {chroma4} lossless rect intra-BC block(s) walked 4x4 chroma \ | ||
| 46150 | + units, {wht} WHT units, 0 split; no oracle aomdec at {}, pixel arm \ | ||
| 46151 | + skipped", | ||
| 46152 | + aomdec_path().display() | ||
| 46153 | + ); | ||
| 46154 | + return; | ||
| 46155 | + } | ||
| 46156 | + // The oracle's own final-frame dumps, in DECODE order, against ours. | ||
| 46157 | + let dir = std::env::temp_dir().join(format!("ec-av1-{NAME}-{}", std::process::id())); | ||
| 46158 | + let _ = std::fs::remove_dir_all(&dir); | ||
| 46159 | + std::fs::create_dir_all(&dir).expect("scratch dir"); | ||
| 46160 | + let in_obu = dir.join("in.obu"); | ||
| 46161 | + std::fs::write(&in_obu, &stream).expect("writing the stream"); | ||
| 46162 | + let aom_prefix = dir.join("aom"); | ||
| 46163 | + let out = Command::new(aomdec_path()) | ||
| 46164 | + .args(["--codec=av1", "-o"]) | ||
| 46165 | + .arg(dir.join("out.y4m")) | ||
| 46166 | + .arg(&in_obu) | ||
| 46167 | + .env("EC_AV1_FINAL_DUMP", &aom_prefix) | ||
| 46168 | + .stdin(Stdio::null()) | ||
| 46169 | + .stdout(Stdio::piped()) | ||
| 46170 | + .stderr(Stdio::piped()) | ||
| 46171 | + .output() | ||
| 46172 | + .expect("aomdec failed to run"); | ||
| 46173 | + assert!( | ||
| 46174 | + out.status.success(), | ||
| 46175 | + "{NAME}: the oracle aomdec refused the stream: {}", | ||
| 46176 | + String::from_utf8_lossy(&out.stderr) | ||
| 46177 | + ); | ||
| 46178 | + let ours_prefix = dir.join("ours"); | ||
| 46179 | + set_final_dump_prefix(Some(ours_prefix.display().to_string())); | ||
| 46180 | + let shown = decode_stream(&stream) | ||
| 46181 | + .unwrap_or_else(|e| panic!("{NAME}: the second decode was refused: {e}")) | ||
| 46182 | + .len(); | ||
| 46183 | + set_final_dump_prefix(None); | ||
| 46184 | + let count = |prefix: &std::path::Path| -> usize { | ||
| 46185 | + let mut n = 0usize; | ||
| 46186 | + while std::path::PathBuf::from(format!("{}.f{n}", prefix.display())).is_file() { | ||
| 46187 | + n += 1; | ||
| 46188 | + } | ||
| 46189 | + n | ||
| 46190 | + }; | ||
| 46191 | + let oracle_frames = count(&aom_prefix); | ||
| 46192 | + let our_frames = count(&ours_prefix); | ||
| 46193 | + assert_eq!( | ||
| 46194 | + our_frames, oracle_frames, | ||
| 46195 | + "{NAME}: decoded {our_frames} frames in decode order, the oracle decoded \ | ||
| 46196 | + {oracle_frames}" | ||
| 46197 | + ); | ||
| 46198 | + for i in 0..oracle_frames { | ||
| 46199 | + let want = | ||
| 46200 | + std::fs::read(format!("{}.f{i}", aom_prefix.display())).expect("oracle dump"); | ||
| 46201 | + let got = std::fs::read(format!("{}.f{i}", ours_prefix.display())).expect("our dump"); | ||
| 46202 | + assert_eq!( | ||
| 46203 | + got.len(), | ||
| 46204 | + want.len(), | ||
| 46205 | + "{NAME}: decode-order frame {i} is {} bytes, the oracle's is {}", | ||
| 46206 | + got.len(), | ||
| 46207 | + want.len() | ||
| 46208 | + ); | ||
| 46209 | + assert_eq!( | ||
| 46210 | + got.len(), | ||
| 46211 | + 3 * PLANE * 2, | ||
| 46212 | + "{NAME}: decode-order frame {i} is not three 256x256 16-bit planes" | ||
| 46213 | + ); | ||
| 46214 | + for (plane, name) in [(0usize, "Y"), (1, "U"), (2, "V")] { | ||
| 46215 | + let at = plane * PLANE * 2; | ||
| 46216 | + let floor = EXACT_PREFIX[i.min(EXACT_PREFIX.len() - 1)][plane].min(PLANE); | ||
| 46217 | + if got[at..at + floor * 2] == want[at..at + floor * 2] { | ||
| 46218 | + continue; | ||
| 46219 | + } | ||
| 46220 | + let first = (0..floor) | ||
| 46221 | + .find(|&s| got[at + s * 2..at + s * 2 + 2] != want[at + s * 2..at + s * 2 + 2]) | ||
| 46222 | + .unwrap_or(floor); | ||
| 46223 | + panic!( | ||
| 46224 | + "{NAME}: decode-order frame {i} plane {name} diverges from the oracle at \ | ||
| 46225 | + sample {first} of {PLANE} (x={}, y={}) -- the exact prefix this gate pins \ | ||
| 46226 | + is {floor} and it only grows; the rest is the OPEN defect named in \ | ||
| 46227 | + lanes/whtshape.report.md r3", | ||
| 46228 | + first % 256, | ||
| 46229 | + first / 256 | ||
| 46230 | + ); | ||
| 46231 | + } | ||
| 46232 | + } | ||
| 46233 | + let _ = std::fs::remove_dir_all(&dir); | ||
| 46234 | + eprintln!( | ||
| 46235 | + "{NAME}: {chroma4} lossless rect intra-BC block(s) walked 4x4 chroma units, \ | ||
| 46236 | + {wht} WHT units, 0 split; {oracle_frames} decode-order frame(s) ({shown} shown) \ | ||
| 46237 | + byte-exact against the oracle up to the per-frame, per-plane exact prefix \ | ||
| 46238 | + -- the tail is the OPEN r3 defect, not an assertion" | ||
| 46239 | + ); | ||
| 46240 | + } | ||
| 46041 | } | 46241 | } |
crates/ec-av1/src/transform.rsmodified+220 -3
| @@ -186,7 +186,7 @@ impl Lane for [i32; 8] { | |||
| 186 | #[cfg(target_arch = "x86_64")] | 186 | #[cfg(target_arch = "x86_64")] |
| 187 | #[allow(unsafe_code)] | 187 | #[allow(unsafe_code)] |
| 188 | mod simd { | 188 | mod simd { |
| 189 | - use super::{inverse_dct_n, Lane, COS_BITS}; | 189 | + use super::{COS_BITS, Lane, inverse_dct_n}; |
| 190 | use std::arch::x86_64::*; | 190 | use std::arch::x86_64::*; |
| 191 | 191 | ||
| 192 | /// Eight `i32` lanes in one AVX2 register. | 192 | /// Eight `i32` lanes in one AVX2 register. |
| @@ -2717,7 +2717,9 @@ mod tests { | |||
| 2717 | inverse_adst16(&mut t, 16); | 2717 | inverse_adst16(&mut t, 16); |
| 2718 | assert_eq!( | 2718 | assert_eq!( |
| 2719 | t, | 2719 | t, |
| 2720 | - [32, 73, 28, 6, -45, -28, 111, -52, 135, -54, 85, -67, 305, 190, 102, 145] | 2720 | + [ |
| 2721 | + 32, 73, 28, 6, -45, -28, 111, -52, 135, -54, 85, -67, 305, 190, 102, 145 | ||
| 2722 | + ] | ||
| 2721 | ); | 2723 | ); |
| 2722 | } | 2724 | } |
| 2723 | 2725 | ||
| @@ -2737,7 +2739,9 @@ mod tests { | |||
| 2737 | inverse_identity(&mut t16, 16); | 2739 | inverse_identity(&mut t16, 16); |
| 2738 | assert_eq!( | 2740 | assert_eq!( |
| 2739 | t16, | 2741 | t16, |
| 2740 | - [283, -141, 71, 20, -8, 170, -34, 23, 42, -113, 93, -14, 62, 3, -198, 124] | 2742 | + [ |
| 2743 | + 283, -141, 71, 20, -8, 170, -34, 23, 42, -113, 93, -14, 62, 3, -198, 124 | ||
| 2744 | + ] | ||
| 2741 | ); | 2745 | ); |
| 2742 | 2746 | ||
| 2743 | let mut t32 = [0i32; 32]; | 2747 | let mut t32 = [0i32; 32]; |
| @@ -3152,6 +3156,92 @@ pub fn dequant_and_inverse_wht4x4( | |||
| 3152 | }) | 3156 | }) |
| 3153 | } | 3157 | } |
| 3154 | 3158 | ||
| 3159 | +/// lane-whtshape: the lossless inverse transform for a unit of ANY shape. | ||
| 3160 | +/// | ||
| 3161 | +/// libaom never codes a lossless transform unit that is not 4x4, and it says | ||
| 3162 | +/// so in two places this decoder already mirrors: | ||
| 3163 | +/// | ||
| 3164 | +/// * `read_tx_mode` (`av1/decoder/decodeframe.c:140`) returns `ONLY_4X4` | ||
| 3165 | +/// for a `coded_lossless` frame BEFORE it looks at the `tx_mode` symbol, so | ||
| 3166 | +/// a lossless frame has no var-tx tree at all; and | ||
| 3167 | +/// * `av1_get_tx_size` (`av1/common/blockd.h`) returns `TX_4X4` for EVERY | ||
| 3168 | +/// plane of a lossless block before it looks at a tree. | ||
| 3169 | +/// | ||
| 3170 | +/// The WHT dispatch proves the same from the other side: of | ||
| 3171 | +/// `av1/common/idct.c`'s `highbd_inv_txfm_add_{4x8,8x4,16x4,...}_c`, ONLY | ||
| 3172 | +/// `highbd_inv_txfm_add_4x4_c` carries a lossless branch | ||
| 3173 | +/// (`idct.c:50`: `if (lossless) { av1_highbd_iwht4x4_add(...); return; }`). | ||
| 3174 | +/// Every other size falls straight through to the IDCT network -- libaom has | ||
| 3175 | +/// no lossless inverse transform for a non-4x4 unit to dispatch to, because | ||
| 3176 | +/// `read_tx_mode`/`av1_get_tx_size` make that unit unreachable. | ||
| 3177 | +/// | ||
| 3178 | +/// So a non-4x4 `lossless: true` [`TxParams`](crate::decode::TxParams) is | ||
| 3179 | +/// never a bitstream libaom could have produced: it is THIS decoder's own | ||
| 3180 | +/// transform-unit geometry being wrong. The function is nevertheless TOTAL | ||
| 3181 | +/// (it used to be a `debug_assert_eq!` plus a 16-value result for a | ||
| 3182 | +/// `w * h` block, which panicked one frame later in RELEASE with an opaque | ||
| 3183 | +/// `range end index .. out of range for slice of length 0`): a unit is | ||
| 3184 | +/// reconstructed as the raster of 4x4 WHT units that libaom's lossless | ||
| 3185 | +/// geometry would have produced for that footprint -- the same numbers, in | ||
| 3186 | +/// the same places, the correct per-4x4 caller would have written. The 4x4 | ||
| 3187 | +/// case is the same single call it always was, so the lossless fast path is | ||
| 3188 | +/// bit-for-bit unchanged. | ||
| 3189 | +/// | ||
| 3190 | +/// `w`/`h` need not be multiples of four: a partial tile is zero-filled, so | ||
| 3191 | +/// no shape panics and no shape returns a buffer the caller cannot index. | ||
| 3192 | +/// Returns the same empty-grid marker as [`dequant_and_inverse_wht4x4`]. | ||
| 3193 | +pub fn dequant_and_inverse_wht( | ||
| 3194 | + levels: &[i32], | ||
| 3195 | + w: usize, | ||
| 3196 | + h: usize, | ||
| 3197 | + bit_depth: u8, | ||
| 3198 | + q_idx: i32, | ||
| 3199 | + dc_delta: i32, | ||
| 3200 | + ac_delta: i32, | ||
| 3201 | +) -> Vec<i32> { | ||
| 3202 | + if w == 4 && h == 4 { | ||
| 3203 | + return dequant_and_inverse_wht4x4(levels, bit_depth, q_idx, dc_delta, ac_delta); | ||
| 3204 | + } | ||
| 3205 | + if crate::decode::is_zero_grid(levels) { | ||
| 3206 | + return Vec::new(); | ||
| 3207 | + } | ||
| 3208 | + let mut out = vec![0i32; w * h]; | ||
| 3209 | + let mut tile = [0i32; 16]; | ||
| 3210 | + for ty in 0..h.div_ceil(4) { | ||
| 3211 | + for tx in 0..w.div_ceil(4) { | ||
| 3212 | + for r in 0..4 { | ||
| 3213 | + for c in 0..4 { | ||
| 3214 | + let (sy, sx) = (ty * 4 + r, tx * 4 + c); | ||
| 3215 | + tile[r * 4 + c] = if sy < h && sx < w { | ||
| 3216 | + levels[sy * w + sx] | ||
| 3217 | + } else { | ||
| 3218 | + 0 | ||
| 3219 | + }; | ||
| 3220 | + } | ||
| 3221 | + } | ||
| 3222 | + let res = dequant_and_inverse_wht4x4(&tile, bit_depth, q_idx, dc_delta, ac_delta); | ||
| 3223 | + // An all-zero tile dequantizes to the same empty marker a 4x4 | ||
| 3224 | + // caller passes straight through, and `out` is already zero -- | ||
| 3225 | + // copying out of it would index an empty slice. | ||
| 3226 | + if res.is_empty() { | ||
| 3227 | + continue; | ||
| 3228 | + } | ||
| 3229 | + for r in 0..4 { | ||
| 3230 | + let (sy, sx) = (ty * 4 + r, tx * 4); | ||
| 3231 | + if sy >= h { | ||
| 3232 | + continue; | ||
| 3233 | + } | ||
| 3234 | + for c in 0..4 { | ||
| 3235 | + if sx + c < w { | ||
| 3236 | + out[sy * w + sx + c] = res[r * 4 + c]; | ||
| 3237 | + } | ||
| 3238 | + } | ||
| 3239 | + } | ||
| 3240 | + } | ||
| 3241 | + } | ||
| 3242 | + out | ||
| 3243 | +} | ||
| 3244 | + | ||
| 3155 | #[cfg(test)] | 3245 | #[cfg(test)] |
| 3156 | mod lossless_tx_tests { | 3246 | mod lossless_tx_tests { |
| 3157 | /// The WHT is its own inverse up to the `UNIT_QUANT_SHIFT` scaling: a | 3247 | /// The WHT is its own inverse up to the `UNIT_QUANT_SHIFT` scaling: a |
| @@ -3216,6 +3306,133 @@ mod lossless_tx_tests { | |||
| 3216 | ); | 3306 | ); |
| 3217 | } | 3307 | } |
| 3218 | } | 3308 | } |
| 3309 | + | ||
| 3310 | + /// lane-whtshape: the shape-total lossless entry must be EXACTLY the | ||
| 3311 | + /// per-4x4 raster libaom's lossless geometry produces -- the same numbers | ||
| 3312 | + /// in the same places that a caller walking `(w/4) * (h/4)` real TX_4X4 | ||
| 3313 | + /// units would have written. Comparing against independently-composed | ||
| 3314 | + /// per-unit [`super::dequant_and_inverse_wht4x4`] calls is what makes the | ||
| 3315 | + /// split a total, not a guess. | ||
| 3316 | + #[test] | ||
| 3317 | + fn a_non_4x4_lossless_unit_is_the_raster_of_4x4_wht_units() { | ||
| 3318 | + let mut state = 0x0bad_c0deu32; | ||
| 3319 | + let mut next = || { | ||
| 3320 | + state = state.wrapping_mul(1_664_525).wrapping_add(1_013_904_223); | ||
| 3321 | + ((state >> 19) as i32 % 2001) - 1000 | ||
| 3322 | + }; | ||
| 3323 | + // A `w x h` coefficient grid is ROW-MAJOR at width `w`, so a 4x4 tile | ||
| 3324 | + // at `(tx * 4, ty * 4)` is a strided gather, not a contiguous run -- | ||
| 3325 | + // the reference below gathers it the same way the split does. | ||
| 3326 | + let tile_of = |levels: &[i32], w: usize, tx: usize, ty: usize| -> Vec<i32> { | ||
| 3327 | + let mut t = vec![0i32; 16]; | ||
| 3328 | + for r in 0..4 { | ||
| 3329 | + for c in 0..4 { | ||
| 3330 | + t[r * 4 + c] = levels[(ty * 4 + r) * w + tx * 4 + c]; | ||
| 3331 | + } | ||
| 3332 | + } | ||
| 3333 | + t | ||
| 3334 | + }; | ||
| 3335 | + for &(w, h) in &[(8usize, 4usize), (4, 8), (8, 8), (16, 4), (4, 16), (16, 16)] { | ||
| 3336 | + let levels: Vec<i32> = (0..w * h).map(|_| next()).collect(); | ||
| 3337 | + let got = super::dequant_and_inverse_wht(&levels, w, h, 10, 0, 0, 0); | ||
| 3338 | + let mut want = vec![0i32; w * h]; | ||
| 3339 | + for ty in 0..h / 4 { | ||
| 3340 | + for tx in 0..w / 4 { | ||
| 3341 | + let unit = super::dequant_and_inverse_wht4x4( | ||
| 3342 | + &tile_of(&levels, w, tx, ty), | ||
| 3343 | + 10, | ||
| 3344 | + 0, | ||
| 3345 | + 0, | ||
| 3346 | + 0, | ||
| 3347 | + ); | ||
| 3348 | + // An all-zero tile is the empty marker on both sides; the | ||
| 3349 | + // output is already zero there. | ||
| 3350 | + if unit.is_empty() { | ||
| 3351 | + continue; | ||
| 3352 | + } | ||
| 3353 | + for r in 0..4 { | ||
| 3354 | + let dst = (ty * 4 + r) * w + tx * 4; | ||
| 3355 | + want[dst..dst + 4].copy_from_slice(&unit[r * 4..][..4]); | ||
| 3356 | + } | ||
| 3357 | + } | ||
| 3358 | + } | ||
| 3359 | + assert_eq!(got.len(), w * h, "{w}x{h}: residual length"); | ||
| 3360 | + assert_eq!(got, want, "{w}x{h}: split differs from the 4x4 raster"); | ||
| 3361 | + } | ||
| 3362 | + } | ||
| 3363 | + | ||
| 3364 | + /// A grid whose non-zero coefficients sit in ONE tile: every other tile is | ||
| 3365 | + /// all zero, so it dequantizes to the empty marker rather than to 16 | ||
| 3366 | + /// zeros. Copying out of that marker is an index panic -- the split has to | ||
| 3367 | + /// leave those samples at zero, exactly as a per-unit caller would. | ||
| 3368 | + #[test] | ||
| 3369 | + fn a_lossless_split_whose_other_tiles_are_all_zero_still_reconstructs() { | ||
| 3370 | + // Row 0 columns 0, 1 and 2 of an 8-wide grid: all three land in the | ||
| 3371 | + // LEFT 4x4 tile, so the right tile is all zero and dequantizes to the | ||
| 3372 | + // empty marker rather than to 16 zeros. | ||
| 3373 | + let mut levels = vec![0i32; 8 * 4]; | ||
| 3374 | + levels[0] = 400; | ||
| 3375 | + levels[1] = -240; | ||
| 3376 | + levels[2] = 88; | ||
| 3377 | + let got = super::dequant_and_inverse_wht(&levels, 8, 4, 10, 0, 0, 0); | ||
| 3378 | + assert_eq!(got.len(), 32, "8x4 residual length"); | ||
| 3379 | + let mut want = vec![0i32; 32]; | ||
| 3380 | + for (tx, ty) in [(0usize, 0usize), (1, 0)] { | ||
| 3381 | + let mut t = vec![0i32; 16]; | ||
| 3382 | + for r in 0..4 { | ||
| 3383 | + for c in 0..4 { | ||
| 3384 | + t[r * 4 + c] = levels[(ty * 4 + r) * 8 + tx * 4 + c]; | ||
| 3385 | + } | ||
| 3386 | + } | ||
| 3387 | + let unit = super::dequant_and_inverse_wht4x4(&t, 10, 0, 0, 0); | ||
| 3388 | + if unit.is_empty() { | ||
| 3389 | + continue; | ||
| 3390 | + } | ||
| 3391 | + for r in 0..4 { | ||
| 3392 | + let dst = (ty * 4 + r) * 8 + tx * 4; | ||
| 3393 | + want[dst..dst + 4].copy_from_slice(&unit[r * 4..][..4]); | ||
| 3394 | + } | ||
| 3395 | + } | ||
| 3396 | + assert_eq!(got, want, "a partially-zero 8x4 lossless grid"); | ||
| 3397 | + assert!( | ||
| 3398 | + got.iter().any(|&v| v != 0), | ||
| 3399 | + "the fixture's non-zero tile produced an all-zero residual -- the arm is vacuous" | ||
| 3400 | + ); | ||
| 3401 | + } | ||
| 3402 | + | ||
| 3403 | + /// The 4x4 fast path is the same single call it has always been: a | ||
| 3404 | + /// lossless unit that IS 4x4 must produce byte-identical numbers with and | ||
| 3405 | + /// without the shape dispatch, so no currently-green lossless pin moves. | ||
| 3406 | + #[test] | ||
| 3407 | + fn the_4x4_lossless_fast_path_is_unchanged() { | ||
| 3408 | + let mut state = 0x5eed_1234u32; | ||
| 3409 | + for _ in 0..64 { | ||
| 3410 | + let levels: Vec<i32> = (0..16) | ||
| 3411 | + .map(|_| { | ||
| 3412 | + state = state.wrapping_mul(1_664_525).wrapping_add(1_013_904_223); | ||
| 3413 | + ((state >> 19) as i32 % 2001) - 1000 | ||
| 3414 | + }) | ||
| 3415 | + .collect(); | ||
| 3416 | + assert_eq!( | ||
| 3417 | + super::dequant_and_inverse_wht(&levels, 4, 4, 8, 0, 0, 0), | ||
| 3418 | + super::dequant_and_inverse_wht4x4(&levels, 8, 0, 0, 0), | ||
| 3419 | + "levels={levels:?}" | ||
| 3420 | + ); | ||
| 3421 | + } | ||
| 3422 | + } | ||
| 3423 | + | ||
| 3424 | + /// The empty-grid marker contract is the one every residual caller | ||
| 3425 | + /// branches on (`TxParams::run` passes it straight through as "this unit | ||
| 3426 | + /// codes nothing"): a shape that is not 4x4 must keep it, or a skipped | ||
| 3427 | + /// 8x4 unit would hand its caller a 32-long zero buffer it then re-adds | ||
| 3428 | + /// onto the prediction twice. | ||
| 3429 | + #[test] | ||
| 3430 | + fn a_non_4x4_all_zero_lossless_unit_keeps_the_empty_marker() { | ||
| 3431 | + assert!( | ||
| 3432 | + super::dequant_and_inverse_wht(&[0i32; 32], 8, 4, 10, 0, 0, 0).is_empty(), | ||
| 3433 | + "an all-zero 8x4 lossless unit must stay the empty marker" | ||
| 3434 | + ); | ||
| 3435 | + } | ||
| 3219 | } | 3436 | } |
| 3220 | 3437 | ||
| 3221 | #[cfg(test)] | 3438 | #[cfg(test)] |
lanes/whtshape.report.mdadded+278 -0
| @@ -0,0 +1,278 @@ | |||
| 1 | +# lane-whtshape — a non-4x4 unit on the LOSSLESS WHT path | ||
| 2 | + | ||
| 3 | +Branch `lane-whtshape`, base `a21f3680`, one commit | ||
| 4 | +`lossless WHT: a non-4x4 unit is reconstructed as a 4x4 raster, not asserted away`. | ||
| 5 | + | ||
| 6 | +Files touched: `crates/ec-av1/src/decode.rs`, `crates/ec-av1/src/transform.rs`, | ||
| 7 | +`crates/ec-av1/src/stream.rs` (the new gate, appended at the end of the | ||
| 8 | +`mod tests` block), and the new pin | ||
| 9 | +`crates/ec-av1/fixtures/ll444_sb64_1to4_lossless.obu`. | ||
| 10 | +Untouched as instructed: the `read_plane` coefficient-reader region (~19600) and | ||
| 11 | +`decode_rect_split`. | ||
| 12 | + | ||
| 13 | +--- | ||
| 14 | + | ||
| 15 | +## r1 — The charter's premise, measured and partly REFUTED | ||
| 16 | + | ||
| 17 | +The ticket says a RELEASE build "silently runs a wrong-shape transform — silent | ||
| 18 | +wrongness, not a panic". **That is wrong, and the measurement matters: RELEASE | ||
| 19 | +panics.** | ||
| 20 | + | ||
| 21 | +`TxParams::run`'s lossless arm was | ||
| 22 | + | ||
| 23 | +```rust | ||
| 24 | +LOSSLESS_WHT_UNITS.fetch_add(1, …); | ||
| 25 | +debug_assert_eq!((self.w, self.h), (4, 4)); | ||
| 26 | +debug_assert_eq!(self.tx_type, TxType::DctDct); | ||
| 27 | +crate::transform::dequant_and_inverse_wht4x4(grid, …) // always 16 values | ||
| 28 | +``` | ||
| 29 | + | ||
| 30 | +`dequant_and_inverse_wht4x4` dequantizes with `w = h = 4` and returns 16 | ||
| 31 | +samples. `TxParams::run` then re-lays them at `stride * h`, copying | ||
| 32 | +`w` per row for `h` rows — so a `w * h > 16` unit indexes past the 16-long | ||
| 33 | +buffer. | ||
| 34 | + | ||
| 35 | +| profile | behaviour on the witness | where | | ||
| 36 | +| --- | --- | --- | | ||
| 37 | +| DEBUG | `assertion left == right failed / left: (8, 4) / right: (4, 4)` | `decode.rs:2787` | | ||
| 38 | +| RELEASE | `panicked … range end index 8 out of range for slice of length 0` | `decode.rs:4034` (the strided copy in `push_mc_rect_tx`) | | ||
| 39 | + | ||
| 40 | +So: no silent wrong pixels, but a *worse* bug than silence — the only thing | ||
| 41 | +naming the invariant was compiled out of the profile that ships, and release's | ||
| 42 | +failure message named neither lossless nor the transform. **No reachable | ||
| 43 | +non-4x4 lossless shape is silent**: every such shape has `w * h > 16`, so the | ||
| 44 | +strided copy always overruns. (An `8 x 2`-shaped unit would have been silent, | ||
| 45 | +but AV1's minimum transform side is 4, so it is not constructible.) | ||
| 46 | + | ||
| 47 | +### Reproduction | ||
| 48 | + | ||
| 49 | +Neither witness named in the ticket exists as a pin; both had to be encoded. | ||
| 50 | +Probe over all 48 pinned fixtures in a DEBUG build: **zero** trip the assert. | ||
| 51 | +Two independent encodes, both 4:4:4 10-bit `--lossless=1 --profile=1 --i444`: | ||
| 52 | + | ||
| 53 | +```text | ||
| 54 | +ffmpeg -f lavfi -i testsrc2=size=<N>x<N>:rate=25:duration=1 -pix_fmt yuv444p10le -f rawvideo src.yuv | ||
| 55 | +aomenc --codec=av1 -w N -h N --i444 --bit-depth=10 --input-bit-depth=10 --passes=1 | ||
| 56 | + --end-usage=q --cpu-used=0 --lag-in-frames=0 --kf-max-dist=1 --limit=2 | ||
| 57 | + --threads=1 --enable-rect-partitions=1 --enable-1to4-partitions=1 | ||
| 58 | + --min-partition-size=4 --max-partition-size=64 --sb-size=64 | ||
| 59 | + --tune-content=screen --enable-intrabc=1 --enable-palette=1 | ||
| 60 | + --cq-level=60 --enable-tx-size-search=0 --lossless=1 --profile=1 --obu -o out.obu src.yuv | ||
| 61 | +``` | ||
| 62 | + | ||
| 63 | +| witness | size | sha256 (16) | DEBUG | RELEASE (pre-fix) | | ||
| 64 | +| --- | --- | --- | --- | --- | | ||
| 65 | +| 256x256 | 51107 B | `fdb6467987095b99` | assert `(8, 4)` | `range end index 8 … length 0` | | ||
| 66 | +| 640x480 | 186912 B | `5e647e3afe60b5f6` | assert `(8, 4)` | `range end index 8 … length 0` | | ||
| 67 | + | ||
| 68 | +The ticket's `left: (4, 8)` did not reproduce; `left: (8, 4)` did, on both | ||
| 69 | +witnesses. Same defect, transposed unit. 4:2:0 cannot produce the shape at all | ||
| 70 | +(its smallest lossless chroma plane block is already 4x4) — which is why the | ||
| 71 | +gate asserts a 4:4:4 10-bit header. | ||
| 72 | + | ||
| 73 | +### Localisation | ||
| 74 | + | ||
| 75 | +A temporary `#[track_caller]` rung on `TxParams::run` and on | ||
| 76 | +`read_inter_plane_rect` (both removed before the commit) put every non-4x4 | ||
| 77 | +lossless unit on one pair of call sites, in `decode_intrabc_rect`'s var-tx arm: | ||
| 78 | + | ||
| 79 | +```text | ||
| 80 | +EC_RECTSITE plane=1 x=104 y=64 w=8 h=4 stride=8 at decode.rs:13392 (U) | ||
| 81 | +EC_RECTSITE plane=2 x=104 y=64 w=8 h=4 stride=8 at decode.rs:13410 (V) | ||
| 82 | +``` | ||
| 83 | + | ||
| 84 | +A census of `decode_intrabc_rect` over every pinned fixture shows its chroma | ||
| 85 | +plane block is `bw / 2` by `bh / 2` — a hardcoded 4:2:0 halving — so a 16x8 | ||
| 86 | +luma block at 4:4:4 got an 8x4 chroma plane block, and the walk read it as ONE | ||
| 87 | +rect transform unit. | ||
| 88 | + | ||
| 89 | +--- | ||
| 90 | + | ||
| 91 | +## r2 — What libaom actually does, and the decision | ||
| 92 | + | ||
| 93 | +Four independent places in the reference say a non-4x4 lossless transform unit | ||
| 94 | +cannot exist: | ||
| 95 | + | ||
| 96 | +1. `av1/decoder/decodeframe.c:140` — `read_tx_mode(rb, coded_lossless)`: | ||
| 97 | + `if (coded_lossless) return ONLY_4X4;` before the `tx_mode` symbol is even | ||
| 98 | + considered. | ||
| 99 | +2. `av1/decoder/decodeframe.c:1117` — `read_tx_size`: | ||
| 100 | + `if (xd->lossless[…]) return TX_4X4;` before any tree. | ||
| 101 | +3. `av1/common/blockd.h:1447` — `get_vartx_max_txsize`: | ||
| 102 | + `if (xd->lossless[…]) return TX_4X4;` for EVERY plane, which is what sizes | ||
| 103 | + the units `decode_token_recon_block` actually reads. | ||
| 104 | +4. `av1/common/idct.c:50` — the WHT dispatch. Of | ||
| 105 | + `highbd_inv_txfm_add_{4x4,4x8,8x4,16x4,…}_c`, **only** the 4x4 one carries a | ||
| 106 | + `lossless` branch (`if (lossless) { av1_highbd_iwht4x4_add(…); return; }`). | ||
| 107 | + Every other size falls straight through to the IDCT network. | ||
| 108 | + | ||
| 109 | +Point 4 is the decisive one for the "refuse or split?" question: libaom has no | ||
| 110 | +non-4x4 lossless inverse transform to dispatch *to*, because points 1–3 make | ||
| 111 | +the unit unreachable. So a non-4x4 lossless unit here is not a bitstream shape | ||
| 112 | +to be decoded — it is this decoder's own unit geometry being wrong. | ||
| 113 | + | ||
| 114 | +**Decision: split into 4x4 WHT calls, counted.** Not a refusal: refusing would | ||
| 115 | +turn a geometry bug into a decode failure with no way to see the pixels, and | ||
| 116 | +`TxParams::run` has no `Result` channel to the point where a refusal could be | ||
| 117 | +surfaced (it is called from the recorded-replay worker as well as inline). | ||
| 118 | +Splitting makes the function *total*: no shape panics, no shape returns a | ||
| 119 | +buffer its caller cannot index, release and debug agree, and the numbers are | ||
| 120 | +the ones a correct per-4x4 caller would have written for the same footprint. | ||
| 121 | +`LOSSLESS_WHT_SPLIT_UNITS` counts every 4x4 tile reconstructed this way, so a | ||
| 122 | +caller that regresses is *named* rather than absorbed. | ||
| 123 | + | ||
| 124 | +The 4x4 fast path is the same single `dequant_and_inverse_wht4x4` call it | ||
| 125 | +always was — `the_4x4_lossless_fast_path_is_unchanged` asserts byte-identity | ||
| 126 | +with and without the shape dispatch. | ||
| 127 | + | ||
| 128 | +The `debug_assert_eq!(self.tx_type, TxType::DctDct)` went with it: the WHT | ||
| 129 | +takes no `tx_type` (libaom's `av1_iwht4x4_add` does not either) and | ||
| 130 | +`av1_get_tx_type` already answers `DCT_DCT` on every plane of a lossless block, | ||
| 131 | +so it asserted an argument nothing reads — a debug-only panic on a value | ||
| 132 | +release ignores, i.e. the same divergence class. | ||
| 133 | + | ||
| 134 | +--- | ||
| 135 | + | ||
| 136 | +## r3 — The call site, and the defect this lane does NOT own | ||
| 137 | + | ||
| 138 | +`decode_intrabc_rect`, lossless arm: | ||
| 139 | + | ||
| 140 | +* chroma plane block = `bw >> ss_x` by `bh >> ss_y` at `(px >> ss_x, | ||
| 141 | + py >> ss_y)` — `av1_get_max_uv_txsize` is `ss_size_lookup[bsize]`, no halving | ||
| 142 | + of its own, so at 4:4:4 it is the block's own footprint; | ||
| 143 | +* walked as a `(cw/4) * (ch/4)` PLANE-MAJOR raster of TX_4X4 units through the | ||
| 144 | + existing `read_inter_chroma_lossless` (the same helper the inter 8x8 and 128 | ||
| 145 | + paths use), matching `decode_token_recon_block`'s | ||
| 146 | + `for plane { for blk_row { for blk_col } }`; | ||
| 147 | +* each unit's own coefficient context replayed **over** the whole-block | ||
| 148 | + `record_split_luma_rect_mi` from the composed grid — class | ||
| 149 | + `override-slot-on-one-arm`, the same one `decode_rect_split`'s | ||
| 150 | + `ll_chroma_units` replay exists for. (Getting this order wrong first cost | ||
| 151 | + the exact prefix below: with the replay *before* the record, frame 0's first | ||
| 152 | + divergence sat at x=226 and 18376 luma samples were wrong; after it, x=224 | ||
| 153 | + and 16022.) | ||
| 154 | + | ||
| 155 | +**Scoped to `lossless` on purpose.** The 4:2:0 halving is correct at 4:2:0. | ||
| 156 | +Every pinned 4:4:4 stream that reaches `decode_intrabc_rect` does so LOSSY | ||
| 157 | +(measured: the `lossless`-gated census over all 48 pins returns nothing), and | ||
| 158 | +that 4:4:4 lossy footprint is a separate, already-named open cell — | ||
| 159 | +`lanes/av1444rect.report.md`'s 4:4:4 intra-BC chroma. This lane does not move | ||
| 160 | +it. A lossless-only split changes no green pin either way. | ||
| 161 | + | ||
| 162 | +### OPEN after this lane (measured, not guessed) | ||
| 163 | + | ||
| 164 | +Pinned witness, 256x256 4:4:4 10-bit, 2 frames, 196608 samples per frame: | ||
| 165 | + | ||
| 166 | +| frame | plane | differing | first differing sample | | ||
| 167 | +| --- | --- | --- | --- | | ||
| 168 | +| 0 (key) | Y | 16022 / 65536 | 32992 → (x=224, y=128) | | ||
| 169 | +| 0 (key) | U | 16985 / 65536 | 32992 → (x=224, y=128) | | ||
| 170 | +| 0 (key) | V | 17047 / 65536 | 32992 → (x=224, y=128) | | ||
| 171 | +| 1 (inter) | Y | 1681 / 65536 | 55008 → (x=224, y=214) | | ||
| 172 | +| 1 (inter) | U | 4071 / 65536 | 9378 → (x=162, y=36) | | ||
| 173 | +| 1 (inter) | V | 4078 / 65536 | 9378 → (x=162, y=36) | | ||
| 174 | + | ||
| 175 | +On the key frame the fork is at the first column PAST the 16x8 lossless | ||
| 176 | +intra-BC block at mi (32, 52) = px (208, 128) — that block's own 16x8 luma and | ||
| 177 | +chroma are byte-exact, so the fork is at the block boundary, in the block that | ||
| 178 | +follows it. That is an entropy desync in a *different* block's residual walk, | ||
| 179 | +not the WHT shape: `LOSSLESS_WHT_SPLIT_UNITS` is 0 and no non-4x4 lossless unit | ||
| 180 | +exists anywhere in the decode. Not chased here — it is a distinct defect in a | ||
| 181 | +distinct path. | ||
| 182 | + | ||
| 183 | +The gate therefore asserts a measured per-frame, per-plane exact **prefix**, and | ||
| 184 | +says so in its own doc comment. Asserting "our output is wrong by exactly N" | ||
| 185 | +would encode the defect as expected behaviour; the prefix is the honest form | ||
| 186 | +and it only ever grows. | ||
| 187 | + | ||
| 188 | +--- | ||
| 189 | + | ||
| 190 | +## r4 — Gate and mutation proof | ||
| 191 | + | ||
| 192 | +`stream::tests::a_444_lossless_sb64_intrabc_rect_chroma_walks_4x4_units` | ||
| 193 | +(pinned fixture, length + FNV asserted first, 4:4:4 10-bit header asserted): | ||
| 194 | + | ||
| 195 | +1. `intrabc_rect_lossless_chroma4_hits() > 0` — `INTRABC_RECT_LOSSLESS_CHROMA4_HITS` | ||
| 196 | + is EXCLUSIVE to the per-4x4 chroma walk (no other caller walks a rect | ||
| 197 | + intra-BC block's chroma), so `>= 1` cannot be satisfied by the old | ||
| 198 | + single-unit read. | ||
| 199 | +2. `lossless_wht_split_units()` delta `== 0` — the shape-total entry is not | ||
| 200 | + quietly papering over a caller that is still wrong. | ||
| 201 | +3. `lossless_wht_units()` delta `> 0` — not vacuous. | ||
| 202 | +4. Both frames decode, and every decode-order frame's per-plane exact prefix | ||
| 203 | + matches the oracle's own `EC_AV1_FINAL_DUMP`. | ||
| 204 | + | ||
| 205 | +Plus four unit tests in `transform::lossless_tx_tests` covering the total entry | ||
| 206 | +directly (raster equality against independently-composed per-unit 4x4 calls for | ||
| 207 | +8x4 / 4x8 / 8x8 / 16x4 / 4x16 / 16x16, the 4x4 fast-path identity, the | ||
| 208 | +empty-grid marker, and the partially-zero grid whose other tiles hit the empty | ||
| 209 | +marker — that last one caught a real index panic in my first draft). | ||
| 210 | + | ||
| 211 | +### Mutation results (RELEASE profile, where the debug-only assert never ran) | ||
| 212 | + | ||
| 213 | +``` | ||
| 214 | +MUT1 decode_intrabc_rect reverted to the single rect unit + the 4:2:0 halving | ||
| 215 | + -> RED panicked at stream.rs:43682 | ||
| 216 | + "the pinned witness was refused: unsupported: AV1 tile | ||
| 217 | + (a Golomb tail longer than this decoder reads)" | ||
| 218 | + test result: FAILED. 0 passed; 1 failed | ||
| 219 | + | ||
| 220 | +MUT2 dequant_and_inverse_wht forced back to the 4x4-only path | ||
| 221 | + -> stream gate: GREEN (survives -- see finding below) | ||
| 222 | + -> lossless_tx_tests: RED | ||
| 223 | + a_non_4x4_lossless_unit_is_the_raster_of_4x4_wht_units FAILED | ||
| 224 | + assertion left == right failed: 8x4: residual length left: 16 right: 32 | ||
| 225 | + a_lossless_split_whose_other_tiles_are_all_zero_still_reconstructs FAILED | ||
| 226 | + assertion left == right failed: 8x4 residual length left: 16 right: 32 | ||
| 227 | + test result: FAILED. 3 passed; 2 failed | ||
| 228 | + | ||
| 229 | +MUT3 hit!(INTRABC_RECT_LOSSLESS_CHROMA4_HITS) removed | ||
| 230 | + -> RED panicked at stream.rs:43687 | ||
| 231 | + "no LOSSLESS rect intra-BC block walked its chroma as 4x4 units -- | ||
| 232 | + the corrected route never ran, so this gate is measuring the old | ||
| 233 | + single rect unit (class gate-blind-to-feature)" | ||
| 234 | + test result: FAILED. 0 passed; 1 failed | ||
| 235 | + | ||
| 236 | +LIVE restored tree: stream gate ok, lossless_tx_tests 5 passed | ||
| 237 | +``` | ||
| 238 | + | ||
| 239 | +**MUT2 survives the stream gate, and that is reported rather than papered over.** | ||
| 240 | +Assertion (2) is a *negative* assertion: after the call-site fix no non-4x4 | ||
| 241 | +lossless unit exists on this stream, so `split == 0` holds whether or not the | ||
| 242 | +total entry works. The stream gate therefore cannot be the positive coverage of | ||
| 243 | +`dequant_and_inverse_wht` for a non-4x4 shape — the four unit tests are, and | ||
| 244 | +they do bite. Do not read the green stream gate as "the split is exercised | ||
| 245 | +here". | ||
| 246 | + | ||
| 247 | +### Regression scope (release, named tests only — no full suite on this box) | ||
| 248 | + | ||
| 249 | +``` | ||
| 250 | +lossless 21 passed; 0 failed | ||
| 251 | +444 16 passed; 0 failed | ||
| 252 | +intrabc_rect 5 passed; 0 failed | ||
| 253 | +rect16x4_chroma_reach 1 passed; 0 failed | ||
| 254 | +a_444_lossless_sb64 1 passed; 0 failed (the new gate) | ||
| 255 | +a_444_intrabc_rect4 1 passed; 0 failed | ||
| 256 | +a_444_sb128_witness 1 passed; 0 failed | ||
| 257 | +real_aomenc_mixed_lossless 1 passed; 0 failed | ||
| 258 | +transform lossless_tx_tests 5 passed; 0 failed | ||
| 259 | +``` | ||
| 260 | + | ||
| 261 | +43 named gates across the lossless / 4:4:4 / intrabc-rect surface, green in | ||
| 262 | +release. `cargo check -p ec-av1` is warning-free. | ||
| 263 | + | ||
| 264 | +## r5 — Follow-ups this lane deliberately did not take | ||
| 265 | + | ||
| 266 | +1. **`read_block_tx_size_rect`'s lossless arm returns before writing the TXFM | ||
| 267 | + bands.** libaom's `parse_decode_block` (`decodeframe.c:1163`) calls | ||
| 268 | + `set_txfm_ctxs(mbmi->tx_size, xd->width, xd->height, …)` on the lossless | ||
| 269 | + path too; our early return skips it. Unreachable on a fully lossless frame | ||
| 270 | + (no `txfm_partition` symbol is read when `tx_mode == ONLY_4X4`), so it is | ||
| 271 | + latent, not measured-wrong. Not fixed here — it is a neighbour-band concern, | ||
| 272 | + not the WHT shape. | ||
| 273 | +2. **The 4:4:4 lossy chroma footprint of `decode_intrabc_rect`** (`bw / 2`, | ||
| 274 | + `px / 2`): wrong at 4:4:4, out of this lane's scope, already named in | ||
| 275 | + `lanes/av1444rect.report.md`. | ||
| 276 | +3. **The r3 entropy fork**, localised to the block following the first lossless | ||
| 277 | + 16x8 intra-BC rect block on the key frame and to (162, 36) on the inter | ||
| 278 | + frame's chroma. | ||