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! {
61166116 static INTRABC_RECT4_OWN_CHROMA444_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
61176117 }
61186118
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+
61196140 /// Current value of [`INTRABC_RECT4_OWN_CHROMA444_HITS`].
61206141 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
61216142 pub(crate) fn intrabc_rect4_own_chroma444_hits() -> usize {
@@ -18218,10 +18239,31 @@ fn decode_rect4_16_intrabc(
1821818239 // `--enable-intrabc=0` at the same settings is byte-exact, and the 4:2:0
1821918240 // twin of the same recipe is byte-exact.
1822018241 //
18221- // 4:2:0 and 4:2:2 keep every constant below verbatim -- the arm is gated on
18222- // the full ss (0,0), not on a per-axis shift, so `pw / 2` and the literal
18223- // halving are untouched for both.
18242+ // 4:2:0 alone keeps every constant below verbatim: a 1:4 strip's chroma
18243+ // plane block is 4:2:0's PAIR (the block above / beside it), because at
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.
1822418259 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;
1822518267 if ss_x(fctx) == 0 && ss_y(fctx) == 0 && has_chroma {
1822618268 hit!(INTRABC_RECT4_OWN_CHROMA444_HITS);
1822718269 }
@@ -18232,9 +18274,13 @@ fn decode_rect4_16_intrabc(
1823218274 } else {
1823318275 (8, 16)
1823418276 };
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+ };
1823618282 let pair_mi = if has_chroma {
18237- if own444 {
18283+ if own_chroma {
1823818284 lmi
1823918285 } else if horz {
1824018286 (lmi.0 - 1, lmi.1)
@@ -18245,8 +18291,8 @@ fn decode_rect4_16_intrabc(
1824518291 lmi
1824618292 };
1824718293 let (cpx, cpy) = if has_chroma {
18248- if own444 {
18249- (px, py)
18294+ if own_chroma {
18295+ (px >> ss_x(fctx), py >> ss_y(fctx))
1825018296 } else {
1825118297 (pair_mi.1 * MI / 2, pair_mi.0 * MI / 2)
1825218298 }
@@ -18528,7 +18574,25 @@ fn decode_rect4_16_intrabc(
1852818574 Grid::Own(vo)
1852918575 };
1853018576 } 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+ };
1853218596 let (ug, _) = read_inter_plane_rect(
1853318597 dec,
1853418598 cdfs,
@@ -18589,7 +18653,18 @@ fn decode_rect4_16_intrabc(
1858918653 luma_grid = g;
1859018654 chroma_stamped_per_unit = false;
1859118655 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+ };
1859318668 let (ug, _) = read_inter_plane_rect(
1859418669 dec,
1859518670 cdfs,
@@ -18652,24 +18727,33 @@ fn decode_rect4_16_intrabc(
1865218727 let mut last_uv = None;
1865318728 if has_chroma {
1865418729 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);
1865618740 if !chroma_stamped_per_unit {
1865718741 let u_state = neighbour_state(&u_grid);
1865818742 let v_state = neighbour_state(&v_grid);
1865918743 let round_up_even = |n: usize| n.div_ceil(2) * 2;
1866018744 let bound_h = round_up_even(neighbours.mi_rows);
1866118745 let bound_w = round_up_even(neighbours.mi_cols);
18662- for cell in 0..(ph / MI) {
18663- if pair_mi.0 + cell < bound_h
18664- && let Some(slot) = neighbours.left.get_mut(pair_mi.0 + cell)
18746+ for cell in 0..(rh / MI) {
18747+ if rmi.0 + cell < bound_h
18748+ && let Some(slot) = neighbours.left.get_mut(rmi.0 + cell)
1866518749 {
1866618750 slot[1] = u_state;
1866718751 slot[2] = v_state;
1866818752 }
1866918753 }
18670- for cell in 0..(pw / MI) {
18671- if pair_mi.1 + cell < bound_w
18672- && let Some(slot) = neighbours.above.get_mut(pair_mi.1 + cell)
18754+ for cell in 0..(rw / MI) {
18755+ if rmi.1 + cell < bound_w
18756+ && let Some(slot) = neighbours.above.get_mut(rmi.1 + cell)
1867318757 {
1867418758 slot[1] = u_state;
1867518759 slot[2] = v_state;