forge
Explore
Log in

Don't you dare go Hollow

ec-av1: lane-av1-ibc128chunk r2 -- the mu_chroma replay walks chunk THEN unit, report red counts corrected

Browse files at this commit

fda214d89d7466b07efbe32d7510c97afd0851faAhmet Kaan GümüşParent: a50f363
Review r1 found a real coverage regression this lane introduced, and a
wrong attribution in the report.

P2, the defect. r1 gave the mu_chroma replay per-axis EXTENTS but kept the
old STEP: rows/cols count mu CHUNKS (ch / chunk_chroma_h) while the loop
body advanced the mi origin and read the grid PER UNIT (cr *
(unit_luma_h / MI), grid (cr * chunk_chroma_h)). Those agree only when a
chunk holds exactly one unit. At 4:2:0 (chunk_chroma == cu == 32) it is
line-identical to the parent, so nothing measured it; at 4:2:2
(chunk_chroma_h = 64 = 2 * cu) the body reached only the FIRST of the two
stacked units per chunk, so rows mi_r+8 .. mi_r+16 kept the composed-grid
smearing the replay exists to undo. The parent reached those rows (wrong
span, full coverage), so this was a regression r1 added, not a pre-existing
gap.

The reshape is the twin's chunk-then-unit loop (decode_inter_block's
mu_chroma_units, lane-av1-444 c8): (ur, uc) = (chunk_chroma_h / cu,
chunk_chroma_w / cu), inner `for kr in 0..ur { for kc in 0..uc {`, mi
origin (cr * 64 + kr * unit_luma_h) / MI per axis -- cr * 64 is the mu
chunk's LUMA-px step, 64 on both axes at every subsampling, which is why
the twin can write it unshifted -- and grid origin (cr * chunk_chroma_h +
kr * cu). At 4:2:0 ur/uc are 1 so kr/kc are 0 and the whole thing
collapses to r1's walk, line for line.

The LOSSLESS arm is pre-existing and deliberately untouched. On a lossless
frame cu is 4 and the composed grid is a raster of TX_4x4 units, so the
chunk-counted rows/cols do not enumerate it at all: that arm re-stamps
only the 4x4 at each chunk's top-left with a 2x2-mi span, where the twin
raster-walks the whole plane block (lane-av1-llinter). It is a 4:2:0
defect, not a subsampling square-cut, so it is out of this lane's class,
and fixing it would change 4:2:0 LOSSLESS output on a reconstruction with
no witness to verify it. Measured unreachability: a temporary env-gated
counter in the arm records 0 hits across the whole lossless and intrabc
gate battery (13 + 19 tests). Unblock named in the report.

P3, the report. The red counts were attributed to the wrong fixture: the
primary witness 422_intrabc_sb128_strip.obu is 46891 (f0) / 44842 (f3) on
the parent, 45135 / 44540 is the _notxsearch arm's. Both re-measured per
fixture and the table now reports each arm separately. The first
difference is byte 98368 = f0 Y row 256 col 64 on both -- the top-left of
the first 128x64 intrabc block at mi(64,0) -- and green is 0/0/0/0/0.

Re-measured after the reshape: both witnesses byte-identical to r1's
output (6 blocks, 48 chroma units, 5/5 frames exact vs aomdec), so the
reshape is a pure coverage repair. Gate battery 7/0 -- the four named
gates, both new gates and the bigblock pin gate -- plus intrabc 19/0 and
422+444+lossless 20/0; cargo check --all-targets 0 warnings. The source
scan gains the chunk-then-unit pins and its non-vacuity is measured twice:
forcing (ur, uc) = (1, 1) fails it (found 0), and re-introducing the
square cut at the read-walk site fails it (left: 1, right: 0). The
EC_AV1_ALLOW_422_PROBE bypass is NOT in the commit.
crates/ec-av1/src/decode.rsmodified+85 -26
@@ -12886,38 +12886,97 @@ fn decode_intrabc_128rect(
1288612886 let cu = if lossless(fctx) { 4usize } else { 32usize };
1288712887 // The unit's own footprint on the LUMA mi grid (the chroma context
1288812888 // bands are luma-mi indexed, [`Self::record_mi_chroma`]'s
12889- // convention), PER AXIS: `cu << ss` px, i.e. 8 px per TX_4X4 unit and
12889+ // convention), PER AXIS: `cu << ss` px, i.e. 8 px per TX_4x4 unit and
1289012890 // 64 px per TX_32X32 one at 4:2:0 -- 4 px / 32 px at 4:2:2.
1289112891 let unit_luma_w = cu << ss_x(fctx);
1289212892 let unit_luma_h = cu << ss_y(fctx);
12893- // Raster over the block's chroma plane, one mu chunk per axis step at
12894- // its own per-axis chroma extent (the same extents the read loop
12895- // above laid the composed grid out at) -- a unit the frame edge
12896- // clipped codes nothing and carries no composed samples beyond the
12897- // clip, so it replays as the zero state exactly like libaom's
12898- // uncoded unit. lane-av1-ibc128chunk: the old `chunk_chroma = cside *
12899- // 64 / side` cut the replay's step to the 4:2:0 square on BOTH axes,
12900- // so at 4:2:2 it walked a 32-row step down a 64-row chunk and
12901- // re-stamped a 16x16-mi span over an 8-row-tall unit.
12893+ // A 64x64 mu chunk's chroma plane block is PER-AXIS
12894+ // `(64 >> ss_x) x (64 >> ss_y)` -- 32x32 at 4:2:0 (ONE TX_32X32 per
12895+ // chunk), 32x64 at 4:2:2 (TWO STACKED), 64x64 at 4:4:4 (FOUR);
12896+ // `av1_get_max_uv_txsize` caps the unit at 32 on each axis.
1290212897 let chunk_chroma_w = (64usize) >> ss_x(fctx);
1290312898 let chunk_chroma_h = (64usize) >> ss_y(fctx);
12904- let (rows, cols) = ((ch / chunk_chroma_h).max(1), (cw / chunk_chroma_w).max(1));
12905- for cr in 0..rows {
12906- for cc in 0..cols {
12907- let unit_mi = (
12908- mi_r + cr * (unit_luma_h / MI),
12909- mi_c + cc * (unit_luma_w / MI),
12910- );
12911- for (plane_idx, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {
12912- let mut unit = Vec::with_capacity(cu * cu);
12913- for rr in 0..cu {
12914- let start = (cr * chunk_chroma_h + rr) * cside
12915- + cc * chunk_chroma_w;
12916- unit.extend_from_slice(&grid[start..start + cu]);
12917- }
12918- neighbours.record_mi_chroma(
12919- unit_mi, unit_luma_w, unit_luma_h, plane_idx, &unit,
12899+ if lossless(fctx) {
12900+ // lane-av1-ibc128chunk, PRE-EXISTING and NOT this lane's: on a
12901+ // LOSSLESS frame `cu` is 4 and the composed plane grid is a raster
12902+ // of TX_4x4 units, not a `cu`-per-chunk tiling -- so `rows`/`cols`
12903+ // below (which count mu CHUNKS at the 4:2:0 chunk extent) do not
12904+ // enumerate it, and this arm re-stamps only the 4x4 at each
12905+ // chunk's top-left with a 2x2-mi span. The twin
12906+ // (`decode_inter_block`'s `mu_chroma_units`, lane-av1-llinter)
12907+ // instead raster-walks the WHOLE plane block at `cu` steps, and
12908+ // that is the correct shape here too. It is left as-is on purpose:
12909+ // it is a 4:2:0 defect, not a subsampling square-cut, and fixing
12910+ // it would change 4:2:0 LOSSLESS output -- which this lane's
12911+ // byte-identity requirement forbids doing on an unverified
12912+ // reconstruction. Measured unreachability: this arm is entered
12913+ // 0 times by the whole `lossless` and `intrabc` gate battery
12914+ // (temporary env-gated counter in the arm). Unblock: one
12915+ // lossless sb128 4:2:0 stream coding a NON-SKIP 128-root
12916+ // intrabc strip (`--lossless=1 --sb-size=128
12917+ // --min-partition-size=64 --enable-rect-partitions=1
12918+ // --enable-intrabc=1` over near-match screen content).
12919+ let (rows, cols) = ((ch / chunk_chroma_h).max(1), (cw / chunk_chroma_w).max(1));
12920+ for cr in 0..rows {
12921+ for cc in 0..cols {
12922+ let unit_mi = (
12923+ mi_r + cr * (unit_luma_h / MI),
12924+ mi_c + cc * (unit_luma_w / MI),
1292012925 );
12926+ for (plane_idx, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {
12927+ let mut unit = Vec::with_capacity(cu * cu);
12928+ for rr in 0..cu {
12929+ let start = (cr * chunk_chroma_h + rr) * cside
12930+ + cc * chunk_chroma_w;
12931+ unit.extend_from_slice(&grid[start..start + cu]);
12932+ }
12933+ neighbours.record_mi_chroma(
12934+ unit_mi, unit_luma_w, unit_luma_h, plane_idx, &unit,
12935+ );
12936+ }
12937+ }
12938+ }
12939+ } else {
12940+ // The chunk count on each axis, then EVERY unit inside each
12941+ // chunk at its own mi origin, its own `(cu << ss)`-px entropy-cell
12942+ // span, and its own quadrant of the composed plane grid -- the
12943+ // twin's loop (decode_inter_block's `mu_chroma_units`,
12944+ // lane-av1-444 c8). lane-av1-ibc128chunk: the loop used to count
12945+ // mu CHUNKS in `rows`/`cols` and then step the mi origin and read
12946+ // the grid PER UNIT, which only agrees when a chunk holds exactly
12947+ // one unit. At 4:2:0 (`chunk_chroma == cu`) it is
12948+ // line-identical to the old walk; at 4:2:2 and 4:4:4 a chunk holds
12949+ // 2 or 4, so the old body reached only the first of the stacked
12950+ // units and the rest of the chunk kept the composed-grid smearing
12951+ // this replay exists to undo. A unit the frame edge clipped codes
12952+ // nothing and carries no composed samples beyond the clip, so it
12953+ // replays as the zero state exactly like libaom's uncoded unit.
12954+ let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu);
12955+ let (rows, cols) = ((ch / chunk_chroma_h).max(1), (cw / chunk_chroma_w).max(1));
12956+ for cr in 0..rows {
12957+ for cc in 0..cols {
12958+ for kr in 0..ur {
12959+ for kc in 0..uc {
12960+ let unit_mi = (
12961+ mi_r + (cr * 64 + kr * unit_luma_h) / MI,
12962+ mi_c + (cc * 64 + kc * unit_luma_w) / MI,
12963+ );
12964+ let (cy, cx) = (
12965+ cr * chunk_chroma_h + kr * cu,
12966+ cc * chunk_chroma_w + kc * cu,
12967+ );
12968+ for (plane_idx, grid) in [(1usize, &u_grid), (2usize, &v_grid)] {
12969+ let mut unit = Vec::with_capacity(cu * cu);
12970+ for rr in 0..cu {
12971+ let start = (cy + rr) * cside + cx;
12972+ unit.extend_from_slice(&grid[start..start + cu]);
12973+ }
12974+ neighbours.record_mi_chroma(
12975+ unit_mi, unit_luma_w, unit_luma_h, plane_idx, &unit,
12976+ );
12977+ }
12978+ }
12979+ }
1292112980 }
1292212981 }
1292312982 }
crates/ec-av1/src/stream.rsmodified+23 -2
@@ -2399,8 +2399,15 @@ pub(crate) mod tests {
23992399 gate exists for (a 64x64 mu chunk's chroma plane block is \
24002400 (64 >> ss_x) x (64 >> ss_y), not `chroma_side` square)"
24012401 );
2402- // Both sites, the read walk and the replay: each declares the pair
2403- // once and each takes its steps on the per-axis halves.
2402+ // The per-axis chunk extent, declared once at the mu-chunk read walk
2403+ // and once at the `mu_chroma` replay -- the two de-square-cut sites.
2404+ //
2405+ // The replay must ALSO enumerate every unit inside a chunk, not just
2406+ // its first: counting mu CHUNKS in `rows`/`cols` and then stepping the
2407+ // mi origin and reading the grid per UNIT only agrees when a chunk
2408+ // holds exactly one unit (4:2:0). At 4:2:2 and 4:4:4 a chunk holds two
2409+ // or four, so the per-unit body alone left the rest of the chunk with
2410+ // the composed-grid smearing the replay exists to undo.
24042411 for name in [
24052412 "let chunk_chroma_w = (64usize) >> ss_x(fctx);",
24062413 "let chunk_chroma_h = (64usize) >> ss_y(fctx);",
@@ -2414,6 +2421,20 @@ pub(crate) mod tests {
24142421 body.matches(name).count()
24152422 );
24162423 }
2424+ for name in [
2425+ "let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu);",
2426+ "for kr in 0..ur {",
2427+ "for kc in 0..uc {",
2428+ ] {
2429+ assert_eq!(
2430+ body.matches(name).count(),
2431+ 1,
2432+ "{NAME}: `{name}` must appear exactly once in \
2433+ decode_intrabc_128rect -- the mu_chroma replay must walk chunk \
2434+ THEN unit (decode_inter_block's `mu_chroma_units` shape), found {}",
2435+ body.matches(name).count()
2436+ );
2437+ }
24172438 for name in [
24182439 "let unit_luma_w = cu_tx << ss_x(fctx);",
24192440 "let unit_luma_h = cu_tx << ss_y(fctx);",
lanes/av1ibc128chunk.report.mdmodified+87 -12
@@ -118,14 +118,22 @@ build, compared with `cmp` on the full raw output.
118118 | `422_intrabc_sb128_strip_notxsearch.obu` | parent `a7d22aec` | **2** | **8** | **DIFF** |
119119 | `422_intrabc_sb128_strip_notxsearch.obu` | this lane | **6** | **48** | **EXACT** |
120120
121-Frame-level detail on the primary witness (245760 samples/frame: 384x320 Y +
122-2 x 192x320 chroma):
123-
124-- **red**, frame 0: 45135 samples differ, first at byte 98368 = Y **row 256,
125- col 64** — the top-left of the first 128x64 intrabc block (traced at
126- `mi_row=64 mi_col=0`, `py = 64*4 = 256`). Frame 3 the same shape (44540
127- samples, same first offset). Frames 1, 2, 4 exact (no intrabc block).
128-- **fixed**: `cmp` identical on all 245760 x 5 bytes; 5 frames decoded, 0 hidden.
121+Frame-level detail, per fixture (245760 samples/frame: 384x320 Y + 2 x 192x320
122+chroma), re-measured per fixture after review — the first cut of this section
123+reported the `_notxsearch` arm's counts under the primary witness:
124+
125+| fixture | build | f0 | f1 | f2 | f3 | f4 |
126+|---|---|---|---|---|---|---|
127+| `422_intrabc_sb128_strip.obu` (primary) | parent `a7d22aec` | **46891** | 0 | 0 | **44842** | 0 |
128+| `422_intrabc_sb128_strip.obu` (primary) | this lane | 0 | 0 | 0 | 0 | 0 |
129+| `422_intrabc_sb128_strip_notxsearch.obu` | parent `a7d22aec` | **45135** | 0 | 0 | **44540** | 0 |
130+| `422_intrabc_sb128_strip_notxsearch.obu` | this lane | 0 | 0 | 0 | 0 | 0 |
131+
132+Both fixtures' red first difference is byte 98368 = frame 0, Y **row 256,
133+col 64** — the top-left of the first 128x64 intrabc block (traced at
134+`mi_row=64 mi_col=0`, `py = 64*4 = 256`). Frames 1, 2, 4 carry no intrabc
135+block and are exact in every build. Green: `cmp` identical on all
136+245760 x 5 bytes, 5 frames decoded, 0 hidden.
129137
130138 The red build reached only 2 of the 6 blocks: reading 4 chroma units where
131139 libaom codes 8 desynced the tile, and the remaining 4 blocks were misparsed.
@@ -137,6 +145,70 @@ position (`rng=49296` at the first block in both):
137145 red 4 stamps (1 per plane per chunk, 2 chunks)
138146 fixed 8 stamps (2 per plane per chunk, 2 chunks)
139147
148+## Rework after review (r2) — the `mu_chroma` replay's chunk/unit step
149+
150+Review r1 FAILed the first cut on a real coverage regression I introduced, and
151+corrected this report's red counts (done above; the 45135/44540 pair was the
152+`_notxsearch` arm, the primary's are 46891/44842).
153+
154+**The defect.** The first cut gave the replay per-axis *extents* but kept the
155+old *step*: `rows`/`cols` count mu CHUNKS (`ch / chunk_chroma_h`), while the
156+loop body advanced the mi origin and read the grid PER UNIT
157+(`cr * (unit_luma_h / MI)`, grid `(cr * chunk_chroma_h)`). Those agree only when
158+a chunk holds exactly one unit. At 4:2:0 (`chunk_chroma == cu == 32`) it is
159+line-identical to the parent, so nothing measured it; at 4:2:2
160+(`chunk_chroma_h = 64 = 2 * cu`) the body reached only the FIRST of the two
161+stacked units per chunk, so rows `mi_r+8 .. mi_r+16` kept the composed-grid
162+smearing the replay exists to undo. The parent reached those rows (with a wrong
163+span but full coverage), so this was a coverage regression *my* patch added,
164+not a pre-existing gap.
165+
166+**The reshape**, in the twin's chunk-then-unit loop
167+(`decode_inter_block`'s `mu_chroma_units`, decode.rs:37456-37494,
168+lane-av1-444 c8):
169+
170+ let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w / cu);
171+ for cr in 0..rows { for cc in 0..cols {
172+ for kr in 0..ur { for kc in 0..uc {
173+ unit_mi = (mi_r + (cr * 64 + kr * unit_luma_h) / MI,
174+ mi_c + (cc * 64 + kc * unit_luma_w) / MI);
175+ (cy, cx) = (cr * chunk_chroma_h + kr * cu, cc * chunk_chroma_w + kc * cu);
176+ ... let start = (cy + rr) * cside + cx;
177+
178+`cr * 64` is the mu chunk's LUMA-px step, which is 64 on both axes at every
179+subsampling — that is why the twin can write it unshifted. At 4:2:0 `ur`/`uc`
180+are 1, so `kr`/`kc` are 0, `unit_mi` collapses to `mi_r + cr*16`, and the grid
181+origin to `(cr*32, cc*32)`: **line-identical to the pre-rework walk**. The new
182+gate pins the shape, and the mutation proof below shows it is load-bearing.
183+
184+**The LOSSLESS arm is pre-existing and deliberately untouched.** On a lossless
185+frame `cu` is 4 and the composed grid is a raster of TX_4x4 units, so the
186+chunk-counted `rows`/`cols` do not enumerate it at all: that arm re-stamps only
187+the 4x4 at each chunk's top-left with a 2x2-mi span. The twin raster-walks the
188+whole plane block instead (lane-av1-llinter). It is left as-is on purpose: it is
189+a **4:2:0** defect, not a subsampling square-cut, so it is out of this lane's
190+class, and fixing it would change 4:2:0 LOSSLESS output — which this lane's
191+byte-identity requirement forbids doing on a reconstruction I have no witness
192+to verify. Measured unreachability: a temporary env-gated counter in the arm
193+records **0 hits across the whole `lossless` and `intrabc` gate battery**
194+(13 + 19 tests). Unblock: one lossless sb128 4:2:0 stream coding a NON-SKIP
195+128-root intrabc strip (`--lossless=1 --sb-size=128 --min-partition-size=64
196+then the twin's raster reshape plus a witness. Carried as a named pre-existing,
197+not as a silent skip.
198+
199+**Re-measured after the reshape (r2):** both witnesses byte-identical to
200+`a7d22aec`-relative tip r1's output (6 blocks, 48 chroma units, 5/5 frames exact
201+vs `aomdec`) — the reshape is a pure coverage repair, no output change on any
202+witness. `an_sb128_rect_strip_with_intrabc_decodes_pixel_exact`,
203+`an_sb128_screen_stream_with_intrabc_decodes_pixel_exact`,
204+`a_lossless_sb128_rect_intra_block_decodes_sample_exact`,
205+`a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact`,
206+`the_pinned_422_bigblock_witnesses_are_present_and_refuse_by_name` and both new
207+gates: **7 passed / 0 failed**. Two mutation proofs on the source-scan arm,
208+both FAILING it: forcing `let (ur, uc) = (1, 1);` (the per-chunk-only shape)
209+gives `found 0`; re-introducing `cside * 64 / side` at the read-walk site gives
210+`left: 1, right: 0`. Restored, the gate passes.
211+
140212 ## Reproduce (patch-run-restore, local only)
141213
142214 python3 - <<'EOF'
@@ -171,13 +243,16 @@ position (`rng=49296` at the first block in both):
171243 source-scan arm. Scans `decode_intrabc_128rect`'s body **with comments
172244 stripped** (the fix's own comments quote the old expression to say what it
173245 was) and pins: zero `cside * 64 / side`; the `chunk_chroma_w/h` pair at
174- **both** de-square-cut sites (read walk and `mu_chroma` replay); the
246+ **both** de-square-cut sites (read walk and `mu_chroma` replay); the replay's
247+ chunk-then-unit shape (`let (ur, uc) = (chunk_chroma_h / cu, chunk_chroma_w /
248+ cu);`, `for kr in 0..ur {`, `for kc in 0..uc {` — the r2 coverage fix); the
175249 `unit_luma_w/h`, `cw/ch`, `cpx/cpy` and `around_mi_rect` forms once each; the
176250 replay's own `cu << ss` pair; the per-axis unit arithmetic
177251 (`(64>>ss_x)/32 * (64>>ss_y)/32` = 1 / 2 / 4 at 4:2:0 / 4:2:2 / 4:4:4); and
178- both new counter accessors. **Non-vacuity measured**: re-introducing
179- `let chunk_chroma_w = cside * 64 / side;` at the read-walk site makes it fail
180- with `left: 1, right: 0`; restored, it passes.
252+ both new counter accessors. **Non-vacuity measured twice**: forcing
253+ `let (ur, uc) = (1, 1);` (the per-chunk-only shape) fails it with
254+ `found 0`, and re-introducing `let chunk_chroma_w = cside * 64 / side;` at
255+ the read-walk site fails it with `left: 1, right: 0`; restored, it passes.
181256
182257 ## Byte-identity outside 4:2:2
183258