forge
Explore
Log in

Don't you dare go Hollow

lane-av1-ibc444rect: intrabc rect leaves at lossless 444 walk per-4x4 units

Browse files at this commit

0bfd062f388c081d2e70b872f4a97874ca50b668Ahmet Kaan GümüşParent: 16748dc
An unskipped intrabc BLOCK_8X4/BLOCK_4X8 leaf on a lossless frame reads
its coefficients as (bw/4)*(bh/4) inter TX_4X4 units, plane-major --
read_tx_size's lossless first line forces TX_4X4 before any tree, the
frame's TxMode is ONLY_4X4 so no var-tx tree is read either, and
av1_read_tx_type's qindex==0 return drops the tx_type the lossy 4x4
inter sets carry. The old route read one LumaRect8x4Inter /
ChromaRect8x4 rect unit and desynced (fail-before: the lossless WHT
assert (4, 8) != (4, 4) at TxParams::run).

- decode_leaf_rect8's intrabc arm: lossless non-skip leaves push the
  per-4x4 leaf list through the existing unit loop; the TXFM band
  publish defers to after the loop (set_txfm_ctxs runs at
  parse_decode_block's tail) and shrinks to (4, 4); the units' coding
  tx_type is nulled at lossless; the residual goes through TxParams
  with the frame's lossless flag (the dequant_and_inverse_typed_wh
  shortcut ran a DCT inverse over WHT-ordered levels).
- sub8_leaf_chroma444's intrabc non-square arm: lossless walks per-4x4
  TxbSet::Chroma4 units like the non-intrabc arm (lane-av1-llsub8),
  predicting the current frame at the DV.
- Counters INTRABC_RECT8_LOSSLESS_{LUMA,CHROMA}_HITS + stream
  accessors; gate a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units
  pins fixtures/ll444_ibc_rect.obu (provenance + measurement in
  lanes/av1ibc444rect.report.md).

Measured vs the instrumented aomdec: EC_TRACE_COEFF ladders align and
the walked leaves' samples are 0-diff on both planes (luma 0/339 leaves,
chroma clean); remaining fixture diffs sit exclusively on skipped
intrabc blocks (the skipped-intrabc sub8 chroma predictor, escalated in
the report) behind the llintra-deferred decode_leaf8 8x8 buffers, which
this lane does not touch. 4:2:0 unchanged: the lossless 420 key/inter,
loss64, 444 key-frame, dodge2 inter and ten lossy intrabc gates all
green.
crates/ec-av1/fixtures/ll444_ibc_rect.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+152 -6
@@ -5325,6 +5325,13 @@ thread_local! {
5325 /// walked at subsampling 0/0 (one unit per mi cell -- the geometry the5325 /// walked at subsampling 0/0 (one unit per mi cell -- the geometry the
5326 /// hardcoded 4:2:0 span mis-stepped).5326 /// hardcoded 4:2:0 span mis-stepped).
5327 static RECT_SPLIT_LOSSLESS_CHROMA444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };5327 static RECT_SPLIT_LOSSLESS_CHROMA444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
5328+ /// lane-av1-ibc444rect: unskipped intrabc 8x4/4x8 leaves whose luma
5329+ /// coefficients a lossless frame walked as per-4x4 inter units (the walk
5330+ /// that replaced the single rect unit).
5331+ static INTRABC_RECT8_LOSSLESS_LUMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
5332+ /// lane-av1-ibc444rect: unskipped intrabc 8x4/4x8 leaves whose chroma a
5333+ /// lossless 4:4:4 frame walked as per-4x4 [`TxbSet::Chroma4`] units.
5334+ static INTRABC_RECT8_LOSSLESS_CHROMA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
5328 }5335 }
5329 5336
5330 /// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape5337 /// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape
@@ -5355,6 +5362,24 @@ pub fn rect_split_lossless_chroma444_hits() -> usize {
5355 RECT_SPLIT_LOSSLESS_CHROMA444_HITS.with(|c| c.get())5362 RECT_SPLIT_LOSSLESS_CHROMA444_HITS.with(|c| c.get())
5356 }5363 }
5357 5364
5365+/// How many unskipped intrabc 8x4/4x8 leaves a lossless frame walked luma as
5366+/// per-4x4 inter units (lane-av1-ibc444rect).
5367+pub fn intrabc_rect8_lossless_luma_hits() -> usize {
5368+ INTRABC_RECT8_LOSSLESS_LUMA_HITS.with(|c| c.get())
5369+}
5370+
5371+/// How many unskipped intrabc 8x4/4x8 leaves a lossless 4:4:4 frame walked
5372+/// chroma as per-4x4 [`TxbSet::Chroma4`] units (lane-av1-ibc444rect).
5373+pub fn intrabc_rect8_lossless_chroma_hits() -> usize {
5374+ INTRABC_RECT8_LOSSLESS_CHROMA_HITS.with(|c| c.get())
5375+}
5376+
5377+/// Gate-side reset for the two lane-av1-ibc444rect counters above.
5378+pub fn reset_ibc444rect_hits() {
5379+ INTRABC_RECT8_LOSSLESS_LUMA_HITS.with(|c| c.set(0));
5380+ INTRABC_RECT8_LOSSLESS_CHROMA_HITS.with(|c| c.set(0));
5381+}
5382+
5358 /// Gate-side reset for the two lane-av1-loss64 counters above.5383 /// Gate-side reset for the two lane-av1-loss64 counters above.
5359 pub fn reset_loss64_hits() {5384 pub fn reset_loss64_hits() {
5360 CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.set(0));5385 CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.set(0));
@@ -18951,6 +18976,63 @@ fn sub8_leaf_chroma444(
18951 )?;18976 )?;
18952 (ug, vg, 4, 4)18977 (ug, vg, 4, 4)
18953 } else {18978 } else {
18979+ // lane-av1-ibc444rect: the unskipped lossless chroma walk this
18980+ // lane fixes (one rect unit -> per-4x4 Chroma4 units).
18981+ if lossless(fctx) {
18982+ hit!(INTRABC_RECT8_LOSSLESS_CHROMA_HITS);
18983+ }
18984+ if lossless(fctx) {
18985+ // lane-av1-ibc444rect: at lossless `read_tx_size` forces
18986+ // TX_4X4 on EVERY plane (`av1_get_tx_size`'s lossless
18987+ // first line), so this rect leaf's chroma is (bw/4)*(bh/4)
18988+ // TX_4X4 units at their own 4x4 origins -- not the single
18989+ // `ChromaRect8x4` rect unit the non-lossless arm below reads
18990+ // (`av1_get_max_uv_txsize(BLOCK_8X4)`'s rect, unreachable at
18991+ // lossless). Same walk the leaf's own non-intrabc lossless
18992+ // arm runs (lane-av1-llsub8's fix), plane-major per libaom
18993+ // `decode_token_recon_block`, with the intra predictor
18994+ // swapped for the CURRENT frame at the DV; CFL is never
18995+ // allowed at lossless and no alpha rides an intrabc leaf.
18996+ let mut out_u = Grid::Own(vec![0i32; bw * bh]);
18997+ let mut out_v = Grid::Own(vec![0i32; bw * bh]);
18998+ for (plane_idx, buf) in [(1usize, u), (2usize, v)] {
18999+ for ur in 0..bh / 4usize {
19000+ for uc in 0..bw / 4usize {
19001+ let (umi_r, umi_c) = (lmi.0 + ur, lmi.1 + uc);
19002+ let (upx, upy) = (px + uc * 4, py + ur * 4);
19003+ let mut pb = vec![0u16; 16];
19004+ mc::predict_with_filter(
19005+ &buf.data, buf.width, buf.true_width, buf.true_height,
19006+ mv_to_q4(upx, dv.1, 0), mv_to_q4(upy, dv.0, 0),
19007+ 4, 4, mc::InterpFilterKind::Bilinear, &mut pb, fctx,
19008+ );
19009+ set_palette_pred(pb, fctx);
19010+ let unit_around = neighbours.around_mi_rect((umi_r, umi_c), 4, 4);
19011+ let unit_reach = Reach::of(4, upx, upy, y.width, y.height, fctx);
19012+ let grid = read_plane(
19013+ dec, cdfs, TxbSet::Chroma4, scan4, plane_idx, unit_around[plane_idx],
19014+ DC_PRED, DC_PRED, 0, unit_reach, buf, upx, upy, 4,
19015+ TX4, base_q_idx, None, None, Some(3), smooth_neighbor_uv, fctx,
19016+ )?;
19017+ let cell = grid_unit_state(&grid, 4, 0, 0, 4, 4);
19018+ if umi_r < neighbours.mi_rows {
19019+ neighbours.left[umi_r][plane_idx] = cell;
19020+ }
19021+ if umi_c < neighbours.mi_cols {
19022+ neighbours.above[umi_c][plane_idx] = cell;
19023+ }
19024+ let out = if plane_idx == 1 { &mut out_u } else { &mut out_v };
19025+ if let Grid::Own(v) = out {
19026+ for r in 0..4usize {
19027+ v[(ur * 4 + r) * bw + uc * 4..][..4]
19028+ .copy_from_slice(&grid[r * 4..][..4]);
19029+ }
19030+ }
19031+ }
19032+ }
19033+ }
19034+ (out_u, out_v, 4, 4)
19035+ } else {
18954 let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 };19036 let scan: &[u16] = if bw > bh { &SCAN_8X4 } else { &SCAN_4X8 };
18955 let default_tx =19037 let default_tx =
18956 fctx.intrabc_chroma_tx.with(std::cell::Cell::get).unwrap_or(TxType::DctDct);19038 fctx.intrabc_chroma_tx.with(std::cell::Cell::get).unwrap_or(TxType::DctDct);
@@ -18977,6 +19059,7 @@ fn sub8_leaf_chroma444(
18977 if plane_idx == 1 { out.0 = levels; } else { out.1 = levels; }19059 if plane_idx == 1 { out.0 = levels; } else { out.1 = levels; }
18978 }19060 }
18979 out19061 out
19062+ }
18980 };19063 };
18981 fctx.intrabc_chroma_tx.with(|c| c.set(None));19064 fctx.intrabc_chroma_tx.with(|c| c.set(None));
18982 pair19065 pair
@@ -19616,6 +19699,11 @@ fn decode_leaf_rect8(
19616 neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode);19699 neighbours.record_mode_mi(lmi.0, lmi.1, w_mi, h_mi, mode);
19617 let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left);19700 let smooth_neighbor = is_smooth_mode(leaf_above) || is_smooth_mode(leaf_left);
19618 if let Some(dv) = intrabc {19701 if let Some(dv) = intrabc {
19702+ // lane-av1-ibc444rect: the unskipped lossless luma walk this lane
19703+ // fixes (one rect unit -> per-4x4 inter units).
19704+ if !skip && lossless(fctx) {
19705+ hit!(INTRABC_RECT8_LOSSLESS_LUMA_HITS);
19706+ }
19619 // lane-av1txr: an intrabc `BLOCK_4X8`/`BLOCK_8X4` leaf. The19707 // lane-av1txr: an intrabc `BLOCK_4X8`/`BLOCK_8X4` leaf. The
19620 // prediction is a frame copy at the DV and the residual reads the19708 // prediction is a frame copy at the DV and the residual reads the
19621 // INTER `LumaRect8x4` set -- but with `TxMode::Select` the leaf19709 // INTER `LumaRect8x4` set -- but with `TxMode::Select` the leaf
@@ -19634,6 +19722,10 @@ fn decode_leaf_rect8(
19634 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);19722 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
19635 flush_recon(fctx, y, u, v);19723 flush_recon(fctx, y, u, v);
19636 let mut luma_leaves: Vec<(usize, usize, usize, usize)> = Vec::new();19724 let mut luma_leaves: Vec<(usize, usize, usize, usize)> = Vec::new();
19725+ // The non-var-tx band publish, deferred to AFTER the unit loop:
19726+ // libaom's `set_txfm_ctxs` runs at `parse_decode_block`'s tail, so
19727+ // a unit's own `txb_skip_ctx` read must see the PRE-block bands.
19728+ let mut publish = Some((bw, bh));
19637 if tx_select && !skip {19729 if tx_select && !skip {
19638 // `max_block_wide`/`max_block_high`: the frame's own mi grid,19730 // `max_block_wide`/`max_block_high`: the frame's own mi grid,
19639 // so a leaf hanging over the right/bottom edge reads no split19731 // so a leaf hanging over the right/bottom edge reads no split
@@ -19656,13 +19748,34 @@ fn decode_leaf_rect8(
19656 &mut luma_leaves,19748 &mut luma_leaves,
19657 );19749 );
19658 hit!(RECT_INTRABC_VARTX_HITS);19750 hit!(RECT_INTRABC_VARTX_HITS);
19751+ publish = None;
19752+ } else if lossless(fctx) && !skip {
19753+ // lane-av1-ibc444rect: `read_tx_size`'s lossless first line
19754+ // (`decodeframe.c:1203`) answers TX_4X4 for EVERY plane before
19755+ // any tree, and a lossless frame's `TxMode` is `ONLY_4X4`
19756+ // (spec 6.8.20) so no var-tx tree is read either -- the leaf's
19757+ // coefficients are (bw/4)*(bh/4) inter TX_4X4 units at their
19758+ // own origins, plane-major, NOT the single rect transform the
19759+ // non-lossless arm reads (that one is
19760+ // `av1_get_max_uv_txsize(BLOCK_8X4)`'s rect, unreachable at
19761+ // lossless). Same unit structure the non-intrabc lossless
19762+ // split below walks; each unit predicts from the CURRENT
19763+ // frame at the DV. Measured on the lane's `e4` fixture
19764+ // (`ll444_ibc_rect.obu`): the single-rect read desynced the
19765+ // tile and tripped the lossless WHT assert `(4, 8) != (4, 4)`
19766+ // at `TxParams::run`.
19767+ for ur in 0..bh / 4usize {
19768+ for uc in 0..bw / 4usize {
19769+ luma_leaves.push((ur, uc, 4, 4));
19770+ }
19771+ }
19772+ publish = Some((4, 4));
19659 } else {19773 } else {
19660 luma_leaves.push((0, 0, bw, bh));19774 luma_leaves.push((0, 0, bw, bh));
19661 // The non-var-tx arm: a SKIPPED intrabc leaf (or a frame19775 // The non-var-tx arm: a SKIPPED intrabc leaf (or a frame
19662 // outside `TxMode::Select`) publishes its own rect transform19776 // outside `TxMode::Select`) publishes its own rect transform
19663 // (`set_txfm_ctxs`'s `skip && is_inter` branch writes the19777 // (`set_txfm_ctxs`'s `skip && is_inter` branch writes the
19664 // block's own pixels -- the same size here).19778 // block's own pixels -- the same size here).
19665- txfm_partition_update_rect(neighbours, lmi, (bw, bh), (bw, bh));
19666 }19779 }
19667 // The transform type an intrabc block's CHROMA inherits is the19780 // The transform type an intrabc block's CHROMA inherits is the
19668 // `tx_type_map` entry at the chroma unit's co-located luma19781 // `tx_type_map` entry at the chroma unit's co-located luma
@@ -19721,6 +19834,17 @@ fn decode_leaf_rect8(
19721 )19834 )
19722 };19835 };
19723 let mut coding = cdfs.txb(set, DC_PRED);19836 let mut coding = cdfs.txb(set, DC_PRED);
19837+ // lane-av1-ibc444rect: `av1_read_tx_type` returns before any
19838+ // symbol for a lossless block (qindex == 0, decodemv.c:681)
19839+ // on EVERY plane and size -- the lossless units this arm now
19840+ // walks must not read the set's tx_type either (`read_plane`
19841+ // does the same for its own call sites). Measured on the
19842+ // lane's `ll444_ibc_rect.obu`: with the symbol read, the
19843+ // first unit's ladder diverged right after a matched
19844+ // `all_zero` (ours +4096 rng on the unused tx_type).
19845+ if lossless(fctx) {
19846+ coding.tx_type = None;
19847+ }
19724 let (levels, tx_type) = read_coeffs_rect(19848 let (levels, tx_type) = read_coeffs_rect(
19725 dec, &mut coding, tu_scan, tw, th, skip_ctx, dc_sign_ctx(around.2),19849 dec, &mut coding, tu_scan, tw, th, skip_ctx, dc_sign_ctx(around.2),
19726 TxType::DctDct,19850 TxType::DctDct,
@@ -19729,11 +19853,28 @@ fn decode_leaf_rect8(
19729 chroma_tx = tx_type;19853 chroma_tx = tx_type;
19730 fctx.luma_tx_type.with(|c| c.set(tx_type));19854 fctx.luma_tx_type.with(|c| c.set(tx_type));
19731 }19855 }
19732- let residual = dequant_and_inverse_typed_wh(19856+ // lane-av1-ibc444rect: the residual goes through [`TxParams`]
19733- &levels, tw, th, crate::decode::bit_depth(fctx), block_q_idx(fctx),19857+ // with the frame's lossless flag, exactly like
19734- plane_q_delta(0, fctx).0, plane_q_delta(0, fctx).1, tx_type,19858+ // [`read_plane`]'s own dequant -- at lossless `TxParams::run`
19735- block_iqmatrix(fctx, 0, tw, th, tx_type),19859+ // is the Walsh-Hadamard inverse on every plane, and the
19736- );19860+ // `dequant_and_inverse_typed_wh` shortcut the lossy var-tx
19861+ // callers use has no lossless flag (it would run the DCT
19862+ // inverse over the WHT-ordered levels). Measured on the lane
19863+ // fixture: the DCT route left ±1..30 sample errors on every
19864+ // walked leaf's luma.
19865+ let tx = TxParams {
19866+ w: tw,
19867+ h: th,
19868+ bit_depth: crate::decode::bit_depth(fctx),
19869+ q_idx: block_q_idx(fctx),
19870+ dc_delta: plane_q_delta(0, fctx).0,
19871+ ac_delta: plane_q_delta(0, fctx).1,
19872+ tx_type,
19873+ qm: block_iqmatrix(fctx, 0, tw, th, tx_type),
19874+ stride: 0,
19875+ lossless: lossless(fctx),
19876+ };
19877+ let residual = tx.run(&levels);
19737 if (tw, th) == (4, 4) {19878 if (tw, th) == (4, 4) {
19738 push_intra(0, tu_px, tu_py, 4, DC_PRED, 0, tu_reach, &residual, None, None, smooth_neighbor, fctx);19879 push_intra(0, tu_px, tu_py, 4, DC_PRED, 0, tu_reach, &residual, None, None, smooth_neighbor, fctx);
19739 } else {19880 } else {
@@ -19751,6 +19892,11 @@ fn decode_leaf_rect8(
19751 neighbours.record_mi_luma(tu_mi, 4, &tu_grid);19892 neighbours.record_mi_luma(tu_mi, 4, &tu_grid);
19752 }19893 }
19753 }19894 }
19895+ // The deferred non-var-tx band publish (see `publish` above): the
19896+ // units' `txb_skip_ctx` reads ran against the pre-block bands.
19897+ if let Some((pub_w, pub_h)) = publish {
19898+ txfm_partition_update_rect(neighbours, lmi, (pub_w, pub_h), (bw, bh));
19899+ }
19754 if single {19900 if single {
19755 let state = neighbour_state(&grid);19901 let state = neighbour_state(&grid);
19756 for cell in 0..h_mi {19902 for cell in 0..h_mi {
crates/ec-av1/src/stream.rsmodified+110 -0
@@ -126,6 +126,23 @@ pub fn rect_intrabc_reads() -> usize {
126 crate::decode::rect_intrabc_reads()126 crate::decode::rect_intrabc_reads()
127 }127 }
128 128
129+/// lane-av1-ibc444rect: unskipped intrabc 8x4/4x8 leaves whose luma a lossless
130+/// frame walked as per-4x4 inter units.
131+pub fn intrabc_rect8_lossless_luma_hits() -> usize {
132+ crate::decode::intrabc_rect8_lossless_luma_hits()
133+}
134+
135+/// lane-av1-ibc444rect: unskipped intrabc 8x4/4x8 leaves whose chroma a
136+/// lossless 4:4:4 frame walked as per-4x4 `Chroma4` units.
137+pub fn intrabc_rect8_lossless_chroma_hits() -> usize {
138+ crate::decode::intrabc_rect8_lossless_chroma_hits()
139+}
140+
141+/// Gate-side reset for the lane-av1-ibc444rect counters above.
142+pub fn reset_ibc444rect_hits() {
143+ crate::decode::reset_ibc444rect_hits()
144+}
145+
129 /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900146 /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900
130 /// r22) -- the counter a screen-content witness gate reads to prove it147 /// r22) -- the counter a screen-content witness gate reads to prove it
131 /// exercises the inter-frame palette path, not the key frame's.148 /// exercises the inter-frame palette path, not the key frame's.
@@ -5974,6 +5991,99 @@ pub(crate) mod tests {
5974 );5991 );
5975 }5992 }
5976 5993
5994+ /// lane-av1-ibc444rect: an unskipped intrabc `BLOCK_8X4`/`BLOCK_4X8` leaf
5995+ /// on a lossless 4:4:4 frame walks its coefficients as per-4x4 inter
5996+ /// `TX_4X4` units on every plane -- `read_tx_size`'s lossless first line
5997+ /// (`decodeframe.c:1203`) forces TX_4X4 before any tree, the frame's
5998+ /// `TxMode` is `ONLY_4X4` so no var-tx tree is read either, and
5999+ /// `av1_read_tx_type`'s qindex==0 early return (`decodemv.c:681`) drops
6000+ /// the tx_type symbol the lossy 4x4 inter sets carry -- NOT the single
6001+ /// `LumaRect8x4Inter`/`ChromaRect8x4` rect unit the non-lossless arm
6002+ /// reads, and not the lossy per-unit arm's tx_type read.
6003+ ///
6004+ /// The pinned fixture `ll444_ibc_rect.obu` (99614 bytes, provenance and
6005+ /// the full pixel measurement in `lanes/av1ibc444rect.report.md`) is a
6006+ /// lossless `--profile=1 --i444 --enable-intrabc=1` key frame. Its first
6007+ /// unskipped intrabc rect leaf (mi (33,2), 8x4, dv (-64, -832)) must walk
6008+ /// its luma + chroma per-4x4 units with the tile's entropy ladder still
6009+ /// aligned afterwards -- three leaves walk before the frame reaches an
6010+ /// intrabc `BLOCK_8X8` leaf, whose llintra-deferred 8x8 chroma prediction
6011+ /// buffers
6012+ /// (`decode_leaf8`'s 16-sample `ub`/`vb`, their deferral in
6013+ /// `lanes/av1llintra.report.md`) panic in `palette_window` -- on the
6014+ /// committed tree that panic is this gate's ALIGNMENT WITNESS: any
6015+ /// unit-structure, context or tx_type regression in the walk desyncs the
6016+ /// tile long before mi (32,10) and the death signature moves (the
6017+ /// fail-before was the lossless WHT assert `(4, 8) != (4, 4)` at
6018+ /// `TxParams::run`). Measured with the two-line 8x8 buffer probe applied
6019+ /// (never committed): the walk is pixel-exact, luma 0 differing samples
6020+ /// on all 339 walked leaves and the walked leaves' chroma clean; the only
6021+ /// remaining diffs sit on SKIPPED intrabc blocks (the skipped-intrabc
6022+ /// sub8 chroma predictor defect, class-adjacent to the reserved 4:2:0
6023+ /// tail skip arm). When the 8x8 buffers are fixed in their owning lane,
6024+ /// this gate flips to a full-frame exact `aomdec` comparison.
6025+ #[test]
6026+ fn a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units() {
6027+ const NAME: &str = "a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units";
6028+ const FIXTURE_LEN: usize = 99614;
6029+ const FIXTURE_FNV: u64 = 0xa1b6_a84e_ac6a_656f;
6030+ let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
6031+ .join("fixtures/ll444_ibc_rect.obu");
6032+ let stream = std::fs::read(&obu).unwrap_or_else(|e| {
6033+ panic!(
6034+ "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \
6035+ which is a failure, not a skip",
6036+ obu.display()
6037+ )
6038+ });
6039+ assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved");
6040+ assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved");
6041+
6042+ let _guard = lock_gate_counters();
6043+ crate::decode::reset_ibc444rect_hits();
6044+ // The known leaf8 panic is the expected outcome; keep it out of the
6045+ // test log and catch it as a value.
6046+ let prev_hook = std::panic::take_hook();
6047+ std::panic::set_hook(std::boxed::Box::new(|_| {}));
6048+ let result = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| {
6049+ decode_stream(&stream)
6050+ }));
6051+ std::panic::set_hook(prev_hook);
6052+ let luma = crate::decode::intrabc_rect8_lossless_luma_hits();
6053+ let chroma = crate::decode::intrabc_rect8_lossless_chroma_hits();
6054+ assert_eq!(
6055+ (luma, chroma),
6056+ (3, 3),
6057+ "{NAME}: the walk must fire exactly three times before the known \
6058+ leaf8 death (got luma {luma}, chroma {chroma}) -- zero means the \
6059+ fixture no longer reaches the fixed body (class \
6060+ gate-blind-to-feature), more means the entropy desynced and \
6061+ garbage blocks read as intrabc rect leaves"
6062+ );
6063+ let payload = match result {
6064+ Err(e) => e,
6065+ Ok(_) => panic!(
6066+ "{NAME}: the fixture decoded to completion -- the known \
6067+ llintra-deferred leaf8 panic at mi (32,10) is gone; flip this \
6068+ gate to the full-frame exact aomdec comparison"
6069+ ),
6070+ };
6071+ let msg = payload
6072+ .downcast_ref::<String>()
6073+ .map(String::as_str)
6074+ .or_else(|| payload.downcast_ref::<&'static str>().copied())
6075+ .unwrap_or("");
6076+ assert!(
6077+ msg.contains("range end index 4 out of range for slice of length 0"),
6078+ "{NAME}: the decode died somewhere OTHER than the known leaf8 \
6079+ palette_window site -- the walk desynced the tile (panic: {msg})"
6080+ );
6081+ eprintln!(
6082+ "{NAME}: walk fired once (luma + chroma), entropy aligned through \
6083+ the leaf, death at the known leaf8 site"
6084+ );
6085+ }
6086+
5977 /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and6087 /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and
5978 /// colours used to stay standing in the mi-granular above/left bands after a6088 /// colours used to stay standing in the mi-granular above/left bands after a
5979 /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published6089 /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published
lanes/av1ibc444rect.report.mdadded+147 -0
@@ -0,0 +1,147 @@
1+# lane-av1-ibc444rect: intrabc rect-leaf chroma walk at lossless 4:4:4 (r1)
2+
3+## Charter
4+
5+Fix the deferred `av1llsub8` gap: intrabc rect leaves at lossless 444 routed
6+the rect arm's `read_coeffs_rect` path with the wrong unit structure.
7+Unblocked by the green inter side (av1llinter2). Work in
8+`edith_codecs-av1ibc444rect` @ 9e77c16b. 4:2:0 stays identical; existing
9+lossless gates stay green. At most 8 encodes for the fixture.
10+
11+## Defect (both planes of the intrabc route)
12+
13+`decode_leaf_rect8`'s intrabc arm at lossless pushed ONE rect unit:
14+
15+- luma: `read_coeffs_rect(LumaRect8x4Inter, 8x4)` — one TX_8X4-shaped read,
16+- chroma: `sub8_leaf_chroma444`'s non-square arm, one `ChromaRect8x4` read.
17+
18+The oracle codes per-4x4 INTER TX_4X4 units, plane-major: `read_tx_size`'s
19+lossless first line (`decodeframe.c:1203`) forces TX_4X4 before any tree, the
20+frame's `TxMode` is `ONLY_4X4` (spec 6.8.20) so no var-tx tree either, and
21+`av1_read_tx_type`'s `qindex == 0` early return (`decodemv.c:681`) drops the
22+tx_type symbol the LOSSY 4x4 inter sets DO carry. Fail-before, measured: the
23+single-rect read desynced the tile and tripped the lossless WHT assert
24+`(4, 8) != (4, 4)` at `TxParams::run` — the same panic class av1llinter2
25+attributed on the inter side.
26+
27+## Fix (same shape as the non-intrabc arm)
28+
29+1. `decode_leaf_rect8` intrabc arm, `lossless && !skip`: the leaf's luma
30+ coefficients become `(bw/4)*(bh/4)` 4x4 units in the EXISTING per-unit
31+ loop (var-tx `(tw,th)==(4,4)` mechanics: `inter_txbset_for(4)`,
32+ `scan4`, per-unit `around_mi`, `luma_skip_ctx`, DV copy prediction via
33+ the palette slot, `push_intra`). The TXFM band publish moved AFTER the
34+ unit loop (`set_txfm_ctxs` runs at `parse_decode_block`'s tail, so the
35+ units' own `txb_skip_ctx` reads must see the pre-block bands). The units'
36+ `coding.tx_type` is nulled at lossless — WITHOUT this the ladder diverges
37+ immediately (ours +4096 rng on a symbol the oracle never codes; found by
38+ the `EC_TRACE_COEFF` ladder, oracle O#1353 vs ours G#1359-1361 on the
39+ fixture's first leaf).
40+2. The units' residual goes through `TxParams { lossless: lossless(fctx) }`
41+ (read_plane's own route), NOT `dequant_and_inverse_typed_wh` — the latter
42+ has no lossless flag and ran a DCT inverse over the WHT-ordered levels
43+ (±1..30 sample errors on every walked leaf; gone after the fix).
44+3. `sub8_leaf_chroma444`'s intrabc non-square arm, `lossless`: per-4x4
45+ `TxbSet::Chroma4` walk mirroring the lane-av1-llsub8 fix (per-unit
46+ `around_mi_rect`, `Reach::of`, per-unit entropy stamps, `Some(3)` big-row
47+ fold), with the intra predictor swapped for the CURRENT frame at the DV.
48+4. Skip arms untouched. 4:2:0: the luma walk also applies at 420 lossless
49+ (luma is subsampling-independent) — that route was equally broken before
50+ and no committed gate reaches it; every currently-green stream is
51+ bit-identical (all 16 battery gates below).
52+
53+Counters `INTRABC_RECT8_LOSSLESS_LUMA_HITS`/`_CHROMA_HITS` + accessors
54+(`stream::intrabc_rect8_lossless_{luma,chroma}_hits`,
55+`reset_ibc444rect_hits`) pin the walk for the gate.
56+
57+## Fixture (bounded grid: 8 encodes, budget used 8/8)
58+
59+`fixtures/ll444_ibc_rect.obu`, 99614 bytes, sha256
60+`482dedca0201beea9b0a05720b5da7fe93c350c9fea7699cdb010c3fbc227ec0`.
61+Source: `lanes/av1ibc444rect_fixture_gen.py` (sha256
62+`3420a1f80603efc16a66a37be72d04dcd66836df0dc79d28710511c165ef92f1`,
63+y4m sha256 `5d3b8a2cbce29766852806787811f28a0b7b7df75409915666bad087e0cc9768`):
64+320x240 C444, dithered chaotic base + single-half 8x4/4x8 near-match stamps
65+(per-copy bias + random flips — never an exact match). Encoder:
66+`$HOME/.cache/aom-oracle/build/aomenc --codec=av1 --bit-depth=8
67+--input-bit-depth=8 --passes=1 --cpu-used=0 --lag-in-frames=0 --kf-max-dist=1
68+--limit=1 --threads=1 --tile-columns=0 --lossless=1 --sb-size=128
69+--enable-1to4-partitions=1 --profile=1 --i444 --enable-intrabc=1
70+--tune-content=screen --min-partition-size=4 --max-partition-size=8 --obu`.
71+The stream codes hundreds of unskipped intrabc rect leaves (oracle inspect
72+census: 8x4 + 4x8 + 4x4 intrabc, most non-skip).
73+
74+Grid summary (all probed with env-gated shape prints + the counters):
75+testsrc2-based and five crafted variants; every stream that codes intrabc
76+rect leaves ALSO codes an intrabc `BLOCK_8X8` leaf (aomenc's dominant
77+intrabc shape — 284 of them in the E7 census) and/or skipped intrabc leaves.
78+`--max-partition-size` cannot forbid 8x8 `PARTITION_NONE` while keeping
79+8x4/4x8 leaves; content shaping reduced but never eliminated 8x8 intrabc.
80+
81+## Verification (measured)
82+
83+- Entropy: `EC_TRACE_COEFF` ladders aligned ours-vs-instrumented-aomdec
84+ (`~/.cache/aom-oracle/build`, `EC_TRACE_COEFF=1`); post-fix the tile runs
85+ through all walked leaves with no desync (pre-fix: desync at the first
86+ leaf's eob read, then the WHT assert).
87+- Pixel exactness of the walk vs the oracle `aomdec --rawvideo`, measured
88+ with a THROWAWAY two-line patch of the sibling 8x8 defect (16->block-size
89+ chroma prediction buffers in `decode_leaf8`) — applied ONLY to measure,
90+ reverted before commit, never part of this lane's diff:
91+ - E4 fixture: luma 0 differing samples; chroma diffs ONLY on skipped
92+ intrabc cells (36727 bytes, 100% `(intrabc=1, skip=1)` cells + their
93+ poisoned neighbours; zero on walked leaves).
94+ - E8 (= the committed fixture): 339 walked rect leaves; luma 0 differing
95+ samples; chroma 5624 bytes, again exclusively on `(intrabc=1, skip=1)`
96+ cells + neighbours.
97+- Gate `a_lossless_444_intrabc_rect_leaf_walks_per_4x4_units` (green):
98+ pins fixture len/FNV, asserts the walk fires exactly (3, 3) before the
99+ known leaf8 death and that the death signature is the leaf8
100+ `palette_window` slice — i.e. the entropy ladder survived the walked
101+ leaves. Fail-before: pre-fix the death was the `(4, 8) != (4, 4)` WHT
102+ assert. Mutation check: flipping the chroma `Some(3)` ctx to `None`
103+ fails the gate (desync moves the death).
104+- Battery, all green: `a_lossless_libaom_key_frame_decodes_sample_exact`,
105+ `a_lossless_libaom_inter_frame_decodes_sample_exact`,
106+ `a_real_aomenc_lossless_444_key_frame_decodes_sample_exact`,
107+ `a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands`,
108+ `a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact`, the new
109+ gate, plus the ten lossy intrabc gates (screen-kf intrabc reads, 16x4
110+ pair strip, both-orientation rect intrabc, sb128 screen + rect strip,
111+ tx4 leaf chroma, sub8 census, var-tx census, mixed var-tx tree, tx-select
112+ census). `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors.
113+
114+## Not claimed
115+
116+The committed tree does NOT decode either candidate fixture to a full frame:
117+every reaching stream panics at its first intrabc `BLOCK_8X8` leaf on the
118+llintra-deferred defect. Whole-fixture 0-diff is therefore NOT claimed and
119+cannot be measured on this tree; the walk's own samples are measured 0-diff
120+as above.
121+
122+## Blocked-by / deferred (spoken, not hidden)
123+
124+1. `decode_leaf8`'s intrabc chroma prediction buffers, hardcoded 4x4
125+ (16 samples for a 64-sample 4:4:4 reconstruct) — panics at
126+ `palette_window` (decode.rs ~2460). OWNER: the `av1llintra` deferral; this
127+ lane did NOT touch `decode_leaf8` (different function, sibling
128+ ownership). Fix is its own two lines (buffer + predict size follow
129+ `chroma_444`); after it lands, decode completes and this lane's gate
130+ flips to the full-frame exact comparison.
131+2. Skipped-intrabc sub-8x8 chroma predictor: `sub8_leaf_chroma444`'s skip
132+ arm (and the 4:2:0 group-tail skip arm) predict INTRA-DC where libaom
133+ predicts the frame copy at the DV (`av1_build_inter_predictors_sb` runs
134+ regardless of skip for an intrabc block). All remaining E4/E8 chroma
135+ diffs sit exactly on those cells. UNNAMED in any prior report (loss64
136+ fixed the STRIP path only); class-adjacent to the RESERVED 4:2:0
137+ group-tail skip arm, so per the standing reservation this lane stops and
138+ escalates instead of editing. Needs: consult the DV in the skip arms
139+ (armed palette slot), plus a fixture gate.
140+3. `av1llintra2`'s rect64 lossless chroma gap (`EC_RECTCHROMA_GAP`) remains
141+ deferred in its own lane; not touched here.
142+
143+## Function-collision statement
144+
145+This lane's diff lands only in `decode_leaf_rect8` and `sub8_leaf_chroma444`
146+(+ counters in decode.rs, accessors/gate in stream.rs). `decode_leaf8` —
147+where the blocking sibling defect lives — is untouched, byte-for-byte.
lanes/av1ibc444rect_fixture_gen.pyadded+40 -0
@@ -0,0 +1,40 @@
1+import sys, random
2+W, H = 320, 240
3+rng = random.Random(60606)
4+y = bytearray(W*H); u = bytearray(W*H); v = bytearray(W*H)
5+def base(x, y):
6+ return ((x*3 + y*5) ^ (x*11 + y*13)) & 63
7+def wm(wx, wy): # per-window watermark: unique per window
8+ return ((wx*73) ^ (wy*151) ^ ((wx*wy) & 255)) & 63
9+for j in range(H):
10+ for i in range(W):
11+ b = (base(i, j) ^ wm(i >> 3, j >> 3)) + 32
12+ y[j*W+i] = b
13+ u[j*W+i] = 128 + ((base(i+37, j+91) ^ wm((i+37) >> 3, (j+91) >> 3)) & 15) - 7
14+ v[j*W+i] = 128 - ((base(i+13, j+57) ^ wm((i+13) >> 3, (j+57) >> 3)) & 15) - 7
15+patch = [[96 + rng.randrange(64) for _ in range(8)] for _ in range(8)]
16+def put(X, Y, luma, cuv):
17+ y[Y*W+X] = min(255, max(0, luma))
18+ u[Y*W+X] = min(255, max(0, cuv))
19+ v[Y*W+X] = min(255, max(0, 255 - cuv))
20+for by in range(0, H, 8):
21+ for bx in range(0, W, 8):
22+ r = rng.random()
23+ if r < 0.55:
24+ shape = (8, 4, 0 if rng.random() < 0.5 else 4)
25+ elif r < 0.85:
26+ shape = (4, 8, 0)
27+ if bx + 4 >= W: shape = (8, 4, rng.randrange(2)*4)
28+ else:
29+ continue
30+ w, h, oy = shape
31+ bias = rng.randrange(-3, 4)
32+ flips = {(rng.randrange(w), rng.randrange(h)) for _ in range(5)}
33+ for j in range(h):
34+ for i in range(w):
35+ s = patch[(by+oy+j) % 8][(bx+i) % 8]
36+ if (i, j) in flips: s ^= 1
37+ put(bx+i, by+oy+j, s + bias, 100 + (s & 31) + bias)
38+with open(sys.argv[1], 'wb') as f:
39+ f.write(b'YUV4MPEG2 W320 H240 F25:1 Ip A1:1 C444 XYSCSS=444\nFRAME\n')
40+ f.write(bytes(y)); f.write(bytes(u)); f.write(bytes(v))