ec-av1: resolve each rect inter chroma unit's tx_type from its own luma leaf
Browse files at this commit7a3673356f157f62db9a4178627c4a281942ba02Parent: 07895763 changed files +158 -1
- crates/ec-av1/fixtures/444_rect_strip_leaf_tx_type.obu +0 -0
- crates/ec-av1/src/decode.rs +59 -1
- crates/ec-av1/src/stream.rs +99 -0
crates/ec-av1/fixtures/444_rect_strip_leaf_tx_type.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+59 -1
| @@ -28242,6 +28242,13 @@ fn read_inter_rect_chroma( | |||
| 28242 | (write_chroma_w, write_chroma_h): (usize, usize), | 28242 | (write_chroma_w, write_chroma_h): (usize, usize), |
| 28243 | chroma_side: usize, | 28243 | chroma_side: usize, |
| 28244 | mode_for_tx: usize, | 28244 | mode_for_tx: usize, |
| 28245 | + // lane-av1chrtx: this block's coded luma transform leaves, `(row, col, | ||
| 28246 | + // tw, th, tx_type)` -- the same list the 4:4:4 four-unit arms resolve | ||
| 28247 | + // through `covering_leaf_tx_type`. This sibling used to hand EVERY unit | ||
| 28248 | + // the block-level `luma_tx_type` (the top-left leaf's type), so a rect | ||
| 28249 | + // inter block whose chroma plane splits (`nx*ny > 1`) over MIXED var-tx | ||
| 28250 | + // leaves read the wrong type per unit. | ||
| 28251 | + leaf_tx_types: &[(usize, usize, usize, usize, TxType)], | ||
| 28245 | luma_tx_type: TxType, | 28252 | luma_tx_type: TxType, |
| 28246 | fctx: &crate::decode::FrameCtx, | 28253 | fctx: &crate::decode::FrameCtx, |
| 28247 | ) -> Result<(Grid, Grid, Vec<((usize, usize), usize, Grid, usize, usize)>)> { | 28254 | ) -> Result<(Grid, Grid, Vec<((usize, usize), usize, Grid, usize, usize)>)> { |
| @@ -28267,7 +28274,12 @@ fn read_inter_rect_chroma( | |||
| 28267 | let invalid_ss_plane = | 28274 | let invalid_ss_plane = |
| 28268 | ss_x(fctx) == 1 && ss_y(fctx) == 0 && (write_chroma_w, write_chroma_h) == (4, 32); | 28275 | ss_x(fctx) == 1 && ss_y(fctx) == 0 && (write_chroma_w, write_chroma_h) == (4, 32); |
| 28269 | let (uw, uh) = if invalid_ss_plane { (4, 8) } else { (uw, uh) }; | 28276 | let (uw, uh) = if invalid_ss_plane { (4, 8) } else { (uw, uh) }; |
| 28270 | - let inherit_tx_type = Some(luma_tx_type); | 28277 | + // lane-av1chrtx: `inherit_tx_type` is resolved PER UNIT below, not once |
| 28278 | + // for the block -- `av1_get_tx_type` (blockd.h:1287-1297) reads | ||
| 28279 | + // `xd->tx_type_map` at the chroma unit's own position scaled back to | ||
| 28280 | + // luma, so a unit sitting over a luma leaf that coded NOTHING takes that | ||
| 28281 | + // leaf's `DCT_DCT` stamp (`decodetxb.c:199-203`), not the block-level | ||
| 28282 | + // (top-left leaf) type. | ||
| 28271 | let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh); | 28283 | let (nx, ny) = (write_chroma_w / uw, write_chroma_h / uh); |
| 28272 | let multi = nx * ny > 1; | 28284 | let multi = nx * ny > 1; |
| 28273 | let set = rect_inter_chroma_set(uw, uh)?; | 28285 | let set = rect_inter_chroma_set(uw, uh)?; |
| @@ -28305,6 +28317,7 @@ fn read_inter_rect_chroma( | |||
| 28305 | at_mi.0 + cu_row * (span_y / MI), | 28317 | at_mi.0 + cu_row * (span_y / MI), |
| 28306 | at_mi.1 + cu_col * (span_x / MI), | 28318 | at_mi.1 + cu_col * (span_x / MI), |
| 28307 | ); | 28319 | ); |
| 28320 | + let unit_rel_mi = (cu_mi.0 - at_mi.0, cu_mi.1 - at_mi.1); | ||
| 28308 | let cu_around = if multi { | 28321 | let cu_around = if multi { |
| 28309 | // lane-av1422ctxgather: at ss (1,0) the unit's above | 28322 | // lane-av1422ctxgather: at ss (1,0) the unit's above |
| 28310 | // span covers `uw` chroma px = `2*uw` luma mi columns, | 28323 | // span covers `uw` chroma px = `2*uw` luma mi columns, |
| @@ -28324,6 +28337,16 @@ fn read_inter_rect_chroma( | |||
| 28324 | }; | 28337 | }; |
| 28325 | let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh); | 28338 | let (cu_x, cu_y) = (cpx + cu_col * uw, cpy + cu_row * uh); |
| 28326 | let cu_pred = src.offset(cu_row * uh * chroma_side + cu_col * uw); | 28339 | let cu_pred = src.offset(cu_row * uh * chroma_side + cu_col * uw); |
| 28340 | + let inherit_tx_type = | ||
| 28341 | + if let Some(t) = covering_leaf_tx_type(leaf_tx_types, unit_rel_mi) { | ||
| 28342 | + hit!(CHROMA_RECT_LEAF_TX_HITS); | ||
| 28343 | + if Some(t) != Some(luma_tx_type) { | ||
| 28344 | + hit!(CHROMA_RECT_LEAF_TX_DIFF_HITS); | ||
| 28345 | + } | ||
| 28346 | + Some(t) | ||
| 28347 | + } else { | ||
| 28348 | + Some(luma_tx_type) | ||
| 28349 | + }; | ||
| 28327 | let cu_grid = read_inter_plane_rect( | 28350 | let cu_grid = read_inter_plane_rect( |
| 28328 | dec, | 28351 | dec, |
| 28329 | cdfs, | 28352 | cdfs, |
| @@ -37983,6 +38006,39 @@ pub(crate) fn chroma_quad_leaf_tx_diff_hits() -> usize { | |||
| 37983 | CHROMA_QUAD_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get) | 38006 | CHROMA_QUAD_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get) |
| 37984 | } | 38007 | } |
| 37985 | 38008 | ||
| 38009 | +thread_local! { | ||
| 38010 | + /// lane-av1chrtx: chroma units of a RECT inter block | ||
| 38011 | + /// ([`read_inter_rect_chroma`], the sibling of the 4:4:4 four-unit arms) | ||
| 38012 | + /// that resolved their `tx_type` from the luma leaf covering their OWN | ||
| 38013 | + /// quadrant instead of the block-level one. A SEPARATE counter from | ||
| 38014 | + /// [`CHROMA_QUAD_LEAF_TX_HITS`] on purpose: that one gates a 4:2:0 control | ||
| 38015 | + /// that must stay at exactly 0, and this route IS reachable at 4:2:0, so | ||
| 38016 | + /// sharing the counter would destroy that control's meaning. | ||
| 38017 | + pub(crate) static CHROMA_RECT_LEAF_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 38018 | +} | ||
| 38019 | + | ||
| 38020 | +thread_local! { | ||
| 38021 | + /// Of those, how many resolved a type that DIFFERS from the block-level | ||
| 38022 | + /// one -- the condition that changes pixels. A route counter alone fires | ||
| 38023 | + /// on every multi-unit rect chroma read, including the blocks whose | ||
| 38024 | + /// leaves all agree (the exact shape a no-op fix looks green on). | ||
| 38025 | + pub(crate) static CHROMA_RECT_LEAF_TX_DIFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 38026 | +} | ||
| 38027 | + | ||
| 38028 | +/// [`CHROMA_RECT_LEAF_TX_HITS`]: rect chroma units that took their type from | ||
| 38029 | +/// the covering luma leaf. | ||
| 38030 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 38031 | +pub(crate) fn chroma_rect_leaf_tx_hits() -> usize { | ||
| 38032 | + CHROMA_RECT_LEAF_TX_HITS.with(std::cell::Cell::get) | ||
| 38033 | +} | ||
| 38034 | + | ||
| 38035 | +/// [`CHROMA_RECT_LEAF_TX_DIFF_HITS`]: of those, the units whose covering | ||
| 38036 | +/// leaf's type differs from the block-level one. | ||
| 38037 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 38038 | +pub(crate) fn chroma_rect_leaf_tx_diff_hits() -> usize { | ||
| 38039 | + CHROMA_RECT_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get) | ||
| 38040 | +} | ||
| 38041 | + | ||
| 37986 | fn decode_inter_block( | 38042 | fn decode_inter_block( |
| 37987 | dec: &mut SymbolDecoder, | 38043 | dec: &mut SymbolDecoder, |
| 37988 | cdfs: &mut Cdfs, | 38044 | cdfs: &mut Cdfs, |
| @@ -39914,6 +39970,7 @@ fn decode_inter_block( | |||
| 39914 | (write_chroma_w, write_chroma_h), | 39970 | (write_chroma_w, write_chroma_h), |
| 39915 | chroma_stride, | 39971 | chroma_stride, |
| 39916 | mode_for_tx, | 39972 | mode_for_tx, |
| 39973 | + &leaf_tx_types, | ||
| 39917 | luma_tx_type, | 39974 | luma_tx_type, |
| 39918 | fctx, | 39975 | fctx, |
| 39919 | )?; | 39976 | )?; |
| @@ -41706,6 +41763,7 @@ fn decode_inter_block( | |||
| 41706 | (write_chroma_w, write_chroma_h), | 41763 | (write_chroma_w, write_chroma_h), |
| 41707 | chroma_stride, | 41764 | chroma_stride, |
| 41708 | mode_for_tx, | 41765 | mode_for_tx, |
| 41766 | + &leaf_tx_types, | ||
| 41709 | luma_tx_type, | 41767 | luma_tx_type, |
| 41710 | fctx, | 41768 | fctx, |
| 41711 | )?; | 41769 | )?; |
crates/ec-av1/src/stream.rsmodified+99 -0
| @@ -19270,6 +19270,105 @@ pub(crate) mod tests { | |||
| 19270 | ); | 19270 | ); |
| 19271 | } | 19271 | } |
| 19272 | 19272 | ||
| 19273 | + /// lane-av1chrtx: the SIBLING of lane-av1444chr's four-unit arm -- a RECT | ||
| 19274 | + /// inter block's chroma plane, read by `read_inter_rect_chroma`. That | ||
| 19275 | + /// helper was left handing every unit the block-level `luma_tx_type` | ||
| 19276 | + /// (the top-left leaf's type) after the four-unit arms were pointed at | ||
| 19277 | + /// `covering_leaf_tx_type`, so a rect block whose chroma plane splits | ||
| 19278 | + /// (`nx*ny > 1`) over MIXED var-tx leaves read the wrong type per unit. | ||
| 19279 | + /// | ||
| 19280 | + /// The witness is pinned into `fixtures/`: `testsrc2 256x256` yuv444p 3 | ||
| 19281 | + /// frames, aomenc `--profile=1 --cq-level=30 --cpu-used=0 --sb-size=64 | ||
| 19282 | + /// --min-partition-size=32 --max-partition-size=64 --enable-tx-size-search=1 | ||
| 19283 | + /// --passes=1 --end-usage=q --threads=1 --row-mt=0 --lag-in-frames=0 | ||
| 19284 | + /// --kf-max-dist=100 --limit=3 --obu`; 26839 bytes, sha256 | ||
| 19285 | + /// `06174a66e92aaeb751a8e86db59711fcb1f18d74bde2d77e1ef1be7983eb7c80`. | ||
| 19286 | + /// Its one qualifying block is the 32x64 inter strip at mi(32,48): a | ||
| 19287 | + /// 4:4:4 chroma plane of (32,64) = TWO TX_32X32 units, over a luma tree | ||
| 19288 | + /// of five leaves -- `Idtx` (32x32) on top, then `VDct`/`DctDct`/`HDct`/ | ||
| 19289 | + /// `VDct` 16x16 leaves. The lower chroma unit therefore inherits `VDct` | ||
| 19290 | + /// where the block-level value is `Idtx`. | ||
| 19291 | + /// | ||
| 19292 | + /// Getting a witness at all took a bounded hunt (200+ encodes): `multi` | ||
| 19293 | + /// is false by construction at 4:2:0 (a `side <= 64` block's chroma plane | ||
| 19294 | + /// is at most 32x32 = one unit), so the arm needs 4:4:4 AND a rect block | ||
| 19295 | + /// that keeps a 64-px axis, AND `--cpu-used=0` with `--min-partition-size=32` | ||
| 19296 | + /// to make aomenc actually pick the 32x64 strip. | ||
| 19297 | + /// | ||
| 19298 | + /// The non-vacuity bar is the DIFFERS counter, not the route counter: the | ||
| 19299 | + /// control below is a committed 4:4:4 rect stream where the route fires | ||
| 19300 | + /// and still changes nothing, because that block's leaves agree. | ||
| 19301 | + #[test] | ||
| 19302 | + fn a_pinned_444_rect_inter_stream_resolves_each_chroma_unit_from_its_own_luma_leaf() { | ||
| 19303 | + const NAME: &str = | ||
| 19304 | + "a_pinned_444_rect_inter_stream_resolves_each_chroma_unit_from_its_own_luma_leaf"; | ||
| 19305 | + const FIXTURE_LEN: usize = 26839; | ||
| 19306 | + const FIXTURE_FNV: u64 = 0xc77f_310c_036d_ff73; | ||
| 19307 | + let _gate_lock = lock_gate_counters(); | ||
| 19308 | + if !have_aomenc() { | ||
| 19309 | + eprintln!( | ||
| 19310 | + "SKIP {NAME}: no aomenc/aomdec oracle at {}", | ||
| 19311 | + aomenc_path().display() | ||
| 19312 | + ); | ||
| 19313 | + return; | ||
| 19314 | + } | ||
| 19315 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 19316 | + .join("fixtures/444_rect_strip_leaf_tx_type.obu"); | ||
| 19317 | + let stream = std::fs::read(&path) | ||
| 19318 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 19319 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | ||
| 19320 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | ||
| 19321 | + | ||
| 19322 | + let hits0 = crate::decode::chroma_rect_leaf_tx_hits(); | ||
| 19323 | + let diff0 = crate::decode::chroma_rect_leaf_tx_diff_hits(); | ||
| 19324 | + let (frames, hidden) = decode_all_frames_vs_oracle(&stream, NAME); | ||
| 19325 | + let hits = crate::decode::chroma_rect_leaf_tx_hits() - hits0; | ||
| 19326 | + let diff = crate::decode::chroma_rect_leaf_tx_diff_hits() - diff0; | ||
| 19327 | + assert_eq!( | ||
| 19328 | + frames, 3, | ||
| 19329 | + "{NAME}: expected 3 decode-order frames ({hidden} hidden)" | ||
| 19330 | + ); | ||
| 19331 | + assert!( | ||
| 19332 | + hits >= 2 * diff && hits > 0, | ||
| 19333 | + "{NAME}: no rect chroma unit took its type from the covering luma leaf (hits {hits}, \ | ||
| 19334 | + differs {diff}) -- the corrected route never ran" | ||
| 19335 | + ); | ||
| 19336 | + assert!( | ||
| 19337 | + diff >= 2, | ||
| 19338 | + "{NAME}: the per-unit resolve never CHANGED an answer (diff {diff}; measured 2 on this \ | ||
| 19339 | + stream, one per chroma plane). A route counter alone is not a witness: the control \ | ||
| 19340 | + below fires it and changes nothing." | ||
| 19341 | + ); | ||
| 19342 | + eprintln!( | ||
| 19343 | + "{NAME}: rect chroma units resolved from their own leaf {hits}, of which {diff} differed" | ||
| 19344 | + ); | ||
| 19345 | + | ||
| 19346 | + // Control: a committed 4:4:4 rect stream where the SAME route fires | ||
| 19347 | + // and every resolved type equals the block-level one -- the shape a | ||
| 19348 | + // no-op fix would also be green on. | ||
| 19349 | + let control = std::fs::read( | ||
| 19350 | + std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 19351 | + .join("fixtures/444_sb128rect_lr_witness.obu"), | ||
| 19352 | + ) | ||
| 19353 | + .unwrap_or_else(|e| panic!("{NAME}: reading the rect-strip control: {e}")); | ||
| 19354 | + let c_hits0 = crate::decode::chroma_rect_leaf_tx_hits(); | ||
| 19355 | + let c_diff0 = crate::decode::chroma_rect_leaf_tx_diff_hits(); | ||
| 19356 | + let c_frames = decode_stream(&control) | ||
| 19357 | + .unwrap_or_else(|e| panic!("{NAME}: the rect-strip control no longer decodes: {e}")) | ||
| 19358 | + .len(); | ||
| 19359 | + let c_hits = crate::decode::chroma_rect_leaf_tx_hits() - c_hits0; | ||
| 19360 | + let c_diff = crate::decode::chroma_rect_leaf_tx_diff_hits() - c_diff0; | ||
| 19361 | + assert!( | ||
| 19362 | + c_frames > 0, | ||
| 19363 | + "{NAME}: the rect-strip control decoded no frames" | ||
| 19364 | + ); | ||
| 19365 | + assert!( | ||
| 19366 | + c_hits > 0 && c_diff == 0, | ||
| 19367 | + "{NAME}: the rect-strip control fired the route {c_hits} times with {c_diff} differing \ | ||
| 19368 | + types -- expected the single-unit/same-type shape (route fires, nothing changes)" | ||
| 19369 | + ); | ||
| 19370 | + } | ||
| 19371 | + | ||
| 19273 | /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` | 19372 | /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` |
| 19274 | /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 | 19373 | /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 |
| 19275 | /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs | 19374 | /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs |