forge
Explore
Log in

Don't you dare go Hollow

lane-av1muchroma: size decode_block's skip-arm chroma grid per axis

Browse files at this commit

66fb25724d76487c7450b929e0773a795f62295bAhmet Kaan GümüşParent: 94cba4d
The `chroma_side * chroma_side` mu-chroma sites split in two once measured.

Under decode_inter_block `chroma_side` is `(side >> ss_x).max(side >> ss_y)`
-- the ENCLOSING square lane-av1-422j introduced -- so at 4:2:2 those eleven
sites allocate 2.0x their per-axis extent: oversized, never short. The
block-tail mu_chroma_units replay strides the assembled grid by chroma_side,
so the square IS the writer/reader contract there; shrinking sites 11/12 to
chroma_w * chroma_h reds two pinned gates. Left alone.

decode_block has its own binding, `side >> ss_x`, which at 4:2:2 is half the
plane block: site 1 sized a 64x64 block's chroma at 32x32 = 1024 where the
plane block is 32x64 = 2048. Latent, not live -- the only consumer reduces the
plane through neighbour_state, which sums the slice and reads grid[0], and a
skip block is all zeros -- but an allocation half the block it names traps
the next per-row consumer. Sized per axis.

Gate: s422_322x240.obu, the smallest 4:2:2 fixture that reaches the site, with
two paired counters. skip_arm_chroma_rect_shapes is the non-vacuity arm (it
fires only where per-axis and square differ); skip_arm_chroma_short_samples
reads the allocation's real length and must stay 0. Restoring the square reds
it by 64 samples. A first draft keyed the counter on `chroma_side !=
chroma_height` and did not bite -- that proxy was replaced by the
length measurement.

Reachability, from an env-gated probe over the pinned 4:2:2 corpus (10
fixtures) and the 51 4:4:4 gates: sites 4/7/10 are guarded ss_x == 0 && ss_y
== 0, so 4:4:4 only -- unreachable at 4:2:2 structurally. Sites 2/8 are the
side > 64 mu-chunk walks: live at 4:2:0 and 4:4:4, unreached at 4:2:2, and
sound where they sit, so no fix was invented for the unwitnessed case. Sites
3/5/6/9/11/12 are reached and already correct.

palette_uv_side and the floor-> chroma plane allocators are untouched and
named still-open in the report.
crates/ec-av1/src/decode.rsmodified+67 -2
@@ -2125,6 +2125,43 @@ thread_local! {
2125 const { std::cell::Cell::new(0) };2125 const { std::cell::Cell::new(0) };
2126 }2126 }
2127 2127
2128+// lane-av1muchroma site 1: the total number of samples by which
2129+// `decode_block`'s SKIP arm chroma bookkeeping grids fell SHORT of their own
2130+// plane block, summed over every skipped block decoded. It reads the
2131+// allocation's real length, so it measures the shape rather than proxying a
2132+// condition: the square form this lane removed is `side >> ss_x` squared,
2133+// which at 4:2:2 (ss (1,0)) is exactly HALF the `side >> ss_x` x `side >> ss_y`
2134+// plane block, and restoring it drives this counter strictly positive on
2135+// every 4:2:2 skip block. Zero on 4:2:0 and 4:4:4, where the two forms are
2136+// the same number.
2137+thread_local! {
2138+ static SKIP_ARM_CHROMA_SHORT_SAMPLES: std::cell::Cell<usize> =
2139+ const { std::cell::Cell::new(0) };
2140+}
2141+
2142+/// Current value of [`SKIP_ARM_CHROMA_SHORT_SAMPLES`].
2143+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2144+pub(crate) fn skip_arm_chroma_short_samples() -> usize {
2145+ SKIP_ARM_CHROMA_SHORT_SAMPLES.with(|c| c.get())
2146+}
2147+
2148+// Number of times `decode_block`'s SKIP arm ran at a shape where the
2149+// per-axis and square chroma allocations DIFFER -- i.e. at 4:2:2, where
2150+// the square is half the plane block. Zero on 4:2:0 and 4:4:4, where the
2151+// two forms are the same number, so a gate that wants to prove it actually
2152+// exercised the shape under test (rather than passing vacuously) asserts
2153+// this moved.
2154+thread_local! {
2155+ static SKIP_ARM_CHROMA_RECT_SHAPES: std::cell::Cell<usize> =
2156+ const { std::cell::Cell::new(0) };
2157+}
2158+
2159+/// Current value of [`SKIP_ARM_CHROMA_RECT_SHAPES`].
2160+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
2161+pub(crate) fn skip_arm_chroma_rect_shapes() -> usize {
2162+ SKIP_ARM_CHROMA_RECT_SHAPES.with(|c| c.get())
2163+}
2164+
2128 /// Current value of [`CHROMA422_SQUARE_HITS`].2165 /// Current value of [`CHROMA422_SQUARE_HITS`].
2129 // lane-av1-422b: `pub` so `examples/decode_probe.rs` can census it the way2166 // lane-av1-422b: `pub` so `examples/decode_probe.rs` can census it the way
2130 // it does every other capability counter.2167 // it does every other capability counter.
@@ -23545,8 +23582,36 @@ fn decode_block(
23545 }23582 }
23546 }23583 }
23547 let luma_grid = vec![0i32; side * side];23584 let luma_grid = vec![0i32; side * side];
23548- let u_grid = vec![0i32; chroma_side * chroma_side];23585+ // lane-av1muchroma site 1: the skip arm's chroma grids are the
23549- let v_grid = vec![0i32; chroma_side * chroma_side];23586+ // block's PLANE BLOCK per axis (`chroma_side` x `chroma_height`),
23587+ // not a square. `chroma_side` here is `side >> ss_x` -- the key-frame
23588+ // path's own binding, which at 4:2:2 (ss (1,0)) is `side / 2`, so the
23589+ // old `chroma_side * chroma_side` allocated HALF the block's chroma:
23590+ // a 64x64 block's plane block is 32x64 = 2048 samples and the square
23591+ // held 1024, a 2x under-read for any per-row consumer. No current
23592+ // consumer indexes it -- `record_rect` -> `record_mi_rect` reduces
23593+ // each plane through `neighbour_state`, which sums the slice and
23594+ // reads `grid[0]` only, and every sample is zero on a skip block --
23595+ // so the shape is latent, not live (mutation-verified: sizing this
23596+ // per-axis leaves every pinned 4:2:2 gate green, shrinking sites
23597+ // 11/12 to per-axis reds two). Fixed here so the allocation cannot
23598+ // go short if a per-row consumer ever lands. At 4:2:0 the two are
23599+ // the same number and at 4:4:4 `chroma_side == chroma_height ==
23600+ // side`, so only 4:2:2 changes.
23601+ let u_grid = vec![0i32; chroma_side * chroma_height];
23602+ let v_grid = vec![0i32; chroma_side * chroma_height];
23603+ // The measured arm, not a proxy: how many samples this block's
23604+ // chroma bookkeeping grid is SHORT of its own plane block. The
23605+ // square form this lane removed is `chroma_side * chroma_side`,
23606+ // which at 4:2:2 is half the plane block; restoring it makes this
23607+ // non-zero on every 4:2:2 skip block, and the witness gate asserts
23608+ // the total stayed 0.
23609+ let plane_block = chroma_side * chroma_height;
23610+ let short = plane_block.saturating_sub(u_grid.len());
23611+ hit_do!(SKIP_ARM_CHROMA_SHORT_SAMPLES.with(|c| c.set(c.get() + short)));
23612+ if chroma_side != chroma_height {
23613+ hit!(SKIP_ARM_CHROMA_RECT_SHAPES);
23614+ }
23550 neighbours.record(23615 neighbours.record(
23551 at,23616 at,
23552 side,23617 side,
crates/ec-av1/src/stream.rsmodified+72 -0
@@ -3136,6 +3136,78 @@ pub(crate) mod tests {
3136 }3136 }
3137 }3137 }
3138 3138
3139+ /// lane-av1muchroma: the `chroma_side * chroma_side` mu-chroma site
3140+ /// census, over the whole committed 4:2:2 corpus, as a per-site
3141+ /// REACHABILITY measurement with a non-vacuity arm.
3142+ ///
3143+ /// `lanes/av1subsizesweep.report.md` named "mu-chroma sites using
3144+ /// `chroma_side * chroma_side`" as unprobed residue. This lane's sweep
3145+ /// (env-gated probe at each of the 12 sites, run over every pinned 4:2:2
3146+ /// gate) measured them:
3147+ ///
3148+ /// - sites 4, 7, 10 are guarded `ss_x == 0 && ss_y == 0`, i.e. 4:4:4
3149+ /// ONLY -- structurally unreachable at 4:2:2, not merely unwitnessed.
3150+ /// - sites 2, 8 (`side > 64` mu-chunk walks) were not reached by any
3151+ /// committed 4:2:2 fixture; their single-reference twin, site 5, is
3152+ /// (side 128, plane 64x128), and its square allocation is the ENCLOSING
3153+ /// square, so it is 2x oversized, never short.
3154+ /// - sites 1, 3, 5, 6, 9, 11, 12 ARE reached. For 3/5/6/9/11/12
3155+ /// `chroma_side` is `max(side >> ss_x, side >> ss_y)` (decode.rs), the
3156+ /// ENCLOSING square of the plane rect, so at 4:2:2 the square is 2x
3157+ /// the per-axis extent: oversized, never short.
3158+ /// - site 1 alone still used `side >> ss_x` and was therefore sized at
3159+ /// HALF the plane block at 4:2:2. Fixed per-axis; this gate pins it.
3160+ ///
3161+ /// Non-vacuity: [`crate::decode::skip_arm_chroma_plane_block_hits`]
3162+ /// fires only where the per-axis and square forms differ, so a green run
3163+ /// that never reached the site would be vacuous and this asserts > 0.
3164+ #[test]
3165+ fn the_422_skip_arm_chroma_grid_is_sized_per_axis_not_square() {
3166+ const NAME: &str = "the_422_skip_arm_chroma_grid_is_sized_per_axis_not_square";
3167+ const FILE: &str = "s422_322x240.obu";
3168+ const BYTES: usize = 21096;
3169+ const FP: u64 = 0x9a96dda2a19d47a6;
3170+ const W: usize = 322;
3171+ const H: usize = 240;
3172+ const FRAMES: usize = 16;
3173+ let _gate_lock = lock_gate_counters();
3174+ let data = std::fs::read(crate_pin(FILE)).unwrap_or_else(|e| {
3175+ panic!("{NAME}: the committed pin {FILE} is missing ({e}) -- a failure, not a skip")
3176+ });
3177+ assert_eq!(data.len(), BYTES, "{NAME}: {FILE} size drifted");
3178+ assert_eq!(fnv1a64(&data), FP, "{NAME}: {FILE} bytes drifted");
3179+ let rect_before = crate::decode::skip_arm_chroma_rect_shapes();
3180+ let short_before = crate::decode::skip_arm_chroma_short_samples();
3181+ let ours = decode_stream(&data)
3182+ .unwrap_or_else(|e| panic!("{NAME}: decode_stream refused a real 4:2:2 stream: {e}"));
3183+ assert_eq!(ours.len(), FRAMES, "{NAME}: decoded frame count");
3184+ for (i, f) in ours.iter().enumerate() {
3185+ assert_eq!((f.width, f.height), (W, H), "{NAME}: frame {i} dimensions");
3186+ assert_eq!(
3187+ (f.u.len(), f.v.len()),
3188+ (W.div_ceil(2) * H, W.div_ceil(2) * H),
3189+ "{NAME}: frame {i} chroma planes are {}/{} samples -- 4:2:2 is HALF WIDTH and \
3190+ FULL HEIGHT; a quarter-height plane means the decode kept a 4:2:0 allocation",
3191+ f.u.len(),
3192+ f.v.len()
3193+ );
3194+ }
3195+ let rect_after = crate::decode::skip_arm_chroma_rect_shapes();
3196+ assert!(
3197+ rect_after > rect_before,
3198+ "{NAME}: no skipped block decoded at a rect chroma shape ({rect_before} -> \
3199+ {rect_after}) -- this gate is then VACUOUS: per-axis and square sizing are the \
3200+ same number at 4:2:0 and 4:4:4, so it proves nothing about the site it claims"
3201+ );
3202+ let short_after = crate::decode::skip_arm_chroma_short_samples();
3203+ assert_eq!(
3204+ short_after, short_before,
3205+ "{NAME}: decode_block's SKIP arm chroma grids fell {short_after} samples SHORT of \
3206+ their own plane block -- the square `side >> ss_x` form this lane removed allocates \
3207+ exactly half the plane block at 4:2:2 (ss (1,0))"
3208+ );
3209+ }
3210+
3139 /// lane-av1422tailskip: the WITNESS cell for the 4:2:2 intra-in-inter3211 /// lane-av1422tailskip: the WITNESS cell for the 4:2:2 intra-in-inter
3140 /// PALETTE chroma per-unit window, and its byte pin.3212 /// PALETTE chroma per-unit window, and its byte pin.
3141 ///3213 ///
lanes/av1muchroma.report.mdadded+186 -0
@@ -0,0 +1,186 @@
1+# lane-av1muchroma — the `chroma_side * chroma_side` mu-chroma sites
2+
3+Base: `main` @ `820eeb68` (post `lane/av1paletteuv`). Branch: `lane/av1muchroma`.
4+Scope: **only** the mu-chroma sites that size a chroma region as
5+`chroma_side * chroma_side`. `palette_uv_side` and the floor-`>>` chroma plane
6+allocators are **untouched** — named still-open at the end.
7+
8+`lanes/av1subsizesweep.report.md:241` named this residue "not probed; needs an
9+owning lane with a 128-root 4:2:2 mu-chunk witness". This lane probed it. The
10+headline is that **the report's premise had gone stale**: line numbers drifted
11+AND `chroma_side` itself was redefined by `lane-av1-422j` after that row was
12+written, which changes most of the verdict.
13+
14+## The two `chroma_side` bindings (this is the whole story)
15+
16+There are two, and they are NOT the same expression:
17+
18+| binding | line | expression | 4:2:2 value for a `side`-square block |
19+|---|---|---|---|
20+| `decode_block` (key frames) | `decode.rs:23261` | `side >> ss_x` | `side / 2` |
21+| `decode_inter_block` (inter) | `decode.rs:42130` | `(side >> ss_x).max(side >> ss_y)` | `side` |
22+
23+`lane-av1-422j` changed the second to the **enclosing square** of the chroma
24+rect. So at 4:2:2 (ss `(1,0)`), where the true plane block is `(side/2, side)`:
25+
26+- every site under `decode_inter_block` allocates `side * side` — the
27+ **enclosing** square, i.e. **2x the per-axis extent: oversized, never short**;
28+- site 1, under `decode_block`, allocates `(side/2) * (side/2)` — exactly
29+ **half** the plane block: **short**.
30+
31+The `subsizesweep` row asserted "a square `side/2` is too short on rows
32+`>= side/2`". That is true of site 1 and false of the other eleven, and the
33+row did not distinguish them.
34+
35+## Reachability, measured
36+
37+Method: an env-gated `eprintln` probe at each of the 12 sites printing
38+`(site, ss_x, ss_y, side, chroma_side, plane_w, plane_h)`, run over every
39+pinned 4:2:2 gate (`the_pinned_422_*`, 7 tests) and the 4:4:4 sweep (51 tests).
40+The probe was temporary and is **not** in the commit. Counts are probe hits:
41+
42+| site | arm | 4:2:2 hits | 4:4:4 hits | 4:2:0 hits |
43+|---|---|---|---|---|
44+| 1 | `decode_block` skip arm | **16** | 344 | 5064 |
45+| 2 | compound `side>64` mu-chunk | 0 | 0 | 2700 |
46+| 3 | compound lossless whole-block | **258** | 2559 | 89 |
47+| 4 | compound 4:4:4 quadrant | 0 | 24 | 0 |
48+| 5 | single-ref `side>64` mu-chunk | **16** | 32 | 2224 |
49+| 6 | single-ref lossless whole-block | **457** | 3892 | 3952 |
50+| 7 | single-ref 4:4:4 quadrant | 0 | 648 | 0 |
51+| 8 | intra-in-inter `side>64` vartx | 0 | 96 | 0 |
52+| 9 | intra lossless whole-block | **160** | 283 | 549 |
53+| 10 | intra 4:4:4 quadrant | 0 | 31 | 0 |
54+| 11 | intra 4:2:2 `side==64` U | **14** | 0 | 0 |
55+| 12 | intra 4:2:2 `side==64` V | **14** | 0 | 0 |
56+
57+Corpus: **10 committed 4:2:2 fixtures** across the 7 pinned gates, plus 51
58+4:4:4 gates. 4:2:2 fixture inventory is 11 `.obu` files; `422_residual_compound_warp_nolr_16f.obu`
59+is the lr-off arm of another gate, so 10 distinct witnesses fed these numbers.
60+
61+## Per-site verdict
62+
63+**Sites 4, 7, 10 — unreachable at 4:2:2, structurally.** Each is guarded
64+`ss_x(fctx) == 0 && ss_y(fctx) == 0` (`decode.rs:43983`, `45806`, `46866`),
65+which is 4:4:4 exactly. Not merely unwitnessed: no 4:2:2 stream can enter them.
66+At 4:4:4 the two forms coincide anyway.
67+
68+**Sites 2, 8 — unreachable at 4:2:2 by the committed corpus.** Both are
69+`side > 64` mu-chunk walks inside the compound and intra-in-inter paths. No
70+committed 4:2:2 fixture reaches them (2 is hit 2700x at 4:2:0, 8 is hit 96x at
71+4:4:4 — so both are live, just not at this subsampling). Their allocation is the
72+enclosing square, and their twin **site 5** *is* reached at 4:2:2 (side 128,
73+plane 64x128) with an in-bounds max index of 16319 against a 16384 allocation.
74+**No fix invented for the unwitnessed case**, per the standing rule.
75+
76+**Sites 3, 5, 6, 9, 11, 12 — already correct.** All reached at 4:2:2. All sit
77+under the enclosing-square `chroma_side`, so each allocates 2.0x its per-axis
78+extent. Arithmetic check at every observed shape, e.g.:
79+
80+```
81+3/6/9 lossless zero side=16 cs=16 plane=(8,16) alloc=256 need=128 maxidx=247 OK 2.0x
82+3/6/9 lossless zero side=32 cs=32 plane=(16,32) alloc=1024 need=512 maxidx=1007 OK 2.0x
83+3/6/9 lossless zero side=64 cs=64 plane=(32,64) alloc=4096 need=2048 maxidx=4063 OK 2.0x
84+5 single-ref mu-chunk side=128 cs=128 plane=(64,128) alloc=16384 need=8192 maxidx=16319 OK 2.0x
85+11/12 422 side==64 side=64 cs=64 plane=(32,64) alloc=4096 need=2048 maxidx=4063 OK 2.0x
86+```
87+
88+Mutation-verified in the other direction too: **shrinking sites 11/12 to
89+`chroma_w * chroma_h` reds** `the_pinned_422_corpus_cells` and
90+`the_pinned_422_palette_intra_in_inter`. The block-tail `mu_chroma_units`
91+replay (`decode.rs:47387`) strides the assembled grid by `chroma_side`, so the
92+square **is** the writer/reader contract here. These are not defects and must
93+not be "fixed" per-axis.
94+
95+**Site 1 — FIXED and gated.** The only genuine under-allocation.
96+`decode.rs:23587`:
97+
98+```rust
99+// before
100+let u_grid = vec![0i32; chroma_side * chroma_side]; // (side/2)^2 at 4:2:2
101+// after
102+let u_grid = vec![0i32; chroma_side * chroma_height]; // the plane block
103+```
104+
105+**Was it live?** No — the shape was latent, and this lane says so rather than
106+overclaiming. The sole consumer is `record_rect` → `record_mi_rect`, which
107+reduces each plane through `neighbour_state` (`decode.rs:9032`): it sums the
108+slice and reads `grid[0]`, nothing per-row, and on a skip block every sample is
109+zero. Mutation-confirmed both ways: sizing site 1 per-axis leaves all 7 pinned
110+4:2:2 gates green (no live pixel path), so this is a correctness fix for a
111+consumer that does not exist yet, not a red-to-green rescue. Fixed anyway: an
112+allocation half the block it names is a trap for the next per-row consumer.
113+
114+## The gate
115+
116+`stream.rs::the_422_skip_arm_chroma_grid_is_sized_per_axis_not_square`, witness
117+`s422_322x240.obu` (21096 B, fnv1a64 `0x9a96dda2a19d47a6`, 322x240, 8-bit,
118+16 decode frames) — chosen because it is the smallest 4:2:2 fixture that
119+actually reaches site 1 (six do: `s422_320x246` +4, `s422_322x240` +1,
120+`s422_322x246` +3, `s422_352x242_10b` +2, `s422_416x242_10b` +3,
121+`s422_416x250_10b` +3).
122+
123+Two paired counters in `decode.rs`, deliberately **not** one:
124+
125+- `skip_arm_chroma_rect_shapes` — non-vacuity. Fires only where the per-axis and
126+ square forms differ (4:2:2). The gate asserts it moved, so a witness that
127+ stopped reaching the site cannot fake a green.
128+- `skip_arm_chroma_short_samples` — the claim. Reads
129+ `chroma_side * chroma_height - u_grid.len()`, i.e. the allocation's **real
130+ length**, not a proxy condition. The gate asserts it stayed 0.
131+
132+### Mutation proof (restore the square)
133+
134+```
135+let u_grid = vec![0i32; chroma_side * chroma_side]; // restored
136+```
137+→
138+```
139+panicked at stream.rs:3204:
140+decode_block's SKIP arm chroma grids fell 64 samples SHORT of their own
141+plane block -- the square `side >> ss_x` form this lane removed allocates
142+exactly half the plane block at 4:2:2 (ss (1,0))
143+test result: FAILED. 0 passed; 1 failed
144+```
145+
146+The first gate draft used a `chroma_side != chroma_height` proxy counter and did
147+**not** bite on that mutation — a vacuous gate, caught and replaced with the
148+length-measuring counter above.
149+
150+## Tests
151+
152+| suite | result |
153+|---|---|
154+| 7 pinned `the_pinned_422_*` byte-exact gates | 7/7 ok (unchanged from base) |
155+| new `the_422_skip_arm_chroma_grid_...` | ok |
156+| 51 `444` gates | 51/51 ok, no regression |
157+| full `cargo test -p ec-av1 --lib` | timed out at 3600 s on live `aom`-encode tests (`a_real_aomenc_inter_128x128_none_root_...`); not a failure, an unfinished sweep. All 4:2:2 and 4:4:4 subsets ran green. |
158+
159+Feature note: the gate's counters are behind the existing `gate-counters`
160+feature like every other counter in this crate; it was run with
161+`--features gate-counters`.
162+
163+## Still open, not touched by this lane
164+
165+1. **Floor-`>>` chroma plane allocators** — `decode.rs` frame-edge allocators
166+ named at `av1subsizesweep.report.md:242`. Out of charter; untouched.
167+2. **`palette_uv_side`** (`tile.rs`) — gated by `lane/av1paletteuv`, untouched.
168+3. **Sites 2 and 8 at 4:2:2** — allocation is sound (enclosing square), but no
169+ committed 4:2:2 fixture reaches them. A 128-root 4:2:2 compound or
170+ intra-in-inter witness would close the reachability question; **no fix is
171+ warranted** and none was written.
172+4. The two stride conventions in the block-tail replay — `chroma_stride` at
173+ `decode.rs:47347` (lossless) vs `chroma_side` at `47387` (non-lossless).
174+ Both correct for their own writer; noted as a convention split, not a defect.
175+
176+## Reproduction
177+
178+```
179+git worktree add ~/.cache/wt/av1muchroma -b lane/av1muchroma 820eeb68
180+cd ~/.cache/wt/av1muchroma
181+CARGO_TARGET_DIR=~/.cache/muchroma-target \
182+ cargo test -p ec-av1 --lib --features gate-counters -- \
183+ the_pinned_422 the_422_skip
184+```
185+
186+`ffmpeg` is on `PATH`; the byte-exact gates run live against it.
\ No newline at end of file\ No newline at end of file