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