Merge branch 'lane-av1444chr'
Browse files at this commit4 changed files +429 -50
- crates/ec-av1/fixtures/444_quad_leaf_tx_type.obu +0 -0
- crates/ec-av1/src/decode.rs +126 -50
- crates/ec-av1/src/stream.rs +102 -0
- lanes/av1444chr.report.md +201 -0
crates/ec-av1/fixtures/444_quad_leaf_tx_type.obuadded+0 -0
Binary file changed
crates/ec-av1/src/decode.rsmodified+126 -50
| @@ -13848,16 +13848,7 @@ fn decode_intrabc_128rect( | |||
| 13848 | // covering its own quadrant (all of this chunk's | 13848 | // covering its own quadrant (all of this chunk's |
| 13849 | // leaves are read by now). | 13849 | // leaves are read by now). |
| 13850 | let unit_rel_mi = (unit_mi.0 - mi_r, unit_mi.1 - mi_c); | 13850 | let unit_rel_mi = (unit_mi.0 - mi_r, unit_mi.1 - mi_c); |
| 13851 | - let covering = leaf_tx_types | 13851 | + let covering = covering_leaf_tx_type(&leaf_tx_types, unit_rel_mi); |
| 13852 | - .iter() | ||
| 13853 | - .copied() | ||
| 13854 | - .find(|&(lr, lc, lw, lh, _)| { | ||
| 13855 | - lr <= unit_rel_mi.0 | ||
| 13856 | - && unit_rel_mi.0 < lr + lh / MI | ||
| 13857 | - && lc <= unit_rel_mi.1 | ||
| 13858 | - && unit_rel_mi.1 < lc + lw / MI | ||
| 13859 | - }) | ||
| 13860 | - .map(|(_, _, _, _, t)| t); | ||
| 13861 | // The prediction window is the block's own square | 13852 | // The prediction window is the block's own square |
| 13862 | // `cside` buffer with the unit's true per-axis | 13853 | // `cside` buffer with the unit's true per-axis |
| 13863 | // position inside it. | 13854 | // position inside it. |
| @@ -37888,6 +37879,70 @@ const fn sub16_to_mi(t: (usize, usize)) -> (usize, usize) { | |||
| 37888 | (t.0 * (SUB / MI), t.1 * (SUB / MI)) | 37879 | (t.0 * (SUB / MI), t.1 * (SUB / MI)) |
| 37889 | } | 37880 | } |
| 37890 | 37881 | ||
| 37882 | +/// The luma transform leaf a chroma unit inherits its `tx_type` from | ||
| 37883 | +/// (libaom `av1_get_tx_type`, `blockd.h:1287-1297`): an INTER block's chroma | ||
| 37884 | +/// unit never codes a `tx_type` symbol of its own, so the type is read out | ||
| 37885 | +/// of `xd->tx_type_map` at the chroma unit's own position scaled back to luma | ||
| 37886 | +/// (`blk_row << ss_y`, `blk_col << ss_x`). `leaves` is the block's coded | ||
| 37887 | +/// transform tree in decode order, `(row, col, tw, th, tx_type)` with | ||
| 37888 | +/// `(row, col)` in MI relative to the block and `(tw, th)` in PIXELS; | ||
| 37889 | +/// `rel_mi` is the chroma unit's own luma-relative top-left MI cell. One | ||
| 37890 | +/// function serves the 128x128 mu-chunk tail and the 64x64 arms alike -- the | ||
| 37891 | +/// lookup is the same rule, so a second inline copy would be a second | ||
| 37892 | +/// convention. | ||
| 37893 | +/// | ||
| 37894 | +/// A leaf that coded nothing resolves to `DctDct` here exactly as libaom's | ||
| 37895 | +/// `decodetxb.c:199-203` stamps `DCT_DCT` into that leaf's map cell on the | ||
| 37896 | +/// `all_zero` path: a chroma unit over a SKIPPED luma quadrant must NOT | ||
| 37897 | +/// inherit the block-level (top-left leaf) type. | ||
| 37898 | +fn covering_leaf_tx_type( | ||
| 37899 | + leaves: &[(usize, usize, usize, usize, TxType)], | ||
| 37900 | + rel_mi: (usize, usize), | ||
| 37901 | +) -> Option<TxType> { | ||
| 37902 | + leaves | ||
| 37903 | + .iter() | ||
| 37904 | + .copied() | ||
| 37905 | + // leaf (row, col) are mi but (tw, th) are px (the rect leaf path | ||
| 37906 | + // divides by MI too) | ||
| 37907 | + .find(|&(lr, lc, lw, lh, _)| { | ||
| 37908 | + lr <= rel_mi.0 && rel_mi.0 < lr + lh / MI && lc <= rel_mi.1 && rel_mi.1 < lc + lw / MI | ||
| 37909 | + }) | ||
| 37910 | + .map(|(_, _, _, _, t)| t) | ||
| 37911 | +} | ||
| 37912 | + | ||
| 37913 | +thread_local! { | ||
| 37914 | + /// lane-av1444chr: how many chroma units resolved their `tx_type` from the | ||
| 37915 | + /// luma leaf covering their OWN quadrant instead of the block-level | ||
| 37916 | + /// (`first_tx_type`) one -- the route this lane corrected. | ||
| 37917 | + /// `CHROMA_SPLIT_TX_HITS` cannot attribute its bumps to it: every split | ||
| 37918 | + /// chroma unit bumps that one. | ||
| 37919 | + pub(crate) static CHROMA_QUAD_LEAF_TX_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 37920 | +} | ||
| 37921 | + | ||
| 37922 | +thread_local! { | ||
| 37923 | + /// Of those, how many resolved a type that DIFFERS from the block-level one | ||
| 37924 | + /// -- the exact condition lane-av1444chr measured wrong: over a luma leaf | ||
| 37925 | + /// that coded nothing the map cell is `DCT_DCT` while the top-left leaf's | ||
| 37926 | + /// is `IDTX`. A gate proving the corrected route fired is NOT enough on | ||
| 37927 | + /// its own (a block whose four leaves agree changes zero pixels); this is | ||
| 37928 | + /// the number that says the route changed an answer. | ||
| 37929 | + pub(crate) static CHROMA_QUAD_LEAF_TX_DIFF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) }; | ||
| 37930 | +} | ||
| 37931 | + | ||
| 37932 | +/// [`CHROMA_QUAD_LEAF_TX_HITS`]: chroma units that took their type from the | ||
| 37933 | +/// covering luma leaf. | ||
| 37934 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 37935 | +pub(crate) fn chroma_quad_leaf_tx_hits() -> usize { | ||
| 37936 | + CHROMA_QUAD_LEAF_TX_HITS.with(std::cell::Cell::get) | ||
| 37937 | +} | ||
| 37938 | + | ||
| 37939 | +/// [`CHROMA_QUAD_LEAF_TX_DIFF_HITS`]: chroma units whose covering leaf's type | ||
| 37940 | +/// differs from the block-level one. | ||
| 37941 | +#[allow(dead_code)] // read only from the `#[cfg(test)]` gates | ||
| 37942 | +pub(crate) fn chroma_quad_leaf_tx_diff_hits() -> usize { | ||
| 37943 | + CHROMA_QUAD_LEAF_TX_DIFF_HITS.with(std::cell::Cell::get) | ||
| 37944 | +} | ||
| 37945 | + | ||
| 37891 | fn decode_inter_block( | 37946 | fn decode_inter_block( |
| 37892 | dec: &mut SymbolDecoder, | 37947 | dec: &mut SymbolDecoder, |
| 37893 | cdfs: &mut Cdfs, | 37948 | cdfs: &mut Cdfs, |
| @@ -39486,12 +39541,13 @@ fn decode_inter_block( | |||
| 39486 | if idx == 0 { | 39541 | if idx == 0 { |
| 39487 | first_tx_type = tu_tx_type; | 39542 | first_tx_type = tu_tx_type; |
| 39488 | } | 39543 | } |
| 39489 | - // lane-av1-444-128: the per-unit chroma inheritance in | 39544 | + // lane-av1444chr: EVERY luma leaf's coded type, at |
| 39490 | - // the chunk tail resolves each unit's own tx_type from | 39545 | + // every block size (see the single-reference twin |
| 39491 | - // the luma leaf covering its quadrant. | 39546 | + // below) -- the chroma units resolve their own |
| 39492 | - if side > 64 { | 39547 | + // quadrant's leaf, and a leaf that coded NOTHING is |
| 39493 | - leaf_tx_types.push((row, col, tw, th, tu_tx_type)); | 39548 | + // `DctDct` exactly as libaom's `decodetxb.c:199-203` |
| 39494 | - } | 39549 | + // stamps `DCT_DCT` into that leaf's map cell. |
| 39550 | + leaf_tx_types.push((row, col, tw, th, tu_tx_type)); | ||
| 39495 | neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); | 39551 | neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); |
| 39496 | // lane-sb128c r1: libaom's `decode_token_recon_block` | 39552 | // lane-sb128c r1: libaom's `decode_token_recon_block` |
| 39497 | // walks 64x64 "mu" chunks (`mu_blocks_wide/high = | 39553 | // walks 64x64 "mu" chunks (`mu_blocks_wide/high = |
| @@ -39613,19 +39669,8 @@ fn decode_inter_block( | |||
| 39613 | // leaves are read by now). | 39669 | // leaves are read by now). |
| 39614 | let unit_rel_mi = | 39670 | let unit_rel_mi = |
| 39615 | (unit_mi.0 - at_mi.0, unit_mi.1 - at_mi.1); | 39671 | (unit_mi.0 - at_mi.0, unit_mi.1 - at_mi.1); |
| 39616 | - let covering = leaf_tx_types | 39672 | + let covering = |
| 39617 | - .iter() | 39673 | + covering_leaf_tx_type(&leaf_tx_types, unit_rel_mi); |
| 39618 | - .copied() | ||
| 39619 | - // leaf (row, col) are mi but | ||
| 39620 | - // (tw, th) are px (the rect | ||
| 39621 | - // leaf path divides by MI too) | ||
| 39622 | - .find(|&(lr, lc, lw, lh, _)| { | ||
| 39623 | - lr <= unit_rel_mi.0 | ||
| 39624 | - && unit_rel_mi.0 < lr + lh / MI | ||
| 39625 | - && lc <= unit_rel_mi.1 | ||
| 39626 | - && unit_rel_mi.1 < lc + lw / MI | ||
| 39627 | - }) | ||
| 39628 | - .map(|(_, _, _, _, t)| t); | ||
| 39629 | // The prediction buffer is | 39674 | // The prediction buffer is |
| 39630 | // `chroma_stride`-strided (the | 39675 | // `chroma_stride`-strided (the |
| 39631 | // plane block's own width at | 39676 | // plane block's own width at |
| @@ -39857,6 +39902,19 @@ fn decode_inter_block( | |||
| 39857 | for cc in 0..mu_units_n { | 39902 | for cc in 0..mu_units_n { |
| 39858 | let cu_mi = (rmi + cr * (cu_tx / MI), cmi + cc * (cu_tx / MI)); | 39903 | let cu_mi = (rmi + cr * (cu_tx / MI), cmi + cc * (cu_tx / MI)); |
| 39859 | let cu_around = neighbours.around_mi(cu_mi, cu_tx); | 39904 | let cu_around = neighbours.around_mi(cu_mi, cu_tx); |
| 39905 | + // Per-quadrant inheritance, as in the | ||
| 39906 | + // single-reference twin: the covering luma | ||
| 39907 | + // leaf's OWN coded type, `DctDct` where that | ||
| 39908 | + // leaf coded nothing. | ||
| 39909 | + let cu_rel_mi = (cr * (cu_tx / MI), cc * (cu_tx / MI)); | ||
| 39910 | + let cu_tx_type = covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi) | ||
| 39911 | + .unwrap_or(luma_tx_type); | ||
| 39912 | + if covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi).is_some() { | ||
| 39913 | + hit!(CHROMA_QUAD_LEAF_TX_HITS); | ||
| 39914 | + if cu_tx_type != luma_tx_type { | ||
| 39915 | + hit!(CHROMA_QUAD_LEAF_TX_DIFF_HITS); | ||
| 39916 | + } | ||
| 39917 | + } | ||
| 39860 | let cu_grid = read_inter_plane( | 39918 | let cu_grid = read_inter_plane( |
| 39861 | dec, | 39919 | dec, |
| 39862 | cdfs, | 39920 | cdfs, |
| @@ -39871,7 +39929,7 @@ fn decode_inter_block( | |||
| 39871 | cu_tx, | 39929 | cu_tx, |
| 39872 | base_q_idx, | 39930 | base_q_idx, |
| 39873 | src.offset(cr * cu_tx * chroma_side + cc * cu_tx), | 39931 | src.offset(cr * cu_tx * chroma_side + cc * cu_tx), |
| 39874 | - Some(luma_tx_type), | 39932 | + Some(cu_tx_type), |
| 39875 | Some(3), | 39933 | Some(3), |
| 39876 | fctx, | 39934 | fctx, |
| 39877 | )? | 39935 | )? |
| @@ -41263,12 +41321,19 @@ fn decode_inter_block( | |||
| 41263 | if idx == 0 { | 41321 | if idx == 0 { |
| 41264 | first_tx_type = tu_tx_type; | 41322 | first_tx_type = tu_tx_type; |
| 41265 | } | 41323 | } |
| 41266 | - // lane-av1-444-128: the per-unit chroma inheritance in | 41324 | + // lane-av1444chr: EVERY luma leaf's coded type, at |
| 41267 | - // the chunk tail resolves each unit's own tx_type from | 41325 | + // every block size -- the chroma units below resolve |
| 41268 | - // the luma leaf covering its quadrant. | 41326 | + // their own quadrant's leaf, and at 64x64 that is |
| 41269 | - if side > 64 { | 41327 | + // this very loop's leaves (`av1_get_tx_type`, |
| 41270 | - leaf_tx_types.push((row, col, tw, th, tu_tx_type)); | 41328 | + // blockd.h:1287-1297, scales the CHROMA 4x4 position |
| 41271 | - } | 41329 | + // back to luma). It used to be collected only for |
| 41330 | + // `side > 64`, so the 64x64 four-unit arm below had | ||
| 41331 | + // nothing to resolve from and handed all four units | ||
| 41332 | + // the block-level (top-left leaf) type. A leaf that | ||
| 41333 | + // coded NOTHING is `DctDct` here exactly as libaom's | ||
| 41334 | + // `decodetxb.c:199-203` stamps `DCT_DCT` into that | ||
| 41335 | + // leaf's map cell on the `all_zero` path. | ||
| 41336 | + leaf_tx_types.push((row, col, tw, th, tu_tx_type)); | ||
| 41272 | neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); | 41337 | neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid); |
| 41273 | // lane-sb128c r1: libaom's `decode_token_recon_block` | 41338 | // lane-sb128c r1: libaom's `decode_token_recon_block` |
| 41274 | // walks 64x64 "mu" chunks (`mu_blocks_wide/high = | 41339 | // walks 64x64 "mu" chunks (`mu_blocks_wide/high = |
| @@ -41390,19 +41455,8 @@ fn decode_inter_block( | |||
| 41390 | // leaves are read by now). | 41455 | // leaves are read by now). |
| 41391 | let unit_rel_mi = | 41456 | let unit_rel_mi = |
| 41392 | (unit_mi.0 - at_mi.0, unit_mi.1 - at_mi.1); | 41457 | (unit_mi.0 - at_mi.0, unit_mi.1 - at_mi.1); |
| 41393 | - let covering = leaf_tx_types | 41458 | + let covering = |
| 41394 | - .iter() | 41459 | + covering_leaf_tx_type(&leaf_tx_types, unit_rel_mi); |
| 41395 | - .copied() | ||
| 41396 | - // leaf (row, col) are mi but | ||
| 41397 | - // (tw, th) are px (the rect | ||
| 41398 | - // leaf path divides by MI too) | ||
| 41399 | - .find(|&(lr, lc, lw, lh, _)| { | ||
| 41400 | - lr <= unit_rel_mi.0 | ||
| 41401 | - && unit_rel_mi.0 < lr + lh / MI | ||
| 41402 | - && lc <= unit_rel_mi.1 | ||
| 41403 | - && unit_rel_mi.1 < lc + lw / MI | ||
| 41404 | - }) | ||
| 41405 | - .map(|(_, _, _, _, t)| t); | ||
| 41406 | // The prediction buffer is | 41460 | // The prediction buffer is |
| 41407 | // `chroma_stride`-strided (the | 41461 | // `chroma_stride`-strided (the |
| 41408 | // plane block's own width at | 41462 | // plane block's own width at |
| @@ -41640,6 +41694,28 @@ fn decode_inter_block( | |||
| 41640 | for cc in 0..mu_units_n { | 41694 | for cc in 0..mu_units_n { |
| 41641 | let cu_mi = (rmi + cr * (cu_tx / MI), cmi + cc * (cu_tx / MI)); | 41695 | let cu_mi = (rmi + cr * (cu_tx / MI), cmi + cc * (cu_tx / MI)); |
| 41642 | let cu_around = neighbours.around_mi(cu_mi, cu_tx); | 41696 | let cu_around = neighbours.around_mi(cu_mi, cu_tx); |
| 41697 | + // `av1_get_tx_type` (blockd.h:1287-1297): an | ||
| 41698 | + // inter block's chroma unit never codes a | ||
| 41699 | + // `tx_type`; it reads the map cell at its OWN | ||
| 41700 | + // position scaled back to luma | ||
| 41701 | + // (`blk_row << ss_y`, `blk_col << ss_x`), | ||
| 41702 | + // which is the coded type of the luma leaf | ||
| 41703 | + // covering this unit's top-left mi cell -- | ||
| 41704 | + // `DctDct` when that leaf coded nothing | ||
| 41705 | + // (`decodetxb.c:199-203`). The block-level | ||
| 41706 | + // `luma_tx_type` is only the TOP-LEFT leaf's | ||
| 41707 | + // type, so handing it to all four units | ||
| 41708 | + // mistyped every unit sitting over a skipped | ||
| 41709 | + // or differently-typed luma quadrant. | ||
| 41710 | + let cu_rel_mi = (cr * (cu_tx / MI), cc * (cu_tx / MI)); | ||
| 41711 | + let cu_tx_type = covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi) | ||
| 41712 | + .unwrap_or(luma_tx_type); | ||
| 41713 | + if covering_leaf_tx_type(&leaf_tx_types, cu_rel_mi).is_some() { | ||
| 41714 | + hit!(CHROMA_QUAD_LEAF_TX_HITS); | ||
| 41715 | + if cu_tx_type != luma_tx_type { | ||
| 41716 | + hit!(CHROMA_QUAD_LEAF_TX_DIFF_HITS); | ||
| 41717 | + } | ||
| 41718 | + } | ||
| 41643 | let cu_grid = read_inter_plane( | 41719 | let cu_grid = read_inter_plane( |
| 41644 | dec, | 41720 | dec, |
| 41645 | cdfs, | 41721 | cdfs, |
| @@ -41654,7 +41730,7 @@ fn decode_inter_block( | |||
| 41654 | cu_tx, | 41730 | cu_tx, |
| 41655 | base_q_idx, | 41731 | base_q_idx, |
| 41656 | src.offset(cr * cu_tx * chroma_side + cc * cu_tx), | 41732 | src.offset(cr * cu_tx * chroma_side + cc * cu_tx), |
| 41657 | - Some(luma_tx_type), | 41733 | + Some(cu_tx_type), |
| 41658 | Some(3), | 41734 | Some(3), |
| 41659 | fctx, | 41735 | fctx, |
| 41660 | )? | 41736 | )? |
crates/ec-av1/src/stream.rsmodified+102 -0
| @@ -18992,6 +18992,108 @@ pub(crate) mod tests { | |||
| 18992 | ); | 18992 | ); |
| 18993 | } | 18993 | } |
| 18994 | 18994 | ||
| 18995 | + /// lane-av1444chr: a 4:4:4 INTER chroma unit inherits the `tx_type` of | ||
| 18996 | + /// the luma leaf covering its OWN quadrant, not the block-level (top-left | ||
| 18997 | + /// leaf) one. `av1_get_tx_type` (`blockd.h:1287-1297`) reads | ||
| 18998 | + /// `xd->tx_type_map` at the chroma unit's own position scaled back to | ||
| 18999 | + /// luma, and `read_coeffs`' `all_zero` arm stamps `DCT_DCT` into that | ||
| 19000 | + /// leaf's cell (`decodetxb.c:199-203`) -- so a chroma unit sitting over a | ||
| 19001 | + /// luma leaf that coded NOTHING must reconstruct as DCT_DCT even when the | ||
| 19002 | + /// block's top-left leaf is `IDTX`. | ||
| 19003 | + /// | ||
| 19004 | + /// The fixture is the report's witness pinned into `fixtures/`: | ||
| 19005 | + /// `testsrc2 128x128` yuv444p 4 frames, aomenc `--profile=1 --cq-level=20 | ||
| 19006 | + /// --cpu-used=2 --sb-size=64 --min-partition-size=64 | ||
| 19007 | + /// --max-partition-size=64 --passes=1 --end-usage=q --threads=1 --row-mt=0 | ||
| 19008 | + /// --lag-in-frames=0 --kf-max-dist=100 --limit=4 --obu`; 27933 bytes, | ||
| 19009 | + /// sha256 `a06c9f7a0862252f6ab7ebdcec340d0602e730e38089365f14747db37f8e78d5`. | ||
| 19010 | + /// Every inter block is a whole 64x64 (min=max partition 64) whose luma | ||
| 19011 | + /// var-tx tree is four TX_32X32 leaves, so each block's chroma plane is | ||
| 19012 | + /// four TX_32X32 units -- one per leaf. | ||
| 19013 | + /// | ||
| 19014 | + /// Pre-fix, decode-order frames 1/2/3 differ from the oracle in 777/640/554 | ||
| 19015 | + /// V samples (luma and U exact) and the per-unit type census disagrees at | ||
| 19016 | + /// exactly the units over the skipped leaf: V(0,32) of block mi(0,0) in | ||
| 19017 | + /// frame 1, V(64,96) of block mi(16,16) in every inter frame. Post-fix all | ||
| 19018 | + /// 136 non-empty inter units agree with the oracle's `EC_DQCOEFF` type and | ||
| 19019 | + /// every frame is byte-exact. | ||
| 19020 | + /// | ||
| 19021 | + /// The non-vacuity bar is the DIFFERS counter, not the route counter: a | ||
| 19022 | + /// route counter fires on every four-unit chroma read (96 of them here) | ||
| 19023 | + /// and stayed green through a no-op fix that changed zero pixels, because | ||
| 19024 | + /// on a block whose four leaves agree the per-quadrant resolve and the | ||
| 19025 | + /// block-level value are the same answer. The number that says the resolve | ||
| 19026 | + /// CHANGED something is 8 on this stream -- the four skipped-leaf quadrants | ||
| 19027 | + /// (two of them in decode-order frame 1), each resolved once per chroma | ||
| 19028 | + /// plane -- and it must be 0 on the 4:2:0 control below, since the arm is | ||
| 19029 | + /// unreachable at 4:2:0. | ||
| 19030 | + #[test] | ||
| 19031 | + fn a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type() { | ||
| 19032 | + const NAME: &str = | ||
| 19033 | + "a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type"; | ||
| 19034 | + const FIXTURE_LEN: usize = 27933; | ||
| 19035 | + const FIXTURE_FNV: u64 = 0x85fa_830b_8800_90df; | ||
| 19036 | + let _gate_lock = lock_gate_counters(); | ||
| 19037 | + if !have_aomenc() { | ||
| 19038 | + eprintln!( | ||
| 19039 | + "SKIP {NAME}: no aomenc/aomdec oracle at {}", | ||
| 19040 | + aomenc_path().display() | ||
| 19041 | + ); | ||
| 19042 | + return; | ||
| 19043 | + } | ||
| 19044 | + let path = std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 19045 | + .join("fixtures/444_quad_leaf_tx_type.obu"); | ||
| 19046 | + let stream = std::fs::read(&path) | ||
| 19047 | + .unwrap_or_else(|e| panic!("{NAME}: reading {}: {e}", path.display())); | ||
| 19048 | + assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved"); | ||
| 19049 | + assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved"); | ||
| 19050 | + | ||
| 19051 | + let quad0 = crate::decode::chroma_quad_leaf_tx_hits(); | ||
| 19052 | + let diff0 = crate::decode::chroma_quad_leaf_tx_diff_hits(); | ||
| 19053 | + let (frames, hidden) = decode_all_frames_vs_oracle(&stream, NAME); | ||
| 19054 | + let quad = crate::decode::chroma_quad_leaf_tx_hits() - quad0; | ||
| 19055 | + let diff = crate::decode::chroma_quad_leaf_tx_diff_hits() - diff0; | ||
| 19056 | + assert_eq!( | ||
| 19057 | + frames, 4, | ||
| 19058 | + "{NAME}: expected 4 decode-order frames ({hidden} hidden)" | ||
| 19059 | + ); | ||
| 19060 | + assert!( | ||
| 19061 | + quad >= 2 * diff && quad > 0, | ||
| 19062 | + "{NAME}: no chroma unit took its type from the covering luma leaf \ | ||
| 19063 | + (quad {quad}, differs {diff}) -- the corrected route never ran" | ||
| 19064 | + ); | ||
| 19065 | + assert!( | ||
| 19066 | + diff >= 2, | ||
| 19067 | + "{NAME}: the per-quadrant resolve never CHANGED an answer (diff {diff}; measured 4 \ | ||
| 19068 | + on this stream, 2 of them in decode-order frame 1). A route counter alone is not a \ | ||
| 19069 | + witness: it fires on every four-unit chroma read, including the \ | ||
| 19070 | + blocks whose four leaves all agree -- the exact shape a no-op fix looked green on." | ||
| 19071 | + ); | ||
| 19072 | + eprintln!("{NAME}: quad-resolved chroma units {quad}, of which {diff} differed"); | ||
| 19073 | + | ||
| 19074 | + // 4:2:0 control: the same decode, same counters, zero differences -- | ||
| 19075 | + // the four-unit arm is the 4:4:4 (`ss 0/0`) route only. | ||
| 19076 | + let control = std::fs::read( | ||
| 19077 | + std::path::Path::new(env!("CARGO_MANIFEST_DIR")) | ||
| 19078 | + .join("fixtures/av1_192x128_8bit_intra64_in_inter.obu"), | ||
| 19079 | + ) | ||
| 19080 | + .unwrap_or_else(|e| panic!("{NAME}: reading the 4:2:0 control: {e}")); | ||
| 19081 | + let c_quad0 = crate::decode::chroma_quad_leaf_tx_hits(); | ||
| 19082 | + let c_diff0 = crate::decode::chroma_quad_leaf_tx_diff_hits(); | ||
| 19083 | + let c_frames = decode_stream(&control) | ||
| 19084 | + .unwrap_or_else(|e| panic!("{NAME}: the 4:2:0 control no longer decodes: {e}")) | ||
| 19085 | + .len(); | ||
| 19086 | + let c_quad = crate::decode::chroma_quad_leaf_tx_hits() - c_quad0; | ||
| 19087 | + let c_diff = crate::decode::chroma_quad_leaf_tx_diff_hits() - c_diff0; | ||
| 19088 | + assert!(c_frames > 0, "{NAME}: the 4:2:0 control decoded no frames"); | ||
| 19089 | + assert_eq!( | ||
| 19090 | + (c_quad, c_diff), | ||
| 19091 | + (0, 0), | ||
| 19092 | + "{NAME}: the 4:2:0 control fired the 4:4:4 four-unit route ({c_quad} units, {c_diff} \ | ||
| 19093 | + differing) -- the counter is not specific to the route it claims to witness" | ||
| 19094 | + ); | ||
| 19095 | + } | ||
| 19096 | + | ||
| 18995 | /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` | 19097 | /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT` |
| 18996 | /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 | 19098 | /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1 |
| 18997 | /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs | 19099 | /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs |
lanes/av1444chr.report.mdadded+201 -0
| @@ -0,0 +1,201 @@ | |||
| 1 | +# lane-av1444chr — 4:4:4 chroma per-quadrant tx_type (H2 fixed) + lossless key-frame chroma localization (H3) | ||
| 2 | + | ||
| 3 | +Branch `lane-av1444chr` (worktree `~/.cache/wt/av1444chr`), base `4155c7c7`. | ||
| 4 | +Oracle `~/.cache/aom-oracle/build/{aomdec,aomenc}` (instrumented). | ||
| 5 | +`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-av1444chr`. | ||
| 6 | + | ||
| 7 | +## H2 — FIXED. Per-quadrant `tx_type` inheritance for 4:4:4 inter chroma units | ||
| 8 | + | ||
| 9 | +### Witness (pinned) | ||
| 10 | + | ||
| 11 | +`crates/ec-av1/fixtures/444_quad_leaf_tx_type.obu`, 27933 bytes, | ||
| 12 | +sha256 `a06c9f7a0862252f6ab7ebdcec340d0602e730e38089365f14747db37f8e78d5`, | ||
| 13 | +fnv1a64 `0x85fa830b880090df`. | ||
| 14 | + | ||
| 15 | +Recipe (reproduces the sha bit-for-bit on this box): | ||
| 16 | + | ||
| 17 | +``` | ||
| 18 | +ffmpeg -f lavfi -i "testsrc2=size=128x128:rate=25" -frames:v 4 -pix_fmt yuv444p -f yuv4mpegpipe - src.y4m | ||
| 19 | +aomenc --codec=av1 --profile=1 --cq-level=20 --cpu-used=2 --sb-size=64 \ | ||
| 20 | + --min-partition-size=64 --max-partition-size=64 --passes=1 --end-usage=q \ | ||
| 21 | + --threads=1 --row-mt=0 --lag-in-frames=0 --kf-max-dist=100 --limit=4 --obu -o w.obu src.y4m | ||
| 22 | +``` | ||
| 23 | + | ||
| 24 | +### The site identification Main asked for (three block-level-type sites instrumented) | ||
| 25 | + | ||
| 26 | +`decode_inter_block` contains TWO structurally duplicated chroma arm chains — the | ||
| 27 | +compound branch and the single-reference branch. The charter's line number | ||
| 28 | +(`~39591` pre-revert) is the COMPOUND copy. Instrumenting all six sites | ||
| 29 | +(env-gated, since removed) with `mi= side= cside= ctx= blk_type= leaves=`: | ||
| 30 | + | ||
| 31 | +| site | hits on the witness | | ||
| 32 | +|---|---| | ||
| 33 | +| compound `rect` / `quad4` / `whole` | 0 / **1** / 0 | | ||
| 34 | +| single-ref `srect` / `squad4` / `swhole` | 0 / **12** / 0 | | ||
| 35 | + | ||
| 36 | +So `quad4` (the 4:4:4 four-unit arm) IS the live site — but only in its | ||
| 37 | +**single-reference** copy, 12 times (4 blocks x 3 inter frames). The compound | ||
| 38 | +copy fires exactly once, on one block whose four leaves all agree: that is why | ||
| 39 | +the earlier port looked like a no-op. Each dump also showed | ||
| 40 | +`side=64 cside=64 ctx=32`, i.e. the 64x64 `chroma_side > chroma_tx` arm with | ||
| 41 | +`chroma_tx=32` — the four-TX_32X32-per-plane shape. | ||
| 42 | + | ||
| 43 | +### Root (measured, not assumed) | ||
| 44 | + | ||
| 45 | +1. Every inter block here is a whole 64x64 (min=max partition 64) whose luma | ||
| 46 | + var-tx tree is four TX_32X32 leaves in raster order. `leaf_tx_types` was | ||
| 47 | + collected ONLY under `if side > 64`, so at 64 it was empty and the arm | ||
| 48 | + handed all four chroma units the block-level `luma_tx_type` = the top-left | ||
| 49 | + leaf's type. | ||
| 50 | +2. Per-unit type census, ours (`EC_TRACE_UNIT`, non-empty units in decode | ||
| 51 | + order) vs the oracle's `EC_DQCOEFF`, paired 1:1 after skipping frame 0's | ||
| 52 | + 45 intra-frame units (136 inter units on each side, counts equal): | ||
| 53 | + **pre-fix 4 disagreements, all V plane, all where the covering luma leaf | ||
| 54 | + coded nothing** — V(0,32) of block mi(0,0) in frame 1, V(64,96) of block | ||
| 55 | + mi(16,16) in each of the three inter frames. Post-fix **136/136 agree**. | ||
| 56 | +3. Our own `EC_TRACE_TXTYPE` shows the covering leaf of exactly those quadrants | ||
| 57 | + returning `DctDct` (the `all_zero` stamp, mirroring `decodetxb.c:199-203`), | ||
| 58 | + while the block-level type is `Idtx`. That is the whole defect: a chroma | ||
| 59 | + unit over a SKIPPED luma quadrant inherited the block's `IDTX` instead of | ||
| 60 | + the map cell's `DCT_DCT`. | ||
| 61 | + | ||
| 62 | +### The fix | ||
| 63 | + | ||
| 64 | +- `covering_leaf_tx_type(leaves, rel_mi)` — one function, extracted from the | ||
| 65 | + three inline copies that already existed (the 128 mu-chunk tail in both | ||
| 66 | + copies and the intrabc-128rect path), so there is no second convention. | ||
| 67 | +- `leaf_tx_types.push(...)` is now unconditional in both copies (the `side > 64` | ||
| 68 | + gate is gone). | ||
| 69 | +- Both four-unit arms resolve per quadrant: | ||
| 70 | + `covering_leaf_tx_type(&leaf_tx_types, (cr * cu_tx/MI, cc * cu_tx/MI))` | ||
| 71 | + with `.unwrap_or(luma_tx_type)` as the fallback for a block that coded a | ||
| 72 | + single luma unit (no vartx tree, so no leaves collected). | ||
| 73 | + | ||
| 74 | +### Bar | ||
| 75 | + | ||
| 76 | +- **Red-before by mutation**: reverting only the live arm's resolve | ||
| 77 | + (`let cu_tx_type = luma_tx_type;`) turns the new gate red with | ||
| 78 | + `decode-order frame 1 of 4 (4 shown, 0 hidden) differs from the oracle at | ||
| 79 | + byte 36635 (ours 127 vs 126), 777 bytes differ` — the report's 777 wrong V | ||
| 80 | + samples. Restored: green. | ||
| 81 | +- **Identity green** (each run as a single named test, `--nocapture`, no SKIP | ||
| 82 | + lines): `a_lossless_444_min_partition64_inter_stream_decodes_pixel_exact`, | ||
| 83 | + `a_lossless_444_defaultp_inter_strip_stream_decodes_byte_exact`, | ||
| 84 | + `a_444_sb128_root_rect_stream_with_restoration_decodes_pixel_exact`, | ||
| 85 | + `a_real_aomenc_stream_with_a_16_level_1to4_partition_decodes_pixel_exact`, | ||
| 86 | + `a_real_aomenc_rect_strip_palette_decodes_pixel_exact` — 5/5 ok. | ||
| 87 | + NOTE: the three sweep gate names in the charter | ||
| 88 | + (`a_real_aomenc_odd_coded_dimension_streams_decode_pixel_exact`, | ||
| 89 | + `a_lossless_444_10bit_inter_stream_decodes_pixel_exact`, | ||
| 90 | + `a_444_12bit_inter_sequence_decodes_pixel_exact`) DO NOT EXIST in this tree; | ||
| 91 | + the closest existing gates from each family were run instead. The 32-attempt | ||
| 92 | + `a_real_aomenc_inter_sequence_with_a_16_level_rect_leaf_decodes_pixel_exact` | ||
| 93 | + was NOT run locally (multi-encode sweep — server/Main territory). | ||
| 94 | +- **New gate**: `stream::tests::a_pinned_444_inter_stream_chroma_units_inherit_their_own_quadrants_tx_type` | ||
| 95 | + (fixtures/444_quad_leaf_tx_type.obu, length + fnv pinned, oracle compare via | ||
| 96 | + the length-asserting `decode_all_frames_vs_oracle`, 4 frames, 0 hidden). | ||
| 97 | + Measured on the witness: `quad-resolved chroma units 96, of which 8 differed` | ||
| 98 | + — 96 = 4 blocks x 4 units x 2 planes x 3 inter frames; the 8 = the four | ||
| 99 | + skipped-leaf quadrants (two of them in frame 1) resolved once per plane. | ||
| 100 | + The gate asserts `diff >= 2` and, per Main's non-vacuity correction, uses the | ||
| 101 | + DIFFERS number rather than the route counter: the route counter fires on all | ||
| 102 | + 96 reads and stayed green through the earlier no-op port. A 4:2:0 control | ||
| 103 | + (`fixtures/av1_192x128_8bit_intra64_in_inter.obu`, sha256 | ||
| 104 | + `e4cff46cb1700527c68efc866db27a2835705e949d646f73f0c9df577d594bd6`) asserts | ||
| 105 | + both counters stay at exactly 0. | ||
| 106 | + | ||
| 107 | +### Class sweep (same rule, other sites) | ||
| 108 | + | ||
| 109 | +- The two 128x128 mu-chunk tails and the intrabc-128rect path now call the | ||
| 110 | + shared helper instead of three inline copies of the same search (pure code | ||
| 111 | + move, no behaviour change). | ||
| 112 | +- `read_inter_rect_chroma` (the `rect_tu || non-square chroma plane` sibling) | ||
| 113 | + still passes the block-level type to its units. Measured unreachable on five | ||
| 114 | + 4:4:4 rect-enabled recipes (testsrc2 128x128/192x128, cq 20/24/28/30/40, | ||
| 115 | + rect + 1to4 + tx-size-search + sb 64/128): the arm fires 13-43 times per | ||
| 116 | + stream but `multi` (nx*ny > 1, the only case where units could sit over | ||
| 117 | + different leaves) is **0 on every one**, and all five streams are | ||
| 118 | + pixel-exact against aomdec. Left unchanged deliberately rather than | ||
| 119 | + speculatively re-signaturing a shared helper; if a witness ever shows | ||
| 120 | + `multi` with mixed leaf types, that is where the same fix goes. | ||
| 121 | + | ||
| 122 | +## H3 — LOCALIZED, not fixed. Lossless 4:4:4 key-frame chroma | ||
| 123 | + | ||
| 124 | +### Witness used | ||
| 125 | + | ||
| 126 | +The charter's sha256 (`87b0d1a5…`, `--lossless=1 --tile-columns=1 --cpu-used=2`, | ||
| 127 | +256x128 testsrc2 yuv444p) did not reproduce from the flags as given: the encode | ||
| 128 | +is not bit-reproducible across the flag variants tried (68142 B | ||
| 129 | +`7b8d4d44…`, 67332 B `04de36a6…`, 75378 B `fe9eab1a…` for | ||
| 130 | +`--passes=1`/`--threads=1 --row-mt=0 --lag-in-frames=0`). I used the plain | ||
| 131 | +`--profile=1 --lossless=1 --tile-columns=1 --cpu-used=2 --limit=6` encode | ||
| 132 | +(68142 B, sha256 `7b8d4d442c4a847314b7bc8c26af79bae1b3e32b22b41eebef4c2dcacf895a57`), | ||
| 133 | +which reproduces the SAME SIGNATURE: luma exact in all six frames, 59-73 wrong U | ||
| 134 | +and 103-139 wrong V samples per frame, deltas ±1, confined to two small bands — | ||
| 135 | +chroma (108..123, 24..31) and (236..255, 56..67) in frame 0. | ||
| 136 | + | ||
| 137 | +### What is measured | ||
| 138 | + | ||
| 139 | +1. **Not coefficients.** Every affected unit's residual is ZERO on our side | ||
| 140 | + (`OUR_LLCHROMA`, all 16-value grids zero for the units at x=112..124, | ||
| 141 | + y=24/28) and the oracle agrees: for the block covering the first band | ||
| 142 | + (mi(6,28), a 16x8 block at (24,112)) `EC_COEFF_STEP tag=all_zero ... =1` on | ||
| 143 | + all eight chroma units with empty `EC_DQCOEFF`. So the WHT is not involved | ||
| 144 | + and neither side codes a residual there. | ||
| 145 | +2. **It is the intra chroma PREDICTION.** Scoped to frame 0 only (the stream | ||
| 146 | + cut to its first shown frame; 98304 bytes both sides, lengths asserted), | ||
| 147 | + `EC_PRED`/`EC_PREDOUT8` vs our `OUR_PRED` compared per unit: | ||
| 148 | + - U px(108,24) oracle sum 267 vs ours 245 | ||
| 149 | + - U px(112,24) 243 vs 236, px(112,28) 1731 vs 1707 | ||
| 150 | + - U px(116,24) 240 vs 248, px(120,24) 248 vs 251 | ||
| 151 | + - V px(116,28), px(120,28), px(124,28) | ||
| 152 | + Every other unit in the window matches by sum, row0 and col0, and the LUMA | ||
| 153 | + of the same blocks matches exactly. | ||
| 154 | +3. **Shape of the divergence.** In every divergent unit the TOP row agrees | ||
| 155 | + (`row0=[17,17,16,16]` vs oracle `17,17,16,16`) and the difference is in the | ||
| 156 | + left column's lower entries — e.g. px(108,24) col0 oracle `17,11,3,32` vs | ||
| 157 | + ours `17,11,3,29`; px(112,24) oracle `16,14,7,32` vs ours `16,14,9,24`. The | ||
| 158 | + first three left samples agree, the last one(s) do not. | ||
| 159 | +4. The affected units are TU rows 2 and 3 of 4x16/16x8 chroma blocks in | ||
| 160 | + `decode_rect_split`'s lossless per-4x4 walk | ||
| 161 | + (`RECT_SPLIT_LOSSLESS_CHROMA444_HITS`): row_off 0/1 match, row_off 2/3 do | ||
| 162 | + not, in every block of the band. | ||
| 163 | + | ||
| 164 | +### Where that points, and what is still open | ||
| 165 | + | ||
| 166 | +The first divergent unit is the third TU row of the leftmost block of the band | ||
| 167 | +(chroma x=108..111, y=24..31), and its only disagreeing input is the BOTTOM | ||
| 168 | +left-edge sample — i.e. a reconstructed pixel from the block to its left at | ||
| 169 | +(x=107, y=27). Everything above and to the left of that agrees, the residual | ||
| 170 | +is zero, and the mode is per-block (one symbol, shared by all four TU rows). | ||
| 171 | +So the open question is narrow and answerable with the next probe: **which | ||
| 172 | +source our lossless 4x4 chroma walk feeds the TU rows below the first as their | ||
| 173 | +`above`/`left` edge** — the reconstructed rows inside the block, or a stale / | ||
| 174 | +wrongly-anchored neighbour column. Two concrete next steps, both cheap: | ||
| 175 | +(a) dump the reconstructed left column and above row the walk hands to | ||
| 176 | +`read_plane` for px(108,24) on both sides (`push_intra`'s edge gather is where | ||
| 177 | +the divergence must show up), and (b) re-check the same comparison with the | ||
| 178 | +walk's `span_x/span_y` reach for rows > 0 — the `lane-av1-llband` note in that | ||
| 179 | +walk already records one span/step bug at 4:4:4 (the 8-px 4:2:0 step), so a | ||
| 180 | +second, row-dependent one in the same walk is the most likely home. | ||
| 181 | + | ||
| 182 | +Not fixed, deliberately: the root is not bounded to a named line yet, and | ||
| 183 | +guessing would have burned the lane's remaining budget without a measurement. | ||
| 184 | + | ||
| 185 | +### Rung gaps found (worth a follow-up lane, not fixed here) | ||
| 186 | + | ||
| 187 | +- Our `OUR_PRED` rung (decode.rs ~19390 / ~19530) carries no PLANE field — | ||
| 188 | + `PlaneBuf::reconstruct*` does not know it — so a per-unit prediction diff | ||
| 189 | + has to disambiguate U from V by value matching. The oracle's `EC_PREDOUT8` | ||
| 190 | + has the same gap the other way: it prints `sum/row0/col0` but NOT the mode for | ||
| 191 | + non-directional 8-bit units (`EC_PREDND` prints the mode but is HBD-only), so | ||
| 192 | + a directional/non-directional disagreement is currently only inferable. | ||
| 193 | +- A temporary plane-tagged `OUR_MODE` rung in `read_plane` was used for this | ||
| 194 | + analysis and removed before the commit; it is a 6-line addition worth landing | ||
| 195 | + in a follow-up. | ||
| 196 | + | ||
| 197 | +## Not run here (Main's validation) | ||
| 198 | + | ||
| 199 | +Full suite, the 32-attempt `…16_level_rect_leaf…` sweep, the 4:2:0/10-bit/12-bit | ||
| 200 | +sweep families, and the server stages. Local runs were single named tests only, per | ||
| 201 | +the lane's local-scope rule. | ||