forge
Explore
Log in

Don't you dare go Hollow

ec-av1: thread the real plane index into read_coeffs_rect's EC_COEFF_STEP traces

Browse files at this commit

078957648c3ef2e5dcbbd64c2ef59620d66c56d6Ahmet Kaan GümüşParent: a460dca
read_coeffs_rect printed a hardcoded plane=0 on its two tagged trace lines
(tag=all_zero, tag=tx_type), so every chroma rect coefficient read was
logged as a luma one. Two independent lane reports mis-read a chroma
unit's txb_skip / tx_type symbol on those lines and followed the luma
arm; the log could not tell them apart.

Adds a plane parameter and passes the caller's own plane index at all
twenty call sites (read_inter_plane_rect / read_rect_chroma_unit /
leaf8_chroma422_unit / sub8_leaf_chroma444 carry plane or plane_idx;
the luma readers pass 0). read_chroma_coeffs_rect takes the same
parameter and passes it through, so the U/V call sites in
decode_block_rect, decode_leaf_rect, decode_block_rect4,
decode_rect4_16_strip and decode_block_rect64 stop collapsing U and V
into one tag.

Measurement (EC_TRACE_COEFF=1 on the 4:4:4 rect gate
a_444_lossy_rect4_inter_stream_decodes_pixel_exact): the all_zero lines
now split 312 plane=0 / 310 plane=1 / 310 plane=2 where every chroma
line previously read plane=0. No gate output changes; the traces are
env-gated and off by default.
crates/ec-av1/src/decode.rsmodified+90 -9
@@ -7832,13 +7832,18 @@ fn read_coeffs_rect(
78327832 skip_ctx: usize,
78337833 sign_ctx: usize,
78347834 default_tx_type: TxType,
7835+ // lane-av1chrtx: the plane this unit belongs to (0 luma, 1 U, 2 V) --
7836+ // printed by the two `EC_COEFF_STEP` traces below, which hardcoded
7837+ // `plane=0` and so mis-attributed a CHROMA read as a luma one in two
7838+ // independent lane reports.
7839+ plane: usize,
78357840 ) -> Result<(Grid, TxType)> {
78367841 let rect_trace = coeff_trace_on();
78377842 let entry_rng = dec.debug_state().0;
78387843 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
78397844 if rect_trace {
78407845 eprintln!(
7841- "EC_COEFF_STEP tag=all_zero plane=0 ctx={skip_ctx} entry={entry_rng} all_zero={} rng={}",
7846+ "EC_COEFF_STEP tag=all_zero plane={plane} ctx={skip_ctx} entry={entry_rng} all_zero={} rng={}",
78427847 all_zero as i32,
78437848 dec.debug_state().0
78447849 );
@@ -7864,7 +7869,7 @@ fn read_coeffs_rect(
78647869 })?;
78657870 if rect_trace {
78667871 eprintln!(
7867- "EC_COEFF_STEP tag=tx_type plane=0 rng={}",
7872+ "EC_COEFF_STEP tag=tx_type plane={plane} rng={}",
78687873 dec.debug_state().0
78697874 );
78707875 }
@@ -8076,11 +8081,25 @@ fn read_chroma_coeffs_rect(
80768081 sign_ctx: usize,
80778082 default_tx_type: TxType,
80788083 fctx: &crate::decode::FrameCtx,
8084+ // lane-av1chrtx: the plane index, threaded to `read_coeffs_rect`'s
8085+ // `EC_COEFF_STEP` traces (they used to print a hardcoded `plane=0`, so a
8086+ // V-plane read was indistinguishable from a luma one in the log).
8087+ plane: usize,
80798088 ) -> Result<(Grid, TxType)> {
80808089 if mono(fctx) {
80818090 return Ok((Grid::Zero(w * h), TxType::DctDct));
80828091 }
8083- read_coeffs_rect(dec, coding, scan, w, h, skip_ctx, sign_ctx, default_tx_type)
8092+ read_coeffs_rect(
8093+ dec,
8094+ coding,
8095+ scan,
8096+ w,
8097+ h,
8098+ skip_ctx,
8099+ sign_ctx,
8100+ default_tx_type,
8101+ plane,
8102+ )
80848103 }
80858104
80868105 /// What one coded block leaves behind for the blocks that read it as a
@@ -11537,6 +11556,7 @@ fn decode_rect_split(
1153711556 tu_skip_ctx,
1153811557 dc_sign_ctx(tu_around.2),
1153911558 TxType::DctDct,
11559+ 0,
1154011560 )?;
1154111561 let residual = dequant_and_inverse_typed_wh(
1154211562 &tu_grid,
@@ -11962,6 +11982,7 @@ fn decode_rect_split(
1196211982 skip_ctx,
1196311983 dc_sign_ctx(cu_around[plane_idx].2),
1196411984 default_tx,
11985+ plane_idx,
1196511986 )?;
1196611987 let residual = dequant_and_inverse_typed_wh(
1196711988 &levels,
@@ -12046,6 +12067,7 @@ fn decode_rect_split(
1204612067 skip_ctx,
1204712068 dc_sign_ctx(around[plane_idx].2),
1204812069 default_tx,
12070+ plane_idx,
1204912071 )?;
1205012072 // The same delta_q proof the unsplit rect64 path records
1205112073 // (lane-rectsplit r4: lifting the split-transform refusal moved
@@ -14510,6 +14532,7 @@ fn decode_block_rect(
1451014532 0,
1451114533 dc_sign_ctx(around[0].2),
1451214534 TxType::DctDct,
14535+ 0,
1451314536 )?;
1451414537 if crate::envflags::env_flag!("EC_AV1_TRACE") {
1451514538 let (rng, _) = dec.debug_state();
@@ -14558,6 +14581,7 @@ fn decode_block_rect(
1455814581 dc_sign_ctx(around[1].2),
1455914582 u_default_tx,
1456014583 fctx,
14584+ 1,
1456114585 )?;
1456214586 if crate::envflags::env_flag!("EC_AV1_TRACE") {
1456314587 let (rng, _) = dec.debug_state();
@@ -14605,6 +14629,7 @@ fn decode_block_rect(
1460514629 dc_sign_ctx(around[2].2),
1460614630 v_default_tx,
1460714631 fctx,
14632+ 2,
1460814633 )?;
1460914634 if crate::envflags::env_flag!("EC_AV1_TRACE") {
1461014635 let (rng, _) = dec.debug_state();
@@ -15087,6 +15112,7 @@ fn decode_leaf_rect(
1508715112 0,
1508815113 dc_sign_ctx(around[0].2),
1508915114 TxType::DctDct,
15115+ 0,
1509015116 )?;
1509115117 if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") {
1509215118 let nz: Vec<(usize, i32)> = l_levels
@@ -15141,6 +15167,7 @@ fn decode_leaf_rect(
1514115167 dc_sign_ctx(around[1].2),
1514215168 u_default_tx,
1514315169 fctx,
15170+ 1,
1514415171 )?;
1514515172 u_levels = u_l;
1514615173 let u_residual = dequant_and_inverse_typed_wh(
@@ -15185,6 +15212,7 @@ fn decode_leaf_rect(
1518515212 dc_sign_ctx(around[2].2),
1518615213 v_default_tx,
1518715214 fctx,
15215+ 2,
1518815216 )?;
1518915217 v_levels = v_l;
1519015218 let v_residual = dequant_and_inverse_typed_wh(
@@ -15608,6 +15636,7 @@ fn decode_block_rect4(
1560815636 0,
1560915637 dc_sign_ctx(around[0].2),
1561015638 TxType::DctDct,
15639+ 0,
1561115640 )?;
1561215641 hit!(RECT4_COEFF_HITS);
1561315642 let luma_residual = dequant_and_inverse_typed_wh(
@@ -15758,6 +15787,7 @@ fn decode_block_rect4(
1575815787 0,
1575915788 dc_sign_ctx(around[0].2),
1576015789 TxType::DctDct,
15790+ 0,
1576115791 )?;
1576215792 let mut planes = Vec::with_capacity(2);
1576315793 for plane in 1..3 {
@@ -15783,6 +15813,7 @@ fn decode_block_rect4(
1578315813 dc_sign_ctx(around[plane].2),
1578415814 default_tx,
1578515815 fctx,
15816+ plane,
1578615817 )?;
1578715818 planes.push((levels, tx_type));
1578815819 }
@@ -17313,6 +17344,7 @@ fn decode_rect4_16_strip(
1731317344 tu_skip_ctx,
1731417345 dc_sign_ctx(tu_around.2),
1731517346 TxType::DctDct,
17347+ 0,
1731617348 )?;
1731717349 let residual = dequant_and_inverse_typed_wh(
1731817350 &tu_grid,
@@ -17419,6 +17451,7 @@ fn decode_rect4_16_strip(
1741917451 0,
1742017452 dc_sign_ctx(around.2),
1742117453 TxType::DctDct,
17454+ 0,
1742217455 )?;
1742317456 let residual = dequant_and_inverse_typed_wh(
1742417457 &levels,
@@ -17935,6 +17968,7 @@ fn decode_rect4_16_strip(
1793517968 dc_sign_ctx(around[plane].2),
1793617969 default_tx,
1793717970 fctx,
17971+ plane,
1793817972 )?;
1793917973 planes.push((levels, tx_type));
1794017974 }
@@ -18441,6 +18475,7 @@ fn decode_block_rect64(
1844118475 0,
1844218476 dc_sign_ctx(around[0].2),
1844318477 TxType::DctDct,
18478+ 0,
1844418479 )?
1844518480 };
1844618481 if coeff_trace_on() {
@@ -18596,6 +18631,7 @@ fn decode_block_rect64(
1859618631 dc_sign_ctx(cu_around[plane_idx].2),
1859718632 TxType::DctDct,
1859818633 fctx,
18634+ plane_idx,
1859918635 )?;
1860018636 let residual = dequant_and_inverse_typed_wh(
1860118637 &levels,
@@ -20074,6 +20110,7 @@ fn read_rect_chroma_unit(
2007420110 usize::from(around.0) + usize::from(around.1) + chroma_skip_offset.unwrap_or(0),
2007520111 dc_sign_ctx(around.2),
2007620112 default_tx,
20113+ plane_idx,
2007720114 )?;
2007820115 let residual = dequant_and_inverse_typed_wh(
2007920116 &levels,
@@ -23125,6 +23162,7 @@ fn leaf8_chroma422_unit(
2312523162 usize::from(around.0) + usize::from(around.1),
2312623163 dc_sign_ctx(around.2),
2312723164 default_tx,
23165+ plane_idx,
2312823166 )?;
2312923167 let residual = dequant_and_inverse_typed_wh(
2313023168 &levels,
@@ -23775,6 +23813,7 @@ fn sub8_leaf_chroma444(
2377523813 skip_ctx,
2377623814 dc_sign_ctx(around[plane_idx].2),
2377723815 default_tx,
23816+ plane_idx,
2377823817 )?;
2377923818 let residual = dequant_and_inverse_typed_wh(
2378023819 &levels,
@@ -23954,6 +23993,7 @@ fn sub8_leaf_chroma444(
2395423993 skip_ctx,
2395523994 dc_sign_ctx(around[plane_idx].2),
2395623995 default_tx,
23996+ plane_idx,
2395723997 )?;
2395823998 let residual = dequant_and_inverse_typed_wh(
2395923999 &levels,
@@ -25337,6 +25377,7 @@ fn decode_leaf_rect8(
2533725377 skip_ctx,
2533825378 dc_sign_ctx(around.2),
2533925379 TxType::DctDct,
25380+ 0,
2534025381 )?;
2534125382 if li == 0 {
2534225383 chroma_tx = tx_type;
@@ -25748,6 +25789,7 @@ fn decode_leaf_rect8(
2574825789 0,
2574925790 dc_sign_ctx(around.2),
2575025791 TxType::DctDct,
25792+ 0,
2575125793 )?;
2575225794 if levels.iter().any(|&l| l != 0) {
2575325795 if vert {
@@ -28442,6 +28484,7 @@ fn read_inter_plane_rect(
2844228484 skip_ctx,
2844328485 dc_sign_ctx(around.2),
2844428486 default_tx_type,
28487+ plane_idx,
2844528488 )?
2844628489 };
2844728490 let grid = extend_corner(corner, cw, ch, w, h);
@@ -35661,10 +35704,7 @@ fn read_intra_chroma_lossless(
3566135704 /// skipped (the returned order is the identity). `changed` is `true` only
3566235705 /// when the sort actually permutes the list, so a no-op ordering reads zero
3566335706 /// on [`MU_CHUNK_ORDER_HITS`] and cannot make a gate look armed.
35664-fn mu_chunk_order(
35665- leaves: &[(usize, usize, usize, usize)],
35666- side: usize,
35667-) -> (Vec<usize>, bool) {
35707+fn mu_chunk_order(leaves: &[(usize, usize, usize, usize)], side: usize) -> (Vec<usize>, bool) {
3566835708 let identity: Vec<usize> = (0..leaves.len()).collect();
3566935709 if side <= 64 {
3567035710 return (identity, false);
@@ -42316,8 +42356,7 @@ fn decode_inter_block(
4231642356 if side > 64 {
4231742357 let chunk = (row / 16, col / 16);
4231842358 let done = pos + 1 == order.len()
42319- || (leaves[order[pos + 1]].0 / 16, leaves[order[pos + 1]].1 / 16)
42320- != chunk;
42359+ || (leaves[order[pos + 1]].0 / 16, leaves[order[pos + 1]].1 / 16) != chunk;
4232142360 if !done {
4232242361 continue;
4232342362 }
@@ -44693,6 +44732,7 @@ fn decode_intra_sub8_leaf(
4469344732 0,
4469444733 dc_sign_ctx(around.2),
4469544734 TxType::DctDct,
44735+ 0,
4469644736 )?;
4469744737 let residual = dequant_and_inverse_typed_wh(
4469844738 &levels,
@@ -45078,6 +45118,7 @@ fn decode_intra_sub8_leaf(
4507845118 skip_ctx,
4507945119 dc_sign_ctx(around.2),
4508045120 uv_tx,
45121+ plane,
4508145122 )?;
4508245123 let residual = dequant_and_inverse_typed_wh(
4508345124 &levels,
@@ -52761,6 +52802,46 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
5276152802
5276252803 #[cfg(test)]
5276352804 mod tests {
52805+ /// lane-av1chrtx: [`covering_leaf_tx_type`] resolves a chroma unit's
52806+ /// `tx_type` from the luma leaf covering the unit's OWN quadrant, and
52807+ /// reports "no leaf there" as `None` so the caller can fall back to the
52808+ /// block-level type. Both halves are load-bearing: the 128 mu-chunk tail,
52809+ /// the 4:4:4 four-unit arms and `read_inter_rect_chroma` all read the
52810+ /// `None` arm as "this block coded a single luma unit".
52811+ #[test]
52812+ fn covering_leaf_tx_type_picks_the_leaf_under_the_unit_or_reports_none() {
52813+ use TxType::*;
52814+ // A 32x64 strip's five-leaf tree, in decode order: one 32x32 leaf
52815+ // over mi rows 0..8, then 16x16 leaves. (row, col) are MI relative
52816+ // to the block, (tw, th) are PIXELS, MI == 4.
52817+ let leaves = [
52818+ (0usize, 0usize, 32usize, 32usize, Idtx),
52819+ (8, 0, 16, 16, VDct),
52820+ (8, 4, 16, 16, DctDct),
52821+ (12, 0, 16, 16, HDct),
52822+ (12, 4, 16, 16, VDct),
52823+ ];
52824+ // The TOP chroma unit (its own mi cell (0,0)) sits over the 32x32
52825+ // leaf; the LOWER one (mi (8,0)) over the first 16x16 leaf. The
52826+ // block-level type is the first leaf's, so only the second read
52827+ // differs -- exactly the condition the gate's DIFF counter counts.
52828+ assert_eq!(covering_leaf_tx_type(&leaves, (0, 0)), Some(Idtx));
52829+ assert_eq!(covering_leaf_tx_type(&leaves, (8, 0)), Some(VDct));
52830+ // Interior cells resolve the same leaf as the cell's top-left: the
52831+ // lookup is a rectangle containment test, not a raster position.
52832+ assert_eq!(covering_leaf_tx_type(&leaves, (11, 3)), Some(VDct));
52833+ assert_eq!(covering_leaf_tx_type(&leaves, (12, 4)), Some(VDct));
52834+ // The bottom-right corner of the last leaf, and the mi cell just
52835+ // past the block's own extent, must not fall into a neighbour.
52836+ assert_eq!(covering_leaf_tx_type(&leaves, (15, 7)), Some(VDct));
52837+ assert_eq!(covering_leaf_tx_type(&leaves, (16, 0)), None);
52838+ assert_eq!(covering_leaf_tx_type(&leaves, (0, 8)), None);
52839+ // A block with no var-tx tree (one coded luma unit) has no leaves at
52840+ // all: the caller's block-level fallback is the answer, and the
52841+ // resolver must say so rather than guess.
52842+ assert_eq!(covering_leaf_tx_type(&[], (0, 0)), None);
52843+ }
52844+
5276452845 /// lane-av1422warp r33: the OBMC pair-merge snap must move the READ to
5276552846 /// libaom's position, not the reported offset.
5276652847 ///