forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-av1h5'

Browse files at this commit

f0bc1ac39f3aac30f700e98bee7376d12c62555aAhmet Kaan GümüşParent: 0d240a70bb7c3c
crates/ec-av1/fixtures/ll444_128root_lossless.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/ll444_minp64_128root_control.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+129 -13
@@ -13682,7 +13682,10 @@ fn decode_intrabc_128rect(
13682 // top-left sample is outside the frame codes nothing.13682 // top-left sample is outside the frame codes nothing.
13683 let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(mi_c));13683 let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(mi_c));
13684 let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(mi_r));13684 let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(mi_r));
13685- for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() {13685+ // lane-av1h5: chunk-major token order at 128 (see [`mu_chunk_order`]).
13686+ let (order, _mu_reordered) = mu_chunk_order(&leaves, side);
13687+ for (pos, &idx) in order.iter().enumerate() {
13688+ let (row, col, tw, th) = leaves[idx];
13686 debug_assert_eq!(13689 debug_assert_eq!(
13687 tw, th,13690 tw, th,
13688 "a square TX_64X64 tree root only yields square leaves"13691 "a square TX_64X64 tree root only yields square leaves"
@@ -13720,8 +13723,8 @@ fn decode_intrabc_128rect(
13720 // are done, its chroma is read immediately (the inter 128 path's13723 // are done, its chroma is read immediately (the inter 128 path's
13721 // interleave).13724 // interleave).
13722 let chunk = (row / 16, col / 16);13725 let chunk = (row / 16, col / 16);
13723- let done = idx + 1 == leaves.len()13726+ let done = pos + 1 == order.len()
13724- || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk;13727+ || (leaves[order[pos + 1]].0 / 16, leaves[order[pos + 1]].1 / 16) != chunk;
13725 if done {13728 if done {
13726 let (cr, cc) = chunk;13729 let (cr, cc) = chunk;
13727 // `av1_get_max_uv_txsize(BLOCK_128X64)` = TX_32X32: one13730 // `av1_get_max_uv_txsize(BLOCK_128X64)` = TX_32X32: one
@@ -19782,6 +19785,7 @@ impl PlaneBuf<'_> {
19782 /// Reads one plane's transform block, reconstructs it into `plane` at19785 /// Reads one plane's transform block, reconstructs it into `plane` at
19783 /// `(x, y)`/`side`, and records what it leaves behind in `neighbours`.19786 /// `(x, y)`/`side`, and records what it leaves behind in `neighbours`.
19784 #[allow(clippy::too_many_arguments)]19787 #[allow(clippy::too_many_arguments)]
19788+
19785 fn read_plane(19789 fn read_plane(
19786 dec: &mut SymbolDecoder,19790 dec: &mut SymbolDecoder,
19787 cdfs: &mut Cdfs,19791 cdfs: &mut Cdfs,
@@ -19834,7 +19838,9 @@ fn read_plane(
19834 // `combine_entropy_contexts(above, left)` plus 7, or plus 10 when the19838 // `combine_entropy_contexts(above, left)` plus 7, or plus 10 when the
19835 // plane block is bigger than the transform. Our chroma tables hold the19839 // plane block is bigger than the transform. Our chroma tables hold the
19836 // offset-7 rows first, so the caller adds 3 for the bigger-block case19840 // offset-7 rows first, so the caller adds 3 for the bigger-block case
19837- // (only a 128x128 block's TX_32X32 chroma units, lane-sb128b r3).19841+ // (every chroma unit of a plane block above TX_4X4 -- lane-sb128b r3,
19842+ // and lane-av1h5 measured the 4:4:4 lossless 128 root's TX_4X4 chroma
19843+ // units reading the offset-10 rows too, against aomdec's `EC_DBGCTX`).
19838 usize::from(around.0) + usize::from(around.1) + luma_skip_ctx.unwrap_or(0)19844 usize::from(around.0) + usize::from(around.1) + luma_skip_ctx.unwrap_or(0)
19839 };19845 };
19840 // spec 5.11.47/libaom `av1_read_tx_type`: a filter-intra luma block's19846 // spec 5.11.47/libaom `av1_read_tx_type`: a filter-intra luma block's
@@ -32298,6 +32304,41 @@ thread_local! {
32298 pub(crate) static CHROMA_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };32304 pub(crate) static CHROMA_SPLIT_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
32299 }32305 }
32300 32306
32307+thread_local! {
32308+ /// lane-av1h5: how many blocks had their leaf walk actually PERMUTED into
32309+ /// libaom's chunk-major order by [`mu_chunk_order`] -- a block above 64
32310+ /// whose sort was not a no-op. Deliberately not "took the order": a
32311+ /// no-op ordering change must read 0 so a gate cannot look armed.
32312+ pub(crate) static MU_CHUNK_ORDER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
32313+ /// lane-av1h5: chunk-major chroma WALKS run for a 128-root plane block --
32314+ /// one per 64x64 mu chunk. libaom codes exactly 4 per unsplit 128x128 root
32315+ /// (`decode_token_recon_block`'s chunk loop), so a stream whose 128 roots
32316+ /// can be counted pins this exactly; the pre-fix redundancy read 64.
32317+ pub(crate) static MU_CHUNK_WALKS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
32318+ /// lane-av1h5: chroma transform units those walks read. On the pinned
32319+ /// 128x96 4:4:4 lossless stream, 1536 per inter frame (768 per plane),
32320+ /// against the oracle's 1536.
32321+ pub(crate) static MU_CHUNK_WALK_UNITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
32322+}
32323+
32324+/// [`MU_CHUNK_WALKS`], for a gate's own before/after delta.
32325+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
32326+pub(crate) fn mu_chunk_walks() -> usize {
32327+ MU_CHUNK_WALKS.with(std::cell::Cell::get)
32328+}
32329+
32330+/// [`MU_CHUNK_WALK_UNITS`], for a gate's own before/after delta.
32331+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
32332+pub(crate) fn mu_chunk_walk_units() -> usize {
32333+ MU_CHUNK_WALK_UNITS.with(std::cell::Cell::get)
32334+}
32335+
32336+/// [`MU_CHUNK_ORDER_HITS`], for a gate's own before/after delta.
32337+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
32338+pub(crate) fn mu_chunk_order_hits() -> usize {
32339+ MU_CHUNK_ORDER_HITS.with(std::cell::Cell::get)
32340+}
32341+
32301 /// [`CHROMA_SPLIT_TX_HITS`], for a gate's own before/after delta.32342 /// [`CHROMA_SPLIT_TX_HITS`], for a gate's own before/after delta.
32302 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates32343 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
32303 pub(crate) fn chroma_split_tx_hits() -> usize {32344 pub(crate) fn chroma_split_tx_hits() -> usize {
@@ -35610,6 +35651,43 @@ fn read_intra_chroma_lossless(
35610 Ok(())35651 Ok(())
35611 }35652 }
35612 35653
35654+/// lane-av1h5: the CHUNK-MAJOR token order for a block's var-tx leaf list.
35655+///
35656+/// libaom's `decode_token_recon_block` (`av1/decoder/decodeframe.c:972`)
35657+/// iterates 64x64 "mu" chunks with the PLANE loop INSIDE the chunk loop:
35658+/// `for (row..) for (col..) { for (plane..) for (blk_row..) for (blk_col..) }`,
35659+/// `blk_row`/`blk_col` restarting at the chunk origin, on a chunk grid of
35660+/// `mi_size_wide[BLOCK_64X64]` = 16 mi per axis.
35661+///
35662+/// The transform tree hands us a BLOCK-wide raster instead (32 leaves across
35663+/// at 128), whose chunk members are NOT contiguous: leaves 0..15 are chunk
35664+/// (0,0) row 0, but chunk (0,0) rows 1..15 are leaves 32..47, 64..79, ...
35665+/// Walking it as given closes each chunk every SIXTEEN leaves and codes its
35666+/// chroma sixteen times -- 64 chroma walks per 128 root where libaom codes 4,
35667+/// and 24576 chroma units per inter frame against the oracle's 1536.
35668+///
35669+/// Below 64 a block IS one chunk, so the two orders coincide and the sort is
35670+/// skipped (the returned order is the identity). `changed` is `true` only
35671+/// when the sort actually permutes the list, so a no-op ordering reads zero
35672+/// on [`MU_CHUNK_ORDER_HITS`] and cannot make a gate look armed.
35673+fn mu_chunk_order(
35674+ leaves: &[(usize, usize, usize, usize)],
35675+ side: usize,
35676+) -> (Vec<usize>, bool) {
35677+ let identity: Vec<usize> = (0..leaves.len()).collect();
35678+ if side <= 64 {
35679+ return (identity, false);
35680+ }
35681+ let nchunk = (side / 64).max(1);
35682+ let mut order = identity.clone();
35683+ order.sort_by_key(|&i| ((leaves[i].0 / 16) * nchunk + (leaves[i].1 / 16), i));
35684+ let changed = order != identity;
35685+ if changed {
35686+ hit!(MU_CHUNK_ORDER_HITS);
35687+ }
35688+ (order, changed)
35689+}
35690+
35613 /// lane-lossless2: the chroma half of a lossless INTER block. libaom's35691 /// lane-lossless2: the chroma half of a lossless INTER block. libaom's
35614 /// `read_tx_size` (`av1/decoder/decodeframe.c`) returns TX_4X4 for EVERY35692 /// `read_tx_size` (`av1/decoder/decodeframe.c`) returns TX_4X4 for EVERY
35615 /// plane of a lossless block, so the chroma plane block is a raster of 4x435693 /// plane of a lossless block, so the chroma plane block is a raster of 4x4
@@ -35650,6 +35728,13 @@ fn read_inter_chroma_lossless(
35650 // plane block is bigger than the transform and 7 when it is the35728 // plane block is bigger than the transform and 7 when it is the
35651 // transform -- our chroma tables carry the offset-10 rows at +3.35729 // transform -- our chroma tables carry the offset-10 rows at +3.
35652 let offset = (blk_w > 4 || blk_h > 4).then_some(3);35730 let offset = (blk_w > 4 || blk_h > 4).then_some(3);
35731+ // lane-av1h5: a plane block above 64 is the 128-root class, whose chroma
35732+ // libaom walks one 64x64 mu chunk at a time. Counted so a gate can pin
35733+ // the walk/unit totals exactly rather than as a floor on wrong output.
35734+ let counted_128 = blk_w > 64 || blk_h > 64;
35735+ if counted_128 {
35736+ hit!(MU_CHUNK_WALKS);
35737+ }
35653 for plane_idx in 1..3 {35738 for plane_idx in 1..3 {
35654 for rr in 0..reg_h / 4 {35739 for rr in 0..reg_h / 4 {
35655 for cc in 0..reg_w / 4 {35740 for cc in 0..reg_w / 4 {
@@ -35712,6 +35797,9 @@ fn read_inter_chroma_lossless(
35712 &cu_grid,35797 &cu_grid,
35713 );35798 );
35714 hit!(CHROMA_SPLIT_TX_HITS);35799 hit!(CHROMA_SPLIT_TX_HITS);
35800+ if counted_128 {
35801+ hit!(MU_CHUNK_WALK_UNITS);
35802+ }
35715 let dst = mu_units(35803 let dst = mu_units(
35716 if plane_idx == 1 {35804 if plane_idx == 1 {
35717 &mut *u_out35805 &mut *u_out
@@ -39332,7 +39420,14 @@ fn decode_inter_block(
39332 // own slice of the block's motion-compensated predictor.39420 // own slice of the block's motion-compensated predictor.
39333 let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);39421 let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);
39334 let mut first_tx_type = TxType::DctDct;39422 let mut first_tx_type = TxType::DctDct;
39335- for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() {39423+ // lane-av1h5: libaom's `decode_token_recon_block` walks
39424+ // 64x64 "mu" chunks with the PLANE loop inside, so at 128
39425+ // the token order is CHUNK-major; the transform tree hands
39426+ // us a BLOCK-wide raster whose chunk members are not
39427+ // contiguous. Below 128 a block IS one chunk.
39428+ let (order, _mu_reordered) = mu_chunk_order(leaves, side);
39429+ for (pos, &idx) in order.iter().enumerate() {
39430+ let (row, col, tw, th) = leaves[idx];
39336 let tu_mi = (at_mi.0 + row, at_mi.1 + col);39431 let tu_mi = (at_mi.0 + row, at_mi.1 + col);
39337 let (tu_px, tu_py) = (px + col * MI, py + row * MI);39432 let (tu_px, tu_py) = (px + col * MI, py + row * MI);
39338 let (tu_grid, tu_tx_type) = if tw == th {39433 let (tu_grid, tu_tx_type) = if tw == th {
@@ -39408,8 +39503,9 @@ fn decode_inter_block(
39408 // is a single chunk and this never fires.39503 // is a single chunk and this never fires.
39409 if side > 64 {39504 if side > 64 {
39410 let chunk = (row / 16, col / 16);39505 let chunk = (row / 16, col / 16);
39411- let done = idx + 1 == leaves.len()39506+ let done = pos + 1 == order.len()
39412- || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk;39507+ || (leaves[order[pos + 1]].0 / 16, leaves[order[pos + 1]].1 / 16)
39508+ != chunk;
39413 if done {39509 if done {
39414 let (cr, cc) = chunk;39510 let (cr, cc) = chunk;
39415 // `av1_get_max_uv_txsize(BLOCK_128X128)` =39511 // `av1_get_max_uv_txsize(BLOCK_128X128)` =
@@ -41093,7 +41189,22 @@ fn decode_inter_block(
41093 // own slice of the block's motion-compensated predictor.41189 // own slice of the block's motion-compensated predictor.
41094 let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);41190 let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);
41095 let mut first_tx_type = TxType::DctDct;41191 let mut first_tx_type = TxType::DctDct;
41096- for (idx, &(row, col, tw, th)) in leaves.iter().enumerate() {41192+ // lane-av1h5: libaom's `decode_token_recon_block` walks the
41193+ // block in 64x64 "mu" CHUNKS and codes EVERY PLANE of a
41194+ // chunk before the next one starts, so at 128 the token
41195+ // order is CHUNK-major. The transform tree hands us a
41196+ // BLOCK-wide raster (32 mi across here), whose chunk
41197+ // members are not contiguous: `leaves` 0..15 are chunk
41198+ // (0,0) row 0, but chunk (0,0) rows 1..15 are leaves
41199+ // 32..47, 64..79, ... Walking it as given closed the
41200+ // "chunk" every 16 leaves and coded each chunk's chroma
41201+ // sixteen times -- 64 chroma walks per 128 root where
41202+ // libaom codes 4 (measured against aomdec's `EC_DBGCTX`:
41203+ // 24576 chroma units per inter frame vs 1536). Below 128 a
41204+ // block IS one chunk and the two orders coincide.
41205+ let (order, _mu_reordered) = mu_chunk_order(leaves, side);
41206+ for (pos, &idx) in order.iter().enumerate() {
41207+ let (row, col, tw, th) = leaves[idx];
41097 let tu_mi = (at_mi.0 + row, at_mi.1 + col);41208 let tu_mi = (at_mi.0 + row, at_mi.1 + col);
41098 let (tu_px, tu_py) = (px + col * MI, py + row * MI);41209 let (tu_px, tu_py) = (px + col * MI, py + row * MI);
41099 let (tu_grid, tu_tx_type) = if tw == th {41210 let (tu_grid, tu_tx_type) = if tw == th {
@@ -41169,8 +41280,9 @@ fn decode_inter_block(
41169 // is a single chunk and this never fires.41280 // is a single chunk and this never fires.
41170 if side > 64 {41281 if side > 64 {
41171 let chunk = (row / 16, col / 16);41282 let chunk = (row / 16, col / 16);
41172- let done = idx + 1 == leaves.len()41283+ let done = pos + 1 == order.len()
41173- || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk;41284+ || (leaves[order[pos + 1]].0 / 16, leaves[order[pos + 1]].1 / 16)
41285+ != chunk;
41174 if done {41286 if done {
41175 let (cr, cc) = chunk;41287 let (cr, cc) = chunk;
41176 // `av1_get_max_uv_txsize(BLOCK_128X128)` =41288 // `av1_get_max_uv_txsize(BLOCK_128X128)` =
@@ -42051,7 +42163,10 @@ fn decode_inter_block(
42051 let mut v_units: Vec<i32> = Vec::new();42163 let mut v_units: Vec<i32> = Vec::new();
42052 if let Some(leaves) = vartx_leaves.as_ref() {42164 if let Some(leaves) = vartx_leaves.as_ref() {
42053 let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);42165 let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);
42054- for (idx, &(row, col, tx_px, _)) in leaves.iter().enumerate() {42166+ // lane-av1h5: chunk-major token order at 128 (see [`mu_chunk_order`]).
42167+ let (order, _mu_reordered) = mu_chunk_order(leaves, side);
42168+ for (pos, &idx) in order.iter().enumerate() {
42169+ let (row, col, tx_px, _) = leaves[idx];
42055 let tu_mi = (at_mi.0 + row, at_mi.1 + col);42170 let tu_mi = (at_mi.0 + row, at_mi.1 + col);
42056 let (tu_px, tu_py) = (px + col * MI, py + row * MI);42171 let (tu_px, tu_py) = (px + col * MI, py + row * MI);
42057 // A transform unit inside a block is not a block at that42172 // A transform unit inside a block is not a block at that
@@ -42124,8 +42239,9 @@ fn decode_inter_block(
42124 neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid);42239 neighbours.record_mi_luma(tu_mi, tx_px, &tu_grid);
42125 if side > 64 {42240 if side > 64 {
42126 let chunk = (row / 16, col / 16);42241 let chunk = (row / 16, col / 16);
42127- let done = idx + 1 == leaves.len()42242+ let done = pos + 1 == order.len()
42128- || (leaves[idx + 1].0 / 16, leaves[idx + 1].1 / 16) != chunk;42243+ || (leaves[order[pos + 1]].0 / 16, leaves[order[pos + 1]].1 / 16)
42244+ != chunk;
42129 if !done {42245 if !done {
42130 continue;42246 continue;
42131 }42247 }
crates/ec-av1/src/stream.rsmodified+178 -0
@@ -4978,6 +4978,75 @@ pub(crate) mod tests {
4978 /// this is a load-bearing-identity fingerprint for flake triage, not a4978 /// this is a load-bearing-identity fingerprint for flake triage, not a
4979 /// security digest, so no `sha2` dep is pulled in) fixture fingerprint4979 /// security digest, so no `sha2` dep is pulled in) fixture fingerprint
4980 /// for the cdf-forwarding gate's instrumentation below.4980 /// for the cdf-forwarding gate's instrumentation below.
4981+ /// Reads a pinned fixture, asserting its length and FNV first, so a
4982+ /// swapped or truncated pin fails loudly instead of silently changing
4983+ /// what the gate measures.
4984+ fn read_pin(path: &std::path::Path, len: usize, fnv: u64, name: &str) -> Vec<u8> {
4985+ let bytes = std::fs::read(path).unwrap_or_else(|e| {
4986+ panic!(
4987+ "{name}: pinned fixture {} is missing ({e}) -- the gate cannot run, \
4988+ which is a failure, not a skip",
4989+ path.display()
4990+ )
4991+ });
4992+ assert_eq!(bytes.len(), len, "{name}: fixture length moved");
4993+ assert_eq!(fnv1a64(&bytes), fnv, "{name}: fixture bytes moved");
4994+ bytes
4995+ }
4996+
4997+ /// Decodes `stream` and the oracle's `aomdec --rawvideo` output and
4998+ /// requires every sample of every frame to agree, in decode order.
4999+ fn assert_rawvideo_matches(
5000+ obu: &std::path::Path,
5001+ stream: &[u8],
5002+ name: &str,
5003+ frames: usize,
5004+ ) {
5005+ let dir = std::env::temp_dir().join(format!("ec-av1-{name}-{}", std::process::id()));
5006+ let _ = std::fs::remove_dir_all(&dir);
5007+ std::fs::create_dir_all(&dir).expect("scratch dir");
5008+ let raw = dir.join("aomdec.raw");
5009+ let out = Command::new(aomdec_path())
5010+ .args(["--codec=av1", "--rawvideo", "-o"])
5011+ .arg(&raw)
5012+ .arg(obu)
5013+ .stdin(Stdio::null())
5014+ .stdout(Stdio::piped())
5015+ .stderr(Stdio::piped())
5016+ .output()
5017+ .expect("aomdec failed to run");
5018+ assert!(
5019+ out.status.success(),
5020+ "{name}: the oracle aomdec refused the stream: {}",
5021+ String::from_utf8_lossy(&out.stderr)
5022+ );
5023+ let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output");
5024+ let _ = std::fs::remove_dir_all(&dir);
5025+ let decoded = decode_stream(stream).expect("decode for comparison");
5026+ let mut ours: Vec<u8> = Vec::with_capacity(ref_raw.len());
5027+ for f in &decoded {
5028+ for p in [&f.y, &f.u, &f.v] {
5029+ for s in p {
5030+ ours.extend_from_slice(&s.to_le_bytes());
5031+ }
5032+ }
5033+ }
5034+ assert_eq!(ours.len(), ref_raw.len(), "{name}: raw sizes differ");
5035+ assert_eq!(decoded.len(), frames, "{name}: frame count");
5036+ let first = ours
5037+ .iter()
5038+ .zip(&ref_raw)
5039+ .position(|(a, b)| a != b)
5040+ .unwrap_or(ours.len());
5041+ assert_eq!(
5042+ first,
5043+ ours.len(),
5044+ "{name}: {} bytes of decoded output differ from aomdec (first at {})",
5045+ ours.iter().zip(&ref_raw).filter(|(a, b)| a != b).count(),
5046+ first
5047+ );
5048+ }
5049+
4981 fn fnv1a64(bytes: &[u8]) -> u64 {5050 fn fnv1a64(bytes: &[u8]) -> u64 {
4982 let mut hash = 0xcbf29ce484222325u64;5051 let mut hash = 0xcbf29ce484222325u64;
4983 for &b in bytes {5052 for &b in bytes {
@@ -6624,6 +6693,115 @@ pub(crate) mod tests {
6624 }6693 }
6625 }6694 }
6626 6695
6696+ /// lane-av1h5: the 128-ROOT lossless 4:4:4 pin, and the control arm
6697+ /// that proves the 128 root is what it needs.
6698+ ///
6699+ /// Witness: testsrc2 128x96 yuv444p10le, aomenc `--profile=1 --lossless=1
6700+ /// --enable-palette=0 --enable-intrabc=0 --cpu-used=0`, 6 frames; 63429
6701+ /// bytes, sha256 `bbffb979d20d581deb271aac75b7ee779dde57c024524ed6b1389356f55ca0fa`.
6702+ /// Control: the same recipe at `--max-partition-size=64` (61494 bytes,
6703+ /// sha256 `4cadce41e1f8967567b32f5cf8abaa46ffdf4fd6d4afe784c8d99a7f6bf1ae4c`),
6704+ /// which never reaches a 128 root.
6705+ ///
6706+ /// libaom's `decode_token_recon_block` (`av1/decoder/decodeframe.c:972`)
6707+ /// walks 64x64 "mu" chunks with the PLANE loop inside the chunk loop, on a
6708+ /// chunk grid of `mi_size_wide[BLOCK_64X64]` = 16 mi per axis. The var-tx
6709+ /// leaf list is a BLOCK-wide raster (32 leaves across at 128), so a chunk's
6710+ /// members are not contiguous: leaves 0..15 are chunk (0,0) row 0, but
6711+ /// chunk (0,0) rows 1..15 are leaves 32..47, 64..79, ... A chunk test on
6712+ /// the given order closed the chunk every SIXTEEN leaves and coded each
6713+ /// chunk's chroma sixteen times.
6714+ ///
6715+ /// The three assertions below are all EXACT and all stay true when the
6716+ /// stream becomes byte-exact. None of them is a floor on wrong output:
6717+ /// a no-op [`crate::decode::mu_chunk_order`] permutation reads 0 on
6718+ /// `mu_chunk_order_hits`, so the first cannot be satisfied by a gate that
6719+ /// merely ran; the walk and unit totals are libaom's own per-chunk counts;
6720+ /// the control arm is a straight exactness assertion.
6721+ #[test]
6722+ fn a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major() {
6723+ const NAME: &str = "a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major";
6724+ const W: usize = 128;
6725+ const H: usize = 96;
6726+ const FRAMES: usize = 6;
6727+ /// 5 inter frames, one unsplit 128 root each; frame 0 splits.
6728+ const ROOTS: usize = 5;
6729+ /// libaom's chunk grid on a 128x128 root: 2x2 chunks per root.
6730+ const CHUNKS_PER_ROOT: usize = 4;
6731+ /// Chroma TX_4X4 units per inter frame: 768 per plane over 128x96.
6732+ const UNITS_PER_FRAME: usize = 1536;
6733+
6734+ let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
6735+ .join("fixtures/ll444_128root_lossless.obu");
6736+ let stream = read_pin(&obu, 63429, 0xf07d_47fc_fd51_2658, NAME);
6737+ let _guard = lock_gate_counters();
6738+ let (o0, w0, u0) = (
6739+ crate::decode::mu_chunk_order_hits(),
6740+ crate::decode::mu_chunk_walks(),
6741+ crate::decode::mu_chunk_walk_units(),
6742+ );
6743+ let frames = decode_stream(&stream)
6744+ .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}"));
6745+ let (o1, w1, u1) = (
6746+ crate::decode::mu_chunk_order_hits(),
6747+ crate::decode::mu_chunk_walks(),
6748+ crate::decode::mu_chunk_walk_units(),
6749+ );
6750+ // (1) the reorder PERMUTED each root's walk -- a no-op reads 0.
6751+ assert_eq!(
6752+ o1 - o0,
6753+ ROOTS,
6754+ "{NAME}: the chunk-major sort permuted {}/{} of the 128 roots -- a no-op \
6755+ ordering must read 0 here, so this is what makes the gate non-vacuous",
6756+ o1 - o0,
6757+ ROOTS
6758+ );
6759+ // (2) libaom's own per-chunk counts: 4 chroma walks per 128 root, and
6760+ // the 1536 chroma units an inter frame codes at 128x96 4:4:4.
6761+ assert_eq!(
6762+ w1 - w0,
6763+ ROOTS * CHUNKS_PER_ROOT,
6764+ "{NAME}: {}/{} chunk-major chroma walks; the 16x redundancy (64 per \
6765+ frame instead of 4) would read {}",
6766+ w1 - w0,
6767+ ROOTS * CHUNKS_PER_ROOT,
6768+ ROOTS * CHUNKS_PER_ROOT * 16
6769+ );
6770+ assert_eq!(
6771+ u1 - u0,
6772+ ROOTS * UNITS_PER_FRAME,
6773+ "{NAME}: {}/{} chroma units over the 128 roots; the oracle codes {} \
6774+ per inter frame and our pre-fix walk read 16x that",
6775+ u1 - u0,
6776+ ROOTS * UNITS_PER_FRAME,
6777+ UNITS_PER_FRAME
6778+ );
6779+ assert_eq!(frames.len(), FRAMES, "{NAME}: frame count");
6780+ for f in &frames {
6781+ assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions");
6782+ }
6783+
6784+ // (3) the control arm: no 128 root, and byte-exact through the oracle.
6785+ let ctrl = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
6786+ .join("fixtures/ll444_minp64_128root_control.obu");
6787+ let ctrl_stream = read_pin(
6788+ &ctrl,
6789+ 61494,
6790+ 0xf6f5_a3cb_efc7_eb10,
6791+ &format!("{NAME} control"),
6792+ );
6793+ let _ = decode_stream(&ctrl_stream)
6794+ .unwrap_or_else(|e| panic!("{NAME}: the control arm no longer decodes cleanly: {e}"));
6795+ if aomdec_path().is_file() {
6796+ assert_rawvideo_matches(&ctrl, &ctrl_stream, NAME, FRAMES);
6797+ } else {
6798+ eprintln!(
6799+ "SKIP {NAME} control aomdec arm: no oracle aomdec at {}",
6800+ aomdec_path().display()
6801+ );
6802+ }
6803+ }
6804+
6627 /// lane-av1llpredgate2: the debug-exact pin for the ss-aware6805 /// lane-av1llpredgate2: the debug-exact pin for the ss-aware
6628 /// `obmc_skip_chroma_above` decision (lane-av1-llpred2). Fixture is the6806 /// `obmc_skip_chroma_above` decision (lane-av1-llpred2). Fixture is the
6629 /// llpred/llpred2 reports' stream pinned into `fixtures/`: testsrc26807 /// llpred/llpred2 reports' stream pinned into `fixtures/`: testsrc2
lanes/av1h5.report.mdadded+255 -0
@@ -0,0 +1,255 @@
1+# lane-av1h5 — 4:4:4 lossless 10-bit, 128-root partition: localized, NOT fixed
2+
3+Handoff of H5 from `lanes/av1formatsweep.report.md`. Worktree
4+`~/.cache/wt/av1h5`, branch `lane-av1h5`, base `4155c7c7`. **Nothing
5+committed, nothing pushed** — the budget ran out mid-localization and the
6+defect is NOT fixed. Everything below is measured, not inferred.
7+
8+## 1. Witness
9+
10+```
11+ffmpeg -y -v error -f lavfi -i testsrc2=s=128x96:r=25 -frames:v 6 \
12+ -pix_fmt yuv444p10le -strict -1 -f yuv4mpegpipe /tmp/h5.y4m
13+~/.cache/aom-oracle/build/aomenc --codec=av1 --profile=1 \
14+ --input-bit-depth=10 --bit-depth=10 --lossless=1 --enable-palette=0 \
15+ --enable-intrabc=0 --cq-level=20 --cpu-used=0 --passes=1 --end-usage=q \
16+ --threads=1 --row-mt=0 --lag-in-frames=0 --kf-max-dist=100 --limit=6 \
17+ --obu -o /tmp/h5.obu /tmp/h5.y4m
18+```
19+
20+63429 bytes, **sha256 `bbffb979d20d581deb271aac75b7ee779dde57c024524ed6b1389356f55ca0fa`**,
21+6 frames, 128x96, `ss (0,0)` at 10-bit, lossless.
22+
23+## 2. The control arm (this is what makes the rest a decoder verdict)
24+
25+Same recipe, one flag changed:
26+
27+| arm | bytes | verdict vs `aomdec --rawvideo` |
28+|---|---|---|
29+| `--max-partition-size=64` (no 128 root) | 61494 | **EXACT**, all 6 frames |
30+| default (128 root reachable) | 63429 | **DIVERGES**, first at byte 74769 |
31+
32+So the comparison harness is sound on this exact content, and the 128x128
33+unsplit root is **necessary** for the defect. The sibling at `--cpu-used=2`
34+(gate B, `a_lossless_444_10bit_inter_stream_decodes_pixel_exact`) never reaches
35+the 128 root and is exact.
36+
37+## 3. First divergence
38+
39+Whole-stream `dump_yuv` (u16 LE) concatenated, compared byte-for-byte with
40+`aomdec --rawvideo`:
41+
42+* first differing byte: **74769** of the concatenation
43+* frame size is 128*96*3*2 = 73728 bytes, so this is **decode-order frame 1**,
44+ offset 1040 bytes = sample 520
45+* 520 = row 4, col 8 of the 128-wide luma plane → **first wrong sample Y(4, 8)**
46+
47+(`av1formatsweep.report.md` recorded this site as `Y(8,4)`; same site, row and
48+column transposed.)
49+
50+## 4. EC_SYMR ladder — entropy fork, not reconstruction
51+
52+Paired `EC_SYMR` traces (ours `msac.rs`, oracle `aom_dsp/bitreader.h`), aligned
53+on `(range, post_rng, s, n)`; the CDF convention reconciles as
54+`32768 - ours_icdf0 == oracle_cdf0` (verified over the first 2000 reads).
55+
56+| index | oracle | ours | |
57+|---|---|---|---|
58+| 43834-43839 | `decodetxb.c:158` n=2 s=1, cdf0 32717..32729 | icdf0 51..39, mirror matches | agree |
59+| **43840** | `decodetxb.c:158` n=2 s=1 **cdf0=32731** | icdf0=63 → mirror **32705** | **first CDF-state divergence** |
60+| 43841-43842 | cdf0 32732, 32733 | mirror 32708, 32711 | diverging |
61+| **43843** | `decodetxb.c:242` n=5 **s=3** | **s=4** | **first SYMBOL divergence** |
62+
63+* `decodetxb.c:158` is the `txb_skip` / `all_zero` read:
64+ `aom_read_symbol(r, ec_ctx->txb_skip_cdf[txs_ctx][txb_ctx->txb_skip_ctx], 2, ...)`.
65+* `decodetxb.c:242` is the EOB pass-count read, `eob_flag_cdf16[plane][ctx]`, 5 symbols.
66+* Both sides at the fork: `ph=inter`, `mi=(0,0)`, identical pre-state
67+ (`pre=(49549, 65280, …)`, range 65280).
68+
69+**Verdict: entropy fork.** The decoder selects a different `txb_skip` CDF ROW
70+for a chroma unit; the symbols happen to survive three reads and then diverge.
71+Nothing here is reconstruction arithmetic — the two decoders are reading
72+different probability distributions from the same bit position.
73+
74+
75+---
76+
77+## 9. RESOLUTION (lane-av1h5 r2, commit `8a91ee14`)
78+
79+### 9a. The handoff's suspect site is REFUTED, not fixed
80+
81+§5 named `read_plane`'s chroma band (`decode.rs:19627-19636`) and pointed at
82+`luma_skip_ctx`. I instrumented the band selection on our side (a
83+`EC_DBGCTX`-shaped rung printing `plane`, `tx`, `above0`, `left0`, `base`,
84+`off`, `ctx`) and diffed it against the oracle's own `EC_DBGCTX` for all
85+**9216** chroma units of the stream.
86+
87+**The band is correct at 100% of them.** After the port's `+7` reindex
88+(our rows 0..2 are libaom's 7..9, our 3..5 are libaom's 10..12):
89+
90+```
91+compared=9216 off/ctx diffs=0
92+```
93+
94+Frame 0 (1536 units) matches the oracle unit-for-unit. Frames 1–5 are
95+**100% `off=10`** on both sides — the 520 `off=7` units in the oracle census
96+are all frame 0 (measured with `--limit=1/2/3`: 1536 / 3072 / 4608). §5's
97+"at the fork site every chroma unit is tx=0 with off=7" was a grep that
98+matched frame 0's `mi=0,0` lines, which recur in every frame.
99+
100+So the offset term was never wrong, and no `+3` was missing. **Do not touch
101+`read_plane`'s band.** (Its doc comment, which scoped the `+3` to "a 128x128
102+block's TX_32X32 chroma units", is now corrected: the 4:4:4 lossless 128
103+root's TX_4X4 chroma units read the offset-10 rows too.)
104+
105+### 9b. The real defect: the token order at a 128 root is chunk-major
106+
107+Our chroma stream diverged from the oracle's at unit **1539** with the band
108+right and `ctx_base` wrong — a left-context that had not been published yet.
109+Instrumenting the walk that produces it (`read_inter_chroma_lossless`) with
110+its caller, region and unit geometry:
111+
112+```
113+EC_DBGCTX walk n=1536 at_mi=(0,0) org=(0,0) reg=(64,64) blk=(128,128) true=(128,96)
114+EC_DBGCTX walk n=2049 at_mi=(0,0) org=(64,0) reg=(64,64) blk=(128,128) true=(128,96)
115+EC_DBGCTX walk n=2562 at_mi=(0,0) org=(0,0) reg=(64,64) blk=(128,128) true=(128,96) <-- again
116+```
117+
118+320 walk calls for 5 inter frames — **64 per frame, where libaom codes 4** —
119+and each `chunkdone` showed `leaves=1024` (the full 32x32 mi block, not the
120+frame's 32x24) firing every 16 leaves:
121+
122+```
123+chunkdone idx=15 chunk=(0,0) at=(0,15,4,4) next=Some((0,16,4,4))
124+chunkdone idx=31 chunk=(0,1) at=(0,31,4,4) next=Some((1,0,4,4))
125+chunkdone idx=47 chunk=(0,0) at=(1,15,4,4) next=Some((1,16,4,4)) <-- back to (0,0)
126+```
127+
128+Ground truth, `decodeframe.c:972-1006`: `decode_token_recon_block` walks
129+`for (row…) for (col…) { for (plane…) { for (blk_row…) for (blk_col…) } }` —
130+the **plane loop is inside the chunk loop**, and `blk_row`/`blk_col` restart
131+at the chunk origin. The chunk grid is `mu_blocks_wide = mi_size_wide[BLOCK_64X64] = 16` mi
132+per axis, i.e. **16 mi across, not 32**.
133+
134+Our var-tx leaf list is a BLOCK-wide raster (32 leaves across at 128), so a
135+chunk's members are **not contiguous**: leaves 0..15 are chunk (0,0) row 0,
136+but chunk (0,0) rows 1..15 are leaves 32..47, 64..79, … A chunk test
137+`(leaves[idx+1].0/16, leaves[idx+1].1/16) != (row/16, col/16)` therefore
138+closed the chunk every **sixteen** leaves, and each of the four chunks' chroma
139+was coded sixteen times — 24576 chroma units per inter frame against the
140+oracle's 1536.
141+
142+Below 64 a block IS one chunk, so the two orders coincide and every committed
143+pin passed. **This is the only committed cell where an unsplit BLOCK_128X128
144+root meets lossless.**
145+
146+### 9c. The fix and the class sweep
147+
148+`grep "row / 16, col / 16"` finds **four** sites carrying the test. All four
149+now sort the leaf walk chunk-major at `side > 64` and take the successor from
150+that order:
151+
152+| site | arm |
153+|---|---|
154+| `decode.rs:13543` | inter 128x64 / 64x128 (compound/intrabc rect) |
155+| `decode.rs:39268` | intra 128 |
156+| `decode.rs:40932` | inter 128x128 (**the H5 cell**) |
157+| `decode.rs:41952` | inter vartx 128 |
158+
159+The order key is `(row/16)*nchunk + (col/16)`, ties broken by the original
160+index, so within a chunk the leaves keep the tree's own raster — which is what
161+libaom's per-chunk `blk_row`/`blk_col` walk is.
162+
163+### 9d. Measured, on the pinned fixture vs `aomdec`
164+
165+| | before | after | oracle |
166+|---|---|---|---|
167+| chroma walks / inter frame | 64 | **4** | 4 |
168+| chroma units / inter frame | 24576 | **1536** | 1536 |
169+| chroma units, whole stream | 124416 | **9216** | 9216 |
170+| first `skip_ctx` divergence | unit 1539 | unit 2573 | — |
171+| first differing pixel byte | 74769 | **90272** | — |
172+| oracle plane sequence / frame | — | 256,256,256,256,128,128,128,128 ×2 | same |
173+
174+Frame 0 is unaffected (it splits, no 128 root) and still matches the oracle
175+exactly on all 1536 chroma units.
176+
177+### 9e. Verification
178+
179+* **Identity**: `lossless_444` 6/6, `sb128` 12/12 (1 pre-existing `#[ignore]`),
180+ `420` 2/2, `vartx` 3/3, `a_real_aomenc_tiny_frame_size_sweep`,
181+ `a_sweep_of_doubly_straddling_sizes_round_trips_through_ffmpeg` all pass.
182+* **Control arm**: the same recipe at `--max-partition-size=64` (61494 B,
183+ sha256 `4cadce41e1f89675…`) decodes **byte-exact** — the 128 root is still
184+ necessary, and the fix does not touch it.
185+* **Gate**: `a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major`,
186+ pins `fixtures/ll444_128root_lossless.obu` (63429 B, sha256 `bbffb979…`,
187+ fnv1a64 `0xf07d47fcfd512658`) and
188+ `fixtures/ll444_minp64_128root_control.obu` (61494 B, sha256
189+ `4cadce41e1f89675…`, fnv1a64 `0xf6f5a3cbefc7eb10`).
190+ Three assertions, **all exact, none a floor on wrong output** (an earlier
191+ draft asserted `first-diff >= 90272`; that shape asserts our output is
192+ still wrong and would fail the day the residual lands — it was cut):
193+
194+ | # | assertion | value | why it is discriminating |
195+ |---|---|---|---|
196+ | 1 | `mu_chunk_order_hits()` rose by | **5** | counts blocks where the sort **permuted** the list, not where it ran — a no-op ordering reads 0, so a gate cannot be armed by merely executing the arm |
197+ | 2 | `mu_chunk_walks()` rose by | **20** | 4 mu chunks × 5 inter frames — libaom's own per-chunk count; the 16x redundancy would read 320 |
198+ | 3 | `mu_chunk_walk_units()` rose by | **7680** | 1536 chroma TX_4X4 units per inter frame × 5 — the oracle's exact count (pre-fix: 122880) |
199+ | 4 | control arm vs `aomdec --rawvideo` | **byte-exact** | straight exactness on the `--max-partition-size=64` stream |
200+
201+ Assertions 2 and 3 are the structural parity this fix established, read
202+ straight off libaom's walk, so they stay true when the stream becomes
203+ byte-exact.
204+* **Mutation (red-before)**: rewriting the chunk key back to a block raster
205+ (`(col/16)*1000 + c`) turns the gate **RED** at assertion 1; reverting turns
206+ it green. Both runs executed on the committed tree.
207+
208+### 9f. OPEN — the residual, handed on (not fixed by this lane)
209+
210+**The fixture is still not byte-exact.** One defect remains, and it is a
211+*different* one, below the chunk-order bug this lane fixed:
212+
213+* first difference: **byte 90272** = decode-order frame 1, sample 4136 →
214+ **Y(32, 40)** (was Y(4, 8)).
215+* first chroma `skip_ctx` divergence: global unit **2573** — frame 1, plane 1,
216+ the clipped lower chunk row.
217+* It is **not** a band/offset error (off matches at every unit) and **not**
218+ the `ctx_base`/left-context gather: at unit 2572 both sides read the SAME
219+ `skip_ctx` (11) and the oracle's unit 2572 publishes level 0 while ours
220+ publishes non-zero. So the two decoders decode *different coefficients*
221+ from an identical CDF row at 2572 — the fork is at the coefficient decode,
222+ not at context selection.
223+
224+**Type/extent is EXCLUDED** (Agent04-2, on my pinned bytes, both rungs, no
225+re-encode): every unit either side published agrees at TX_4X4 / DCT_DCT, no
226+exception anywhere in the stream. So there is no inherited-`tx_type` or
227+chroma-extent term in this defect — it is a coefficient READ / consumption
228+difference. Their caveat, which I accept: the oracle's `idct.c` rung
229+early-returns on `eob == 0`, so it is structurally blind at unit 2572 itself
230+(the oracle publishes it as cul_level 0). The strong direction holds — no
231+type or extent disagrees anywhere — but 2572 specifically needs a rung that
232+does not early-return (`EC_COEFF_STEP`, or the oracle's `decodetxb.c`
233+sequence), not `idct.c`.
234+
235+Next step for whoever takes it: re-anchor `EC_SYMR` at unit 2572, and check
236+the coefficient-read side. Handed to `agent://Agent24-2` with the byte and the
237+fact that the chroma unit COUNTS now match the oracle exactly, so the
238+residual is a per-unit VALUE, not an ordering one. §7's plan is superseded:
239+**the band is fine, the order was the bug, and this residual is neither.**
240+
241+### 9g. Interaction with H1
242+
243+Untouched and unaffected: `strip_chroma` is still `Some` only from the
244+PARTITION_HORZ_4 / VERT_4 setter, which an unsplit BLOCK_128X128 root never
245+enters. This lane's change is the leaf-walk ORDER at `side > 64`; it touches
246+no `strip_chroma` site and no chroma-context predicate, so it cannot double-fix
247+Agent04-2's arm. Their stream should be unaffected — `agent://Agent04-2` was
248+notified.
249+
250+### 9h. State
251+
252+Branch `lane-av1h5`, two commits on top of `4155c7c7`:
253+`11954074` (report as handed over, incl. §6b) and `8a91ee14` (the fix, the
254+gate, the pin). Nothing pushed. All instrumentation was env-gated and has been
255+removed from the commit; no `EC_AV1_ALLOW_422_PROBE` bypass was used or needed.