forge
Explore
Log in

Don't you dare go Hollow

lane-av1422luma: 4:2:2 IntraBC 1:4 strips code their OWN chroma -- six sweep cells byte-exact, luma desync gone

Browse files at this commit

3ce52f6537f95a0e3794f313e3de8719a831e7a4Ahmet Kaan GümüşParent: 4ef5ae8
An intra-BC 16x4 (HORZ 1:4) strip's chroma plane block is its own at
4:2:2, not 4:2:0's pair: 4:2:2 subsamples x only, so the strip's chroma
is 8x4 (full height) at the strip's own origin, and libaom's own
is_chroma_reference (av1_common_int.h:1454) ends in "|| !subsampling_y",
which answers true for every block at ss_y 0. decode_rect4_16_intrabc
gated that whole pair geometry on ss (0,0) and left 4:2:2 on the 4:2:0
constants, so the chroma unit was read one mi row high. On
s422_416x250_10b (416x250 10-bit, sha256 d6aa7f45) that is the U/V
txb_skip read at mi (51,84): ctx 2 where the oracle reads 8, all_zero
decoded 1 instead of 0, and the frame desyncs from there -- which is why
this is the one 4:2:2 cell whose LUMA is wrong too.

Four sites move together, all gated on the new own422 = ss (1,0) && horz:
  - cw,ch      = (bw >> ss_x, bh >> ss_y)      (was (pw/2, ph/2))
  - pair_mi    = lmi                           (was (lmi.0-1, lmi.1))
  - cpx,cpy    = (px >> ss_x, py >> ss_y)      (was (pair_mi.1*MI/2, ...))
  - the chroma coefficient-context gather and the uv-mode / left / above
    publication read over the strip's OWN extent, and at ss (1,0) through
    around_mi_422_chroma (one chroma 4-px column spans two luma mi
    columns, so the per-mi gather double-counts each column's whole-unit
    dc sign and ORs in cells the unit does not cover)

The first three are lane/av1422seed's hunk, unlanded at the time of
writing and reproduced here so the arm is measurable whole; the gather and
the publication are this lane's. VERT_4 stays on the pair:
ss_size_lookup[BLOCK_4X16][1][0] is BLOCK_INVALID at 4:2:2, so only HORZ
reaches it. 4:4:4 keeps the per-mi gather (at ss_x 0 a chroma column IS a
luma mi column, so sampling would halve its own above span) and 4:2:0 is
untouched by construction.

Measured (ffmpeg 8.1.3 oracle, 16 shown frames, per-plane wrong samples;
pre = main 1bc6f543 with a patch-run-restore 4:2:2 probe bypass, post =
this tree, same bypass, same comparator):

  s422_320x246      0/7810/5531   -> 0/0/0        BYTE-EXACT
  s422_322x240      0/22003/21625 -> 0/0/0        BYTE-EXACT
  s422_322x246      0/3437/2222   -> 0/0/0        BYTE-EXACT
  s422_352x242_10b  0/4653/3777   -> 0/0/0        BYTE-EXACT
  s422_416x242_10b  0/5740/4348   -> 0/0/0        BYTE-EXACT
  s422_416x250_10b  99011/61486/60106 -> 0/0/0     BYTE-EXACT (this lane's cell)

25 of the 26 swept cells are byte-exact after the change; s422_384x240 is
unchanged at 0/1780/1871 and is a different residual. 4:2:0 10-bit
(s420_416x250_10b, s420_416x242_10b, s420_352x242_10b, s420_320x242_10b,
s420_320x250_10b) and 4:4:4 10-bit (s444_416x250_10b, s444_352x242_10b,
s444_320x250_10b) are byte-exact before and after. In DECODE order (17
frames, hidden alt-refs included) s422_416x250_10b is 17/17 byte-exact
against the instrumented aomdec, and so are s422_416x242_10b and
s422_320x246.

Gate: a_444_intrbac_rect4_reads_its_own_chroma_plane_block passes with
the 4:4:4 numbers unchanged (23 own-chroma strips, first wrong sample
index 20532, entropy fork read 12465 at mi (90,108)) and the 4:2:0 twin
byte-exact; the 26 intrabc-named tests pass. 4:2:2 is refused at the
sequence header, so no committed test can assert the new route: a
INTRABC_RECT4_OWN_CHROMA422_HITS counter records reach (56 HORZ 1:4
strips in frame 0 of the reproducer alone) and lanes/av1422luma.report.md
carries the measurement. The 4:2:2 refusal is untouched in this tree.
crates/ec-av1/src/decode.rsmodified+100 -16
@@ -6116,6 +6116,27 @@ thread_local! {
6116 static INTRABC_RECT4_OWN_CHROMA444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };6116 static INTRABC_RECT4_OWN_CHROMA444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
6117 }6117 }
6118 6118
6119+// lane-av1422luma: the ss (1,0) twin of `INTRABC_RECT4_OWN_CHROMA444_HITS`
6120+// -- how many intra-BC 1:4 strips at 4:2:2 took the own-chroma (no pair)
6121+// route. Same caveat as the 4:4:4 counter: it proves REACH and nothing else,
6122+// and 4:2:2 is refused at the sequence header, so no committed test can read
6123+// it (the count in `lanes/av1422luma.report.md` is from a bypassed probe build).
6124+thread_local! {
6125+ static INTRABC_RECT4_OWN_CHROMA422_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
6126+}
6127+
6128+/// Current value of [`INTRABC_RECT4_OWN_CHROMA422_HITS`].
6129+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
6130+pub(crate) fn intrabc_rect4_own_chroma422_hits() -> usize {
6131+ INTRABC_RECT4_OWN_CHROMA422_HITS.with(std::cell::Cell::get)
6132+}
6133+
6134+/// Resets [`INTRABC_RECT4_OWN_CHROMA422_HITS`] before a decode.
6135+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
6136+pub(crate) fn reset_intrabc_rect4_own_chroma422_hits() {
6137+ INTRABC_RECT4_OWN_CHROMA422_HITS.with(|c| c.set(0));
6138+}
6139+
6119 /// Current value of [`INTRABC_RECT4_OWN_CHROMA444_HITS`].6140 /// Current value of [`INTRABC_RECT4_OWN_CHROMA444_HITS`].
6120 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates6141 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
6121 pub(crate) fn intrabc_rect4_own_chroma444_hits() -> usize {6142 pub(crate) fn intrabc_rect4_own_chroma444_hits() -> usize {
@@ -18218,10 +18239,31 @@ fn decode_rect4_16_intrabc(
18218 // `--enable-intrabc=0` at the same settings is byte-exact, and the 4:2:018239 // `--enable-intrabc=0` at the same settings is byte-exact, and the 4:2:0
18219 // twin of the same recipe is byte-exact.18240 // twin of the same recipe is byte-exact.
18220 //18241 //
18221- // 4:2:0 and 4:2:2 keep every constant below verbatim -- the arm is gated on18242+ // 4:2:0 alone keeps every constant below verbatim: a 1:4 strip's chroma
18222- // the full ss (0,0), not on a per-axis shift, so `pw / 2` and the literal18243+ // plane block is 4:2:0's PAIR (the block above / beside it), because at
18223- // halving are untouched for both.18244+ // ss (1,1) the strip's 8x2 chroma lies INSIDE that neighbour's chroma.
18245+ //
18246+ // lane-av1422luma: at ss (1,0) that containment is gone -- 4:2:2 subsamples
18247+ // x only, so the strip's chroma is 8x4 (full height) at the STRIP'S OWN
18248+ // origin, and libaom's own clause agrees: `is_chroma_reference`
18249+ // (av1_common_int.h:1454) ends in `|| !subsampling_y`, which answers TRUE
18250+ // for every block at ss_y 0. Reading the strip's chroma at the 4:2:0 pair
18251+ // origin instead puts the unit one mi row high: on `s422_416x250_10b`
18252+ // (416x250 10-bit, sha256 d6aa7f45...) that is the V/U pair's `txb_skip`
18253+ // read at mi (51,84) -- ctx 2 where the oracle reads 8, `all_zero` decoded
18254+ // as 1 instead of 0, and the frame desyncs from there (luma included).
18255+ // The origin half is `lane/av1422seed`'s unlanded hunk, reproduced here so
18256+ // the arm is measurable whole; the gather and the publication extents
18257+ // below are this lane's. VERT_4 stays on the pair: `ss_size_lookup
18258+ // [BLOCK_4X16][1][0]` is BLOCK_INVALID at 4:2:2, so only HORZ reaches it.
18224 let own444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;18259 let own444 = ss_x(fctx) == 0 && ss_y(fctx) == 0;
18260+ let own422 = ss_x(fctx) == 1 && ss_y(fctx) == 0 && horz;
18261+ if own422 && has_chroma {
18262+ hit!(INTRABC_RECT4_OWN_CHROMA422_HITS);
18263+ }
18264+ // One predicate for "this strip IS its own chroma reference": the strip's
18265+ // own mi position, its own luma extent, and per-axis subsampled sizes.
18266+ let own_chroma = own444 || own422;
18225 if ss_x(fctx) == 0 && ss_y(fctx) == 0 && has_chroma {18267 if ss_x(fctx) == 0 && ss_y(fctx) == 0 && has_chroma {
18226 hit!(INTRABC_RECT4_OWN_CHROMA444_HITS);18268 hit!(INTRABC_RECT4_OWN_CHROMA444_HITS);
18227 }18269 }
@@ -18232,9 +18274,13 @@ fn decode_rect4_16_intrabc(
18232 } else {18274 } else {
18233 (8, 16)18275 (8, 16)
18234 };18276 };
18235- let (cw, ch) = if own444 { (bw, bh) } else { (pw / 2, ph / 2) };18277+ let (cw, ch) = if own_chroma {
18278+ (bw >> ss_x(fctx), bh >> ss_y(fctx))
18279+ } else {
18280+ (pw / 2, ph / 2)
18281+ };
18236 let pair_mi = if has_chroma {18282 let pair_mi = if has_chroma {
18237- if own444 {18283+ if own_chroma {
18238 lmi18284 lmi
18239 } else if horz {18285 } else if horz {
18240 (lmi.0 - 1, lmi.1)18286 (lmi.0 - 1, lmi.1)
@@ -18245,8 +18291,8 @@ fn decode_rect4_16_intrabc(
18245 lmi18291 lmi
18246 };18292 };
18247 let (cpx, cpy) = if has_chroma {18293 let (cpx, cpy) = if has_chroma {
18248- if own444 {18294+ if own_chroma {
18249- (px, py)18295+ (px >> ss_x(fctx), py >> ss_y(fctx))
18250 } else {18296 } else {
18251 (pair_mi.1 * MI / 2, pair_mi.0 * MI / 2)18297 (pair_mi.1 * MI / 2, pair_mi.0 * MI / 2)
18252 }18298 }
@@ -18528,7 +18574,25 @@ fn decode_rect4_16_intrabc(
18528 Grid::Own(vo)18574 Grid::Own(vo)
18529 };18575 };
18530 } else if has_chroma {18576 } else if has_chroma {
18531- let around = neighbours.around_mi_rect(pair_mi, pw, ph);18577+ // lane-av1422luma: the own-chroma route reads its context over its
18578+ // OWN extent; at ss (1,0) it additionally goes through the
18579+ // every-second-column gather (one chroma 4-px column spans two
18580+ // luma mi columns, so the per-mi gather would count each column's
18581+ // whole-unit dc sign twice and OR in cells the unit does not
18582+ // cover) -- the same choice the `decode_rect4_16` chroma arm
18583+ // makes at `decode.rs:19577`. 4:4:4 keeps the per-mi gather: at
18584+ // ss_x 0 a chroma column IS a luma mi column, so sampling would
18585+ // halve its own above span.
18586+ let (gmi, gw, gh) = if own_chroma {
18587+ (lmi, bw, bh)
18588+ } else {
18589+ (pair_mi, pw, ph)
18590+ };
18591+ let around = if own422 {
18592+ neighbours.around_mi_422_chroma(gmi, gw, gh)
18593+ } else {
18594+ neighbours.around_mi_rect(gmi, gw, gh)
18595+ };
18532 let (ug, _) = read_inter_plane_rect(18596 let (ug, _) = read_inter_plane_rect(
18533 dec,18597 dec,
18534 cdfs,18598 cdfs,
@@ -18589,7 +18653,18 @@ fn decode_rect4_16_intrabc(
18589 luma_grid = g;18653 luma_grid = g;
18590 chroma_stamped_per_unit = false;18654 chroma_stamped_per_unit = false;
18591 if has_chroma {18655 if has_chroma {
18592- let around = neighbours.around_mi_rect(pair_mi, pw, ph);18656+ // lane-av1422luma: as the lossless twin above -- own extent, and
18657+ // the sampled gather at 4:2:2 only.
18658+ let (gmi, gw, gh) = if own_chroma {
18659+ (lmi, bw, bh)
18660+ } else {
18661+ (pair_mi, pw, ph)
18662+ };
18663+ let around = if own422 {
18664+ neighbours.around_mi_422_chroma(gmi, gw, gh)
18665+ } else {
18666+ neighbours.around_mi_rect(gmi, gw, gh)
18667+ };
18593 let (ug, _) = read_inter_plane_rect(18668 let (ug, _) = read_inter_plane_rect(
18594 dec,18669 dec,
18595 cdfs,18670 cdfs,
@@ -18652,24 +18727,33 @@ fn decode_rect4_16_intrabc(
18652 let mut last_uv = None;18727 let mut last_uv = None;
18653 if has_chroma {18728 if has_chroma {
18654 hit!(RECT4_16_CHROMA_HITS);18729 hit!(RECT4_16_CHROMA_HITS);
18655- neighbours.record_uv_mode_mi(pair_mi.0, pair_mi.1, pw / MI, ph / MI, DC_PRED);18730+ // lane-av1422luma: the uv-mode publication and the left/above skip
18731+ // state below are the STRIP's own at 4:2:2 / 4:4:4 -- publishing the
18732+ // pair extent (one mi row off, `ph`/`pw`) is what the NEXT block's
18733+ // chroma skip context then reads.
18734+ let (rmi, rw, rh) = if own_chroma {
18735+ (lmi, bw, bh)
18736+ } else {
18737+ (pair_mi, pw, ph)
18738+ };
18739+ neighbours.record_uv_mode_mi(rmi.0, rmi.1, rw / MI, rh / MI, DC_PRED);
18656 if !chroma_stamped_per_unit {18740 if !chroma_stamped_per_unit {
18657 let u_state = neighbour_state(&u_grid);18741 let u_state = neighbour_state(&u_grid);
18658 let v_state = neighbour_state(&v_grid);18742 let v_state = neighbour_state(&v_grid);
18659 let round_up_even = |n: usize| n.div_ceil(2) * 2;18743 let round_up_even = |n: usize| n.div_ceil(2) * 2;
18660 let bound_h = round_up_even(neighbours.mi_rows);18744 let bound_h = round_up_even(neighbours.mi_rows);
18661 let bound_w = round_up_even(neighbours.mi_cols);18745 let bound_w = round_up_even(neighbours.mi_cols);
18662- for cell in 0..(ph / MI) {18746+ for cell in 0..(rh / MI) {
18663- if pair_mi.0 + cell < bound_h18747+ if rmi.0 + cell < bound_h
18664- && let Some(slot) = neighbours.left.get_mut(pair_mi.0 + cell)18748+ && let Some(slot) = neighbours.left.get_mut(rmi.0 + cell)
18665 {18749 {
18666 slot[1] = u_state;18750 slot[1] = u_state;
18667 slot[2] = v_state;18751 slot[2] = v_state;
18668 }18752 }
18669 }18753 }
18670- for cell in 0..(pw / MI) {18754+ for cell in 0..(rw / MI) {
18671- if pair_mi.1 + cell < bound_w18755+ if rmi.1 + cell < bound_w
18672- && let Some(slot) = neighbours.above.get_mut(pair_mi.1 + cell)18756+ && let Some(slot) = neighbours.above.get_mut(rmi.1 + cell)
18673 {18757 {
18674 slot[1] = u_state;18758 slot[1] = u_state;
18675 slot[2] = v_state;18759 slot[2] = v_state;