forge
Explore
Log in

Don't you dare go Hollow

ec-av1: stamp the 128-root tail replay per axis

Browse files at this commit

8fb4cf6c7c491e79318ff7008d8baf9edc672406Ahmet Kaan GümüşParent: bdf5b5e
`decode_block_128rect`'s end-of-block replay re-stamped every coded
chroma transform unit with the block's LUMA WIDTH on both axes, while
the walk that read those units stamped them with the per-axis height
(`luma_span_h`). `record_mi_chroma`'s height drives the `left[]` rows,
so wherever the two spans differ the replay reached 8 mi rows past the
block's own extent on its last unit. At 4:2:2 (ss 1,0, luma spans
64x32) that is exactly the shape's tall axis; 4:2:0 (ss 1,1) and 4:4:4
(ss 0,0) have equal spans, so the line is a no-op on every stream this
decoder admits and 4:2:2 -- the one format where they differ -- is
refused by name at the sequence header.

The comment at the site pins that, and `SB128RECT_CHROMA_REPLAY_HITS` /
`SB128RECT_REPLAY_SPAN_MISMATCH_HITS` make the arm and the 4:2:2
signature observable: the 4:4:4 superblock-128 rect gate and the 4:2:0
lossless superblock-128 rect gate now assert the replay fired (32 and
512 chroma units on their pinned streams) with no span mismatch.

Two same-class sites are marked, not fixed: `decode_intrabc_128rect`'s
chroma walk and the tile 128-root writer both hardcode a square
per-axis chroma unit (one TX_32X32 per 64x64 mu chunk at span 64 on
both axes). That is a 4:2:2 port, not a one-line span fix, and it is
unreachable while the format is refused.
crates/ec-av1/src/decode.rsmodified+62 -1
@@ -12618,6 +12618,16 @@ fn decode_intrabc_128rect(
12618 // within the chunk, plane-major inside the chunk.12618 // within the chunk, plane-major inside the chunk.
12619 let cu_tx = 32usize;12619 let cu_tx = 32usize;
12620 let chunk_chroma = cside * 64 / side;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 let unit_luma = cu_tx * (side / cside);12631 let unit_luma = cu_tx * (side / cside);
12622 let chunk_w_mi = 16.min(max_w_mi.saturating_sub(cc * 16));12632 let chunk_w_mi = 16.min(max_w_mi.saturating_sub(cc * 16));
12623 let chunk_h_mi = 16.min(max_h_mi.saturating_sub(cr * 16));12633 let chunk_h_mi = 16.min(max_h_mi.saturating_sub(cr * 16));
@@ -18795,6 +18805,25 @@ thread_local! {
18795 /// frame's `tx_mode` is forced `ONLY_4X4`). Keeps the gate that owns this18805 /// frame's `tx_mode` is forced `ONLY_4X4`). Keeps the gate that owns this
18796 /// shape non-vacuous -- a stream that never codes one reads 0.18806 /// shape non-vacuous -- a stream that never codes one reads 0.
18797 pub(crate) static INTRA128_LOSSLESS_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };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 times that replay stamped a unit's state over a
18817+ /// height other than 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 /// [`SKIP_VARTX_LUMA_RESET_HITS`], for a gate's own before/after delta.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 /// The 128 root's HORZ/VERT arm on an INTRA frame: ONE 128x64 (HORZ) or18865 /// The 128 root's HORZ/VERT arm on an INTRA frame: ONE 128x64 (HORZ) or
18826 /// 64x128 (VERT) intra block (lane-sb128c r8; the inter twin is18866 /// 64x128 (VERT) intra block (lane-sb128c r8; the inter twin is
18827 /// `decode_inter_block`'s own rect path).18867 /// `decode_inter_block`'s own rect path).
@@ -19189,8 +19229,29 @@ fn decode_block_128rect(
19189 uv_predict_mode,19229 uv_predict_mode,
19190 [&last_grids[0], &last_grids[1]],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 for (plane, cu_mi, grid) in &units {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 // No palette exists at this size; the unconditional stamp clears any19257 // 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 crate::decode::intra128_lossless_hits()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 /// lane-sb128c r9: the four AB shapes at the 128 root, in `PARTITION_HORZ_A`,272 /// lane-sb128c r9: the four AB shapes at the 128 root, in `PARTITION_HORZ_A`,
264 /// `_HORZ_B`, `_VERT_A`, `_VERT_B` order (key and inter tile paths share the273 /// `_HORZ_B`, `_VERT_A`, `_VERT_B` order (key and inter tile paths share the
265 /// counter -- it is bumped where the root symbol resolves).274 /// counter -- it is bumped where the root symbol resolves).
@@ -5868,6 +5877,7 @@ pub(crate) mod tests {
5868 5877
5869 let _guard = lock_gate_counters();5878 let _guard = lock_gate_counters();
5870 let before = crate::decode::intra_sb128_hits();5879 let before = crate::decode::intra_sb128_hits();
5880+ let before_replay = crate::decode::sb128rect_chroma_replay_hits();
5871 let frames = decode_stream(&stream).unwrap_or_else(|e| {5881 let frames = decode_stream(&stream).unwrap_or_else(|e| {
5872 panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")5882 panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")
5873 });5883 });
@@ -5877,6 +5887,35 @@ pub(crate) mod tests {
5877 "{NAME}: this stream coded NO 128-axis intra block -- the fixed body \5887 "{NAME}: this stream coded NO 128-axis intra block -- the fixed body \
5878 never ran (class gate-blind-to-feature)"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 assert_eq!(frames.len(), FRAMES, "{NAME}: frame count");5919 assert_eq!(frames.len(), FRAMES, "{NAME}: frame count");
5881 for f in &frames {5920 for f in &frames {
5882 assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions");5921 assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions");
@@ -6382,9 +6421,12 @@ pub(crate) mod tests {
6382 #[test]6421 #[test]
6383 fn a_lossless_sb128_rect_intra_block_decodes_sample_exact() {6422 fn a_lossless_sb128_rect_intra_block_decodes_sample_exact() {
6384 const NAME: &str = "a_lossless_sb128_rect_intra_block_decodes_sample_exact";6423 const NAME: &str = "a_lossless_sb128_rect_intra_block_decodes_sample_exact";
6385- if !have_ffmpeg() {6424+ // The pixel arm needs ffmpeg; the decode and its counter deltas do
6386- eprintln!("SKIP {NAME}: no ffmpeg");6425+ // not, so a box without ffmpeg still proves the shape was reached
6387- return;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 let (w, h, frames) = (320usize, 256usize, 4usize);6431 let (w, h, frames) = (320usize, 256usize, 4usize);
6390 let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))6432 let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
@@ -6392,6 +6434,7 @@ pub(crate) mod tests {
6392 let stream = std::fs::read(&path)6434 let stream = std::fs::read(&path)
6393 .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));6435 .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
6394 let before = crate::decode::intra128_lossless_hits();6436 let before = crate::decode::intra128_lossless_hits();
6437+ let before_replay = crate::decode::sb128rect_chroma_replay_hits();
6395 let ours = decode_stream(&stream)6438 let ours = decode_stream(&stream)
6396 .unwrap_or_else(|e| panic!("{NAME}: a lossless 128-axis key frame decodes: {e}"));6439 .unwrap_or_else(|e| panic!("{NAME}: a lossless 128-axis key frame decodes: {e}"));
6397 let hits = crate::decode::intra128_lossless_hits() - before;6440 let hits = crate::decode::intra128_lossless_hits() - before;
@@ -6400,6 +6443,33 @@ pub(crate) mod tests {
6400 "{NAME}: this stream coded NO lossless 128-axis intra block -- the fixed body \6443 "{NAME}: this stream coded NO lossless 128-axis intra block -- the fixed body \
6401 was never reached (class gate-blind-to-feature)"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 let refs = ffmpeg_decode_sequence(&stream, w, h, frames);6473 let refs = ffmpeg_decode_sequence(&stream, w, h, frames);
6404 assert_eq!(ours.len(), frames, "{NAME}: decode-order frame count");6474 assert_eq!(ours.len(), frames, "{NAME}: decode-order frame count");
6405 for (i, (got, want)) in ours.iter().zip(refs.iter()).enumerate() {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 // libaom codes every plane of a mu chunk before moving on. The413 // libaom codes every plane of a mu chunk before moving on. The
414 // chroma `txb_skip_ctx` takes `get_txb_ctx`'s offset-10 rows414 // chroma `txb_skip_ctx` takes `get_txb_ctx`'s offset-10 rows
415 // (+3 here) because the uv plane block is bigger than the unit.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 let mut pair = [Vec::new(), Vec::new()];424 let mut pair = [Vec::new(), Vec::new()];
417 for plane in 1..3usize {425 for plane in 1..3usize {
418 let grid = unit_of(plane, cr, cc);426 let grid = unit_of(plane, cr, cc);