4:4:4 witness pin + ss-derived chroma extent at the 128-root intra-BC strip
Browse files at this commit287d79c7d0fe62b925f080b123d895bad7c02344Parent: ecb98e23 changed files +125 -50
- crates/ec-av1/fixtures/r512.obu +0 -0
- crates/ec-av1/src/decode.rs +56 -50
- crates/ec-av1/src/stream.rs +69 -0
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! { | |||
| 4708 | /// be satisfied by any older route. | 4708 | /// be satisfied by any older route. |
| 4709 | static INTRABC_RECT_LOSSLESS_CHROMA4_HITS: std::cell::Cell<usize> = | 4709 | static INTRABC_RECT_LOSSLESS_CHROMA4_HITS: std::cell::Cell<usize> = |
| 4710 | const { std::cell::Cell::new(0) }; | 4710 | 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) }; | ||
| 4711 | } | 4721 | } |
| 4712 | 4722 | ||
| 4713 | /// lane-av1-intrabc r4: coded (`skip == 0`) rect intrabc blocks reconstructed, | 4723 | /// 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() { | |||
| 4751 | IBC_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0)); | 4761 | IBC_RECT_CHROMA_FOOTPRINT_444_HITS.with(|c| c.set(0)); |
| 4752 | } | 4762 | } |
| 4753 | 4763 | ||
| 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 | + | ||
| 4754 | /// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`]. | 4776 | /// lane-whtshape: [`INTRABC_RECT_LOSSLESS_CHROMA4_HITS`]. |
| 4755 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates | 4777 | #[allow(dead_code)] // read only from the `#[cfg(test)]` gates |
| 4756 | pub fn intrabc_rect_lossless_chroma4_hits() -> usize { | 4778 | pub fn intrabc_rect_lossless_chroma4_hits() -> usize { |
| @@ -16838,25 +16860,31 @@ fn decode_intrabc_owned_rect( | |||
| 16838 | ) -> Result<()> { | 16860 | ) -> Result<()> { |
| 16839 | let _ = base_q_idx; | 16861 | let _ = base_q_idx; |
| 16840 | let (px, py) = (mi_c * MI, mi_r * MI); | 16862 | let (px, py) = (mi_c * MI, mi_r * MI); |
| 16841 | - // lane-av1chromahalvings r5: libaom-WRONG at 4:4:4 -- `av1_get_max_uv_txsize` | 16863 | + // lane-av1chromarect: libaom does NOT halve a 128-root intra-BC strip's |
| 16842 | - // is `ss_size_lookup[bsize]` and `get_vartx_max_txsize` (blockd.h:1447) reads | 16864 | + // chroma plane block. `av1_get_max_uv_txsize` (blockd.h:1372) is |
| 16843 | - // that plane block as `max_txsize_rect_lookup[plane_bsize]`, so chroma extent | 16865 | + // `max_txsize_rect_lookup[get_plane_block_size(bsize, ss_x, ss_y)]` run |
| 16844 | - // == luma extent at ss (0,0) -- and the chroma MV origins below are the | 16866 | + // through `av1_get_adjusted_tx_size`, and `get_plane_block_size` is |
| 16845 | - // prediction half of the same defect. MEASURED on the 4:4:4 LOSSY witness | 16867 | + // `ss_size_lookup[bsize]` -- at 4:4:4 the chroma plane block is the block's |
| 16846 | - // fixtures/r512.obu, chroma-only, luma byte-exact on both inter frames. | 16868 | + // OWN footprint, so the extent below and the eight chroma MV origin pairs |
| 16847 | - // BLOCKED, not missing: with the ss-derived extent the decode REFUSES -- | 16869 | + // that follow must be `>> ss_x` / `>> ss_y`, not `/ 2`. At 4:2:0 |
| 16848 | - // "a rectangular inter chroma transform unit whose shape has no coefficient | 16870 | + // (`ss_x == ss_y == 1`) the two forms are the same arithmetic. |
| 16849 | - // table set here" -- because a 4:4:4 32x64 chroma plane block needs a | 16871 | + // MEASURED on the 4:4:4 LOSSY witness `fixtures/r512.obu` (6948 B, 3 |
| 16850 | - // `TxbSet` this crate lacks. The fix is a new coefficient set, not a swap. | 16872 | + // frames, 5 strips through this function): with the halving, frame 0 |
| 16851 | - // Left as the halving deliberately: turning a decoding stream into a | 16873 | + // diverges from the aomdec oracle in 166229 Y / 155383 U / 153498 V |
| 16852 | - // refusal is a behaviour change with its own decision. See | 16874 | + // samples and both later frames keep luma byte-exact while 74708 U + |
| 16853 | - // lanes/av1chromahalvings.report.md r5. | 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. | ||
| 16854 | if crate::envflags::env_flag!("EC_HALVSWEEP") { | 16878 | if crate::envflags::env_flag!("EC_HALVSWEEP") { |
| 16855 | eprintln!("EC_HALV ibc_owned mi=({mi_r},{mi_c}) bw={bw} bh={bh} skip={skip}"); | 16879 | eprintln!("EC_HALV ibc_owned mi=({mi_r},{mi_c}) bw={bw} bh={bh} skip={skip}"); |
| 16856 | } | 16880 | } |
| 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)); | ||
| 16858 | let side = bw.max(bh); | 16883 | let side = bw.max(bh); |
| 16859 | let cside = cw.max(ch); | 16884 | 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 | + } | ||
| 16860 | let saved_reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); | 16888 | let saved_reduced = fctx.reduced_tx_set_inter.with(std::cell::Cell::get); |
| 16861 | let saved_tx = fctx.tx_select_inter.with(std::cell::Cell::get); | 16889 | let saved_tx = fctx.tx_select_inter.with(std::cell::Cell::get); |
| 16862 | fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set)); | 16890 | fctx.reduced_tx_set_inter.with(|c| c.set(reduced_tx_set)); |
| @@ -16871,30 +16899,8 @@ fn decode_intrabc_owned_rect( | |||
| 16871 | 16899 | ||
| 16872 | flush_recon(fctx, y, u, v); | 16900 | flush_recon(fctx, y, u, v); |
| 16873 | let pred_y = predict_intrabc_window(y, px, py, bw, bh, dv_col, dv_row, true, side, fctx); | 16901 | 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( | 16902 | + let pred_u = predict_intrabc_window(u, cpx, cpy, cw, ch, dv_col, dv_row, false, cside, fctx); |
| 16875 | - u, | 16903 | + let pred_v = predict_intrabc_window(v, cpx, cpy, cw, ch, dv_col, dv_row, false, cside, fctx); |
| 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 | - ); | ||
| 16898 | 16904 | ||
| 16899 | let mi_cols = 2 * y.true_width.div_ceil(8); | 16905 | let mi_cols = 2 * y.true_width.div_ceil(8); |
| 16900 | let mi_rows = 2 * y.true_height.div_ceil(8); | 16906 | let mi_rows = 2 * y.true_height.div_ceil(8); |
| @@ -16928,8 +16934,8 @@ fn decode_intrabc_owned_rect( | |||
| 16928 | ); | 16934 | ); |
| 16929 | push_mc_rect( | 16935 | push_mc_rect( |
| 16930 | 1, | 16936 | 1, |
| 16931 | - px / 2, | 16937 | + cpx, |
| 16932 | - py / 2, | 16938 | + cpy, |
| 16933 | cside, | 16939 | cside, |
| 16934 | cw, | 16940 | cw, |
| 16935 | ch, | 16941 | ch, |
| @@ -16939,8 +16945,8 @@ fn decode_intrabc_owned_rect( | |||
| 16939 | ); | 16945 | ); |
| 16940 | push_mc_rect( | 16946 | push_mc_rect( |
| 16941 | 2, | 16947 | 2, |
| 16942 | - px / 2, | 16948 | + cpx, |
| 16943 | - py / 2, | 16949 | + cpy, |
| 16944 | cside, | 16950 | cside, |
| 16945 | cw, | 16951 | cw, |
| 16946 | ch, | 16952 | ch, |
| @@ -17044,8 +17050,8 @@ fn decode_intrabc_owned_rect( | |||
| 17044 | around[1], | 17050 | around[1], |
| 17045 | 0, | 17051 | 0, |
| 17046 | u, | 17052 | u, |
| 17047 | - px / 2, | 17053 | + cpx, |
| 17048 | - py / 2, | 17054 | + cpy, |
| 17049 | Pred::Inline(&pred_u, cside), | 17055 | Pred::Inline(&pred_u, cside), |
| 17050 | Some(luma_tx_type), | 17056 | Some(luma_tx_type), |
| 17051 | None, | 17057 | None, |
| @@ -17061,8 +17067,8 @@ fn decode_intrabc_owned_rect( | |||
| 17061 | around[2], | 17067 | around[2], |
| 17062 | 0, | 17068 | 0, |
| 17063 | v, | 17069 | v, |
| 17064 | - px / 2, | 17070 | + cpx, |
| 17065 | - py / 2, | 17071 | + cpy, |
| 17066 | Pred::Inline(&pred_v, cside), | 17072 | Pred::Inline(&pred_v, cside), |
| 17067 | Some(luma_tx_type), | 17073 | Some(luma_tx_type), |
| 17068 | None, | 17074 | None, |
| @@ -17101,8 +17107,8 @@ fn decode_intrabc_owned_rect( | |||
| 17101 | around[1], | 17107 | around[1], |
| 17102 | 0, | 17108 | 0, |
| 17103 | u, | 17109 | u, |
| 17104 | - px / 2, | 17110 | + cpx, |
| 17105 | - py / 2, | 17111 | + cpy, |
| 17106 | Pred::Inline(&pred_u, cside), | 17112 | Pred::Inline(&pred_u, cside), |
| 17107 | Some(luma_tx_type), | 17113 | Some(luma_tx_type), |
| 17108 | None, | 17114 | None, |
| @@ -17118,8 +17124,8 @@ fn decode_intrabc_owned_rect( | |||
| 17118 | around[2], | 17124 | around[2], |
| 17119 | 0, | 17125 | 0, |
| 17120 | v, | 17126 | v, |
| 17121 | - px / 2, | 17127 | + cpx, |
| 17122 | - py / 2, | 17128 | + cpy, |
| 17123 | Pred::Inline(&pred_v, cside), | 17129 | Pred::Inline(&pred_v, cside), |
| 17124 | Some(luma_tx_type), | 17130 | Some(luma_tx_type), |
| 17125 | None, | 17131 | None, |
crates/ec-av1/src/stream.rsmodified+69 -0
| @@ -140,6 +140,23 @@ pub fn reset_ibc444rect_hits() { | |||
| 140 | crate::decode::reset_ibc444rect_hits() | 140 | crate::decode::reset_ibc444rect_hits() |
| 141 | } | 141 | } |
| 142 | 142 | ||
| 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 | + | ||
| 143 | /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900 | 160 | /// `(y, uv)` palette blocks RECONSTRUCTED inside an inter frame (lane-t900 |
| 144 | /// r22) -- the counter a screen-content witness gate reads to prove it | 161 | /// r22) -- the counter a screen-content witness gate reads to prove it |
| 145 | /// exercises the inter-frame palette path, not the key frame's. | 162 | /// exercises the inter-frame palette path, not the key frame's. |
| @@ -48449,4 +48466,56 @@ pub(crate) mod tests { | |||
| 48449 | (lanes/ibc444c.report.md r2), NOT an assertion" | 48466 | (lanes/ibc444c.report.md r2), NOT an assertion" |
| 48450 | ); | 48467 | ); |
| 48451 | } | 48468 | } |
| 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 | + } | ||
| 48452 | } | 48521 | } |