forge
Explore
Log in

Don't you dare go Hollow

A sub-8x8 intra leaf stamps its own mi footprint, not 1x1

Browse files at this commit

120e018e7201dd8752b4ca9c151b3c1e9d882fb7Ahmet Kaan GümüşParent: 96c590f
  • fix
    • a sub-8x8 intra leaf stamps its own mi footprint, not 1x1
Show full message
fix(av1): a sub-8x8 intra leaf stamps its own mi footprint, not 1x1

An 8x4/4x8 leaf goes through the same reader as a BLOCK_4X4 split leaf; a
1x1 segment stamp left its second mi cell at segment 0, which a later
block read back as the spatial prediction and cdf_index. Adds the EC_SEG /
EC_SEGHDR / sub8 EC_ISTEP traces the diff was found with.
crates/ec-av1/src/decode.rsmodified+39 -7
@@ -871,6 +871,12 @@ pub(crate) fn set_segmentation(
871871 mi_cols: usize,
872872 prev: Option<&[u8]>, fctx: &crate::decode::FrameCtx,
873873 ) {
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+ }
874880 fctx.seg.with(|s| *s.borrow_mut() = seg);
875881 fctx.seg_mi_dims.with(|c| c.set((mi_rows, mi_cols)));
876882 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:
10581064 let coded = dec.symbol(&mut cdfs.segment_id[ctx]) as i32;
10591065 hit!(SEG_ID_HITS);
10601066 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
10621074 }
10631075
10641076 /// `read_intra_segment_id` (spec 5.11.7): called twice per intra-frame block
@@ -15703,12 +15715,28 @@ fn read_intra_mode_sub8(
1570315715 skip_ctx: usize,
1570415716 allow_intrabc: bool,
1570515717 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,
1570715725 ) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> {
1570815726 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 {
1571015729 eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0);
1571115730 }
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+ }
1571215740 // lane-seg2: same `intra_segment_id` placement as the square and rect
1571315741 // readers (spec 5.11.6) -- a `BLOCK_4X4` leaf codes its own `segment_id`
1571415742 // like any other block, over its own 1x1 mi footprint. Dropping it here
@@ -15716,18 +15744,21 @@ fn read_intra_mode_sub8(
1571615744 // split) and left `cur_segment_id` on the previous block, so the leaf
1571715745 // dequantized with a neighbour's `SEG_LVL_ALT_Q`.
1571815746 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);
1572015748 }
1572115749 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
1572215750 if trace {
1572315751 eprintln!("TRACE sub8 skip mi=({mi_r},{mi_c}) ctx={skip_ctx} value={} rng={}", skip as i32, dec.debug_state().0);
1572415752 }
15753+ istep!("skip", skip as i32);
1572515754 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);
1572715756 }
1572815757 maybe_read_cdef_idx(dec, mi_r, mi_c, skip, fctx);
15758+ istep!("cdef", 0);
1572915759 maybe_read_delta_q(dec, cdfs, mi_r, mi_c, false, skip, fctx);
1573015760 maybe_read_delta_lf(dec, cdfs, mi_r, mi_c, false, skip, fctx);
15761+ istep!("dq", 0);
1573115762 if allow_intrabc {
1573215763 let use_intrabc = dec.symbol(&mut cdfs.intrabc) != 0;
1573315764 if use_intrabc {
@@ -15739,6 +15770,7 @@ fn read_intra_mode_sub8(
1573915770 let above_ctx = INTRA_MODE_CTX[above_mode];
1574015771 let left_ctx = INTRA_MODE_CTX[left_mode];
1574115772 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
15773+ istep!("mode", mode);
1574215774 if trace {
1574315775 eprintln!("TRACE sub8 y_mode mi=({mi_r},{mi_c}) ctx=({above_ctx},{left_ctx}) value={mode} rng={}", dec.debug_state().0);
1574415776 }
@@ -15855,7 +15887,7 @@ fn decode_leaf_split4(
1585515887 let (skip, mode, angle_delta_y, chroma, filter_intra) = read_intra_mode_sub8(
1585615888 dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra,
1585715889 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,
1585915891 )?;
1586015892 leaf_modes[i] = mode;
1586115893 leaf_skips[i] = skip;
@@ -16081,7 +16113,7 @@ fn decode_leaf_rect8(
1608116113 dec, cdfs, leaf_above, leaf_left, has_chroma, enable_filter_intra,
1608216114 filter_intra_size_class_rect(bw, bh)
1608316115 .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,
1608516117 )?;
1608616118 if filter_intra.is_some() {
1608716119 // lane-fi8 r1: `predict_filter_intra` walks its 4x2 patches over