forge
Explore
Log in

Don't you dare go Hollow

4:4:4 witness pin + ss-derived chroma extent at the 128-root intra-BC strip

Browse files at this commit

287d79c7d0fe62b925f080b123d895bad7c02344Ahmet Kaan GümüşParent: ecb98e2
Pins crates/ec-av1/fixtures/r512.obu (6948 B, blob bff992e9, taken from
lane-chromahalvings-r3 -- the only one of the three chromahalvings refs
that carries it) and replaces `decode_intrabc_owned_rect`'s hardcoded
`(bw / 2, bh / 2)` chroma extent and its eight `px / 2, py / 2` chroma MV
origin pairs with the ss-derived `>> ss_x` / `>> ss_y` forms.

libaom: `av1_get_max_uv_txsize` (blockd.h:1372) is
`max_txsize_rect_lookup[get_plane_block_size(bsize, ss_x, ss_y)]` through
`av1_get_adjusted_tx_size`, and `get_plane_block_size` is
`ss_size_lookup[bsize]` -- at ss (0,0) the chroma plane block IS the
luma footprint. At 4:2:0 the two forms are the same arithmetic.

RED-BEFORE, measured on the UNPATCHED line in this worktree, per-plane
sample counts against the instrumented aomdec (`EC_AV1_FINAL_DUMP`):

  f0  Y 166229 wrong from 65728 | U 155383 from 32848 | V 153498 from 32848
  f1  Y       0 (byte-exact)   | U 74708 from 49282  | V 73501 from 49280
  f2  Y       0 (byte-exact)   | U  9216 from 114880 | V  8192 from 229760

Luma byte-exact on f1 and f2 while chroma is wrong is the signature that
makes this a chroma-plane sizing defect and not a block-geometry one.

New counter IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS: the 128-root
intra-BC strips whose chroma plane block was sized at ss (0,0). At 4:2:0
the corrected and halving forms are identical, so >= 1 cannot be
satisfied by a 4:2:0 stream; the arm is exclusive to this function.

Gate `a_444_intrabc_owned_rect_strip_refuses_the_missing_rect_chroma_
coefficient_set` asserts -- deliberately -- that the witness is now
REFUSED with the exact string "a rectangular inter chroma transform unit
whose shape has no coefficient table set here". That is the state this
commit lands in: the extent is libaom-correct, and a 4:4:4 32x64 luma
block's chroma plane block is 32x64, which this crate has no
`TxbSet` for. The gate exists so the day that arm lands the gate goes RED
and the assertion has to become the pixel-exactness check. Reach proof
for the site, on the whole witness with EC_HALVSWEEP=1: 5 strips
(mi 32x64 skip=false at mi(32,40); 32x64 skip=true at mi(48,64); 16x64
skip=true at mi(64,108); 32x64 skip=true at mi(112,96) and mi(112,104)).
crates/ec-av1/fixtures/r512.obuadded+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+56 -50
@@ -4708,6 +4708,16 @@ thread_local! {
47084708 /// be satisfied by any older route.
47094709 static INTRABC_RECT_LOSSLESS_CHROMA4_HITS: std::cell::Cell<usize> =
47104710 const { std::cell::Cell::new(0) };
4711+ /// lane-av1chromarect: 128-root intra-BC HORZ/VERT strips
4712+ /// ([`decode_intrabc_owned_rect`]) whose chroma plane block was sized
4713+ /// `bw >> ss_x` by `bh >> ss_y` -- the 4:4:4 and 4:4:0 cells, where
4714+ /// `av1_get_max_uv_txsize` (`ss_size_lookup[bsize]`, blockd.h:1372) applies
4715+ /// no halving of its own. At 4:2:0 the two forms are the same arithmetic,
4716+ /// so a `>= 1` witness can only come from a stream that is not 4:2:0.
4717+ /// EXCLUSIVE to this arm: no other caller sizes a 128-root intra-BC
4718+ /// strip's chroma plane block.
4719+ static IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS: std::cell::Cell<usize> =
4720+ const { std::cell::Cell::new(0) };
47114721 }
47124722
47134723 /// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed,
@@ -4751,6 +4761,18 @@ pub(crate) fn reset_ibc_rect_chroma_footprint_444_hits() {
47514761 IBC_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0));
47524762 }
47534763
4764+/// lane-av1chromarect: [`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS`].
4765+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4766+pub fn ibc_owned_rect_chroma_footprint_444_hits() -> usize {
4767+ IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.get())
4768+}
4769+
4770+/// lane-av1chromarect: zeroes [`IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS`].
4771+#[allow(dead_code)] // read only from the `#[cfg(test)]` gates
4772+pub(crate) fn reset_ibc_owned_rect_chroma_footprint_444_hits() {
4773+ IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0));
4774+}
4775+
47544776 /// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`].
47554777 #[allow(dead_code)] // read only from the `#[cfg(test)]` gates
47564778 pub fn intrabc_rect_lossless_chroma4_hits() -> usize {
@@ -16838,25 +16860,31 @@ fn decode_intrabc_owned_rect(
1683816860 ) -> Result<()> {
1683916861 let _ = base_q_idx;
1684016862 let (px, py) = (mi_c * MI, mi_r * MI);
16841- // lane-av1chromahalvings r5: libaom-WRONG at 4:4:4 -- `av1_get_max_uv_txsize`
16842- // is `ss_size_lookup[bsize]` and `get_vartx_max_txsize` (blockd.h:1447) reads
16843- // that plane block as `max_txsize_rect_lookup[plane_bsize]`, so chroma extent
16844- // == luma extent at ss (0,0) -- and the chroma MV origins below are the
16845- // prediction half of the same defect. MEASURED on the 4:4:4 LOSSY witness
16846- // fixtures/r512.obu, chroma-only, luma byte-exact on both inter frames.
16847- // BLOCKED, not missing: with the ss-derived extent the decode REFUSES --
16848- // "a rectangular inter chroma transform unit whose shape has no coefficient
16849- // table set here" -- because a 4:4:4 32x64 chroma plane block needs a
16850- // `TxbSet` this crate lacks. The fix is a new coefficient set, not a swap.
16851- // Left as the halving deliberately: turning a decoding stream into a
16852- // refusal is a behaviour change with its own decision. See
16853- // lanes/av1chromahalvings.report.md r5.
16863+ // lane-av1chromarect: libaom does NOT halve a 128-root intra-BC strip's
16864+ // chroma plane block. `av1_get_max_uv_txsize` (blockd.h:1372) is
16865+ // `max_txsize_rect_lookup[get_plane_block_size(bsize, ss_x, ss_y)]` run
16866+ // through `av1_get_adjusted_tx_size`, and `get_plane_block_size` is
16867+ // `ss_size_lookup[bsize]` -- at 4:4:4 the chroma plane block is the block's
16868+ // OWN footprint, so the extent below and the eight chroma MV origin pairs
16869+ // that follow must be `>> ss_x` / `>> ss_y`, not `/ 2`. At 4:2:0
16870+ // (`ss_x == ss_y == 1`) the two forms are the same arithmetic.
16871+ // MEASURED on the 4:4:4 LOSSY witness `fixtures/r512.obu` (6948 B, 3
16872+ // frames, 5 strips through this function): with the halving, frame 0
16873+ // diverges from the aomdec oracle in 166229 Y / 155383 U / 153498 V
16874+ // samples and both later frames keep luma byte-exact while 74708 U +
16875+ // 73501 V (f1) and 9216 U + 8192 V (f2) are wrong -- chroma-only, which is
16876+ // what makes this a chroma-sizing defect and not a block-geometry one.
16877+ // Re-measured by this lane; see lanes/av1chromarect.report.md.
1685416878 if crate::envflags::env_flag!("EC_HALVSWEEP") {
1685516879 eprintln!("EC_HALV ibc_owned mi=({mi_r},{mi_c}) bw={bw} bh={bh} skip={skip}");
1685616880 }
16857- let (cw, ch) = (bw / 2, bh / 2);
16881+ let (cw, ch) = (bw >> ss_x(fctx), bh >> ss_y(fctx));
16882+ let (cpx, cpy) = (px >> ss_x(fctx), py >> ss_y(fctx));
1685816883 let side = bw.max(bh);
1685916884 let cside = cw.max(ch);
16885+ if ss_x(fctx) == 0 && ss_y(fctx) == 0 {
16886+ hit!(IBC_OWNED_RECT_CHROMA_FOOTPRINT_444_HITS);
16887+ }
1686016888 let saved_reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get);
1686116889 let saved_tx = fctx.tx_select_inter.with(std::cell::Cell::get);
1686216890 fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set));
@@ -16871,30 +16899,8 @@ fn decode_intrabc_owned_rect(
1687116899
1687216900 flush_recon(fctx, y, u, v);
1687316901 let pred_y = predict_intrabc_window(y, px, py, bw, bh, dv_col, dv_row, true, side, fctx);
16874- let pred_u = predict_intrabc_window(
16875- u,
16876- px / 2,
16877- py / 2,
16878- cw,
16879- ch,
16880- dv_col,
16881- dv_row,
16882- false,
16883- cside,
16884- fctx,
16885- );
16886- let pred_v = predict_intrabc_window(
16887- v,
16888- px / 2,
16889- py / 2,
16890- cw,
16891- ch,
16892- dv_col,
16893- dv_row,
16894- false,
16895- cside,
16896- fctx,
16897- );
16902+ let pred_u = predict_intrabc_window(u, cpx, cpy, cw, ch, dv_col, dv_row, false, cside, fctx);
16903+ let pred_v = predict_intrabc_window(v, cpx, cpy, cw, ch, dv_col, dv_row, false, cside, fctx);
1689816904
1689916905 let mi_cols = 2 * y.true_width.div_ceil(8);
1690016906 let mi_rows = 2 * y.true_height.div_ceil(8);
@@ -16928,8 +16934,8 @@ fn decode_intrabc_owned_rect(
1692816934 );
1692916935 push_mc_rect(
1693016936 1,
16931- px / 2,
16932- py / 2,
16937+ cpx,
16938+ cpy,
1693316939 cside,
1693416940 cw,
1693516941 ch,
@@ -16939,8 +16945,8 @@ fn decode_intrabc_owned_rect(
1693916945 );
1694016946 push_mc_rect(
1694116947 2,
16942- px / 2,
16943- py / 2,
16948+ cpx,
16949+ cpy,
1694416950 cside,
1694516951 cw,
1694616952 ch,
@@ -17044,8 +17050,8 @@ fn decode_intrabc_owned_rect(
1704417050 around[1],
1704517051 0,
1704617052 u,
17047- px / 2,
17048- py / 2,
17053+ cpx,
17054+ cpy,
1704917055 Pred::Inline(&pred_u, cside),
1705017056 Some(luma_tx_type),
1705117057 None,
@@ -17061,8 +17067,8 @@ fn decode_intrabc_owned_rect(
1706117067 around[2],
1706217068 0,
1706317069 v,
17064- px / 2,
17065- py / 2,
17070+ cpx,
17071+ cpy,
1706617072 Pred::Inline(&pred_v, cside),
1706717073 Some(luma_tx_type),
1706817074 None,
@@ -17101,8 +17107,8 @@ fn decode_intrabc_owned_rect(
1710117107 around[1],
1710217108 0,
1710317109 u,
17104- px / 2,
17105- py / 2,
17110+ cpx,
17111+ cpy,
1710617112 Pred::Inline(&pred_u, cside),
1710717113 Some(luma_tx_type),
1710817114 None,
@@ -17118,8 +17124,8 @@ fn decode_intrabc_owned_rect(
1711817124 around[2],
1711917125 0,
1712017126 v,
17121- px / 2,
17122- py / 2,
17127+ cpx,
17128+ cpy,
1712317129 Pred::Inline(&pred_v, cside),
1712417130 Some(luma_tx_type),
1712517131 None,
crates/ec-av1/src/stream.rsmodified+69 -0
@@ -140,6 +140,23 @@ pub fn reset_ibc444rect_hits() {
140140 crate::decode::reset_ibc444rect_hits()
141141 }
142142
143+/// lane-av1chromarect: 128-root intra-BC HORZ/VERT strips whose chroma plane
144+/// block was sized `bw >> ss_x` by `bh >> ss_y` rather than the hardcoded
145+/// 4:2:0 halving -- i.e. the 4:4:4 (and 4:4:0) cells, where
146+/// `av1_get_max_uv_txsize` (`ss_size_lookup[bsize]`, blockd.h:1372) applies no
147+/// halving of its own. At 4:2:0 the two forms are the same arithmetic, so a
148+/// `>= 1` witness can only come from a stream that is not 4:2:0. EXCLUSIVE to
149+/// `decode_intrabc_owned_rect`: no other caller sizes a 128-root intra-BC
150+/// strip's chroma plane block.
151+pub fn ibc_owned_rect_chroma_footprint_444_hits() -> usize {
152+ crate::decode::ibc_owned_rect_chroma_footprint_444_hits()
153+}
154+
155+/// Gate-side reset for the lane-av1chromarect counter above.
156+pub fn reset_ibc_owned_rect_chroma_footprint_444_hits() {
157+ crate::decode::reset_ibc_owned_rect_chroma_footprint_444_hits()
158+}
159+
143160 /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900
144161 /// r22) -- the counter a screen-content witness gate reads to prove it
145162 /// exercises the inter-frame palette path, not the key frame's.
@@ -48449,4 +48466,56 @@ pub(crate) mod tests {
4844948466 (lanes/ibc444c.report.md r2), NOT an assertion"
4845048467 );
4845148468 }
48469+
48470+ /// lane-av1chromarect: the 128-root intra-BC HORZ/VERT strip's chroma
48471+ /// plane block, on the 4:4:4 LOSSY witness that reaches
48472+ /// `decode_intrabc_owned_rect`.
48473+ ///
48474+ /// The extent is the ss-derived one (`bw >> ss_x` by `bh >> ss_y`,
48475+ /// `av1_get_max_uv_txsize` = `ss_size_lookup[bsize]`, blockd.h:1372), and
48476+ /// the witness is pinned at the size that shape forces -- a 4:4:4 32x64
48477+ /// luma block's chroma plane block is 32x64. **This gate asserts the
48478+ /// refusal, on purpose.** It exists so the day the missing arm lands the
48479+ /// gate goes RED and the assertion has to be rewritten as the
48480+ /// pixel-exactness check -- a witness with no gate is a pin, and a pin
48481+ /// with no governing refusal is a defect nobody is looking at.
48482+ #[test]
48483+ fn a_444_intrabc_owned_rect_strip_refuses_the_missing_rect_chroma_coefficient_set() {
48484+ const NAME: &str =
48485+ "a_444_intrabc_owned_rect_strip_refuses_the_missing_rect_chroma_coefficient_set";
48486+ const FILE: &str = "r512.obu";
48487+ const LEN: usize = 6948;
48488+ let path =
48489+ std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(format!("fixtures/{FILE}"));
48490+ let stream = std::fs::read(&path)
48491+ .unwrap_or_else(|e| panic!("{NAME}: pinned fixture {FILE} missing: {e}"));
48492+ assert_eq!(stream.len(), LEN, "{NAME}: {FILE} length moved");
48493+ assert_444_header(&stream, NAME, 8);
48494+
48495+ let _guard = lock_gate_counters();
48496+ reset_ibc_owned_rect_chroma_footprint_444_hits();
48497+ let err = decode_stream(&stream).err().unwrap_or_else(|| {
48498+ panic!(
48499+ "{NAME}: the witness DECODED -- the extent is not the ss-derived one any \
48500+ more, so this gate is no longer measuring what it names"
48501+ )
48502+ });
48503+ let msg = err.to_string();
48504+ assert!(
48505+ msg.contains(
48506+ "a rectangular inter chroma transform unit whose shape has no coefficient table \
48507+ set here"
48508+ ),
48509+ "{NAME}: expected the missing-rect-chroma-set refusal, got: {msg}"
48510+ );
48511+ let hits = ibc_owned_rect_chroma_footprint_444_hits();
48512+ // Exactly 1, not 5: the decode stops AT the first 4:4:4 strip, so this
48513+ // counts the strips that reached the corrected extent before the
48514+ // refusal ended the stream. The pixel-exactness gate that replaces
48515+ // this one sees all five.
48516+ assert_eq!(
48517+ hits, 1,
48518+ "{NAME}: {hits} 128-root intra-BC strip(s) sized at 4:4:4 before the refusal, not 1"
48519+ );
48520+ }
4845248521 }