An inter block's chroma tx_type is the colocated luma type NARROWED to the chroma size's ext-tx set, not DCT_DCT at every side >= 32
Browse files at this commit555df44328181b04f53dde8f73daca15423dd764Parent: d5f333b- fix
- an inter block's chroma tx_type is the colocated luma type NARROWED to the chroma size's ext-tx set, not DCT_DCT at every side >= 32
3 changed files +185 -8
- crates/ec-av1/src/decode.rs +76 -8
- crates/ec-av1/src/stream.rs +13 -0
- lanes/golomb-r7.report.md +96 -0
crates/ec-av1/src/decode.rsmodified+76 -8
| @@ -11750,8 +11750,8 @@ fn read_inter_plane_rect( | |||
| 11750 | // `av1_get_ext_tx_set_type`'s DCT-only clamp is on `tx_size_sqr_up`, i.e. | 11750 | // `av1_get_ext_tx_set_type`'s DCT-only clamp is on `tx_size_sqr_up`, i.e. |
| 11751 | // the *longer* side of this rect transform. | 11751 | // the *longer* side of this rect transform. |
| 11752 | let default_tx_type = match inherited_luma_tx_type { | 11752 | let default_tx_type = match inherited_luma_tx_type { |
| 11753 | - Some(t) if w.max(h) < 32 => t, | 11753 | + Some(t) => reduce_inherited_chroma_tx_type(t, w, h), |
| 11754 | - _ => TxType::DctDct, | 11754 | + None => TxType::DctDct, |
| 11755 | }; | 11755 | }; |
| 11756 | // lane-r14 r2: a 64-length axis codes only its low 32 coefficients | 11756 | // lane-r14 r2: a 64-length axis codes only its low 32 coefficients |
| 11757 | // (`av1_get_max_eob`), so the coded unit is the `min(w,32) x min(h,32)` | 11757 | // (`av1_get_max_eob`), so the coded unit is the `min(w,32) x min(h,32)` |
| @@ -11918,6 +11918,45 @@ fn read_inter_luma8( | |||
| 11918 | 11918 | ||
| 11919 | /// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its | 11919 | /// The [`TxbSet`] one leaf of an inter block's var-tx tree reads its |
| 11920 | /// coefficient tables from -- the inter counterpart of [`txbset_for`]. | 11920 | /// coefficient tables from -- the inter counterpart of [`txbset_for`]. |
| 11921 | +/// `av1_get_tx_type`'s chroma tail (libaom `av1/common/blockd.h:1291-1305`): | ||
| 11922 | +/// an inter block's chroma transform inherits the *colocated luma* unit's | ||
| 11923 | +/// coded `tx_type`, then drops back to `DCT_DCT` unless that type is a member | ||
| 11924 | +/// of the extended set the CHROMA transform size selects | ||
| 11925 | +/// (`av1_ext_tx_used[av1_get_ext_tx_set_type(uv_tx, 1, reduced)][tx_type]`, | ||
| 11926 | +/// `blockd.h:1036`/`1097`). lane-golomb r7: we used to force `DCT_DCT` at | ||
| 11927 | +/// every chroma side >= 32, but `av1_get_ext_tx_set_type`'s DCT-only rung is | ||
| 11928 | +/// `tx_size_sqr_up > TX_32X32`; at exactly TX_32X32 an inter block reads | ||
| 11929 | +/// `EXT_TX_SET_DCT_IDTX`, so a 64x64 inter block whose first luma leaf coded | ||
| 11930 | +/// `IDTX` inherits IDTX on its 32x32 chroma units. `IDTX` and `DCT_DCT` are | ||
| 11931 | +/// both `TX_CLASS_2D`, so that mistake left the entropy stream perfectly in | ||
| 11932 | +/// sync and only corrupted the inverse transform (one 64x64 superblock of | ||
| 11933 | +/// high-frequency chroma noise, luma bit-exact). | ||
| 11934 | +fn reduce_inherited_chroma_tx_type(t: TxType, w: usize, h: usize) -> TxType { | ||
| 11935 | + use TxType::*; | ||
| 11936 | + let sqr_up = w.max(h); | ||
| 11937 | + let sqr = w.min(h); | ||
| 11938 | + let reduced = REDUCED_TX_SET_INTER.with(std::cell::Cell::get); | ||
| 11939 | + // `av1_get_ext_tx_set_type(tx_size, is_inter = 1, reduced)`. | ||
| 11940 | + let allowed: &[TxType] = if sqr_up > 32 { | ||
| 11941 | + // EXT_TX_SET_DCTONLY | ||
| 11942 | + &[DctDct] | ||
| 11943 | + } else if sqr_up == 32 || reduced { | ||
| 11944 | + // EXT_TX_SET_DCT_IDTX | ||
| 11945 | + &[DctDct, Idtx] | ||
| 11946 | + } else if sqr == 16 { | ||
| 11947 | + // EXT_TX_SET_DTT9_IDTX_1DDCT -- TX_TYPES 0..=11, i.e. everything but | ||
| 11948 | + // the four 1D ADST/FLIPADST types. | ||
| 11949 | + &[ | ||
| 11950 | + DctDct, AdstDct, DctAdst, AdstAdst, FlipAdstDct, DctFlipAdst, FlipAdstFlipAdst, | ||
| 11951 | + AdstFlipAdst, FlipAdstAdst, Idtx, VDct, HDct, | ||
| 11952 | + ] | ||
| 11953 | + } else { | ||
| 11954 | + // EXT_TX_SET_ALL16 | ||
| 11955 | + return t; | ||
| 11956 | + }; | ||
| 11957 | + if allowed.contains(&t) { t } else { DctDct } | ||
| 11958 | +} | ||
| 11959 | + | ||
| 11921 | fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet { | 11960 | fn inter_txbset_for(tx_px: usize, reduced_tx_set: bool) -> TxbSet { |
| 11922 | match tx_px { | 11961 | match tx_px { |
| 11923 | 32 => TxbSet::Luma32Inter, | 11962 | 32 => TxbSet::Luma32Inter, |
| @@ -14972,10 +15011,9 @@ fn read_inter_plane( | |||
| 14972 | // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's | 15011 | // `tx_type` -- `av1_get_tx_type` (libaom `blockd.h`): an inter block's |
| 14973 | // chroma plane never codes its own `tx_type` symbol, but (unlike an | 15012 | // chroma plane never codes its own `tx_type` symbol, but (unlike an |
| 14974 | // intra block, which falls back to `Intra_Mode_To_Tx_Type`) it inherits | 15013 | // intra block, which falls back to `Intra_Mode_To_Tx_Type`) it inherits |
| 14975 | - // the colocated luma transform's coded type verbatim, clamped back to | 15014 | + // the colocated luma transform's coded type, narrowed to the extended |
| 14976 | - // `DCT_DCT` at the chroma tx sizes the spec forces DCT-only | 15015 | + // set the CHROMA size selects ([`reduce_inherited_chroma_tx_type`]). |
| 14977 | - // (`av1_get_ext_tx_set_type`: `tx_size_sqr_up >= TX_32X32`, i.e. this | 15016 | + // `None` for the luma call itself |
| 14978 | - // function's own `side >= 32`). `None` for the luma call itself | ||
| 14979 | // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true | 15017 | // (`plane_idx == 0`), where the `TxbSet`'s own symbol (or the true |
| 14980 | // `DCT_DCT` default at 32-point+) already resolves it without help. | 15018 | // `DCT_DCT` default at 32-point+) already resolves it without help. |
| 14981 | inherited_luma_tx_type: Option<TxType>, | 15019 | inherited_luma_tx_type: Option<TxType>, |
| @@ -14993,8 +15031,8 @@ fn read_inter_plane( | |||
| 14993 | }; | 15031 | }; |
| 14994 | let mut coding = cdfs.txb(set, tx_mode); | 15032 | let mut coding = cdfs.txb(set, tx_mode); |
| 14995 | let default_tx_type = match inherited_luma_tx_type { | 15033 | let default_tx_type = match inherited_luma_tx_type { |
| 14996 | - Some(t) if side < 32 => t, | 15034 | + Some(t) => reduce_inherited_chroma_tx_type(t, side, side), |
| 14997 | - _ => TxType::DctDct, | 15035 | + None => TxType::DctDct, |
| 14998 | }; | 15036 | }; |
| 14999 | let (grid, tx_type) = read_coeffs( | 15037 | let (grid, tx_type) = read_coeffs( |
| 15000 | dec, | 15038 | dec, |
| @@ -22472,6 +22510,36 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs( | |||
| 22472 | #[cfg(test)] | 22510 | #[cfg(test)] |
| 22473 | mod tests { | 22511 | mod tests { |
| 22474 | 22512 | ||
| 22513 | + /// lane-golomb r7: [`reduce_inherited_chroma_tx_type`] must reproduce | ||
| 22514 | + /// `av1_ext_tx_used[av1_get_ext_tx_set_type(uv_tx, 1, reduced)]` | ||
| 22515 | + /// (libaom `av1/common/blockd.h:1036`/`1097`) exactly -- the g35 residue | ||
| 22516 | + /// was one 64x64 inter superblock whose 32x32 chroma units are | ||
| 22517 | + /// `EXT_TX_SET_DCT_IDTX`, where IDTX survives and we forced `DCT_DCT`. | ||
| 22518 | + #[test] | ||
| 22519 | + fn an_inter_chroma_transform_narrows_its_inherited_tx_type_to_its_own_set() { | ||
| 22520 | + use TxType::*; | ||
| 22521 | + // EXT_TX_SET_DCTONLY: `tx_size_sqr_up > TX_32X32`. | ||
| 22522 | + set_inter_tx_mode(true, false, true); | ||
| 22523 | + assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 64, 64), DctDct); | ||
| 22524 | + // EXT_TX_SET_DCT_IDTX at exactly TX_32X32 -- the residue's case. | ||
| 22525 | + assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 32, 32), Idtx); | ||
| 22526 | + assert_eq!(reduce_inherited_chroma_tx_type(AdstAdst, 32, 32), DctDct); | ||
| 22527 | + // EXT_TX_SET_DTT9_IDTX_1DDCT at `tx_size_sqr == TX_16X16`: the four | ||
| 22528 | + // 1D ADST/FLIPADST types (TX_TYPES 12..15) drop out, the rest stay. | ||
| 22529 | + assert_eq!(reduce_inherited_chroma_tx_type(HDct, 16, 16), HDct); | ||
| 22530 | + assert_eq!(reduce_inherited_chroma_tx_type(FlipAdstAdst, 16, 16), FlipAdstAdst); | ||
| 22531 | + assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 16, 16), DctDct); | ||
| 22532 | + // EXT_TX_SET_ALL16 below that (`tx_size_sqr < TX_16X16`, so a 16x8 | ||
| 22533 | + // chroma unit too). | ||
| 22534 | + assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 16, 8), HAdst); | ||
| 22535 | + assert_eq!(reduce_inherited_chroma_tx_type(VFlipAdst, 8, 8), VFlipAdst); | ||
| 22536 | + // `reduced_tx_set` collapses every inter set to DCT_IDTX. | ||
| 22537 | + set_inter_tx_mode(true, true, true); | ||
| 22538 | + assert_eq!(reduce_inherited_chroma_tx_type(Idtx, 8, 8), Idtx); | ||
| 22539 | + assert_eq!(reduce_inherited_chroma_tx_type(HAdst, 8, 8), DctDct); | ||
| 22540 | + set_inter_tx_mode(true, false, true); | ||
| 22541 | + } | ||
| 22542 | + | ||
| 22475 | /// lane-fistrip r1 (class `enumerate-the-table-domain`): every block | 22543 | /// lane-fistrip r1 (class `enumerate-the-table-domain`): every block |
| 22476 | /// shape this decoder can hand [`filter_intra_size_class_rect`], against | 22544 | /// shape this decoder can hand [`filter_intra_size_class_rect`], against |
| 22477 | /// `av1_filter_intra_allowed_bsize` (`block_size_wide <= 32 && | 22545 | /// `av1_filter_intra_allowed_bsize` (`block_size_wide <= 32 && |
crates/ec-av1/src/stream.rsmodified+13 -0
| @@ -18439,6 +18439,19 @@ mod tests { | |||
| 18439 | // The inter arm: >= 4 frames so the 32-level edge path in the INTER | 18439 | // The inter arm: >= 4 frames so the 32-level edge path in the INTER |
| 18440 | // tile walk is exercised too. | 18440 | // tile walk is exercised too. |
| 18441 | arms.push((192, 80, 5, false)); | 18441 | arms.push((192, 80, 5, false)); |
| 18442 | + // lane-golomb r7 MEASURED, arm NOT added (it would be vacuous or red): | ||
| 18443 | + // a 68-px axis leaves the last superblock straddling by 4 px, the | ||
| 18444 | + // shape `read_var_tx_size`'s `blk_row >= max_h_mi || blk_col >= | ||
| 18445 | + // max_w_mi` early return exists for. With | ||
| 18446 | + // `arms.push((192, 68, 5, false))` all EIGHT cq attempts refuse by | ||
| 18447 | + // name -- "a reference picture whose height does not match this | ||
| 18448 | + // frame's own true size" -- so the arm compares nothing (class | ||
| 18449 | + // `counter-from-refused-stream`). With | ||
| 18450 | + // `arms.push((68, 192, 5, false))` the gate goes RED on a real, | ||
| 18451 | + // separate defect: `68x192 cq35 frames=5 10bit=false frame 1 plane Y: | ||
| 18452 | + // 141 pixels differ, first at row 0 col 64 (ours 167 vs ffmpeg 166) | ||
| 18453 | + // [edge32=[0,34,0,0,1,17,0,1]]` -- LUMA, inside the 4-px straddling | ||
| 18454 | + // COLUMN. Both are unrelated to this round's chroma tx_type fix. | ||
| 18442 | let cqs: [u32; 8] = [35, 40, 45, 50, 55, 57, 59, 61]; | 18455 | let cqs: [u32; 8] = [35, 40, 45, 50, 55, 57, 59, 61]; |
| 18443 | let mut totals = [0usize; 8]; | 18456 | let mut totals = [0usize; 8]; |
| 18444 | let mut compared = 0usize; | 18457 | let mut compared = 0usize; |
lanes/golomb-r7.report.mdadded+96 -0
| @@ -0,0 +1,96 @@ | |||
| 1 | +# lane-golomb r7 REPORT -- GREEN (the r6 chroma residue is closed at its root cause) | ||
| 2 | + | ||
| 3 | +## What changed | ||
| 4 | +* `crates/ec-av1/src/decode.rs` -- new `fn reduce_inherited_chroma_tx_type(t, w, h)` | ||
| 5 | + (inserted just above `fn inter_txbset_for`), and both inter-chroma callers now use it: | ||
| 6 | + * `read_inter_plane_rect`'s `default_tx_type` (was `Some(t) if w.max(h) < 32 => t`) | ||
| 7 | + * `read_inter_plane`'s `default_tx_type` (was `Some(t) if side < 32 => t`) | ||
| 8 | + Those two are the ONLY sites in the crate that derive a chroma `tx_type` for an INTER | ||
| 9 | + block (`rg inherited_luma_tx_type`); the intra chroma sites (`decode.rs:6056`, `9195`) | ||
| 10 | + take `default_intra_tx_type` and are already correct -- every value that table can | ||
| 11 | + produce is a member of both intra sets below 32, and both already force `DCT_DCT` at | ||
| 12 | + `>= 32`, which for INTRA is right (`av1_get_ext_tx_set_type` returns `EXT_TX_SET_DCTONLY` | ||
| 13 | + for intra at `tx_size_sqr_up == TX_32X32`). | ||
| 14 | +* `crates/ec-av1/src/decode.rs` -- new unit test | ||
| 15 | + `decode::tests::an_inter_chroma_transform_narrows_its_inherited_tx_type_to_its_own_set`. | ||
| 16 | +* `crates/ec-av1/src/stream.rs` -- comment only: the measured reason the 192x68 / 68x192 | ||
| 17 | + straddling arms are NOT in `edge32_gate` (below). | ||
| 18 | + | ||
| 19 | +## ROOT CAUSE (libaom citation) | ||
| 20 | +`av1_get_tx_type` (`av1/common/blockd.h:1278-1309`) for a chroma plane of an INTER block: | ||
| 21 | +1. `if (txsize_sqr_up_map[tx_size] > TX_32X32) return DCT_DCT;` -- **strictly greater**; | ||
| 22 | +2. `tx_type = xd->tx_type_map[(blk_row << ss_y) * stride + (blk_col << ss_x)]` -- the | ||
| 23 | + colocated luma unit's coded type (for a chroma unit at (0,0), the FIRST var-tx leaf); | ||
| 24 | +3. `if (!av1_ext_tx_used[av1_get_ext_tx_set_type(tx_size, 1, reduced)][tx_type]) | ||
| 25 | + tx_type = DCT_DCT;` -- narrowed by the set the **chroma** size selects | ||
| 26 | + (`av1_ext_tx_used` `blockd.h:1036`, `av1_get_ext_tx_set_type` `blockd.h:1097`). | ||
| 27 | + | ||
| 28 | +We had step 1 as `chroma side >= 32 -> DCT_DCT` and no step 3 at all. At exactly | ||
| 29 | +`TX_32X32` an inter block reads `EXT_TX_SET_DCT_IDTX`, which **contains IDTX**. So a | ||
| 30 | +64x64 inter superblock, whose chroma units are 32x32 (`av1_get_max_uv_txsize(BLOCK_64X64)`), | ||
| 31 | +whose first luma var-tx leaf coded `IDTX`, must inverse-transform its chroma with IDTX -- | ||
| 32 | +we used DCT_DCT. | ||
| 33 | + | ||
| 34 | +`IDTX` and `DCT_DCT` are both `TX_CLASS_2D`: same scan, same coefficient contexts, same | ||
| 35 | +msac ranges. That is why the whole stream stayed in entropy sync and only one superblock | ||
| 36 | +of chroma came out as high-frequency noise with luma bit-exact -- the r6 handoff's exact | ||
| 37 | +signature. (Class for the ledger: a tx_type set-membership bug is invisible to every | ||
| 38 | +range ladder; only pixels see it.) | ||
| 39 | + | ||
| 40 | +The old rule was also wrong the other way for chroma 16x16 under 8x8 luma leaves | ||
| 41 | +(`EXT_TX_SET_DTT9_IDTX_1DDCT` excludes V_ADST/H_ADST/V_FLIPADST/H_FLIPADST, which we would | ||
| 42 | +have inherited verbatim). The new helper covers all four sets. | ||
| 43 | + | ||
| 44 | +## Localization (how the tx_type was identified, no aomdec rebuild) | ||
| 45 | +`EC_TRACE_MODE=1 EC_TRACE_COEFF=1` on `g35.obu` (md5 `9037f5b21db95d35e71f91f040fc33e1`, | ||
| 46 | +`scratchpad/gl-gen.sh 35`), split into frames on `EC_MODE mi_row=0 mi_col=0`: decode-order | ||
| 47 | +picture 4 is segment 4. Its block at `mi(0,16)` (luma x=64,y=0) runs to the next | ||
| 48 | +`EC_MODE mi_row=0 mi_col=32`, i.e. it is a **64x64** block (not 32x32 as r6 recorded), | ||
| 49 | +var-tx split into 16x16 leaves. Its last two coefficient units are | ||
| 50 | +`eob=1022 tx=DctDct` and `eob=1020 tx=DctDct` with `ctx=0` -- eob > 256 proves 32x32 | ||
| 51 | +chroma units -- while its FIRST luma leaf is `eob=254 tx=Idtx`. libaom inherits that | ||
| 52 | +`Idtx`; we produced `DctDct`. | ||
| 53 | + | ||
| 54 | +## Gate | ||
| 55 | +`cargo test -p ec-av1 --lib -- a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition --nocapture` | ||
| 56 | +(under `systemd-run --user --unit=golomb-gate-r7-... -p MemoryMax=10G`, | ||
| 57 | +`EC_AV1_REQUIRE_AOMENC=1`, `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-golomb`) | ||
| 58 | + | ||
| 59 | +BEFORE (r6 handoff): `192x80 cq35 frames=5 10bit=false frame 3 plane U: 978 pixels differ, | ||
| 60 | +first at row 0 col 32 (ours 33 vs ffmpeg 8) [edge32=[0,36,0,0,0,18,0,0]]`. | ||
| 61 | +AFTER: `ok` -- 5 arms x cq {35,40,45,50,55,57,59,61}, 8-bit and 10-bit, | ||
| 62 | +`38 pixel-exact attempts, 32-level edge bits [horz_or_vert=0 split=394], 64-level edge | ||
| 63 | +bits [horz_or_vert=7 split=197] right-VERT=7, 2 named refusals` (both the inter SB-level | ||
| 64 | +AB partition another lane owns). | ||
| 65 | + | ||
| 66 | +EVIDENCE: $HOME/.cache/golomb-gate-r7.log | cargo test -- a_real_aomenc_stream_with_a_32x32_frame_edge_rect_partition --nocapture, 40 aomenc encodes decoded and compared plane-by-plane vs ffmpeg | 38/38 compared attempts pixel-exact, 0 differing pixels (was 978 U pixels on the 192x80 cq35 5-frame arm) | ||
| 67 | +EVIDENCE: $HOME/.cache/golomb-gate-r7b.log | same gate + arms (192,68,5) and (68,192,5) | 68x192 cq35 frame 1 plane Y 141 px differ first at row 0 col 64 -- separate OPEN defect, arm not kept | ||
| 68 | +EVIDENCE: scratchpad/r7-ours.err | EC_TRACE_MODE=1 EC_TRACE_COEFF=1 decode_probe g35.obu, segment 4, block mi(0,16) | first luma leaf tx=Idtx, the two 32x32 chroma units (eob 1022/1020) took tx=DctDct | ||
| 69 | + | ||
| 70 | +Unit check: `cargo test -p ec-av1 --lib -- an_inter_chroma_transform_narrows` => `ok. 1 passed`. | ||
| 71 | + | ||
| 72 | +## Refusals lifted | ||
| 73 | +None this round -- this is a wrong-pixels fix, not a refusal lift. `refusal_inventory` / | ||
| 74 | +`gate_coverage` untouched. | ||
| 75 | + | ||
| 76 | +## The 192x68 / 68x192 straddling arm (r3 verifier ask) -- NOT ADDED, measured why | ||
| 77 | +* `(192, 68, 5, false)`: all EIGHT cq attempts refuse by name, `a reference picture whose | ||
| 78 | + height does not match this frame's own true size` -> the arm compares nothing (vacuous, | ||
| 79 | + class `counter-from-refused-stream`). | ||
| 80 | +* `(68, 192, 5, false)`: RED on a real separate defect -- | ||
| 81 | + `68x192 cq35 frames=5 10bit=false frame 1 plane Y: 141 pixels differ, first at row 0 | ||
| 82 | + col 64 (ours 167 vs ffmpeg 166) [edge32=[0,34,0,0,1,17,0,1]]`. LUMA, inside the 4-px | ||
| 83 | + straddling COLUMN; the straddling ROW twin (192x68) never gets that far. | ||
| 84 | + disposition: deferred(the right-edge straddling-column luma defect above, and the | ||
| 85 | + reference-size refusal) -- both are outside this lane's chroma tx_type cause. | ||
| 86 | + | ||
| 87 | +## Test totals | ||
| 88 | +`$HOME/.cache/golomb-suite-r7.log` (unit `golomb-suite-r7`) -- see the `test result:` line. | ||
| 89 | +NOTE: `$HOME/.cache/golomb-suite-r6.log` never produced a `test result:` line: it was still | ||
| 90 | +`active` (254/404 tests, stuck in the long superres/encoder tests) and holding | ||
| 91 | +`CARGO_TARGET_DIR`, so it was stopped -- it was measuring the PRE-fix tree and is superseded | ||
| 92 | +by r7. Every `test` line it did produce was `ok` or a documented `ignored`. | ||
| 93 | + | ||
| 94 | +## Open / residue | ||
| 95 | +* `main` has advanced to `85887c7` (we merged `18bf7dc`); this branch is NOT re-merged. | ||
| 96 | +* the two defects the 68-px arms found (above), deferred. | ||