forge
Explore
Log in

Don't you dare go Hollow

lane-av1-llintra8: the inter frame's 8x8 intra leaf lossless 444 chroma walk

Browse files at this commit

3e0f6821e928786c2179a8274861b329b9f35444Ahmet Kaan GümüşParent: 92ce894
decode_inter_block8's intra leaf read 4:4:4 lossless chroma as one TX_8X8
unit and hit TxParams::run's lossless WHT assert (8, 8) != (4, 4) -- the
one arm the inter arms' leaf8_inter_chroma_lossless did not cover. Route
it through read_intra_chroma_lossless (2x2 TX_4X4 raster per plane,
plane-major) and stamp chroma_stamped_per_unit so the tail's record_mi
keeps the walk's per-unit contexts. 4:2:0 keeps its single TX_4X4 unit.

Same leaf, one read earlier: gate the uv_mode CDF row on cfl_allowed_px
(decodemv.c:145, cfl.h:29 -- at lossless the CFL alphabet exists only
when the chroma plane block is BLOCK_4X4), so the 4:4:4 lossless leaf
reads the 13-symbol uv_mode_no_cfl alphabet instead of consuming a
different partition at its own uv_mode symbol.

Counter LLINTRA8_CHROMA_WALK_HITS + decode_probe line; report in
lanes/av1llintra8.report.md. Witness: testsrc2 128x96 lossless 444
min-partition-8, EC_COEFF trace 11292/11292 all_zero rngs byte-matched
against aomdec with the walk firing 34 times, key frame and all luma
planes byte-exact; dodge2.obu stays byte-exact; a_lossless gates 6/6.
crates/ec-av1/examples/decode_probe.rsmodified+4 -0
@@ -105,6 +105,10 @@ fn main() {
105 );105 );
106 let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits();106 let (h84, h48) = ec_av1::decode::sub8_inter_rect_hits();
107 println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}");107 println!("sub8_inter_rect: horz8x4={h84} vert4x8={h48}");
108+ println!(
109+ "llintra8_chroma_walk: {}",
110+ ec_av1::decode::llintra8_chroma_walk_hits()
111+ );
108 let si = ec_av1::stream::sub8_intra_rect_hits();112 let si = ec_av1::stream::sub8_intra_rect_hits();
109 println!(113 println!(
110 "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={} split4x4={}",114 "sub8_intra_rect: horz8x4={} vert4x8={} chroma_ref={} mixed={} split4x4={}",
crates/ec-av1/src/decode.rsmodified+56 -1
@@ -25795,6 +25795,21 @@ pub(crate) fn chroma_split_tx_hits() -> usize {
25795 CHROMA_SPLIT_TX_HITS.with(std::cell::Cell::get)25795 CHROMA_SPLIT_TX_HITS.with(std::cell::Cell::get)
25796 }25796 }
25797 25797
25798+thread_local! {
25799+ /// How many INTRA leaves of an inter frame's 8x8 block ran the lossless
25800+ /// 4:4:4 chroma walk ([`read_intra_chroma_lossless`], lane-av1-llintra8)
25801+ /// -- one bump per leaf, four units per plane inside it. A gate proving
25802+ /// the arm must see this nonzero; CHROMA_SPLIT_TX_HITS alone cannot
25803+ /// attribute its bumps to THIS leaf.
25804+ pub(crate) static LLINTRA8_CHROMA_WALK_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
25805+}
25806+
25807+/// [`LLINTRA8_CHROMA_WALK_HITS`]: lossless 4:4:4 chroma walks through an
25808+/// inter frame's 8x8 INTRA leaf.
25809+pub fn llintra8_chroma_walk_hits() -> usize {
25810+ LLINTRA8_CHROMA_WALK_HITS.with(|c| c.get())
25811+}
25812+
25798 fn read_sb128_root(25813 fn read_sb128_root(
25799 dec: &mut SymbolDecoder,25814 dec: &mut SymbolDecoder,
25800 cdfs: &mut Cdfs,25815 cdfs: &mut Cdfs,
@@ -38538,10 +38553,22 @@ fn decode_inter_block8(
38538 // but `DC_PRED` was refused here, which is what blocked the low-cq38553 // but `DC_PRED` was refused here, which is what blocked the low-cq
38539 // CDEF arms and the 10-bit gates.38554 // CDEF arms and the 10-bit gates.
38540 let has_chroma = !mono(fctx);38555 let has_chroma = !mono(fctx);
38556+ // lane-av1-llintra8: `read_intra_mode_uv` (decodemv.c:145) picks the
38557+ // uv CDF row by `is_cfl_allowed` (cfl.h:23) -- at LOSSLESS that is
38558+ // "the chroma plane block is BLOCK_4X4" (cfl.h:29), for this
38559+ // BLOCK_8X8 leaf only at 4:2:0. The 4:4:4 lossless leaf reads the
38560+ // 13-symbol `uv_mode_no_cfl` alphabet; the unconditional CFL row
38561+ // consumed a different partition than aomdec at the leaf's own
38562+ // uv_mode symbol (class wrong-alphabet-same-value) and desynced
38563+ // every stream that reached the leaf's lossless chroma walk below.
38564+ // 4:2:0 and every non-lossless partition keep the CFL row
38565+ // (`cfl_allowed_px` answers true exactly as before).
38541 let uv_mode = if !has_chroma {38566 let uv_mode = if !has_chroma {
38542 DC_PRED38567 DC_PRED
38543- } else {38568+ } else if cfl_allowed_px(SIDE, SIDE, fctx) {
38544 dec.symbol(&mut cdfs.uv_mode_cfl[mode])38569 dec.symbol(&mut cdfs.uv_mode_cfl[mode])
38570+ } else {
38571+ dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
38545 };38572 };
38546 if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {38573 if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
38547 eprintln!(38574 eprintln!(
@@ -38951,6 +38978,33 @@ fn decode_inter_block8(
38951 )?38978 )?
38952 };38979 };
38953 let ac = alpha.map(|_| cfl_src(px, py, SIDE));38980 let ac = alpha.map(|_| cfl_src(px, py, SIDE));
38981+ if chroma_side == 8 && lossless(fctx) && !mono(fctx) {
38982+ // lane-av1-llintra8: lossless codes TX_4X4 on EVERY plane
38983+ // (`av1_get_tx_size`, blockd.h:1383), so this intra leaf's 8x8
38984+ // chroma plane block is a 2x2 raster of TX_4X4 units per
38985+ // plane, plane-major -- the same per-unit walk the >=16x16
38986+ // intra-in-inter block runs, not one TX_8X8 unit (whose WHT
38987+ // hits `TxParams::run`'s `(8, 8) != (4, 4)` lossless assert).
38988+ // The walk stamps each unit's own coefficient context
38989+ // (`record_mi_chroma` inside it), so the tail's whole-block
38990+ // `record_mi` gets its chroma half saved/restored around --
38991+ // the same rule the INTER arms'
38992+ // `leaf8_inter_chroma_lossless` obeys. 4:2:0 keeps its single
38993+ // TX_4X4 unit in the `else` below.
38994+ let (mut uo, mut vo) = (Vec::new(), Vec::new());
38995+ read_intra_chroma_lossless(
38996+ dec, cdfs, neighbours, u, v, leaf_mi, (px, py), (cpx, cpy),
38997+ SIDE, (chroma_side, chroma_side), (0, 0),
38998+ (chroma_side, chroma_side), chroma_side, reach,
38999+ (y.width, y.height), mode, uv_predict_mode, angle_delta_uv,
39000+ palette_uv_bufs.as_ref().map(|(a, b)| (&a[..], &b[..])),
39001+ smooth_neighbor_uv, base_q_idx, &mut uo, &mut vo, fctx,
39002+ )?;
39003+ u_grid = if uo.is_empty() { Grid::Zero(64) } else { Grid::Own(uo) };
39004+ v_grid = if vo.is_empty() { Grid::Zero(64) } else { Grid::Own(vo) };
39005+ chroma_stamped_per_unit = true;
39006+ hit!(LLINTRA8_CHROMA_WALK_HITS);
39007+ } else {
38954 if let Some((ub, _)) = &palette_uv_bufs {39008 if let Some((ub, _)) = &palette_uv_bufs {
38955 set_palette_pred(ub.clone(), fctx);39009 set_palette_pred(ub.clone(), fctx);
38956 }39010 }
@@ -39001,6 +39055,7 @@ fn decode_inter_block8(
39001 None,39055 None,
39002 smooth_neighbor_uv, fctx,39056 smooth_neighbor_uv, fctx,
39003 )?;39057 )?;
39058+ }
39004 }39059 }
39005 }39060 }
39006 // lane-txselect: a split leaf's plane-0 neighbour context is per 4x439061 // lane-txselect: a split leaf's plane-0 neighbour context is per 4x4
lanes/av1llintra8.report.mdadded+105 -0
@@ -0,0 +1,105 @@
1+# lane-av1-llintra8: the inter frame's 8x8 INTRA leaf lossless 4:4:4 chroma walk
2+
3+## Ticket
4+
5+`decode_inter_block8`'s intra leaf read 4:4:4 lossless chroma as ONE TX_8X8
6+unit (`u_grid`/`v_grid = read_plane(..)` at `chroma_side == 8`,
7+decode.rs:38958/:38985 pre-change) and hit `TxParams::run`'s lossless WHT
8+assert `(8, 8) != (4, 4)` at decode.rs:2566 — the one arm sibling
9+`84acbd09`/fb4e4b0e did not cover (it routed the INTER arms only, named in
10+llsub8b's report item 1). `decode_inter_sub8_rect2` and
11+`sub8_leaf_chroma444` untouched (owned elsewhere).
12+
13+## Change (decode.rs, one branch + one alphabet gate + counter)
14+
15+1. `chroma_side == 8 && lossless(fctx) && !mono(fctx)` routes the leaf's
16+ chroma through `read_intra_chroma_lossless` — the intra twin the >=16x16
17+ intra-in-inter block already runs (plane-major 2x2 raster of TX_4X4
18+ units per plane, `av1_get_tx_size` blockd.h:1383) — with region and
19+ block `(8, 8)` at stride 8, the leaf's own `reach`, and the leaf's
20+ `palette_uv_bufs` windowed per unit by the helper. The walk stamps each
21+ unit's own coefficient context, so `chroma_stamped_per_unit = true` and
22+ the tail's whole-block `record_mi` gets its chroma half saved/restored
23+ around — the same rule the INTER arms' `leaf8_inter_chroma_lossless`
24+ obeys (the mechanism was already in place). `Grid::Zero(64)` when every
25+ unit hung off the frame edge, matching the inter helper. 4:2:0: zero
26+ change — the branch lives inside `chroma_side == 8`, and the reserved
27+ 4:2:0 group-tail chroma arm was not touched.
28+2. SAME LEAF, one read earlier, second defect of the same class: the leaf
29+ read `uv_mode` off `uv_mode_cfl[mode]` unconditionally, but libaom picks
30+ the uv CDF row by `is_cfl_allowed` (decodemv.c:145, cfl.h:23) and at
31+ LOSSLESS that is "the chroma plane block is BLOCK_4X4" (cfl.h:29) —
32+ for this BLOCK_8X8 leaf only at 4:2:0. A 4:4:4 lossless leaf must read
33+ the 13-symbol `uv_mode_no_cfl` alphabet; the tables differ (cdf.rs
34+ `UV_MODE_CFL` vs `UV_MODE_NO_CFL`, row 0: 10407.. vs 22631..), so the
35+ unconditional CFL row consumed a different partition at the leaf's own
36+ uv_mode symbol and desynced every stream that reached the leaf.
37+ Now gated on `cfl_allowed_px(SIDE, SIDE, fctx)` — the same gate five
38+ other readers use; 4:2:0 lossless and every non-lossless partition
39+ still take the CFL row (value-identical reads).
40+3. Non-vacuity counter `LLINTRA8_CHROMA_WALK_HITS` +
41+ `llintra8_chroma_walk_hits()` + a `decode_probe` line, per the lane
42+ convention: CHROMA_SPLIT_TX_HITS cannot attribute its bumps to this
43+ leaf.
44+
45+## Verification (measured, this tree @ HEAD + this change)
46+
47+- Fail-before (assert): `testsrc2 128x96 yuv444p`, aomenc
48+ `--profile=1 --lossless=1 --enable-palette=0 --enable-intrabc=0
49+ --max-partition-size=64`, 6 frames (`/tmp/llintra8/t6.obu`) → panic
50+ `(8, 8) != (4, 4)` at decode.rs:2566, debug backtrace
51+ `read_plane (decode.rs:38958) → push_intra_tx → TxParams::run`. The
52+ release build's assert folds into an index panic at `exec_intra`; the
53+ debug line numbers are the evidence.
54+- Fail-before (alphabet): with only the uv hunk reverted, the regenerated
55+ `--min-partition-size=8` stream's EC_COEFF trace diverges from aomdec's
56+ at all_zero #2400 — `plane=0 mi(4,0)`, the reads right after that leaf's
57+ uv_mode symbol. With the fix: divergence gone (below).
58+- Entropy witness: `testsrc2 128x96 yuv444p` with
59+ `--min-partition-size=8 --max-partition-size=64` (min 8 excludes the
60+ sub-8 shapes so the leaf actually fires; key frame becomes exact too):
61+ our EC_COEFF `all_zero` rng sequence matches fresh
62+ `aomdec --rawvideo` **11292/11292 reads across all 6 frames** with the
63+ walk firing 34 times; frame 0 is byte-exact and ALL luma planes are
64+ byte-exact stream-wide. The pre-fix stream panicked at the leaf; this
65+ stream decodes all 6 frames.
66+- Non-regression: sibling's own witness bytes
67+ `/tmp/ll444/dodge2.obu` decode byte-exact vs fresh `aomdec`, 6 frames,
68+ in this tree with this change.
69+- Gates: `cargo test -p ec-av1 --lib a_lossless` → 6 passed, 0 failed
70+ (both 4:2:0 lossless libaom gates, the 444 min-partition-64 inter gate,
71+ the sb128 pair, the 16x4 pair).
72+- `cargo check -p ec-av1 --all-targets`: 0 warnings, 0 errors (target dir
73+ `$HOME/.cache/cargo-target-av1llintra8`). Release decode_probe output
74+ identical to debug on both streams.
75+- Fixtures are scratch in /tmp/llintra8 (regenerable recipes above);
76+ fixtures/ is gitignored, nothing committed from it.
77+
78+## Named, not chased (spoken)
79+
80+1. Chroma PREDICTION pixel diffs, entropy-exact: on the min-8 stream,
81+ 2772 bytes differ from aomdec — all chroma, luma exact, and the EC_COEFF
82+ trace is bit-aligned everywhere (so symbols, uv modes and angle deltas
83+ all match; only reconstructed pixels differ). Frame 1's diffs cover
84+ three readers at once with clean upstream edges: the inter 8x16 strip's
85+ chroma at mi(0,16) (2x4 units, MC-side), an INTRA 8x8 leaf at mi(2,24)
86+ (uv V_PRED, via this lane's new walk), and the >=16x16 intra block's
87+ chroma at mi(8,28) (the pre-existing `read_intra_chroma_lossless`
88+ caller, untouched by this change). One shared per-unit chroma
89+ prediction-input class across readers, present before this change
90+ (the >=16 arm predates it) — larger than this arm.
91+ deferred(the lane owning per-unit 4:4:4 chroma prediction:
92+ `read_plane`/`PlaneBuf::reconstruct` intra chroma edges + the inter
93+ strip chroma MC), with the min-8 stream as a ready-made fixture.
94+2. The default-partition (min 4) testsrc2 key frame still entropy-diverges
95+ at frame-0 coefficient read #452 (pre-existing, key-frame intra lane;
96+ llsub8b's item 3). The min-8 key frame is exact, so this lane's witness
97+ does not depend on it.
98+
99+## Note on the shared oracle
100+
101+aomenc/aomdec are the shared `$HOME/.cache/aom-oracle/build`; the
102+EC_COEFF/EC_COEFF_STEP rungs of that patched tree are what the entropy
103+pairing above used. Today's aomenc produces different RD picks than this
104+morning's (llsub8b's note), so every comparison is against fresh aomdec
105+output of THE SAME bytes.