av1h5: shared mu_chunk_order helper, control pin, gate helpers
Browse files at this commit0bb7c3c8c0d2c8472478a071119c91b61406d3d7Parent: 032da643 changed files +231 -135
- crates/ec-av1/fixtures/ll444_minp64_128root_control.obu +0 -0
- crates/ec-av1/src/decode.rs +78 -48
- crates/ec-av1/src/stream.rs +153 -87
crates/ec-av1/fixtures/ll444_minp64_128root_control.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+78 -48
| @@ -13540,16 +13540,8 @@ fn decode_intrabc_128rect( | ||
| 13540 | 13540 | // top-left sample is outside the frame codes nothing. |
| 13541 | 13541 | let max_w_mi = (bw / MI).min(mi_cols.saturating_sub(mi_c)); |
| 13542 | 13542 | let max_h_mi = (bh / MI).min(mi_rows.saturating_sub(mi_r)); |
| 13543 | - // lane-av1h5: chunk-major token order at 128 (see the 128x128 arm). | |
| 13544 | - let order: Vec<usize> = if side > 64 { | |
| 13545 | - hit!(MU_CHUNK_ORDER_HITS); | |
| 13546 | - let nchunk = (side / 64).max(1); | |
| 13547 | - let mut o: Vec<usize> = (0..leaves.len()).collect(); | |
| 13548 | - o.sort_by_key(|&i| ((leaves[i].0 / 16) * nchunk + (leaves[i].1 / 16), i)); | |
| 13549 | - o | |
| 13550 | - } else { | |
| 13551 | - (0..leaves.len()).collect() | |
| 13552 | - }; | |
| 13543 | + // lane-av1h5: chunk-major token order at 128 (see [`mu_chunk_order`]). | |
| 13544 | + let (order, _mu_reordered) = mu_chunk_order(&leaves, side); | |
| 13553 | 13545 | for (pos, &idx) in order.iter().enumerate() { |
| 13554 | 13546 | let (row, col, tw, th) = leaves[idx]; |
| 13555 | 13547 | debug_assert_eq!( |
| @@ -32110,12 +32102,32 @@ thread_local! { | ||
| 32110 | 32102 | } |
| 32111 | 32103 | |
| 32112 | 32104 | thread_local! { |
| 32113 | - /// lane-av1h5: how many blocks took the CHUNK-MAJOR token order -- a | |
| 32114 | - /// block above 64 whose leaf walk was reordered into libaom's 64x64 "mu" | |
| 32115 | - /// chunks (`decode_token_recon_block`'s plane loop is INSIDE the chunk | |
| 32116 | - /// loop). One bump per such block. Below 64 a block IS one chunk and the | |
| 32117 | - /// orders coincide, so the arm stays at 0 there. | |
| 32105 | + /// lane-av1h5: how many blocks had their leaf walk actually PERMUTED into | |
| 32106 | + /// libaom's chunk-major order by [`mu_chunk_order`] -- a block above 64 | |
| 32107 | + /// whose sort was not a no-op. Deliberately not "took the order": a | |
| 32108 | + /// no-op ordering change must read 0 so a gate cannot look armed. | |
| 32118 | 32109 | pub(crate) static MU_CHUNK_ORDER_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 32110 | + /// lane-av1h5: chunk-major chroma WALKS run for a 128-root plane block -- | |
| 32111 | + /// one per 64x64 mu chunk. libaom codes exactly 4 per unsplit 128x128 root | |
| 32112 | + /// (`decode_token_recon_block`'s chunk loop), so a stream whose 128 roots | |
| 32113 | + /// can be counted pins this exactly; the pre-fix redundancy read 64. | |
| 32114 | + pub(crate) static MU_CHUNK_WALKS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 32115 | + /// lane-av1h5: chroma transform units those walks read. On the pinned | |
| 32116 | + /// 128x96 4:4:4 lossless stream, 1536 per inter frame (768 per plane), | |
| 32117 | + /// against the oracle's 1536. | |
| 32118 | + pub(crate) static MU_CHUNK_WALK_UNITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 32119 | +} | |
| 32120 | + | |
| 32121 | +/// [`MU_CHUNK_WALKS`], for a gate's own before/after delta. | |
| 32122 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | |
| 32123 | +pub(crate) fn mu_chunk_walks() -> usize { | |
| 32124 | + MU_CHUNK_WALKS.with(std::cell::Cell::get) | |
| 32125 | +} | |
| 32126 | + | |
| 32127 | +/// [`MU_CHUNK_WALK_UNITS`], for a gate's own before/after delta. | |
| 32128 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | |
| 32129 | +pub(crate) fn mu_chunk_walk_units() -> usize { | |
| 32130 | + MU_CHUNK_WALK_UNITS.with(std::cell::Cell::get) | |
| 32119 | 32131 | } |
| 32120 | 32132 | |
| 32121 | 32133 | /// [`MU_CHUNK_ORDER_HITS`], for a gate's own before/after delta. |
| @@ -35436,6 +35448,43 @@ fn read_intra_chroma_lossless( | ||
| 35436 | 35448 | Ok(()) |
| 35437 | 35449 | } |
| 35438 | 35450 | |
| 35451 | +/// lane-av1h5: the CHUNK-MAJOR token order for a block's var-tx leaf list. | |
| 35452 | +/// | |
| 35453 | +/// libaom's `decode_token_recon_block` (`av1/decoder/decodeframe.c:972`) | |
| 35454 | +/// iterates 64x64 "mu" chunks with the PLANE loop INSIDE the chunk loop: | |
| 35455 | +/// `for (row..) for (col..) { for (plane..) for (blk_row..) for (blk_col..) }`, | |
| 35456 | +/// `blk_row`/`blk_col` restarting at the chunk origin, on a chunk grid of | |
| 35457 | +/// `mi_size_wide[BLOCK_64X64]` = 16 mi per axis. | |
| 35458 | +/// | |
| 35459 | +/// The transform tree hands us a BLOCK-wide raster instead (32 leaves across | |
| 35460 | +/// at 128), whose chunk members are NOT contiguous: leaves 0..15 are chunk | |
| 35461 | +/// (0,0) row 0, but chunk (0,0) rows 1..15 are leaves 32..47, 64..79, ... | |
| 35462 | +/// Walking it as given closes each chunk every SIXTEEN leaves and codes its | |
| 35463 | +/// chroma sixteen times -- 64 chroma walks per 128 root where libaom codes 4, | |
| 35464 | +/// and 24576 chroma units per inter frame against the oracle's 1536. | |
| 35465 | +/// | |
| 35466 | +/// Below 64 a block IS one chunk, so the two orders coincide and the sort is | |
| 35467 | +/// skipped (the returned order is the identity). `changed` is `true` only | |
| 35468 | +/// when the sort actually permutes the list, so a no-op ordering reads zero | |
| 35469 | +/// on [`MU_CHUNK_ORDER_HITS`] and cannot make a gate look armed. | |
| 35470 | +fn mu_chunk_order( | |
| 35471 | + leaves: &[(usize, usize, usize, usize)], | |
| 35472 | + side: usize, | |
| 35473 | +) -> (Vec<usize>, bool) { | |
| 35474 | + let identity: Vec<usize> = (0..leaves.len()).collect(); | |
| 35475 | + if side <= 64 { | |
| 35476 | + return (identity, false); | |
| 35477 | + } | |
| 35478 | + let nchunk = (side / 64).max(1); | |
| 35479 | + let mut order = identity.clone(); | |
| 35480 | + order.sort_by_key(|&i| ((leaves[i].0 / 16) * nchunk + (leaves[i].1 / 16), i)); | |
| 35481 | + let changed = order != identity; | |
| 35482 | + if changed { | |
| 35483 | + hit!(MU_CHUNK_ORDER_HITS); | |
| 35484 | + } | |
| 35485 | + (order, changed) | |
| 35486 | +} | |
| 35487 | + | |
| 35439 | 35488 | /// lane-lossless2: the chroma half of a lossless INTER block. libaom's |
| 35440 | 35489 | /// `read_tx_size` (`av1/decoder/decodeframe.c`) returns TX_4X4 for EVERY |
| 35441 | 35490 | /// plane of a lossless block, so the chroma plane block is a raster of 4x4 |
| @@ -35476,6 +35525,13 @@ fn read_inter_chroma_lossless( | ||
| 35476 | 35525 | // plane block is bigger than the transform and 7 when it is the |
| 35477 | 35526 | // transform -- our chroma tables carry the offset-10 rows at +3. |
| 35478 | 35527 | let offset = (blk_w > 4 || blk_h > 4).then_some(3); |
| 35528 | + // lane-av1h5: a plane block above 64 is the 128-root class, whose chroma | |
| 35529 | + // libaom walks one 64x64 mu chunk at a time. Counted so a gate can pin | |
| 35530 | + // the walk/unit totals exactly rather than as a floor on wrong output. | |
| 35531 | + let counted_128 = blk_w > 64 || blk_h > 64; | |
| 35532 | + if counted_128 { | |
| 35533 | + hit!(MU_CHUNK_WALKS); | |
| 35534 | + } | |
| 35479 | 35535 | for plane_idx in 1..3 { |
| 35480 | 35536 | for rr in 0..reg_h / 4 { |
| 35481 | 35537 | for cc in 0..reg_w / 4 { |
| @@ -35538,6 +35594,9 @@ fn read_inter_chroma_lossless( | ||
| 35538 | 35594 | &cu_grid, |
| 35539 | 35595 | ); |
| 35540 | 35596 | hit!(CHROMA_SPLIT_TX_HITS); |
| 35597 | + if counted_128 { | |
| 35598 | + hit!(MU_CHUNK_WALK_UNITS); | |
| 35599 | + } | |
| 35541 | 35600 | let dst = mu_units( |
| 35542 | 35601 | if plane_idx == 1 { |
| 35543 | 35602 | &mut *u_out |
| @@ -39163,17 +39222,7 @@ fn decode_inter_block( | ||
| 39163 | 39222 | // the token order is CHUNK-major; the transform tree hands |
| 39164 | 39223 | // us a BLOCK-wide raster whose chunk members are not |
| 39165 | 39224 | // contiguous. Below 128 a block IS one chunk. |
| 39166 | - let mu_order = |leaves: &Vec<(usize, usize, usize, usize)>, side: usize| { | |
| 39167 | - if side <= 64 { | |
| 39168 | - return (0..leaves.len()).collect::<Vec<usize>>(); | |
| 39169 | - } | |
| 39170 | - let nchunk = side / 64; | |
| 39171 | - let mut o: Vec<usize> = (0..leaves.len()).collect(); | |
| 39172 | - o.sort_by_key(|&i| ((leaves[i].0 / 16) * nchunk + (leaves[i].1 / 16), i)); | |
| 39173 | - o | |
| 39174 | - }; | |
| 39175 | - let order = mu_order(leaves, side); | |
| 39176 | - hit!(MU_CHUNK_ORDER_HITS); | |
| 39225 | + let (order, _mu_reordered) = mu_chunk_order(leaves, side); | |
| 39177 | 39226 | for (pos, &idx) in order.iter().enumerate() { |
| 39178 | 39227 | let (row, col, tw, th) = leaves[idx]; |
| 39179 | 39228 | let tu_mi = (at_mi.0 + row, at_mi.1 + col); |
| @@ -40929,18 +40978,7 @@ fn decode_inter_block( | ||
| 40929 | 40978 | // libaom codes 4 (measured against aomdec's `EC_DBGCTX`: |
| 40930 | 40979 | // 24576 chroma units per inter frame vs 1536). Below 128 a |
| 40931 | 40980 | // block IS one chunk and the two orders coincide. |
| 40932 | - let nchunk = (side / 64).max(1); | |
| 40933 | - let order: Vec<usize> = if side > 64 { | |
| 40934 | - hit!(MU_CHUNK_ORDER_HITS); | |
| 40935 | - let mut o: Vec<usize> = (0..leaves.len()).collect(); | |
| 40936 | - o.sort_by_key(|&i| { | |
| 40937 | - let (r, c) = (leaves[i].0, leaves[i].1); | |
| 40938 | - ((r / 16) * nchunk + (c / 16), i) | |
| 40939 | - }); | |
| 40940 | - o | |
| 40941 | - } else { | |
| 40942 | - (0..leaves.len()).collect() | |
| 40943 | - }; | |
| 40981 | + let (order, _mu_reordered) = mu_chunk_order(leaves, side); | |
| 40944 | 40982 | for (pos, &idx) in order.iter().enumerate() { |
| 40945 | 40983 | let (row, col, tw, th) = leaves[idx]; |
| 40946 | 40984 | let tu_mi = (at_mi.0 + row, at_mi.1 + col); |
| @@ -41901,16 +41939,8 @@ fn decode_inter_block( | ||
| 41901 | 41939 | let mut v_units: Vec<i32> = Vec::new(); |
| 41902 | 41940 | if let Some(leaves) = vartx_leaves.as_ref() { |
| 41903 | 41941 | let reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); |
| 41904 | - // lane-av1h5: chunk-major token order at 128 (see the 128x128 arm). | |
| 41905 | - let order: Vec<usize> = if side > 64 { | |
| 41906 | - hit!(MU_CHUNK_ORDER_HITS); | |
| 41907 | - let nchunk = (side / 64).max(1); | |
| 41908 | - let mut o: Vec<usize> = (0..leaves.len()).collect(); | |
| 41909 | - o.sort_by_key(|&i| ((leaves[i].0 / 16) * nchunk + (leaves[i].1 / 16), i)); | |
| 41910 | - o | |
| 41911 | - } else { | |
| 41912 | - (0..leaves.len()).collect() | |
| 41913 | - }; | |
| 41942 | + // lane-av1h5: chunk-major token order at 128 (see [`mu_chunk_order`]). | |
| 41943 | + let (order, _mu_reordered) = mu_chunk_order(leaves, side); | |
| 41914 | 41944 | for (pos, &idx) in order.iter().enumerate() { |
| 41915 | 41945 | let (row, col, tx_px, _) = leaves[idx]; |
| 41916 | 41946 | let tu_mi = (at_mi.0 + row, at_mi.1 + col); |
crates/ec-av1/src/stream.rsmodified+153 -87
| @@ -4979,6 +4979,75 @@ pub(crate) mod tests { | ||
| 4979 | 4979 | /// this is a load-bearing-identity fingerprint for flake triage, not a |
| 4980 | 4980 | /// security digest, so no `sha2` dep is pulled in) fixture fingerprint |
| 4981 | 4981 | /// for the cdf-forwarding gate's instrumentation below. |
| 4982 | + /// Reads a pinned fixture, asserting its length and FNV first, so a | |
| 4983 | + /// swapped or truncated pin fails loudly instead of silently changing | |
| 4984 | + /// what the gate measures. | |
| 4985 | + fn read_pin(path: &std::path::Path, len: usize, fnv: u64, name: &str) -> Vec<u8> { | |
| 4986 | + let bytes = std::fs::read(path).unwrap_or_else(|e| { | |
| 4987 | + panic!( | |
| 4988 | + "{name}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | |
| 4989 | + which is a failure, not a skip", | |
| 4990 | + path.display() | |
| 4991 | + ) | |
| 4992 | + }); | |
| 4993 | + assert_eq!(bytes.len(), len, "{name}: fixture length moved"); | |
| 4994 | + assert_eq!(fnv1a64(&bytes), fnv, "{name}: fixture bytes moved"); | |
| 4995 | + bytes | |
| 4996 | + } | |
| 4997 | + | |
| 4998 | + /// Decodes `stream` and the oracle's `aomdec --rawvideo` output and | |
| 4999 | + /// requires every sample of every frame to agree, in decode order. | |
| 5000 | + fn assert_rawvideo_matches( | |
| 5001 | + obu: &std::path::Path, | |
| 5002 | + stream: &[u8], | |
| 5003 | + name: &str, | |
| 5004 | + frames: usize, | |
| 5005 | + ) { | |
| 5006 | + let dir = std::env::temp_dir().join(format!("ec-av1-{name}-{}", std::process::id())); | |
| 5007 | + let _ = std::fs::remove_dir_all(&dir); | |
| 5008 | + std::fs::create_dir_all(&dir).expect("scratch dir"); | |
| 5009 | + let raw = dir.join("aomdec.raw"); | |
| 5010 | + let out = Command::new(aomdec_path()) | |
| 5011 | + .args(["--codec=av1", "--rawvideo", "-o"]) | |
| 5012 | + .arg(&raw) | |
| 5013 | + .arg(obu) | |
| 5014 | + .stdin(Stdio::null()) | |
| 5015 | + .stdout(Stdio::piped()) | |
| 5016 | + .stderr(Stdio::piped()) | |
| 5017 | + .output() | |
| 5018 | + .expect("aomdec failed to run"); | |
| 5019 | + assert!( | |
| 5020 | + out.status.success(), | |
| 5021 | + "{name}: the oracle aomdec refused the stream: {}", | |
| 5022 | + String::from_utf8_lossy(&out.stderr) | |
| 5023 | + ); | |
| 5024 | + let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); | |
| 5025 | + let _ = std::fs::remove_dir_all(&dir); | |
| 5026 | + let decoded = decode_stream(stream).expect("decode for comparison"); | |
| 5027 | + let mut ours: Vec<u8> = Vec::with_capacity(ref_raw.len()); | |
| 5028 | + for f in &decoded { | |
| 5029 | + for p in [&f.y, &f.u, &f.v] { | |
| 5030 | + for s in p { | |
| 5031 | + ours.extend_from_slice(&s.to_le_bytes()); | |
| 5032 | + } | |
| 5033 | + } | |
| 5034 | + } | |
| 5035 | + assert_eq!(ours.len(), ref_raw.len(), "{name}: raw sizes differ"); | |
| 5036 | + assert_eq!(decoded.len(), frames, "{name}: frame count"); | |
| 5037 | + let first = ours | |
| 5038 | + .iter() | |
| 5039 | + .zip(&ref_raw) | |
| 5040 | + .position(|(a, b)| a != b) | |
| 5041 | + .unwrap_or(ours.len()); | |
| 5042 | + assert_eq!( | |
| 5043 | + first, | |
| 5044 | + ours.len(), | |
| 5045 | + "{name}: {} bytes of decoded output differ from aomdec (first at {})", | |
| 5046 | + ours.iter().zip(&ref_raw).filter(|(a, b)| a != b).count(), | |
| 5047 | + first | |
| 5048 | + ); | |
| 5049 | + } | |
| 5050 | + | |
| 4982 | 5051 | fn fnv1a64(bytes: &[u8]) -> u64 { |
| 4983 | 5052 | let mut hash = 0xcbf29ce484222325u64; |
| 4984 | 5053 | for &b in bytes { |
| @@ -6625,113 +6694,110 @@ pub(crate) mod tests { | ||
| 6625 | 6694 | } |
| 6626 | 6695 | } |
| 6627 | 6696 | |
| 6628 | - /// lane-av1h5: the 128-ROOT lossless 4:4:4 pin. testsrc2 128x96 | |
| 6629 | - /// yuv444p10le, aomenc `--profile=1 --lossless=1 --enable-palette=0 | |
| 6630 | - /// --enable-intrabc=0 --cpu-used=0`, 6 frames; 63429 bytes, sha256 | |
| 6631 | - /// `bbffb979d20d581deb271aac75b7ee779dde57c024524ed6b1389356f55ca0fa`. | |
| 6697 | + /// lane-av1h5: the 128-ROOT lossless 4:4:4 pin, and the control arm | |
| 6698 | + /// that proves the 128 root is what it needs. | |
| 6699 | + /// | |
| 6700 | + /// Witness: testsrc2 128x96 yuv444p10le, aomenc `--profile=1 --lossless=1 | |
| 6701 | + /// --enable-palette=0 --enable-intrabc=0 --cpu-used=0`, 6 frames; 63429 | |
| 6702 | + /// bytes, sha256 `bbffb979d20d581deb271aac75b7ee779dde57c024524ed6b1389356f55ca0fa`. | |
| 6703 | + /// Control: the same recipe at `--max-partition-size=64` (61494 bytes, | |
| 6704 | + /// sha256 `4cadce41e1f8967567b32f5cf8abaa46ffdf4fd6d4afe784c8d99a7f6bf1ae4c`), | |
| 6705 | + /// which never reaches a 128 root. | |
| 6632 | 6706 | /// |
| 6633 | - /// This is the only committed cell where an UNSPLIT `BLOCK_128X128` root | |
| 6634 | - /// meets lossless, and the only one that reaches libaom's 64x64 "mu" chunk | |
| 6635 | - /// walk (`decode_token_recon_block`, decodeframe.c:972: the PLANE loop is | |
| 6636 | - /// INSIDE the chunk loop). The var-tx leaf list is a BLOCK-wide raster, so | |
| 6637 | - /// its chunk members are not contiguous: leaf 0..15 is chunk (0,0) row 0, | |
| 6638 | - /// but chunk (0,0) rows 1..15 are leaves 32..47, 64..79, ... A chunk test | |
| 6639 | - /// on the given order therefore closed the chunk every SIXTEEN leaves and | |
| 6640 | - /// coded each chunk's chroma sixteen times -- 64 chroma walks per root | |
| 6641 | - /// where libaom codes 4, and 24576 chroma units per inter frame against | |
| 6642 | - /// the oracle's 1536. | |
| 6707 | + /// libaom's `decode_token_recon_block` (`av1/decoder/decodeframe.c:972`) | |
| 6708 | + /// walks 64x64 "mu" chunks with the PLANE loop inside the chunk loop, on a | |
| 6709 | + /// chunk grid of `mi_size_wide[BLOCK_64X64]` = 16 mi per axis. The var-tx | |
| 6710 | + /// leaf list is a BLOCK-wide raster (32 leaves across at 128), so a chunk's | |
| 6711 | + /// members are not contiguous: leaves 0..15 are chunk (0,0) row 0, but | |
| 6712 | + /// chunk (0,0) rows 1..15 are leaves 32..47, 64..79, ... A chunk test on | |
| 6713 | + /// the given order closed the chunk every SIXTEEN leaves and coded each | |
| 6714 | + /// chunk's chroma sixteen times. | |
| 6643 | 6715 | /// |
| 6644 | - /// The gate pins the corrected route ([`crate::decode::mu_chunk_order_hits`] | |
| 6645 | - /// must fire) and the first-difference position against `aomdec`'s | |
| 6646 | - /// rawvideo. Reverting the reorder moves that position from 90273 back to | |
| 6647 | - /// 74769, so the byte arm is the mutation witness. | |
| 6716 | + /// The three assertions below are all EXACT and all stay true when the | |
| 6717 | + /// stream becomes byte-exact. None of them is a floor on wrong output: | |
| 6718 | + /// a no-op [`crate::decode::mu_chunk_order`] permutation reads 0 on | |
| 6719 | + /// `mu_chunk_order_hits`, so the first cannot be satisfied by a gate that | |
| 6720 | + /// merely ran; the walk and unit totals are libaom's own per-chunk counts; | |
| 6721 | + /// the control arm is a straight exactness assertion. | |
| 6648 | 6722 | #[test] |
| 6649 | 6723 | fn a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major() { |
| 6650 | 6724 | const NAME: &str = "a_lossless_444_128_root_lossless_stream_reads_chunks_chunk_major"; |
| 6651 | - const FIXTURE_LEN: usize = 63429; | |
| 6652 | - const FIXTURE_FNV: u64 = 0xf07d_47fc_fd51_2658; | |
| 6653 | - /// First differing byte of the u16-LE YUV concatenation, measured | |
| 6654 | - /// against `aomdec --rawvideo` with the chunk-major reorder in place. | |
| 6655 | - /// The block-wide raster reaches 74769; the residual defect below it | |
| 6656 | - /// is tracked in `lanes/av1h5.report.md` and is NOT what this gate | |
| 6657 | - /// holds. | |
| 6658 | - const FIRST_DIFF_FROM: usize = 90272; | |
| 6659 | 6725 | const W: usize = 128; |
| 6660 | 6726 | const H: usize = 96; |
| 6661 | 6727 | const FRAMES: usize = 6; |
| 6728 | + /// 5 inter frames, one unsplit 128 root each; frame 0 splits. | |
| 6729 | + const ROOTS: usize = 5; | |
| 6730 | + /// libaom's chunk grid on a 128x128 root: 2x2 chunks per root. | |
| 6731 | + const CHUNKS_PER_ROOT: usize = 4; | |
| 6732 | + /// Chroma TX_4X4 units per inter frame: 768 per plane over 128x96. | |
| 6733 | + const UNITS_PER_FRAME: usize = 1536; | |
| 6734 | + | |
| 6662 | 6735 | let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) |
| 6663 | 6736 | .join("fixtures/ll444_128root_lossless.obu"); |
| 6664 | - let stream = std::fs::read(&obu).unwrap_or_else(|e| { | |
| 6665 | - panic!( | |
| 6666 | - "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | |
| 6667 | - which is a failure, not a skip", | |
| 6668 | - obu.display() | |
| 6669 | - ) | |
| 6670 | - }); | |
| 6671 | - assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | |
| 6672 | - assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | |
| 6673 | - | |
| 6737 | + let stream = read_pin(&obu, 63429, 0xf07d_47fc_fd51_2658, NAME); | |
| 6674 | 6738 | let _guard = lock_gate_counters(); |
| 6675 | - let before = crate::decode::mu_chunk_order_hits(); | |
| 6676 | - let frames = decode_stream(&stream).unwrap_or_else(|e| { | |
| 6677 | - panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | |
| 6678 | - }); | |
| 6679 | - let hits = crate::decode::mu_chunk_order_hits(); | |
| 6680 | - assert!( | |
| 6681 | - hits > before, | |
| 6682 | - "{NAME}: gate is vacuous -- no block took the chunk-major token order \ | |
| 6683 | - (delta {before} -> {hits})" | |
| 6739 | + let (o0, w0, u0) = ( | |
| 6740 | + crate::decode::mu_chunk_order_hits(), | |
| 6741 | + crate::decode::mu_chunk_walks(), | |
| 6742 | + crate::decode::mu_chunk_walk_units(), | |
| 6743 | + ); | |
| 6744 | + let frames = decode_stream(&stream) | |
| 6745 | + .unwrap_or_else(|e| panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")); | |
| 6746 | + let (o1, w1, u1) = ( | |
| 6747 | + crate::decode::mu_chunk_order_hits(), | |
| 6748 | + crate::decode::mu_chunk_walks(), | |
| 6749 | + crate::decode::mu_chunk_walk_units(), | |
| 6750 | + ); | |
| 6751 | + // (1) the reorder PERMUTED each root's walk -- a no-op reads 0. | |
| 6752 | + assert_eq!( | |
| 6753 | + o1 - o0, | |
| 6754 | + ROOTS, | |
| 6755 | + "{NAME}: the chunk-major sort permuted {}/{} of the 128 roots -- a no-op \ | |
| 6756 | + ordering must read 0 here, so this is what makes the gate non-vacuous", | |
| 6757 | + o1 - o0, | |
| 6758 | + ROOTS | |
| 6759 | + ); | |
| 6760 | + // (2) libaom's own per-chunk counts: 4 chroma walks per 128 root, and | |
| 6761 | + // the 1536 chroma units an inter frame codes at 128x96 4:4:4. | |
| 6762 | + assert_eq!( | |
| 6763 | + w1 - w0, | |
| 6764 | + ROOTS * CHUNKS_PER_ROOT, | |
| 6765 | + "{NAME}: {}/{} chunk-major chroma walks; the 16x redundancy (64 per \ | |
| 6766 | + frame instead of 4) would read {}", | |
| 6767 | + w1 - w0, | |
| 6768 | + ROOTS * CHUNKS_PER_ROOT, | |
| 6769 | + ROOTS * CHUNKS_PER_ROOT * 16 | |
| 6770 | + ); | |
| 6771 | + assert_eq!( | |
| 6772 | + u1 - u0, | |
| 6773 | + ROOTS * UNITS_PER_FRAME, | |
| 6774 | + "{NAME}: {}/{} chroma units over the 128 roots; the oracle codes {} \ | |
| 6775 | + per inter frame and our pre-fix walk read 16x that", | |
| 6776 | + u1 - u0, | |
| 6777 | + ROOTS * UNITS_PER_FRAME, | |
| 6778 | + UNITS_PER_FRAME | |
| 6684 | 6779 | ); |
| 6685 | 6780 | assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); |
| 6686 | 6781 | for f in &frames { |
| 6687 | 6782 | assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); |
| 6688 | 6783 | } |
| 6689 | 6784 | |
| 6785 | + // (3) the control arm: no 128 root, and byte-exact through the oracle. | |
| 6786 | + let ctrl = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | |
| 6787 | + .join("fixtures/ll444_minp64_128root_control.obu"); | |
| 6788 | + let ctrl_stream = read_pin( | |
| 6789 | + &ctrl, | |
| 6790 | + 61494, | |
| 6791 | + 0xf6f5_a3cb_efc7_eb10, | |
| 6792 | + &format!("{NAME} control"), | |
| 6793 | + ); | |
| 6794 | + let _ = decode_stream(&ctrl_stream) | |
| 6795 | + .unwrap_or_else(|e| panic!("{NAME}: the control arm no longer decodes cleanly: {e}")); | |
| 6690 | 6796 | if aomdec_path().is_file() { |
| 6691 | - let dir = std::env::temp_dir().join(format!("ec-av1-ll444root-{}", std::process::id())); | |
| 6692 | - let _ = std::fs::remove_dir_all(&dir); | |
| 6693 | - std::fs::create_dir_all(&dir).expect("scratch dir"); | |
| 6694 | - let raw = dir.join("aomdec.raw"); | |
| 6695 | - let out = Command::new(aomdec_path()) | |
| 6696 | - .args(["--codec=av1", "--rawvideo", "-o"]) | |
| 6697 | - .arg(&raw) | |
| 6698 | - .arg(&obu) | |
| 6699 | - .stdin(Stdio::null()) | |
| 6700 | - .stdout(Stdio::piped()) | |
| 6701 | - .stderr(Stdio::piped()) | |
| 6702 | - .output() | |
| 6703 | - .expect("aomdec failed to run"); | |
| 6704 | - assert!( | |
| 6705 | - out.status.success(), | |
| 6706 | - "{NAME}: the oracle aomdec refused the stream: {}", | |
| 6707 | - String::from_utf8_lossy(&out.stderr) | |
| 6708 | - ); | |
| 6709 | - let ref_raw = std::fs::read(&raw).expect("aomdec rawvideo output"); | |
| 6710 | - let _ = std::fs::remove_dir_all(&dir); | |
| 6711 | - // u16 LE, the concatenation `decode_probe` writes. | |
| 6712 | - let mut ours: Vec<u8> = Vec::with_capacity(ref_raw.len()); | |
| 6713 | - for f in &frames { | |
| 6714 | - for p in [&f.y, &f.u, &f.v] { | |
| 6715 | - for s in p { | |
| 6716 | - ours.extend_from_slice(&s.to_le_bytes()); | |
| 6717 | - } | |
| 6718 | - } | |
| 6719 | - } | |
| 6720 | - assert_eq!(ours.len(), ref_raw.len(), "{NAME}: raw sizes differ"); | |
| 6721 | - let first = ours | |
| 6722 | - .iter() | |
| 6723 | - .zip(&ref_raw) | |
| 6724 | - .position(|(a, b)| a != b) | |
| 6725 | - .unwrap_or(ours.len()); | |
| 6726 | - assert!( | |
| 6727 | - first >= FIRST_DIFF_FROM, | |
| 6728 | - "{NAME}: the chunk-major token order regressed -- first differing \ | |
| 6729 | - byte is {first}, the block-wide raster reached {FIRST_DIFF_FROM} \ | |
| 6730 | - or earlier (pre-fix this stream first differed at 74769)" | |
| 6731 | - ); | |
| 6797 | + assert_rawvideo_matches(&ctrl, &ctrl_stream, NAME, FRAMES); | |
| 6732 | 6798 | } else { |
| 6733 | 6799 | eprintln!( |
| 6734 | - "SKIP {NAME} aomdec arm: no oracle aomdec at {}", | |
| 6800 | + "SKIP {NAME} control aomdec arm: no oracle aomdec at {}", | |
| 6735 | 6801 | aomdec_path().display() |
| 6736 | 6802 | ); |
| 6737 | 6803 | } |