forge
Explore
Log in

Don't you dare go Hollow

ec-av1: decode lossless 128-axis intra blocks as TX_4X4

Browse files at this commit

6202aac9b716787333cbe6f391d281fa9cc5a961Ahmet Kaan GümüşParent: 7d74f02
decode_block_128rect had no lossless carve-out, so a conformant
BLOCK_64X128 on a CodedLossless frame reconstructed a 16-sample WHT
residual with 64-point geometry and panicked. The body now matches
libaom's read_tx_size early return: no tx-size symbol, every plane
walked as TX_4X4, chroma plane-major inside each mu chunk.

Gate a_lossless_sb128_rect_intra_block_decodes_sample_exact fails
pre-fix (panic at decode.rs:3596) and is sample-exact vs ffmpeg
after, with a non-zero engagement counter. Non-lossless 128 streams
are unchanged (cn == 1).

deferred: lossless 16x4/4x16 chroma still reads one ChromaRect8x4
instead of two TX_4X4 units (pre-existing, identical on base).
crates/ec-av1/examples/decode_probe.rsmodified+6 -0
@@ -111,6 +111,12 @@ fn main() {
111 // an INTER frame -- the arm this round implemented.111 // an INTER frame -- the arm this round implemented.
112 let i128 = ec_av1::stream::intra128_in_inter_counters();112 let i128 = ec_av1::stream::intra128_in_inter_counters();
113 println!("intra128_in_inter: 128x64={} 64x128={}", i128[0], i128[1]);113 println!("intra128_in_inter: 128x64={} 64x128={}", i128[0], i128[1]);
114+ // lane-lossless128: intra 128-axis blocks on a LOSSLESS frame (every
115+ // plane TX_4X4) -- the shape whose reconstruction used to panic.
116+ println!(
117+ "intra128_lossless: {}",
118+ ec_av1::stream::intra128_lossless_counters()
119+ );
114 let sb = ec_av1::stream::sb128_rect_counters();120 let sb = ec_av1::stream::sb128_rect_counters();
115 println!(121 println!(
116 "sb128_rect: edge_horz={} edge_vert={} inter_128x64={} inter_64x128={}",122 "sb128_rect: edge_horz={} edge_vert={} inter_128x64={} inter_64x128={}",
crates/ec-av1/fixtures/lossless_sb128_rect_kf.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+129 -59
@@ -15097,6 +15097,11 @@ thread_local! {
15097 /// `TX_MODE_LARGEST` is one; the counter is what keeps that reset's gate15097 /// `TX_MODE_LARGEST` is one; the counter is what keeps that reset's gate
15098 /// non-vacuous.15098 /// non-vacuous.
15099 pub(crate) static SKIP_VARTX_LUMA_RESET_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };15099 pub(crate) static SKIP_VARTX_LUMA_RESET_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
15100+ /// lane-lossless128: an intra 128-axis (BLOCK_128X64/64X128) block decoded
15101+ /// on a LOSSLESS frame, where every plane is coded as TX_4X4 units (the
15102+ /// frame's `tx_mode` is forced `ONLY_4X4`). Keeps the gate that owns this
15103+ /// shape non-vacuous -- a stream that never codes one reads 0.
15104+ pub(crate) static INTRA128_LOSSLESS_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
15100 }15105 }
15101 15106
15102 /// [`SKIP_VARTX_LUMA_RESET_HITS`], for a gate's own before/after delta.15107 /// [`SKIP_VARTX_LUMA_RESET_HITS`], for a gate's own before/after delta.
@@ -15104,6 +15109,11 @@ pub fn skip_vartx_luma_reset_hits() -> usize {
15104 SKIP_VARTX_LUMA_RESET_HITS.with(std::cell::Cell::get)15109 SKIP_VARTX_LUMA_RESET_HITS.with(std::cell::Cell::get)
15105 }15110 }
15106 15111
15112+/// [`INTRA128_LOSSLESS_HITS`], for a gate's own before/after delta.
15113+pub(crate) fn intra128_lossless_hits() -> usize {
15114+ INTRA128_LOSSLESS_HITS.with(std::cell::Cell::get)
15115+}
15116+
15107 /// [`INTRA128_IN_INTER_HITS`], for a gate's own before/after delta.15117 /// [`INTRA128_IN_INTER_HITS`], for a gate's own before/after delta.
15108 pub(crate) fn intra128_in_inter_hits() -> [usize; 2] {15118 pub(crate) fn intra128_in_inter_hits() -> [usize; 2] {
15109 INTRA128_IN_INTER_HITS.with(std::cell::Cell::get)15119 INTRA128_IN_INTER_HITS.with(std::cell::Cell::get)
@@ -15141,6 +15151,17 @@ pub(crate) fn intra_sb128_hits() -> (usize, usize, [usize; 3]) {
15141 /// No CfL, no filter intra (both cap at 32x32) and no palette15151 /// No CfL, no filter intra (both cap at 32x32) and no palette
15142 /// (`av1_allow_palette` caps at 64x64) exist at this size -- the mode15152 /// (`av1_allow_palette` caps at 64x64) exist at this size -- the mode
15143 /// reader's own size gates already say so, and the guard below is defensive.15153 /// reader's own size gates already say so, and the guard below is defensive.
15154+///
15155+/// lane-lossless128: on a LOSSLESS frame every one of those sizes collapses to
15156+/// TX_4X4 -- `read_tx_mode` returns `ONLY_4X4` before the frame codes a tx-size
15157+/// symbol and `read_tx_size` returns `TX_4X4` before it looks at anything
15158+/// (`decodeframe.c:140`, `:1183`) -- so the block is tiled into 4x4 luma units
15159+/// and (because a lossless frame forces `TX_4X4` on CHROMA too) 4x4 chroma
15160+/// units, plane-major inside each 64x64 mu chunk exactly as
15161+/// `decode_token_recon_block` codes them. Reading the 64-point geometry there
15162+/// reconstructs into a `side`-sized plane with a 16-sample residual (the panic
15163+/// this lane closed); the geometry and the unit walks below are normalized on
15164+/// `lossless_frame`.
15144 #[allow(clippy::too_many_arguments)]15165 #[allow(clippy::too_many_arguments)]
15145 fn decode_block_128rect(15166 fn decode_block_128rect(
15146 dec: &mut SymbolDecoder,15167 dec: &mut SymbolDecoder,
@@ -15198,8 +15219,15 @@ fn decode_block_128rect(
15198 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);15219 let smooth_neighbor_uv = neighbours.smooth_uv_neighbour(mi_r, mi_c, r, c);
15199 // spec 5.11.16 `read_tx_size`: read for every intra block, skipped or15220 // spec 5.11.16 `read_tx_size`: read for every intra block, skipped or
15200 // not. `bsize_to_tx_size_cat(BLOCK_128X64)` is 3 (see this fn's doc).15221 // not. `bsize_to_tx_size_cat(BLOCK_128X64)` is 3 (see this fn's doc).
15222+ // lane-lossless128: a LOSSLESS frame codes no tx-size symbol at all --
15223+ // libaom's `read_tx_mode` returns `ONLY_4X4` for a `coded_lossless` frame
15224+ // before the symbol is even considered (`decodeframe.c:140`) and
15225+ // `read_tx_size` returns `TX_4X4` before it looks at anything
15226+ // (`decodeframe.c:1183`). So `tx_select` is off, every plane is walked as
15227+ // TX_4X4 transform units, and no `tx_size_cat3` symbol may be consumed.
15228+ let lossless_frame = lossless(fctx);
15201 let in_inter = fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some();15229 let in_inter = fctx.intra_in_inter_mode.with(std::cell::Cell::get).is_some();
15202- let depth = if tx_select {15230+ let depth = if tx_select && !lossless_frame {
15203 // lane-inter128intra r1: `get_tx_size_context` compares the bands15231 // lane-inter128intra r1: `get_tx_size_context` compares the bands
15204 // against `tx_size_wide/high[max_txsize_rect_lookup[bsize]]` --15232 // against `tx_size_wide/high[max_txsize_rect_lookup[bsize]]` --
15205 // TX_64X64 for every 128-axis block, hence the `min(64)`.15233 // TX_64X64 for every 128-axis block, hence the `min(64)`.
@@ -15218,24 +15246,49 @@ fn decode_block_128rect(
15218 c.set(h);15246 c.set(h);
15219 });15247 });
15220 }15248 }
15221- let logical_tx = 64 >> depth;15249+ let logical_tx = if lossless_frame { 4 } else { 64 >> depth };
15250+ if lossless_frame {
15251+ hit!(INTRA128_LOSSLESS_HITS);
15252+ }
15222 // A 64-point transform codes nothing past its low 32 coefficients.15253 // A 64-point transform codes nothing past its low 32 coefficients.
15223 let coeff_tx_side = logical_tx.min(32);15254 let coeff_tx_side = logical_tx.min(32);
15224- let luma_set = txbset_for(logical_tx, reduced_tx_set);15255+ let luma_set = if lossless_frame {
15256+ TxbSet::Luma4
15257+ } else {
15258+ txbset_for(logical_tx, reduced_tx_set)
15259+ };
15225 let luma_scan = default_scan(coeff_tx_side);15260 let luma_scan = default_scan(coeff_tx_side);
15226- let chroma_tx = 32;15261+ // `av1_get_max_uv_txsize` caps at TX_32X32 normally; a lossless frame
15262+ // forces every plane to TX_4X4 (its own `Chroma4` set and 4x4 scan).
15263+ let chroma_tx = if lossless_frame { 4 } else { 32 };
15264+ let chroma_set = if lossless_frame {
15265+ TxbSet::Chroma4
15266+ } else {
15267+ TxbSet::Chroma32
15268+ };
15227 let chroma_scan = default_scan(chroma_tx);15269 let chroma_scan = default_scan(chroma_tx);
15228 let (cpx, cpy) = (px / 2, py / 2);15270 let (cpx, cpy) = (px / 2, py / 2);
15229 let (chroma_w, chroma_h) = (bw / 2, bh / 2);15271 let (chroma_w, chroma_h) = (bw / 2, bh / 2);
15230 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);15272 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height, fctx);
15231 let (nch_x, nch_y) = (bw / 64, bh / 64);15273 let (nch_x, nch_y) = (bw / 64, bh / 64);
15232- // One 32x32 chroma unit per mu chunk, per plane.15274+ // The frame's own mi grid (`av1_calc_mi_size`, 8-px aligned): libaom's
15233- debug_assert_eq!((chroma_w / chroma_tx, chroma_h / chroma_tx), (nch_x, nch_y));15275+ // `decode_token_recon_block` clips each vector's walk to
15276+ // `max_block_wide/high`, so a chroma unit whose top-left is off the frame
15277+ // codes nothing.
15278+ let mi_cols = 2 * y.true_width.div_ceil(8);
15279+ let mi_rows = 2 * y.true_height.div_ceil(8);
15280+ let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(mi_c));
15281+ let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(mi_r));
15282+ // Non-lossless: one 32x32 chroma unit per mu chunk, per plane.
15283+ debug_assert!(lossless_frame || (chroma_w / chroma_tx, chroma_h / chroma_tx) == (nch_x, nch_y));
15234 let tpc = 64 / logical_tx;15284 let tpc = 64 / logical_tx;
15235 let zero_tu = vec![0i32; logical_tx * logical_tx];15285 let zero_tu = vec![0i32; logical_tx * logical_tx];
15236 let zero_cu = vec![0i32; chroma_tx * chroma_tx];15286 let zero_cu = vec![0i32; chroma_tx * chroma_tx];
15237 let mut last_grids = [Grid::Zero(0), Grid::Zero(0)];15287 let mut last_grids = [Grid::Zero(0), Grid::Zero(0)];
15238- let mut units: Vec<((usize, usize), Grid, Grid)> = Vec::new();15288+ let mut units: Vec<(usize, (usize, usize), Grid)> = Vec::new();
15289+ // The chroma context arrays are indexed in LUMA mi; every chroma unit of
15290+ // every chunk shares this luma span (2 chroma pixels per luma unit).
15291+ let luma_span = chroma_tx * 2;
15239 for ch_row in 0..nch_y {15292 for ch_row in 0..nch_y {
15240 for ch_col in 0..nch_x {15293 for ch_col in 0..nch_x {
15241 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {15294 for tu_row in ch_row * tpc..(ch_row + 1) * tpc {
@@ -15305,56 +15358,74 @@ fn decode_block_128rect(
15305 neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid);15358 neighbours.record_mi_luma(tu_mi, logical_tx, &tu_grid);
15306 }15359 }
15307 }15360 }
15308- // The chroma context arrays are indexed in LUMA mi, so this15361+ // Transform units per axis inside this mu chunk's 32x32 chroma
15309- // unit's anchor is its own 64x64 mu chunk.15362+ // span: one 32x32 unit normally, 8x8 TX_4X4 units when lossless.
15310- let luma_span = chroma_tx * 2;15363+ let cn = (32 / chroma_tx).max(1);
15311- let cu_mi = (15364+ // libaom's per-chunk `unit_width/height` (plane-mi units of the
15312- mi_r + ch_row * (luma_span / MI),15365+ // luma mi grid): `min(mu_blocks + col, max_blocks) >> ss`.
15313- mi_c + ch_col * (luma_span / MI),15366+ let unit_w = ((ch_col + 1) * 16).min(max_w_mi) >> 1;
15314- );15367+ let unit_h = ((ch_row + 1) * 16).min(max_h_mi) >> 1;
15315- let cu_r = tu_reach(15368+ let stepc = (chroma_tx / 4).max(1);
15316- bw,15369+ // `decode_token_recon_block` codes a mu chunk PLANE-MAJOR: every U
15317- bh,15370+ // unit of the chunk, then every V unit. At one unit per plane per
15318- ch_col * luma_span,15371+ // chunk (every non-lossless 128-axis block) that is the same
15319- ch_row * luma_span,15372+ // symbol order the interleaved pair used to read; a lossless
15320- luma_span,15373+ // frame's 4x4 chroma units are where it becomes observable.
15321- reach,15374+ for plane_pass in 1..=2usize {
15322- px,15375+ for ci_row in 0..cn {
15323- py,15376+ for ci_col in 0..cn {
15324- y.width,15377+ if ch_col * 8 + ci_col * stepc >= unit_w
15325- y.height, fctx,15378+ || ch_row * 8 + ci_row * stepc >= unit_h
15326- );15379+ {
15327- let (cu_x, cu_y) = (cpx + ch_col * chroma_tx, cpy + ch_row * chroma_tx);15380+ continue;
15328- if skip {15381+ }
15329- push_intra(1, 15382+ let cu_x = cpx + ch_col * 32 + ci_col * chroma_tx;
15330- cu_x, cu_y, chroma_tx, uv_predict_mode, angle_delta_uv, cu_r, &zero_cu, None,15383+ let cu_y = cpy + ch_row * 32 + ci_row * chroma_tx;
15331- None, smooth_neighbor_uv, fctx,15384+ let cu_mi = (
15332- );15385+ mi_r + ch_row * 16 + ci_row * (chroma_tx / 2),
15333- push_intra(2, 15386+ mi_c + ch_col * 16 + ci_col * (chroma_tx / 2),
15334- cu_x, cu_y, chroma_tx, uv_predict_mode, angle_delta_uv, cu_r, &zero_cu, None,15387+ );
15335- None, smooth_neighbor_uv, fctx,15388+ let cu_r = tu_reach(
15336- );15389+ bw,
15337- continue;15390+ bh,
15391+ ch_col * 64 + ci_col * luma_span,
15392+ ch_row * 64 + ci_row * luma_span,
15393+ luma_span,
15394+ reach,
15395+ px,
15396+ py,
15397+ y.width,
15398+ y.height, fctx,
15399+ );
15400+ if skip {
15401+ push_intra(plane_pass,
15402+ cu_x, cu_y, chroma_tx, uv_predict_mode, angle_delta_uv, cu_r,
15403+ &zero_cu, None, None, smooth_neighbor_uv, fctx,
15404+ );
15405+ continue;
15406+ }
15407+ let cu_around = neighbours.around_mi(cu_mi, luma_span);
15408+ let buf: &mut PlaneBuf<'static> =
15409+ if plane_pass == 1 { &mut *u } else { &mut *v };
15410+ let grid = read_plane(
15411+ dec, cdfs, chroma_set, &chroma_scan, plane_pass, cu_around[plane_pass],
15412+ mode, uv_predict_mode, angle_delta_uv, cu_r, buf, cu_x, cu_y,
15413+ chroma_tx, chroma_tx, base_q_idx, None, None, Some(3),
15414+ smooth_neighbor_uv, fctx,
15415+ )?;
15416+ last_grids[plane_pass - 1] = grid.clone();
15417+ // Immediately, so the NEXT unit of this same block
15418+ // reads this one's coefficient context; replayed after
15419+ // `record_split_luma_rect` below, which would otherwise
15420+ // clobber them whole-block.
15421+ neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, plane_pass, &grid);
15422+ units.push((plane_pass, cu_mi, grid));
15423+ }
15424+ }
15425+ }
15426+ if !skip {
15427+ hit!(CHROMA_SPLIT_TX_HITS);
15338 }15428 }
15339- let cu_around = neighbours.around_mi(cu_mi, luma_span);
15340- let u_grid = read_plane(
15341- dec, cdfs, TxbSet::Chroma32, &chroma_scan, 1, cu_around[1], mode, uv_predict_mode,
15342- angle_delta_uv, cu_r, u, cu_x, cu_y, chroma_tx, chroma_tx, base_q_idx, None, None,
15343- Some(3), smooth_neighbor_uv, fctx,
15344- )?;
15345- let v_grid = read_plane(
15346- dec, cdfs, TxbSet::Chroma32, &chroma_scan, 2, cu_around[2], mode, uv_predict_mode,
15347- angle_delta_uv, cu_r, v, cu_x, cu_y, chroma_tx, chroma_tx, base_q_idx, None, None,
15348- Some(3), smooth_neighbor_uv, fctx,
15349- )?;
15350- hit!(CHROMA_SPLIT_TX_HITS);
15351- // Immediately, so the NEXT unit of this same block reads this
15352- // one's coefficient context; replayed after `record_split_luma_rect`
15353- // below, which would otherwise clobber them whole-block.
15354- neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, 1, &u_grid);
15355- neighbours.record_mi_chroma(cu_mi, luma_span, luma_span, 2, &v_grid);
15356- units.push((cu_mi, u_grid.clone(), v_grid.clone()));
15357- last_grids = [u_grid, v_grid];
15358 }15429 }
15359 }15430 }
15360 if skip {15431 if skip {
@@ -15379,9 +15450,8 @@ fn decode_block_128rect(
15379 uv_predict_mode,15450 uv_predict_mode,
15380 [&last_grids[0], &last_grids[1]],15451 [&last_grids[0], &last_grids[1]],
15381 );15452 );
15382- for (cu_mi, u_grid, v_grid) in &units {15453+ for (plane, cu_mi, grid) in &units {
15383- neighbours.record_mi_chroma(*cu_mi, 64, 64, 1, u_grid);15454+ neighbours.record_mi_chroma(*cu_mi, luma_span, luma_span, *plane, grid);
15384- neighbours.record_mi_chroma(*cu_mi, 64, 64, 2, v_grid);
15385 }15455 }
15386 }15456 }
15387 // No palette exists at this size; the unconditional stamp clears any15457 // No palette exists at this size; the unconditional stamp clears any
crates/ec-av1/src/stream.rsmodified+69 -0
@@ -207,6 +207,13 @@ pub fn intra128_in_inter_counters() -> [usize; 2] {
207 crate::decode::intra128_in_inter_hits()207 crate::decode::intra128_in_inter_hits()
208 }208 }
209 209
210+/// lane-lossless128: intra 128-axis blocks decoded on a LOSSLESS frame, where
211+/// every plane is a TX_4X4 unit. The engagement counter for
212+/// `a_lossless_sb128_rect_intra_block_decodes_sample_exact`.
213+pub fn intra128_lossless_counters() -> usize {
214+ crate::decode::intra128_lossless_hits()
215+}
216+
210 /// lane-sb128c r9: the four AB shapes at the 128 root, in `PARTITION_HORZ_A`,217 /// lane-sb128c r9: the four AB shapes at the 128 root, in `PARTITION_HORZ_A`,
211 /// `_HORZ_B`, `_VERT_A`, `_VERT_B` order (key and inter tile paths share the218 /// `_HORZ_B`, `_VERT_A`, `_VERT_B` order (key and inter tile paths share the
212 /// counter -- it is bumped where the root symbol resolves).219 /// counter -- it is bumped where the root symbol resolves).
@@ -4950,6 +4957,68 @@ pub(crate) mod tests {
4950 }4957 }
4951 }4958 }
4952 4959
4960+ /// lane-lossless128: a LOSSLESS key frame that codes a 128-axis
4961+ /// (`BLOCK_64X128`) intra block -- the shape libaom's `read_tx_size` forces
4962+ /// to `TX_4X4` on its very first line (`decodeframe.c:1183`), so every plane
4963+ /// of the block is a 4x4 transform unit and NO `tx_size_cat3` symbol is
4964+ /// coded.
4965+ ///
4966+ /// On the merged base `decode_block_128rect` had no lossless carve-out: it
4967+ /// read `logical_tx = 64` off `depth == 0`, handed `PlaneBuf::reconstruct`
4968+ /// a 64x64 geometry with the 16-sample 4x4 residual
4969+ /// [`TxParams::run`](crate::decode::TxParams) produced -- `index out of
4970+ /// bounds: the len is 16 but the index is 16` at the reconstruction call,
4971+ /// on EVERY conformant stream of this shape (a panic, never a refusal).
4972+ ///
4973+ /// `crates/ec-av1/fixtures/lossless_sb128_rect_kf.obu`, 3471 bytes, sha256
4974+ /// `013b07979c8be999c70d47f32768c2bf959be086a893f60dde1b0f5e35d4f475`:
4975+ /// `aomenc --codec=av1 --passes=1 --threads=1 --obu --lossless=1
4976+ /// --cpu-used=0` over a 320x256, 4-frame source that is flat grey except a
4977+ /// textured 64x128 patch in the top-right corner -- which is what makes the
4978+ /// 128 root take `PARTITION_VERT` and code the `BLOCK_64X128` at mi(0,64).
4979+ ///
4980+ /// The counter delta keeps the gate non-vacuous: a stream that stopped
4981+ /// coding the shape reads 0 and the gate fails instead of passing on a
4982+ /// decode that never reached the fixed body (class
4983+ /// `gate-blind-to-feature`).
4984+ #[test]
4985+ fn a_lossless_sb128_rect_intra_block_decodes_sample_exact() {
4986+ const NAME: &str = "a_lossless_sb128_rect_intra_block_decodes_sample_exact";
4987+ if !have_ffmpeg() {
4988+ eprintln!("SKIP {NAME}: no ffmpeg");
4989+ return;
4990+ }
4991+ let (w, h, frames) = (320usize, 256usize, 4usize);
4992+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
4993+ .join("fixtures/lossless_sb128_rect_kf.obu");
4994+ let stream = std::fs::read(&path)
4995+ .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
4996+ let before = crate::decode::intra128_lossless_hits();
4997+ let ours = decode_stream(&stream)
4998+ .unwrap_or_else(|e| panic!("{NAME}: a lossless 128-axis key frame decodes: {e}"));
4999+ let hits = crate::decode::intra128_lossless_hits() - before;
5000+ assert!(
5001+ hits > 0,
5002+ "{NAME}: this stream coded NO lossless 128-axis intra block -- the fixed body \
5003+ was never reached (class gate-blind-to-feature)"
5004+ );
5005+ let refs = ffmpeg_decode_sequence(&stream, w, h, frames);
5006+ assert_eq!(ours.len(), frames, "{NAME}: decode-order frame count");
5007+ for (i, (got, want)) in ours.iter().zip(refs.iter()).enumerate() {
5008+ for (plane, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)]
5009+ .iter()
5010+ .enumerate()
5011+ {
5012+ let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
5013+ assert_eq!(
5014+ bad, 0,
5015+ "{NAME}: frame {i} plane {plane}: {bad} samples differ from ffmpeg"
5016+ );
5017+ }
5018+ }
5019+ eprintln!("{NAME}: {frames} frames sample-exact, intra128_lossless hits {hits}");
5020+ }
5021+
4953 /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and5022 /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and
4954 /// colours used to stay standing in the mi-granular above/left bands after a5023 /// colours used to stay standing in the mi-granular above/left bands after a
4955 /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published5024 /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published
lanes/av1lossless128.report.mdadded+199 -0
@@ -0,0 +1,199 @@
1+# lane-av1-lossless128 — the lossless 128-axis intra panic is closed (byte-exact)
2+
3+Base: `main` **46f07214**. Worktree `../edith_codecs-av1ll`, branch
4+`lane-av1-lossless128`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1ll`,
5+`TMPDIR=$HOME/.cache/tmp-av1ll`. Nothing pushed.
6+
7+## 0. WIP assessment (cancelled agent, kept)
8+
9+The uncommitted WIP (`decode.rs`, `stream.rs`, `examples/decode_probe.rs`, plus
10+an untracked report and a gitignored fixture) was a **coherent** fix of
11+`decode_block_128rect`, not a half-applied edit. It already:
12+
13+* skipped the `tx_size_cat3` read on a lossless frame,
14+* walked every plane as TX_4X4 (`TxbSet::Luma4` / `Chroma4`),
15+* made the chroma walk plane-major inside each 64x64 mu chunk (a no-op when
16+ `cn == 1`, i.e. every non-lossless block),
17+* bumped `INTRA128_LOSSLESS_HITS`, and
18+* added `a_lossless_sb128_rect_intra_block_decodes_sample_exact`.
19+
20+What it had not done: prove the gate, force-add the gitignored fixture, run
21+the wave-1 probes, or run the suite. Those are this resume. The three files
22+were **not** reset.
23+
24+## 1. Headline
25+
26+A lossless key frame that codes an intra `BLOCK_64X128` no longer panics. The
27+committed fixture is sample-exact against ffmpeg, and the fixed body is
28+reached (`intra128_lossless` hits 2).
29+
30+```
31+$PROBE crates/ec-av1/fixtures/lossless_sb128_rect_kf.obu out.raw
32+OK: 4 frames decoded, 320x256
33+intra128_lossless: 2
34+ffmpeg -loglevel error -i crates/ec-av1/fixtures/lossless_sb128_rect_kf.obu \
35+ -pix_fmt yuv420p -f rawvideo ref.raw -y
36+cmp out.raw ref.raw # identical
37+sha256 of the planes: b30015ecfdd5091a02be1b1d92e467fc63d65e0fd6775fc17e01589b2f7edc44
38+sha256 of the .obu: 013b07979c8be999c70d47f32768c2bf959be086a893f60dde1b0f5e35d4f475
39+```
40+
41+On the merged base (`$HOME/.cache/av1ll-base`, probe
42+`$HOME/.cache/cargo-target-av1ll-base`) the same fixture **panics** (rc 101):
43+
44+```
45+thread 'main' panicked at crates/ec-av1/src/decode.rs:3596:16:
46+index out of bounds: the len is 16 but the index is 16
47+ decode::exec_intra <- decode::read_plane <- decode::decode_block_128rect
48+```
49+
50+The txbands repro (`aomenc --lossless=1 --cpu-used=0 --sb-size=128` over
51+testsrc2 320x240, 24 frames) also panics on that base probe and decodes all
52+24 frames on this lane (`intra128_lossless: 13`). It is **not** sample-exact
53+against ffmpeg — the first wrong luma sample is frame 0 col 108, and that
54+desync is the pre-existing 16x4 chroma bug in §6, not this panic. Base and
55+this lane consume the same mode-symbol ladder up to the 128-axis block
56+(identical `EC_ISTEP` through `mi(0,64)`); they diverge only inside that
57+block, which is the fix.
58+
59+## 2. Root cause
60+
61+`decode_block_128rect` had no lossless carve-out. libaom forces TX_4X4 for a
62+`CodedLossless` frame before any tx-size syntax exists (read in
63+`~/.cache/aom-oracle/src`):
64+
65+* `read_tx_mode` returns `ONLY_4X4` when `coded_lossless`
66+ (`av1/decoder/decodeframe.c:141`);
67+* `read_tx_size` returns `TX_4X4` before it looks at anything
68+ (`decodeframe.c:1183`);
69+* `av1_get_tx_size` returns `TX_4X4` for every plane of a lossless `xd`
70+ (`av1/common/blockd.h:1381`), so chroma is 4x4 too;
71+* `decode_token_recon_block` then walks each 64x64 mu chunk plane-major
72+ (`decodeframe.c:982-1006`): all Y, then all U, then all V, clipped to
73+ `max_block_wide/high`.
74+
75+With `tx_select == false` the old body took `depth = 0`, hence
76+`logical_tx = 64`, and called `read_plane` with a 64-point geometry.
77+`TxParams::run` on a lossless frame always returns the 16-sample
78+Walsh-Hadamard residual (`dequant_and_inverse_wht4x4`), and
79+`PlaneBuf::reconstruct` indexes that slice with the 64-point side
80+(`residual[idx]`, `dense_residual` does not pad a non-empty slice). Index 16
81+on a len-16 slice. A panic on a conformant stream.
82+
83+The committed fixture's 128 roots (aomdec `EC_PART_VAL`, `bsize=15`) are
84+`PARTITION_NONE` except `mi(0,64)` and `mi(32,64)`, which are
85+`PARTITION_VERT` (value 2) — two `BLOCK_64X128` blocks. That is the shape the
86+txbands report named (`fn=rect bw=64 bh=128`).
87+
88+## 3. Fix
89+
90+`decode_block_128rect` now mirrors `decode_block`'s lossless path:
91+
92+* `depth` is read only when `tx_select && !lossless_frame` (no `tx_size_cat3`
93+ symbol on a lossless frame);
94+* `logical_tx = 4`, `luma_set = TxbSet::Luma4`, `chroma_tx = 4`,
95+ `chroma_set = TxbSet::Chroma4`;
96+* chroma units inside each mu chunk are `cn = 32 / chroma_tx` per axis and
97+ plane-major (all U, then all V), which is `decode_token_recon_block`'s
98+ order and is a no-op at `cn == 1`;
99+* a unit whose top-left is outside libaom's per-chunk
100+ `unit_width/height = min(mu_blocks + col, max_blocks) >> ss` is not coded;
101+* `INTRA128_LOSSLESS_HITS` is bumped at the head; the probe prints it.
102+
103+Non-lossless behavior is unchanged: the 23 previously committed
104+`crates/ec-av1/fixtures/*.obu` decode byte-identical to the base probe
105+(§5).
106+
107+## 4. The gate (non-vacuous, fails pre-fix)
108+
109+`a_lossless_sb128_rect_intra_block_decodes_sample_exact` (`stream.rs`):
110+decodes the committed fixture, asserts `intra128_lossless_hits()` delta > 0,
111+then compares all four frames' Y/U/V against `ffmpeg_decode_sequence`.
112+
113+Fail-pre-fix, measured on the base probe (rc 101, panic quoted in §1).
114+
115+Pass post-fix:
116+
117+```
118+test stream::tests::a_lossless_sb128_rect_intra_block_decodes_sample_exact ... ok
119+ "4 frames sample-exact, intra128_lossless hits 2"
120+```
121+
122+Fixture: `crates/ec-av1/fixtures/lossless_sb128_rect_kf.obu`, 3471 bytes,
123+sha256 `013b07979c8be999c70d47f32768c2bf959be086a893f60dde1b0f5e35d4f475`.
124+The path is gitignored (`fixtures` in `.gitignore`); it is force-added, same
125+as the other 23 committed `.obu` files. 320x256, 4 frames, lossless,
126+`use_128x128_superblock=true`, single tile. The cancelled agent's generator
127+script is not in the tree; the bytes and the aomenc recipe in the test doc
128+are what this lane verified (base panics, this lane is sample-exact, sha256
129+matches).
130+
131+The panic witness is the **vertical** axis (`BLOCK_64X128`). A bottom-edge
132+`PARTITION_HORZ` (`BLOCK_128X64`) stream generated here decoded sample-exact
133+on **both** the base probe and this lane, so it does not exercise the
134+panicking reconstruct; aomenc did not emit an interior non-skip `PARTITION_HORZ`
135+128 root on the seams tried. The function is shared (`bw, bh` swapped, same
136+unit walk). Not separately panic-witnessed.
137+
138+## 5. Regression evidence
139+
140+* **23 committed fixtures** (`crates/ec-av1/fixtures/*.obu` except the new
141+ one): lane probe raw bytes **identical** to the base probe. The only row
142+ that moves is the new fixture (base rc 101 → lane OK, sample-exact vs
143+ ffmpeg).
144+* Wave-1 probes, this lane's `decode_probe`:
145+ * gray 60-frame key (`libaom-av1`, 320x240, `mono_chrome=true`): `OK: 60
146+ frames`, luma `cmp` identical to `ffmpeg -pix_fmt gray`.
147+ * `fixtures/bitstreams/av1-monochrome.ivf` remuxed to OBU: `OK: 60 frames`,
148+ luma identical to ffmpeg gray.
149+ * `av1-profile1-444.ivf` remuxed to OBU: refused by name (`a chroma format
150+ other than 4:2:0`).
151+ * `aomenc --enable-qm=1` (160x96, 4 frames): refused by name (`a frame
152+ using quantisation matrices`). The `--enable-qm=0` control of the same
153+ source is sample-exact vs ffmpeg.
154+ * `~/.cache/av1txr/s/cdf0.obu` (`disable_cdf` stream, 3 frames, 320x240):
155+ sample-exact vs ffmpeg `yuv420p`.
156+ * `reelb_kf900.obu` (3840x1608, 10-bit, 1 shown frame): `EC_PROBE_OUT16` cmp
157+ identical to `ffmpeg -pix_fmt yuv420p10le` (18524160 bytes). The other
158+ committed `reelb_*` fixtures are in the 23-file base-vs-lane sweep (identical).
159+* `cargo check -p ec-av1 --all-targets`: **0 warnings**.
160+* A 640x256 lossless `--sb-size=128 --tile-columns=1` stream refuses on both
161+ base and this lane with the existing string `intra block copy on a
162+ HORZ/VERT/1:4 rect intra strip` (lane-av1-intrabc's shape). Not a regression.
163+ `intra128_lossless` was 0 on that stream — it never reached this body.
164+
165+## 6. Found and DEFERRED: lossless 16x4/4x16 chroma is still one rect, not TX_4X4
166+
167+Pre-existing. Independent of the panic: it reproduces on a stream with no
168+128-axis block, and the base probe's `EC_ISTEP` ladder matches this lane's
169+through the divergence (so this lane's edit did not move it).
170+
171+**Measured on** `aomenc --lossless=1 --cpu-used=0 --sb-size=128` over
172+testsrc2 320x240, frame 0. aomdec `EC_PART`: the 16x16 at `mi(0,20)` is
173+`PARTITION_HORZ_4` (value 8) — four 16x4 strips. Mode symbols match through
174+`mi(1,20) uv_mode` (rng 53536 both sides). The next strip's `skip` does not
175+(aom rng 50651, ours 56265). That is the chroma-reference strip's coefficient
176+read: `decode_rect4_16_strip` still reads one `TxbSet::ChromaRect8x4` for the
177+pair (`decode.rs` around the `read_chroma_coeffs_rect` call at the chroma-pair
178+arm) where libaom codes two TX_4X4 units per plane. One symbol block too few,
179+and the tile desyncs from that strip on. First wrong luma sample on the
180+24-frame file is frame 0 col 108 (the strip at pixel x=104).
181+
182+`deferred(lossless 16x4/4x16 chroma pair — decode_rect4_16_strip needs the
183+two-TX_4X4 walk; unblock: a lossless-shape lane).` Different shape, different
184+symptom (silent wrong pixels, never a panic), and not what the 128-axis body
185+reads. Not folded into the success summary.
186+
187+## 7. Not changed
188+
189+* No refusal string added or removed.
190+* No encoder change.
191+* Sibling `lane-av1-intrabc` (Nazli, worktree `edith_codecs-av1ibc`) owns
192+ intrabc / MV-grid. This lane did not touch those regions. Shared helpers
193+ (`read_plane`, `exec_intra`, txfm bands) were not modified.
194+
195+## 8. Suite
196+
197+`cargo test -p ec-av1 --release --lib -- --test-threads=1`, hub process
198+`av1ll-suite`, on the committed tree. Expected **601 passed; 0 failed; 60
199+ignored** (base 600 + this gate). Literal final line filled after the run.