forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1-loss64: lossless sb128 full-frame exact + skipped sub8 intrabc chroma

Browse files at this commit

4181246f7ee83d78548550cbbf6d5ef6e1f28d3eAhmet Kaan GümüşParent: b8ca5338173962
Conflict resolution with the intrabc merge (both feature sets kept):
- loss64's three fixes intact: the lossless chroma TU edge clip, the skipped
  strip's entropy-band reset, and the skipped sub8 intrabc chroma route.
- the intrabc merge's call-site wiring intact: decode_intrabc_rect at the
  2:1 + 1:4 strip sites, decode_intrabc_owned_rect at decode_block_rect64.
- semantic conflict resolved IN the merge: decode_intrabc_rect's skip arm
  gains the band reset loss64 had added only to decode_intrabc_owned_rect's
  (the function that served 1:4 strips before the intrabc merge). Without it
  the 320x242 lossless sb128 gate mis-parses a phantom 8x32 intrabc strip at
  mi(56,66) right after the skipped 8x16 one at mi(48,66) and dies on a
  lossless (4,16) chroma WHT unit; the reset walk is lossless-scoped because
  read_block_tx_size_rect's lossless arm resolves leaves before the skip
  check. Cites libaom av1_reset_entropy_context, decodeframe.c:1262.
crates/ec-av1/examples/decode_probe.rsmodified+5 -0
@@ -189,6 +189,11 @@ fn main() {
189 ec_av1::decode::rect4_16_lossless_chroma_hits(),189 ec_av1::decode::rect4_16_lossless_chroma_hits(),
190 ec_av1::decode::rect4_16_intrabc_hits(),190 ec_av1::decode::rect4_16_intrabc_hits(),
191 );191 );
192+ println!(
193+ "loss64: chroma_edge_tu_clip={} skip_lossless_band_reset={}",
194+ ec_av1::decode::chroma_edge_tu_clip_hits(),
195+ ec_av1::decode::skip_lossless_band_reset_hits(),
196+ );
192 // lane-t900 r12: chroma edge-filter neighbour answered from the mi-granular197 // lane-t900 r12: chroma edge-filter neighbour answered from the mi-granular
193 // uv_mode grid instead of the coarse one-slot-per-column map.198 // uv_mode grid instead of the coarse one-slot-per-column map.
194 println!(199 println!(
crates/ec-av1/src/decode.rsmodified+154 -24
@@ -5084,6 +5084,15 @@ thread_local! {
5084 /// lane-kf1200 r2: sub-8x8 chroma blocks that are `skip_txfm` AND5084 /// lane-kf1200 r2: sub-8x8 chroma blocks that are `skip_txfm` AND
5085 /// `UV_CFL_PRED` -- the arm that used to drop the CfL alpha entirely.5085 /// `UV_CFL_PRED` -- the arm that used to drop the CfL alpha entirely.
5086 static SKIP_CFL_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };5086 static SKIP_CFL_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
5087+ /// lane-av1-loss64: chroma transform units the frame-edge clip skipped
5088+ /// (libaom `decode_reconstruct_tx`'s `max_blocks_wide/high` test) in
5089+ /// [`decode_block`]'s multi-transform-unit walk -- the units a lossless
5090+ /// block overhanging the frame does NOT code.
5091+ static CHROMA_EDGE_TU_CLIP_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
5092+ /// lane-av1-loss64: skipped lossless intrabc rect strips whose luma
5093+ /// entropy bands were zeroed per unit (libaom `av1_reset_entropy_context`,
5094+ /// decodeframe.c:1262) instead of leaking the previous occupant's.
5095+ static SKIP_LOSSLESS_BAND_RESET_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
5087 }5096 }
5088 5097
5089 /// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape5098 /// How many skipped sub-8x8 chroma blocks carried a CfL alpha (the shape
@@ -5092,6 +5101,26 @@ pub fn skip_cfl_hits() -> usize {
5092 SKIP_CFL_HITS.with(|c| c.get())5101 SKIP_CFL_HITS.with(|c| c.get())
5093 }5102 }
5094 5103
5104+/// How many chroma transform units the frame-edge clip skipped in
5105+/// [`decode_block`]'s multi-transform-unit walk (lane-av1-loss64). Zero on a
5106+/// stream whose lossless blocks never overhang the frame -- a gate asserting
5107+/// the clip fired must see this nonzero.
5108+pub fn chroma_edge_tu_clip_hits() -> usize {
5109+ CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.get())
5110+}
5111+
5112+/// How many skipped lossless intrabc rect strips had their luma entropy
5113+/// bands zeroed per unit (lane-av1-loss64).
5114+pub fn skip_lossless_band_reset_hits() -> usize {
5115+ SKIP_LOSSLESS_BAND_RESET_HITS.with(|c| c.get())
5116+}
5117+
5118+/// Gate-side reset for the two lane-av1-loss64 counters above.
5119+pub fn reset_loss64_hits() {
5120+ CHROMA_EDGE_TU_CLIP_HITS.with(|c| c.set(0));
5121+ SKIP_LOSSLESS_BAND_RESET_HITS.with(|c| c.set(0));
5122+}
5123+
5095 /// How many 16x4/4x16 chroma pairs took a different `intra_edge_filter_type`5124 /// How many 16x4/4x16 chroma pairs took a different `intra_edge_filter_type`
5096 /// from the pair's base mi than the strip's own mi would have given.5125 /// from the pair's base mi than the strip's own mi would have given.
5097 pub fn rect4_16_uv_pair_filt_hits() -> usize {5126 pub fn rect4_16_uv_pair_filt_hits() -> usize {
@@ -11147,6 +11176,29 @@ fn decode_intrabc_rect(
11147 push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * side], fctx);11176 push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * side], fctx);
11148 push_mc_rect(1, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * cside], fctx);11177 push_mc_rect(1, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * cside], fctx);
11149 push_mc_rect(2, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * cside], fctx);11178 push_mc_rect(2, cpx, cpy, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * cside], fctx);
11179+ if let Some(ls) = leaves.as_ref() {
11180+ // lane-av1-loss64, merged: the same reset [`decode_intrabc_owned_rect`]'s
11181+ // skip arm performs -- libaom `av1_reset_entropy_context`
11182+ // (`if (mbmi->skip_txfm)`, decodeframe.c:1262 -> blockd.c:58): a
11183+ // SKIPPED block zeroes its whole entropy-band footprint. This
11184+ // helper serves `decode_block_rect4`'s 1:4 strips on this tree,
11185+ // so a skipped lossless strip whose `leaves` resolved (every
11186+ // lossless frame -- `read_block_tx_size_rect`'s lossless arm
11187+ // returns the 4x4 grid before it looks at `skip`) left the
11188+ // PREVIOUS occupant's luma bands standing and the NEXT block's
11189+ // partition parse diverged from libaom's: the 320x242 lossless
11190+ // sb128 gate read a phantom unskipped 8x32 intrabc strip at
11191+ // mi(56,66) right after the skipped 8x16 one at mi(48,66).
11192+ hit!(SKIP_LOSSLESS_BAND_RESET_HITS);
11193+ for &(row, col, tw, th) in ls {
11194+ neighbours.record_mi_luma_rect(
11195+ (mi_r + row, mi_c + col),
11196+ tw,
11197+ th,
11198+ &ZERO_RESIDUAL[..tw * th],
11199+ );
11200+ }
11201+ }
11150 luma_tx_type = TxType::DctDct;11202 luma_tx_type = TxType::DctDct;
11151 luma_grid = Grid::Zero(side * side);11203 luma_grid = Grid::Zero(side * side);
11152 u_grid = Grid::Zero(cside * cside);11204 u_grid = Grid::Zero(cside * cside);
@@ -12810,6 +12862,30 @@ fn decode_intrabc_owned_rect(
12810 push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * bh], fctx);12862 push_mc_rect(0, px, py, side, bw, bh, Pred::Inline(&pred_y, side), &ZERO_RESIDUAL[..side * bh], fctx);
12811 push_mc_rect(1, px / 2, py / 2, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * ch], fctx);12863 push_mc_rect(1, px / 2, py / 2, cside, cw, ch, Pred::Inline(&pred_u, cside), &ZERO_RESIDUAL[..cside * ch], fctx);
12812 push_mc_rect(2, px / 2, py / 2, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * ch], fctx);12864 push_mc_rect(2, px / 2, py / 2, cside, cw, ch, Pred::Inline(&pred_v, cside), &ZERO_RESIDUAL[..cside * ch], fctx);
12865+ if let Some(ls) = leaves.as_ref() {
12866+ // libaom `av1_reset_entropy_context` (`if (mbmi->skip_txfm)`,
12867+ // decodeframe.c:1262 -> blockd.c:58): a SKIPPED block zeroes its
12868+ // whole entropy-band footprint. The non-skip arm below writes
12869+ // those bands per transform unit and the tail's
12870+ // `record_split_luma_rect_mi` writes chroma only, so without
12871+ // this walk a skipped strip whose `leaves` resolved (every
12872+ // lossless frame -- `read_block_tx_size_rect`'s lossless arm
12873+ // returns the 4x4 grid before it looks at `skip`) leaked the
12874+ // PREVIOUS occupant's luma bands into the next block's
12875+ // `txb_skip`/coefficient contexts (lane-av1-loss64: the skipped
12876+ // 8x16 intrabc strip at mi(48,66) of the 320x242 lossless sb128
12877+ // stream left a stale 7 in left[48] and mi(48,68)'s first
12878+ // transform unit read `txb_skip_ctx` 3 where aomdec reads 1).
12879+ hit!(SKIP_LOSSLESS_BAND_RESET_HITS);
12880+ for &(row, col, tw, th) in ls {
12881+ neighbours.record_mi_luma_rect(
12882+ (mi_r + row, mi_c + col),
12883+ tw,
12884+ th,
12885+ &ZERO_RESIDUAL[..tw * th],
12886+ );
12887+ }
12888+ }
12813 luma_grid = Grid::Zero(side * side);12889 luma_grid = Grid::Zero(side * side);
12814 u_grid = Grid::Zero(cside * cside);12890 u_grid = Grid::Zero(cside * cside);
12815 v_grid = Grid::Zero(cside * cside);12891 v_grid = Grid::Zero(cside * cside);
@@ -16088,6 +16164,35 @@ fn decode_block(
16088 let mut pass_idx = 0usize;16164 let mut pass_idx = 0usize;
16089 for cu_row in ch_row * cpc..(ch_row + 1) * cpc {16165 for cu_row in ch_row * cpc..(ch_row + 1) * cpc {
16090 for cu_col in ch_col * cpc..(ch_col + 1) * cpc {16166 for cu_col in ch_col * cpc..(ch_col + 1) * cpc {
16167+ // libaom `decode_reconstruct_tx`'s frame-edge clip
16168+ // (decodeframe.c:299, `blk_row >= max_blocks_high || blk_col
16169+ // >= max_blocks_wide` returns before ANY symbol is read): a
16170+ // transform unit whose 4x4 origin sits outside the frame's mi
16171+ // grid is not coded at all. The luma loop above carries the
16172+ // same clip; its absence here read `txb_skip` (+coeffs) for
16173+ // chroma units libaom never wrote -- the lossless 64x64 block
16174+ // at mi(48,0) of a 320x240 frame overhangs the bottom edge by
16175+ // 4 mi, so its 32x32 chroma codes SIX rows of 4x4 units, not
16176+ // eight (lane-av1-loss64; 48 chroma units per plane in
16177+ // aomdec's EC_COEFF census vs the 64 this loop read).
16178+ // `max_block_wide/high` (av1_common_int.h:1565): the plane
16179+ // block's pixel span (4:2:0 halves the luma span, clamped to
16180+ // 4 by `set_plane_n4`) plus the negative overhang
16181+ // (`mb_to_*_edge` = `2 * overhang_mi` chroma px), in 4x4
16182+ // units.
16183+ let span_mi = side / MI;
16184+ let over_w_mi =
16185+ (2 * y.true_width.div_ceil(8)) as i32 - mi_c as i32 - span_mi as i32;
16186+ let over_h_mi =
16187+ (2 * y.true_height.div_ceil(8)) as i32 - mi_r as i32 - span_mi as i32;
16188+ let plane_px = ((span_mi * 2).max(4)) as i32;
16189+ let max_units_w = ((plane_px + 2 * over_w_mi.min(0)) >> 2).max(0) as usize;
16190+ let max_units_h = ((plane_px + 2 * over_h_mi.min(0)) >> 2).max(0) as usize;
16191+ let unit = chroma_tx / 4; // TU side in 4x4 chroma units
16192+ if cu_col * unit >= max_units_w || cu_row * unit >= max_units_h {
16193+ hit!(CHROMA_EDGE_TU_CLIP_HITS);
16194+ continue;
16195+ }
16091 // The chroma context arrays are indexed in LUMA mi, so this16196 // The chroma context arrays are indexed in LUMA mi, so this
16092 // unit's anchor is its own luma quadrant: `chroma_tx` chroma16197 // unit's anchor is its own luma quadrant: `chroma_tx` chroma
16093 // pixels span `2 * chroma_tx` luma ones.16198 // pixels span `2 * chroma_tx` luma ones.
@@ -18261,7 +18366,7 @@ fn decode_leaf_rect8(
18261 neighbours.above_uv_mode[c] = uv_predict_mode;18366 neighbours.above_uv_mode[c] = uv_predict_mode;
18262 neighbours.left_uv_mode[r] = uv_predict_mode;18367 neighbours.left_uv_mode[r] = uv_predict_mode;
18263 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);18368 neighbours.record_uv_mode_mi(leaf_mi.0, leaf_mi.1, 2, 2, uv_predict_mode);
18264- let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[1] {18369+ let (u_grid, v_grid): (Grid, Grid) = if leaf_skips[1] && last_intrabc.is_none() {
18265 // A skipped chroma block still gets its CfL contribution: libaom's18370 // A skipped chroma block still gets its CfL contribution: libaom's
18266 // `predict_and_reconstruct_intra_block` calls `cfl_predict_block`18371 // `predict_and_reconstruct_intra_block` calls `cfl_predict_block`
18267 // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719)18372 // from `av1_predict_intra_block_facade` (av1/common/reconintra.c:1719)
@@ -18291,37 +18396,62 @@ fn decode_leaf_rect8(
18291 }18396 }
18292 (Grid::Zero(16), Grid::Zero(16))18397 (Grid::Zero(16), Grid::Zero(16))
18293 } else if let Some(dv) = last_intrabc {18398 } else if let Some(dv) = last_intrabc {
18294- // lane-av1txr: the chroma-reference leaf was an intrabc block, so the18399+ // A 4:2:0 `BLOCK_4X8`/`BLOCK_8X4` leaf maps to a clamped chroma
18295- // group's one chroma unit is a frame copy at that DV too (its residual18400+ // `BLOCK_4X4` (`get_plane_block_size`, blockd.h:1184; `set_plane_n4`,
18296- // still reads the ordinary `Chroma4` coefficient tables -- libaom18401+ // av1_common_int.h:1344). The chroma reference is still the whole
18297- // codes a chroma `tx_type` nowhere).18402+ // 8x8 group's 4x4 plane block at `(cpx, cpy)`, so prediction uses the
18403+ // group's destination origin, not the odd-mi leaf's nominal 2x4/4x2
18404+ // extent. The old route treated a skipped intrabc leaf as skipped
18405+ // intra and predicted this block with DC, first differing at
18406+ // mi(46,52), U(104,92), while consuming identical symbols.
18407+ let chroma_mv_x = mv_to_q4(cpx, dv.1, false);
18408+ let chroma_mv_y = mv_to_q4(cpy, dv.0, false);
18409+ // `decode_reconstruct_tx` reads no chroma coefficients for a skipped
18410+ // intrabc block, but an unskipped one reads the ordinary Chroma4
18411+ // tables; chroma inherits no coded tx_type of its own.
18298 let mut ub = vec![0u16; 16];18412 let mut ub = vec![0u16; 16];
18299 mc::predict_with_filter(18413 mc::predict_with_filter(
18300 &u.data, u.width, u.true_width, u.true_height,18414 &u.data, u.width, u.true_width, u.true_height,
18301- mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false),18415+ chroma_mv_x, chroma_mv_y, 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
18302- 4, 4, mc::InterpFilterKind::Bilinear, &mut ub, fctx,
18303 );18416 );
18304 let mut vb = vec![0u16; 16];18417 let mut vb = vec![0u16; 16];
18305 mc::predict_with_filter(18418 mc::predict_with_filter(
18306 &v.data, v.width, v.true_width, v.true_height,18419 &v.data, v.width, v.true_width, v.true_height,
18307- mv_to_q4(cpx, dv.1, false), mv_to_q4(cpy, dv.0, false),18420+ chroma_mv_x, chroma_mv_y, 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
18308- 4, 4, mc::InterpFilterKind::Bilinear, &mut vb, fctx,
18309 );18421 );
18310- let chroma_around = neighbours.around_mi(leaf_mi, 8);18422+ if leaf_skips[1] {
18311- set_palette_pred(ub, fctx);18423+ // `skip_txfm` still reconstructs an intrabc prediction, but
18312- let ug = read_plane(18424+ // libaom's `decode_reconstruct_tx` reads NO chroma coefficients.
18313- dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED,18425+ // The ordinary skipped-intra arm above is therefore not valid for
18314- 0, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,18426+ // an intrabc leaf: use the copied, clamped 4x4 prediction directly.
18315- None, None, None, smooth_neighbor_uv, fctx,18427+ push_mc_rect(
18316- )?;18428+ 1, cpx, cpy, 4, 4, 4, Pred::Inline(&ub, 4),
18317- set_palette_pred(vb, fctx);18429+ &ZERO_RESIDUAL[..16], fctx,
18318- let vg = read_plane(18430+ );
18319- dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED,18431+ push_mc_rect(
18320- 0, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,18432+ 2, cpx, cpy, 4, 4, 4, Pred::Inline(&vb, 4),
18321- None, None, None, smooth_neighbor_uv, fctx,18433+ &ZERO_RESIDUAL[..16], fctx,
18322- )?;18434+ );
18323- fctx.intrabc_chroma_tx.with(|c| c.set(None));18435+ hit!(SKIPPED_INTRABC_CHROMA_ARM_HITS);
18324- (ug, vg)18436+ fctx.intrabc_chroma_tx.with(|c| c.set(None));
18437+ (Grid::Zero(16), Grid::Zero(16))
18438+ } else {
18439+ let chroma_around = neighbours.around_mi(leaf_mi, 8);
18440+ set_palette_pred(ub, fctx);
18441+ let ug = read_plane(
18442+ dec, cdfs, TxbSet::Chroma4, scan4, 1, chroma_around[1], DC_PRED, DC_PRED,
18443+ 0, group_reach, u, cpx, cpy, 4, TX4, base_q_idx,
18444+ None, None, None, smooth_neighbor_uv, fctx,
18445+ )?;
18446+ set_palette_pred(vb, fctx);
18447+ let vg = read_plane(
18448+ dec, cdfs, TxbSet::Chroma4, scan4, 2, chroma_around[2], DC_PRED, DC_PRED,
18449+ 0, group_reach, v, cpx, cpy, 4, TX4, base_q_idx,
18450+ None, None, None, smooth_neighbor_uv, fctx,
18451+ )?;
18452+ fctx.intrabc_chroma_tx.with(|c| c.set(None));
18453+ (ug, vg)
18454+ }
18325 } else {18455 } else {
18326 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));18456 let ac = alpha.map(|_| cfl_src(gpx, gpy, 8));
18327 let chroma_around = neighbours.around_mi(leaf_mi, 8);18457 let chroma_around = neighbours.around_mi(leaf_mi, 8);
crates/ec-av1/src/stream.rsmodified+179 -0
@@ -5019,6 +5019,185 @@ pub(crate) mod tests {
5019 eprintln!("{NAME}: {frames} frames sample-exact, intra128_lossless hits {hits}");5019 eprintln!("{NAME}: {frames} frames sample-exact, intra128_lossless hits {hits}");
5020 }5020 }
5021 5021
5022+ /// lane-av1-loss64: the generator for the two gates below -- a deterministic
5023+ /// 1-frame lossless superblock-128 aomenc stream of `testsrc2`. `extra`
5024+ /// flags land last (aomenc keeps the LAST occurrence of a repeated flag).
5025+ /// The recipe is the one lanes/av1rect14.report.md section 2 measured
5026+ /// (`--lossless=1 --sb-size=128 --enable-1to4-partitions=1`); the
5027+ /// `--min-partition-size` override is what steers the bottom superblock
5028+ /// row's RD into overhanging 64x64 `NONE` blocks (the shape the first fix
5029+ /// clips) or, at 8, keeps sub-8x8 partitions out of the second gate's
5030+ /// stream so the whole frame is decodable.
5031+ fn lossless_sb128_testsrc2(width: usize, height: usize, extra: &[&str]) -> Vec<u8> {
5032+ let mut ff = Command::new("ffmpeg");
5033+ let out = ff
5034+ .args(["-v", "error", "-f", "lavfi", "-i"])
5035+ .arg(format!("testsrc2=s={width}x{height}:r=25"))
5036+ .args(["-frames:v", "1", "-pix_fmt", "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-"])
5037+ .stdin(Stdio::null())
5038+ .stdout(Stdio::piped())
5039+ .stderr(Stdio::piped())
5040+ .output()
5041+ .expect("ffmpeg failed to run");
5042+ assert!(out.status.success(), "ffmpeg failed for testsrc2 {width}x{height}");
5043+ let y4m = out.stdout;
5044+ let mut child = Command::new(aomenc_path())
5045+ .args(["--codec=av1", "--bit-depth=8", "--input-bit-depth=8"])
5046+ .args([
5047+ "--passes=1",
5048+ "--cpu-used=0",
5049+ "--lag-in-frames=0",
5050+ "--kf-max-dist=1",
5051+ "--limit=1",
5052+ "--threads=1",
5053+ "--tile-columns=0",
5054+ "--lossless=1",
5055+ "--sb-size=128",
5056+ "--enable-1to4-partitions=1",
5057+ ])
5058+ .args(extra)
5059+ .args(["--obu", "-o", "-", "-"])
5060+ .stdin(Stdio::piped())
5061+ .stdout(Stdio::piped())
5062+ .stderr(Stdio::piped())
5063+ .spawn()
5064+ .expect("aomenc failed to start");
5065+ child
5066+ .stdin
5067+ .take()
5068+ .expect("aomenc stdin")
5069+ .write_all(&y4m)
5070+ .expect("aomenc stdin write");
5071+ let out = child.wait_with_output().expect("aomenc failed to run");
5072+ assert!(out.status.success(), "aomenc failed: {}", String::from_utf8_lossy(&out.stderr));
5073+ out.stdout
5074+ }
5075+
5076+ /// lane-av1-loss64: a lossless superblock-128 frame whose intra blocks
5077+ /// overhang the bottom frame edge codes NO coefficient symbols for the
5078+ /// chroma transform units whose 4x4 origin sits outside the frame's mi
5079+ /// grid -- libaom `decode_reconstruct_tx` returns before any read
5080+ /// (`decodeframe.c:299`, `blk_row >= max_blocks_high || blk_col >=
5081+ /// max_blocks_wide`, the limits from `max_block_wide/high`,
5082+ /// av1_common_int.h:1565). The square multi-transform-unit chroma loop in
5083+ /// [`crate::decode`] carried no such clip (the luma loop had one) and read
5084+ /// `txb_skip`+coefficients for the phantom units: on the measured stream
5085+ /// the first lossless 64x64 `NONE` block, at mi(48,0), overhangs the
5086+ /// 240-px frame by 4 mi, so its 32x32 chroma codes SIX rows of 4x4 units,
5087+ /// not eight -- 32 phantom unit reads per plane desynced the tile and
5088+ /// every later symbol (including partition reads, which is what made
5089+ /// aomdec's zero-`value=8/9` census look like a partition-reader defect
5090+ /// in the rect14 review) decoded as garbage.
5091+ ///
5092+ /// Fail-pre-fix, measured on the ed12fe52 probe: both arms differ from
5093+ /// ffmpeg at byte 41120 (luma row 128 col 160, the first block decoded
5094+ /// after the phantom reads). The counter delta pins non-vacuity (class
5095+ /// `gate-blind-to-feature`): 96 clipped units on each arm.
5096+ #[test]
5097+ fn a_lossless_sb128_square_frame_clips_overhanging_chroma_tus() {
5098+ const NAME: &str = "a_lossless_sb128_square_frame_clips_overhanging_chroma_tus";
5099+ if !have_ffmpeg() {
5100+ eprintln!("SKIP {NAME}: no ffmpeg");
5101+ return;
5102+ }
5103+ // Arm 0 is the rect14 report's `loss320` recipe verbatim; arm 1 is its
5104+ // `lnone` companion (1:4 and rect partitions off) -- both coded the
5105+ // overhanging 64x64 blocks and both desynced at byte 41120 pre-fix.
5106+ let arms: [&[&str]; 2] = [
5107+ &["--min-partition-size=4"],
5108+ &["--min-partition-size=4", "--enable-1to4-partitions=0", "--enable-rect-partitions=0"],
5109+ ];
5110+ let mut clips_total = 0usize;
5111+ for (arm, extra) in arms.iter().enumerate() {
5112+ let stream = lossless_sb128_testsrc2(320, 240, extra);
5113+ crate::decode::reset_loss64_hits();
5114+ let ours = decode_stream(&stream)
5115+ .unwrap_or_else(|e| panic!("{NAME}: arm {arm} decodes: {e}"));
5116+ let clips = crate::decode::chroma_edge_tu_clip_hits();
5117+ assert!(
5118+ clips > 0,
5119+ "{NAME}: arm {arm} clipped NO overhanging chroma transform unit -- \
5120+ the fixed body was never reached (class gate-blind-to-feature)"
5121+ );
5122+ clips_total += clips;
5123+ let refs = ffmpeg_decode_sequence(&stream, 320, 240, 1);
5124+ assert_eq!(ours.len(), 1, "{NAME}: arm {arm} frame count");
5125+ for (plane, (g, r)) in [(&ours[0].y, &refs[0].y), (&ours[0].u, &refs[0].u), (&ours[0].v, &refs[0].v)]
5126+ .iter()
5127+ .enumerate()
5128+ {
5129+ let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
5130+ assert_eq!(bad, 0, "{NAME}: arm {arm} plane {plane}: {bad} samples differ from ffmpeg");
5131+ }
5132+ }
5133+ eprintln!("{NAME}: 2 arms full-frame exact, {clips_total} chroma units clipped");
5134+ }
5135+
5136+ /// lane-av1-loss64: a SKIPPED intrabc rect strip on a lossless frame
5137+ /// zeroes its whole entropy-band footprint (libaom
5138+ /// `av1_reset_entropy_context`, `if (mbmi->skip_txfm)` decodeframe.c:1262 ->
5139+ /// blockd.c:58) instead of leaving the previous occupant's luma bands
5140+ /// standing. The skip arm of `decode_intrabc_owned_rect` never wrote the
5141+ /// luma bands: the lossless `read_block_tx_size_rect` resolves the 4x4
5142+ /// leaf list before it looks at `skip`, so the tail took the
5143+ /// per-transform-unit record path (chroma only) with no per-unit luma
5144+ /// writes ever run. The next block then read a STALE band: on the 320x242
5145+ /// `--min-partition-size=4` sibling of this stream the skipped 8x16
5146+ /// intrabc strip at mi(48,66) left a 7 in left[48] and mi(48,68)'s first
5147+ /// transform unit read `txb_skip_ctx` 3 where aomdec reads 1 (measured
5148+ /// `EC_ECDUMP` against the instrumented aomdec) -- a coefficient-walk
5149+ /// desync at byte 61712 with every mode symbol still matching.
5150+ ///
5151+ /// This gate uses the same `--min-partition-size=4` arm that reaches the
5152+ /// sub-8x8 VERT -> 4x8 skipped-intrabc leaf. Post-fix it is full-frame
5153+ /// exact: the skip path uses libaom's clamped 4x4 chroma intrabc
5154+ /// prediction (`decodeframe.c:1011-1065`, `reconinter_template.inc:186-207`)
5155+ /// instead of the ordinary skipped-intra DC predictor. The old route first
5156+ /// differed at U(104,92) with the entropy ladder fully synced.
5157+ ///
5158+ /// Fail-pre-fix, measured on the ed12fe52 probe: differs at byte 41120
5159+ /// (the chroma-clip class, fixed in the same lane). Single-mutation on
5160+ /// the lane tree with ONLY this gate's walk reverted: differs at byte
5161+ /// 61712, the band-leak site.
5162+ #[test]
5163+ fn a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands() {
5164+ const NAME: &str = "a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands";
5165+ if !have_ffmpeg() {
5166+ eprintln!("SKIP {NAME}: no ffmpeg");
5167+ return;
5168+ }
5169+ let stream = lossless_sb128_testsrc2(320, 242, &["--min-partition-size=4"]);
5170+ crate::decode::reset_loss64_hits();
5171+ crate::decode::reset_skipped_intrabc_chroma_arm_hits();
5172+ let ours = decode_stream(&stream)
5173+ .unwrap_or_else(|e| panic!("{NAME}: decodes: {e}"));
5174+ let resets = crate::decode::skip_lossless_band_reset_hits();
5175+ let intrabc_skips = crate::decode::skipped_intrabc_chroma_arm_hits();
5176+ assert!(
5177+ resets > 0,
5178+ "{NAME}: this stream coded NO skipped lossless intrabc rect strip -- \
5179+ the fixed body was never reached (class gate-blind-to-feature)"
5180+ );
5181+ assert!(
5182+ intrabc_skips > 0,
5183+ "{NAME}: this stream coded NO skipped sub-8x8 intrabc chroma leaf -- \
5184+ the clamped chroma prediction fix was never reached (class gate-blind-to-feature)"
5185+ );
5186+ let refs = ffmpeg_decode_sequence(&stream, 320, 242, 1);
5187+ assert_eq!(ours.len(), 1, "{NAME}: frame count");
5188+ for (plane, (g, r)) in [(&ours[0].y, &refs[0].y), (&ours[0].u, &refs[0].u), (&ours[0].v, &refs[0].v)]
5189+ .iter()
5190+ .enumerate()
5191+ {
5192+ let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
5193+ assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ from ffmpeg");
5194+ }
5195+ eprintln!(
5196+ "{NAME}: full-frame exact, {resets} band resets, \
5197+ {intrabc_skips} skipped intrabc chroma predictions"
5198+ );
5199+ }
5200+
5022 /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and5201 /// lane-dkey: the palette-neighbour-band gate. A palette-Y block's size and
5023 /// colours used to stay standing in the mi-granular above/left bands after a5202 /// colours used to stay standing in the mi-granular above/left bands after a
5024 /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published5203 /// sub-8x8 group was decoded next to it -- the sub-8x8 readers published
lanes/av1loss64.report.mdadded+118 -0
@@ -0,0 +1,118 @@
1+# lane-av1-loss64 — lossless sb128 full-frame exact, including skipped sub-8x8 intrabc chroma
2+
3+Base: `main` **ed12fe52** (rect14 merged). Worktree
4+`/home/user/Documents/Code/Rust/edith_codecs-av1l64`, branch
5+`lane-av1-loss64`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1loss64`,
6+`TMPDIR=$HOME/.cache/tmp-av1loss64`. Nothing pushed.
7+
8+## 1. Headline
9+
10+The lane closes the lossless `sb-size=128` 320x240 acceptance arm at
11+full-frame sample exactness. It also fixes the remaining 4:8/8:4 sub-8x8
12+chroma prediction defect in a skipped intrabc leaf. The first source fix is
13+committed as `0226fc11` (`ec-av1: clip lossless chroma TUs and reset skip bands`);
14+the skipped-intrabc chroma fix and its gate are the follow-up commit on this
15+branch.
16+
17+Verified gates:
18+
19+```
20+a_lossless_sb128_square_frame_clips_overhanging_chroma_tus
21+ 2 arms full-frame exact, 192 chroma units clipped
22+
23+a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands
24+ full-frame exact, 1 band resets, 3 skipped intrabc chroma predictions
25+```
26+
27+The first gate is the required 320x240 lossless sb128 full-frame witness. The
28+second is a 320x242 sibling generated with `--min-partition-size=4`; it reaches
29+the sub-8x8 VERT -> 4x8 skipped-intrabc leaf and is also full-frame exact.
30+
31+## 2. Root causes
32+
33+Two independent defects were present in the cancelled WIP:
34+
35+* A lossless chroma transform unit at a frame edge was read with the nominal
36+ geometry instead of libaom's clipped per-plane geometry. The decoder could
37+ read or reconstruct outside the valid chroma plane footprint.
38+* In `decode_leaf_rect8`, a 4:8/8:4 chroma-reference leaf with `skip_txfm=1`
39+ and `use_intrabc=1` was sent through the ordinary skipped-intra branch.
40+ That branch predicts chroma with DC/CfL, but libaom still reconstructs a
41+ skipped intrabc block from its motion-compensated copy; skip only suppresses
42+ residual coefficient reads. The entropy ladder remained synchronized while
43+ the first wrong sample was U(104,92) at luma mi(46,52).
44+
45+For 4:2:0, libaom clamps a 4x8/8x4 leaf's chroma plane block to `BLOCK_4X4`:
46+`set_plane_n4` in `av1_common_int.h:1344` and `get_plane_block_size` in
47+`blockd.h:1184`. The fix therefore predicts a 4x4 U and V block at the group's
48+chroma origin `(cpx, cpy)`, using the intrabc DV, and writes no chroma
49+coefficients on the skipped route. An unskipped intrabc leaf keeps the ordinary
50+`Chroma4` coefficient walk over the same 4x4 prediction. Both routes disarm
51+`intrabc_chroma_tx`.
52+
53+The lossless skip-band fix resets the complete luma entropy-band footprint
54+before the next block. Its measured sibling previously left a stale band and
55+read the next `txb_skip_ctx` differently from libaom.
56+
57+## 3. Repro and exactness
58+
59+Oracle: `~/.cache/aom-oracle/build/aomenc`; pixel reference: ffmpeg.
60+
61+The sub-8x8 witness was generated from `testsrc2=s=320x242:r=25`, one frame,
62+with `--lossless=1 --sb-size=128 --enable-1to4-partitions=1
63+--min-partition-size=4 --obu`. The committed-lane release probe and ffmpeg
64+reference have identical decoded bytes (`diff 0`). Artifact hashes:
65+
66+```
67+obu: 1fe5edc300a378c486abe385dad8251f3f21452f04e5a6f60f69feb48e58c8cb
68+ref8: 421ca38c91a133e78b84a9a3c9f79defbddbc7163a0b3088a176f4cd50179728
69+ours: 421ca38c91a133e78b84a9a3c9f79defbddbc7163a0b3088a176f4cd50179728
70+```
71+
72+Before the chroma-route fix, Y was exact but U/V differed at 2,488 samples;
73+the first difference was U(104,92). After the fix, all Y/U/V samples are exact.
74+The gate reports three reached skipped-intrabc chroma predictions and one
75+lossless band reset, so neither fix is gate-blind.
76+
77+## 4. Changed paths
78+
79+* `crates/ec-av1/src/decode.rs`: clip lossless chroma TU geometry; clear the
80+ skipped lossless entropy bands; route skipped sub-8x8 intrabc chroma through
81+ clamped 4x4 motion-compensated prediction; add the engagement hit used by the
82+ gate.
83+* `crates/ec-av1/src/stream.rs`: change the lossless skip-band gate to the
84+ min-partition-size=4 witness and assert both the band-reset and skipped
85+ intrabc-chroma counters.
86+
87+No refusal string, encoder path, or unrelated decode seat was changed.
88+
89+## 5. Verification run
90+
91+Targeted commands, all with private lane target and temp directories:
92+
93+```
94+EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \
95+ a_skipped_lossless_intrabc_rect_strip_zeroes_its_entropy_bands -- --nocapture
96+EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib \
97+ a_lossless_sb128_square_frame_clips_overhanging_chroma_tus -- --nocapture
98+```
99+
100+Both passed. The release `decode_probe` was rebuilt and independently compared
101+to ffmpeg for the 320x242 min4 witness; all planes were byte exact.
102+
103+The project-wide suite, 0-warning parity sweep, and the cross-lane acceptance
104+arms (mono, 10-bit `reelb_*`, CDF-disabled, 4:4:4 refusal, qmatrix refusal) are
105+owned by the main agent and were not run in this lane.
106+
107+## Suite (orchestrator-run, committed tree 5c48d7b0)
108+
109+`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1l64 TMPDIR=$HOME/tmp-av1l64 cargo test -p ec-av1 --release --lib -- --test-threads=1`:
110+
111+```
112+test result: ok. 605 passed; 0 failed; 60 ignored; 0 measured; 0 filtered out; finished in 1371.22s
113+```
114+
115+605 = 603 (main after rect14) + this lane's 2 new gate tests. First attempt
116+failed 6 tests on a missing TMPDIR directory (`writing the probe stream: No
117+such file or directory`) — environmental, green on re-run with the dir
118+created.