forge
Explore
Log in

Don't you dare go Hollow

A sub-8x8 inter group's chroma inherits the CHROMA-REFERENCE sub-block's tx_type, not the first sub-block's

Browse files at this commit

3898141691caa34dc40829ee092112e202afebe6Ahmet Kaan GümüşParent: 873b00a
  • fix
    • a sub-8x8 inter group's chroma inherits the CHROMA-REFERENCE sub-block's tx_type, not the first sub-block's
Show full message
fix(av1): a sub-8x8 inter group's chroma inherits the CHROMA-REFERENCE sub-block's tx_type, not the first sub-block's

`av1_get_tx_type` (libaom `av1/common/blockd.h:1291-1305`) scales the chroma
transform's `blk_row`/`blk_col` back by the subsampling and indexes
`xd->tx_type_map` -- which `set_mi_offsets` (`av1_common_int.h:1679`) re-points
to the CURRENT sub-block's mi. For a sub-8x8 group the current block at the
chroma read is the chroma-reference (last) sub-block, so the group's one 4x4
chroma unit per plane inherits THAT sub-block's first transform unit's
tx_type. Both sub-8x8 inter paths took the group's FIRST sub-block instead.

No chroma tx_type symbol is coded, so the entropy stream stayed perfectly in
sync and the defect only inverted a chroma unit on the wrong basis: on the
10-bit 1920x792 128-superblock stream, decode-order frame 14 differed in
exactly 14 U pixels inside one aligned 4x4 chroma TU (V exact -- its unit was
all_zero), where instrumented aomdec reads tx_type=7 (ADST_FLIPADST, the
bottom 8x4 sub-block's own) and we read DCT_DCT (the top 8x4 sub-block was
skip).

New counter `sub8_chroma_tx_from_ref_hits` counts the groups that tell the two
rules apart: chroma-reference tx_type != first sub-block's AND the chroma unit
codes coefficients. The 128-SB witness fixture is extended from 19 to 23
frame-carrying OBUs (14 -> 16 decode-order frames, 12 -> 15 shown, 177773
bytes, sha256 09d995946d27695ef4b7b1a24a4d7ad85f8e2c8176d58ee54e825efc061f9cbc,
two independent cuts hash identically) so the gate covers frame 14, and it
hard-asserts the new counter (2 hits) alongside the eight it already had.
crates/ec-av1/examples/decode_probe.rsmodified+4 -0
@@ -118,6 +118,10 @@ fn main() {
118118 );
119119 // lane-rectres r1: how many of those 32x8/8x32 strips coded a real
120120 // rectangular residual transform unit (a skipped one codes none).
121+ println!(
122+ "sub8_chroma_tx_from_ref: {}",
123+ ec_av1::stream::sub8_chroma_tx_from_ref_hits()
124+ );
121125 let r328 = ec_av1::stream::rect32x8_inter_tu_hits();
122126 println!("rect32x8_inter_tu: 32x8={} 8x32={}", r328[0], r328[1]);
123127 // lane-intra16x4: INTRA strips of an inter 16x16-level 1:4 partition.
crates/ec-av1/fixtures/reelc_sb128_inter_witness.obumodified+0 -0

Binary file changed

crates/ec-av1/src/decode.rsmodified+62 -19
@@ -3318,6 +3318,29 @@ pub fn sub8_inter_split_hits() -> usize {
33183318 SUB8_INTER_SPLIT_HITS.with(|c| c.get())
33193319 }
33203320
3321+// lane-t900 r7: sub-8x8 inter groups whose one chroma unit inherits a
3322+// `tx_type` DIFFERENT from the group's FIRST sub-block -- the only shape that
3323+// tells the two rules apart (`av1_get_tx_type` indexes `xd->tx_type_map`,
3324+// which `set_mi_offsets` re-points to the CHROMA-REFERENCE sub-block, so the
3325+// first sub-block's type is never the one). Reading it off sub-block 0
3326+// inverted one 4x4 chroma unit on the wrong basis with the entropy stream
3327+// perfectly in sync (no chroma `tx_type` symbol is coded), so a gate can only
3328+// see this rule through this counter.
3329+thread_local! {
3330+ static SUB8_CHROMA_TX_FROM_REF_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
3331+}
3332+
3333+/// Current value of `SUB8_CHROMA_TX_FROM_REF_HITS`.
3334+pub fn sub8_chroma_tx_from_ref_hits() -> usize {
3335+ SUB8_CHROMA_TX_FROM_REF_HITS.with(|c| c.get())
3336+}
3337+
3338+fn note_sub8_chroma_tx(first_sub: TxType, chroma_ref: TxType, coeffs: bool) {
3339+ if coeffs && first_sub != chroma_ref {
3340+ SUB8_CHROMA_TX_FROM_REF_HITS.with(|c| c.set(c.get() + 1));
3341+ }
3342+}
3343+
33213344 // How many 4x8 / 8x4 leaves (lane-tx4x8's `PARTITION_VERT`/`PARTITION_HORZ`
33223345 // of an 8x8 block) this thread's decode reconstructed with REAL coefficients
33233346 // -- a skipped leaf exercises the prediction and the mi bookkeeping but never
@@ -14668,6 +14691,9 @@ fn read_inter_plane_rect(
1466814691 ac_delta,
1466914692 tx_type,
1467014693 );
14694+ if std::env::var_os("EC_TRACE_TXTYPE").is_some() {
14695+ eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} w={w} h={h} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}");
14696+ }
1467114697 // `reconstruct_mc_rect` reads both buffers at the square prediction
1467214698 // stride, so the dense `w x h` residual is re-laid at that stride first.
1467314699 let mut strided = vec![0i32; stride * stride];
@@ -18449,6 +18475,9 @@ fn read_inter_plane(
1844918475 None,
1845018476 )?;
1845118477 note_chroma_class1(plane_idx, tx_type);
18478+ if std::env::var_os("EC_TRACE_TXTYPE").is_some() {
18479+ eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} side={side} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}");
18480+ }
1845218481 // lane-inter8 r1: a 64-point transform covers the whole 64x64 area but
1845318482 // codes only its top-left 32x32 of frequencies (spec 5.11.40) -- the
1845418483 // caller hands the 32-point `scan` there, and the coded corner goes into
@@ -22451,10 +22480,11 @@ fn decode_inter_block(
2245122480 // lane-t900 r6: THAT WITNESS EXISTS, so `EC_INTRA16X4_DECODE` is gone
2245222481 // and the refusal is narrowed back to "no chroma-pair record". The
2245322482 // witness is a REAL 10-bit 1920x792 128-superblock film stream, not an
22454- // aomenc recipe: `fixtures/reelc_sb128_inter_witness.obu` (166303 bytes,
22455- // 19 frame-carrying OBUs, 14 decode-order frames) decodes all 14
22456- // decode-order frames byte-exact against instrumented aomdec
22457- // (`EC_AV1_FINAL_DUMP`) and all 12 shown frames pixel-exact against
22483+ // aomenc recipe: `fixtures/reelc_sb128_inter_witness.obu` (177773 bytes,
22484+ // 23 frame-carrying OBUs, 16 decode-order frames, extended from 14 in
22485+ // lane-t900 r7) decodes all 16 decode-order frames byte-exact against
22486+ // instrumented aomdec
22487+ // (`EC_AV1_FINAL_DUMP`) and all 15 shown frames pixel-exact against
2245822488 // ffmpeg, while this arm fires 78x 16x4 + 149x 4x16 (108 of them
2245922489 // chroma-paired). Unlike lane-sub8x4 r3's phantom (class
2246022490 // `counter-from-refused-stream`) every one of those hits lies inside a
@@ -23282,6 +23312,7 @@ fn decode_inter_sub8_split4(
2328223312 let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 4] =
2328323313 [None; 4];
2328423314 let mut first_tx_type = TxType::DctDct;
23315+ let mut sub0_tx_type = TxType::DctDct;
2328523316 let mut last_skip = true;
2328623317 // Set when the chroma-reference (last) sub-block is INTRA: it coded the
2328723318 // group's one chroma unit itself.
@@ -23576,14 +23607,19 @@ fn decode_inter_sub8_split4(
2357623607 None,
2357723608 None,
2357823609 )?;
23579- if i == 0 || piece[0].is_none() {
23580- // `av1_get_tx_type`: an inter block's chroma inherits the
23581- // tx_type of the CO-LOCATED luma position, which for the
23582- // group's one chroma unit is luma (0, 0) -- the FIRST
23583- // sub-block, not the last. lane-sub8intra: an INTRA first
23584- // sub-block writes no inter tx_type there at all, so the
23585- // later inter sub-blocks' own is what `xd->tx_type_map`
23586- // holds.
23610+ if i == 0 {
23611+ sub0_tx_type = tx_type;
23612+ }
23613+ if i == 3 {
23614+ // `av1_get_tx_type`'s chroma tail scales `blk_row`/`blk_col`
23615+ // back by the subsampling, but it indexes `xd->tx_type_map`,
23616+ // which `set_mi_offsets` (av1_common_int.h:1679) re-points to
23617+ // the CURRENT sub-block's own mi -- so the group's one chroma
23618+ // unit inherits the CHROMA-REFERENCE (last) sub-block's
23619+ // tx_type, never the group's first. lane-t900 r7: reading it
23620+ // off sub-block 0 left the entropy stream in sync (no symbol
23621+ // is coded for chroma) and inverted one 4x4 chroma unit on the
23622+ // wrong basis.
2358723623 first_tx_type = tx_type;
2358823624 }
2358923625 neighbours.record_mi_luma_rect(lmi, B4, B4, &luma_grid);
@@ -23673,6 +23709,8 @@ fn decode_inter_sub8_split4(
2367323709 &pred_v, Some(first_tx_type), None,
2367423710 )?
2367523711 .0;
23712+ let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0);
23713+ note_sub8_chroma_tx(sub0_tx_type, first_tx_type, coded);
2367623714 (ug, vg)
2367723715 };
2367823716 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
@@ -24204,6 +24242,7 @@ fn decode_inter_sub8_rect2(
2420424242 let mut piece: [Option<(i8, (i32, i32), mc::InterpFilterKind, mc::InterpFilterKind)>; 2] =
2420524243 [None; 2];
2420624244 let mut first_tx_type = TxType::DctDct;
24245+ let mut sub0_tx_type = TxType::DctDct;
2420724246 let mut last_skip = true;
2420824247 // Set when the chroma-reference sub-block is INTRA: it coded the group's
2420924248 // one chroma unit itself.
@@ -24552,13 +24591,15 @@ fn decode_inter_sub8_rect2(
2455224591 None,
2455324592 )?
2455424593 };
24555- if idx == 0 && (i == 0 || piece[0].is_none()) {
24556- // `av1_get_tx_type`: the group's one chroma unit scales
24557- // back to luma (0, 0), i.e. the FIRST sub-block's first
24558- // transform unit -- unless that sub-block is INTRA
24559- // (lane-sub8intra), in which case it wrote no inter
24560- // tx_type at all and `xd->tx_type_map[0]` of the
24561- // chroma-reference block is this one's.
24594+ if idx == 0 && i == 0 {
24595+ sub0_tx_type = tu_tx_type;
24596+ }
24597+ if idx == 0 && i == 1 {
24598+ // `av1_get_tx_type` indexes `xd->tx_type_map`, which
24599+ // `set_mi_offsets` (av1_common_int.h:1679) re-points to the
24600+ // CURRENT sub-block: the group's one chroma unit inherits
24601+ // the CHROMA-REFERENCE (second) sub-block's first transform
24602+ // unit, never the first sub-block's (lane-t900 r7).
2456224603 first_tx_type = tu_tx_type;
2456324604 }
2456424605 neighbours.record_mi_luma_rect(tu_mi, tw, th, &tu_grid);
@@ -24662,6 +24703,8 @@ fn decode_inter_sub8_rect2(
2466224703 &pred_v, Some(first_tx_type), None,
2466324704 )?
2466424705 .0;
24706+ let coded = ug.iter().chain(vg.iter()).any(|&c| c != 0);
24707+ note_sub8_chroma_tx(sub0_tx_type, first_tx_type, coded);
2466524708 (ug, vg)
2466624709 };
2466724710 neighbours.record_uv_mode_mi(gr, gc, 2, 2, DC_PRED);
crates/ec-av1/src/stream.rsmodified+25 -8
@@ -87,6 +87,13 @@ pub fn rect32x8_inter_tu_hits() -> [usize; 2] {
8787 crate::decode::rect32x8_inter_tu_hits()
8888 }
8989
90+/// lane-t900 r7: sub-8x8 inter groups whose one chroma unit inherited a
91+/// `tx_type` different from the group's FIRST sub-block, i.e. groups that can
92+/// only decode right under `av1_get_tx_type`'s chroma-reference rule.
93+pub fn sub8_chroma_tx_from_ref_hits() -> usize {
94+ crate::decode::sub8_chroma_tx_from_ref_hits()
95+}
96+
9097 /// lane-intra16x4: `(16x4, 4x16, chroma-reference)` INTRA strips decoded inside
9198 /// an inter 16x16-level 1:4 partition.
9299 pub fn intra16x4_in_inter_hits() -> (usize, usize, usize) {
@@ -30282,12 +30289,18 @@ mod tests {
3028230289 }
3028330290
3028430291 /// lane-t900 r6: the 128-superblock INTER witness.
30285- /// `crates/ec-av1/fixtures/reelc_sb128_inter_witness.obu`, 166303 bytes,
30286- /// sha256 `1191ce80e2c6c5855eaf7a8f5e8cda2cdf809f467b0dbc5e26df96dfa6b2c8bd`:
30287- /// the first 19 frame-carrying OBUs of a 2 s cut taken 900 s into a 10-bit
30288- /// 1920x792 AV1 stream with `use_128x128_superblock=1`, 14 decode-order
30289- /// frames, 12 shown. Cut twice independently from the source (`-ss 900 -t 2
30292+ /// `crates/ec-av1/fixtures/reelc_sb128_inter_witness.obu`, 177773 bytes,
30293+ /// sha256 `09d995946d27695ef4b7b1a24a4d7ad85f8e2c8176d58ee54e825efc061f9cbc`:
30294+ /// the first 23 frame-carrying OBUs of a 2 s cut taken 900 s into a 10-bit
30295+ /// 1920x792 AV1 stream with `use_128x128_superblock=1`, 16 decode-order
30296+ /// frames, 15 shown. Cut twice independently from the source (`-ss 900 -t 2
3029030297 /// -c:v copy` then the OBU truncation) -- both cuts hash identically.
30298+ /// lane-t900 r7 extended it from 19 OBUs / 14 frames: decode-order frame 14
30299+ /// is the ONLY frame in this repository's fixtures whose sub-8x8 inter
30300+ /// chroma inherits a `tx_type` from a chroma-reference sub-block that
30301+ /// differs from its group's first sub-block AND codes coefficients
30302+ /// (`sub8_chroma_tx_from_ref_hits`), i.e. the only frame that can tell
30303+ /// `av1_get_tx_type`'s two candidate rules apart.
3029130304 ///
3029230305 /// It is the first stream in this repository that decodes exactly while
3029330306 /// five separately-found defects' paths all fire, which is why the asserts
@@ -30344,6 +30357,7 @@ mod tests {
3034430357 crate::decode::intra_in_inter_txctx_hits(),
3034530358 crate::decode::edge_filter_mi_fix_hits(),
3034630359 );
30360+ let sub8tx_before = crate::decode::sub8_chroma_tx_from_ref_hits();
3034730361 let i16_before = crate::decode::intra16x4_in_inter_hits();
3034830362 let frames = match decode_stream(&stream) {
3034930363 Ok(frames) => frames,
@@ -30358,6 +30372,7 @@ mod tests {
3035830372 crate::decode::intra_in_inter_txctx_hits() - before.5,
3035930373 crate::decode::edge_filter_mi_fix_hits() - before.6,
3036030374 );
30375+ let sub8tx = crate::decode::sub8_chroma_tx_from_ref_hits() - sub8tx_before;
3036130376 let i16_now = crate::decode::intra16x4_in_inter_hits();
3036230377 let i16 = (
3036330378 i16_now.0 - i16_before.0,
@@ -30375,13 +30390,14 @@ mod tests {
3037530390 ("intra16x4_in_inter 16x4", i16.0),
3037630391 ("intra16x4_in_inter 4x16", i16.1),
3037730392 ("intra16x4_in_inter chroma_ref", i16.2),
30393+ ("sub8_chroma_tx_from_ref", sub8tx),
3037830394 ] {
3037930395 assert!(
3038030396 n > 0,
3038130397 "{NAME}: {what} never fired on this stream -- the gate would be vacuous for it"
3038230398 );
3038330399 }
30384- assert_eq!(frames.len(), 12, "{NAME}: 12 shown frames");
30400+ assert_eq!(frames.len(), 15, "{NAME}: 15 shown frames");
3038530401 assert_eq!((frames[0].width, frames[0].height), (width, height));
3038630402 let ffmpeg_frames = ffmpeg_decode_sequence_10bit(&stream, width, height, frames.len());
3038730403 assert_eq!(
@@ -30397,9 +30413,10 @@ mod tests {
3039730413 assert_eq!(ours.v, theirs.v, "{NAME}: frame {i} V vs ffmpeg");
3039830414 }
3039930415 eprintln!(
30400- "{NAME}: 12 shown frames pixel-exact on every plane; warp_plane_suppress={} \
30416+ "{NAME}: 15 shown frames pixel-exact on every plane; warp_plane_suppress={} \
3040130417 cdef_idx={} inter_sb128_vert={} interintra_rect={} non_chroma_ref_ctx_skip={} \
30402- intra_in_inter_txctx={} edge_filter_mi_fix={} intra16x4_in_inter={:?}",
30418+ intra_in_inter_txctx={} edge_filter_mi_fix={} intra16x4_in_inter={:?} \
30419+ sub8_chroma_tx_from_ref={sub8tx}",
3040330420 fired.0, fired.1, fired.2, fired.3, fired.4, fired.5, fired.6, i16
3040430421 );
3040530422 }