A sub-8x8 intra leaf stamps its own mi footprint, not 1x1
Browse files at this commit120e018e7201dd8752b4ca9c151b3c1e9d882fb7Parent: 96c590f- fix
- a sub-8x8 intra leaf stamps its own mi footprint, not 1x1
1 changed file +39 -7
- crates/ec-av1/src/decode.rs +39 -7
crates/ec-av1/src/decode.rsmodified+39 -7
| @@ -871,6 +871,12 @@ pub(crate) fn set_segmentation( | |||
| 871 | mi_cols: usize, | 871 | mi_cols: usize, |
| 872 | prev: Option<&[u8]>, fctx: &crate::decode::FrameCtx, | 872 | prev: Option<&[u8]>, fctx: &crate::decode::FrameCtx, |
| 873 | ) { | 873 | ) { |
| 874 | + if crate::envflags::env_flag!("EC_HDR") { | ||
| 875 | + eprintln!( | ||
| 876 | + "EC_SEGHDR enabled={} update_map={} temporal={} preskip={} last_active={} data={:?}", | ||
| 877 | + seg.enabled, seg.update_map, seg.temporal_update, seg.seg_id_pre_skip, seg.last_active_seg_id, seg.feature_data | ||
| 878 | + ); | ||
| 879 | + } | ||
| 874 | fctx.seg.with(|s| *s.borrow_mut() = seg); | 880 | fctx.seg.with(|s| *s.borrow_mut() = seg); |
| 875 | fctx.seg_mi_dims.with(|c| c.set((mi_rows, mi_cols))); | 881 | fctx.seg_mi_dims.with(|c| c.set((mi_rows, mi_cols))); |
| 876 | fctx.seg_ids.with(|m| *m.borrow_mut() = vec![0u8; mi_rows * mi_cols]); | 882 | fctx.seg_ids.with(|m| *m.borrow_mut() = vec![0u8; mi_rows * mi_cols]); |
| @@ -1058,7 +1064,13 @@ fn read_segment_id(dec: &mut SymbolDecoder, cdfs: &mut Cdfs, mi_r: usize, mi_c: | |||
| 1058 | let coded = dec.symbol(&mut cdfs.segment_id[ctx]) as i32; | 1064 | let coded = dec.symbol(&mut cdfs.segment_id[ctx]) as i32; |
| 1059 | hit!(SEG_ID_HITS); | 1065 | hit!(SEG_ID_HITS); |
| 1060 | let last_active = fctx.seg.with(|s| i32::from(s.borrow().last_active_seg_id)); | 1066 | let last_active = fctx.seg.with(|s| i32::from(s.borrow().last_active_seg_id)); |
| 1061 | - neg_deinterleave(coded, pred, last_active + 1).clamp(0, last_active) as u8 | 1067 | + let id = neg_deinterleave(coded, pred, last_active + 1).clamp(0, last_active); |
| 1068 | + // Mirrors the oracle's own `EC_SEG mi_row=.. cdf=.. pred=.. coded=.. id=..` | ||
| 1069 | + // (libaom `decodemv.c:read_segment_id`), for a cross-decoder segment diff. | ||
| 1070 | + if crate::envflags::env_flag!("EC_TRACE_SEG") { | ||
| 1071 | + eprintln!("EC_SEG mi_row={mi_r} mi_col={mi_c} cdf={ctx} pred={pred} coded={coded} id={id} rng={}", dec.debug_state().0); | ||
| 1072 | + } | ||
| 1073 | + id as u8 | ||
| 1062 | } | 1074 | } |
| 1063 | 1075 | ||
| 1064 | /// `read_intra_segment_id` (spec 5.11.7): called twice per intra-frame block | 1076 | /// `read_intra_segment_id` (spec 5.11.7): called twice per intra-frame block |
| @@ -15703,12 +15715,28 @@ fn read_intra_mode_sub8( | |||
| 15703 | skip_ctx: usize, | 15715 | skip_ctx: usize, |
| 15704 | allow_intrabc: bool, | 15716 | allow_intrabc: bool, |
| 15705 | mi_r: usize, | 15717 | mi_r: usize, |
| 15706 | - mi_c: usize, fctx: &crate::decode::FrameCtx, | 15718 | + mi_c: usize, |
| 15719 | + // The leaf's own mi footprint for `set_segment_id`: 1x1 for a `BLOCK_4X4` | ||
| 15720 | + // split leaf, 2x1/1x2 for an 8x4/4x8 one. Stamping 1x1 for a rect leaf | ||
| 15721 | + // left the second mi column at segment 0, which reads back as a | ||
| 15722 | + // neighbour's `cdf_index`/prediction two blocks later. | ||
| 15723 | + seg_w_mi: usize, | ||
| 15724 | + seg_h_mi: usize, fctx: &crate::decode::FrameCtx, | ||
| 15707 | ) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> { | 15725 | ) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> { |
| 15708 | let trace = crate::envflags::env_flag!("EC_AV1_TRACE"); | 15726 | let trace = crate::envflags::env_flag!("EC_AV1_TRACE"); |
| 15709 | - if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") { | 15727 | + let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP"); |
| 15728 | + if ec_istep { | ||
| 15710 | eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0); | 15729 | eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0); |
| 15711 | } | 15730 | } |
| 15731 | + // Same `EC_ISTEP` ladder the square/rect readers print, so a cross-decoder | ||
| 15732 | + // range diff lands on the ELEMENT inside a 4x4 leaf, not just the block. | ||
| 15733 | + macro_rules! istep { | ||
| 15734 | + ($name:literal, $val:expr) => { | ||
| 15735 | + if ec_istep { | ||
| 15736 | + eprintln!("EC_ISTEP mi_row={mi_r} mi_col={mi_c} name={} val={} rng={}", $name, $val, dec.debug_state().0); | ||
| 15737 | + } | ||
| 15738 | + }; | ||
| 15739 | + } | ||
| 15712 | // lane-seg2: same `intra_segment_id` placement as the square and rect | 15740 | // lane-seg2: same `intra_segment_id` placement as the square and rect |
| 15713 | // readers (spec 5.11.6) -- a `BLOCK_4X4` leaf codes its own `segment_id` | 15741 | // readers (spec 5.11.6) -- a `BLOCK_4X4` leaf codes its own `segment_id` |
| 15714 | // like any other block, over its own 1x1 mi footprint. Dropping it here | 15742 | // like any other block, over its own 1x1 mi footprint. Dropping it here |
| @@ -15716,18 +15744,21 @@ fn read_intra_mode_sub8( | |||
| 15716 | // split) and left `cur_segment_id` on the previous block, so the leaf | 15744 | // split) and left `cur_segment_id` on the previous block, so the leaf |
| 15717 | // dequantized with a neighbour's `SEG_LVL_ALT_Q`. | 15745 | // dequantized with a neighbour's `SEG_LVL_ALT_Q`. |
| 15718 | if seg_id_pre_skip(fctx) { | 15746 | if seg_id_pre_skip(fctx) { |
| 15719 | - intra_segment_id(dec, cdfs, mi_r, mi_c, 1, 1, false, fctx); | 15747 | + intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, false, fctx); |
| 15720 | } | 15748 | } |
| 15721 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; | 15749 | let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0; |
| 15722 | if trace { | 15750 | if trace { |
| 15723 | eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", skip as i32, dec.debug_state().0); | 15751 | eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", skip as i32, dec.debug_state().0); |
| 15724 | } | 15752 | } |
| 15753 | + istep!("skip", skip as i32); | ||
| 15725 | if !seg_id_pre_skip(fctx) { | 15754 | if !seg_id_pre_skip(fctx) { |
| 15726 | - intra_segment_id(dec, cdfs, mi_r, mi_c, 1, 1, skip, fctx); | 15755 | + intra_segment_id(dec, cdfs, mi_r, mi_c, seg_w_mi, seg_h_mi, skip, fctx); |
| 15727 | } | 15756 | } |
| 15728 | maybe_read_cdef_idx(dec, mi_r, mi_c, skip, fctx); | 15757 | maybe_read_cdef_idx(dec, mi_r, mi_c, skip, fctx); |
| 15758 | + istep!("cdef", 0); | ||
| 15729 | maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip, fctx); | 15759 | maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip, fctx); |
| 15730 | maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip, fctx); | 15760 | maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip, fctx); |
| 15761 | + istep!("dq", 0); | ||
| 15731 | if allow_intrabc { | 15762 | if allow_intrabc { |
| 15732 | let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; | 15763 | let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0; |
| 15733 | if use_intrabc { | 15764 | if use_intrabc { |
| @@ -15739,6 +15770,7 @@ fn read_intra_mode_sub8( | |||
| 15739 | let above_ctx = INTRA_MODE_CTX[above_mode]; | 15770 | let above_ctx = INTRA_MODE_CTX[above_mode]; |
| 15740 | let left_ctx = INTRA_MODE_CTX[left_mode]; | 15771 | let left_ctx = INTRA_MODE_CTX[left_mode]; |
| 15741 | let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); | 15772 | let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]); |
| 15773 | + istep!("mode", mode); | ||
| 15742 | if trace { | 15774 | if trace { |
| 15743 | eprintln!("TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0); | 15775 | eprintln!("TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0); |
| 15744 | } | 15776 | } |
| @@ -15855,7 +15887,7 @@ fn decode_leaf_split4( | |||
| 15855 | let (skip, mode, angle_delta_y, chroma, filter_intra) = read_intra_mode_sub8( | 15887 | let (skip, mode, angle_delta_y, chroma, filter_intra) = read_intra_mode_sub8( |
| 15856 | dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, | 15888 | dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, |
| 15857 | filter_intra_size_class(4).expect("BLOCK_4X4 has its own filter_intra row"), | 15889 | filter_intra_size_class(4).expect("BLOCK_4X4 has its own filter_intra row"), |
| 15858 | - skip_ctx, allow_intrabc, lmi.0, lmi.1, fctx, | 15890 | + skip_ctx, allow_intrabc, lmi.0, lmi.1, 1, 1, fctx, |
| 15859 | )?; | 15891 | )?; |
| 15860 | leaf_modes[i] = mode; | 15892 | leaf_modes[i] = mode; |
| 15861 | leaf_skips[i] = skip; | 15893 | leaf_skips[i] = skip; |
| @@ -16081,7 +16113,7 @@ fn decode_leaf_rect8( | |||
| 16081 | dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, | 16113 | dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra, |
| 16082 | filter_intra_size_class_rect(bw, bh) | 16114 | filter_intra_size_class_rect(bw, bh) |
| 16083 | .expect("BLOCK_4X8/BLOCK_8X4 are inside av1_filter_intra_allowed_bsize"), | 16115 | .expect("BLOCK_4X8/BLOCK_8X4 are inside av1_filter_intra_allowed_bsize"), |
| 16084 | - skip_ctx, allow_intrabc, lmi.0, lmi.1, fctx, | 16116 | + skip_ctx, allow_intrabc, lmi.0, lmi.1, bw / 4, bh / 4, fctx, |
| 16085 | )?; | 16117 | )?; |
| 16086 | if filter_intra.is_some() { | 16118 | if filter_intra.is_some() { |
| 16087 | // lane-fi8 r1: `predict_filter_intra` walks its 4x2 patches over | 16119 | // lane-fi8 r1: `predict_filter_intra` walks its 4x2 patches over |