forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1-ibc128chunk: per-axis chroma chunk walk in decode_intrabc_128rect

Browse files at this commit

b430562021685bc8ff953f73dc55b7e8c445b72fAhmet Kaan GümüşParent: f896619405e2ec
- de-square-cuts the mu-chunk chroma read walk and the mu_chroma replay (chunk-then-unit, the twin's shape); witnessed red/green on two pinned 4:2:2 intrabc sb128 fixtures, byte-exact vs aomdec
- reviewer PASS after rework (replay coverage regression found and fixed)
- suite 640/0 on server-3

# Conflicts:
#	crates/ec-av1/src/decode.rs

6 changed files +21673 -11323

crates/ec-av1/examples/decode_probe.rsmodified+9 -0
@@ -1,3 +1,5 @@
1+/home/user/Documents/Code/Rust/edith_codecs/crates/ec-av1/examples/decode_probe.rs:
2+
13 //! Where does a real stream stop? Decode one AV1 file and print the answer.
24 //!
35 //! The gates in [`ec_av1::stream`] each pin one capability against one encoder
@@ -91,6 +93,13 @@ fn main() {
9193 "intrabc_128rect: {}",
9294 ec_av1::stream::intrabc_128rect_hits()
9395 );
96+ // lane-av1-ibc128chunk: the 128-root intrabc strip's per-axis chroma
97+ // mu-chunk walk -- unit count and the `(64>>ss_x)|(64>>ss_y)` extent.
98+ println!(
99+ "intrabc_128rect_chroma_chunk: units={} shape=0x{:x}",
100+ ec_av1::stream::intrabc_128rect_chroma_chunk_hits(),
101+ ec_av1::stream::intrabc_128rect_chunk_shape()
102+ );
94103 let (rtu, rsplit, robmc) = ec_av1::stream::rect_inter_tu_counters();
95104 println!("rect_inter: tu={rtu} txsplit={rsplit} obmc_leaf={robmc}");
96105 println!(
crates/ec-av1/fixtures/422_intrabc_sb128_strip.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/422_intrabc_sb128_strip_notxsearch.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+14892 -8650

Diff too large; view file

@@ -1,3 +1,5 @@
1+/home/user/Documents/Code/Rust/edith_codecs/crates/ec-av1/src/decode.rs:
2+
13 //! Software decoder for this crate's own key-frame tile payloads (spec 5.11),
24 //! the reader half of [`crate::tile`]'s writer.
35 //!
@@ -305,7 +307,8 @@ impl FrameCtx {
305307 let ctx = Self::new();
306308 let on = crate::encode::sb128_on();
307309 ctx.sb128_flag.set(on);
308- ctx.reach_sb_px.set(if on { 128 } else { crate::encode::SUPERBLOCK });
310+ ctx.reach_sb_px
311+ .set(if on { 128 } else { crate::encode::SUPERBLOCK });
309312 ctx
310313 }
311314 }
@@ -362,9 +365,9 @@ use crate::msac::SymbolDecoder;
362365 use crate::mvstack::{
363366 ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME, LAST3_FRAME,
364367 MiGrid, MiInfo, NO_REF1, NO_SIGN_BIAS, NeighbourRef, SignBiasTable, comp_reference_type_ctx,
365- find_mv_stack_with_sign_bias, mv16, mv32, reference_mode_ctx,
366- single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx,
367- single_ref_p6_ctx, uni_comp_ref_p1_ctx,
368+ find_mv_stack_with_sign_bias, mv16, mv32, reference_mode_ctx, single_ref_p1_ctx,
369+ single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx,
370+ uni_comp_ref_p1_ctx,
368371 };
369372 use crate::tile::{INTRA_MODE_CTX, block_grid, has_half};
370373 use crate::transform::{TxType, dequant_and_inverse_typed_wh};
@@ -429,7 +432,6 @@ pub(crate) fn coeff_trace_on() -> bool {
429432 }
430433 }
431434
432-
433435 /// Sets [`SB128`] for this thread (called once per frame from `stream.rs`).
434436 pub(crate) fn set_sb128(v: bool, fctx: &crate::decode::FrameCtx) {
435437 fctx.sb128_flag.with(|c| c.set(v));
@@ -438,10 +440,7 @@ pub(crate) fn set_sb128(v: bool, fctx: &crate::decode::FrameCtx) {
438440
439441 /// lane-av1mixloss: sets [`FrameCtx::lossless_per_seg`] (called once per frame
440442 /// from `stream.rs`).
441-pub(crate) fn set_lossless_per_seg(
442- table: [bool; MAX_SEGMENTS],
443- fctx: &crate::decode::FrameCtx,
444-) {
443+pub(crate) fn set_lossless_per_seg(table: [bool; MAX_SEGMENTS], fctx: &crate::decode::FrameCtx) {
445444 fctx.lossless_per_seg.with(|c| c.set(table));
446445 }
447446
@@ -701,17 +700,16 @@ pub(crate) fn round_ss(dim: usize, ss: usize) -> usize {
701700 (dim + ((1usize << ss) >> 1)) >> ss
702701 }
703702
704-
705- /// This frame's superres state: `(upscaled_width, superres_denom)`, or
706- /// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs
707- /// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid,
708- /// `read_lr`'s unit corners and the pixel filters themselves -- works in
709- /// UPSCALED coordinates while deblock and CDEF work in downscaled ones
710- /// (libaom `av1_superres_upscale` in `decodeframe.c`, and
711- /// `av1_loop_restoration_corners_in_sb`'s own `mi_to_num_x`/`denom_x`
712- /// superres arms). Set once per frame from [`crate::stream`]'s decode
713- /// loop, like [`BIT_DEPTH`], and reset to `(0, 8)` on an unscaled frame
714- /// so a later frame never inherits it.
703+/// This frame's superres state: `(upscaled_width, superres_denom)`, or
704+/// `(0, 8)` when the frame is not scaled. Spec 7.16's upscale runs
705+/// between CDEF and loop restoration, so LOOP RESTORATION -- unit grid,
706+/// `read_lr`'s unit corners and the pixel filters themselves -- works in
707+/// UPSCALED coordinates while deblock and CDEF work in downscaled ones
708+/// (libaom `av1_superres_upscale` in `decodeframe.c`, and
709+/// `av1_loop_restoration_corners_in_sb`'s own `mi_to_num_x`/`denom_x`
710+/// superres arms). Set once per frame from [`crate::stream`]'s decode
711+/// loop, like [`BIT_DEPTH`], and reset to `(0, 8)` on an unscaled frame
712+/// so a later frame never inherits it.
715713
716714 /// Sets [`SUPERRES`] for the current thread. `upscaled_width` is 0 (and
717715 /// `denom` 8) for a frame that is not superres-scaled.
@@ -902,7 +900,15 @@ fn block_iqmatrix(
902900 /// top-left leaf is the only block that can ever land there), or when that
903901 /// leaf both *is* the whole superblock and is `skip` (the one case libaom
904902 /// itself skips the read, state carrying over unchanged).
905-fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, is_whole_sb: bool, skip: bool, fctx: &crate::decode::FrameCtx) {
903+fn maybe_read_delta_q(
904+ dec: &mut SymbolDecoder,
905+ cdfs: &mut Cdfs,
906+ mi_r: usize,
907+ mi_c: usize,
908+ is_whole_sb: bool,
909+ skip: bool,
910+ fctx: &crate::decode::FrameCtx,
911+) {
906912 if !fctx.delta_q_present.with(|c| c.get()) {
907913 return;
908914 }
@@ -929,7 +935,8 @@ fn maybe_read_delta_q(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_
929935 let reduced = if sign_negative { -abs } else { abs };
930936 hit!(DELTA_Q_HITS);
931937 let res = fctx.delta_q_res.with(|c| c.get());
932- fctx.current_q_idx.with(|c| c.set((c.get() + reduced * res).clamp(1, 255)));
938+ fctx.current_q_idx
939+ .with(|c| c.set((c.get() + reduced * res).clamp(1, 255)));
933940 }
934941
935942 // lane-realworld r5: this frame's `delta.lf_present`/`lf_res`/`lf_multi`
@@ -956,7 +963,15 @@ pub(crate) fn delta_lf_hits() -> usize {
956963 /// [`maybe_read_delta_q`] (spec order `delta_q -> delta_lf`), looped over
957964 /// `FRAME_LF_COUNT = 4` planes/directions when `delta_lf_multi` is set, or
958965 /// read once into index 0 otherwise.
959-fn maybe_read_delta_lf(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, is_whole_sb: bool, skip: bool, fctx: &crate::decode::FrameCtx) {
966+fn maybe_read_delta_lf(
967+ dec: &mut SymbolDecoder,
968+ cdfs: &mut Cdfs,
969+ mi_r: usize,
970+ mi_c: usize,
971+ is_whole_sb: bool,
972+ skip: bool,
973+ fctx: &crate::decode::FrameCtx,
974+) {
960975 if !fctx.delta_lf_present.with(|c| c.get()) {
961976 return;
962977 }
@@ -1091,17 +1106,24 @@ pub(crate) fn set_segmentation(
10911106 seg: SegmentationParams,
10921107 mi_rows: usize,
10931108 mi_cols: usize,
1094- prev: Option<&[u8]>, fctx: &crate::decode::FrameCtx,
1109+ prev: Option<&[u8]>,
1110+ fctx: &crate::decode::FrameCtx,
10951111 ) {
10961112 if crate::envflags::env_flag!("EC_HDR") {
10971113 eprintln!(
10981114 "EC_SEGHDR enabled={} update_map={} temporal={} preskip={} last_active={} data={:?}",
1099- seg.enabled, seg.update_map, seg.temporal_update, seg.seg_id_pre_skip, seg.last_active_seg_id, seg.feature_data
1115+ seg.enabled,
1116+ seg.update_map,
1117+ seg.temporal_update,
1118+ seg.seg_id_pre_skip,
1119+ seg.last_active_seg_id,
1120+ seg.feature_data
11001121 );
11011122 }
11021123 fctx.seg.with(|s| *s.borrow_mut() = seg);
11031124 fctx.seg_mi_dims.with(|c| c.set((mi_rows, mi_cols)));
1104- fctx.seg_ids.with(|m| *m.borrow_mut() = vec![0u8; mi_rows * mi_cols]);
1125+ fctx.seg_ids
1126+ .with(|m| *m.borrow_mut() = vec![0u8; mi_rows * mi_cols]);
11051127 fctx.prev_seg_ids.with(|m| {
11061128 let mut m = m.borrow_mut();
11071129 m.clear();
@@ -1111,8 +1133,10 @@ pub(crate) fn set_segmentation(
11111133 }
11121134 }
11131135 });
1114- fctx.above_seg_pred.with(|m| *m.borrow_mut() = vec![0u8; mi_cols]);
1115- fctx.left_seg_pred.with(|m| *m.borrow_mut() = vec![0u8; mi_rows]);
1136+ fctx.above_seg_pred
1137+ .with(|m| *m.borrow_mut() = vec![0u8; mi_cols]);
1138+ fctx.left_seg_pred
1139+ .with(|m| *m.borrow_mut() = vec![0u8; mi_rows]);
11161140 fctx.cur_segment_id.with(|c| c.set(0));
11171141 }
11181142
@@ -1200,9 +1224,19 @@ fn segment_id_at(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) -> u8
12001224 }
12011225
12021226 /// `set_segment_id`: stamps `id` over every mi cell this block covers.
1203-fn write_segment_id(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, id: u8, fctx: &crate::decode::FrameCtx) {
1227+fn write_segment_id(
1228+ mi_r: usize,
1229+ mi_c: usize,
1230+ w_mi: usize,
1231+ h_mi: usize,
1232+ id: u8,
1233+ fctx: &crate::decode::FrameCtx,
1234+) {
12041235 let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get());
1205- let (x_mis, y_mis) = (w_mi.min(mi_cols.saturating_sub(mi_c)), h_mi.min(mi_rows.saturating_sub(mi_r)));
1236+ let (x_mis, y_mis) = (
1237+ w_mi.min(mi_cols.saturating_sub(mi_c)),
1238+ h_mi.min(mi_rows.saturating_sub(mi_r)),
1239+ );
12061240 fctx.seg_ids.with(|m| {
12071241 let mut m = m.borrow_mut();
12081242 for y in 0..y_mis {
@@ -1219,9 +1253,18 @@ fn write_segment_id(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, id: u8,
12191253 /// inherited VERBATIM over this block's own mi footprint -- per-cell copies,
12201254 /// not the minified id [`predicted_segment_id`] hands the block. Without a
12211255 /// previous map the footprint is zeroed, exactly as the C NULL branch does.
1222-fn copy_segment_ids(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, fctx: &crate::decode::FrameCtx) {
1256+fn copy_segment_ids(
1257+ mi_r: usize,
1258+ mi_c: usize,
1259+ w_mi: usize,
1260+ h_mi: usize,
1261+ fctx: &crate::decode::FrameCtx,
1262+) {
12231263 let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get());
1224- let (x_mis, y_mis) = (w_mi.min(mi_cols.saturating_sub(mi_c)), h_mi.min(mi_rows.saturating_sub(mi_r)));
1264+ let (x_mis, y_mis) = (
1265+ w_mi.min(mi_cols.saturating_sub(mi_c)),
1266+ h_mi.min(mi_rows.saturating_sub(mi_r)),
1267+ );
12251268 fctx.seg_ids.with(|m| {
12261269 let mut m = m.borrow_mut();
12271270 fctx.prev_seg_ids.with(|p| {
@@ -1239,14 +1282,23 @@ fn copy_segment_ids(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, fctx: &c
12391282 /// `get_predicted_segment_id` (libaom `dec_get_segment_id` over
12401283 /// `last_frame_seg_map`): the minimum previous-frame segment id over the
12411284 /// block's own mi footprint. `0` when there is no previous map.
1242-fn predicted_segment_id(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, fctx: &crate::decode::FrameCtx) -> u8 {
1285+fn predicted_segment_id(
1286+ mi_r: usize,
1287+ mi_c: usize,
1288+ w_mi: usize,
1289+ h_mi: usize,
1290+ fctx: &crate::decode::FrameCtx,
1291+) -> u8 {
12431292 let (mi_rows, mi_cols) = fctx.seg_mi_dims.with(|c| c.get());
12441293 fctx.prev_seg_ids.with(|m| {
12451294 let m = m.borrow();
12461295 if m.is_empty() {
12471296 return 0;
12481297 }
1249- let (x_mis, y_mis) = (w_mi.min(mi_cols.saturating_sub(mi_c)), h_mi.min(mi_rows.saturating_sub(mi_r)));
1298+ let (x_mis, y_mis) = (
1299+ w_mi.min(mi_cols.saturating_sub(mi_c)),
1300+ h_mi.min(mi_rows.saturating_sub(mi_r)),
1301+ );
12501302 let mut id = u8::MAX;
12511303 for y in 0..y_mis {
12521304 for x in 0..x_mis {
@@ -1277,7 +1329,11 @@ fn neg_deinterleave(diff: i32, reference: i32, max: i32) -> i32 {
12771329 reference - (diff >> 1)
12781330 };
12791331 }
1280- if 2 * reference < max { diff } else { max - (diff + 1) }
1332+ if 2 * reference < max {
1333+ diff
1334+ } else {
1335+ max - (diff + 1)
1336+ }
12811337 }
12821338
12831339 /// `av1_get_spatial_seg_pred`: `(prediction, cdf_index)` from the current
@@ -1311,7 +1367,14 @@ fn spatial_seg_pred(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) ->
13111367 /// `read_segment_id` (libaom `decodemv.c:280`): the spatially predicted id
13121368 /// when `skip`, otherwise one `segment_id` symbol de-interleaved against
13131369 /// that prediction. Does NOT write the map -- callers do.
1314-fn read_segment_id(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: usize, skip: bool, fctx: &crate::decode::FrameCtx) -> u8 {
1370+fn read_segment_id(
1371+ dec: &mut SymbolDecoder,
1372+ cdfs: &mut Cdfs,
1373+ mi_r: usize,
1374+ mi_c: usize,
1375+ skip: bool,
1376+ fctx: &crate::decode::FrameCtx,
1377+) -> u8 {
13151378 let (pred, ctx) = spatial_seg_pred(mi_r, mi_c, fctx);
13161379 if skip {
13171380 return pred as u8;
@@ -1323,7 +1386,10 @@ fn read_segment_id(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c:
13231386 // Mirrors the oracle's own `EC_SEG mi_row=.. cdf=.. pred=.. coded=.. id=..`
13241387 // (libaom `decodemv.c:read_segment_id`), for a cross-decoder segment diff.
13251388 if crate::envflags::env_flag!("EC_TRACE_SEG") {
1326- eprintln!("EC_SEG mi_row={mi_r} mi_col={mi_c} cdf={ctx} pred={pred} coded={coded} id={id} rng={}", dec.debug_state().0);
1389+ eprintln!(
1390+ "EC_SEG mi_row={mi_r} mi_col={mi_c} cdf={ctx} pred={pred} coded={coded} id={id} rng={}",
1391+ dec.debug_state().0
1392+ );
13271393 }
13281394 id as u8
13291395 }
@@ -1338,7 +1404,8 @@ fn intra_segment_id(
13381404 mi_c: usize,
13391405 w_mi: usize,
13401406 h_mi: usize,
1341- skip: bool, fctx: &crate::decode::FrameCtx,
1407+ skip: bool,
1408+ fctx: &crate::decode::FrameCtx,
13421409 ) {
13431410 if !fctx.seg.with(|s| s.borrow().enabled) {
13441411 return;
@@ -1367,11 +1434,17 @@ fn inter_segment_id(
13671434 w_mi: usize,
13681435 h_mi: usize,
13691436 skip: bool,
1370- pre_skip: bool, fctx: &crate::decode::FrameCtx,
1437+ pre_skip: bool,
1438+ fctx: &crate::decode::FrameCtx,
13711439 ) {
13721440 let (enabled, update_map, temporal_update, pre_skip_frame) = fctx.seg.with(|s| {
13731441 let s = s.borrow();
1374- (s.enabled, s.update_map, s.temporal_update, s.seg_id_pre_skip)
1442+ (
1443+ s.enabled,
1444+ s.update_map,
1445+ s.temporal_update,
1446+ s.seg_id_pre_skip,
1447+ )
13751448 });
13761449 if !enabled {
13771450 return;
@@ -1426,12 +1499,14 @@ fn seg_pred_ctx(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) -> usi
14261499 // what keeps a previous tile's stamps out of this tile's context.
14271500 let (row0, col0) = fctx.seg_tile_origin.with(|c| c.get());
14281501 let above = if mi_r > row0 {
1429- fctx.above_seg_pred.with(|m| m.borrow().get(mi_c).copied().unwrap_or(0))
1502+ fctx.above_seg_pred
1503+ .with(|m| m.borrow().get(mi_c).copied().unwrap_or(0))
14301504 } else {
14311505 0
14321506 };
14331507 let left = if mi_c > col0 {
1434- fctx.left_seg_pred.with(|m| m.borrow().get(mi_r).copied().unwrap_or(0))
1508+ fctx.left_seg_pred
1509+ .with(|m| m.borrow().get(mi_r).copied().unwrap_or(0))
14351510 } else {
14361511 0
14371512 };
@@ -1439,7 +1514,14 @@ fn seg_pred_ctx(mi_r: usize, mi_c: usize, fctx: &crate::decode::FrameCtx) -> usi
14391514 }
14401515
14411516 /// Spec 5.11.9's `AboveSegPredContext`/`LeftSegPredContext` update.
1442-fn stamp_seg_pred(mi_r: usize, mi_c: usize, w_mi: usize, h_mi: usize, value: u8, fctx: &crate::decode::FrameCtx) {
1517+fn stamp_seg_pred(
1518+ mi_r: usize,
1519+ mi_c: usize,
1520+ w_mi: usize,
1521+ h_mi: usize,
1522+ value: u8,
1523+ fctx: &crate::decode::FrameCtx,
1524+) {
14431525 fctx.above_seg_pred.with(|m| {
14441526 let mut m = m.borrow_mut();
14451527 for i in 0..w_mi {
@@ -1507,7 +1589,8 @@ fn tu_reach(
15071589 px: usize,
15081590 py: usize,
15091591 width: usize,
1510- height: usize, fctx: &crate::decode::FrameCtx,
1592+ height: usize,
1593+ fctx: &crate::decode::FrameCtx,
15111594 ) -> Reach {
15121595 let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx, tx, block);
15131596 let standalone = Reach::of(tx, px + col_off, py + row_off, width, height, fctx);
@@ -1535,7 +1618,8 @@ fn tu_reach_rect(
15351618 px: usize,
15361619 py: usize,
15371620 width: usize,
1538- height: usize, fctx: &crate::decode::FrameCtx,
1621+ height: usize,
1622+ fctx: &crate::decode::FrameCtx,
15391623 ) -> Reach {
15401624 let fixed = Reach::of_tu(bw, bh, col_off, row_off, tx_w, tx_h, block);
15411625 if tx_w == tx_h {
@@ -1589,8 +1673,7 @@ thread_local! {
15891673 /// lane-comppin r4: decode-order picture counter for `EC_AV1_PREFILT_DUMP`,
15901674 /// mirroring stream.rs's `pictures_decoded` so the two dumps index
15911675 /// identically against aomdec's own `ec_frame_idx` in decodeframe.c.
1592-static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize =
1593- std::sync::atomic::AtomicUsize::new(0);
1676+static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
15941677
15951678 /// Current value of [`DEBLOCK_HITS`].
15961679 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
@@ -1802,7 +1885,11 @@ fn vartx_rect_leaf_hit(tw: usize, th: usize) {
18021885 if crate::envflags::env_flag!("EC_VARTXLEAF") {
18031886 eprintln!("EC_VARTXLEAF tw={tw} th={th}");
18041887 }
1805- let cell = if tw.min(th) == 4 { &VARTX_RECT_LEAF4_HITS } else { &VARTX_RECT_LEAF_HITS };
1888+ let cell = if tw.min(th) == 4 {
1889+ &VARTX_RECT_LEAF4_HITS
1890+ } else {
1891+ &VARTX_RECT_LEAF_HITS
1892+ };
18061893 cell.with(|c| {
18071894 let mut h = c.get();
18081895 h[usize::from(th > tw)] += 1;
@@ -1815,13 +1902,15 @@ fn vartx_rect_leaf_hit(tw: usize, th: usize) {
18151902 pub(crate) fn set_inter_tx_mode(
18161903 tx_select: bool,
18171904 reduced_tx_set: bool,
1818- enable_filter_intra: bool, fctx: &crate::decode::FrameCtx,
1905+ enable_filter_intra: bool,
1906+ fctx: &crate::decode::FrameCtx,
18191907 ) {
18201908 fctx.tx_select_inter.with(|c| c.set(tx_select));
18211909 fctx.intra_only.with(|c| c.set(false));
18221910 fctx.tx_select_frame.with(|c| c.set(tx_select));
18231911 fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set));
1824- fctx.enable_filter_intra_inter.with(|c| c.set(enable_filter_intra));
1912+ fctx.enable_filter_intra_inter
1913+ .with(|c| c.set(enable_filter_intra));
18251914 }
18261915
18271916 // How many `partition_w16` reads (a 16x16 block's own partition symbol, key
@@ -2559,15 +2648,14 @@ pub(crate) fn intra_in_inter_split_tx_hits() -> [usize; 4] {
25592648 INTRA_IN_INTER_SPLIT_TX_HITS.with(std::cell::Cell::get)
25602649 }
25612650
2562- /// A just-decoded palette-Y block's own predicted pixels
2563- /// (`side*side`, row-major, `colors[map[i]]`), consumed by
2564- /// [`PlaneBuf::reconstruct`]'s next call in place of `predict()` -- the
2565- /// same off-the-call-stack idiom as [`ENABLE_EDGE_FILTER`] (threading a
2566- /// per-block override through `read_plane`'s two dozen call sites is the
2567- /// alternative this avoids). Always empty again once that call consumes
2568- /// it (`.take()`), so a non-palette block's own `reconstruct` call never
2569- /// sees stale state.
2570-
2651+/// A just-decoded palette-Y block's own predicted pixels
2652+/// (`side*side`, row-major, `colors[map[i]]`), consumed by
2653+/// [`PlaneBuf::reconstruct`]'s next call in place of `predict()` -- the
2654+/// same off-the-call-stack idiom as [`ENABLE_EDGE_FILTER`] (threading a
2655+/// per-block override through `read_plane`'s two dozen call sites is the
2656+/// alternative this avoids). Always empty again once that call consumes
2657+/// it (`.take()`), so a non-palette block's own `reconstruct` call never
2658+/// sees stale state.
25712659
25722660 /// Arms the pending [`PALETTE_PRED`] override for the next `reconstruct`
25732661 /// (`set`) / consumes it (`take`). Set and take MUST pair: a buffer armed at a
@@ -2579,7 +2667,14 @@ pub(crate) fn intra_in_inter_split_tx_hits() -> [usize; 4] {
25792667 /// top-left corner (the luma split-transform paths already window; the chroma
25802668 /// ones did not, which is invisible until a lossless frame codes a palette
25812669 /// block as 4x4 chroma units).
2582-fn palette_window(buf: &[u16], stride: usize, ox: usize, oy: usize, w: usize, h: usize) -> Vec<u16> {
2670+fn palette_window(
2671+ buf: &[u16],
2672+ stride: usize,
2673+ ox: usize,
2674+ oy: usize,
2675+ w: usize,
2676+ h: usize,
2677+) -> Vec<u16> {
25832678 (0..h)
25842679 .flat_map(|r| buf[(oy + r) * stride + ox..][..w].iter().copied())
25852680 .collect()
@@ -2624,7 +2719,12 @@ pub(crate) struct CflSrc {
26242719 }
26252720
26262721 fn cfl_src(px: usize, py: usize, side: usize) -> CflSrc {
2627- CflSrc { px, py, bw: side, bh: side }
2722+ CflSrc {
2723+ px,
2724+ py,
2725+ bw: side,
2726+ bh: side,
2727+ }
26282728 }
26292729
26302730 fn cfl_src_rect(px: usize, py: usize, bw: usize, bh: usize) -> CflSrc {
@@ -2670,8 +2770,7 @@ pub(crate) struct TxParams {
26702770 /// The mixed-lossless witness's proof the per-segment lossless path really
26712771 /// ran on a frame that is NOT `CodedLossless`. Atomic because the wavefront
26722772 /// workers run this on their own threads.
2673-static LOSSLESS_WHT_UNITS: std::sync::atomic::AtomicUsize =
2674- std::sync::atomic::AtomicUsize::new(0);
2773+static LOSSLESS_WHT_UNITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
26752774
26762775 /// [`LOSSLESS_WHT_UNITS`] -- total over the process, read as a before/after
26772776 /// delta around one decode.
@@ -2690,11 +2789,21 @@ impl TxParams {
26902789 debug_assert_eq!((self.w, self.h), (4, 4));
26912790 debug_assert_eq!(self.tx_type, TxType::DctDct);
26922791 crate::transform::dequant_and_inverse_wht4x4(
2693- grid, self.bit_depth, self.q_idx, self.dc_delta, self.ac_delta,
2792+ grid,
2793+ self.bit_depth,
2794+ self.q_idx,
2795+ self.dc_delta,
2796+ self.ac_delta,
26942797 )
26952798 } else {
26962799 dequant_and_inverse_typed_wh(
2697- grid, self.w, self.h, self.bit_depth, self.q_idx, self.dc_delta, self.ac_delta,
2800+ grid,
2801+ self.w,
2802+ self.h,
2803+ self.bit_depth,
2804+ self.q_idx,
2805+ self.dc_delta,
2806+ self.ac_delta,
26982807 self.tx_type,
26992808 self.qm,
27002809 )
@@ -2836,7 +2945,11 @@ pub(crate) fn is_zero_grid(grid: &[i32]) -> bool {
28362945
28372946 /// `residual`, or `n` zeros when it is the empty all-zero marker.
28382947 fn dense_residual(residual: &[i32], n: usize) -> &[i32] {
2839- if residual.is_empty() { &ZERO_RESIDUAL[..n] } else { residual }
2948+ if residual.is_empty() {
2949+ &ZERO_RESIDUAL[..n]
2950+ } else {
2951+ residual
2952+ }
28402953 }
28412954
28422955 /// Where a recorded motion-compensated write reads its prediction from.
@@ -2854,7 +2967,11 @@ pub(crate) enum Pred<'a> {
28542967 Inline(&'a [u16], usize),
28552968 /// The current block's deferred prediction: plane, its stride, and this
28562969 /// unit's offset into it.
2857- Cur { plane: usize, stride: usize, off: usize },
2970+ Cur {
2971+ plane: usize,
2972+ stride: usize,
2973+ off: usize,
2974+ },
28582975 }
28592976
28602977 impl<'a> Pred<'a> {
@@ -2878,7 +2995,11 @@ impl<'a> Pred<'a> {
28782995 fn offset(self, n: usize) -> Self {
28792996 match self {
28802997 Self::Inline(b, s) => Self::Inline(&b[n..], s),
2881- Self::Cur { plane, stride, off } => Self::Cur { plane, stride, off: off + n },
2998+ Self::Cur { plane, stride, off } => Self::Cur {
2999+ plane,
3000+ stride,
3001+ off: off + n,
3002+ },
28823003 }
28833004 }
28843005 }
@@ -2891,7 +3012,11 @@ pub(crate) enum PredSrc {
28913012 /// stride it is read at -- which is the block's, not necessarily the
28923013 /// op's (a transform unit's residual stays dense, so the worker takes
28933014 /// its window out of the block prediction itself).
2894- Cur { plane: usize, off: usize, src: usize },
3015+ Cur {
3016+ plane: usize,
3017+ off: usize,
3018+ src: usize,
3019+ },
28953020 }
28963021
28973022 /// One block's whole-block prediction build, deferred to a recon worker.
@@ -2954,12 +3079,12 @@ fn push_pred<'a>(
29543079 ) + 'a,
29553080 ) {
29563081 type Dyn<'x> = dyn FnOnce(
2957- &mut PlaneBuf<'static>,
2958- &mut PlaneBuf<'static>,
2959- &mut PlaneBuf<'static>,
2960- &crate::decode::FrameCtx,
2961- &mut [Vec<u16>; 3],
2962- ) + 'x;
3082+ &mut PlaneBuf<'static>,
3083+ &mut PlaneBuf<'static>,
3084+ &mut PlaneBuf<'static>,
3085+ &crate::decode::FrameCtx,
3086+ &mut [Vec<u16>; 3],
3087+ ) + 'x;
29633088 let boxed: Box<Dyn<'a>> = Box::new(f);
29643089 // SAFETY: see [`PredBuild`] -- every worker is joined by [`WaveGuard`]
29653090 // before the borrows the closure holds go out of scope.
@@ -3090,7 +3215,16 @@ fn push_op(fctx: &crate::decode::FrameCtx, op: ReconOp) {
30903215 // The inline path never records coefficients (the transform runs at
30913216 // the push site), so the arena is not read here.
30923217 unsafe {
3093- exec_op(op, &mut *y, &mut *u, &mut *v, &mut Default::default(), &[], &[], fctx)
3218+ exec_op(
3219+ op,
3220+ &mut *y,
3221+ &mut *u,
3222+ &mut *v,
3223+ &mut Default::default(),
3224+ &[],
3225+ &[],
3226+ fctx,
3227+ )
30943228 };
30953229 return;
30963230 }
@@ -3172,11 +3306,7 @@ type JobBufs = (Vec<ReconOp>, Vec<i32>, Vec<u16>);
31723306 impl WaveQueue {
31733307 /// The lowest-row queued job whose wavefront dependencies are satisfied,
31743308 /// or `None` (with the blocking condition counted when instrumented).
3175- fn take_runnable(
3176- &mut self,
3177- last_col: usize,
3178- stats: bool,
3179- ) -> Option<(usize, usize, ReconJob)> {
3309+ fn take_runnable(&mut self, last_col: usize, stats: bool) -> Option<(usize, usize, ReconJob)> {
31803310 let mut blocked: Option<bool> = None;
31813311 for r in 0..self.rows.len() {
31823312 let Some(front) = self.rows[r].front() else {
@@ -3312,10 +3442,16 @@ fn wave_worker(st: &WaveState, idx: usize) {
33123442 // every superblock that could have written or be reading them is
33133443 // complete by the wavefront rule above.
33143444 let mut cur: [Vec<u16>; 3] = Default::default();
3315- let ReconJob { mut ops, mut coeffs, mut preds } = job;
3445+ let ReconJob {
3446+ mut ops,
3447+ mut coeffs,
3448+ mut preds,
3449+ } = job;
33163450 unsafe {
33173451 for op in ops.drain(..) {
3318- exec_op(op, &mut *y, &mut *u, &mut *v, &mut cur, &coeffs, &preds, &fctx);
3452+ exec_op(
3453+ op, &mut *y, &mut *u, &mut *v, &mut cur, &coeffs, &preds, &fctx,
3454+ );
33193455 }
33203456 }
33213457 if stats {
@@ -3361,7 +3497,9 @@ impl<'a> WaveGuard<'a> {
33613497 }
33623498 let st = std::sync::Arc::new(WaveState {
33633499 q: std::sync::Mutex::new(WaveQueue {
3364- rows: (0..rows).map(|_| std::collections::VecDeque::new()).collect(),
3500+ rows: (0..rows)
3501+ .map(|_| std::collections::VecDeque::new())
3502+ .collect(),
33653503 queued: 0,
33663504 done: vec![-1; rows],
33673505 last_sub: vec![-1; rows],
@@ -3393,7 +3531,8 @@ impl<'a> WaveGuard<'a> {
33933531 batch.submit(move || wave_worker(&st, idx));
33943532 }
33953533 fctx.wave.with(|w| *w.borrow_mut() = Some(st));
3396- fctx.wave_mark.with(|c| c.set(Some(std::time::Instant::now())));
3534+ fctx.wave_mark
3535+ .with(|c| c.set(Some(std::time::Instant::now())));
33973536 Some(Self(fctx, Some(batch)))
33983537 }
33993538 }
@@ -3527,8 +3666,24 @@ fn inline_intra(
35273666 // SAFETY: see [`ReconPlanes`].
35283667 unsafe {
35293668 exec_intra(
3530- &mut *y, &mut *u, &mut *v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach,
3531- residual, cfl, filter_intra, smooth_neighbor, pred, fctx,
3669+ &mut *y,
3670+ &mut *u,
3671+ &mut *v,
3672+ plane,
3673+ x,
3674+ oy,
3675+ bw,
3676+ bh,
3677+ rect,
3678+ mode,
3679+ angle_delta,
3680+ reach,
3681+ residual,
3682+ cfl,
3683+ filter_intra,
3684+ smooth_neighbor,
3685+ pred,
3686+ fctx,
35323687 );
35333688 }
35343689 true
@@ -3553,7 +3708,9 @@ fn inline_mc(
35533708 };
35543709 // SAFETY: see [`ReconPlanes`].
35553710 unsafe {
3556- exec_mc(&mut *y, &mut *u, &mut *v, plane, x, oy, stride, w, h, prediction, residual, fctx);
3711+ exec_mc(
3712+ &mut *y, &mut *u, &mut *v, plane, x, oy, stride, w, h, prediction, residual, fctx,
3713+ );
35573714 }
35583715 true
35593716 }
@@ -3571,19 +3728,47 @@ fn push_intra(
35713728 residual: &[i32],
35723729 cfl: Option<(i32, CflSrc)>,
35733730 filter_intra: Option<usize>,
3574- smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
3731+ smooth_neighbor: bool,
3732+ fctx: &crate::decode::FrameCtx,
35753733 ) {
35763734 if inline_intra(
3577- plane, x, y, side, side, false, mode, angle_delta, reach, residual, cfl, filter_intra,
3578- smooth_neighbor, fctx,
3735+ plane,
3736+ x,
3737+ y,
3738+ side,
3739+ side,
3740+ false,
3741+ mode,
3742+ angle_delta,
3743+ reach,
3744+ residual,
3745+ cfl,
3746+ filter_intra,
3747+ smooth_neighbor,
3748+ fctx,
35793749 ) {
35803750 return;
35813751 }
35823752 let pred = take_palette_pred(fctx);
3583- push_op(fctx, ReconOp::Intra {
3584- plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,
3585- residual: Residual::done(residual, fctx), cfl, filter_intra, smooth_neighbor, pred,
3586- });
3753+ push_op(
3754+ fctx,
3755+ ReconOp::Intra {
3756+ plane,
3757+ x,
3758+ y,
3759+ bw: side,
3760+ bh: side,
3761+ rect: false,
3762+ mode,
3763+ angle_delta,
3764+ reach,
3765+ residual: Residual::done(residual, fctx),
3766+ cfl,
3767+ filter_intra,
3768+ smooth_neighbor,
3769+ pred,
3770+ },
3771+ );
35873772 }
35883773
35893774 /// [`PlaneBuf::reconstruct_rect`], recorded (lane-wave1 step (i)).
@@ -3600,19 +3785,47 @@ fn push_intra_rect(
36003785 residual: &[i32],
36013786 cfl: Option<(i32, CflSrc)>,
36023787 filter_intra: Option<usize>,
3603- smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
3788+ smooth_neighbor: bool,
3789+ fctx: &crate::decode::FrameCtx,
36043790 ) {
36053791 if inline_intra(
3606- plane, x, y, bw, bh, true, mode, angle_delta, reach, residual, cfl, filter_intra,
3607- smooth_neighbor, fctx,
3792+ plane,
3793+ x,
3794+ y,
3795+ bw,
3796+ bh,
3797+ true,
3798+ mode,
3799+ angle_delta,
3800+ reach,
3801+ residual,
3802+ cfl,
3803+ filter_intra,
3804+ smooth_neighbor,
3805+ fctx,
36083806 ) {
36093807 return;
36103808 }
36113809 let pred = take_palette_pred(fctx);
3612- push_op(fctx, ReconOp::Intra {
3613- plane, x, y, bw, bh, rect: true, mode, angle_delta, reach,
3614- residual: Residual::done(residual, fctx), cfl, filter_intra, smooth_neighbor, pred,
3615- });
3810+ push_op(
3811+ fctx,
3812+ ReconOp::Intra {
3813+ plane,
3814+ x,
3815+ y,
3816+ bw,
3817+ bh,
3818+ rect: true,
3819+ mode,
3820+ angle_delta,
3821+ reach,
3822+ residual: Residual::done(residual, fctx),
3823+ cfl,
3824+ filter_intra,
3825+ smooth_neighbor,
3826+ pred,
3827+ },
3828+ );
36163829 }
36173830
36183831 /// [`PlaneBuf::reconstruct_mc_rect`] at `stride == w == h == side`, recorded.
@@ -3622,7 +3835,8 @@ fn push_mc(
36223835 y: usize,
36233836 side: usize,
36243837 prediction: Pred<'_>,
3625- residual: &[i32], fctx: &crate::decode::FrameCtx,
3838+ residual: &[i32],
3839+ fctx: &crate::decode::FrameCtx,
36263840 ) {
36273841 push_mc_rect(plane, x, y, side, side, side, prediction, residual, fctx);
36283842 }
@@ -3637,30 +3851,58 @@ fn push_mc_rect(
36373851 w: usize,
36383852 h: usize,
36393853 prediction: Pred<'_>,
3640- residual: &[i32], fctx: &crate::decode::FrameCtx,
3854+ residual: &[i32],
3855+ fctx: &crate::decode::FrameCtx,
36413856 ) {
36423857 let (src, stride) = match prediction.inline(stride) {
36433858 Some(v) => v,
36443859 None => {
3645- let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() };
3646- push_op(fctx, ReconOp::Mc {
3647- plane, x, y, stride: ss, w, h,
3648- prediction: PredSrc::Cur { plane: sp, off, src: ss },
3649- residual: Residual::done(residual, fctx),
3650- });
3860+ let Pred::Cur {
3861+ plane: sp,
3862+ stride: ss,
3863+ off,
3864+ } = prediction
3865+ else {
3866+ unreachable!()
3867+ };
3868+ push_op(
3869+ fctx,
3870+ ReconOp::Mc {
3871+ plane,
3872+ x,
3873+ y,
3874+ stride: ss,
3875+ w,
3876+ h,
3877+ prediction: PredSrc::Cur {
3878+ plane: sp,
3879+ off,
3880+ src: ss,
3881+ },
3882+ residual: Residual::done(residual, fctx),
3883+ },
3884+ );
36513885 return;
36523886 }
36533887 };
36543888 if inline_mc(plane, x, y, stride, w, h, src, residual, fctx) {
36553889 return;
36563890 }
3657- push_op(fctx, ReconOp::Mc {
3658- plane, x, y, stride, w, h,
3659- // The whole window `reconstruct_mc_rect` reads at `stride`, not
3660- // `w * h`: the record keeps exactly what `src.to_vec()` carried.
3661- prediction: PredSrc::Owned(push_pred_samples(src, fctx), src.len() as u32),
3662- residual: Residual::done(residual, fctx),
3663- });
3891+ push_op(
3892+ fctx,
3893+ ReconOp::Mc {
3894+ plane,
3895+ x,
3896+ y,
3897+ stride,
3898+ w,
3899+ h,
3900+ // The whole window `reconstruct_mc_rect` reads at `stride`, not
3901+ // `w * h`: the record keeps exactly what `src.to_vec()` carried.
3902+ prediction: PredSrc::Owned(push_pred_samples(src, fctx), src.len() as u32),
3903+ residual: Residual::done(residual, fctx),
3904+ },
3905+ );
36643906 }
36653907
36663908 /// [`push_intra_rect`] carrying the transform's INPUTS: at one reconstruction
@@ -3686,16 +3928,43 @@ fn push_intra_tx(
36863928 ) {
36873929 if fctx.recon_planes.with(std::cell::Cell::get).is_some() {
36883930 inline_intra(
3689- plane, x, y, bw, bh, rect, mode, angle_delta, reach, &tx.run(grid), cfl, filter_intra,
3690- smooth_neighbor, fctx,
3931+ plane,
3932+ x,
3933+ y,
3934+ bw,
3935+ bh,
3936+ rect,
3937+ mode,
3938+ angle_delta,
3939+ reach,
3940+ &tx.run(grid),
3941+ cfl,
3942+ filter_intra,
3943+ smooth_neighbor,
3944+ fctx,
36913945 );
36923946 return;
36933947 }
36943948 let pred = take_palette_pred(fctx);
3695- push_op(fctx, ReconOp::Intra {
3696- plane, x, y, bw, bh, rect, mode, angle_delta, reach,
3697- residual: Residual::coeffs(tx, grid, fctx), cfl, filter_intra, smooth_neighbor, pred,
3698- });
3949+ push_op(
3950+ fctx,
3951+ ReconOp::Intra {
3952+ plane,
3953+ x,
3954+ y,
3955+ bw,
3956+ bh,
3957+ rect,
3958+ mode,
3959+ angle_delta,
3960+ reach,
3961+ residual: Residual::coeffs(tx, grid, fctx),
3962+ cfl,
3963+ filter_intra,
3964+ smooth_neighbor,
3965+ pred,
3966+ },
3967+ );
36993968 }
37003969
37013970 /// [`push_mc_rect`] carrying the transform's inputs -- see [`push_intra_tx`].
@@ -3719,14 +3988,33 @@ fn push_mc_rect_tx(
37193988 let (prediction, stride) = match prediction.inline(stride) {
37203989 Some(v) => v,
37213990 None => {
3722- let Pred::Cur { plane: sp, stride: ss, off } = prediction else { unreachable!() };
3991+ let Pred::Cur {
3992+ plane: sp,
3993+ stride: ss,
3994+ off,
3995+ } = prediction
3996+ else {
3997+ unreachable!()
3998+ };
37233999 let mut tx = tx;
37244000 tx.stride = 0;
3725- push_op(fctx, ReconOp::Mc {
3726- plane, x, y, stride: w, w, h,
3727- prediction: PredSrc::Cur { plane: sp, off, src: ss },
3728- residual: Residual::coeffs(tx, grid, fctx),
3729- });
4001+ push_op(
4002+ fctx,
4003+ ReconOp::Mc {
4004+ plane,
4005+ x,
4006+ y,
4007+ stride: w,
4008+ w,
4009+ h,
4010+ prediction: PredSrc::Cur {
4011+ plane: sp,
4012+ off,
4013+ src: ss,
4014+ },
4015+ residual: Residual::coeffs(tx, grid, fctx),
4016+ },
4017+ );
37304018 return;
37314019 }
37324020 };
@@ -3768,10 +4056,19 @@ fn push_mc_rect_tx(
37684056 });
37694057 let mut tx = tx;
37704058 tx.stride = 0;
3771- push_op(fctx, ReconOp::Mc {
3772- plane, x, y, stride: w, w, h, prediction: PredSrc::Owned(off, (w * h) as u32),
3773- residual: Residual::coeffs(tx, grid, fctx),
3774- });
4059+ push_op(
4060+ fctx,
4061+ ReconOp::Mc {
4062+ plane,
4063+ x,
4064+ y,
4065+ stride: w,
4066+ w,
4067+ h,
4068+ prediction: PredSrc::Owned(off, (w * h) as u32),
4069+ residual: Residual::coeffs(tx, grid, fctx),
4070+ },
4071+ );
37754072 }
37764073
37774074 /// Replays every recorded [`ReconOp`] into the frame's planes, in push order,
@@ -3791,12 +4088,21 @@ fn flush_recon(
37914088 // lane-wave1 step (ii): a parse-time pixel READ needs every worker's
37924089 // writes in place, not just this superblock's queue.
37934090 wave_barrier(fctx);
3794- let mut ops = fctx.recon_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));
3795- fctx.recon_ops.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops));
3796- let mut coeffs = fctx.coeff_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));
3797- fctx.coeff_arena.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut coeffs));
3798- let mut preds = fctx.pred_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));
3799- fctx.pred_arena.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut preds));
4091+ let mut ops = fctx
4092+ .recon_spare
4093+ .with(|c| std::mem::take(&mut *c.borrow_mut()));
4094+ fctx.recon_ops
4095+ .with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops));
4096+ let mut coeffs = fctx
4097+ .coeff_spare
4098+ .with(|c| std::mem::take(&mut *c.borrow_mut()));
4099+ fctx.coeff_arena
4100+ .with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut coeffs));
4101+ let mut preds = fctx
4102+ .pred_spare
4103+ .with(|c| std::mem::take(&mut *c.borrow_mut()));
4104+ fctx.pred_arena
4105+ .with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut preds));
38004106 let mut cur: [Vec<u16>; 3] = Default::default();
38014107 for op in ops.drain(..) {
38024108 exec_op(op, y, u, v, &mut cur, &coeffs, &preds, fctx);
@@ -3838,24 +4144,77 @@ fn exec_op(
38384144 match op {
38394145 ReconOp::Pred(b) => (b.0)(y, u, v, fctx, cur),
38404146 ReconOp::Intra {
3841- plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl,
3842- filter_intra, smooth_neighbor, pred,
4147+ plane,
4148+ x,
4149+ y: oy,
4150+ bw,
4151+ bh,
4152+ rect,
4153+ mode,
4154+ angle_delta,
4155+ reach,
4156+ residual,
4157+ cfl,
4158+ filter_intra,
4159+ smooth_neighbor,
4160+ pred,
38434161 } => exec_intra(
3844- y, u, v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach,
4162+ y,
4163+ u,
4164+ v,
4165+ plane,
4166+ x,
4167+ oy,
4168+ bw,
4169+ bh,
4170+ rect,
4171+ mode,
4172+ angle_delta,
4173+ reach,
38454174 residual.resolve(coeffs, &mut scratch),
3846- cfl, filter_intra, smooth_neighbor, pred, fctx,
4175+ cfl,
4176+ filter_intra,
4177+ smooth_neighbor,
4178+ pred,
4179+ fctx,
38474180 ),
3848- ReconOp::Mc { plane, x, y: oy, stride, w, h, prediction, residual } => {
4181+ ReconOp::Mc {
4182+ plane,
4183+ x,
4184+ y: oy,
4185+ stride,
4186+ w,
4187+ h,
4188+ prediction,
4189+ residual,
4190+ } => {
38494191 let residual = residual.resolve(coeffs, &mut scratch);
38504192 match prediction {
38514193 PredSrc::Owned(off, len) => {
38524194 let p = &preds[off as usize..][..len as usize];
38534195 exec_mc(y, u, v, plane, x, oy, stride, w, h, p, residual, fctx);
38544196 }
3855- PredSrc::Cur { plane: sp, off, src } => {
4197+ PredSrc::Cur {
4198+ plane: sp,
4199+ off,
4200+ src,
4201+ } => {
38564202 let block = std::mem::take(&mut cur[sp]);
38574203 if src == stride {
3858- exec_mc(y, u, v, plane, x, oy, stride, w, h, &block[off..], residual, fctx);
4204+ exec_mc(
4205+ y,
4206+ u,
4207+ v,
4208+ plane,
4209+ x,
4210+ oy,
4211+ stride,
4212+ w,
4213+ h,
4214+ &block[off..],
4215+ residual,
4216+ fctx,
4217+ );
38594218 } else {
38604219 // A transform unit's residual is dense, so its window
38614220 // of the block prediction is taken out dense too --
@@ -3906,16 +4265,41 @@ fn exec_intra(
39064265 (alpha, sig)
39074266 });
39084267 let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice()));
3909- let target: &mut PlaneBuf<'static> = match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v };
4268+ let target: &mut PlaneBuf<'static> = match plane {
4269+ 0 => &mut *y,
4270+ 1 => &mut *u,
4271+ _ => &mut *v,
4272+ };
39104273 if rect {
39114274 target.reconstruct_rect(
3912- x, oy, bw, bh, mode, angle_delta, reach, residual, cfl, filter_intra,
3913- smooth_neighbor, pred, fctx,
4275+ x,
4276+ oy,
4277+ bw,
4278+ bh,
4279+ mode,
4280+ angle_delta,
4281+ reach,
4282+ residual,
4283+ cfl,
4284+ filter_intra,
4285+ smooth_neighbor,
4286+ pred,
4287+ fctx,
39144288 );
39154289 } else {
39164290 target.reconstruct(
3917- x, oy, bw, mode, angle_delta, reach, residual, cfl, filter_intra,
3918- smooth_neighbor, pred, fctx,
4291+ x,
4292+ oy,
4293+ bw,
4294+ mode,
4295+ angle_delta,
4296+ reach,
4297+ residual,
4298+ cfl,
4299+ filter_intra,
4300+ smooth_neighbor,
4301+ pred,
4302+ fctx,
39194303 );
39204304 }
39214305 }
@@ -3936,7 +4320,11 @@ fn exec_mc(
39364320 residual: &[i32],
39374321 fctx: &crate::decode::FrameCtx,
39384322 ) {
3939- let target: &mut PlaneBuf<'static> = match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v };
4323+ let target: &mut PlaneBuf<'static> = match plane {
4324+ 0 => &mut *y,
4325+ 1 => &mut *u,
4326+ _ => &mut *v,
4327+ };
39404328 target.reconstruct_mc_rect(x, oy, stride, w, h, prediction, residual, fctx);
39414329 }
39424330
@@ -3962,19 +4350,19 @@ thread_local! {
39624350 /// is never reconstructed).
39634351 static INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
39644352 }
3965- // The `tx_type` the last plane-0 [`read_plane`] actually coded, kept so
3966- // an intrabc block's chroma reads can inherit it (see
3967- // [`INTRABC_CHROMA_TX`]). Written on every luma read; only ever read
3968- // through that one arming site.
3969- // libaom `av1_get_tx_type` (`blockd.h:1350`): for `PLANE_TYPE_UV` it
3970- // branches on `is_inter_block(mbmi)` -- which `is_intrabc_block` also
3971- // satisfies (`blockd.h:373`) -- and takes the *colocated luma
3972- // transform's coded* `tx_type` (`mbmi->txk_type[...]`), never
3973- // `intra_mode_to_tx_type` of the chroma mode. `Some` only across an
3974- // intrabc block's two chroma [`read_plane`] calls; the type decides the
3975- // `TX_CLASS`, hence the scan order, `eob_multi_ctx` and every nz context
3976- // -- getting it wrong desyncs the chroma coefficients, it is not a
3977- // reconstruction-only detail.
4353+// The `tx_type` the last plane-0 [`read_plane`] actually coded, kept so
4354+// an intrabc block's chroma reads can inherit it (see
4355+// [`INTRABC_CHROMA_TX`]). Written on every luma read; only ever read
4356+// through that one arming site.
4357+// libaom `av1_get_tx_type` (`blockd.h:1350`): for `PLANE_TYPE_UV` it
4358+// branches on `is_inter_block(mbmi)` -- which `is_intrabc_block` also
4359+// satisfies (`blockd.h:373`) -- and takes the *colocated luma
4360+// transform's coded* `tx_type` (`mbmi->txk_type[...]`), never
4361+// `intra_mode_to_tx_type` of the chroma mode. `Some` only across an
4362+// intrabc block's two chroma [`read_plane`] calls; the type decides the
4363+// `TX_CLASS`, hence the scan order, `eob_multi_ctx` and every nz context
4364+// -- getting it wrong desyncs the chroma coefficients, it is not a
4365+// reconstruction-only detail.
39784366
39794367 /// Whether this frame's header set `allow_intrabc` -- [`INTRABC_MI_GRID`] is
39804368 /// `Some` exactly then (set once per frame in `decode_frame`), so the flag
@@ -4179,6 +4567,21 @@ thread_local! {
41794567 /// guard (`decode_block_128rect`). A refused block bumps
41804568 /// [`INTRABC_HITS`] but never this one.
41814569 static INTRABC_128RECT_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
4570+ /// lane-av1-ibc128chunk: chroma transform units the 128-root intrabc
4571+ /// strip's mu-chunk walk read, one per `read_inter_plane` chroma call.
4572+ /// At 4:2:0 a 64x64 mu chunk's chroma plane block is 32x32, so one
4573+ /// TX_32X32 per plane per chunk; at 4:2:2 it is 32x64 and holds TWO
4574+ /// STACKED units per plane. The square-cut `chunk_chroma = cside * 64 /
4575+ /// side` model walked the 4:2:0 count on every axis, so this counter is
4576+ /// the reach/arm witness for the per-axis walk.
4577+ static INTRABC_128RECT_CHROMA_CHUNK_HITS: std::cell::Cell<usize> =
4578+ const { std::cell::Cell::new(0) };
4579+ /// lane-av1-ibc128chunk: the mu-chunk walk's per-axis chroma extents, as
4580+ /// `(64 >> ss_x) << 8 | (64 >> ss_y)` on the LAST chunk -- the pair the
4581+ /// per-axis walk used. A 4:2:2 run and a 4:2:0 run of the same block
4582+ /// differ here (32|64 vs 32|32), which is what the de-square-cut fixes.
4583+ static INTRABC_128RECT_CHUNK_SHAPE: std::cell::Cell<usize> =
4584+ const { std::cell::Cell::new(0) };
41824585 }
41834586
41844587 /// Current value of [`INTRABC_128RECT_HITS`].
@@ -4193,6 +4596,26 @@ pub(crate) fn reset_intrabc_128rect_hits() {
41934596 INTRABC_128RECT_HITS.with(|c| c.set(0));
41944597 }
41954598
4599+/// Current value of [`INTRABC_128RECT_CHROMA_CHUNK_HITS`].
4600+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4601+pub fn intrabc_128rect_chroma_chunk_hits() -> usize {
4602+ INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.get())
4603+}
4604+
4605+/// Current value of [`INTRABC_128RECT_CHUNK_SHAPE`].
4606+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4607+pub fn intrabc_128rect_chunk_shape() -> usize {
4608+ INTRABC_128RECT_CHUNK_SHAPE.with(|c| c.get())
4609+}
4610+
4611+/// Zeroes [`INTRABC_128RECT_CHROMA_CHUNK_HITS`] and
4612+/// [`INTRABC_128RECT_CHUNK_SHAPE`].
4613+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4614+pub(crate) fn reset_intrabc_128rect_chroma_chunk_hits() {
4615+ INTRABC_128RECT_CHROMA_CHUNK_HITS.with(|c| c.set(0));
4616+ INTRABC_128RECT_CHUNK_SHAPE.with(|c| c.set(0));
4617+}
4618+
41964619 /// Current value of [`INTRABC_VARTX_HITS`].
41974620 pub fn intrabc_vartx_hits() -> usize {
41984621 INTRABC_VARTX_HITS.with(|c| c.get())
@@ -4226,7 +4649,14 @@ pub fn rect_intrabc_vartx_hits() -> usize {
42264649 /// its size (libaom's `scan_row_mbmi` advances `processed_rows` off any
42274650 /// candidate's `bsize`, ref-match or not), an intrabc one also its DV as an
42284651 /// `INTRA_FRAME` candidate (libaom treats intrabc as `is_inter_block`).
4229-fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)>, n: &mut Neighbours, fctx: &crate::decode::FrameCtx) {
4652+fn record_intrabc_mi(
4653+ mi_r: usize,
4654+ mi_c: usize,
4655+ n4: usize,
4656+ dv: Option<(i32, i32)>,
4657+ n: &mut Neighbours,
4658+ fctx: &crate::decode::FrameCtx,
4659+) {
42304660 record_intrabc_mi_rect(mi_r, mi_c, n4, n4, dv, n, fctx);
42314661 }
42324662
@@ -5461,8 +5891,8 @@ pub(crate) struct InterStripChroma {
54615891 prev: Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>,
54625892 }
54635893
5464- /// The single-reference MC parameters of the inter block that decoded
5465- /// last -- read by the next 1:4 strip to build its pair's chroma.
5894+/// The single-reference MC parameters of the inter block that decoded
5895+/// last -- read by the next 1:4 strip to build its pair's chroma.
54665896
54675897 fn bump_ab16_inter(arm: usize) {
54685898 hit_do! {
@@ -5820,7 +6250,11 @@ pub(crate) fn build_motion_field(
58206250 let i = rf.wrapping_sub(LAST_FRAME as usize);
58216251 order_hint_bits != 0
58226252 && i < 7
5823- && (crate::motion_field::get_relative_dist(order_hint_bits, ref_order_hints[i], order_hint) > 0
6253+ && (crate::motion_field::get_relative_dist(
6254+ order_hint_bits,
6255+ ref_order_hints[i],
6256+ order_hint,
6257+ ) > 0
58246258 || ref_order_hints[i] == order_hint)
58256259 });
58266260 // libaom `REFMVS_LIMIT` (`mvref_common.h`): a stored motion field mv is
@@ -5913,11 +6347,11 @@ pub(crate) fn ref_hits(ref_frame: i8) -> usize {
59136347 c.with(|v| v.get())
59146348 }
59156349
5916- /// The sequence header's `enable_intra_edge_filter`, set once per
5917- /// [`decode_key_frame_tile_with_cdfs`] call: [`PlaneBuf::reconstruct`]'s
5918- /// own read of it, kept off the call stack (see that function's own doc
5919- /// comment for why) rather than threaded through every `read_plane`/
5920- /// `decode_block`/`decode_leaf8` call between here and there.
6350+/// The sequence header's `enable_intra_edge_filter`, set once per
6351+/// [`decode_key_frame_tile_with_cdfs`] call: [`PlaneBuf::reconstruct`]'s
6352+/// own read of it, kept off the call stack (see that function's own doc
6353+/// comment for why) rather than threaded through every `read_plane`/
6354+/// `decode_block`/`decode_leaf8` call between here and there.
59216355
59226356 /// Set [`ENABLE_EDGE_FILTER`] for this thread.
59236357 ///
@@ -6496,9 +6930,7 @@ fn br_ctx(grid: &[u8], stride: usize, row: usize, col: usize, class: TxClass) ->
64966930 TxClass::Horiz => neighbour(grid, stride, row, col + 2),
64976931 TxClass::Vert => neighbour(grid, stride, row + 2, col),
64986932 };
6499- let mag = neighbour(grid, stride, row + 1, col)
6500- + neighbour(grid, stride, row, col + 1)
6501- + extra;
6933+ let mag = neighbour(grid, stride, row + 1, col) + neighbour(grid, stride, row, col + 1) + extra;
65026934 let mag = (((mag + 1) >> 1).min(6)) as usize;
65036935 if row == 0 && col == 0 {
65046936 return mag;
@@ -6517,33 +6949,33 @@ fn br_ctx(grid: &[u8], stride: usize, row: usize, col: usize, class: TxClass) ->
65176949 /// against the real table). Not the square zigzag formula generalized to
65186950 /// unequal `w`/`h` -- checked and that does NOT reproduce this table.
65196951 const SCAN_32X16: [u16; 512] = [
6520- 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161,
6521- 130, 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 256, 225, 194, 163, 132, 101, 70, 39,
6522- 8, 288, 257, 226, 195, 164, 133, 102, 71, 40, 9, 320, 289, 258, 227, 196, 165, 134, 103, 72,
6523- 41, 10, 352, 321, 290, 259, 228, 197, 166, 135, 104, 73, 42, 11, 384, 353, 322, 291, 260, 229,
6524- 198, 167, 136, 105, 74, 43, 12, 416, 385, 354, 323, 292, 261, 230, 199, 168, 137, 106, 75, 44,
6525- 13, 448, 417, 386, 355, 324, 293, 262, 231, 200, 169, 138, 107, 76, 45, 14, 480, 449, 418,
6526- 387, 356, 325, 294, 263, 232, 201, 170, 139, 108, 77, 46, 15, 481, 450, 419, 388, 357, 326,
6527- 295, 264, 233, 202, 171, 140, 109, 78, 47, 16, 482, 451, 420, 389, 358, 327, 296, 265, 234,
6528- 203, 172, 141, 110, 79, 48, 17, 483, 452, 421, 390, 359, 328, 297, 266, 235, 204, 173, 142,
6529- 111, 80, 49, 18, 484, 453, 422, 391, 360, 329, 298, 267, 236, 205, 174, 143, 112, 81, 50, 19,
6530- 485, 454, 423, 392, 361, 330, 299, 268, 237, 206, 175, 144, 113, 82, 51, 20, 486, 455, 424,
6531- 393, 362, 331, 300, 269, 238, 207, 176, 145, 114, 83, 52, 21, 487, 456, 425, 394, 363, 332,
6532- 301, 270, 239, 208, 177, 146, 115, 84, 53, 22, 488, 457, 426, 395, 364, 333, 302, 271, 240,
6533- 209, 178, 147, 116, 85, 54, 23, 489, 458, 427, 396, 365, 334, 303, 272, 241, 210, 179, 148,
6534- 117, 86, 55, 24, 490, 459, 428, 397, 366, 335, 304, 273, 242, 211, 180, 149, 118, 87, 56, 25,
6535- 491, 460, 429, 398, 367, 336, 305, 274, 243, 212, 181, 150, 119, 88, 57, 26, 492, 461, 430,
6536- 399, 368, 337, 306, 275, 244, 213, 182, 151, 120, 89, 58, 27, 493, 462, 431, 400, 369, 338,
6537- 307, 276, 245, 214, 183, 152, 121, 90, 59, 28, 494, 463, 432, 401, 370, 339, 308, 277, 246,
6538- 215, 184, 153, 122, 91, 60, 29, 495, 464, 433, 402, 371, 340, 309, 278, 247, 216, 185, 154,
6539- 123, 92, 61, 30, 496, 465, 434, 403, 372, 341, 310, 279, 248, 217, 186, 155, 124, 93, 62, 31,
6540- 497, 466, 435, 404, 373, 342, 311, 280, 249, 218, 187, 156, 125, 94, 63, 498, 467, 436, 405,
6541- 374, 343, 312, 281, 250, 219, 188, 157, 126, 95, 499, 468, 437, 406, 375, 344, 313, 282, 251,
6542- 220, 189, 158, 127, 500, 469, 438, 407, 376, 345, 314, 283, 252, 221, 190, 159, 501, 470, 439,
6543- 408, 377, 346, 315, 284, 253, 222, 191, 502, 471, 440, 409, 378, 347, 316, 285, 254, 223, 503,
6544- 472, 441, 410, 379, 348, 317, 286, 255, 504, 473, 442, 411, 380, 349, 318, 287, 505, 474, 443,
6545- 412, 381, 350, 319, 506, 475, 444, 413, 382, 351, 507, 476, 445, 414, 383, 508, 477, 446, 415,
6546- 509, 478, 447, 510, 479, 511,
6952+ 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, 130,
6953+ 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 256, 225, 194, 163, 132, 101, 70, 39, 8,
6954+ 288, 257, 226, 195, 164, 133, 102, 71, 40, 9, 320, 289, 258, 227, 196, 165, 134, 103, 72, 41,
6955+ 10, 352, 321, 290, 259, 228, 197, 166, 135, 104, 73, 42, 11, 384, 353, 322, 291, 260, 229, 198,
6956+ 167, 136, 105, 74, 43, 12, 416, 385, 354, 323, 292, 261, 230, 199, 168, 137, 106, 75, 44, 13,
6957+ 448, 417, 386, 355, 324, 293, 262, 231, 200, 169, 138, 107, 76, 45, 14, 480, 449, 418, 387,
6958+ 356, 325, 294, 263, 232, 201, 170, 139, 108, 77, 46, 15, 481, 450, 419, 388, 357, 326, 295,
6959+ 264, 233, 202, 171, 140, 109, 78, 47, 16, 482, 451, 420, 389, 358, 327, 296, 265, 234, 203,
6960+ 172, 141, 110, 79, 48, 17, 483, 452, 421, 390, 359, 328, 297, 266, 235, 204, 173, 142, 111, 80,
6961+ 49, 18, 484, 453, 422, 391, 360, 329, 298, 267, 236, 205, 174, 143, 112, 81, 50, 19, 485, 454,
6962+ 423, 392, 361, 330, 299, 268, 237, 206, 175, 144, 113, 82, 51, 20, 486, 455, 424, 393, 362,
6963+ 331, 300, 269, 238, 207, 176, 145, 114, 83, 52, 21, 487, 456, 425, 394, 363, 332, 301, 270,
6964+ 239, 208, 177, 146, 115, 84, 53, 22, 488, 457, 426, 395, 364, 333, 302, 271, 240, 209, 178,
6965+ 147, 116, 85, 54, 23, 489, 458, 427, 396, 365, 334, 303, 272, 241, 210, 179, 148, 117, 86, 55,
6966+ 24, 490, 459, 428, 397, 366, 335, 304, 273, 242, 211, 180, 149, 118, 87, 56, 25, 491, 460, 429,
6967+ 398, 367, 336, 305, 274, 243, 212, 181, 150, 119, 88, 57, 26, 492, 461, 430, 399, 368, 337,
6968+ 306, 275, 244, 213, 182, 151, 120, 89, 58, 27, 493, 462, 431, 400, 369, 338, 307, 276, 245,
6969+ 214, 183, 152, 121, 90, 59, 28, 494, 463, 432, 401, 370, 339, 308, 277, 246, 215, 184, 153,
6970+ 122, 91, 60, 29, 495, 464, 433, 402, 371, 340, 309, 278, 247, 216, 185, 154, 123, 92, 61, 30,
6971+ 496, 465, 434, 403, 372, 341, 310, 279, 248, 217, 186, 155, 124, 93, 62, 31, 497, 466, 435,
6972+ 404, 373, 342, 311, 280, 249, 218, 187, 156, 125, 94, 63, 498, 467, 436, 405, 374, 343, 312,
6973+ 281, 250, 219, 188, 157, 126, 95, 499, 468, 437, 406, 375, 344, 313, 282, 251, 220, 189, 158,
6974+ 127, 500, 469, 438, 407, 376, 345, 314, 283, 252, 221, 190, 159, 501, 470, 439, 408, 377, 346,
6975+ 315, 284, 253, 222, 191, 502, 471, 440, 409, 378, 347, 316, 285, 254, 223, 503, 472, 441, 410,
6976+ 379, 348, 317, 286, 255, 504, 473, 442, 411, 380, 349, 318, 287, 505, 474, 443, 412, 381, 350,
6977+ 319, 506, 475, 444, 413, 382, 351, 507, 476, 445, 414, 383, 508, 477, 446, 415, 509, 478, 447,
6978+ 510, 479, 511,
65476979 ];
65486980
65496981 /// `Default_Scan_16x32`, this decoder's own row-major transcription (see
@@ -6623,18 +7055,18 @@ const SCAN_8X16: [u16; 128] = [
66237055 /// are byte-identical to this decoder's [`SCAN_8X16`].
66247056 const SCAN_32X8: [u16; 256] = [
66257057 0, 32, 1, 64, 33, 2, 96, 65, 34, 3, 128, 97, 66, 35, 4, 160, 129, 98, 67, 36, 5, 192, 161, 130,
6626- 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 225, 194, 163, 132, 101, 70, 39, 8, 226, 195,
6627- 164, 133, 102, 71, 40, 9, 227, 196, 165, 134, 103, 72, 41, 10, 228, 197, 166, 135, 104, 73, 42,
6628- 11, 229, 198, 167, 136, 105, 74, 43, 12, 230, 199, 168, 137, 106, 75, 44, 13, 231, 200, 169,
6629- 138, 107, 76, 45, 14, 232, 201, 170, 139, 108, 77, 46, 15, 233, 202, 171, 140, 109, 78, 47, 16,
6630- 234, 203, 172, 141, 110, 79, 48, 17, 235, 204, 173, 142, 111, 80, 49, 18, 236, 205, 174, 143,
6631- 112, 81, 50, 19, 237, 206, 175, 144, 113, 82, 51, 20, 238, 207, 176, 145, 114, 83, 52, 21, 239,
6632- 208, 177, 146, 115, 84, 53, 22, 240, 209, 178, 147, 116, 85, 54, 23, 241, 210, 179, 148, 117,
6633- 86, 55, 24, 242, 211, 180, 149, 118, 87, 56, 25, 243, 212, 181, 150, 119, 88, 57, 26, 244, 213,
6634- 182, 151, 120, 89, 58, 27, 245, 214, 183, 152, 121, 90, 59, 28, 246, 215, 184, 153, 122, 91,
6635- 60, 29, 247, 216, 185, 154, 123, 92, 61, 30, 248, 217, 186, 155, 124, 93, 62, 31, 249, 218, 187,
6636- 156, 125, 94, 63, 250, 219, 188, 157, 126, 95, 251, 220, 189, 158, 127, 252, 221, 190, 159, 253,
6637- 222, 191, 254, 223, 255,
7058+ 99, 68, 37, 6, 224, 193, 162, 131, 100, 69, 38, 7, 225, 194, 163, 132, 101, 70, 39, 8, 226,
7059+ 195, 164, 133, 102, 71, 40, 9, 227, 196, 165, 134, 103, 72, 41, 10, 228, 197, 166, 135, 104,
7060+ 73, 42, 11, 229, 198, 167, 136, 105, 74, 43, 12, 230, 199, 168, 137, 106, 75, 44, 13, 231, 200,
7061+ 169, 138, 107, 76, 45, 14, 232, 201, 170, 139, 108, 77, 46, 15, 233, 202, 171, 140, 109, 78,
7062+ 47, 16, 234, 203, 172, 141, 110, 79, 48, 17, 235, 204, 173, 142, 111, 80, 49, 18, 236, 205,
7063+ 174, 143, 112, 81, 50, 19, 237, 206, 175, 144, 113, 82, 51, 20, 238, 207, 176, 145, 114, 83,
7064+ 52, 21, 239, 208, 177, 146, 115, 84, 53, 22, 240, 209, 178, 147, 116, 85, 54, 23, 241, 210,
7065+ 179, 148, 117, 86, 55, 24, 242, 211, 180, 149, 118, 87, 56, 25, 243, 212, 181, 150, 119, 88,
7066+ 57, 26, 244, 213, 182, 151, 120, 89, 58, 27, 245, 214, 183, 152, 121, 90, 59, 28, 246, 215,
7067+ 184, 153, 122, 91, 60, 29, 247, 216, 185, 154, 123, 92, 61, 30, 248, 217, 186, 155, 124, 93,
7068+ 62, 31, 249, 218, 187, 156, 125, 94, 63, 250, 219, 188, 157, 126, 95, 251, 220, 189, 158, 127,
7069+ 252, 221, 190, 159, 253, 222, 191, 254, 223, 255,
66387070 ];
66397071 /// `Default_Scan_8x32`, [`SCAN_32X8`]'s transpose (the chroma plane of a
66407072 /// 16x64 `PARTITION_VERT_4` strip).
@@ -6737,13 +7169,7 @@ fn base_ctx_rect(
67377169 /// its body was character-for-character [`br_ctx`]'s, which
67387170 /// `flat_taps_match_the_row_col_neighbour_reads` now asserts.
67397171 #[cfg(test)]
6740-fn br_ctx_rect(
6741- grid: &[u8],
6742- stride: usize,
6743- row: usize,
6744- col: usize,
6745- class: TxClass,
6746-) -> usize {
7172+fn br_ctx_rect(grid: &[u8], stride: usize, row: usize, col: usize, class: TxClass) -> usize {
67477173 let extra = match class {
67487174 TxClass::TwoD => neighbour_rect(grid, stride, row + 1, col + 1),
67497175 TxClass::Horiz => neighbour_rect(grid, stride, row, col + 2),
@@ -6933,7 +7359,9 @@ fn is_smooth_mode(mode: usize) -> bool {
69337359 #[cold]
69347360 #[inline(never)]
69357361 fn trace_base_eob(scan_idx: usize, pos: usize, row: usize, col: usize, ctx: usize, v: i32) {
6936- eprintln!("TRACE base_eob scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={v}");
7362+ eprintln!(
7363+ "TRACE base_eob scan_idx={scan_idx} pos={pos} row={row} col={col} ctx={ctx} value={v}"
7364+ );
69377365 }
69387366
69397367 #[cold]
@@ -6966,7 +7394,10 @@ fn coeff_step_br(dec: &SymbolDecoder, scan_idx: usize, apos: usize, ctx: usize,
69667394 #[inline(never)]
69677395 fn coeff_step_sign(dec: &SymbolDecoder, c: usize, negative: bool) {
69687396 let (rng, _) = dec.debug_state();
6969- eprintln!("EC_COEFF_STEP tag=sign c={c} sign={} rng={rng}", negative as i32);
7397+ eprintln!(
7398+ "EC_COEFF_STEP tag=sign c={c} sign={} rng={rng}",
7399+ negative as i32
7400+ );
69707401 }
69717402
69727403 #[cold]
@@ -7026,14 +7457,15 @@ fn read_coeffs(
70267457 let (rng, _) = dec.debug_state();
70277458 eprintln!(
70287459 "EC_COEFF_STEP tag=all_zero side={} ctx={skip_ctx} dcctx={sign_ctx} cdf={dbg_txbskip:?} all_zero={} rng={rng}",
7029- coding.side,
7030- all_zero as i32
7460+ coding.side, all_zero as i32
70317461 );
70327462 }
70337463 if crate::envflags::env_flag!("EC_AV1_TELL") {
70347464 eprintln!(
70357465 "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}",
7036- all_zero as u8, dec.debug_bitpos(), dec.debug_state().0
7466+ all_zero as u8,
7467+ dec.debug_bitpos(),
7468+ dec.debug_state().0
70377469 );
70387470 }
70397471 if trace {
@@ -7076,8 +7508,9 @@ fn read_coeffs(
70767508 if trace {
70777509 eprintln!("TRACE tx_type value={t} len={len}");
70787510 }
7079- tx_type = tx_type_from_symbol(len, t)
7080- .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;
7511+ tx_type = tx_type_from_symbol(len, t).ok_or_else(|| {
7512+ unsupported(format!("a tx_type symbol outside its CDF's own set: {t}"))
7513+ })?;
70817514 }
70827515
70837516 let class = TxClass::of(tx_type);
@@ -7092,7 +7525,11 @@ fn read_coeffs(
70927525 let ec_trace_coeff = coeff_trace_on();
70937526 if ec_trace_coeff {
70947527 let (rng, _) = dec.debug_state();
7095- let cls = match class { TxClass::TwoD => "2d", TxClass::Horiz => "horiz", TxClass::Vert => "vert" };
7528+ let cls = match class {
7529+ TxClass::TwoD => "2d",
7530+ TxClass::Horiz => "horiz",
7531+ TxClass::Vert => "vert",
7532+ };
70967533 eprintln!("EC_COEFF_STEP tag=eob eob={eob} tx={tx_type:?} class={cls} rng={rng}");
70977534 }
70987535 let class_scan;
@@ -7297,10 +7734,14 @@ fn read_coeffs_rect(
72977734 let len = tx_type_cdf.len();
72987735 let t = dec.symbol(tx_type_cdf);
72997736 crate::census::tx_type(len, t);
7300- tx_type = tx_type_from_symbol(len, t)
7301- .ok_or_else(|| unsupported(format!("a tx_type symbol outside its CDF's own set: {t}")))?;
7737+ tx_type = tx_type_from_symbol(len, t).ok_or_else(|| {
7738+ unsupported(format!("a tx_type symbol outside its CDF's own set: {t}"))
7739+ })?;
73027740 if rect_trace {
7303- eprintln!("EC_COEFF_STEP tag=tx_type plane=0 rng={}", dec.debug_state().0);
7741+ eprintln!(
7742+ "EC_COEFF_STEP tag=tx_type plane=0 rng={}",
7743+ dec.debug_state().0
7744+ );
73047745 }
73057746 }
73067747 let class = TxClass::of(tx_type);
@@ -7309,7 +7750,10 @@ fn read_coeffs_rect(
73097750 }
73107751 let eob = read_eob(dec, coding, class);
73117752 if rect_trace {
7312- eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={}", dec.debug_state().0);
7753+ eprintln!(
7754+ "EC_COEFF_STEP tag=eob eob={eob} rng={}",
7755+ dec.debug_state().0
7756+ );
73137757 }
73147758 let class_scan;
73157759 let scan: &[u16] = if class == TxClass::TwoD {
@@ -7449,7 +7893,10 @@ fn read_coeffs_rect(
74497893 };
74507894 if rect_trace {
74517895 let (rng, _) = dec.debug_state();
7452- eprintln!("EC_COEFF_STEP tag=sign_rect pos={pos} sign={} dcctx={sign_ctx} rng={rng}", u8::from(negative));
7896+ eprintln!(
7897+ "EC_COEFF_STEP tag=sign_rect pos={pos} sign={} dcctx={sign_ctx} rng={rng}",
7898+ u8::from(negative)
7899+ );
74537900 }
74547901 let level = if level > MAX_BR_LEVEL {
74557902 let g = read_golomb(dec)?;
@@ -7470,7 +7917,10 @@ fn read_coeffs_rect(
74707917 .filter(|&(_, &v)| v != 0)
74717918 .map(|(i, &v)| format!("{}/{}:{v}", i / w, i % w))
74727919 .collect();
7473- eprintln!("OUR_LEVELS w={w} h={h} eob={eob} tx={tx_type:?} nz={}", nz.join(","));
7920+ eprintln!(
7921+ "OUR_LEVELS w={w} h={h} eob={eob} tx={tx_type:?} nz={}",
7922+ nz.join(",")
7923+ );
74747924 }
74757925 Ok((Grid::Own(grid), tx_type))
74767926 }
@@ -7813,7 +8263,13 @@ struct Neighbours {
78138263 impl Neighbours {
78148264 /// `cols`/`rows` are in [`SUB`] units; `mi_cols`/`mi_rows` are the frame's
78158265 /// true (unpadded) size in 4x4 mode-info units.
7816- fn new(cols: usize, rows: usize, mi_cols: usize, mi_rows: usize, fctx: &crate::decode::FrameCtx) -> Self {
8266+ fn new(
8267+ cols: usize,
8268+ rows: usize,
8269+ mi_cols: usize,
8270+ mi_rows: usize,
8271+ fctx: &crate::decode::FrameCtx,
8272+ ) -> Self {
78178273 // lane-sb128c r7: a 128x64 block at the bottom frame edge records its
78188274 // neighbour state over the whole 64-row extent, past the frame's last
78198275 // mi row (mi_rows 198, block rows 192..208). libaom's own context
@@ -7822,10 +8278,7 @@ impl Neighbours {
78228278 // side arrays to a superblock multiple and leave those cells unread --
78238279 // every availability check uses the true `mi_rows`/`mi_cols` below.
78248280 let sb_sub = (sb_mi_cur(fctx) as usize) / (SUB / MI);
7825- let (cols, rows) = (
7826- cols.next_multiple_of(sb_sub),
7827- rows.next_multiple_of(sb_sub),
7828- );
8281+ let (cols, rows) = (cols.next_multiple_of(sb_sub), rows.next_multiple_of(sb_sub));
78298282 Self {
78308283 above: vec![[Neighbour::default(); 3]; cols * (SUB / MI)],
78318284 left: vec![[Neighbour::default(); 3]; rows * (SUB / MI)],
@@ -7868,7 +8321,12 @@ impl Neighbours {
78688321 mi_cols,
78698322 mi_rows,
78708323 blk_grid: vec![
7871- BlkCell { skip: false, written: false, org: [0; 2], dim: [1; 2] };
8324+ BlkCell {
8325+ skip: false,
8326+ written: false,
8327+ org: [0; 2],
8328+ dim: [1; 2]
8329+ };
78728330 cols * (SUB / MI) * rows * (SUB / MI)
78738331 ],
78748332 skip_grid_cols_mi: cols * (SUB / MI),
@@ -7897,7 +8355,13 @@ impl Neighbours {
78978355 /// availability check below. Left context resets every superblock row
78988356 /// regardless of tile ([`Self::start_row`], already called once per SB
78998357 /// row by every caller) so it needs no tile-specific reset here.
7900- fn start_tile(&mut self, row0_mi: usize, col0_mi: usize, col1_mi: usize, fctx: &crate::decode::FrameCtx) {
8358+ fn start_tile(
8359+ &mut self,
8360+ row0_mi: usize,
8361+ col0_mi: usize,
8362+ col1_mi: usize,
8363+ fctx: &crate::decode::FrameCtx,
8364+ ) {
79018365 // lane-seg: `AvailU`/`AvailL` for the segment-id neighbour prediction
79028366 // are tile-relative, same as every other neighbour lookup here.
79038367 fctx.seg_tile_origin.with(|c| c.set((row0_mi, col0_mi)));
@@ -7953,7 +8417,13 @@ impl Neighbours {
79538417 /// mirrors [`Self::record_rect`]'s loop shape, square-only (this lane's
79548418 /// call sites are all square blocks).
79558419 fn record_palette_y(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) {
7956- self.record_palette_y_rect((at.0 * (SUB / MI), at.1 * (SUB / MI)), side, side, size, colors);
8420+ self.record_palette_y_rect(
8421+ (at.0 * (SUB / MI), at.1 * (SUB / MI)),
8422+ side,
8423+ side,
8424+ size,
8425+ colors,
8426+ );
79578427 }
79588428
79598429 /// [`Self::record_palette_y`] with independent above (`w`)/left (`h`)
@@ -8029,7 +8499,10 @@ impl Neighbours {
80298499 // `xd->above_mbmi` exists for every row but the tile's own first.
80308500 let above_is_palette = r > self.tile_row0_mi && self.above_palette_size[c] > 0;
80318501 let (above_n, above_colors) = if above_ok && self.above_palette_size[c] > 0 {
8032- (usize::from(self.above_palette_size[c]), self.above_palette_colors[c])
8502+ (
8503+ usize::from(self.above_palette_size[c]),
8504+ self.above_palette_colors[c],
8505+ )
80338506 } else {
80348507 (0, [0u16; 8])
80358508 };
@@ -8040,7 +8513,10 @@ impl Neighbours {
80408513 // and its `palette_y_mode` ctx.
80418514 let left_ok = c > self.tile_col0_mi;
80428515 let (left_n, left_colors) = if left_ok && self.left_palette_size[r] > 0 {
8043- (usize::from(self.left_palette_size[r]), self.left_palette_colors[r])
8516+ (
8517+ usize::from(self.left_palette_size[r]),
8518+ self.left_palette_colors[r],
8519+ )
80448520 } else {
80458521 (0, [0u16; 8])
80468522 };
@@ -8079,7 +8555,13 @@ impl Neighbours {
80798555 /// As [`Self::record_palette_y`], for a just-decoded block's own chroma
80808556 /// (U-channel) palette size/colours -- `size == 0` clears stale state the
80818557 /// same way (lane-palette2 r1).
8082- fn record_palette_uv(&mut self, at: (usize, usize), side: usize, size: usize, colors: [u16; 8]) {
8558+ fn record_palette_uv(
8559+ &mut self,
8560+ at: (usize, usize),
8561+ side: usize,
8562+ size: usize,
8563+ colors: [u16; 8],
8564+ ) {
80838565 self.record_palette_uv_rect(
80848566 (at.0 * (SUB / MI), at.1 * (SUB / MI)),
80858567 side,
@@ -8136,14 +8618,20 @@ impl Neighbours {
81368618 let (r, c) = mi;
81378619 let above_ok = r % 16 != 0;
81388620 let (above_n, above_colors) = if above_ok && self.above_palette_uv_size[c] > 0 {
8139- (usize::from(self.above_palette_uv_size[c]), self.above_palette_uv_colors[c])
8621+ (
8622+ usize::from(self.above_palette_uv_size[c]),
8623+ self.above_palette_uv_colors[c],
8624+ )
81408625 } else {
81418626 (0, [0u16; 8])
81428627 };
81438628 // Same tile-relative left availability as the luma cache above.
81448629 let left_ok = c > self.tile_col0_mi;
81458630 let (left_n, left_colors) = if left_ok && self.left_palette_uv_size[r] > 0 {
8146- (usize::from(self.left_palette_uv_size[r]), self.left_palette_uv_colors[r])
8631+ (
8632+ usize::from(self.left_palette_uv_size[r]),
8633+ self.left_palette_uv_colors[r],
8634+ )
81478635 } else {
81488636 (0, [0u16; 8])
81498637 };
@@ -8182,7 +8670,14 @@ impl Neighbours {
81828670 /// transform width (in pixels) and `is_inter` flag -- the loop filter's
81838671 /// per-edge lookup (`apply_deblock`), filled at the same call sites and
81848672 /// units as [`Self::fill_skip_grid`].
8185- fn fill_lf_grid(&mut self, at_mi: (usize, usize), side_mi: usize, tx_px: u8, ref_frame: i8, fctx: &crate::decode::FrameCtx) {
8673+ fn fill_lf_grid(
8674+ &mut self,
8675+ at_mi: (usize, usize),
8676+ side_mi: usize,
8677+ tx_px: u8,
8678+ ref_frame: i8,
8679+ fctx: &crate::decode::FrameCtx,
8680+ ) {
81868681 self.fill_lf_grid_rect(at_mi, side_mi, side_mi, tx_px, tx_px, ref_frame, fctx);
81878682 }
81888683
@@ -8218,7 +8713,8 @@ impl Neighbours {
82188713 h_mi: usize,
82198714 tx_px: u8,
82208715 tx_h_px: u8,
8221- ref_frame: i8, fctx: &crate::decode::FrameCtx,
8716+ ref_frame: i8,
8717+ fctx: &crate::decode::FrameCtx,
82228718 ) {
82238719 let (mi_r, mi_c) = at_mi;
82248720 // `av1_get_max_uv_txsize` under 4:2:0: the block's chroma extent is
@@ -8227,7 +8723,9 @@ impl Neighbours {
82278723 let uv_tx_w = (((w_mi * MI) >> ss_x(fctx)).max(4).min(32)) as u8;
82288724 let uv_tx_h = (((h_mi * MI) >> ss_y(fctx)).max(4).min(32)) as u8;
82298725 if crate::envflags::env_flag!("EC_TXGRID_TRACE") {
8230- eprintln!("EC_LFGRID mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}");
8726+ eprintln!(
8727+ "EC_LFGRID mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}"
8728+ );
82318729 }
82328730 crate::census::tx(tx_px, tx_h_px);
82338731 let cur = fctx.current_delta_lf.with(|c| c.get());
@@ -8313,7 +8811,9 @@ impl Neighbours {
83138811 ) {
83148812 let (mi_r, mi_c) = at_mi;
83158813 if crate::envflags::env_flag!("EC_TXGRID_TRACE") {
8316- eprintln!("EC_LFLEAF mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}");
8814+ eprintln!(
8815+ "EC_LFLEAF mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}"
8816+ );
83178817 }
83188818 for rr in 0..h_mi {
83198819 let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;
@@ -8394,8 +8894,12 @@ impl Neighbours {
83948894 self.left.iter_mut().for_each(|l| *l = Default::default());
83958895 self.left_mode.iter_mut().for_each(|m| *m = DC_PRED);
83968896 self.left_uv_mode.iter_mut().for_each(|m| *m = DC_PRED);
8397- self.left_side.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE);
8398- self.left_side_mi.iter_mut().for_each(|s| *s = NO_NEIGHBOUR_SIDE as u8);
8897+ self.left_side
8898+ .iter_mut()
8899+ .for_each(|s| *s = NO_NEIGHBOUR_SIDE);
8900+ self.left_side_mi
8901+ .iter_mut()
8902+ .for_each(|s| *s = NO_NEIGHBOUR_SIDE as u8);
83998903 self.left_skip.iter_mut().for_each(|s| *s = false);
84008904 self.left_skip_mode.iter_mut().for_each(|s| *s = false);
84018905 self.left_inter.iter_mut().for_each(|i| *i = false);
@@ -8406,16 +8910,22 @@ impl Neighbours {
84068910 self.left_filter.iter_mut().for_each(|f| *f = [3u8; 2]);
84078911 // lane-sub8 r6: mi-granular row maps reset with the rest of the left
84088912 // context (a tile/SB-row boundary has no left neighbour).
8409- self.sub8_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0));
8913+ self.sub8_mode_row
8914+ .iter_mut()
8915+ .for_each(|s| *s = (u16::MAX, 0));
84108916 self.uv_mode_row.iter_mut().for_each(|s| *s = (u16::MAX, 0));
84118917 // lane-tiles r11 (COMMON's NEIGHBOUR MAPS rule): the palette side bands
84128918 // are per-mi maps like every other one here, so they reset with the
84138919 // row too -- the left guard above is what actually stops a cross-tile
84148920 // read, this keeps a stale colour out of the arrays at all.
84158921 self.left_palette_size.iter_mut().for_each(|s| *s = 0);
8416- self.left_palette_colors.iter_mut().for_each(|c| *c = [0u16; 8]);
8922+ self.left_palette_colors
8923+ .iter_mut()
8924+ .for_each(|c| *c = [0u16; 8]);
84178925 self.left_palette_uv_size.iter_mut().for_each(|s| *s = 0);
8418- self.left_palette_uv_colors.iter_mut().for_each(|c| *c = [0u16; 8]);
8926+ self.left_palette_uv_colors
8927+ .iter_mut()
8928+ .for_each(|c| *c = [0u16; 8]);
84198929 // lane-mergefix r2: `av1_zero_left_context` memsets
84208930 // `left_txfm_context_buffer` to `tx_size_high[TX_SIZES_LARGEST]` at
84218931 // every superblock row of every tile -- the var-tx left context does
@@ -8662,7 +9172,7 @@ impl Neighbours {
86629172 o.2 += dc_vote(left[plane].dc);
86639173 }
86649174 }
8665- out
9175+ out
86669176 }
86679177
86689178 /// [`Self::around_mi_rect`] for the CHROMA planes of a 4:2:2 frame
@@ -8710,12 +9220,28 @@ impl Neighbours {
87109220 let vote = o.2;
87119221 let ab: Vec<String> = (0..above_mi)
87129222 .step_by(2)
8713- .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))
9223+ .map(|k| {
9224+ format!(
9225+ "{:?}/{}",
9226+ self.above[mi_c + k][plane].dc,
9227+ self.above[mi_c + k][plane].level
9228+ )
9229+ })
87149230 .collect();
87159231 let lf: Vec<String> = (0..left_mi)
8716- .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level))
9232+ .map(|k| {
9233+ format!(
9234+ "{:?}/{}",
9235+ self.left[mi_r + k][plane].dc,
9236+ self.left[mi_r + k][plane].level
9237+ )
9238+ })
87179239 .collect();
8718- eprintln!("EC_DCDUMP422 mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(","));
9240+ eprintln!(
9241+ "EC_DCDUMP422 mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]",
9242+ ab.join(","),
9243+ lf.join(",")
9244+ );
87199245 }
87209246 }
87219247 out
@@ -8730,7 +9256,12 @@ impl Neighbours {
87309256
87319257 /// [`Self::around_rect`] taking the block's position directly in 4x4
87329258 /// mode-info units, mirroring [`Self::around_mi`].
8733- fn around_mi_rect(&self, (mi_r, mi_c): (usize, usize), w: usize, h: usize) -> [(bool, bool, i32); 3] {
9259+ fn around_mi_rect(
9260+ &self,
9261+ (mi_r, mi_c): (usize, usize),
9262+ w: usize,
9263+ h: usize,
9264+ ) -> [(bool, bool, i32); 3] {
87349265 let (w_mi, h_mi) = (w / MI, h / MI);
87359266 let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c));
87369267 let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r));
@@ -8754,12 +9285,28 @@ impl Neighbours {
87549285 for (plane, o) in out.iter().enumerate() {
87559286 let vote = o.2;
87569287 let ab: Vec<String> = (0..above_mi)
8757- .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))
9288+ .map(|k| {
9289+ format!(
9290+ "{:?}/{}",
9291+ self.above[mi_c + k][plane].dc,
9292+ self.above[mi_c + k][plane].level
9293+ )
9294+ })
87589295 .collect();
87599296 let lf: Vec<String> = (0..left_mi)
8760- .map(|k| format!("{:?}/{}", self.left[mi_r + k][plane].dc, self.left[mi_r + k][plane].level))
9297+ .map(|k| {
9298+ format!(
9299+ "{:?}/{}",
9300+ self.left[mi_r + k][plane].dc,
9301+ self.left[mi_r + k][plane].level
9302+ )
9303+ })
87619304 .collect();
8762- eprintln!("EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]", ab.join(","), lf.join(","));
9305+ eprintln!(
9306+ "EC_DCDUMP mi=({mi_r},{mi_c}) plane={plane} wh=({w},{h}) vote={vote} above=[{}] left=[{}]",
9307+ ab.join(","),
9308+ lf.join(",")
9309+ );
87639310 }
87649311 }
87659312 out
@@ -8779,12 +9326,7 @@ impl Neighbours {
87799326 /// [`Self::luma_skip_ctx`] with the unit's own width and height in mi
87809327 /// units (lane-rectsplitx r1) -- `get_txb_ctx_general` ORs the above
87819328 /// context over `tx_size_wide` and the left one over `tx_size_high`.
8782- fn luma_skip_ctx_rect(
8783- &self,
8784- (mi_r, mi_c): (usize, usize),
8785- w_mi: usize,
8786- h_mi: usize,
8787- ) -> usize {
9329+ fn luma_skip_ctx_rect(&self, (mi_r, mi_c): (usize, usize), w_mi: usize, h_mi: usize) -> usize {
87889330 let side_mi = w_mi;
87899331 let above_mi = w_mi.min(self.mi_cols.saturating_sub(mi_c));
87909332 let left_mi = h_mi.min(self.mi_rows.saturating_sub(mi_r));
@@ -8798,10 +9340,12 @@ impl Neighbours {
87989340 }
87999341 let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)];
88009342 if crate::envflags::env_flag!("EC_ECDUMP") {
8801- let ab: Vec<String> =
8802- (0..above_mi).map(|k| self.above[mi_c + k][0].level.to_string()).collect();
8803- let lf: Vec<String> =
8804- (0..left_mi).map(|k| self.left[mi_r + k][0].level.to_string()).collect();
9343+ let ab: Vec<String> = (0..above_mi)
9344+ .map(|k| self.above[mi_c + k][0].level.to_string())
9345+ .collect();
9346+ let lf: Vec<String> = (0..left_mi)
9347+ .map(|k| self.left[mi_r + k][0].level.to_string())
9348+ .collect();
88059349 // lane-av1mix: the last few msac register states, so the
88069350 // byte-position of the `all_zero` read can be matched against
88079351 // aomdec's `EC=(value,rng,bytepos)` dump (decodetxb.c) without a
@@ -8813,7 +9357,9 @@ impl Neighbours {
88139357 .join(" ");
88149358 eprintln!(
88159359 "EC_ECDUMP plane=0 mi=({mi_r},{mi_c}) wh=({w_mi},{h_mi}) ctx={ctx} above=[{},] left=[{},] recentEC=[{}]",
8816- ab.join(","), lf.join(","), recent
9360+ ab.join(","),
9361+ lf.join(","),
9362+ recent
88179363 );
88189364 }
88199365 if crate::envflags::env_flag!("EC_AV1_TRACE") {
@@ -8856,14 +9402,7 @@ impl Neighbours {
88569402 /// block to the right reads via `mi(row, col-1)`). Only sub-8x8 leaves
88579403 /// read these back, and only when the recorded position is exactly their
88589404 /// own neighbour -- see [`Self::sub8_mode_col`]'s doc.
8859- fn record_mode_mi(
8860- &mut self,
8861- mi_r: usize,
8862- mi_c: usize,
8863- mi_w: usize,
8864- mi_h: usize,
8865- mode: usize,
8866- ) {
9405+ fn record_mode_mi(&mut self, mi_r: usize, mi_c: usize, mi_w: usize, mi_h: usize, mode: usize) {
88679406 let (last_r, last_c) = ((mi_r + mi_h - 1) as u16, (mi_c + mi_w - 1) as u16);
88689407 let mode = mode as u8;
88699408 for cell in 0..mi_w {
@@ -8884,14 +9423,18 @@ impl Neighbours {
88849423 /// construction). See [`Self::record_mode_mi`].
88859424 fn mode_above_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
88869425 match self.sub8_mode_col.get(mi_c) {
8887- Some(&(row, m)) if mi_r > self.tile_row0_mi && usize::from(row) == mi_r - 1 => Some(usize::from(m)),
9426+ Some(&(row, m)) if mi_r > self.tile_row0_mi && usize::from(row) == mi_r - 1 => {
9427+ Some(usize::from(m))
9428+ }
88889429 _ => None,
88899430 }
88909431 }
88919432
88929433 fn mode_left_mi(&self, mi_r: usize, mi_c: usize) -> Option<usize> {
88939434 match self.sub8_mode_row.get(mi_r) {
8894- Some(&(col, m)) if mi_c > self.tile_col0_mi && usize::from(col) == mi_c - 1 => Some(usize::from(m)),
9435+ Some(&(col, m)) if mi_c > self.tile_col0_mi && usize::from(col) == mi_c - 1 => {
9436+ Some(usize::from(m))
9437+ }
88959438 _ => None,
88969439 }
88979440 }
@@ -8907,14 +9450,29 @@ impl Neighbours {
89079450 uv_mode: usize,
89089451 ) {
89099452 let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1);
8910- fill_span(&mut self.uv_mode_col, mi_c, mi_w, (last_r as u16, uv_mode as u8));
8911- fill_span(&mut self.uv_mode_row, mi_r, mi_h, (last_c as u16, uv_mode as u8));
9453+ fill_span(
9454+ &mut self.uv_mode_col,
9455+ mi_c,
9456+ mi_w,
9457+ (last_r as u16, uv_mode as u8),
9458+ );
9459+ fill_span(
9460+ &mut self.uv_mode_row,
9461+ mi_r,
9462+ mi_h,
9463+ (last_c as u16, uv_mode as u8),
9464+ );
89129465 // libaom writes one `MB_MODE_INFO` pointer into every mi cell a block
89139466 // covers, so the chroma neighbour read below is a plain grid read.
89149467 let stride = self.uv_grid_cols;
89159468 let n = stride.saturating_sub(mi_c).min(last_c + 1 - mi_c);
89169469 for row in mi_r..=last_r {
8917- fill_span(&mut self.uv_mode_grid, row * stride + mi_c, n, uv_mode as u8);
9470+ fill_span(
9471+ &mut self.uv_mode_grid,
9472+ row * stride + mi_c,
9473+ n,
9474+ uv_mode as u8,
9475+ );
89189476 }
89199477 }
89209478
@@ -8961,13 +9519,7 @@ impl Neighbours {
89619519 /// counter wants this: it measures how often the snap CHANGES the answer,
89629520 /// which is what the lane-kf1200/kf900 chroma-reference fix buys. Every
89639521 /// decode path uses the snapping form.
8964- fn smooth_uv_neighbour_unsnapped(
8965- &self,
8966- mi_r: usize,
8967- mi_c: usize,
8968- r: usize,
8969- c: usize,
8970- ) -> bool {
9522+ fn smooth_uv_neighbour_unsnapped(&self, mi_r: usize, mi_c: usize, r: usize, c: usize) -> bool {
89719523 // lane-mtfix r1: availability is TILE-relative on BOTH axes and on the
89729524 // coarse fallback too. `above_uv_mode` is a frame-wide [`SUB`]-grid
89739525 // array that `start_tile` does not clear, so a block on a tile's first
@@ -9152,18 +9704,15 @@ impl Neighbours {
91529704
91539705 /// [`Self::record_mi`] with independent above (`w`)/left (`h`) extents,
91549706 /// in pixels (lane-partitions r1, mirroring [`Self::record_rect`]).
9155- fn record_mi_rect(
9156- &mut self,
9157- at_mi: (usize, usize),
9158- w: usize,
9159- h: usize,
9160- grids: &[&[i32]; 3],
9161- ) {
9707+ fn record_mi_rect(&mut self, at_mi: (usize, usize), w: usize, h: usize, grids: &[&[i32]; 3]) {
91629708 let (mi_r, mi_c) = at_mi;
91639709 let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(grids[plane]));
91649710 let (w_mi, h_mi) = (w / MI, h / MI);
91659711 if crate::envflags::env_flag!("EC_ECPUB") {
9166- eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level);
9712+ eprintln!(
9713+ "EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}",
9714+ states[0].level
9715+ );
91679716 }
91689717 fill_span(&mut self.left_side_mi, mi_r, h_mi, h as u8);
91699718 fill_span(&mut self.above_side_mi, mi_c, w_mi, w as u8);
@@ -9271,7 +9820,10 @@ impl Neighbours {
92719820 ) {
92729821 let state = neighbour_state(grid);
92739822 if crate::envflags::env_flag!("EC_ECPUB") {
9274- eprintln!("EC_ECPUB tu mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={}", state.level);
9823+ eprintln!(
9824+ "EC_ECPUB tu mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={}",
9825+ state.level
9826+ );
92759827 }
92769828 for cell in 0..h_px / MI {
92779829 if mi_r + cell < self.mi_rows {
@@ -9509,7 +10061,11 @@ struct PaletteUv {
950910061 /// `get_unsigned_bits`, which is the same formula): smallest `n` with
951010062 /// `2^n >= x`, `0` for `x <= 1`.
951110063 pub(crate) fn ceil_log2(x: u32) -> u32 {
9512- if x < 2 { 0 } else { 32 - (x - 1).leading_zeros() }
10064+ if x < 2 {
10065+ 0
10066+ } else {
10067+ 32 - (x - 1).leading_zeros()
10068+ }
951310069 }
951410070
951510071 /// `av1_read_uniform` (decoder.h:425): a uniform `0..n` value coded as
@@ -9560,7 +10116,12 @@ fn merge_colors(transmitted: &[u16], cached: &[u16]) -> Vec<u16> {
956010116 /// (one flag bit each, in cache order), then delta-codes the remainder
956110117 /// (first value raw, each following delta `>= 1` off a shrinking bit width),
956210118 /// and merges the two ascending lists back together.
9563-fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16], fctx: &crate::decode::FrameCtx) -> [u16; 8] {
10119+fn read_palette_colors_y(
10120+ dec: &mut SymbolDecoder,
10121+ n: usize,
10122+ cache: &[u16],
10123+ fctx: &crate::decode::FrameCtx,
10124+) -> [u16; 8] {
956410125 let mut cached = Vec::with_capacity(n);
956510126 for &c in cache {
956610127 if cached.len() >= n {
@@ -9607,7 +10168,12 @@ fn read_palette_colors_y(dec: &mut SymbolDecoder, n: usize, cache: &[u16], fctx:
960710168 /// side by side). V never uses a cache: a leading bit picks either `n` raw
960810169 /// literals, or a first raw value plus `n-1` signed deltas that wrap mod 256
960910170 /// rather than clamp.
9610-fn read_palette_colors_uv(dec: &mut SymbolDecoder, n: usize, cache: &[u16], fctx: &crate::decode::FrameCtx) -> ([u16; 8], [u16; 8]) {
10171+fn read_palette_colors_uv(
10172+ dec: &mut SymbolDecoder,
10173+ n: usize,
10174+ cache: &[u16],
10175+ fctx: &crate::decode::FrameCtx,
10176+) -> ([u16; 8], [u16; 8]) {
961110177 let mut cached = Vec::with_capacity(n);
961210178 for &c in cache {
961310179 if cached.len() >= n {
@@ -9689,13 +10255,21 @@ pub(crate) fn palette_color_index_context(
968910255 col: usize,
969010256 n: usize,
969110257 ) -> (usize, [u8; 8]) {
9692- let left = if col >= 1 { Some(map[row * side + col - 1]) } else { None };
10258+ let left = if col >= 1 {
10259+ Some(map[row * side + col - 1])
10260+ } else {
10261+ None
10262+ };
969310263 let up_left = if col >= 1 && row >= 1 {
969410264 Some(map[(row - 1) * side + col - 1])
969510265 } else {
969610266 None
969710267 };
9698- let up = if row >= 1 { Some(map[(row - 1) * side + col]) } else { None };
10268+ let up = if row >= 1 {
10269+ Some(map[(row - 1) * side + col])
10270+ } else {
10271+ None
10272+ };
969910273 let mut scores = [0i32; 8];
970010274 for (neighbour, weight) in [(left, 2), (up_left, 1), (up, 2)] {
970110275 if let Some(v) = neighbour {
@@ -9847,7 +10421,10 @@ fn decode_color_index_map_wh(
984710421 } else {
984810422 &cdfs.palette_y_color_index[n - 2][ctx]
984910423 };
9850- eprintln!("EC_PAL row={row} col={col} ctx={ctx} n={n} cdf0={} cnt={} rng={rng}", row_cdf[0], row_cdf[n]);
10424+ eprintln!(
10425+ "EC_PAL row={row} col={col} ctx={ctx} n={n} cdf0={} cnt={} rng={rng}",
10426+ row_cdf[0], row_cdf[n]
10427+ );
985110428 }
985210429 let symbol = if uv {
985310430 dec.symbol(&mut cdfs.palette_uv_color_index[n - 2][ctx][..=n])
@@ -9914,7 +10491,8 @@ fn read_intra_mode_rect(
991410491 palette: Option<(usize, &[u16])>,
991510492 palette_uv_cache: &[u16],
991610493 mi_r: usize,
9917- mi_c: usize, fctx: &crate::decode::FrameCtx,
10494+ mi_c: usize,
10495+ fctx: &crate::decode::FrameCtx,
991810496 ) -> Result<(
991910497 bool,
992010498 usize,
@@ -9946,7 +10524,12 @@ fn read_intra_mode_rect(
994610524 // (decodemv.c:818), printed at the same point: before the first
994710525 // mode-info symbol of the block, so a cross-decoder range ladder can
994810526 // be keyed on the BLOCK, not just on the symbol sequence.
9949- eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=rect bw={bw} bh={bh} efi={} cls={:?} rng={}", enable_filter_intra as i32, filter_intra_size_class_rect(bw, bh), dec.debug_state().0);
10527+ eprintln!(
10528+ "EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=rect bw={bw} bh={bh} efi={} cls={:?} rng={}",
10529+ enable_filter_intra as i32,
10530+ filter_intra_size_class_rect(bw, bh),
10531+ dec.debug_state().0
10532+ );
995010533 }
995110534 macro_rules! istep {
995210535 ($name:literal, $val:expr) => {
@@ -9977,60 +10560,60 @@ fn read_intra_mode_rect(
997710560 let skip = if let Some((_, skip)) = inter {
997810561 skip
997910562 } else {
9980- // Same `intra_segment_id` placement as the square reader above.
9981- let (seg_w_mi, seg_h_mi) = (bw / 4, bh / 4);
9982- if seg_id_pre_skip(fctx) {
9983- intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, false, fctx);
9984- }
9985- let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
9986- istep!("skip", skip as i32);
9987- if !seg_id_pre_skip(fctx) {
9988- intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, skip, fctx);
9989- }
9990- maybe_read_cdef_idx(dec, mi_r, mi_c, (bw / MI, bh / MI), skip, fctx);
crates/ec-av1/src/stream.rsmodified+6445 -2673

Diff too large; view file

@@ -1,3 +1,5 @@
1+/home/user/Documents/Code/Rust/edith_codecs/crates/ec-av1/src/stream.rs:
2+
13 //! The stream-level entry point a real decoder needs: walk a raw AV1 OBU
24 //! stream (`Encoded::stream`, or any low-overhead-format bitstream this
35 //! crate's own writers produce) via [`ec_av1_syntax::Av1Parser`] and dispatch
@@ -28,12 +30,9 @@ use ec_core::{Error, Result};
2830
2931 use crate::cdf_state::Cdfs;
3032 use crate::decode;
31-use crate::decode::{
32- decode_inter_frame_tile_with_cdfs, decode_key_frame_tile_with_cdfs,
33- q_ctx_of,
34-};
3533 #[cfg(test)]
3634 use crate::decode::decode_key_frame_tile_lr;
35+use crate::decode::{decode_inter_frame_tile_with_cdfs, decode_key_frame_tile_with_cdfs, q_ctx_of};
3736 use crate::encode::Picture;
3837
3938 /// lane-midcut r1: `EC_AV1_NO_GRAIN=1` skips film grain synthesis at output, so a
@@ -217,6 +216,22 @@ pub fn intrabc_128rect_hits() -> usize {
217216 crate::decode::intrabc_128rect_hits()
218217 }
219218
219+/// lane-av1-ibc128chunk: chroma transform units the 128-root intrabc strip's
220+/// mu-chunk walk read, one per `read_inter_plane` chroma call. At 4:2:2 a
221+/// 64x64 mu chunk's chroma plane block is 32x64 and holds TWO STACKED
222+/// TX_32X32 units per plane; the square-cut walk this gate witnesses read
223+/// one. Measured on the pinned witness: 8 before, 48 after.
224+pub fn intrabc_128rect_chroma_chunk_hits() -> usize {
225+ crate::decode::intrabc_128rect_chroma_chunk_hits()
226+}
227+
228+/// lane-av1-ibc128chunk: the 128-root intrabc strip's per-axis chroma chunk
229+/// extents as `(64 >> ss_x) << 8 | (64 >> ss_y)` on the last chunk walked --
230+/// 32|32 at 4:2:0, 32|64 at 4:2:2, 64|64 at 4:4:4.
231+pub fn intrabc_128rect_chunk_shape() -> usize {
232+ crate::decode::intrabc_128rect_chunk_shape()
233+}
234+
220235 /// Blocks reconstructed with intra block copy at an 8x8 LEAF specifically
221236 /// (lane-kf900 r7's shape); [`crate::decode::intrabc_hits`] counts every shape.
222237 pub fn leaf8_intrabc_hits() -> usize {
@@ -384,16 +399,19 @@ struct Reorder {
384399 }
385400
386401 impl Reorder {
387- fn push(&mut self, seq: usize, picture: std::sync::Arc<Picture>, decode_idx: usize, shown: bool) {
402+ fn push(
403+ &mut self,
404+ seq: usize,
405+ picture: std::sync::Arc<Picture>,
406+ decode_idx: usize,
407+ shown: bool,
408+ ) {
388409 self.pending.insert(seq, (picture, decode_idx, shown));
389410 }
390411
391412 /// Emits every queued picture whose turn has come. An `Err` from `sink`
392413 /// aborts the decode, unchanged, exactly as the serial path did.
393- fn drain(
394- &mut self,
395- sink: &mut impl FnMut(&Picture, usize, bool) -> Result<()>,
396- ) -> Result<()> {
414+ fn drain(&mut self, sink: &mut impl FnMut(&Picture, usize, bool) -> Result<()>) -> Result<()> {
397415 while let Some((picture, decode_idx, shown)) = self.pending.remove(&self.next) {
398416 self.next += 1;
399417 sink(&picture, decode_idx, shown)?;
@@ -411,8 +429,7 @@ impl Reorder {
411429 /// inline. (lane-thread2 counted only LEAF frames, the only ones it could
412430 /// dispatch; lane-thread3 dispatches every non-key, non-`show_existing_frame`
413431 /// frame, hence the rename.)
414-static FRAMES_DISPATCHED: std::sync::atomic::AtomicUsize =
415- std::sync::atomic::AtomicUsize::new(0);
432+static FRAMES_DISPATCHED: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
416433
417434 /// Reads [`FRAMES_DISPATCHED`].
418435 pub fn frames_dispatched() -> usize {
@@ -724,12 +741,12 @@ pub fn decode_stream_with_threads(
724741 let capped = in_flight_shows >= in_flight_cap;
725742 while in_flight_shows >= in_flight_cap {
726743 collect_one(
727- &rx,
728- &mut in_flight_decodes,
729- &mut in_flight_shows,
730- &mut reorder,
731- &mut sink,
732- )?;
744+ &rx,
745+ &mut in_flight_decodes,
746+ &mut in_flight_shows,
747+ &mut reorder,
748+ &mut sink,
749+ )?;
733750 }
734751 if capped {
735752 crate::timeline::cap_wait("show", cap_t0, crate::timeline::now());
@@ -803,7 +820,8 @@ pub fn decode_stream_with_threads(
803820 &picture,
804821 &header.film_grain,
805822 mc_identity,
806- bit_depth as u32, fctx,
823+ bit_depth as u32,
824+ fctx,
807825 ))
808826 } else {
809827 picture
@@ -1214,8 +1232,7 @@ pub fn decode_stream_with_threads(
12141232 final_dump.as_deref(),
12151233 None,
12161234 )?;
1217- let motion_field =
1218- motion_field.expect("the inline path passes no stage-1 sink");
1235+ let motion_field = motion_field.expect("the inline path passes no stage-1 sink");
12191236 pictures_decoded += 1;
12201237 // lane-pool1: one allocation, then every slot store and the output
12211238 // itself are refcount bumps instead of plane copies.
@@ -1271,7 +1288,8 @@ pub fn decode_stream_with_threads(
12711288 &picture,
12721289 &header.film_grain,
12731290 mc_identity,
1274- bit_depth as u32, fctx,
1291+ bit_depth as u32,
1292+ fctx,
12751293 ))
12761294 } else {
12771295 picture
@@ -1304,8 +1322,6 @@ pub fn decode_stream_with_threads(
13041322 Ok(())
13051323 }
13061324
1307-
1308-
13091325 /// lane-thread2: the sequence-header bits a single frame's decode needs,
13101326 /// read once on the parsing thread so that [`decode_frame`] never touches the
13111327 /// [`Av1Parser`] (a worker thread has no access to it).
@@ -1394,8 +1410,8 @@ impl<'a> RefSnapshot<'a> {
13941410 // spec 7.9's own driver, `av1_setup_motion_field`: only run when
13951411 // this frame's header asks for it, and never for a key frame (which
13961412 // codes no inter block at all).
1397- let tpl_field = (header.frame_type != FrameType::Key && header.use_ref_frame_mvs).then(
1398- || {
1413+ let tpl_field =
1414+ (header.frame_type != FrameType::Key && header.use_ref_frame_mvs).then(|| {
13991415 crate::motion_field::setup_motion_field(
14001416 motion_field_slots,
14011417 header.ref_frame_idx,
@@ -1404,8 +1420,7 @@ impl<'a> RefSnapshot<'a> {
14041420 header.mi_rows as usize,
14051421 header.mi_cols as usize,
14061422 )
1407- },
1408- );
1423+ });
14091424 if std::env::var_os("EC_TPL").is_some() {
14101425 eprintln!(
14111426 "EC_TPL order_hint={} use_ref_frame_mvs={} cells={}",
@@ -1520,7 +1535,8 @@ fn decode_frame(
15201535 header.segmentation,
15211536 header.mi_rows as usize,
15221537 header.mi_cols as usize,
1523- snap.prev_seg_map.as_deref(), fctx,
1538+ snap.prev_seg_map.as_deref(),
1539+ fctx,
15241540 );
15251541 // lane-superres stage 2/3: `use_superres` adds/removes no per-block
15261542 // symbol (spec 7.16's upscaling is a pixel-domain post-process
@@ -1833,8 +1849,13 @@ fn decode_frame(
18331849 // the LR unit grid in upscaled coordinates. Cleared (0, 8) on an
18341850 // unscaled frame so a later frame never inherits it.
18351851 crate::decode::set_superres(
1836- if header.use_superres { header.upscaled_width } else { 0 },
1837- u32::from(header.superres_denom), fctx,
1852+ if header.use_superres {
1853+ header.upscaled_width
1854+ } else {
1855+ 0
1856+ },
1857+ u32::from(header.superres_denom),
1858+ fctx,
18381859 );
18391860 // lane-av1comp: `comp_group_idx`/`compound_idx`'s own gating bits.
18401861 let enable_masked_compound = seq.enable_masked_compound;
@@ -1942,7 +1963,8 @@ fn decode_frame(
19421963 header.reduced_tx_set,
19431964 header.allow_screen_content_tools,
19441965 header.allow_intrabc,
1945- header.delta, fctx,
1966+ header.delta,
1967+ fctx,
19461968 )?;
19471969 // A key frame codes no inter blocks -- its own saved motion
19481970 // field has no cells set, matching libaom's own "intra frame
@@ -2219,9 +2241,8 @@ pub(crate) mod tests {
22192241 crate::encode::key_frame_headers_colour(64, 64, 100, color).unwrap();
22202242 seq.seq_profile = profile;
22212243 let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();
2222- stream.extend_from_slice(
2223- &crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap(),
2224- );
2244+ stream
2245+ .extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap());
22252246 let err = decode_stream(&stream).unwrap_err().to_string();
22262247 assert!(
22272248 err.contains(REFUSAL),
@@ -2233,7 +2254,11 @@ pub(crate) mod tests {
22332254 let mut stream = crate::sequence::sequence_header_obu(&seq).unwrap();
22342255 stream.extend_from_slice(&crate::frame::frame_obu(&seq, &header, &encoded.tile).unwrap());
22352256 let frames = decode_stream(&stream).expect("the 4:2:0 control must decode");
2236- assert_eq!(frames.len(), 1, "{NAME}: the 4:2:0 control decoded no frame");
2257+ assert_eq!(
2258+ frames.len(),
2259+ 1,
2260+ "{NAME}: the 4:2:0 control decoded no frame"
2261+ );
22372262 }
22382263 /// lane-av1-422bigblock: the two witnessed 4:2:2 big-block defects, pinned
22392264 /// as fixtures (`git add -f`; `fixtures/` is gitignored).
@@ -2291,6 +2316,193 @@ pub(crate) mod tests {
22912316 }
22922317 }
22932318
2319+ /// lane-av1-ibc128chunk: the WITNESS for the 128-root intrabc strip's
2320+ /// de-square-cut mu-chunk chroma walk, and the byte pin for it.
2321+ ///
2322+ /// `decode_intrabc_128rect` cut each mu chunk's chroma plane block with
2323+ /// `chunk_chroma = cside * 64 / side` -- a `chroma_side`-SQUARE chunk,
2324+ /// i.e. the 4:2:0 count on BOTH axes (the same defect lane-av1-422bigblock
2325+ /// fixed, and witnessed, in `decode_inter_block` and
2326+ /// `decode_block_128rect`; this copy was deferred there as unwitnessed).
2327+ /// At 4:2:2 a 64x64 mu chunk's chroma plane block is 32x64, so it holds
2328+ /// TWO STACKED TX_32X32 units per plane: the square-cut walk read one per
2329+ /// plane per chunk, left the chunk's lower 32 chroma rows with no
2330+ /// residual at all, and stamped each unit's entropy context over a
2331+ /// 16x16-mi luma span instead of 16x8.
2332+ ///
2333+ /// Measured red-before on the pinned witness (parent `a7d22aec`, via the
2334+ /// local `EC_AV1_ALLOW_422_PROBE` patch-run-restore build): 8 chroma
2335+ /// units stamped over the stream's two reached blocks and frames 0 and 3
2336+ /// diverge from `aomdec` (45135 / 44540 of 245760 samples each), the
2337+ /// first difference at Y sample 98368 -- frame 0, row 256, col 64, the
2338+ /// top-left corner of the first 128x64 intrabc block at mi(64,0). The
2339+ /// red build then lost 4 of the stream's 6 intrabc blocks to the desync.
2340+ /// Green-after, same fixture: 48 chroma units stamped, all 6 blocks
2341+ /// decoded, and ALL FIVE frames byte-identical to `aomdec --rawvideo`.
2342+ ///
2343+ /// Committed code refuses 4:2:2 at the sequence header, so the decode
2344+ /// assertions above are probe-measured and reproducible from the lane
2345+ /// report's recipe; what this gate can assert in committed code is the
2346+ /// byte pin, the refusal-by-name contract, and -- in the arm below --
2347+ /// that the per-axis walk is still spelled per-axis in the source.
2348+ #[test]
2349+ fn the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name() {
2350+ const NAME: &str = "the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name";
2351+ const REFUSAL: &str = "a chroma format of 4:2:2";
2352+ for (file, bytes, fp) in [
2353+ (
2354+ "422_intrabc_sb128_strip.obu",
2355+ 1672usize,
2356+ 0x50f5cfc576e4cd00_u64,
2357+ ),
2358+ (
2359+ "422_intrabc_sb128_strip_notxsearch.obu",
2360+ 1675,
2361+ 0xd4936f252ff8cff0,
2362+ ),
2363+ ] {
2364+ let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
2365+ .join("fixtures")
2366+ .join(file);
2367+ let data = std::fs::read(&path).unwrap_or_else(|e| {
2368+ panic!(
2369+ "{NAME}: pinned witness {} is missing ({e}) -- the gate cannot run",
2370+ path.display()
2371+ )
2372+ });
2373+ assert_eq!(data.len(), bytes, "{NAME}: {file} size drifted");
2374+ assert_eq!(fnv1a64(&data), fp, "{NAME}: {file} bytes drifted");
2375+ let err = decode_stream(&data).unwrap_err().to_string();
2376+ assert!(
2377+ err.contains(REFUSAL),
2378+ "{NAME}: {file} must refuse by name, got: {err}"
2379+ );
2380+ }
2381+ }
2382+
2383+ /// lane-av1-ibc128chunk: the SOURCE-SCAN arm of the witness gate above.
2384+ ///
2385+ /// The decode-level half of the red/green evidence cannot run in
2386+ /// committed code (the 4:2:2 refusal stands), so this arm pins the thing
2387+ /// that would silently bring the defect back: the square-cut
2388+ /// `chunk_chroma = cside * 64 / side` expression, and the per-axis
2389+ /// replacements that replaced it at BOTH sites in
2390+ /// [`decode_intrabc_128rect`] -- the mu-chunk read walk and the
2391+ /// `mu_chroma` per-unit context replay. It also pins the per-axis
2392+ /// counters' accessors so the arms stay reachable, and the walk's own
2393+ /// per-axis extent, derived here from the same `64 >> ss` form the
2394+ /// witnesses measured (4:2:0 = one TX_32X32 per plane per chunk,
2395+ /// 4:2:2 = two stacked, 4:4:4 = four).
2396+ #[test]
2397+ fn the_intrabc_128rect_chroma_chunk_walk_stays_per_axis() {
2398+ const NAME: &str = "the_intrabc_128rect_chroma_chunk_walk_stays_per_axis";
2399+ let src = include_str!("decode.rs");
2400+ let body = src
2401+ .split_once("fn decode_intrabc_128rect(")
2402+ .expect("decode_intrabc_128rect must exist")
2403+ .1
2404+ .split_once("\nfn ")
2405+ .expect("decode_intrabc_128rect must be a top-level fn")
2406+ .0;
2407+ // Scan CODE only: the fix's own comments quote the old expression to
2408+ // say what it was, and a prose mention must not read as a
2409+ // reintroduction (nor mask one).
2410+ let stripped: Vec<&str> = body
2411+ .lines()
2412+ .map(|l| l.split_once("//").map_or(l, |(c, _)| c))
2413+ .collect();
2414+ let code = stripped.join("\n");
2415+ let body = code.as_str();
2416+ assert_eq!(
2417+ body.matches("cside * 64 / side").count(),
2418+ 0,
2419+ "{NAME}: the square-cut `cside * 64 / side` chunk extent is BACK in \
2420+ decode_intrabc_128rect -- that expression is the 4:2:2 defect this \
2421+ gate exists for (a 64x64 mu chunk's chroma plane block is \
2422+ (64 >> ss_x) x (64 >> ss_y), not `chroma_side` square)"
2423+ );
2424+ // The per-axis chunk extent, declared once at the mu-chunk read walk
2425+ // and once at the `mu_chroma` replay -- the two de-square-cut sites.
2426+ //
2427+ // The replay must ALSO enumerate every unit inside a chunk, not just
2428+ // its first: counting mu CHUNKS in `rows`/`cols` and then stepping the
2429+ // mi origin and reading the grid per UNIT only agrees when a chunk
2430+ // holds exactly one unit (4:2:0). At 4:2:2 and 4:4:4 a chunk holds two
2431+ // or four, so the per-unit body alone left the rest of the chunk with
2432+ // the composed-grid smearing the replay exists to undo.
2433+ for name in [
2434+ "let chunk_chroma_w = (64usize) >> ss_x(fctx);",
2435+ "let chunk_chroma_h = (64usize) >> ss_y(fctx);",
2436+ ] {
2437+ assert_eq!(
2438+ body.matches(name).count(),
2439+ 2,
2440+ "{NAME}: `{name}` must appear at BOTH de-square-cut sites in \
2441+ decode_intrabc_128rect (the mu-chunk read walk and the mu_chroma \
2442+ context replay), found {}",
2443+ body.matches(name).count()
2444+ );
2445+ }
2446+ for name in [
2447+ "let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu);",
2448+ "for kr in 0..ur {",
2449+ "for kc in 0..uc {",
2450+ ] {
2451+ assert_eq!(
2452+ body.matches(name).count(),
2453+ 1,
2454+ "{NAME}: `{name}` must appear exactly once in \
2455+ decode_intrabc_128rect -- the mu_chroma replay must walk chunk \
2456+ THEN unit (decode_inter_block's `mu_chroma_units` shape), found {}",
2457+ body.matches(name).count()
2458+ );
2459+ }
2460+ for name in [
2461+ "let unit_luma_w = cu_tx << ss_x(fctx);",
2462+ "let unit_luma_h = cu_tx << ss_y(fctx);",
2463+ "let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx));",
2464+ "let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));",
2465+ "neighbours.around_mi_rect(unit_mi, unit_luma_w, unit_luma_h)",
2466+ ] {
2467+ assert_eq!(
2468+ body.matches(name).count(),
2469+ 1,
2470+ "{NAME}: `{name}` must appear exactly once in \
2471+ decode_intrabc_128rect, found {}",
2472+ body.matches(name).count()
2473+ );
2474+ }
2475+ // The replay's own unit luma span is the lossless/lossy `cu << ss` form
2476+ // (site 2 spells it separately from the read walk's `cu_tx << ss`).
2477+ for name in [
2478+ "let unit_luma_w = cu << ss_x(fctx);",
2479+ "let unit_luma_h = cu << ss_y(fctx);",
2480+ ] {
2481+ assert_eq!(
2482+ body.matches(name).count(),
2483+ 1,
2484+ "{NAME}: `{name}` must appear exactly once in \
2485+ decode_intrabc_128rect, found {}",
2486+ body.matches(name).count()
2487+ );
2488+ }
2489+ // The per-axis chunk extent the geometry demands, spelled out here so
2490+ // the scan and the witnesses cannot disagree about it.
2491+ let per_axis_units = |ss_x: u32, ss_y: u32| (64 >> ss_x) / 32 * (64 >> ss_y) / 32;
2492+ assert_eq!(per_axis_units(1, 1), 1, "{NAME}: 4:2:0 must stay one unit");
2493+ assert_eq!(per_axis_units(1, 0), 2, "{NAME}: 4:2:2 must be two units");
2494+ assert_eq!(per_axis_units(0, 0), 4, "{NAME}: 4:4:4 must be four units");
2495+ // The counters the probe arms read must stay exported.
2496+ for name in [
2497+ "pub fn intrabc_128rect_chroma_chunk_hits()",
2498+ "pub fn intrabc_128rect_chunk_shape()",
2499+ ] {
2500+ assert!(
2501+ src.contains(name),
2502+ "{NAME}: the accessor `{name}` must stay in decode.rs"
2503+ );
2504+ }
2505+ }
22942506
22952507 /// lane-av1-qmatrix: WITNESS for the lifted `using_qmatrix` refusal (the
22962508 /// old gate `a_frame_using_quantisation_matrices_is_refused_by_name` is
@@ -2376,7 +2588,12 @@ pub(crate) mod tests {
23762588 .collect();
23772589 args.push(format!("--limit={FRAMES}"));
23782590 args.extend(extra.iter().map(|s| (*s).to_owned()));
2379- args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]);
2591+ args.extend([
2592+ "--obu".to_owned(),
2593+ "-o".to_owned(),
2594+ "-".to_owned(),
2595+ "-".to_owned(),
2596+ ]);
23802597 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
23812598 assert!(
23822599 out.status.success(),
@@ -2393,13 +2610,23 @@ pub(crate) mod tests {
23932610 decode_stream(stream).unwrap_or_else(|e| panic!("{NAME}: {label} decode: {e}"));
23942611 assert_eq!(got.len(), want.len(), "{NAME}: {label} frame count");
23952612 for (i, (g, w)) in got.iter().zip(want.iter()).enumerate() {
2396- for (plane, (gp, wp)) in
2397- [(&g.y, &w.y), (&g.u, &w.u), (&g.v, &w.v)].into_iter().enumerate()
2613+ for (plane, (gp, wp)) in [(&g.y, &w.y), (&g.u, &w.u), (&g.v, &w.v)]
2614+ .into_iter()
2615+ .enumerate()
23982616 {
2399- assert_eq!(gp, wp,
2617+ assert_eq!(
2618+ gp,
2619+ wp,
24002620 "{NAME}: {label} frame {i} plane {plane} differs from ffmpeg (first mismatching sample: got {}, want {})",
2401- gp.iter().zip(wp.iter()).find(|(a, b)| a != b).map_or(0, |(a, _)| *a),
2402- gp.iter().zip(wp.iter()).find(|(a, b)| a != b).map_or(0, |(_, b)| *b));
2621+ gp.iter()
2622+ .zip(wp.iter())
2623+ .find(|(a, b)| a != b)
2624+ .map_or(0, |(a, _)| *a),
2625+ gp.iter()
2626+ .zip(wp.iter())
2627+ .find(|(a, b)| a != b)
2628+ .map_or(0, |(_, b)| *b)
2629+ );
24032630 }
24042631 }
24052632 };
@@ -2417,7 +2644,10 @@ pub(crate) mod tests {
24172644 "{NAME}: the qm-off control decoded no frame"
24182645 );
24192646 for (using, y, u, v) in qm_headers(&control_stream) {
2420- assert!(!using, "{NAME}: the control's frame header set using_qmatrix");
2647+ assert!(
2648+ !using,
2649+ "{NAME}: the control's frame header set using_qmatrix"
2650+ );
24212651 assert_eq!(
24222652 (y, u, v),
24232653 (0, 0, 0),
@@ -2579,7 +2809,7 @@ pub(crate) mod tests {
25792809 /// never reports this refusal for any of them.
25802810 #[test]
25812811 fn a_frame_obu_that_parses_always_carries_at_least_one_tile() {
2582- let fctx = &crate::decode::FrameCtx::new();
2812+ let fctx = &crate::decode::FrameCtx::new();
25832813 const REFUSAL: &str = "a frame OBU with no tile group";
25842814 let picture = test_card(64, 64);
25852815 let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
@@ -2635,9 +2865,8 @@ pub(crate) mod tests {
26352865 /// first, a middle and the last segment id.
26362866 #[test]
26372867 fn a_frame_whose_segmentation_overrides_a_block_mode_is_refused_by_name() {
2638- let fctx = &crate::decode::FrameCtx::new();
2639- const REFUSAL: &str =
2640- "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV";
2868+ let fctx = &crate::decode::FrameCtx::new();
2869+ const REFUSAL: &str = "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV";
26412870 let picture = test_card(64, 64);
26422871 let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
26432872 let (seq, key) = crate::encode::key_frame_headers(64, 64, 100).unwrap();
@@ -2688,15 +2917,31 @@ pub(crate) mod tests {
26882917 let src = format!("{source}=size={width}x{height}:rate=25");
26892918 let y4m = Command::new("ffmpeg")
26902919 .args([
2691- "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", "yuv420p",
2692- "-strict", "-1", "-f", "yuv4mpegpipe", "-",
2920+ "-v",
2921+ "error",
2922+ "-f",
2923+ "lavfi",
2924+ "-i",
2925+ &src,
2926+ "-t",
2927+ &duration,
2928+ "-pix_fmt",
2929+ "yuv420p",
2930+ "-strict",
2931+ "-1",
2932+ "-f",
2933+ "yuv4mpegpipe",
2934+ "-",
26932935 ])
26942936 .stdin(Stdio::null())
26952937 .stdout(Stdio::piped())
26962938 .stderr(Stdio::piped())
26972939 .output()
26982940 .expect("ffmpeg failed to run");
2699- assert!(y4m.status.success(), "ffmpeg refused the {width}x{height} fixture");
2941+ assert!(
2942+ y4m.status.success(),
2943+ "ffmpeg refused the {width}x{height} fixture"
2944+ );
27002945 let limit = format!("--limit={frames}");
27012946 let mut args: Vec<String> = [
27022947 "--codec=av1",
@@ -2712,10 +2957,18 @@ pub(crate) mod tests {
27122957 .collect();
27132958 args.push(limit);
27142959 args.extend(extra.iter().map(|s| (*s).to_owned()));
2715- args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]);
2716- let out = run_with_stdin(Command::new(aomenc_path())
2717- .args(&args), &y4m.stdout);
2718- assert!(out.status.success(), "aomenc refused {args:?}: {}", String::from_utf8_lossy(&out.stderr));
2960+ args.extend([
2961+ "--obu".to_owned(),
2962+ "-o".to_owned(),
2963+ "-".to_owned(),
2964+ "-".to_owned(),
2965+ ]);
2966+ let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
2967+ assert!(
2968+ out.status.success(),
2969+ "aomenc refused {args:?}: {}",
2970+ String::from_utf8_lossy(&out.stderr)
2971+ );
27192972 let stream = out.stdout;
27202973 let result = match decode_stream(&stream) {
27212974 Ok(pictures) => Ok(pictures.len()),
@@ -2740,15 +2993,31 @@ pub(crate) mod tests {
27402993 let src = format!("{source}=size={width}x{height}:rate=25");
27412994 let y4m = Command::new("ffmpeg")
27422995 .args([
2743- "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", "yuv420p",
2744- "-strict", "-1", "-f", "yuv4mpegpipe", "-",
2996+ "-v",
2997+ "error",
2998+ "-f",
2999+ "lavfi",
3000+ "-i",
3001+ &src,
3002+ "-t",
3003+ &duration,
3004+ "-pix_fmt",
3005+ "yuv420p",
3006+ "-strict",
3007+ "-1",
3008+ "-f",
3009+ "yuv4mpegpipe",
3010+ "-",
27453011 ])
27463012 .stdin(Stdio::null())
27473013 .stdout(Stdio::piped())
27483014 .stderr(Stdio::piped())
27493015 .output()
27503016 .expect("ffmpeg failed to run");
2751- assert!(y4m.status.success(), "ffmpeg refused the {width}x{height} fixture");
3017+ assert!(
3018+ y4m.status.success(),
3019+ "ffmpeg refused the {width}x{height} fixture"
3020+ );
27523021 let limit = format!("--limit={frames}");
27533022 let mut args: Vec<String> = [
27543023 "--codec=av1",
@@ -2764,9 +3033,18 @@ pub(crate) mod tests {
27643033 .collect();
27653034 args.push(limit);
27663035 args.extend(extra.iter().map(|s| (*s).to_owned()));
2767- args.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]);
3036+ args.extend([
3037+ "--obu".to_owned(),
3038+ "-o".to_owned(),
3039+ "-".to_owned(),
3040+ "-".to_owned(),
3041+ ]);
27683042 let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
2769- assert!(out.status.success(), "aomenc refused {args:?}: {}", String::from_utf8_lossy(&out.stderr));
3043+ assert!(
3044+ out.status.success(),
3045+ "aomenc refused {args:?}: {}",
3046+ String::from_utf8_lossy(&out.stderr)
3047+ );
27703048 out.stdout
27713049 }
27723050
@@ -2787,17 +3065,34 @@ pub(crate) mod tests {
27873065 let src = format!("{source}=size={width}x{height}:rate=25");
27883066 let y4m = Command::new("ffmpeg")
27893067 .args([
2790- "-v", "error", "-f", "lavfi", "-i", &src, "-t", &duration, "-pix_fmt", "yuv420p",
2791- "-strict", "-1", "-f", "yuv4mpegpipe", "-",
3068+ "-v",
3069+ "error",
3070+ "-f",
3071+ "lavfi",
3072+ "-i",
3073+ &src,
3074+ "-t",
3075+ &duration,
3076+ "-pix_fmt",
3077+ "yuv420p",
3078+ "-strict",
3079+ "-1",
3080+ "-f",
3081+ "yuv4mpegpipe",
3082+ "-",
27923083 ])
27933084 .stdin(Stdio::null())
27943085 .stdout(Stdio::piped())
27953086 .stderr(Stdio::piped())
27963087 .output()
27973088 .expect("ffmpeg failed to run");
2798- assert!(y4m.status.success(), "ffmpeg refused the {width}x{height} fixture");
3089+ assert!(
3090+ y4m.status.success(),
3091+ "ffmpeg refused the {width}x{height} fixture"
3092+ );
27993093 let limit = format!("--limit={frames}");
2800- let fpf = std::env::temp_dir().join(format!("ec-av1-segldapass-{}.fpf", std::process::id()));
3094+ let fpf =
3095+ std::env::temp_dir().join(format!("ec-av1-segldapass-{}.fpf", std::process::id()));
28013096 let mut base: Vec<String> = [
28023097 "--codec=av1",
28033098 "--passes=2",
@@ -2814,15 +3109,33 @@ pub(crate) mod tests {
28143109 base.extend(extra.iter().map(|s| (*s).to_owned()));
28153110 let mut pass1 = base.clone();
28163111 pass1.extend(["--pass=1".to_owned(), format!("--fpf={}", fpf.display())]);
2817- pass1.extend(["--obu".to_owned(), "-o".to_owned(), "/dev/null".to_owned(), "-".to_owned()]);
3112+ pass1.extend([
3113+ "--obu".to_owned(),
3114+ "-o".to_owned(),
3115+ "/dev/null".to_owned(),
3116+ "-".to_owned(),
3117+ ]);
28183118 let out1 = run_with_stdin(Command::new(aomenc_path()).args(&pass1), &y4m.stdout);
2819- assert!(out1.status.success(), "aomenc pass 1 refused {pass1:?}: {}", String::from_utf8_lossy(&out1.stderr));
3119+ assert!(
3120+ out1.status.success(),
3121+ "aomenc pass 1 refused {pass1:?}: {}",
3122+ String::from_utf8_lossy(&out1.stderr)
3123+ );
28203124 let mut pass2 = base;
28213125 pass2.extend(["--pass=2".to_owned(), format!("--fpf={}", fpf.display())]);
2822- pass2.extend(["--obu".to_owned(), "-o".to_owned(), "-".to_owned(), "-".to_owned()]);
3126+ pass2.extend([
3127+ "--obu".to_owned(),
3128+ "-o".to_owned(),
3129+ "-".to_owned(),
3130+ "-".to_owned(),
3131+ ]);
28233132 let out2 = run_with_stdin(Command::new(aomenc_path()).args(&pass2), &y4m.stdout);
28243133 let _ = std::fs::remove_file(&fpf);
2825- assert!(out2.status.success(), "aomenc pass 2 refused {pass2:?}: {}", String::from_utf8_lossy(&out2.stderr));
3134+ assert!(
3135+ out2.status.success(),
3136+ "aomenc pass 2 refused {pass2:?}: {}",
3137+ String::from_utf8_lossy(&out2.stderr)
3138+ );
28263139 out2.stdout
28273140 }
28283141
@@ -2921,15 +3234,36 @@ pub(crate) mod tests {
29213234 let arms: [(&str, &[&str]); 3] = [
29223235 (
29233236 "testsrc2=size=256x192:rate=25",
2924- &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=3", "--sb-size=64"],
3237+ &[
3238+ "--end-usage=q",
3239+ "--cq-level=0",
3240+ "--aq-mode=1",
3241+ "--good",
3242+ "--cpu-used=3",
3243+ "--sb-size=64",
3244+ ],
29253245 ),
29263246 (
29273247 "testsrc2=size=256x192:rate=25",
2928- &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=5", "--sb-size=64"],
3248+ &[
3249+ "--end-usage=q",
3250+ "--cq-level=0",
3251+ "--aq-mode=1",
3252+ "--good",
3253+ "--cpu-used=5",
3254+ "--sb-size=64",
3255+ ],
29293256 ),
29303257 (
29313258 "gradients=size=256x192:rate=25",
2932- &["--end-usage=q", "--cq-level=0", "--aq-mode=1", "--good", "--cpu-used=6", "--sb-size=64"],
3259+ &[
3260+ "--end-usage=q",
3261+ "--cq-level=0",
3262+ "--aq-mode=1",
3263+ "--good",
3264+ "--cpu-used=6",
3265+ "--sb-size=64",
3266+ ],
29333267 ),
29343268 ];
29353269 let mut mixed_arms = 0usize;
@@ -2939,8 +3273,21 @@ pub(crate) mod tests {
29393273 for (src, extra) in &arms {
29403274 let y4m = Command::new("ffmpeg")
29413275 .args([
2942- "-v", "error", "-f", "lavfi", "-i", *src, "-t", "0.16", "-pix_fmt",
2943- "yuv420p", "-strict", "-1", "-f", "yuv4mpegpipe", "-",
3276+ "-v",
3277+ "error",
3278+ "-f",
3279+ "lavfi",
3280+ "-i",
3281+ *src,
3282+ "-t",
3283+ "0.16",
3284+ "-pix_fmt",
3285+ "yuv420p",
3286+ "-strict",
3287+ "-1",
3288+ "-f",
3289+ "yuv4mpegpipe",
3290+ "-",
29443291 ])
29453292 .stdin(Stdio::null())
29463293 .stdout(Stdio::piped())
@@ -2949,14 +3296,21 @@ pub(crate) mod tests {
29493296 .expect("ffmpeg failed to run");
29503297 assert!(y4m.status.success(), "{NAME}: ffmpeg failed for {src}");
29513298 let limit = format!("--limit={FRAMES}");
2952- let mut args: Vec<String> = ["--codec=av1", "--passes=1", "--threads=1", "--obu", "-o", "-", "-"]
2953- .iter()
2954- .map(|s| (*s).to_owned())
2955- .collect();
3299+ let mut args: Vec<String> = [
3300+ "--codec=av1",
3301+ "--passes=1",
3302+ "--threads=1",
3303+ "--obu",
3304+ "-o",
3305+ "-",
3306+ "-",
3307+ ]
3308+ .iter()
3309+ .map(|s| (*s).to_owned())
3310+ .collect();
29563311 args.insert(1, limit);
29573312 args.extend(extra.iter().map(|s| (*s).to_owned()));
2958- let out = run_with_stdin(Command::new(aomenc_path())
2959- .args(&args), &y4m.stdout);
3313+ let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
29603314 assert!(
29613315 out.status.success(),
29623316 "{NAME}: aomenc refused {args:?}: {}",
@@ -2986,8 +3340,9 @@ pub(crate) mod tests {
29863340 // WHT-unit delta proves the per-segment lossless reconstruction
29873341 // really ran inside a frame that is NOT `CodedLossless`.
29883342 let before = crate::decode::lossless_wht_units();
2989- let ours = decode_stream(&stream)
2990- .unwrap_or_else(|e| panic!("{NAME}: a mixed-lossless frame decodes after the per-segment lift: {e}"));
3343+ let ours = decode_stream(&stream).unwrap_or_else(|e| {
3344+ panic!("{NAME}: a mixed-lossless frame decodes after the per-segment lift: {e}")
3345+ });
29913346 let wht_units = crate::decode::lossless_wht_units() - before;
29923347 let refs = ffmpeg_decode_sequence(&stream, WIDTH, HEIGHT, FRAMES);
29933348 assert_eq!(ours.len(), FRAMES, "{NAME}: frame count");
@@ -2997,10 +3352,16 @@ pub(crate) mod tests {
29973352 .enumerate()
29983353 {
29993354 let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
3000- assert_eq!(bad, 0, "{NAME}: arm {extra:?} frame {i} plane {plane}: {bad} samples differ");
3355+ assert_eq!(
3356+ bad, 0,
3357+ "{NAME}: arm {extra:?} frame {i} plane {plane}: {bad} samples differ"
3358+ );
30013359 }
30023360 }
3003- assert!(wht_units > 0, "{NAME}: arm {extra:?} reconstructed no Walsh-Hadamard unit -- the mixed census is lying or the lossless path never ran");
3361+ assert!(
3362+ wht_units > 0,
3363+ "{NAME}: arm {extra:?} reconstructed no Walsh-Hadamard unit -- the mixed census is lying or the lossless path never ran"
3364+ );
30043365 mixed_arms += 1;
30053366 eprintln!(
30063367 "{NAME}: arm {extra:?}: {mixed} mixed frame(s), {FRAMES} frames sample-exact vs ffmpeg, {wht_units} WHT units"
@@ -3035,15 +3396,29 @@ pub(crate) mod tests {
30353396 eprintln!("SKIP a_segmentation_census_over_real_aq_streams: no aomenc");
30363397 return;
30373398 }
3038- const REFUSAL: &str =
3039- "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV";
3399+ const REFUSAL: &str = "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV";
30403400 let recipes: [(&str, Vec<&str>); 6] = [
30413401 ("baseline", vec!["--cpu-used=4", "--cq-level=40"]),
3042- ("aq-mode=1", vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=40"]),
3043- ("aq-mode=2", vec!["--cpu-used=4", "--aq-mode=2", "--cq-level=40"]),
3044- ("aq-mode=3", vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=40"]),
3045- ("aq-mode=3 cq10", vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=10"]),
3046- ("deltaq-mode=1", vec!["--cpu-used=4", "--deltaq-mode=1", "--cq-level=40"]),
3402+ (
3403+ "aq-mode=1",
3404+ vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=40"],
3405+ ),
3406+ (
3407+ "aq-mode=2",
3408+ vec!["--cpu-used=4", "--aq-mode=2", "--cq-level=40"],
3409+ ),
3410+ (
3411+ "aq-mode=3",
3412+ vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=40"],
3413+ ),
3414+ (
3415+ "aq-mode=3 cq10",
3416+ vec!["--cpu-used=4", "--aq-mode=3", "--cq-level=10"],
3417+ ),
3418+ (
3419+ "deltaq-mode=1",
3420+ vec!["--cpu-used=4", "--deltaq-mode=1", "--cq-level=40"],
3421+ ),
30473422 ];
30483423 // Arrival, not intent (class knob-never-reached-the-tool): a recipe
30493424 // whose stream is byte-for-byte the baseline's changed nothing, and a
@@ -3090,7 +3465,11 @@ pub(crate) mod tests {
30903465 "SEGCENSUS: {} recipes, {decoded} decoded, {refused} refused for other reasons",
30913466 recipes.len()
30923467 );
3093- assert_eq!(decoded, recipes.len(), "every recipe must decode; {refused} refused");
3468+ assert_eq!(
3469+ decoded,
3470+ recipes.len(),
3471+ "every recipe must decode; {refused} refused"
3472+ );
30943473 assert!(
30953474 segment_symbols > 0,
30963475 "no recipe coded a single segment_id symbol -- segmentation never arrived, so \
@@ -3116,21 +3495,39 @@ pub(crate) mod tests {
31163495 "mandelbrot",
31173496 192,
31183497 128,
3119- vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=45", "--lag-in-frames=16", "--auto-alt-ref=1"],
3498+ vec![
3499+ "--cpu-used=4",
3500+ "--aq-mode=1",
3501+ "--cq-level=45",
3502+ "--lag-in-frames=16",
3503+ "--auto-alt-ref=1",
3504+ ],
31203505 ),
31213506 (
31223507 "aq-mode=1 lag16 screen",
31233508 "testsrc2",
31243509 256,
31253510 192,
3126- vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=45", "--lag-in-frames=16", "--auto-alt-ref=1"],
3511+ vec![
3512+ "--cpu-used=4",
3513+ "--aq-mode=1",
3514+ "--cq-level=45",
3515+ "--lag-in-frames=16",
3516+ "--auto-alt-ref=1",
3517+ ],
31273518 ),
31283519 (
31293520 "aq-mode=1 lag16 cq63 high_q",
31303521 "mandelbrot",
31313522 192,
31323523 128,
3133- vec!["--cpu-used=4", "--aq-mode=1", "--cq-level=63", "--lag-in-frames=16", "--auto-alt-ref=1"],
3524+ vec![
3525+ "--cpu-used=4",
3526+ "--aq-mode=1",
3527+ "--cq-level=63",
3528+ "--lag-in-frames=16",
3529+ "--auto-alt-ref=1",
3530+ ],
31343531 ),
31353532 // `--aq-mode=2 lag16` (complexity AQ over an alt-ref group) was
31363533 // measured 2026-09-24: it encodes and decodes cleanly but codes
@@ -3167,7 +3564,13 @@ pub(crate) mod tests {
31673564 192,
31683565 128,
31693566 40,
3170- &["--cpu-used=4", "--aq-mode=1", "--cq-level=45", "--lag-in-frames=16", "--auto-alt-ref=1"],
3567+ &[
3568+ "--cpu-used=4",
3569+ "--aq-mode=1",
3570+ "--cq-level=45",
3571+ "--lag-in-frames=16",
3572+ "--auto-alt-ref=1",
3573+ ],
31713574 );
31723575 let (enabled, umap, inherited, alt_q, frames_per_feature) =
31733576 segmentation_feature_census(&stream);
@@ -3239,7 +3642,8 @@ pub(crate) mod tests {
32393642 /// `SEG_LVL_ALT_Q`, and an inheritance-heavy shape).
32403643 #[test]
32413644 fn a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact() {
3242- const NAME: &str = "a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact";
3645+ const NAME: &str =
3646+ "a_real_aomenc_segmentation_stream_with_map_inheritance_decodes_pixel_exact";
32433647 if !have_aomenc() {
32443648 eprintln!("SKIP {NAME}: no aomenc");
32453649 return;
@@ -3350,8 +3754,18 @@ pub(crate) mod tests {
33503754 "--enable-intrabc=0",
33513755 ];
33523756 let recipes: [(&str, usize, usize, Vec<&str>); 2] = [
3353- ("obmc dual cq40", 192, 128, [vec!["--cq-level=40"], base.clone()].concat()),
3354- ("obmc dual cq20", 192, 128, [vec!["--cq-level=20"], base.clone()].concat()),
3757+ (
3758+ "obmc dual cq40",
3759+ 192,
3760+ 128,
3761+ [vec!["--cq-level=40"], base.clone()].concat(),
3762+ ),
3763+ (
3764+ "obmc dual cq20",
3765+ 192,
3766+ 128,
3767+ [vec!["--cq-level=20"], base.clone()].concat(),
3768+ ),
33553769 ];
33563770 let mut reads = 0usize;
33573771 let mut decoded = 0usize;
@@ -3372,7 +3786,9 @@ pub(crate) mod tests {
33723786 }
33733787 Err(e) => {
33743788 assert!(
3375- !e.contains("an OBMC neighbour whose switchable interp filter was never recorded"),
3789+ !e.contains(
3790+ "an OBMC neighbour whose switchable interp filter was never recorded"
3791+ ),
33763792 "{name}: a real OBMC stream reached the unrecorded-filter refusal -- \
33773793 a publication site is missing: {e}"
33783794 );
@@ -3380,7 +3796,10 @@ pub(crate) mod tests {
33803796 }
33813797 }
33823798 }
3383- assert!(decoded > 0, "no OBMC recipe decoded -- the witness is vacuous");
3799+ assert!(
3800+ decoded > 0,
3801+ "no OBMC recipe decoded -- the witness is vacuous"
3802+ );
33843803 assert!(
33853804 reads > 0,
33863805 "every OBMC blend took the fixed-filter path: the band was never read, so this \
@@ -3417,12 +3836,62 @@ pub(crate) mod tests {
34173836 "--enable-intrabc=0",
34183837 ];
34193838 let recipes: [(&str, usize, usize, Vec<&str>); 6] = [
3420- ("denom12 320x180 cq32", 320, 180, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=12", "--cq-level=32"]),
3421- ("denom12 320x180 cq50", 320, 180, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=12", "--cq-level=50"]),
3422- ("denom16 320x180 cq32", 320, 180, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=16", "--cq-level=32"]),
3423- ("denom10 192x128 cq32", 192, 128, vec!["--cpu-used=4", "--superres-mode=1", "--superres-denominator=10", "--cq-level=32"]),
3424- ("auto 320x180 cq50", 320, 180, vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"]),
3425- ("auto 192x128 cq50", 192, 128, vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"]),
3839+ (
3840+ "denom12 320x180 cq32",
3841+ 320,
3842+ 180,
3843+ vec![
3844+ "--cpu-used=4",
3845+ "--superres-mode=1",
3846+ "--superres-denominator=12",
3847+ "--cq-level=32",
3848+ ],
3849+ ),
3850+ (
3851+ "denom12 320x180 cq50",
3852+ 320,
3853+ 180,
3854+ vec![
3855+ "--cpu-used=4",
3856+ "--superres-mode=1",
3857+ "--superres-denominator=12",
3858+ "--cq-level=50",
3859+ ],
3860+ ),
3861+ (
3862+ "denom16 320x180 cq32",
3863+ 320,
3864+ 180,
3865+ vec![
3866+ "--cpu-used=4",
3867+ "--superres-mode=1",
3868+ "--superres-denominator=16",
3869+ "--cq-level=32",
3870+ ],
3871+ ),
3872+ (
3873+ "denom10 192x128 cq32",
3874+ 192,
3875+ 128,
3876+ vec![
3877+ "--cpu-used=4",
3878+ "--superres-mode=1",
3879+ "--superres-denominator=10",
3880+ "--cq-level=32",
3881+ ],
3882+ ),
3883+ (
3884+ "auto 320x180 cq50",
3885+ 320,
3886+ 180,
3887+ vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"],
3888+ ),
3889+ (
3890+ "auto 192x128 cq50",
3891+ 192,
3892+ 128,
3893+ vec!["--cpu-used=4", "--superres-mode=3", "--cq-level=50"],
3894+ ),
34263895 ];
34273896 let (mut decoded, mut warp, mut sub8, mut leaf8) = (0, 0, 0, 0);
34283897 // lane-t900 r36 (class [[gate-blind-to-feature]]): unknown refusal
@@ -3475,7 +3944,10 @@ pub(crate) mod tests {
34753944 // front of them: whichever partition path a scaled frame takes, the
34763945 // leaf guard is reached first. Lifting the leaf gap is what makes the
34773946 // other two measurable, so this gate pins the ORDER, not just a count.
3478- assert!(decoded > 0, "no superres recipe decoded -- the census is vacuous");
3947+ assert!(
3948+ decoded > 0,
3949+ "no superres recipe decoded -- the census is vacuous"
3950+ );
34793951 // lane-t900 r28: all three scaled refusals are LIFTED, so the census
34803952 // now pins the opposite shape -- every fixed-denominator recipe must
34813953 // DECODE, and none of the three strings may come back.
@@ -3484,7 +3956,10 @@ pub(crate) mod tests {
34843956 (0, 0, 0),
34853957 "a scaled-reference refusal came back (warp {warp}, sub8 {sub8}, leaf8 {leaf8})"
34863958 );
3487- assert!(decoded > 0, "no superres recipe decoded -- the census is vacuous");
3959+ assert!(
3960+ decoded > 0,
3961+ "no superres recipe decoded -- the census is vacuous"
3962+ );
34883963 }
34893964
34903965 /// lane-t900 r25, negative gate: a `show_existing_frame` header naming a
@@ -3536,7 +4011,10 @@ pub(crate) mod tests {
35364011 err.contains(REFUSAL),
35374012 "slot {slot}: expected {REFUSAL:?}, got: {err}"
35384013 );
3539- assert_eq!(shown, 0, "slot {slot}: an empty slot was output as a picture");
4014+ assert_eq!(
4015+ shown, 0,
4016+ "slot {slot}: an empty slot was output as a picture"
4017+ );
35404018 }
35414019 }
35424020
@@ -3554,7 +4032,7 @@ pub(crate) mod tests {
35544032 /// tile is decoded.
35554033 #[test]
35564034 fn an_inter_frame_opening_a_stream_is_refused_by_name() {
3557- let fctx = &crate::decode::FrameCtx::new();
4035+ let fctx = &crate::decode::FrameCtx::new();
35584036 const REFUSAL: &str = "an inter frame with no key frame before it";
35594037 let picture = test_card(64, 64);
35604038 let encoded = encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
@@ -3581,7 +4059,10 @@ pub(crate) mod tests {
35814059 .unwrap_err()
35824060 .to_string();
35834061 assert!(err.contains(REFUSAL), "expected {REFUSAL:?}, got: {err}");
3584- assert_eq!(shown, 0, "an inter frame with no reference produced a picture");
4062+ assert_eq!(
4063+ shown, 0,
4064+ "an inter frame with no reference produced a picture"
4065+ );
35854066 }
35864067
35874068 /// lane-t900 r26, negative gate: an inter frame whose own coded size is
@@ -3600,7 +4081,7 @@ pub(crate) mod tests {
36004081 /// fires on the reference's dimensions before a tile symbol is read.
36014082 #[test]
36024083 fn an_inter_frame_shorter_than_its_reference_is_refused_by_name() {
3603- let fctx = &crate::decode::FrameCtx::new();
4084+ let fctx = &crate::decode::FrameCtx::new();
36044085 const REFUSAL: &str =
36054086 "a reference picture whose height does not match this frame's own true size";
36064087 let picture = test_card(64, 64);
@@ -3630,7 +4111,10 @@ pub(crate) mod tests {
36304111 .unwrap_err()
36314112 .to_string();
36324113 assert!(err.contains(REFUSAL), "expected {REFUSAL:?}, got: {err}");
3633- assert_eq!(shown, 1, "expected the key frame alone, got {shown} pictures");
4114+ assert_eq!(
4115+ shown, 1,
4116+ "expected the key frame alone, got {shown} pictures"
4117+ );
36344118 }
36354119
36364120 /// lane-t900 r26, negative gate: an inter frame naming a
@@ -3652,7 +4136,7 @@ pub(crate) mod tests {
36524136 /// before the reference pictures are looked up.
36534137 #[test]
36544138 fn an_inter_frame_naming_an_unrefreshed_primary_ref_slot_is_refused_by_name() {
3655- let fctx = &crate::decode::FrameCtx::new();
4139+ let fctx = &crate::decode::FrameCtx::new();
36564140 const REFUSAL: &str =
36574141 "a frame naming primary_ref_frame at a reference slot with no saved CDF state";
36584142 // The invariant above, read off the source: every line that stores a
@@ -3708,8 +4192,14 @@ pub(crate) mod tests {
37084192 })
37094193 .unwrap_err()
37104194 .to_string();
3711- assert!(err.contains(REFUSAL), "slot {slot}: expected {REFUSAL:?}, got: {err}");
3712- assert_eq!(shown, 0, "slot {slot}: a frame with no CDF state produced a picture");
4195+ assert!(
4196+ err.contains(REFUSAL),
4197+ "slot {slot}: expected {REFUSAL:?}, got: {err}"
4198+ );
4199+ assert_eq!(
4200+ shown, 0,
4201+ "slot {slot}: a frame with no CDF state produced a picture"
4202+ );
37134203 }
37144204 }
37154205
@@ -3756,7 +4246,9 @@ pub(crate) mod tests {
37564246 continue;
37574247 };
37584248 let mut parser = Av1Parser::new();
3759- parser.parse_obu(&crate::sequence::sequence_header_obu(&seq).unwrap()).unwrap();
4249+ parser
4250+ .parse_obu(&crate::sequence::sequence_header_obu(&seq).unwrap())
4251+ .unwrap();
37604252 let obu = parser.parse_obu(&stream).unwrap();
37614253 let ObuKind::Frame(parsed, _) = &obu.kind else {
37624254 panic!("{w}x{h}: the written frame OBU did not parse as one");
@@ -3804,11 +4296,28 @@ pub(crate) mod tests {
38044296 ) -> ([usize; 6], usize, usize) {
38054297 let duration = format!("{}", frames as f64 / 25.0);
38064298 let source = format!("mandelbrot=size={width}x{height}:rate=25");
3807- let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
4299+ let pix_fmt = if bit_depth == 10 {
4300+ "yuv420p10le"
4301+ } else {
4302+ "yuv420p"
4303+ };
38084304 let y4m = Command::new("ffmpeg")
38094305 .args([
3810- "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration, "-pix_fmt",
3811- pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
4306+ "-v",
4307+ "error",
4308+ "-f",
4309+ "lavfi",
4310+ "-i",
4311+ &source,
4312+ "-t",
4313+ &duration,
4314+ "-pix_fmt",
4315+ pix_fmt,
4316+ "-strict",
4317+ "-1",
4318+ "-f",
4319+ "yuv4mpegpipe",
4320+ "-",
38124321 ])
38134322 .stdin(Stdio::null())
38144323 .stdout(Stdio::piped())
@@ -3824,34 +4333,58 @@ pub(crate) mod tests {
38244333 let input_depth_arg = format!("--input-bit-depth={bit_depth}");
38254334 let cq_arg = format!("--cq-level={cq}");
38264335 let limit_arg = format!("--limit={frames}");
3827- let out = run_with_stdin(Command::new(aomenc_path())
3828- .args([
3829- "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg,
4336+ let out = run_with_stdin(
4337+ Command::new(aomenc_path()).args([
4338+ "--codec=av1",
4339+ "--passes=1",
4340+ "--end-usage=q",
4341+ &cq_arg,
38304342 // cpu-used >= 1 keeps libaom on 64x64 superblocks at these
38314343 // sizes (`av1_select_sb_size`).
3832- "--cpu-used=4", "--threads=1", "--row-mt=0", "--kf-max-dist=9999",
4344+ "--cpu-used=4",
4345+ "--threads=1",
4346+ "--row-mt=0",
4347+ "--kf-max-dist=9999",
38334348 &limit_arg,
38344349 // decode order == display order, so the compare below covers
38354350 // every frame the stream carries (class gate-blind-to-hidden-frames).
3836- "--lag-in-frames=0", &depth_arg, &input_depth_arg,
4351+ "--lag-in-frames=0",
4352+ &depth_arg,
4353+ &input_depth_arg,
38374354 // Rect partitions stay ON: the frame-edge strip is a FORCED
38384355 // (gathered) HORZ/VERT, but with rect coding off the encoder
38394356 // answers that gathered symbol SPLIT every time and no edge
38404357 // strip ever fires (lane-oddh r2's finding, re-measured r1).
3841- "--enable-rect-partitions=1", "--enable-ab-partitions=0",
3842- "--enable-1to4-partitions=0", "--min-partition-size=8",
4358+ "--enable-rect-partitions=1",
4359+ "--enable-ab-partitions=0",
4360+ "--enable-1to4-partitions=0",
4361+ "--min-partition-size=8",
38434362 "--max-partition-size=64",
38444363 // Other lanes' open gaps this recipe must not trip.
3845- "--enable-palette=0", "--enable-intrabc=0", "--enable-warped-motion=0",
3846- "--enable-obmc=0", "--enable-masked-comp=0", "--enable-interintra-comp=0",
3847- "--enable-onesided-comp=0", "--enable-interintra-wedge=0",
3848- "--enable-smooth-interintra=0", "--enable-ref-frame-mvs=0",
3849- "--enable-angle-delta=0", "--enable-cfl-intra=0",
3850- "--enable-directional-intra=0", "--enable-smooth-intra=0",
3851- "--enable-paeth-intra=0", "--enable-filter-intra=0",
4364+ "--enable-palette=0",
4365+ "--enable-intrabc=0",
4366+ "--enable-warped-motion=0",
4367+ "--enable-obmc=0",
4368+ "--enable-masked-comp=0",
4369+ "--enable-interintra-comp=0",
4370+ "--enable-onesided-comp=0",
4371+ "--enable-interintra-wedge=0",
4372+ "--enable-smooth-interintra=0",
4373+ "--enable-ref-frame-mvs=0",
4374+ "--enable-angle-delta=0",
4375+ "--enable-cfl-intra=0",
4376+ "--enable-directional-intra=0",
4377+ "--enable-smooth-intra=0",
4378+ "--enable-paeth-intra=0",
4379+ "--enable-filter-intra=0",
38524380 "--enable-tx-size-search=0",
3853- "--obu", "-o", "-", "-",
3854- ]), &y4m.stdout);
4381+ "--obu",
4382+ "-o",
4383+ "-",
4384+ "-",
4385+ ]),
4386+ &y4m.stdout,
4387+ );
38554388 assert!(
38564389 out.status.success(),
38574390 "aomenc refused: {}",
@@ -4000,24 +4533,55 @@ pub(crate) mod tests {
40004533 let (width, height) = (64usize, 72usize);
40014534 let y4m = Command::new("ffmpeg")
40024535 .args([
4003- "-v", "error", "-f", "lavfi", "-i",
4004- "mandelbrot=size=64x72:rate=25:start_x=-0.6:start_y=-0.4", "-t", "0.04",
4005- "-pix_fmt", "yuv420p", "-f", "yuv4mpegpipe", "-",
4536+ "-v",
4537+ "error",
4538+ "-f",
4539+ "lavfi",
4540+ "-i",
4541+ "mandelbrot=size=64x72:rate=25:start_x=-0.6:start_y=-0.4",
4542+ "-t",
4543+ "0.04",
4544+ "-pix_fmt",
4545+ "yuv420p",
4546+ "-f",
4547+ "yuv4mpegpipe",
4548+ "-",
40064549 ])
40074550 .stdin(Stdio::null())
40084551 .stdout(Stdio::piped())
40094552 .stderr(Stdio::piped())
40104553 .output()
40114554 .expect("ffmpeg failed to run");
4012- assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr));
4013- let out = run_with_stdin(Command::new(aomenc_path())
4014- .args([
4015- "--codec=av1", "--passes=1", "--end-usage=q", "--cq-level=32",
4016- "--cpu-used=0", "--sb-size=128", "--min-partition-size=16",
4017- "--kf-max-dist=0", "--limit=1",
4018- "--threads=1", "--row-mt=0", "--obu", "-o", "-", "-",
4019- ]), &y4m.stdout);
4020- assert!(out.status.success(), "aomenc refused: {}", String::from_utf8_lossy(&out.stderr));
4555+ assert!(
4556+ y4m.status.success(),
4557+ "ffmpeg fixture: {}",
4558+ String::from_utf8_lossy(&y4m.stderr)
4559+ );
4560+ let out = run_with_stdin(
4561+ Command::new(aomenc_path()).args([
4562+ "--codec=av1",
4563+ "--passes=1",
4564+ "--end-usage=q",
4565+ "--cq-level=32",
4566+ "--cpu-used=0",
4567+ "--sb-size=128",
4568+ "--min-partition-size=16",
4569+ "--kf-max-dist=0",
4570+ "--limit=1",
4571+ "--threads=1",
4572+ "--row-mt=0",
4573+ "--obu",
4574+ "-o",
4575+ "-",
4576+ "-",
4577+ ]),
4578+ &y4m.stdout,
4579+ );
4580+ assert!(
4581+ out.status.success(),
4582+ "aomenc refused: {}",
4583+ String::from_utf8_lossy(&out.stderr)
4584+ );
40214585 let stream = out.stdout;
40224586
40234587 // The knob actually arrived: this stream's sequence header codes
@@ -4035,19 +4599,19 @@ pub(crate) mod tests {
40354599 break;
40364600 }
40374601 }
4038- assert!(sb128, "aomenc ignored --sb-size=128: this stream is 64x64-superblock");
4602+ assert!(
4603+ sb128,
4604+ "aomenc ignored --sb-size=128: this stream is 64x64-superblock"
4605+ );
40394606
40404607 let _guard = lock_gate_counters();
4041- let before = crate::decode::part128_symbols()
4042- + crate::decode::part128_gathered_symbols();
4043- let (frames, hidden) =
4044- decode_all_frames_vs_oracle(&stream, "sb128-oddh-64x72");
4608+ let before = crate::decode::part128_symbols() + crate::decode::part128_gathered_symbols();
4609+ let (frames, hidden) = decode_all_frames_vs_oracle(&stream, "sb128-oddh-64x72");
40454610 assert!(frames > 0, "no frames decoded for {width}x{height}");
40464611 // The 128 root actually READ a partition symbol here: at mi_rows=18
40474612 // `has_rows` is true, so BLOCK_128X128 is not a forced split.
4048- let part128 = crate::decode::part128_symbols()
4049- + crate::decode::part128_gathered_symbols()
4050- - before;
4613+ let part128 =
4614+ crate::decode::part128_symbols() + crate::decode::part128_gathered_symbols() - before;
40514615 assert!(
40524616 part128 > 0,
40534617 "{width}x{height} decoded without reading a single BLOCK_128X128 \
@@ -4099,7 +4663,8 @@ pub(crate) mod tests {
40994663 encoded.screen,
41004664 // ... and its own `allow_intrabc` (stale-header class).
41014665 encoded.allow_intrabc,
4102- &encoded.loop_restoration, fctx,
4666+ &encoded.loop_restoration,
4667+ fctx,
41034668 )
41044669 .unwrap();
41054670 let via_stream = decode_stream(&encoded.stream).unwrap();
@@ -4142,7 +4707,7 @@ pub(crate) mod tests {
41424707
41434708 #[test]
41444709 fn decode_stream_round_trips_a_gop() {
4145- let fctx = &crate::decode::FrameCtx::for_encoder();
4710+ let fctx = &crate::decode::FrameCtx::for_encoder();
41464711 gop_round_trips(128, 64, fctx);
41474712 }
41484713
@@ -4150,7 +4715,7 @@ pub(crate) mod tests {
41504715 /// the inter frame's 16x16-leaf split path is exercised too.
41514716 #[test]
41524717 fn decode_stream_round_trips_an_odd_size_gop() {
4153- let fctx = &crate::decode::FrameCtx::for_encoder();
4718+ let fctx = &crate::decode::FrameCtx::for_encoder();
41544719 gop_round_trips(216, 96, fctx);
41554720 }
41564721
@@ -4162,9 +4727,11 @@ pub(crate) mod tests {
41624727 /// decode indices non-decreasing, and an `Err` from the sink aborting.
41634728 #[test]
41644729 fn streaming_decode_matches_the_collecting_one() {
4165- let fctx = &crate::decode::FrameCtx::for_encoder();
4730+ let fctx = &crate::decode::FrameCtx::for_encoder();
41664731 let pictures: Vec<_> = (0..4).map(|i| panned_test_card(128, 64, i * 3)).collect();
4167- let stream = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx).unwrap().stream;
4732+ let stream = encode_sequence_with_ctx(&pictures, 100, 0.5, fctx)
4733+ .unwrap()
4734+ .stream;
41684735 let collected = decode_stream(&stream).unwrap();
41694736
41704737 let mut shown = Vec::new();
@@ -4179,8 +4746,15 @@ pub(crate) mod tests {
41794746 Ok(())
41804747 })
41814748 .unwrap();
4182- assert_eq!(shown.len(), collected.len(), "callback count vs shown frames");
4183- assert!(live >= shown.len(), "every shown picture is also a callback");
4749+ assert_eq!(
4750+ shown.len(),
4751+ collected.len(),
4752+ "callback count vs shown frames"
4753+ );
4754+ assert!(
4755+ live >= shown.len(),
4756+ "every shown picture is also a callback"
4757+ );
41844758 assert!(
41854759 idxs.windows(2).all(|w| w[0] <= w[1]),
41864760 "decode indices out of order: {idxs:?}"
@@ -4301,9 +4875,18 @@ pub(crate) mod tests {
43014875 Pic {
43024876 width,
43034877 height,
4304- y: out.stdout[base..base + luma].iter().map(|&v| u16::from(v)).collect(),
4305- u: out.stdout[base + luma..base + luma + chroma].iter().map(|&v| u16::from(v)).collect(),
4306- v: out.stdout[base + luma + chroma..base + frame_bytes].iter().map(|&v| u16::from(v)).collect(),
4878+ y: out.stdout[base..base + luma]
4879+ .iter()
4880+ .map(|&v| u16::from(v))
4881+ .collect(),
4882+ u: out.stdout[base + luma..base + luma + chroma]
4883+ .iter()
4884+ .map(|&v| u16::from(v))
4885+ .collect(),
4886+ v: out.stdout[base + luma + chroma..base + frame_bytes]
4887+ .iter()
4888+ .map(|&v| u16::from(v))
4889+ .collect(),
43074890 }
43084891 })
43094892 .collect()
@@ -4352,8 +4935,17 @@ pub(crate) mod tests {
43524935 ) -> Vec<Pic> {
43534936 let out = run_with_stdin(
43544937 Command::new("ffmpeg").args([
4355- "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt",
4356- "yuv420p10le", "-",
4938+ "-v",
4939+ "error",
4940+ "-f",
4941+ "obu",
4942+ "-i",
4943+ "-",
4944+ "-f",
4945+ "rawvideo",
4946+ "-pix_fmt",
4947+ "yuv420p10le",
4948+ "-",
43574949 ]),
43584950 stream,
43594951 );
@@ -4419,10 +5011,27 @@ pub(crate) mod tests {
44195011 let (width, height) = (384usize, 152usize);
44205012 let out = Command::new("ffmpeg")
44215013 .args([
4422- "-v", "error", "-f", "lavfi", "-i",
5014+ "-v",
5015+ "error",
5016+ "-f",
5017+ "lavfi",
5018+ "-i",
44235019 "smptebars=s=384x152:r=12,drawgrid=w=8:h=8:t=1:c=black",
4424- "-frames:v", "4", "-c:v", "libsvtav1", "-preset", "8", "-crf", "30",
4425- "-svtav1-params", "lp=1:screen-content-mode=1", "-g", "12", "-f", "obu", "-",
5020+ "-frames:v",
5021+ "4",
5022+ "-c:v",
5023+ "libsvtav1",
5024+ "-preset",
5025+ "8",
5026+ "-crf",
5027+ "30",
5028+ "-svtav1-params",
5029+ "lp=1:screen-content-mode=1",
5030+ "-g",
5031+ "12",
5032+ "-f",
5033+ "obu",
5034+ "-",
44265035 ])
44275036 .stdin(Stdio::null())
44285037 .stdout(Stdio::piped())
@@ -4511,7 +5120,7 @@ pub(crate) mod tests {
45115120 /// independent decoder, not just this crate checking its own tile path.
45125121 #[test]
45135122 fn decode_stream_agrees_with_ffmpeg_on_a_gop() {
4514- let fctx = &crate::decode::FrameCtx::for_encoder();
5123+ let fctx = &crate::decode::FrameCtx::for_encoder();
45155124 if !have_ffmpeg() {
45165125 eprintln!("SKIP decode_stream_agrees_with_ffmpeg_on_a_gop: no ffmpeg");
45175126 return;
@@ -4539,9 +5148,18 @@ pub(crate) mod tests {
45395148 // decoder-side one.
45405149 for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() {
45415150 let rec = &frame.reconstruction;
4542- assert_eq!(rec.y, want.y, "{width}x{height} frame {i} luma: reconstruction vs ffmpeg");
4543- assert_eq!(rec.u, want.u, "{width}x{height} frame {i} U: reconstruction vs ffmpeg");
4544- assert_eq!(rec.v, want.v, "{width}x{height} frame {i} V: reconstruction vs ffmpeg");
5151+ assert_eq!(
5152+ rec.y, want.y,
5153+ "{width}x{height} frame {i} luma: reconstruction vs ffmpeg"
5154+ );
5155+ assert_eq!(
5156+ rec.u, want.u,
5157+ "{width}x{height} frame {i} U: reconstruction vs ffmpeg"
5158+ );
5159+ assert_eq!(
5160+ rec.v, want.v,
5161+ "{width}x{height} frame {i} V: reconstruction vs ffmpeg"
5162+ );
45455163 }
45465164 }
45475165 }
@@ -4567,7 +5185,9 @@ pub(crate) mod tests {
45675185 fn a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg() {
45685186 let fctx = &crate::decode::FrameCtx::for_encoder();
45695187 if !have_ffmpeg() {
4570- eprintln!("SKIP a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg: no ffmpeg");
5188+ eprintln!(
5189+ "SKIP a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg: no ffmpeg"
5190+ );
45715191 return;
45725192 }
45735193 const FRAMES: usize = 4;
@@ -4600,9 +5220,18 @@ pub(crate) mod tests {
46005220 }
46015221 for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() {
46025222 let rec = &frame.reconstruction;
4603- assert_eq!(rec.y, want.y, "{width}x{height} frame {i} luma: recon vs ffmpeg");
4604- assert_eq!(rec.u, want.u, "{width}x{height} frame {i} U: recon vs ffmpeg");
4605- assert_eq!(rec.v, want.v, "{width}x{height} frame {i} V: recon vs ffmpeg");
5223+ assert_eq!(
5224+ rec.y, want.y,
5225+ "{width}x{height} frame {i} luma: recon vs ffmpeg"
5226+ );
5227+ assert_eq!(
5228+ rec.u, want.u,
5229+ "{width}x{height} frame {i} U: recon vs ffmpeg"
5230+ );
5231+ assert_eq!(
5232+ rec.v, want.v,
5233+ "{width}x{height} frame {i} V: recon vs ffmpeg"
5234+ );
46065235 }
46075236 }
46085237 }
@@ -4660,18 +5289,40 @@ pub(crate) mod tests {
46605289 let decoded = decode_stream(&encoded.stream)
46615290 .unwrap_or_else(|e| panic!("{width}x{height}: our decoder refused: {e}"));
46625291 let ffmpeg_frames = ffmpeg_decode_sequence(&encoded.stream, width, height, FRAMES);
4663- assert_eq!(ffmpeg_frames.len(), FRAMES, "{width}x{height}: ffmpeg frame count");
5292+ assert_eq!(
5293+ ffmpeg_frames.len(),
5294+ FRAMES,
5295+ "{width}x{height}: ffmpeg frame count"
5296+ );
46645297 assert_eq!(decoded.len(), FRAMES, "{width}x{height}: frame count");
46655298 for (i, (got, want)) in decoded.iter().zip(&ffmpeg_frames).enumerate() {
4666- assert_eq!(got.y, want.y, "{width}x{height} frame {i} luma: ours vs ffmpeg");
4667- assert_eq!(got.u, want.u, "{width}x{height} frame {i} U: ours vs ffmpeg");
4668- assert_eq!(got.v, want.v, "{width}x{height} frame {i} V: ours vs ffmpeg");
5299+ assert_eq!(
5300+ got.y, want.y,
5301+ "{width}x{height} frame {i} luma: ours vs ffmpeg"
5302+ );
5303+ assert_eq!(
5304+ got.u, want.u,
5305+ "{width}x{height} frame {i} U: ours vs ffmpeg"
5306+ );
5307+ assert_eq!(
5308+ got.v, want.v,
5309+ "{width}x{height} frame {i} V: ours vs ffmpeg"
5310+ );
46695311 }
46705312 for (i, (frame, want)) in encoded.frames.iter().zip(&ffmpeg_frames).enumerate() {
46715313 let rec = &frame.reconstruction;
4672- assert_eq!(rec.y, want.y, "{width}x{height} frame {i} luma: recon vs ffmpeg");
4673- assert_eq!(rec.u, want.u, "{width}x{height} frame {i} U: recon vs ffmpeg");
4674- assert_eq!(rec.v, want.v, "{width}x{height} frame {i} V: recon vs ffmpeg");
5314+ assert_eq!(
5315+ rec.y, want.y,
5316+ "{width}x{height} frame {i} luma: recon vs ffmpeg"
5317+ );
5318+ assert_eq!(
5319+ rec.u, want.u,
5320+ "{width}x{height} frame {i} U: recon vs ffmpeg"
5321+ );
5322+ assert_eq!(
5323+ rec.v, want.v,
5324+ "{width}x{height} frame {i} V: recon vs ffmpeg"
5325+ );
46755326 }
46765327 }
46775328 }
@@ -4704,7 +5355,7 @@ pub(crate) mod tests {
47045355 /// with itself would prove nothing.
47055356 #[test]
47065357 fn a_hand_built_golden_reference_decodes_pixel_exact_against_ffmpeg() {
4707- let fctx = &crate::decode::FrameCtx::new();
5358+ let fctx = &crate::decode::FrameCtx::new();
47085359 if !have_ffmpeg() {
47095360 eprintln!(
47105361 "SKIP a_hand_built_golden_reference_decodes_pixel_exact_against_ffmpeg: no ffmpeg"
@@ -4855,7 +5506,9 @@ pub(crate) mod tests {
48555506 hash_color(seed, 2),
48565507 hash_color(seed, 3),
48575508 );
4858- format!("gradients=size={width}x{height}:c0={c0}:c1={c1}:c2={c2}:c3={c3}:seed={seed}:{tail}")
5509+ format!(
5510+ "gradients=size={width}x{height}:c0={c0}:c1={c1}:c2={c2}:c3={c3}:seed={seed}:{tail}"
5511+ )
48595512 }
48605513
48615514 /// The determinism guard: same seed twice must byte-match ffmpeg's own
@@ -4870,7 +5523,16 @@ pub(crate) mod tests {
48705523 fn render_hash(lavfi: &str) -> Vec<u8> {
48715524 let out = Command::new("ffmpeg")
48725525 .args([
4873- "-v", "error", "-f", "lavfi", "-i", lavfi, "-frames:v", "1", "-f", "rawvideo",
5526+ "-v",
5527+ "error",
5528+ "-f",
5529+ "lavfi",
5530+ "-i",
5531+ lavfi,
5532+ "-frames:v",
5533+ "1",
5534+ "-f",
5535+ "rawvideo",
48745536 "-",
48755537 ])
48765538 .stdin(Stdio::null())
@@ -5088,7 +5750,17 @@ pub(crate) mod tests {
50885750 .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"])
50895751 .arg(&src)
50905752 .args(["-an", "-threads", "1", "-g", "16", "-c:v", "libaom-av1"])
5091- .args(["-cpu-used", "6", "-b:v", "0", "-crf", "35", "-f", "obu", "-"])
5753+ .args([
5754+ "-cpu-used",
5755+ "6",
5756+ "-b:v",
5757+ "0",
5758+ "-crf",
5759+ "35",
5760+ "-f",
5761+ "obu",
5762+ "-",
5763+ ])
50925764 .stdin(Stdio::null())
50935765 .stdout(Stdio::piped())
50945766 .stderr(Stdio::piped())
@@ -5178,18 +5850,37 @@ pub(crate) mod tests {
51785850 let load = Command::new("ffmpeg")
51795851 .args(["-v", "error", "-y", "-i"])
51805852 .arg(&clip)
5181- .args(["-frames:v", &frames.to_string(), "-vf", "crop=1920:1024:960:568"])
5853+ .args([
5854+ "-frames:v",
5855+ &frames.to_string(),
5856+ "-vf",
5857+ "crop=1920:1024:960:568",
5858+ ])
51825859 .args(["-f", "rawvideo", "-pix_fmt", "yuv420p"])
51835860 .arg(&src)
51845861 .output()
51855862 .expect("ffmpeg failed to run");
5186- assert!(load.status.success(), "{NAME}: {}", String::from_utf8_lossy(&load.stderr));
5863+ assert!(
5864+ load.status.success(),
5865+ "{NAME}: {}",
5866+ String::from_utf8_lossy(&load.stderr)
5867+ );
51875868 let out = Command::new("ffmpeg")
51885869 .args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", "yuv420p"])
51895870 .args(["-s", &format!("{w}x{h}"), "-r", "24", "-i"])
51905871 .arg(&src)
51915872 .args(["-an", "-threads", "1", "-g", "12", "-c:v", "libaom-av1"])
5192- .args(["-cpu-used", "6", "-b:v", "0", "-crf", "45", "-f", "obu", "-"])
5873+ .args([
5874+ "-cpu-used",
5875+ "6",
5876+ "-b:v",
5877+ "0",
5878+ "-crf",
5879+ "45",
5880+ "-f",
5881+ "obu",
5882+ "-",
5883+ ])
51935884 .stdin(Stdio::null())
51945885 .stdout(Stdio::piped())
51955886 .stderr(Stdio::piped())
@@ -5307,7 +5998,10 @@ pub(crate) mod tests {
53075998 lossless += 1;
53085999 }
53096000 }
5310- assert_eq!(lossless, frames, "{NAME} went blind: libaom coded no lossless key frame at -crf 0");
6001+ assert_eq!(
6002+ lossless, frames,
6003+ "{NAME} went blind: libaom coded no lossless key frame at -crf 0"
6004+ );
53116005 let ours = decode_stream(&stream).expect("a lossless key-frame stream decodes");
53126006 let refs = ffmpeg_decode_sequence(&stream, w, h, frames);
53136007 assert_eq!(ours.len(), frames, "{NAME}: frame count");
@@ -5317,7 +6011,10 @@ pub(crate) mod tests {
53176011 .enumerate()
53186012 {
53196013 let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
5320- assert_eq!(bad, 0, "{NAME}: frame {i} plane {plane}: {bad} samples differ");
6014+ assert_eq!(
6015+ bad, 0,
6016+ "{NAME}: frame {i} plane {plane}: {bad} samples differ"
6017+ );
53216018 }
53226019 }
53236020 }
@@ -5380,7 +6077,11 @@ pub(crate) mod tests {
53806077 for col in 0..w {
53816078 let v = if screen {
53826079 if row % 7 == 0 && col % 3 == 0 {
5383- if (col / 3 + row + f) % 2 == 1 { 16 } else { 235 }
6080+ if (col / 3 + row + f) % 2 == 1 {
6081+ 16
6082+ } else {
6083+ 235
6084+ }
53846085 } else {
53856086 PAL[((col + 4 * f) / 16 + row / 16) % PAL.len()]
53866087 }
@@ -5405,10 +6106,16 @@ pub(crate) mod tests {
54056106 }
54066107 }
54076108 }
5408- let pix = if depth == 10 { "yuv420p10le" } else { "yuv420p" };
6109+ let pix = if depth == 10 {
6110+ "yuv420p10le"
6111+ } else {
6112+ "yuv420p"
6113+ };
54096114 // [[pid-keyed-temp-path]]: parallel test binaries must not share a name.
5410- let src = std::env::temp_dir()
5411- .join(format!("ec-av1-lossless2-{}-{w}x{h}-{depth}.yuv", std::process::id()));
6115+ let src = std::env::temp_dir().join(format!(
6116+ "ec-av1-lossless2-{}-{w}x{h}-{depth}.yuv",
6117+ std::process::id()
6118+ ));
54126119 std::fs::write(&src, &raw).expect("raw source");
54136120 let mut cmd = Command::new("ffmpeg");
54146121 cmd.args(["-v", "error", "-y", "-f", "rawvideo", "-pix_fmt", pix])
@@ -5456,7 +6163,10 @@ pub(crate) mod tests {
54566163 inters += 1;
54576164 }
54586165 }
5459- assert!(lossless >= frames, "{NAME} [{tag}] went blind: {lossless} lossless frames");
6166+ assert!(
6167+ lossless >= frames,
6168+ "{NAME} [{tag}] went blind: {lossless} lossless frames"
6169+ );
54606170 assert!(
54616171 screen || inters > 0,
54626172 "{NAME} [{tag}] went blind: no inter frame at gop {gop}"
@@ -5475,7 +6185,10 @@ pub(crate) mod tests {
54756185 .enumerate()
54766186 {
54776187 let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
5478- assert_eq!(bad, 0, "{NAME} [{tag}]: frame {i} plane {plane}: {bad} samples differ");
6188+ assert_eq!(
6189+ bad, 0,
6190+ "{NAME} [{tag}]: frame {i} plane {plane}: {bad} samples differ"
6191+ );
54796192 }
54806193 }
54816194 }
@@ -5521,7 +6234,10 @@ pub(crate) mod tests {
55216234 lossless = h.lossless.iter().all(|&l| l);
55226235 }
55236236 }
5524- assert!(lossless, "{NAME} went blind: the pinned frame is not lossless");
6237+ assert!(
6238+ lossless,
6239+ "{NAME} went blind: the pinned frame is not lossless"
6240+ );
55256241 let before = crate::decode::rect_split_lossless_chroma444_hits();
55266242 let ours = decode_stream(&stream).expect("a 444 lossless key-frame stream decodes");
55276243 assert_eq!(ours.len(), 1, "{NAME}: frame count");
@@ -5531,7 +6247,9 @@ pub(crate) mod tests {
55316247 as 4x4 units at subsampling 0/0"
55326248 );
55336249 let refs = Command::new("ffmpeg")
5534- .args(["-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-"])
6250+ .args([
6251+ "-v", "error", "-f", "obu", "-i", "-", "-f", "rawvideo", "-pix_fmt", "yuv444p", "-",
6252+ ])
55356253 .stdin(Stdio::piped())
55366254 .stdout(Stdio::piped())
55376255 .stderr(Stdio::piped())
@@ -5542,7 +6260,11 @@ pub(crate) mod tests {
55426260 child.wait_with_output()
55436261 })
55446262 .expect("ffmpeg 444 decode failed");
5545- assert!(refs.status.success(), "{}", String::from_utf8_lossy(&refs.stderr));
6263+ assert!(
6264+ refs.status.success(),
6265+ "{}",
6266+ String::from_utf8_lossy(&refs.stderr)
6267+ );
55466268 let frame = &ours[0];
55476269 let planes = [
55486270 (&frame.y, frame.width * frame.height),
@@ -5552,7 +6274,11 @@ pub(crate) mod tests {
55526274 let mut off = 0usize;
55536275 for (plane, (g, len)) in planes.iter().enumerate() {
55546276 let raw = &refs.stdout[off..off + len];
5555- let bad = g.iter().zip(raw.iter()).filter(|&(&a, &b)| a != u16::from(b)).count();
6277+ let bad = g
6278+ .iter()
6279+ .zip(raw.iter())
6280+ .filter(|&(&a, &b)| a != u16::from(b))
6281+ .count();
55566282 assert_eq!(bad, 0, "{NAME}: plane {plane}: {bad} samples differ");
55576283 off += len;
55586284 }
@@ -5592,9 +6318,18 @@ pub(crate) mod tests {
55926318 Pic {
55936319 width,
55946320 height,
5595- y: out.stdout[base..base + plane].iter().map(|&v| u16::from(v)).collect(),
5596- u: out.stdout[base + plane..base + 2 * plane].iter().map(|&v| u16::from(v)).collect(),
5597- v: out.stdout[base + 2 * plane..base + 3 * plane].iter().map(|&v| u16::from(v)).collect(),
6321+ y: out.stdout[base..base + plane]
6322+ .iter()
6323+ .map(|&v| u16::from(v))
6324+ .collect(),
6325+ u: out.stdout[base + plane..base + 2 * plane]
6326+ .iter()
6327+ .map(|&v| u16::from(v))
6328+ .collect(),
6329+ v: out.stdout[base + 2 * plane..base + 3 * plane]
6330+ .iter()
6331+ .map(|&v| u16::from(v))
6332+ .collect(),
55986333 }
55996334 })
56006335 .collect()
@@ -5641,9 +6376,8 @@ pub(crate) mod tests {
56416376
56426377 let _guard = lock_gate_counters();
56436378 let before = crate::decode::chroma_split_tx_hits();
5644- let frames = decode_stream(&stream).unwrap_or_else(|e| {
5645- panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")
5646- });
6379+ let frames = decode_stream(&stream)
6380+ .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}"));
56476381 let hits = crate::decode::chroma_split_tx_hits();
56486382 assert!(
56496383 hits > before,
@@ -5685,12 +6419,22 @@ pub(crate) mod tests {
56856419 .zip(["y", "u", "v"])
56866420 {
56876421 let want = &ref_raw[base + off..base + off + W * H];
5688- let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count();
5689- assert_eq!(bad, 0, "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ");
6422+ let bad = plane
6423+ .iter()
6424+ .zip(want)
6425+ .filter(|&(&a, &b)| a as u8 != b)
6426+ .count();
6427+ assert_eq!(
6428+ bad, 0,
6429+ "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ"
6430+ );
56906431 }
56916432 }
56926433 } else {
5693- eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display());
6434+ eprintln!(
6435+ "SKIP {NAME} aomdec arm: no oracle aomdec at {}",
6436+ aomdec_path().display()
6437+ );
56946438 }
56956439
56966440 // ffmpeg's decoder: same frames, full-resolution chroma.
@@ -5702,7 +6446,10 @@ pub(crate) mod tests {
57026446 .enumerate()
57036447 {
57046448 let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
5705- assert_eq!(bad, 0, "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ");
6449+ assert_eq!(
6450+ bad, 0,
6451+ "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ"
6452+ );
57066453 }
57076454 }
57086455 } else {
@@ -5760,9 +6507,8 @@ pub(crate) mod tests {
57606507 assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved");
57616508
57626509 let _guard = lock_gate_counters();
5763- let frames = decode_stream(&stream).unwrap_or_else(|e| {
5764- panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")
5765- });
6510+ let frames = decode_stream(&stream)
6511+ .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}"));
57666512 assert_eq!(frames.len(), FRAMES, "{NAME}: frame count");
57676513 for f in &frames {
57686514 assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions");
@@ -5798,7 +6544,11 @@ pub(crate) mod tests {
57986544 .zip(["y", "u", "v"])
57996545 {
58006546 let want = &ref_raw[base + off..base + off + W * H];
5801- let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count();
6547+ let bad = plane
6548+ .iter()
6549+ .zip(want)
6550+ .filter(|&(&a, &b)| a as u8 != b)
6551+ .count();
58026552 assert_eq!(
58036553 bad, 0,
58046554 "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \
@@ -5807,7 +6557,10 @@ pub(crate) mod tests {
58076557 }
58086558 }
58096559 } else {
5810- eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display());
6560+ eprintln!(
6561+ "SKIP {NAME} aomdec arm: no oracle aomdec at {}",
6562+ aomdec_path().display()
6563+ );
58116564 }
58126565
58136566 // ffmpeg's decoder: same frames, full-resolution chroma.
@@ -5819,7 +6572,10 @@ pub(crate) mod tests {
58196572 .enumerate()
58206573 {
58216574 let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
5822- assert_eq!(bad, 0, "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ");
6575+ assert_eq!(
6576+ bad, 0,
6577+ "{NAME}: ffmpeg frame {i} plane {p}: {bad} samples differ"
6578+ );
58236579 }
58246580 }
58256581 } else {
@@ -5878,9 +6634,8 @@ pub(crate) mod tests {
58786634 let _guard = lock_gate_counters();
58796635 let before = crate::decode::intra_sb128_hits();
58806636 let before_replay = crate::decode::sb128rect_chroma_replay_hits();
5881- let frames = decode_stream(&stream).unwrap_or_else(|e| {
5882- panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")
5883- });
6637+ let frames = decode_stream(&stream)
6638+ .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}"));
58846639 let (horz, vert, _) = crate::decode::intra_sb128_hits();
58856640 assert!(
58866641 horz - before.0 + (vert - before.1) > 0,
@@ -5937,8 +6692,7 @@ pub(crate) mod tests {
59376692
59386693 // The oracle aomdec, rawvideo out: FRAMES concatenated yuv444p frames.
59396694 if aomdec_path().is_file() {
5940- let dir =
5941- std::env::temp_dir().join(format!("ec-av1-444sb-{}", std::process::id()));
6695+ let dir = std::env::temp_dir().join(format!("ec-av1-444sb-{}", std::process::id()));
59426696 let _ = std::fs::remove_dir_all(&dir);
59436697 std::fs::create_dir_all(&dir).expect("scratch dir");
59446698 let raw = dir.join("aomdec.raw");
@@ -5961,14 +6715,16 @@ pub(crate) mod tests {
59616715 assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size");
59626716 for (i, f) in frames.iter().enumerate().take(3) {
59636717 let base = i * W * H * 3;
5964- for ((plane, off), p) in
5965- [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)]
5966- .into_iter()
5967- .zip(["y", "u", "v"])
6718+ for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)]
6719+ .into_iter()
6720+ .zip(["y", "u", "v"])
59686721 {
59696722 let want = &ref_raw[base + off..base + off + W * H];
5970- let bad =
5971- plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count();
6723+ let bad = plane
6724+ .iter()
6725+ .zip(want)
6726+ .filter(|&(&a, &b)| a as u8 != b)
6727+ .count();
59726728 assert_eq!(
59736729 bad, 0,
59746730 "{NAME}: aomdec frame {i} plane {p}: {bad} samples differ \
@@ -5977,7 +6733,10 @@ pub(crate) mod tests {
59776733 }
59786734 }
59796735 } else {
5980- eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display());
6736+ eprintln!(
6737+ "SKIP {NAME} aomdec arm: no oracle aomdec at {}",
6738+ aomdec_path().display()
6739+ );
59816740 }
59826741
59836742 // ffmpeg's decoder: same frames, full-resolution chroma. Same
@@ -5985,10 +6744,9 @@ pub(crate) mod tests {
59856744 if have_ffmpeg() {
59866745 let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES);
59876746 for (i, (got, want)) in frames.iter().zip(refs.iter()).enumerate().take(3) {
5988- for (p, (g, r)) in
5989- [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)]
5990- .iter()
5991- .enumerate()
6747+ for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)]
6748+ .iter()
6749+ .enumerate()
59926750 {
59936751 let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
59946752 assert_eq!(
@@ -6050,8 +6808,8 @@ pub(crate) mod tests {
60506808 assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved");
60516809
60526810 let _guard = lock_gate_counters();
6053- let serial = decode_stream(&stream)
6054- .unwrap_or_else(|e| panic!("{NAME}: serial decode failed: {e}"));
6811+ let serial =
6812+ decode_stream(&stream).unwrap_or_else(|e| panic!("{NAME}: serial decode failed: {e}"));
60556813 assert_eq!(serial.len(), FRAMES, "{NAME}: frame count");
60566814
60576815 let pipe_before = crate::decode::pipeline_taken_frames();
@@ -6087,8 +6845,9 @@ pub(crate) mod tests {
60876845 // frame -- including frame 2, the 128-root-rect inter frame the
60886846 // r2 defect named.
60896847 for (i, (s, p)) in serial.iter().zip(piped.iter()).enumerate() {
6090- for (pl, (a, b)) in
6091- [(&s.y, &p.y), (&s.u, &p.u), (&s.v, &p.v)].into_iter().enumerate()
6848+ for (pl, (a, b)) in [(&s.y, &p.y), (&s.u, &p.u), (&s.v, &p.v)]
6849+ .into_iter()
6850+ .enumerate()
60926851 {
60936852 assert_eq!(
60946853 a, b,
@@ -6123,13 +6882,16 @@ pub(crate) mod tests {
61236882 assert_eq!(ref_raw.len(), W * H * 3 * FRAMES, "{NAME}: aomdec raw size");
61246883 for (i, f) in piped.iter().enumerate().take(2) {
61256884 let base = i * W * H * 3;
6126- for ((plane, off), p) in
6127- [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)]
6128- .into_iter()
6129- .zip(["y", "u", "v"])
6885+ for ((plane, off), p) in [(&f.y, 0usize), (&f.u, W * H), (&f.v, 2 * W * H)]
6886+ .into_iter()
6887+ .zip(["y", "u", "v"])
61306888 {
61316889 let want = &ref_raw[base + off..base + off + W * H];
6132- let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count();
6890+ let bad = plane
6891+ .iter()
6892+ .zip(want)
6893+ .filter(|&(&a, &b)| a as u8 != b)
6894+ .count();
61336895 assert_eq!(
61346896 bad, 0,
61356897 "{NAME}: aomdec frame {i} plane {p} THROUGH THE PIPELINE: \
@@ -6138,15 +6900,17 @@ pub(crate) mod tests {
61386900 }
61396901 }
61406902 } else {
6141- eprintln!("SKIP {NAME} aomdec arm: no oracle aomdec at {}", aomdec_path().display());
6903+ eprintln!(
6904+ "SKIP {NAME} aomdec arm: no oracle aomdec at {}",
6905+ aomdec_path().display()
6906+ );
61426907 }
61436908 if have_ffmpeg() {
61446909 let refs = ffmpeg_decode_sequence_444(&stream, W, H, FRAMES);
61456910 for (i, (got, want)) in piped.iter().zip(refs.iter()).enumerate().take(2) {
6146- for (p, (g, r)) in
6147- [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)]
6148- .iter()
6149- .enumerate()
6911+ for (p, (g, r)) in [(&got.y, &want.y), (&got.u, &want.u), (&got.v, &want.v)]
6912+ .iter()
6913+ .enumerate()
61506914 {
61516915 let bad = g.iter().zip(r.iter()).filter(|(a, b)| a != b).count();
61526916 assert_eq!(
@@ -6203,9 +6967,8 @@ pub(crate) mod tests {
62036967
62046968 let _guard = lock_gate_counters();
62056969 let strips_before = decode::inter16_rect4_counters();
6206- let frames = decode_stream(&stream).unwrap_or_else(|e| {
6207- panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")
6208- });
6970+ let frames = decode_stream(&stream)
6971+ .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}"));
62096972 let strips_after = decode::inter16_rect4_counters();
62106973 assert_eq!(frames.len(), FRAMES, "{NAME}: frame count");
62116974 for f in &frames {
@@ -6256,7 +7019,11 @@ pub(crate) mod tests {
62567019 .zip(["y", "u", "v"])
62577020 {
62587021 let want = &ref_raw[base + off..base + off + W * H];
6259- let bad = plane.iter().zip(want).filter(|&(&a, &b)| a as u8 != b).count();
7022+ let bad = plane
7023+ .iter()
7024+ .zip(want)
lanes/av1ibc128chunk.report.mdadded+327 -0
@@ -0,0 +1,327 @@
1+# lane-av1-ibc128chunk — the 128-root intrabc strip's square-cut mu-chunk chroma walk, de-square-cut and WITNESSED
2+
3+Branch `lane-av1-ibc128chunk`, parent `a7d22aec`. Target dir
4+`$HOME/.cache/cargo-target-av1ibc128chunk` throughout. No push.
5+
6+## Verdict
7+
8+The deferred copy is fixed **and witnessed** — this is not a defensive fix.
9+`decode_intrabc_128rect` cut each mu chunk's chroma plane block with
10+`chunk_chroma = cside * 64 / side` (two sites, decode.rs:12663 and decode.rs:12896
11+at the parent), the same square-cut defect lane-av1-422bigblock fixed and
12+witnessed in `decode_inter_block` and `decode_block_128rect`. Red before: a real
13+4:2:2 `aomenc --enable-intrabc` sb128 stream loses half of every mu chunk's
14+chroma units and its frames 0 and 3 diverge from `aomdec`, first difference at
15+the top-left corner of the very first 128x64 intrabc block. Green after: the
16+same stream decodes all five frames byte-identical to `aomdec --rawvideo`, and
17+the red build's 4 lost blocks are recovered.
18+
19+Both pinned witnesses are committed; committed code still refuses 4:2:2 at the
20+sequence header and the `EC_AV1_ALLOW_422_PROBE` bypass was applied and
21+reverted per probe run (`git diff` on the refusal line is empty; the only
22+`EC_AV1_ALLOW_422_PROBE` strings left in the tree are two doc-comment mentions
23+of the recipe).
24+
25+## The defect (both sites)
26+
27+`decode_intrabc_128rect` is the intrabc arm of `decode_block_128rect`: a
28+128x64 / 64x128 / 128x128 strip coded with `use_intrabc`, predicted from this
29+frame's own reconstruction, reconstructed through the INTER residual walk
30+(`decode_token_recon_block`'s else arm).
31+
32+A 64x64 mu chunk's chroma plane block is **per-axis** `(64 >> ss_x) x
33+(64 >> ss_y)`: 32x32 at 4:2:0 (one TX_32X32 per plane per chunk), **32x64 at
34+4:2:2 (TWO STACKED TX_32X32 per plane per chunk)**, 64x64 at 4:4:4 (four).
35+`av1_get_max_uv_txsize` caps the unit at 32 on each axis. The square-cut model
36+walked a `chroma_side`-square chunk, i.e. the 4:2:0 count on both axes.
37+
38+Measured consequences at 4:2:2 (witness below):
39+
40+1. **Half the units.** One chroma unit per plane per chunk instead of two
41+ stacked — the chunk's lower 32 chroma rows got no residual at all.
42+2. **Wrong extent, twice.** The block's own chroma plane block was still
43+ `bw / 2 x bh / 2` (`cpx, cpy = px / 2, py / 2`), i.e. 4:2:0-shaped, even
44+ though the same function's two `mv_to_q4(cpy, dv_row, ss_y(fctx))` calls
45+ already scaled the DV on the y axis by **its own** subsampling — the
46+ prediction window was half as tall as the motion vector asked for.
47+3. **Wrong entropy spans.** `around_mi` / `record_mi_chroma` stamped every unit
48+ over a `unit_luma = cu_tx * (side / cside)` = 16x16-mi luma square instead
49+ of the per-axis 16x8 at 4:2:2, and the `mu_chroma` per-unit replay walked a
50+ 32-row step down a 64-row chunk.
51+4. **Entropy lock lost.** The halved unit count desynced the tile: the red build
52+ decoded 2 of the stream's 6 intrabc blocks; the fixed build decodes all 6.
53+
54+## The fix (mirror of the two witnessed twins)
55+
56+Both sites, per-axis, in the same expression shape
57+`decode_inter_block` already carries:
58+
59+| old | new |
60+|---|---|
61+| `let (cpx, cpy) = (px / 2, py / 2);` | `(px >> ss_x(fctx), py >> ss_y(fctx))` |
62+| `let (cw, ch) = (bw / 2, bh / 2);` | `(bw >> ss_x(fctx), bh >> ss_y(fctx))` |
63+| `let chunk_chroma = cside * 64 / side;` | `chunk_chroma_w = (64usize) >> ss_x(fctx)` / `chunk_chroma_h = (64usize) >> ss_y(fctx)` |
64+| `let unit_luma = cu_tx * (side / cside);` | `unit_luma_w = cu_tx << ss_x(fctx)` / `unit_luma_h = cu_tx << ss_y(fctx)` |
65+| `units_x/y = chunk_*_mi / (unit_luma / MI)` | same, on `unit_luma_w` / `unit_luma_h` |
66+| `around_mi(unit_mi, unit_luma)` | `around_mi_rect(unit_mi, unit_luma_w, unit_luma_h)` |
67+| `record_mi_chroma(unit_mi, unit_luma, unit_luma, ..)` | `.. unit_luma_w, unit_luma_h, ..` |
68+| `cu_x = cpx + cc * chunk_chroma + uc * cu_tx` | `.. cc * chunk_chroma_w + ..` |
69+| `cu_y = cpy + cr * chunk_chroma + ur * cu_tx` | `.. cr * chunk_chroma_h + ..` |
70+| `cu_pred` / composed-grid `dst` offsets | per-axis offsets at the square `cside` stride |
71+| `read_inter_chroma_lossless(.., (cc*cc_, cr*cc_), (cc_, cc_), ..)` | per-axis org and region |
72+| replay `unit_luma = cu * 2` | `unit_luma_w = cu << ss_x(fctx)` / `unit_luma_h = cu << ss_y(fctx)` |
73+| replay `ch / chunk_chroma`, `cw / chunk_chroma` | `ch / chunk_chroma_h`, `cw / chunk_chroma_w` |
74+| `EC_IBC128_BANDS` trace spans | per-axis |
75+
76+New counters (both exported from `stream` and printed by `decode_probe`):
77+`INTRABC_128RECT_CHROMA_CHUNK_HITS` (one bump per chroma `read_inter_plane` of
78+this walk) and `INTRABC_128RECT_CHUNK_SHAPE`
79+(`(64 >> ss_x) << 8 | (64 >> ss_y)` of the last chunk walked).
80+
81+## Fixtures (pinned, `git add -f`; `fixtures/` is gitignored)
82+
83+| fixture | bytes | sha256 | fnv1a64 |
84+|---|---|---|---|
85+| `422_intrabc_sb128_strip.obu` | 1672 | `f92000db86df7acc577d60dd1d0d97454bff4705799ea59d9de34eb5a71dbbcd` | `0x50f5cfc576e4cd00` |
86+| `422_intrabc_sb128_strip_notxsearch.obu` | 1675 | `80dd0d4e93fd6c3d4b7188a43e69d9638f2bece38edfab60ff3582628314b5ec` | `0xd4936f252ff8cff0` |
87+
88+Source (the deterministic `geq` sinusoid the tree's own sb128 intrabc-rect gate
89+uses, re-cut at `yuv422p` — the 4:2:2 twin of that gate's arm 1):
90+
91+ ffmpeg -v error -f lavfi -i "nullsrc=size=384x320:rate=25,format=yuv420p,\
92+ geq=lum='128+90*sin((X+2*N)/37)+30*sin(Y/29)':\
93+ cb='128+30*sin(X/23)':cr='128+30*sin((Y+N)/19)'" \
94+ -pix_fmt yuv422p -strict -1 -t 0.2 -f yuv4mpegpipe -y geq/384x320.y4m
95+
96+ ~/.cache/aom-oracle/build/aomenc --codec=av1 --i422 --profile=2 --passes=1 \
97+ --end-usage=q --cq-level=32 --cpu-used=0 --threads=1 --row-mt=0 \
98+ --lag-in-frames=0 --kf-max-dist=1 --limit=5 --tile-columns=0 --sb-size=128 \
99+ --min-partition-size=64 --enable-rect-partitions=1 --enable-ab-partitions=0 \
100+ --enable-1to4-partitions=0 --enable-palette=0 --tune-content=screen \
101+ --enable-intrabc=1 --deltaq-mode=0 --enable-tx-size-search=1 \
102+ --obu -o geq/384x320_cq32_ts1.obu geq/384x320.y4m
103+
104+`_notxsearch` is the same command with `--enable-tx-size-search=0`. Both are
105+pinned and both are red-before / green-after (the tx-size-search arm is not
106+required — a mis-signed flag on a witness is a coin flip, so both went in).
107+
108+## Red before / green after (measured)
109+
110+`aomdec` is `~/.cache/aom-oracle/build/aomdec`; ours is `decode_probe` (debug,
111+`--features gate-counters`) on the `EC_AV1_ALLOW_422_PROBE` patch-run-restore
112+build, compared with `cmp` on the full raw output.
113+
114+| fixture | build | 128-root blocks | chroma units stamped | vs `aomdec` |
115+|---|---|---|---|---|
116+| `422_intrabc_sb128_strip.obu` | parent `a7d22aec` | **2** | **8** | **DIFF** |
117+| `422_intrabc_sb128_strip.obu` | this lane | **6** | **48** | **EXACT** (5/5 frames) |
118+| `422_intrabc_sb128_strip_notxsearch.obu` | parent `a7d22aec` | **2** | **8** | **DIFF** |
119+| `422_intrabc_sb128_strip_notxsearch.obu` | this lane | **6** | **48** | **EXACT** |
120+
121+Frame-level detail, per fixture (245760 samples/frame: 384x320 Y + 2 x 192x320
122+chroma), re-measured per fixture after review — the first cut of this section
123+reported the `_notxsearch` arm's counts under the primary witness:
124+
125+| fixture | build | f0 | f1 | f2 | f3 | f4 |
126+|---|---|---|---|---|---|---|
127+| `422_intrabc_sb128_strip.obu` (primary) | parent `a7d22aec` | **46891** | 0 | 0 | **44842** | 0 |
128+| `422_intrabc_sb128_strip.obu` (primary) | this lane | 0 | 0 | 0 | 0 | 0 |
129+| `422_intrabc_sb128_strip_notxsearch.obu` | parent `a7d22aec` | **45135** | 0 | 0 | **44540** | 0 |
130+| `422_intrabc_sb128_strip_notxsearch.obu` | this lane | 0 | 0 | 0 | 0 | 0 |
131+
132+Both fixtures' red first difference is byte 98368 = frame 0, Y **row 256,
133+col 64** — the top-left of the first 128x64 intrabc block (traced at
134+`mi_row=64 mi_col=0`, `py = 64*4 = 256`). Frames 1, 2, 4 carry no intrabc
135+block and are exact in every build. Green: `cmp` identical on all
136+245760 x 5 bytes, 5 frames decoded, 0 hidden.
137+
138+The red build reached only 2 of the 6 blocks: reading 4 chroma units where
139+libaom codes 8 desynced the tile, and the remaining 4 blocks were misparsed.
140+Recovering them is the green signal, not just the pixel count.
141+
142+`EC_ECDUMP` per-unit stamps on the primary witness, red vs fixed, same entropy
143+position (`rng=49296` at the first block in both):
144+
145+ red 4 stamps (1 per plane per chunk, 2 chunks)
146+ fixed 8 stamps (2 per plane per chunk, 2 chunks)
147+
148+## Rework after review (r2) — the `mu_chroma` replay's chunk/unit step
149+
150+Review r1 FAILed the first cut on a real coverage regression I introduced, and
151+corrected this report's red counts (done above; the 45135/44540 pair was the
152+`_notxsearch` arm, the primary's are 46891/44842).
153+
154+**The defect.** The first cut gave the replay per-axis *extents* but kept the
155+old *step*: `rows`/`cols` count mu CHUNKS (`ch / chunk_chroma_h`), while the
156+loop body advanced the mi origin and read the grid PER UNIT
157+(`cr * (unit_luma_h / MI)`, grid `(cr * chunk_chroma_h)`). Those agree only when
158+a chunk holds exactly one unit. At 4:2:0 (`chunk_chroma == cu == 32`) it is
159+line-identical to the parent, so nothing measured it; at 4:2:2
160+(`chunk_chroma_h = 64 = 2 * cu`) the body reached only the FIRST of the two
161+stacked units per chunk, so rows `mi_r+8 .. mi_r+16` kept the composed-grid
162+smearing the replay exists to undo. The parent reached those rows (with a wrong
163+span but full coverage), so this was a coverage regression *my* patch added,
164+not a pre-existing gap.
165+
166+**The reshape**, in the twin's chunk-then-unit loop
167+(`decode_inter_block`'s `mu_chroma_units`, decode.rs:37456-37494,
168+lane-av1-444 c8):
169+
170+ let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu);
171+ for cr in 0..rows { for cc in 0..cols {
172+ for kr in 0..ur { for kc in 0..uc {
173+ unit_mi = (mi_r + (cr * 64 + kr * unit_luma_h) / MI,
174+ mi_c + (cc * 64 + kc * unit_luma_w) / MI);
175+ (cy, cx) = (cr * chunk_chroma_h + kr * cu, cc * chunk_chroma_w + kc * cu);
176+ ... let start = (cy + rr) * cside + cx;
177+
178+`cr * 64` is the mu chunk's LUMA-px step, which is 64 on both axes at every
179+subsampling — that is why the twin can write it unshifted. At 4:2:0 `ur`/`uc`
180+are 1, so `kr`/`kc` are 0, `unit_mi` collapses to `mi_r + cr*16`, and the grid
181+origin to `(cr*32, cc*32)`: **line-identical to the pre-rework walk**. The new
182+gate pins the shape, and the mutation proof below shows it is load-bearing.
183+
184+**The LOSSLESS arm is pre-existing and deliberately untouched.** On a lossless
185+frame `cu` is 4 and the composed grid is a raster of TX_4x4 units, so the
186+chunk-counted `rows`/`cols` do not enumerate it at all: that arm re-stamps only
187+the 4x4 at each chunk's top-left with a 2x2-mi span. The twin raster-walks the
188+whole plane block instead (lane-av1-llinter). It is left as-is on purpose: it is
189+a **4:2:0** defect, not a subsampling square-cut, so it is out of this lane's
190+class, and fixing it would change 4:2:0 LOSSLESS output — which this lane's
191+byte-identity requirement forbids doing on a reconstruction I have no witness
192+to verify. Measured unreachability: a temporary env-gated counter in the arm
193+records **0 hits across the whole `lossless` and `intrabc` gate battery**
194+(13 + 19 tests). Unblock: one lossless sb128 4:2:0 stream coding a NON-SKIP
195+128-root intrabc strip (`--lossless=1 --sb-size=128 --min-partition-size=64
196+--enable-rect-partitions=1 --enable-intrabc=1` over near-match screen
197+content), then the twin's raster reshape plus a witness. Carried as a named pre-existing,
198+not as a silent skip.
199+
200+**Re-measured after the reshape (r2):** both witnesses byte-identical to
201+`a7d22aec`-relative tip r1's output (6 blocks, 48 chroma units, 5/5 frames exact
202+vs `aomdec`) — the reshape is a pure coverage repair, no output change on any
203+witness. `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact`,
204+`an_sb128_screen_stream_with_intrabc_decodes_pixel_exact`,
205+`a_lossless_sb128_rect_intra_block_decodes_sample_exact`,
206+`a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact`,
207+`the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name` and both new
208+gates: **7 passed / 0 failed**. Two mutation proofs on the source-scan arm,
209+both FAILING it: forcing `let (ur, uc) = (1, 1);` (the per-chunk-only shape)
210+gives `found 0`; re-introducing `cside * 64 / side` at the read-walk site gives
211+`left: 1, right: 0`. Restored, the gate passes.
212+
213+## Reproduce (patch-run-restore, local only)
214+
215+ python3 - <<'EOF'
216+ p='crates/ec-av1/src/stream.rs'; s=open(p).read()
217+ s=s.replace(" if seq.subsampling_x != seq.subsampling_y {",
218+ " if seq.subsampling_x != seq.subsampling_y && !crate::envflags::env_flag!(\"EC_AV1_ALLOW_422_PROBE\") {",1)
219+ open(p,'w').write(s)
220+ EOF
221+ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1ibc128chunk \
222+ cargo build -p ec-av1 --example decode_probe --features gate-counters
223+ EC_AV1_ALLOW_422_PROBE=1 EC_ECDUMP=1 \
224+ $HOME/.cache/cargo-target-av1ibc128chunk/debug/examples/decode_probe \
225+ crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu 2>&1 | grep -c EC_IBC128_STAMP
226+ -> 48 (parent: 8)
227+ EC_AV1_ALLOW_422_PROBE=1 EC_PROBE_OUT=/tmp/ours.raw \
228+ $HOME/.cache/cargo-target-av1ibc128chunk/debug/examples/decode_probe \
229+ crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu
230+ ~/.cache/aom-oracle/build/aomdec --rawvideo -o /tmp/oracle.raw \
231+ crates/ec-av1/fixtures/422_intrabc_sb128_strip.obu
232+ cmp /tmp/ours.raw /tmp/oracle.raw # identical
233+ git checkout -- crates/ec-av1/src/stream.rs
234+
235+## Gates
236+
237+- `the_pinned_422_intrabc_sb128_strip_witnesses_refuse_by_name` (stream.rs) —
238+ both fixtures' byte pins (`len` + `fnv1a64`) and the unconditional
239+ refusal-by-name contract. The decode-level assertions above cannot run in
240+ committed code (the 4:2:2 refusal stands), so they are probe-measured and
241+ reproducible from the recipe; this is the same split
242+ `the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name` uses.
243+- `the_intrabc_128rect_chroma_chunk_walk_stays_per_axis` (stream.rs) — the
244+ source-scan arm. Scans `decode_intrabc_128rect`'s body **with comments
245+ stripped** (the fix's own comments quote the old expression to say what it
246+ was) and pins: zero `cside * 64 / side`; the `chunk_chroma_w/h` pair at
247+ **both** de-square-cut sites (read walk and `mu_chroma` replay); the replay's
248+ chunk-then-unit shape (`let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w /
249+ cu);`, `for kr in 0..ur {`, `for kc in 0..uc {` — the r2 coverage fix); the
250+ `unit_luma_w/h`, `cw/ch`, `cpx/cpy` and `around_mi_rect` forms once each; the
251+ replay's own `cu << ss` pair; the per-axis unit arithmetic
252+ (`(64>>ss_x)/32 * (64>>ss_y)/32` = 1 / 2 / 4 at 4:2:0 / 4:2:2 / 4:4:4); and
253+ both new counter accessors. **Non-vacuity measured twice**: forcing
254+ `let (ur, uc) = (1, 1);` (the per-chunk-only shape) fails it with
255+ `found 0`, and re-introducing `let chunk_chroma_w = cside * 64 / side;` at
256+ the read-walk site fails it with `left: 1, right: 0`; restored, it passes.
257+
258+## Byte-identity outside 4:2:2
259+
260+- `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact` — **green**, and it
261+ is the right gate: same deterministic `geq` recipe as the witness, at
262+ `yuv420p` / `yuv420p10le`, all three arms decode-order pixel-exact vs the
263+ oracle with `intrabc_128rect_hits=+14 / +1 / +15` (30 blocks through the
264+ changed walk, `skip=false`, real residual reads). At ss (1,1) every new
265+ expression reduces to the old constant: `64 >> 1 = 32`, `32 << 1 = 64`,
266+ `bw >> 1 = bw / 2`, 16x16-mi spans.
267+- `an_sb128_screen_stream_with_intrabc_decodes_pixel_exact` — green (8 arms,
268+ 4-6 intrabc blocks each).
269+- `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact` — green.
270+- `a_lossless_sb128_rect_intra_block_decodes_sample_exact` — green.
271+- `a_real_aomenc_intrabc_mixed_vartx_tree_decodes_without_the_mixed_leaf_refusal`
272+ and `a_real_aomenc_screen_key_frame_reads_use_intrabc_on_rect_strips` — green.
273+- `the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name` — green
274+ (the twin lane's fixtures are untouched).
275+- Scoped battery: `intrabc` filter 19 passed / 0 failed / 1 ignored;
276+ `422` + `444` filters 12 passed / 0 failed. `cargo check -p ec-av1
277+ --all-targets`: 0 warnings.
278+
279+**DISCLOSED 4:4:4 behavior change.** At ss (0,0) the walk now codes FOUR
280+TX_32X32 units per mu chunk per plane (1x1 -> 2x2) where the parent coded one,
281+and the block's chroma plane block is now luma-sized (`bw x bh`) instead of
282+`bw/2 x bh/2`. This is the same disclosure lane-av1-422bigblock made for
283+`decode_block_128rect`: the parent's walk was **provably wrong** at ss (0,0) —
284+`cside = (side/2).max(...)` is the 4:2:0 half-side, so the old 32x32 chunk
285+covered a quarter of a 64x64 4:4:4 chroma chunk and the origin `px/2` was off by
286+half a superblock. Unlike that lane, this one also changes the *block* shape at
287+4:4:4 (`cw/ch`, `cpx/cpy`), so the ticket's "spans are equal at (0,0)"
288+premise does not hold for this function, whose extents were 4:2:0-hardcoded
289+throughout. Measured unreachability: **no committed 4:4:4 fixture engages
290+`decode_intrabc_128rect` at all** (`ibc128=0` on all six 4:4:4 fixtures
291+including `444_sb128rect_lr_witness.obu` and `ll444_ibc_rect.obu`), so no
292+green gate covers or contradicts the change; it is landed on the same geometry
293+argument that the two reviewed twins landed on, and the 4:4:4 route needs its
294+own witness (`aomenc --i444 --profile=1 --sb-size=128 --enable-rect-partitions=1
295+--enable-intrabc=1` over content that makes aomenc take a 128-root PARTITION_NONE
296+or HORZ/VERT strip — no committed 4:4:4 fixture does).
297+
298+## Hunt recipe sweep (what was tried before the hit)
299+
300+`--profile=2 --sb-size=128 --enable-intrabc=1` at 4:2:2, all with
301+`--i422`, `--tune-content=screen`, `--enable-palette=0`, `--passes=1`,
302+`--lag-in-frames=0`, `--kf-max-dist=1`, `--min-partition-size=8`,
303+`--max-partition-size=128`, `--enable-rect-partitions=1`,
304+`--enable-1to4-partitions=1`:
305+
306+- **lavfi `testsrc2 / smptebars / mandelbrot / life / rgbtestsrc /
307+ smptehdbars`, 128x128 and 256x256/384x256/512x256/128x128, `cpu-used` 0/2/3/4,
308+ `cq-level` 15-60, 2x2/3x2/4x4 `tile=`** (24 encodes + 24 x 2 x 8 = ~400
309+ encodes): 9 streams reached `decode_intrabc_128rect`; **all 9 reached it with
310+ a frame that was ALREADY desynced** before the block. The blocker is
311+ pre-existing and unrelated: at 4:2:2 a chroma tx unit goes non-square
312+ (TX_16X8 etc.) and the merged tree does not read the `tx_type` the oracle
313+ codes for it — first divergence on `c_testsrc2_cq40.obu` at coefficient unit
314+ **4** (plane 1, `mi_row=0 mi_col=0`, `tx_size=5` = TX_16X8: the oracle emits
315+ `tx_type` after `all_zero` where ours goes straight to `eob`, rng 55680 /
316+ 34568 identical up to that point). **Named for its owning lane, not chased
317+ here.**
318+- **the tree's own gate recipe re-cut at `yuv422p`** (the `geq` sinusoid
319+ sources, 384x320 cq32 and 512x512 cq45, `enable-tx-size-search` 0/1): the
320+ smooth-chroma `geq` content avoids the non-square-chroma-tx defect, and both
321+ cq32 arms are the red/green witnesses above. cq20/45/55 code no 128-root
322+ intrabc block at all (`ibc128=0`), so the hit is a cq32 window, not a
323+ content accident.
324+
325+Control that clean 4:2:2 witnesses do exist on this tree (so the "already
326+desynced" arms above were a content choice, not a tree-wide wall):
327+`422_sb128_3f.obu` decodes byte-exact vs `aomdec` here.