av1intrapred: gate the intrabc TX4-split chroma frame-copy route
Browse files at this commit0c936b64c4026fe7428e7cc95547d0b96f256a64Parent: 3ab8e304 changed files +168 -0
- crates/ec-av1/fixtures/intrabc_tx4_chroma_kf.obu +0 -0
- crates/ec-av1/src/decode.rs +27 -0
- crates/ec-av1/src/stream.rs +123 -0
- lanes/av1intrapred.report.md +18 -0
crates/ec-av1/fixtures/intrabc_tx4_chroma_kf.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+27 -0
| @@ -3694,6 +3694,27 @@ thread_local! { | |||
| 3694 | static LEAF8_INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | 3694 | static LEAF8_INTRABC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; |
| 3695 | } | 3695 | } |
| 3696 | 3696 | ||
| 3697 | +thread_local! { | ||
| 3698 | + /// Chroma reads of an intrabc TX4-split leaf that consulted an ARMED | ||
| 3699 | + /// [`INTRABC_CHROMA_TX`] slot -- proof that the arm's frame-copy + | ||
| 3700 | + /// inherited-type route actually ran (lane-av1intrapred r2's non-vacuity | ||
| 3701 | + /// counter: zero means the gate's fixture no longer reaches the route). | ||
| 3702 | + static INTRABC_TX4_CHROMA_COPY_HITS: std::cell::Cell<usize> = | ||
| 3703 | + const { std::cell::Cell::new(0) }; | ||
| 3704 | +} | ||
| 3705 | + | ||
| 3706 | +/// Current value of [`INTRABC_TX4_CHROMA_COPY_HITS`]. | ||
| 3707 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 3708 | +pub(crate) fn intrabc_tx4_chroma_copy_hits() -> usize { | ||
| 3709 | + INTRABC_TX4_CHROMA_COPY_HITS.with(|c| c.get()) | ||
| 3710 | +} | ||
| 3711 | + | ||
| 3712 | +/// Zeroes [`INTRABC_TX4_CHROMA_COPY_HITS`] (gate tests call this before a decode). | ||
| 3713 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 3714 | +pub(crate) fn reset_intrabc_tx4_chroma_copy_hits() { | ||
| 3715 | + INTRABC_TX4_CHROMA_COPY_HITS.with(|c| c.set(0)); | ||
| 3716 | +} | ||
| 3717 | + | ||
| 3697 | /// Current value of [`LEAF8_INTRABC_HITS`]. | 3718 | /// Current value of [`LEAF8_INTRABC_HITS`]. |
| 3698 | pub(crate) fn leaf8_intrabc_hits() -> usize { | 3719 | pub(crate) fn leaf8_intrabc_hits() -> usize { |
| 3699 | LEAF8_INTRABC_HITS.with(|c| c.get()) | 3720 | LEAF8_INTRABC_HITS.with(|c| c.get()) |
| @@ -17365,6 +17386,12 @@ fn decode_leaf8( | |||
| 17365 | } | 17386 | } |
| 17366 | let ac = alpha.map(|_| cfl_src(px, py, 8)); | 17387 | let ac = alpha.map(|_| cfl_src(px, py, 8)); |
| 17367 | let chroma_around = neighbours.around_mi(leaf_mi, 8); | 17388 | let chroma_around = neighbours.around_mi(leaf_mi, 8); |
| 17389 | + // lane-av1intrapred: the non-vacuity counter -- armed slot consulted | ||
| 17390 | + // by this arm's chroma reads means the frame-copy + inherited-type | ||
| 17391 | + // route ran; zero at gate time means the fixture stopped reaching it. | ||
| 17392 | + if fctx.intrabc_chroma_tx.with(std::cell::Cell::get).is_some() { | ||
| 17393 | + hit!(INTRABC_TX4_CHROMA_COPY_HITS); | ||
| 17394 | + } | ||
| 17368 | if let Some((ub, _)) = &palette_uv_bufs { | 17395 | if let Some((ub, _)) = &palette_uv_bufs { |
| 17369 | set_palette_pred(ub.clone(), fctx); | 17396 | set_palette_pred(ub.clone(), fctx); |
| 17370 | } | 17397 | } |
crates/ec-av1/src/stream.rsmodified+123 -0
| @@ -7098,6 +7098,129 @@ pub(crate) mod tests { | |||
| 7098 | ); | 7098 | ); |
| 7099 | } | 7099 | } |
| 7100 | 7100 | ||
| 7101 | + /// lane-av1intrapred r2, REGRESSION GATE for the two intrabc TX4-split | ||
| 7102 | + /// chroma defects this lane fixed. | ||
| 7103 | + /// | ||
| 7104 | + /// An intrabc 8x8 leaf whose var-tx tree split to TX_4X4 must (a) arm | ||
| 7105 | + /// `INTRABC_CHROMA_TX` from the co-located luma TU's coded type -- the | ||
| 7106 | + /// chroma units then take that type's class-1 eob row, HORIZ scan and nz | ||
| 7107 | + /// contexts (libaom `av1_get_tx_type`'s is_inter branch; intrabc is | ||
| 7108 | + /// inter-classified) -- and (b) predict the chroma units from the FRAME | ||
| 7109 | + /// COPY at the DV, not intra-from-UV-mode (intrabc's UV mode is DC, so a | ||
| 7110 | + /// leaf that loses the override predicts flat DC where libaom copies a | ||
| 7111 | + /// busy region). | ||
| 7112 | + /// | ||
| 7113 | + /// Pre-r2, decode_leaf8's TX4 arm did neither: R5's chroma U txb at | ||
| 7114 | + /// mi (36,66) decoded `eob=11` off the 2D row where aomdec decoded | ||
| 7115 | + /// `eob=13` off the class-1 row, and the first surviving pixel fork was | ||
| 7116 | + /// U(184,4) of mi (2,92) (class `intrabc-chroma-tx-not-armed`, then | ||
| 7117 | + /// `intrabc-chroma-predicts-intra`). | ||
| 7118 | + /// | ||
| 7119 | + /// The fixture is the report's R5 stream pinned into `fixtures/` | ||
| 7120 | + /// (aomenc oracle, testsrc2 320x180 tiled 2x2 -> 640x360, sb64 maxp64 | ||
| 7121 | + /// square-only screen intrabc, cq20, 1 frame; 7173 bytes, | ||
| 7122 | + /// sha256 bc699af4a6e7c1c5657f041e8cbdf2d3d899ddb80ec2a549a950b7cebb5b41bd). | ||
| 7123 | + /// The gate needs no oracle at run time and cannot be skipped: a missing | ||
| 7124 | + /// fixture, a decode error, a zero counter, a moved pixel patch or a | ||
| 7125 | + /// changed full-frame fingerprint each fail by name. The fingerprint is | ||
| 7126 | + /// FNV-1a (dependency-free, same rationale as the cdf-forwarding gate's). | ||
| 7127 | + #[test] | ||
| 7128 | + fn an_intrabc_tx4_leaf_chroma_inherits_the_luma_type_and_predicts_from_the_frame_copy() { | ||
| 7129 | + const NAME: &str = | ||
| 7130 | + "an_intrabc_tx4_leaf_chroma_inherits_the_luma_type_and_predicts_from_the_frame_copy"; | ||
| 7131 | + const FIXTURE_LEN: usize = 7173; | ||
| 7132 | + const FIXTURE_FNV: u64 = 0x3a57_d075_5e4c_fe5b; | ||
| 7133 | + const RAW_LEN: usize = 640 * 360 * 3 / 2; | ||
| 7134 | + const RAW_FNV: u64 = 0xf271_df27_ce4d_ba66; | ||
| 7135 | + // The 4x4 chroma patches at (184,4) -- the first surviving pixel fork | ||
| 7136 | + // -- as the oracles (aomdec and ffmpeg agree) reconstruct them. | ||
| 7137 | + const U_PATCH: [u16; 16] = [ | ||
| 7138 | + 86, 116, 55, 110, 114, 114, 51, 83, 99, 121, 48, 114, 103, 117, 102, 67, | ||
| 7139 | + ]; | ||
| 7140 | + const V_PATCH: [u16; 16] = [ | ||
| 7141 | + 179, 158, 199, 105, 155, 158, 195, 147, 163, 153, 194, 108, 170, 148, 168, 172, | ||
| 7142 | + ]; | ||
| 7143 | + | ||
| 7144 | + let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")) | ||
| 7145 | + .join("fixtures/intrabc_tx4_chroma_kf.obu"); | ||
| 7146 | + let stream = std::fs::read(&obu).unwrap_or_else(|e| { | ||
| 7147 | + panic!( | ||
| 7148 | + "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \ | ||
| 7149 | + which is a failure, not a skip", | ||
| 7150 | + obu.display() | ||
| 7151 | + ) | ||
| 7152 | + }); | ||
| 7153 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | ||
| 7154 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | ||
| 7155 | + | ||
| 7156 | + let _guard = lock_gate_counters(); | ||
| 7157 | + crate::decode::reset_leaf8_intrabc_hits(); | ||
| 7158 | + crate::decode::reset_intrabc_tx4_chroma_copy_hits(); | ||
| 7159 | + let frames = decode_stream(&stream).unwrap_or_else(|e| { | ||
| 7160 | + panic!("{NAME}: the pinned stream no longer decodes cleanly: {e}") | ||
| 7161 | + }); | ||
| 7162 | + assert_eq!(frames.len(), 1, "{NAME}: frame count"); | ||
| 7163 | + let frame = &frames[0]; | ||
| 7164 | + assert_eq!((frame.width, frame.height), (640, 360), "{NAME}: dimensions"); | ||
| 7165 | + | ||
| 7166 | + // Non-vacuity, both halves: the leaf shape must be reached at all, | ||
| 7167 | + // and its chroma route must have consulted the ARMED slot (pre-r2 | ||
| 7168 | + // this counter is 0 -- the arm never armed the slot). | ||
| 7169 | + assert!( | ||
| 7170 | + crate::decode::leaf8_intrabc_hits() > 0, | ||
| 7171 | + "{NAME}: gate is vacuous -- no intrabc 8x8 leaf was decoded" | ||
| 7172 | + ); | ||
| 7173 | + assert!( | ||
| 7174 | + crate::decode::intrabc_tx4_chroma_copy_hits() > 0, | ||
| 7175 | + "{NAME}: gate is vacuous -- no intrabc TX4-split leaf's chroma read consulted \ | ||
| 7176 | + the armed slot (class intrabc-chroma-tx-not-armed)" | ||
| 7177 | + ); | ||
| 7178 | + | ||
| 7179 | + // The first surviving pixel fork: chroma 4x4 at (184,4). The wrong | ||
| 7180 | + // wirings put flat intra-DC predictions or the wrong eob class here. | ||
| 7181 | + let cw = frame.width / 2; | ||
| 7182 | + let u_patch: Vec<u16> = (0..4) | ||
| 7183 | + .flat_map(|dy| (0..4).map(move |dx| frame.u[(4 + dy) * cw + 184 + dx])) | ||
| 7184 | + .collect(); | ||
| 7185 | + let v_patch: Vec<u16> = (0..4) | ||
| 7186 | + .flat_map(|dy| (0..4).map(move |dx| frame.v[(4 + dy) * cw + 184 + dx])) | ||
| 7187 | + .collect(); | ||
| 7188 | + assert_eq!(u_patch, U_PATCH, "{NAME}: U(184,4) patch moved"); | ||
| 7189 | + assert_eq!(v_patch, V_PATCH, "{NAME}: V(184,4) patch moved"); | ||
| 7190 | + // The unit the FRAME-COPY override specifically pins: chroma 4x4 at | ||
| 7191 | + // (168,0) is an intrabc TX4-split leaf's chroma whose copy source is | ||
| 7192 | + // a busy ramp region; without the `palette_uv_bufs` intrabc wrap the | ||
| 7193 | + // read predicts flat intra-DC here (78k chroma bytes drift from this | ||
| 7194 | + // unit alone), with it the copy reproduces the oracle exactly. | ||
| 7195 | + const U_COPY_PATCH: [u16; 16] = [ | ||
| 7196 | + 91, 91, 91, 91, 120, 120, 120, 120, 120, 120, 120, 120, 73, 102, 116, 116, | ||
| 7197 | + ]; | ||
| 7198 | + const V_COPY_PATCH: [u16; 16] = [ | ||
| 7199 | + 241, 241, 241, 241, 156, 156, 156, 156, 158, 158, 158, 158, 181, 163, 154, 154, | ||
| 7200 | + ]; | ||
| 7201 | + let u_copy: Vec<u16> = (0..4) | ||
| 7202 | + .flat_map(|dy| (0..4).map(move |dx| frame.u[dy * cw + 168 + dx])) | ||
| 7203 | + .collect(); | ||
| 7204 | + let v_copy: Vec<u16> = (0..4) | ||
| 7205 | + .flat_map(|dy| (0..4).map(move |dx| frame.v[dy * cw + 168 + dx])) | ||
| 7206 | + .collect(); | ||
| 7207 | + assert_eq!( | ||
| 7208 | + u_copy, U_COPY_PATCH, | ||
| 7209 | + "{NAME}: U(168,0) patch moved -- the intrabc TX4 chroma read no longer \ | ||
| 7210 | + predicts from the frame copy (class intrabc-chroma-predicts-intra)" | ||
| 7211 | + ); | ||
| 7212 | + assert_eq!(v_copy, V_COPY_PATCH, "{NAME}: V(168,0) patch moved"); | ||
| 7213 | + | ||
| 7214 | + // The whole frame, packed as the rawvideo byte stream the oracles | ||
| 7215 | + // produce: any remaining byte anywhere in Y/U/V fails the gate. | ||
| 7216 | + let mut raw = Vec::with_capacity(RAW_LEN); | ||
| 7217 | + for plane in [&frame.y, &frame.u, &frame.v] { | ||
| 7218 | + raw.extend(plane.iter().map(|&s| s as u8)); | ||
| 7219 | + } | ||
| 7220 | + assert_eq!(raw.len(), RAW_LEN, "{NAME}: raw size"); | ||
| 7221 | + assert_eq!(fnv1a64(&raw), RAW_FNV, "{NAME}: full-frame fingerprint moved"); | ||
| 7222 | + } | ||
| 7223 | + | ||
| 7101 | /// lane-t900 r33, CENSUS for "a sub-8x8 leaf that uses intrabc". | 7224 | /// lane-t900 r33, CENSUS for "a sub-8x8 leaf that uses intrabc". |
| 7102 | /// | 7225 | /// |
| 7103 | /// The `use_intrabc` symbol IS read at that reader for every sub-8x8 leaf | 7226 | /// The `use_intrabc` symbol IS read at that reader for every sub-8x8 leaf |
lanes/av1intrapred.report.mdmodified+18 -0
| @@ -142,3 +142,21 @@ copying the frame at the DV. | |||
| 142 | * Cached-fixture sweep A1/A2/A3/D1/D2/D3: byte-exact vs their ffmpeg raws. | 142 | * Cached-fixture sweep A1/A2/A3/D1/D2/D3: byte-exact vs their ffmpeg raws. |
| 143 | * Targeted tests (intrabc/lossless/screen filters): 14 passed, 0 failed. Full suite on | 143 | * Targeted tests (intrabc/lossless/screen filters): 14 passed, 0 failed. Full suite on |
| 144 | the r2 fix alone: 607 passed / 0 failed (exit 0). | 144 | the r2 fix alone: 607 passed / 0 failed (exit 0). |
| 145 | + | ||
| 146 | +## Regression gate (r2c) | ||
| 147 | + | ||
| 148 | +`stream::tests::an_intrabc_tx4_leaf_chroma_inherits_the_luma_type_and_predicts_from_the_frame_copy` | ||
| 149 | ++ pinned fixture `crates/ec-av1/fixtures/intrabc_tx4_chroma_kf.obu` (the R5 stream, | ||
| 150 | + 7173 bytes, sha256 `bc699af4…b41bd`, FNV-1a `0x3a57d0755e4cfe5b`; aomenc oracle, | ||
| 151 | + testsrc2 320x180 tiled 2x2 → 640x360, sb64 maxp64 square-only screen intrabc, cq20, | ||
| 152 | + 1 frame). The gate runs unconditionally (no oracle binary needed, no skip path): a | ||
| 153 | + missing fixture, a decode error, a zero `INTRABC_TX4_CHROMA_COPY_HITS` counter (new | ||
| 154 | + non-vacuity counter bumped when the TX4 arm's chroma reads consult the armed slot), | ||
| 155 | + a moved U(184,4)/U(168,0)/V(168,0) pixel patch, or a changed full-frame FNV-1a | ||
| 156 | + fingerprint each fail with the class name. | ||
| 157 | + | ||
| 158 | +* Fixed tree: passes. | ||
| 159 | +* Unwrap regression (decode_block's `palette_uv_bufs` intrabc wrap removed — the exact | ||
| 160 | + "chroma predicts from the unwrapped palette buffer" state): **fails at the U(168,0) | ||
| 161 | + patch assert** (`intrabc-chroma-predicts-intra`), 78182 chroma bytes wrong. | ||
| 162 | +* Pre-r2 parent (3f6748d5): fails at decode (tile desync, byte 82216/352 forks). | ||