Merge lane-av1-128rect-tail-replay-span: stamp the 128-root tail replay per axis (luma_span_h)
Browse files at this commit3 changed files +143 -4
- crates/ec-av1/src/decode.rs +62 -1
- crates/ec-av1/src/stream.rs +73 -3
- crates/ec-av1/src/tile.rs +8 -0
crates/ec-av1/src/decode.rsmodified+62 -1
| @@ -12618,6 +12618,16 @@ fn decode_intrabc_128rect( | ||
| 12618 | 12618 | // within the chunk, plane-major inside the chunk. |
| 12619 | 12619 | let cu_tx = 32usize; |
| 12620 | 12620 | let chunk_chroma = cside * 64 / side; |
| 12621 | + // lane-av1-128rectspan: SQUARE per-axis geometry -- one value | |
| 12622 | + // for both axes, which holds only while `ss_x == ss_y`. At | |
| 12623 | + // 4:2:2 a TX_32X32 chroma unit's luma footprint is | |
| 12624 | + // (64, 32), a mu chunk's chroma plane block is 32x64 (two | |
| 12625 | + // stacked units), and `units_y`/`cu_y`/`unit_mi.0` below all | |
| 12626 | + // need the same per-axis treatment | |
| 12627 | + // `decode_block_128rect`'s walk already has. 4:2:2 is refused | |
| 12628 | + // by name at the sequence header, so this arm is | |
| 12629 | + // unreachable for it today -- it is a PORT note for that | |
| 12630 | + // format, not a live defect. | |
| 12621 | 12631 | let unit_luma = cu_tx * (side / cside); |
| 12622 | 12632 | let chunk_w_mi = 16.min(max_w_mi.saturating_sub(cc * 16)); |
| 12623 | 12633 | let chunk_h_mi = 16.min(max_h_mi.saturating_sub(cr * 16)); |
| @@ -18795,6 +18805,25 @@ thread_local! { | ||
| 18795 | 18805 | /// frame's `tx_mode` is forced `ONLY_4X4`). Keeps the gate that owns this |
| 18796 | 18806 | /// shape non-vacuous -- a stream that never codes one reads 0. |
| 18797 | 18807 | pub(crate) static INTRA128_LOSSLESS_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 18808 | + /// lane-av1-128rectspan: chroma transform units of a 128-root HORZ/VERT | |
| 18809 | + /// intra block re-stamped by the end-of-block replay | |
| 18810 | + /// (`record_split_luma_rect` clobbers the per-unit contexts the chroma | |
| 18811 | + /// walk published, so every unit replays its own state after it). A | |
| 18812 | + /// non-skip 128x64/64x128 block codes `nch_x * cn * 2 + nch_y * cn_h * 2` | |
| 18813 | + /// of them, so this reads 0 on any stream that never codes one -- the | |
| 18814 | + /// non-vacuity anchor for the replay's own gate. | |
| 18815 | + pub(crate) static SB128RECT_CHROMA_REPLAY_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 18816 | + /// ... and the number of non-skip 128-root rect BLOCKS whose replay | |
| 18817 | + /// height differs from the unit's own LUMA-MI height -- the signature of the | |
| 18818 | + /// width passed to both axes (`luma_span` where the in-loop stamp used | |
| 18819 | + /// `luma_span_h`). Zero on every stream this decoder admits: both | |
| 18820 | + /// supported chroma formats have `ss_x == ss_y` (4:2:0 and 4:4:4), and | |
| 18821 | + /// 4:2:2 -- the one format whose two spans differ -- is refused by name | |
| 18822 | + /// at the sequence header (`stream::decode_frame`), so the arm is | |
| 18823 | + /// defensive until that format is ported. The counter turns a future | |
| 18824 | + /// 4:2:2 admission (or any hardcoded span) into a named red gate instead | |
| 18825 | + /// of silent mi-state corruption. | |
| 18826 | + pub(crate) static SB128RECT_REPLAY_SPAN_MISMATCH_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | |
| 18798 | 18827 | } |
| 18799 | 18828 | |
| 18800 | 18829 | /// [`SKIP_VARTX_LUMA_RESET_HITS`], for a gate's own before/after delta. |
| @@ -18822,6 +18851,17 @@ pub(crate) fn intra_sb128_hits() -> (usize, usize, [usize; 3]) { | ||
| 18822 | 18851 | ) |
| 18823 | 18852 | } |
| 18824 | 18853 | |
| 18854 | +/// [`SB128RECT_CHROMA_REPLAY_HITS`] (chroma units re-stamped by | |
| 18855 | +/// `decode_block_128rect`'s end-of-block replay) and | |
| 18856 | +/// [`SB128RECT_REPLAY_SPAN_MISMATCH_HITS`] (replays whose stamped height was | |
| 18857 | +/// not the unit's own), for a gate's own before/after delta. | |
| 18858 | +pub(crate) fn sb128rect_chroma_replay_hits() -> (usize, usize) { | |
| 18859 | + ( | |
| 18860 | + SB128RECT_CHROMA_REPLAY_HITS.with(std::cell::Cell::get), | |
| 18861 | + SB128RECT_REPLAY_SPAN_MISMATCH_HITS.with(std::cell::Cell::get), | |
| 18862 | + ) | |
| 18863 | +} | |
| 18864 | + | |
| 18825 | 18865 | /// The 128 root's HORZ/VERT arm on an INTRA frame: ONE 128x64 (HORZ) or |
| 18826 | 18866 | /// 64x128 (VERT) intra block (lane-sb128c r8; the inter twin is |
| 18827 | 18867 | /// `decode_inter_block`'s own rect path). |
| @@ -19189,8 +19229,29 @@ fn decode_block_128rect( | ||
| 19189 | 19229 | uv_predict_mode, |
| 19190 | 19230 | [&last_grids[0], &last_grids[1]], |
| 19191 | 19231 | ); |
| 19232 | + // lane-av1-128rectspan: the replay must re-stamp each unit over the | |
| 19233 | + // SAME cells the walk above stamped it over -- `record_mi_chroma`'s | |
| 19234 | + // height drives `left[]` and its width `above[]`, and the walk used | |
| 19235 | + // the per-axis `luma_span_h`. Passing the width on both axes doubled | |
| 19236 | + // the `left[]` run wherever the two differ (4:2:2), reaching 8 mi | |
| 19237 | + // rows below the block on the last unit of a 128x64/64x128 strip and | |
| 19238 | + // smearing a neighbour chunk's unit over its neighbour's rows. | |
| 19239 | + // | |
| 19240 | + // DEFENSIVE at the decoder's current capability set: both admitted | |
| 19241 | + // chroma formats have `ss_x == ss_y` (4:2:0 ss (1,1), 4:4:4 ss | |
| 19242 | + // (0,0)), so the two spans are equal and this line is a no-op on | |
| 19243 | + // every stream `decode_stream` accepts; 4:2:2 (ss (1,0)) -- the one | |
| 19244 | + // format where they differ -- is refused by name at the sequence | |
| 19245 | + // header, so the arm is unreachable there. It stays per-axis because | |
| 19246 | + // the walk it replays is per-axis, and a 4:2:2 port must not have to | |
| 19247 | + // re-derive this. `SB128RECT_REPLAY_SPAN_MISMATCH_HITS` names the | |
| 19248 | + // day that changes. | |
| 19249 | + if luma_span != luma_span_h { | |
| 19250 | + hit!(SB128RECT_REPLAY_SPAN_MISMATCH_HITS); | |
| 19251 | + } | |
| 19192 | 19252 | for (plane, cu_mi, grid) in &units { |
| 19193 | - neighbours.record_mi_chroma(*cu_mi, luma_span, luma_span, *plane, grid); | |
| 19253 | + neighbours.record_mi_chroma(*cu_mi, luma_span, luma_span_h, *plane, grid); | |
| 19254 | + hit!(SB128RECT_CHROMA_REPLAY_HITS); | |
| 19194 | 19255 | } |
| 19195 | 19256 | } |
| 19196 | 19257 | // No palette exists at this size; the unconditional stamp clears any |
crates/ec-av1/src/stream.rsmodified+73 -3
| @@ -260,6 +260,15 @@ pub fn intra128_lossless_counters() -> usize { | ||
| 260 | 260 | crate::decode::intra128_lossless_hits() |
| 261 | 261 | } |
| 262 | 262 | |
| 263 | +/// lane-av1-128rectspan: chroma transform units re-stamped by | |
| 264 | +/// `decode_block_128rect`'s end-of-block replay, and how many of those | |
| 265 | +/// replays stamped a height that was not the unit's own (the 4:2:2 signature | |
| 266 | +/// -- zero on every stream this decoder admits, since 4:2:2 is refused by | |
| 267 | +/// name at the sequence header). | |
| 268 | +pub fn sb128rect_chroma_replay_counters() -> (usize, usize) { | |
| 269 | + crate::decode::sb128rect_chroma_replay_hits() | |
| 270 | +} | |
| 271 | + | |
| 263 | 272 | /// lane-sb128c r9: the four AB shapes at the 128 root, in `PARTITION_HORZ_A`, |
| 264 | 273 | /// `_HORZ_B`, `_VERT_A`, `_VERT_B` order (key and inter tile paths share the |
| 265 | 274 | /// counter -- it is bumped where the root symbol resolves). |
| @@ -5868,6 +5877,7 @@ pub(crate) mod tests { | ||
| 5868 | 5877 | |
| 5869 | 5878 | let _guard = lock_gate_counters(); |
| 5870 | 5879 | let before = crate::decode::intra_sb128_hits(); |
| 5880 | + let before_replay = crate::decode::sb128rect_chroma_replay_hits(); | |
| 5871 | 5881 | let frames = decode_stream(&stream).unwrap_or_else(|e| { |
| 5872 | 5882 | panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") |
| 5873 | 5883 | }); |
| @@ -5877,6 +5887,35 @@ pub(crate) mod tests { | ||
| 5877 | 5887 | "{NAME}: this stream coded NO 128-axis intra block -- the fixed body \ |
| 5878 | 5888 | never ran (class gate-blind-to-feature)" |
| 5879 | 5889 | ); |
| 5890 | + // lane-av1-128rectspan: the block-level `record_split_luma_rect` | |
| 5891 | + // above clobbers the per-unit chroma contexts, so every coded unit | |
| 5892 | + // replays its own state after it -- the arm the span fix sits on. | |
| 5893 | + // The delta keeps THAT arm non-vacuous (a 128-root rect stream that | |
| 5894 | + // stopped replaying reads 0), and the mismatch half is the 4:2:2 | |
| 5895 | + // signature: this stream is 4:4:4 (ss 0,0), where the unit's luma | |
| 5896 | + // width and height are equal, so a replay that stamped one axis with | |
| 5897 | + // the other's span would still read 0 here -- the counter is what | |
| 5898 | + // names the day 4:2:2 (ss 1,0, refused by name at the sequence | |
| 5899 | + // header) is admitted, rather than letting the 8-row spill below the | |
| 5900 | + // block corrupt the next block's `txb_skip` silently. | |
| 5901 | + let after_replay = crate::decode::sb128rect_chroma_replay_hits(); | |
| 5902 | + assert!( | |
| 5903 | + after_replay.0 > before_replay.0, | |
| 5904 | + "{NAME}: no 128-root rect block replayed a chroma unit's own mi state -- the \ | |
| 5905 | + replay arm never ran (class gate-blind-to-feature)" | |
| 5906 | + ); | |
| 5907 | + assert_eq!( | |
| 5908 | + after_replay.1, | |
| 5909 | + before_replay.1, | |
| 5910 | + "{NAME}: the tail replay stamped {} unit(s) over a height that was not the \ | |
| 5911 | + unit's own luma height (4:2:2 spans leaked into an admitted stream)", | |
| 5912 | + after_replay.1 - before_replay.1 | |
| 5913 | + ); | |
| 5914 | + eprintln!( | |
| 5915 | + "{NAME}: replayed {} chroma unit(s), {} span mismatch(es)", | |
| 5916 | + after_replay.0 - before_replay.0, | |
| 5917 | + after_replay.1 - before_replay.1 | |
| 5918 | + ); | |
| 5880 | 5919 | assert_eq!(frames.len(), FRAMES, "{NAME}: frame count"); |
| 5881 | 5920 | for f in &frames { |
| 5882 | 5921 | assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions"); |
| @@ -6382,9 +6421,12 @@ pub(crate) mod tests { | ||
| 6382 | 6421 | #[test] |
| 6383 | 6422 | fn a_lossless_sb128_rect_intra_block_decodes_sample_exact() { |
| 6384 | 6423 | const NAME: &str = "a_lossless_sb128_rect_intra_block_decodes_sample_exact"; |
| 6385 | - if !have_ffmpeg() { | |
| 6386 | - eprintln!("SKIP {NAME}: no ffmpeg"); | |
| 6387 | - return; | |
| 6424 | + // The pixel arm needs ffmpeg; the decode and its counter deltas do | |
| 6425 | + // not, so a box without ffmpeg still proves the shape was reached | |
| 6426 | + // (class `gate-skips-on-its-own-failure`) -- the skip is still named. | |
| 6427 | + let ffmpeg = have_ffmpeg(); | |
| 6428 | + if !ffmpeg { | |
| 6429 | + eprintln!("SKIP {NAME}: no ffmpeg -- the ffmpeg pixel arm only"); | |
| 6388 | 6430 | } |
| 6389 | 6431 | let (w, h, frames) = (320usize, 256usize, 4usize); |
| 6390 | 6432 | let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) |
| @@ -6392,6 +6434,7 @@ pub(crate) mod tests { | ||
| 6392 | 6434 | let stream = std::fs::read(&path) |
| 6393 | 6435 | .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); |
| 6394 | 6436 | let before = crate::decode::intra128_lossless_hits(); |
| 6437 | + let before_replay = crate::decode::sb128rect_chroma_replay_hits(); | |
| 6395 | 6438 | let ours = decode_stream(&stream) |
| 6396 | 6439 | .unwrap_or_else(|e| panic!("{NAME}: a lossless 128-axis key frame decodes: {e}")); |
| 6397 | 6440 | let hits = crate::decode::intra128_lossless_hits() - before; |
| @@ -6400,6 +6443,33 @@ pub(crate) mod tests { | ||
| 6400 | 6443 | "{NAME}: this stream coded NO lossless 128-axis intra block -- the fixed body \ |
| 6401 | 6444 | was never reached (class gate-blind-to-feature)" |
| 6402 | 6445 | ); |
| 6446 | + // lane-av1-128rectspan: the 4:2:0 twin of the 4:4:4 gate's replay | |
| 6447 | + // assertion. This stream codes the 64x128 block at mi(0,64) with | |
| 6448 | + // TX_4X4 chroma units, so the end-of-block replay re-stamps each of | |
| 6449 | + // them over its own luma-mi rows -- the arm the span fix sits on, on | |
| 6450 | + // the OTHER admitted ss (1,1). The mismatch half is the 4:2:2 | |
| 6451 | + // signature and reads 0 here because 4:2:2 is refused by name at the | |
| 6452 | + // sequence header; it is the tripwire for the day it is not. | |
| 6453 | + let after_replay = crate::decode::sb128rect_chroma_replay_hits(); | |
| 6454 | + assert!( | |
| 6455 | + after_replay.0 > before_replay.0, | |
| 6456 | + "{NAME}: no 128-axis block replayed a chroma unit's own mi state -- the replay \ | |
| 6457 | + arm never ran (class gate-blind-to-feature)" | |
| 6458 | + ); | |
| 6459 | + assert_eq!( | |
| 6460 | + after_replay.1, before_replay.1, | |
| 6461 | + "{NAME}: the tail replay stamped {} unit(s) over a height that was not the \ | |
| 6462 | + unit's own luma height (4:2:2 spans leaked into an admitted stream)", | |
| 6463 | + after_replay.1 - before_replay.1 | |
| 6464 | + ); | |
| 6465 | + eprintln!( | |
| 6466 | + "{NAME}: replayed {} chroma unit(s), {} span mismatch(es)", | |
| 6467 | + after_replay.0 - before_replay.0, | |
| 6468 | + after_replay.1 - before_replay.1 | |
| 6469 | + ); | |
| 6470 | + if !ffmpeg { | |
| 6471 | + return; | |
| 6472 | + } | |
| 6403 | 6473 | let refs = ffmpeg_decode_sequence(&stream, w, h, frames); |
| 6404 | 6474 | assert_eq!(ours.len(), frames, "{NAME}: decode-order frame count"); |
| 6405 | 6475 | for (i, (got, want)) in ours.iter().zip(refs.iter()).enumerate() { |
crates/ec-av1/src/tile.rsmodified+8 -0
| @@ -413,6 +413,14 @@ fn write_inter_block_128( | ||
| 413 | 413 | // libaom codes every plane of a mu chunk before moving on. The |
| 414 | 414 | // chroma `txb_skip_ctx` takes `get_txb_ctx`'s offset-10 rows |
| 415 | 415 | // (+3 here) because the uv plane block is bigger than the unit. |
| 416 | + // lane-av1-128rectspan: SQUARE per-axis geometry -- one TX_32X32 | |
| 417 | + // per 64x64 mu chunk, stamped at span 64 on BOTH axes. That is | |
| 418 | + // 4:2:0/4:4:4 only: at 4:2:2 the chunk's chroma plane block is | |
| 419 | + // 32x64 (two stacked units) with a (64, 32) luma footprint per | |
| 420 | + // unit, so `unit_mi`, the `64`-spans and the whole `CHUNKS` | |
| 421 | + // raster need the same per-axis treatment before 4:2:2 could be | |
| 422 | + // written here. Refused by name at the sequence header today, so | |
| 423 | + // this is a PORT note, not a live defect. | |
| 416 | 424 | let mut pair = [Vec::new(), Vec::new()]; |
| 417 | 425 | for plane in 1..3usize { |
| 418 | 426 | let grid = unit_of(plane, cr, cc); |