forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1-128rect-tail-replay-span: stamp the 128-root tail replay per axis (luma_span_h)

Browse files at this commit

f8966191c4e20380c04ad93b9f901d71a75df548Ahmet Kaan GümüşParent: 20c4f0e2f0f6f8
- decode_block_128rect tail replay now passes luma_span_h (per-axis) instead of luma_span twice; no-op at 4:2:0/4:4:4 (spans equal), correct for a future 4:2:2 port; proven unreachable today (422 refused at the sequence header)
- SB128RECT_CHROMA_REPLAY_HITS + SB128RECT_REPLAY_SPAN_MISMATCH_HITS counters; reviewer PASS 0.90; suite 638/0 on server-2
crates/ec-av1/src/decode.rsmodified+62 -1
@@ -12618,6 +12618,16 @@ fn decode_intrabc_128rect(
1261812618 // within the chunk, plane-major inside the chunk.
1261912619 let cu_tx = 32usize;
1262012620 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.
1262112631 let unit_luma = cu_tx * (side / cside);
1262212632 let chunk_w_mi = 16.min(max_w_mi.saturating_sub(cc * 16));
1262312633 let chunk_h_mi = 16.min(max_h_mi.saturating_sub(cr * 16));
@@ -18795,6 +18805,25 @@ thread_local! {
1879518805 /// frame's `tx_mode` is forced `ONLY_4X4`). Keeps the gate that owns this
1879618806 /// shape non-vacuous -- a stream that never codes one reads 0.
1879718807 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) };
1879818827 }
1879918828
1880018829 /// [`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]) {
1882218851 )
1882318852 }
1882418853
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+
1882518865 /// The 128 root's HORZ/VERT arm on an INTRA frame: ONE 128x64 (HORZ) or
1882618866 /// 64x128 (VERT) intra block (lane-sb128c r8; the inter twin is
1882718867 /// `decode_inter_block`'s own rect path).
@@ -19189,8 +19229,29 @@ fn decode_block_128rect(
1918919229 uv_predict_mode,
1919019230 [&last_grids[0], &last_grids[1]],
1919119231 );
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+ }
1919219252 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);
1919419255 }
1919519256 }
1919619257 // 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 {
260260 crate::decode::intra128_lossless_hits()
261261 }
262262
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+
263272 /// lane-sb128c r9: the four AB shapes at the 128 root, in `PARTITION_HORZ_A`,
264273 /// `_HORZ_B`, `_VERT_A`, `_VERT_B` order (key and inter tile paths share the
265274 /// counter -- it is bumped where the root symbol resolves).
@@ -5868,6 +5877,7 @@ pub(crate) mod tests {
58685877
58695878 let _guard = lock_gate_counters();
58705879 let before = crate::decode::intra_sb128_hits();
5880+ let before_replay = crate::decode::sb128rect_chroma_replay_hits();
58715881 let frames = decode_stream(&stream).unwrap_or_else(|e| {
58725882 panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}")
58735883 });
@@ -5877,6 +5887,35 @@ pub(crate) mod tests {
58775887 "{NAME}: this stream coded NO 128-axis intra block -- the fixed body \
58785888 never ran (class gate-blind-to-feature)"
58795889 );
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+ );
58805919 assert_eq!(frames.len(), FRAMES, "{NAME}: frame count");
58815920 for f in &frames {
58825921 assert_eq!((f.width, f.height), (W, H), "{NAME}: dimensions");
@@ -6382,9 +6421,12 @@ pub(crate) mod tests {
63826421 #[test]
63836422 fn a_lossless_sb128_rect_intra_block_decodes_sample_exact() {
63846423 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");
63886430 }
63896431 let (w, h, frames) = (320usize, 256usize, 4usize);
63906432 let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
@@ -6392,6 +6434,7 @@ pub(crate) mod tests {
63926434 let stream = std::fs::read(&path)
63936435 .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display()));
63946436 let before = crate::decode::intra128_lossless_hits();
6437+ let before_replay = crate::decode::sb128rect_chroma_replay_hits();
63956438 let ours = decode_stream(&stream)
63966439 .unwrap_or_else(|e| panic!("{NAME}: a lossless 128-axis key frame decodes: {e}"));
63976440 let hits = crate::decode::intra128_lossless_hits() - before;
@@ -6400,6 +6443,33 @@ pub(crate) mod tests {
64006443 "{NAME}: this stream coded NO lossless 128-axis intra block -- the fixed body \
64016444 was never reached (class gate-blind-to-feature)"
64026445 );
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+ }
64036473 let refs = ffmpeg_decode_sequence(&stream, w, h, frames);
64046474 assert_eq!(ours.len(), frames, "{NAME}: decode-order frame count");
64056475 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(
413413 // libaom codes every plane of a mu chunk before moving on. The
414414 // chroma `txb_skip_ctx` takes `get_txb_ctx`'s offset-10 rows
415415 // (+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.
416424 let mut pair = [Vec::new(), Vec::new()];
417425 for plane in 1..3usize {
418426 let grid = unit_of(plane, cr, cc);