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(
7832 skip_ctx: usize,7832 skip_ctx: usize,
7833 sign_ctx: usize,7833 sign_ctx: usize,
7834 default_tx_type: TxType,7834 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,
7835 ) -> Result<(Grid, TxType)> {7840 ) -> Result<(Grid, TxType)> {
7836 let rect_trace = coeff_trace_on();7841 let rect_trace = coeff_trace_on();
7837 let entry_rng = dec.debug_state().0;7842 let entry_rng = dec.debug_state().0;
7838 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;7843 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
7839 if rect_trace {7844 if rect_trace {
7840 eprintln!(7845 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={}",
7842 all_zero as i32,7847 all_zero as i32,
7843 dec.debug_state().07848 dec.debug_state().0
7844 );7849 );
@@ -7864,7 +7869,7 @@ fn read_coeffs_rect(
7864 })?;7869 })?;
7865 if rect_trace {7870 if rect_trace {
7866 eprintln!(7871 eprintln!(
7867- "EC_COEFF_STEP tag=tx_type plane=0 rng={}",7872+ "EC_COEFF_STEP tag=tx_type plane={plane} rng={}",
7868 dec.debug_state().07873 dec.debug_state().0
7869 );7874 );
7870 }7875 }
@@ -8076,11 +8081,25 @@ fn read_chroma_coeffs_rect(
8076 sign_ctx: usize,8081 sign_ctx: usize,
8077 default_tx_type: TxType,8082 default_tx_type: TxType,
8078 fctx: &crate::decode::FrameCtx,8083 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,
8079 ) -> Result<(Grid, TxType)> {8088 ) -> Result<(Grid, TxType)> {
8080 if mono(fctx) {8089 if mono(fctx) {
8081 return Ok((Grid::Zero(w * h), TxType::DctDct));8090 return Ok((Grid::Zero(w * h), TxType::DctDct));
8082 }8091 }
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+ )
8084 }8103 }
8085 8104
8086 /// What one coded block leaves behind for the blocks that read it as a8105 /// What one coded block leaves behind for the blocks that read it as a
@@ -11537,6 +11556,7 @@ fn decode_rect_split(
11537 tu_skip_ctx,11556 tu_skip_ctx,
11538 dc_sign_ctx(tu_around.2),11557 dc_sign_ctx(tu_around.2),
11539 TxType::DctDct,11558 TxType::DctDct,
11559+ 0,
11540 )?;11560 )?;
11541 let residual = dequant_and_inverse_typed_wh(11561 let residual = dequant_and_inverse_typed_wh(
11542 &tu_grid,11562 &tu_grid,
@@ -11962,6 +11982,7 @@ fn decode_rect_split(
11962 skip_ctx,11982 skip_ctx,
11963 dc_sign_ctx(cu_around[plane_idx].2),11983 dc_sign_ctx(cu_around[plane_idx].2),
11964 default_tx,11984 default_tx,
11985+ plane_idx,
11965 )?;11986 )?;
11966 let residual = dequant_and_inverse_typed_wh(11987 let residual = dequant_and_inverse_typed_wh(
11967 &levels,11988 &levels,
@@ -12046,6 +12067,7 @@ fn decode_rect_split(
12046 skip_ctx,12067 skip_ctx,
12047 dc_sign_ctx(around[plane_idx].2),12068 dc_sign_ctx(around[plane_idx].2),
12048 default_tx,12069 default_tx,
12070+ plane_idx,
12049 )?;12071 )?;
12050 // The same delta_q proof the unsplit rect64 path records12072 // The same delta_q proof the unsplit rect64 path records
12051 // (lane-rectsplit r4: lifting the split-transform refusal moved12073 // (lane-rectsplit r4: lifting the split-transform refusal moved
@@ -14510,6 +14532,7 @@ fn decode_block_rect(
14510 0,14532 0,
14511 dc_sign_ctx(around[0].2),14533 dc_sign_ctx(around[0].2),
14512 TxType::DctDct,14534 TxType::DctDct,
14535+ 0,
14513 )?;14536 )?;
14514 if crate::envflags::env_flag!("EC_AV1_TRACE") {14537 if crate::envflags::env_flag!("EC_AV1_TRACE") {
14515 let (rng, _) = dec.debug_state();14538 let (rng, _) = dec.debug_state();
@@ -14558,6 +14581,7 @@ fn decode_block_rect(
14558 dc_sign_ctx(around[1].2),14581 dc_sign_ctx(around[1].2),
14559 u_default_tx,14582 u_default_tx,
14560 fctx,14583 fctx,
14584+ 1,
14561 )?;14585 )?;
14562 if crate::envflags::env_flag!("EC_AV1_TRACE") {14586 if crate::envflags::env_flag!("EC_AV1_TRACE") {
14563 let (rng, _) = dec.debug_state();14587 let (rng, _) = dec.debug_state();
@@ -14605,6 +14629,7 @@ fn decode_block_rect(
14605 dc_sign_ctx(around[2].2),14629 dc_sign_ctx(around[2].2),
14606 v_default_tx,14630 v_default_tx,
14607 fctx,14631 fctx,
14632+ 2,
14608 )?;14633 )?;
14609 if crate::envflags::env_flag!("EC_AV1_TRACE") {14634 if crate::envflags::env_flag!("EC_AV1_TRACE") {
14610 let (rng, _) = dec.debug_state();14635 let (rng, _) = dec.debug_state();
@@ -15087,6 +15112,7 @@ fn decode_leaf_rect(
15087 0,15112 0,
15088 dc_sign_ctx(around[0].2),15113 dc_sign_ctx(around[0].2),
15089 TxType::DctDct,15114 TxType::DctDct,
15115+ 0,
15090 )?;15116 )?;
15091 if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") {15117 if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") {
15092 let nz: Vec<(usize, i32)> = l_levels15118 let nz: Vec<(usize, i32)> = l_levels
@@ -15141,6 +15167,7 @@ fn decode_leaf_rect(
15141 dc_sign_ctx(around[1].2),15167 dc_sign_ctx(around[1].2),
15142 u_default_tx,15168 u_default_tx,
15143 fctx,15169 fctx,
15170+ 1,
15144 )?;15171 )?;
15145 u_levels = u_l;15172 u_levels = u_l;
15146 let u_residual = dequant_and_inverse_typed_wh(15173 let u_residual = dequant_and_inverse_typed_wh(
@@ -15185,6 +15212,7 @@ fn decode_leaf_rect(
15185 dc_sign_ctx(around[2].2),15212 dc_sign_ctx(around[2].2),
15186 v_default_tx,15213 v_default_tx,
15187 fctx,15214 fctx,
15215+ 2,
15188 )?;15216 )?;
15189 v_levels = v_l;15217 v_levels = v_l;
15190 let v_residual = dequant_and_inverse_typed_wh(15218 let v_residual = dequant_and_inverse_typed_wh(
@@ -15608,6 +15636,7 @@ fn decode_block_rect4(
15608 0,15636 0,
15609 dc_sign_ctx(around[0].2),15637 dc_sign_ctx(around[0].2),
15610 TxType::DctDct,15638 TxType::DctDct,
15639+ 0,
15611 )?;15640 )?;
15612 hit!(RECT4_COEFF_HITS);15641 hit!(RECT4_COEFF_HITS);
15613 let luma_residual = dequant_and_inverse_typed_wh(15642 let luma_residual = dequant_and_inverse_typed_wh(
@@ -15758,6 +15787,7 @@ fn decode_block_rect4(
15758 0,15787 0,
15759 dc_sign_ctx(around[0].2),15788 dc_sign_ctx(around[0].2),
15760 TxType::DctDct,15789 TxType::DctDct,
15790+ 0,
15761 )?;15791 )?;
15762 let mut planes = Vec::with_capacity(2);15792 let mut planes = Vec::with_capacity(2);
15763 for plane in 1..3 {15793 for plane in 1..3 {
@@ -15783,6 +15813,7 @@ fn decode_block_rect4(
15783 dc_sign_ctx(around[plane].2),15813 dc_sign_ctx(around[plane].2),
15784 default_tx,15814 default_tx,
15785 fctx,15815 fctx,
15816+ plane,
15786 )?;15817 )?;
15787 planes.push((levels, tx_type));15818 planes.push((levels, tx_type));
15788 }15819 }
@@ -17313,6 +17344,7 @@ fn decode_rect4_16_strip(
17313 tu_skip_ctx,17344 tu_skip_ctx,
17314 dc_sign_ctx(tu_around.2),17345 dc_sign_ctx(tu_around.2),
17315 TxType::DctDct,17346 TxType::DctDct,
17347+ 0,
17316 )?;17348 )?;
17317 let residual = dequant_and_inverse_typed_wh(17349 let residual = dequant_and_inverse_typed_wh(
17318 &tu_grid,17350 &tu_grid,
@@ -17419,6 +17451,7 @@ fn decode_rect4_16_strip(
17419 0,17451 0,
17420 dc_sign_ctx(around.2),17452 dc_sign_ctx(around.2),
17421 TxType::DctDct,17453 TxType::DctDct,
17454+ 0,
17422 )?;17455 )?;
17423 let residual = dequant_and_inverse_typed_wh(17456 let residual = dequant_and_inverse_typed_wh(
17424 &levels,17457 &levels,
@@ -17935,6 +17968,7 @@ fn decode_rect4_16_strip(
17935 dc_sign_ctx(around[plane].2),17968 dc_sign_ctx(around[plane].2),
17936 default_tx,17969 default_tx,
17937 fctx,17970 fctx,
17971+ plane,
17938 )?;17972 )?;
17939 planes.push((levels, tx_type));17973 planes.push((levels, tx_type));
17940 }17974 }
@@ -18441,6 +18475,7 @@ fn decode_block_rect64(
18441 0,18475 0,
18442 dc_sign_ctx(around[0].2),18476 dc_sign_ctx(around[0].2),
18443 TxType::DctDct,18477 TxType::DctDct,
18478+ 0,
18444 )?18479 )?
18445 };18480 };
18446 if coeff_trace_on() {18481 if coeff_trace_on() {
@@ -18596,6 +18631,7 @@ fn decode_block_rect64(
18596 dc_sign_ctx(cu_around[plane_idx].2),18631 dc_sign_ctx(cu_around[plane_idx].2),
18597 TxType::DctDct,18632 TxType::DctDct,
18598 fctx,18633 fctx,
18634+ plane_idx,
18599 )?;18635 )?;
18600 let residual = dequant_and_inverse_typed_wh(18636 let residual = dequant_and_inverse_typed_wh(
18601 &levels,18637 &levels,
@@ -20074,6 +20110,7 @@ fn read_rect_chroma_unit(
20074 usize::from(around.0) + usize::from(around.1) + chroma_skip_offset.unwrap_or(0),20110 usize::from(around.0) + usize::from(around.1) + chroma_skip_offset.unwrap_or(0),
20075 dc_sign_ctx(around.2),20111 dc_sign_ctx(around.2),
20076 default_tx,20112 default_tx,
20113+ plane_idx,
20077 )?;20114 )?;
20078 let residual = dequant_and_inverse_typed_wh(20115 let residual = dequant_and_inverse_typed_wh(
20079 &levels,20116 &levels,
@@ -23125,6 +23162,7 @@ fn leaf8_chroma422_unit(
23125 usize::from(around.0) + usize::from(around.1),23162 usize::from(around.0) + usize::from(around.1),
23126 dc_sign_ctx(around.2),23163 dc_sign_ctx(around.2),
23127 default_tx,23164 default_tx,
23165+ plane_idx,
23128 )?;23166 )?;
23129 let residual = dequant_and_inverse_typed_wh(23167 let residual = dequant_and_inverse_typed_wh(
23130 &levels,23168 &levels,
@@ -23775,6 +23813,7 @@ fn sub8_leaf_chroma444(
23775 skip_ctx,23813 skip_ctx,
23776 dc_sign_ctx(around[plane_idx].2),23814 dc_sign_ctx(around[plane_idx].2),
23777 default_tx,23815 default_tx,
23816+ plane_idx,
23778 )?;23817 )?;
23779 let residual = dequant_and_inverse_typed_wh(23818 let residual = dequant_and_inverse_typed_wh(
23780 &levels,23819 &levels,
@@ -23954,6 +23993,7 @@ fn sub8_leaf_chroma444(
23954 skip_ctx,23993 skip_ctx,
23955 dc_sign_ctx(around[plane_idx].2),23994 dc_sign_ctx(around[plane_idx].2),
23956 default_tx,23995 default_tx,
23996+ plane_idx,
23957 )?;23997 )?;
23958 let residual = dequant_and_inverse_typed_wh(23998 let residual = dequant_and_inverse_typed_wh(
23959 &levels,23999 &levels,
@@ -25337,6 +25377,7 @@ fn decode_leaf_rect8(
25337 skip_ctx,25377 skip_ctx,
25338 dc_sign_ctx(around.2),25378 dc_sign_ctx(around.2),
25339 TxType::DctDct,25379 TxType::DctDct,
25380+ 0,
25340 )?;25381 )?;
25341 if li == 0 {25382 if li == 0 {
25342 chroma_tx = tx_type;25383 chroma_tx = tx_type;
@@ -25748,6 +25789,7 @@ fn decode_leaf_rect8(
25748 0,25789 0,
25749 dc_sign_ctx(around.2),25790 dc_sign_ctx(around.2),
25750 TxType::DctDct,25791 TxType::DctDct,
25792+ 0,
25751 )?;25793 )?;
25752 if levels.iter().any(|&l| l != 0) {25794 if levels.iter().any(|&l| l != 0) {
25753 if vert {25795 if vert {
@@ -28442,6 +28484,7 @@ fn read_inter_plane_rect(
28442 skip_ctx,28484 skip_ctx,
28443 dc_sign_ctx(around.2),28485 dc_sign_ctx(around.2),
28444 default_tx_type,28486 default_tx_type,
28487+ plane_idx,
28445 )?28488 )?
28446 };28489 };
28447 let grid = extend_corner(corner, cw, ch, w, h);28490 let grid = extend_corner(corner, cw, ch, w, h);
@@ -35661,10 +35704,7 @@ fn read_intra_chroma_lossless(
35661 /// skipped (the returned order is the identity). `changed` is `true` only35704 /// skipped (the returned order is the identity). `changed` is `true` only
35662 /// when the sort actually permutes the list, so a no-op ordering reads zero35705 /// when the sort actually permutes the list, so a no-op ordering reads zero
35663 /// on [`MU_CHUNK_ORDER_HITS`] and cannot make a gate look armed.35706 /// on [`MU_CHUNK_ORDER_HITS`] and cannot make a gate look armed.
35664-fn mu_chunk_order(35707+fn mu_chunk_order(leaves: &[(usize, usize, usize, usize)], side: usize) -> (Vec<usize>, bool) {
35665- leaves: &[(usize, usize, usize, usize)],
35666- side: usize,
35667-) -> (Vec<usize>, bool) {
35668 let identity: Vec<usize> = (0..leaves.len()).collect();35708 let identity: Vec<usize> = (0..leaves.len()).collect();
35669 if side <= 64 {35709 if side <= 64 {
35670 return (identity, false);35710 return (identity, false);
@@ -42316,8 +42356,7 @@ fn decode_inter_block(
42316 if side > 64 {42356 if side > 64 {
42317 let chunk = (row / 16, col / 16);42357 let chunk = (row / 16, col / 16);
42318 let done = pos + 1 == order.len()42358 let done = pos + 1 == order.len()
42319- || (leaves[order[pos + 1]].0 / 16, leaves[order[pos + 1]].1 / 16)42359+ || (leaves[order[pos + 1]].0 / 16, leaves[order[pos + 1]].1 / 16) != chunk;
42320- != chunk;
42321 if !done {42360 if !done {
42322 continue;42361 continue;
42323 }42362 }
@@ -44693,6 +44732,7 @@ fn decode_intra_sub8_leaf(
44693 0,44732 0,
44694 dc_sign_ctx(around.2),44733 dc_sign_ctx(around.2),
44695 TxType::DctDct,44734 TxType::DctDct,
44735+ 0,
44696 )?;44736 )?;
44697 let residual = dequant_and_inverse_typed_wh(44737 let residual = dequant_and_inverse_typed_wh(
44698 &levels,44738 &levels,
@@ -45078,6 +45118,7 @@ fn decode_intra_sub8_leaf(
45078 skip_ctx,45118 skip_ctx,
45079 dc_sign_ctx(around.2),45119 dc_sign_ctx(around.2),
45080 uv_tx,45120 uv_tx,
45121+ plane,
45081 )?;45122 )?;
45082 let residual = dequant_and_inverse_typed_wh(45123 let residual = dequant_and_inverse_typed_wh(
45083 &levels,45124 &levels,
@@ -52761,6 +52802,46 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
52761 52802
52762 #[cfg(test)]52803 #[cfg(test)]
52763 mod tests {52804 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+
52764 /// lane-av1422warp r33: the OBMC pair-merge snap must move the READ to52845 /// lane-av1422warp r33: the OBMC pair-merge snap must move the READ to
52765 /// libaom's position, not the reported offset.52846 /// libaom's position, not the reported offset.
52766 ///52847 ///