forge
Explore
Log in

Don't you dare go Hollow

ec-av1: lane-av1422ctxgather -- the 4:2:2 strip chroma entropy context

Browse files at this commit

76c34660473f190bed1a97cabfb7a4a501f33b8fAhmet Kaan GümüşParent: 8dcaf0a
fixed at source: decode_inter_block's pair write and around_c gather kept
the 4:2:0 pair span (16,8) for a HORZ strip that at ss (1,0) is its OWN
chroma reference, so the strip at mi(8,4) zeroed left[9][1] under the
mi(8,2) 8x8 leaf's level 5 and the mi(9,4) strip's U all_zero read one
ctx row low (t422 frame 1, the parent lane's anchor; the write span is
(16,4) at ss (1,0)); the strip chroma gathers (decode_rect4_16_strip's
else arm, decode_inter_block's around_c, read_inter_rect_chroma's chunked
units) route through around_mi_422_chroma at ss (1,0) -- one chroma column
spans two luma mi at ss_x 1 and the per-mi gather double-counts each
column's dc sign; 4:2:0/4:4:4 take the original expressions verbatim (all
edits gated ss_x==1 && ss_y==0), lossless 4:4:4 stream gates green,
frame 0 of the pinned t422 fixture exact at all ladder stages, the inter
divergence drops 10x on frame 1 (Y 23948 -> 1739) with no frame regressed
and the residual attributed downstream (first diffs Y (96,240), U (2,44),
V (0,44)); the 4:2:2 header refusal stays unconditional
crates/ec-av1/src/decode.rsmodified+67 -8
@@ -15328,7 +15328,18 @@ fn decode_rect4_16_strip(
15328 }15328 }
15329 (Grid::Zero(cw * ch), Grid::Zero(cw * ch))15329 (Grid::Zero(cw * ch), Grid::Zero(cw * ch))
15330 } else {15330 } else {
15331- let around = neighbours.around_mi_rect(pair_mi, pw, ph);15331+ // lane-av1422ctxgather: 4:2:2's chroma above votes sample
15332+ // every second luma-mi cell
15333+ // ([`Neighbours::around_mi_422_chroma`]: at ss_x 1 one
15334+ // chroma 4-px column spans two luma mi columns, and the
15335+ // plain per-mi gather counts each column's whole-unit dc
15336+ // sign twice). The left extent is unsubsampled at ss_y 0,
15337+ // so its per-mi cells already line up one-to-one.
15338+ let around = if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
15339+ neighbours.around_mi_422_chroma(pair_mi, pw, ph)
15340+ } else {
15341+ neighbours.around_mi_rect(pair_mi, pw, ph)
15342+ };
15332 // lane-av1-444: the strip's own 16x4 / 4x16 chroma at ss 0/015343 // lane-av1-444: the strip's own 16x4 / 4x16 chroma at ss 0/0
15333 // (`TxbSet::Chroma8`, `get_txsize_entropy_ctx(TX_16X4)` =15344 // (`TxbSet::Chroma8`, `get_txsize_entropy_ctx(TX_16X4)` =
15334 // the 8x8 set); 4:2:0 keeps the pair's 8x4 / 4x8.15345 // the 8x8 set); 4:2:0 keeps the pair's 8x4 / 4x8.
@@ -23347,7 +23358,19 @@ fn read_inter_rect_chroma(
23347 at_mi.1 + cu_col * (span_x / MI),23358 at_mi.1 + cu_col * (span_x / MI),
23348 );23359 );
23349 let cu_around = if multi {23360 let cu_around = if multi {
23350- neighbours.around_mi_rect(cu_mi, span_x, span_y)23361+ // lane-av1422ctxgather: at ss (1,0) the unit's above
23362+ // span covers `uw` chroma px = `2*uw` luma mi columns,
23363+ // so the plain per-mi gather counts every chroma
23364+ // column's whole-unit dc sign twice
23365+ // ([`Neighbours::around_mi_422_chroma`]; the left
23366+ // extent is 1:1 at ss_y 0). 4:2:0 keeps the per-mi
23367+ // gather (both extents duplicated there, measured
23368+ // elsewhere).
23369+ if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
23370+ neighbours.around_mi_422_chroma(cu_mi, span_x, span_y)
23371+ } else {
23372+ neighbours.around_mi_rect(cu_mi, span_x, span_y)
23373+ }
23351 } else {23374 } else {
23352 around23375 around
23353 };23376 };
@@ -34557,12 +34580,31 @@ fn decode_inter_block(
34557 // EVEN strip's mi origin and spans both strips, so its34580 // EVEN strip's mi origin and spans both strips, so its
34558 // above/left coefficient context is the pair's, not this34581 // above/left coefficient context is the pair's, not this
34559 // strip's row.34582 // strip's row.
34583+ // lane-av1422ctxgather: at 4:2:2 (ss 1,0) a HORZ strip is
34584+ // its own chroma reference (`is_chroma_reference`'s
34585+ // `!(subsampling_y)` row clause) -- pair_mi is the strip
34586+ // itself and the context reads the strip's own 8x4, ONE
34587+ // luma-mi row tall, with the 4:2:2 above sampling
34588+ // ([`Neighbours::around_mi_422_chroma`]). The 4:2:0 pair
34589+ // merge keeps the (16, 8) span and the plain per-mi gather
34590+ // (as do 4:4:4 and every VERT shape).
34560 let around_c = match strip_chroma {34591 let around_c = match strip_chroma {
34561- Some(s) if s.has_chroma => neighbours.around_mi_rect(34592+ Some(s) if s.has_chroma => {
34562- s.pair_mi,34593+ let (pw, ph) = if s.horz {
34563- if s.horz { 16 } else { 8 },34594+ if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
34564- if s.horz { 8 } else { 16 },34595+ (16, 4)
34565- ),34596+ } else {
34597+ (16, 8)
34598+ }
34599+ } else {
34600+ (8, 16)
34601+ };
34602+ if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
34603+ neighbours.around_mi_422_chroma(s.pair_mi, pw, ph)
34604+ } else {
34605+ neighbours.around_mi_rect(s.pair_mi, pw, ph)
34606+ }
34607+ }
34566 _ => around,34608 _ => around,
34567 };34609 };
34568 let luma_tx_type;34610 let luma_tx_type;
@@ -36199,7 +36241,24 @@ fn decode_inter_block(
36199 }36241 }
36200 }36242 }
36201 if let Some((s, u_state, v_state)) = pair_chroma {36243 if let Some((s, u_state, v_state)) = pair_chroma {
36202- let (pw, ph) = if s.horz { (16usize, 8usize) } else { (8, 16) };36244+ // lane-av1422ctxgather: at 4:2:2 (ss 1,0) a horz strip is its own
36245+ // chroma reference -- no pair merge ever happened, so the write
36246+ // covers the strip's own 8x4: ONE luma-mi left row (libaom's
36247+ // `av1_set_contexts` for the TX_8X4 at ss_y 0 stamps
36248+ // `tx_size_high_unit` = 1 cell). The 4:2:0 pair's two-row (16, 8)
36249+ // span would overwrite the NEXT row's leaf-stamped level state
36250+ // (measured: t422 frame 1, the strip at mi(8,4) zeroed
36251+ // left[9][1] under the mi(8,2) 8x8's level 5 before the mi(9,4)
36252+ // strip's own all_zero read it one ctx row low).
36253+ let (pw, ph) = if s.horz {
36254+ if ss_x(fctx) == 1 && ss_y(fctx) == 0 {
36255+ (16usize, 4usize)
36256+ } else {
36257+ (16usize, 8usize)
36258+ }
36259+ } else {
36260+ (8, 16)
36261+ };
36203 let round_up_even = |n: usize| n.div_ceil(2) * 2;36262 let round_up_even = |n: usize| n.div_ceil(2) * 2;
36204 let (bound_h, bound_w) = (36263 let (bound_h, bound_w) = (
36205 round_up_even(neighbours.mi_rows),36264 round_up_even(neighbours.mi_rows),
lanes/av1422ctxgather.report.mdadded+89 -0
@@ -0,0 +1,89 @@
1+# lane-av1422ctxgather — the 4:2:2 strip chroma context gather and the
2+# clobbering pair write fixed at source; 4:2:0/4:4:4 byte-identical; the
3+# 4:2:2 header refusal STAYS
4+
5+## Outcome
6+
7+1. **The clobber (the anchor's root cause).** `decode_inter_block`'s
8+ `pair_chroma` write hardcoded the 4:2:0 pair span `(pw, ph) = (16, 8)`
9+ for every horz strip. At 4:2:2 (ss 1,0) a horz 16x4 strip is its OWN
10+ chroma reference (`is_chroma_reference`'s `!(subsampling_y)` row
11+ clause) — no pair merge ever happened, `pair_mi` is the strip itself,
12+ and the two-row span overwrote one row it does not own. Measured
13+ (t422 frame 1, EC422WATCH probe, since removed): the inter strip at
14+ mi(8,4) zeroed `left[9][1]` under the mi(8,2) 8x8 leaf's level 5
15+ before the mi(9,4) strip's own U `all_zero` read it one ctx row low
16+ (ours base 0 + 7, oracle base 1 + 7 — the parent lane's anchor
17+ facts, reproduced). The span is now `(16, 4)` at ss (1,0); 4:2:0
18+ keeps `(16, 8)`; VERT keeps `(8, 16)` in every format.
19+2. **The inter strip's chroma gather.** `decode_inter_block`'s
20+ `around_c` gathered the horz strip's context with
21+ `around_mi_rect(pair_mi, 16, 8)` — the pair span AND the plain
22+ per-mi above sampling (one chroma 4-px column spans two luma mi
23+ columns at ss_x 1, so every column's whole-unit dc sign is counted
24+ twice). At ss (1,0) it now reads `(16, 4)` through
25+ [`Neighbours::around_mi_422_chroma`]; the 4:2:0 pair merge keeps the
26+ (16, 8) span and the per-mi gather, as do 4:4:4 and every VERT shape.
27+3. **The intra strip's chroma gather** (the charter's named site,
28+ `decode_rect4_16_strip` ~15331): the else arm's
29+ `around_mi_rect(pair_mi, pw, ph)` is routed through
30+ [`around_mi_422_chroma`] at ss (1,0) — the same measured rule as the
31+ other chroma gathers (10754/13774/15297/17862/18061). Shapes at other
32+ subsamplings keep the original gather.
33+4. **Class sweep found one more instance, fixed:**
34+ `read_inter_rect_chroma`'s chunked units (`multi` arm) gathered each
35+ unit with `around_mi_rect(cu_mi, span_x, span_y)`; at ss (1,0) the
36+ unit's above span covers `2*uw` luma mi columns and the per-mi gather
37+ double-counts every column. Now routed through [`around_mi_422_chroma`]
38+ at ss (1,0) only; the `else` (4:2:0/4:4:4) arm is the original
39+ expression verbatim.
40+5. Untouched, byte-identical: the intra strip's own chroma write (its
41+ pair is already `(16, 4)` at 4:2:2), `decode_rect4_16_intrabc`'s pair
42+ write (intrabc counters are 0 on the pinned fixture and intrabc has
43+ its own inventory discipline), the 4:2:0 group-tail chroma SKIP arm
44+ (reserved for its owning lane), `stream.rs`, and the 4:2:2 header
45+ refusal. The `EC_AV1_ALLOW_422_PROBE` bypass was applied to stream.rs
46+ for the probe runs and reverted; `git status` names only decode.rs.
47+
48+## Verification
49+
50+- **The anchor, before/after (probed, EC422WATCH + EC_DCDUMP):** before,
51+ `inter_pair` wrote `left[9][1] 5 -> 0` and the mi(9,4) strip's U gather
52+ read `left=[None/0]` -> base 0; after, nothing writes row 9 between the
53+ leaf's stamp and the gather, the gather reads `left=[Some(true)/5]` ->
54+ base 1 = the oracle's row. First U divergence at the parent's anchor
55+ (pre-all_zero rng 49672) is gone.
56+- **t422 inter ladder re-measured** (decode_probe + EC_AV1_{PREFILT,
57+ POSTDEBLOCK,POSTCDEF}_DUMP vs the parent's oracle dumps,
58+ /tmp/i422/ladder/oracle, our dumps /tmp/i422/av1422ctxgather/final):
59+ frame 0 is **exact at all three stages (0 diffs per plane per frame)**.
60+ Frame 1 pre-fix Y=23948 U=13513 V=13544 -> post-fix Y=1739 U=4346
61+ V=4974 (first Y diff moved from the anchor's ctx row to y=96 x=240;
62+ first chroma diffs at chroma (0,44)/(2,44)). Frames 2-15 improved on
63+ every plane (no frame regressed) but remain nonzero.
64+- **Frame exactness claimed ONLY where measured 0:** frame 0 at all
65+ stages. Frames 1+ are NOT claimed. The residual is downstream of this
66+ lane's class: frame 1's first Y diff sits at (96, 240) (mi(24,60)) and
67+ the first U/V diffs at chroma (2,44)/(0,44) — neither is a strip
68+ gather nor a pair write; attributing them is the next lane's first
69+ diff.
70+- **4:2:0/4:4:4 identity:** all four edits are gated
71+ `ss_x(fctx) == 1 && ss_y(fctx) == 0` with the non-4:2:2 arm the
72+ original expression verbatim; the lossless 4:4:4 stream gates stay
73+ green — `a_lossless_libaom_key_frame_decodes_sample_exact`,
74+ `a_lossless_libaom_inter_frame_decodes_sample_exact`,
75+ `a_real_aomenc_mixed_lossless_segment_frame_decodes_sample_exact`:
76+ 3 passed, 0 failed.
77+- `cargo check -p ec-av1` (target dir `~/.cache/cargo-target-av1422ctxgather`):
78+ **0 warnings, 0 errors**.
79+- Probes: the temporary EC422WATCH write-watch was removed before the
80+ final build and commit; the final ladder was re-run on the clean tree
81+ and matches the probed run exactly (the watch was eprintln-only).
82+
83+## State
84+
85+- Commit on lane-av1422ctxgather (no push): the four gated edits in
86+ `crates/ec-av1/src/decode.rs` + this report.
87+- Next stop named for the owning lane: the frame-1 Y diff at mi(24,60)
88+ and the chroma diffs at chroma (0,44)/(2,44) — re-run the stage ladder
89+ and the EC_ISTEP/EC_COEFF pairing from there.