forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-interintra': non-wedge interintra decode; warp-sample interintra exclusion; switchable_interp CDF counter reset

Browse files at this commit

5c61a65fb3c61fb9efb9001943e35c486254ee85Ahmet Kaan GümüşParent: d45c7f80ce8a5b
crates/ec-av1/src/cdf.rsmodified+41 -0
@@ -1246,6 +1246,47 @@ pub const INTERINTRA: [[u16; 3]; 4] = [
1246 [30237, 32768, 0],1246 [30237, 32768, 0],
1247 ];1247 ];
1248 1248
1249+/// `default_interintra_mode_cdf` (spec 9.4): `interintra_mode` (II_DC/II_V/
1250+/// II_H/II_SMOOTH), indexed by `size_group_lookup[bsize]`, read right after
1251+/// `interintra == 1` (lane-interintra r1).
1252+pub const INTERINTRA_MODE: [[u16; 5]; 4] = [
1253+ [8192, 16384, 24576, 32768, 0],
1254+ [1875, 11082, 27332, 32768, 0],
1255+ [2473, 9996, 26388, 32768, 0],
1256+ [4238, 11537, 25926, 32768, 0],
1257+];
1258+
1259+/// `default_wedge_interintra_cdf` (spec 9.4): `wedge_interintra`, indexed by
1260+/// bsize over `BLOCK_SIZES_ALL` -- read for every interintra block whose
1261+/// size `av1_is_wedge_used` allows (the 8x8..32x32 family), REGARDLESS of
1262+/// the sequence header's `enable_interintra_wedge` bit (libaom
1263+/// decodemv.c:1548 gates on block size alone; the seq bit constrains only
1264+/// the encoder).
1265+pub const WEDGE_INTERINTRA: [[u16; 3]; 22] = [
1266+ [16384, 32768, 0],
1267+ [16384, 32768, 0],
1268+ [16384, 32768, 0],
1269+ [20036, 32768, 0],
1270+ [24957, 32768, 0],
1271+ [26704, 32768, 0],
1272+ [27530, 32768, 0],
1273+ [29564, 32768, 0],
1274+ [29444, 32768, 0],
1275+ [26872, 32768, 0],
1276+ [16384, 32768, 0],
1277+ [16384, 32768, 0],
1278+ [16384, 32768, 0],
1279+ [16384, 32768, 0],
1280+ [16384, 32768, 0],
1281+ [16384, 32768, 0],
1282+ [16384, 32768, 0],
1283+ [16384, 32768, 0],
1284+ [16384, 32768, 0],
1285+ [16384, 32768, 0],
1286+ [16384, 32768, 0],
1287+ [16384, 32768, 0],
1288+];
1289+
1249 /// `Default_Comp_Mode_Cdf` (spec 9.4, `default_comp_inter_cdf`): whether an1290 /// `Default_Comp_Mode_Cdf` (spec 9.4, `default_comp_inter_cdf`): whether an
1250 /// inter block reads `SINGLE_REFERENCE` or `COMPOUND_REFERENCE` -- only1291 /// inter block reads `SINGLE_REFERENCE` or `COMPOUND_REFERENCE` -- only
1251 /// reached once `read_ref_frames` knows the frame's `reference_select`1292 /// reached once `read_ref_frames` knows the frame's `reference_select`
crates/ec-av1/src/cdf_state.rsmodified+17 -0
@@ -336,6 +336,12 @@ pub(crate) struct Cdfs {
336 /// `interintra`, indexed by `size_group_lookup[bsize]` -- see336 /// `interintra`, indexed by `size_group_lookup[bsize]` -- see
337 /// `cdf::INTERINTRA`'s own doc.337 /// `cdf::INTERINTRA`'s own doc.
338 pub interintra: [[u16; 3]; 4],338 pub interintra: [[u16; 3]; 4],
339+ /// `interintra_mode` (II_DC/II_V/II_H/II_SMOOTH), same size-group
340+ /// indexing -- see `cdf::INTERINTRA_MODE` (lane-interintra r1).
341+ pub interintra_mode: [[u16; 5]; 4],
342+ /// `wedge_interintra`, indexed by bsize over `BLOCK_SIZES_ALL` -- see
343+ /// `cdf::WEDGE_INTERINTRA` (lane-interintra r1).
344+ pub wedge_interintra: [[u16; 3]; 22],
339 /// Which of the eight `INTER_COMPOUND_MODES` a `COMPOUND_REFERENCE`345 /// Which of the eight `INTER_COMPOUND_MODES` a `COMPOUND_REFERENCE`
340 /// block takes (lane-av1comp, spec 5.11.24's `compound_mode`).346 /// block takes (lane-av1comp, spec 5.11.24's `compound_mode`).
341 pub inter_compound_mode: [[u16; 9]; 8],347 pub inter_compound_mode: [[u16; 9]; 8],
@@ -568,7 +574,16 @@ impl Cdfs {
568 reset2(&mut self.skip_mode);574 reset2(&mut self.skip_mode);
569 reset2(&mut self.obmc);575 reset2(&mut self.obmc);
570 reset2(&mut self.motion_mode);576 reset2(&mut self.motion_mode);
577+ // lane-interintra r1 (ii-flake-9): the ONE table this list missed --
578+ // an unreset counter saturates past 15 reads and slows update_cdf's
579+ // rate to >>5 while libaom (reset per frame) stays at >>4; the rows
580+ // drift a few counts apart and the gate flakes only on streams with
581+ // enough switchable-filter reads. Audit: every other Cdfs field was
582+ // covered (script-checked against the struct's field list).
583+ reset2(&mut self.switchable_interp);
571 reset2(&mut self.interintra);584 reset2(&mut self.interintra);
585+ reset2(&mut self.interintra_mode);
586+ reset2(&mut self.wedge_interintra);
572 reset2(&mut self.inter_compound_mode);587 reset2(&mut self.inter_compound_mode);
573 reset2(&mut self.comp_ref_type);588 reset2(&mut self.comp_ref_type);
574 reset3(&mut self.uni_comp_ref);589 reset3(&mut self.uni_comp_ref);
@@ -1012,6 +1027,8 @@ impl Cdfs {
1012 obmc: cdf::OBMC,1027 obmc: cdf::OBMC,
1013 motion_mode: cdf::MOTION_MODE,1028 motion_mode: cdf::MOTION_MODE,
1014 interintra: cdf::INTERINTRA,1029 interintra: cdf::INTERINTRA,
1030+ interintra_mode: cdf::INTERINTRA_MODE,
1031+ wedge_interintra: cdf::WEDGE_INTERINTRA,
1015 comp_group_idx: cdf::COMP_GROUP_IDX,1032 comp_group_idx: cdf::COMP_GROUP_IDX,
1016 compound_idx: cdf::COMPOUND_IDX,1033 compound_idx: cdf::COMPOUND_IDX,
1017 y_mode: cdf::Y_MODE,1034 y_mode: cdf::Y_MODE,
crates/ec-av1/src/decode.rsmodified+152 -10
@@ -190,6 +190,16 @@ pub(crate) fn warp_selected_hits() -> usize {
190 WARP_SELECTED_HITS.load(std::sync::atomic::Ordering::Relaxed)190 WARP_SELECTED_HITS.load(std::sync::atomic::Ordering::Relaxed)
191 }191 }
192 192
193+/// How many blocks decoded `interintra == 1` with the non-wedge blended
194+/// prediction applied (lane-interintra r1) -- the gate's proof that a
195+/// stream actually exercised interintra.
196+static INTERINTRA_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
197+
198+/// Current value of [`INTERINTRA_HITS`].
199+pub(crate) fn interintra_hits() -> usize {
200+ INTERINTRA_HITS.load(std::sync::atomic::Ordering::Relaxed)
201+}
202+
193 /// Current value of [`OBMC_HITS_8`].203 /// Current value of [`OBMC_HITS_8`].
194 pub(crate) fn obmc_hits_8() -> usize {204 pub(crate) fn obmc_hits_8() -> usize {
195 OBMC_HITS_8.load(std::sync::atomic::Ordering::Relaxed)205 OBMC_HITS_8.load(std::sync::atomic::Ordering::Relaxed)
@@ -3770,9 +3780,21 @@ fn resolve_interp_filter(
3770 // `h_kind`/`v_kind` argument order, which is why this function returns3780 // `h_kind`/`v_kind` argument order, which is why this function returns
3771 // `(h, v, ..)` but reads `dir0` (`v`) before `dir1` (`h`).3781 // `(h, v, ..)` but reads `dir0` (`v`) before `dir1` (`h`).
3772 let ctx0 = switchable_interp_ctx(above[0], left[0], 0, is_compound);3782 let ctx0 = switchable_interp_ctx(above[0], left[0], 0, is_compound);
3783+ if std::env::var_os("EC_AV1_IFDBG").is_some() {
3784+ eprintln!(
3785+ "IFDBG dir=0 ctx={ctx0} above={above:?} left={left:?} cdf={:?}",
3786+ &cdfs.switchable_interp[ctx0][..3]
3787+ );
3788+ }
3773 let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8;3789 let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8;
3774 let sym1 = if enable_dual_filter {3790 let sym1 = if enable_dual_filter {
3775 let ctx1 = switchable_interp_ctx(above[1], left[1], 1, is_compound);3791 let ctx1 = switchable_interp_ctx(above[1], left[1], 1, is_compound);
3792+ if std::env::var_os("EC_AV1_IFDBG").is_some() {
3793+ eprintln!(
3794+ "IFDBG dir=1 ctx={ctx1} above={above:?} left={left:?} cdf={:?} sym0={sym0}",
3795+ &cdfs.switchable_interp[ctx1][..3]
3796+ );
3797+ }
3776 dec.symbol(&mut cdfs.switchable_interp[ctx1]) as u83798 dec.symbol(&mut cdfs.switchable_interp[ctx1]) as u8
3777 } else {3799 } else {
3778 sym03800 sym0
@@ -4378,6 +4400,73 @@ fn obmc_neighbour_pred(
4378 4400
4379 /// Blends `tmp` into `dst` (stride `stride`) at `(ox, oy)`, mask varying by4401 /// Blends `tmp` into `dst` (stride `stride`) at `(ox, oy)`, mask varying by
4380 /// row (the above-neighbour pass, `aom_blend_a64_vmask`).4402 /// row (the above-neighbour pass, `aom_blend_a64_vmask`).
4403+/// `ii_weights1d` (reconinter.c:524): the interintra smooth-mask falloff.
4404+const II_WEIGHTS_1D: [u8; 128] = [
4405+ 60, 58, 56, 54, 52, 50, 48, 47, 45, 44, 42, 41, 39, 38, 37, 35, 34, 33, 32,
4406+ 31, 30, 29, 28, 27, 26, 25, 24, 23, 22, 22, 21, 20, 19, 19, 18, 18, 17, 16,
4407+ 16, 15, 15, 14, 14, 13, 13, 12, 12, 12, 11, 11, 10, 10, 10, 9, 9, 9, 8,
4408+ 8, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 4, 4,
4409+ 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3, 3, 2, 2, 2, 2,
4410+ 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1,
4411+ 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
4412+];
4413+
4414+/// lane-interintra r1: non-wedge interintra prediction for one plane
4415+/// (reconinter.c `av1_build_interintra_predictor` + `combine_interintra` +
4416+/// `build_smooth_interintra_mask`). Builds the intra predictor for the
4417+/// block's II mode (DC/V/H/SMOOTH, angle 0, no filter-intra) from `plane`'s
4418+/// own decoded edges at `(x, y)`, then blends it over the inter prediction
4419+/// in `pred`: `comp = (mask*intra + (64-mask)*inter + 32) >> 6`
4420+/// (`aom_blend_a64_mask`, intra as src0). `ii_size_scales[plane_bsize]`
4421+/// reduces to `128 / side` for the square plane sizes this decoder reaches.
4422+fn interintra_blend(plane: &PlaneBuf, x: usize, y: usize, side: usize, ii_mode: u8, pred: &mut [u8]) {
4423+ // `interintra_to_intra_mode`: II_DC/II_V/II_H/II_SMOOTH.
4424+ let intra_mode = match ii_mode {
4425+ 0 => crate::intra::DC_PRED,
4426+ 1 => crate::intra::V_PRED,
4427+ 2 => crate::intra::H_PRED,
4428+ _ => crate::intra::SMOOTH_PRED,
4429+ };
4430+ let (above, left, corner) = plane.edges(
4431+ x,
4432+ y,
4433+ side,
4434+ crate::encode::Reach {
4435+ above_right: false,
4436+ below_left: false,
4437+ },
4438+ );
4439+ let mut intra = vec![0u8; side * side];
4440+ // Edge filtering never applies here: V/H at delta 0 are plain edge
4441+ // copies (angle 90/180 skip the directional walk), DC/SMOOTH carry no
4442+ // angle at all.
4443+ predict(
4444+ intra_mode,
4445+ 0,
4446+ above.as_deref(),
4447+ left.as_deref(),
4448+ corner,
4449+ side,
4450+ false,
4451+ false,
4452+ &mut intra,
4453+ );
4454+ let scale = 128 / side;
4455+ for i in 0..side {
4456+ for j in 0..side {
4457+ let m = u32::from(match ii_mode {
4458+ 0 => 32,
4459+ 1 => II_WEIGHTS_1D[i * scale],
4460+ 2 => II_WEIGHTS_1D[j * scale],
4461+ _ => II_WEIGHTS_1D[i.min(j) * scale],
4462+ });
4463+ let idx = i * side + j;
4464+ pred[idx] =
4465+ ((m * u32::from(intra[idx]) + (64 - m) * u32::from(pred[idx]) + 32) >> 6) as u8;
4466+ }
4467+ }
4468+}
4469+
4381 fn obmc_blend_v(dst: &mut [u8], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u8]) {4470 fn obmc_blend_v(dst: &mut [u8], stride: usize, ox: usize, oy: usize, w: usize, h: usize, tmp: &[u8]) {
4382 let mask = obmc_mask(h);4471 let mask = obmc_mask(h);
4383 for row in 0..h {4472 for row in 0..h {
@@ -5642,14 +5731,26 @@ fn decode_inter_block(
5642 // branch produces -- NEARESTMV/NEARMV/GLOBALMV/NEWMV -- is5731 // branch produces -- NEARESTMV/NEARMV/GLOBALMV/NEWMV -- is
5643 // `SINGLE_INTER_MODE_START..END` by construction).5732 // `SINGLE_INTER_MODE_START..END` by construction).
5644 // `size_group_lookup`: BLOCK_16X16 -> 2, BLOCK_32X32 -> 3.5733 // `size_group_lookup`: BLOCK_16X16 -> 2, BLOCK_32X32 -> 3.
5734+ let mut interintra_mode: Option<u8> = None;
5645 if enable_interintra_compound && !skip_mode && (side == 16 || side == 32) {5735 if enable_interintra_compound && !skip_mode && (side == 16 || side == 32) {
5646 let bsize_group = if side == 16 { 2 } else { 3 };5736 let bsize_group = if side == 16 { 2 } else { 3 };
5647 let interintra = dec.symbol(&mut cdfs.interintra[bsize_group]) == 1;5737 let interintra = dec.symbol(&mut cdfs.interintra[bsize_group]) == 1;
5648 if interintra {5738 if interintra {
5649- return Err(unsupported(5739+ // lane-interintra r1 (decodemv.c 1540-1555): interintra_mode,
5650- "an interintra-compound block (interintra == 1, inter+intra \5740+ // then -- gated on block size ALONE, never the
5651- blended prediction unimplemented)",5741+ // `enable_interintra_wedge` seq bit -- the wedge flag
5652- ));5742+ // (`av1_is_wedge_used(bsize)` holds for 16x16/32x32).
5743+ let ii = dec.symbol(&mut cdfs.interintra_mode[bsize_group]) as u8;
5744+ let wedge_bsize = if side == 16 { 6 } else { 9 };
5745+ let wedge = dec.symbol(&mut cdfs.wedge_interintra[wedge_bsize]) == 1;
5746+ if wedge {
5747+ return Err(unsupported(
5748+ "a wedge-interintra block (use_wedge_interintra == 1, \
5749+ wedge-masked blending unimplemented)",
5750+ ));
5751+ }
5752+ INTERINTRA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
5753+ interintra_mode = Some(ii);
5653 }5754 }
5654 }5755 }
5655 if std::env::var_os("EC_AV1_TELL").is_some() {5756 if std::env::var_os("EC_AV1_TELL").is_some() {
@@ -5679,8 +5780,12 @@ fn decode_inter_block(
5679 // from an `OBMC_CAUSAL`-only one (2-symbol `obmc_cdf`) whenever5780 // from an `OBMC_CAUSAL`-only one (2-symbol `obmc_cdf`) whenever
5680 // the header allows warp -- reading the wrong alphabet desyncs5781 // the header allows warp -- reading the wrong alphabet desyncs
5681 // the tile.5782 // the tile.
5783+ // An interintra block has `ref_frame[1] == INTRA_FRAME`, which
5784+ // fails libaom's `is_motion_variation_allowed_compound`: the
5785+ // motion_mode symbol is NOT read (SIMPLE_TRANSLATION implied).
5682 let motion_mode_eligible = switchable_motion_mode5786 let motion_mode_eligible = switchable_motion_mode
5683 && !skip_mode5787 && !skip_mode
5788+ && interintra_mode.is_none()
5684 && (!overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).is_empty()5789 && (!overlappable_above(grid, mi_row, mi_col, bw4, mi_cols as usize, 1).is_empty()
5685 || !overlappable_left(grid, mi_row, mi_col, bw4, mi_rows as usize, 1)5790 || !overlappable_left(grid, mi_row, mi_col, bw4, mi_rows as usize, 1)
5686 .is_empty());5791 .is_empty());
@@ -5833,7 +5938,13 @@ fn decode_inter_block(
5833 MiInfo {5938 MiInfo {
5834 is_inter: true,5939 is_inter: true,
5835 ref_frame,5940 ref_frame,
5836- ref_frame1: None,5941+ // An interintra block records ref_frame[1] ==
5942+ // INTRA_FRAME (0): warp-sample gathering
5943+ // (libaom av1_findSamples, mvref_common.c:1155)
5944+ // requires ref_frame[1] == NONE_FRAME, so such a
5945+ // neighbour must not donate samples or count in
5946+ // num_proj_ref.
5947+ ref_frame1: interintra_mode.map(|_| 0),
5837 mv1: None,5948 mv1: None,
5838 mv,5949 mv,
5839 is_new_mv,5950 is_new_mv,
@@ -5931,6 +6042,16 @@ fn decode_inter_block(
5931 )?;6042 )?;
5932 }6043 }
5933 6044
6045+ // Mutually exclusive with warp/OBMC (motion_mode is not read for
6046+ // an interintra block): blend the intra predictor over the MC
6047+ // result, all planes (reconinter.c av1_build_interintra_predictor
6048+ // plane loop).
6049+ if let Some(ii) = interintra_mode {
6050+ interintra_blend(y, px, py, side, ii, &mut pred_y);
6051+ interintra_blend(u, cpx, cpy, chroma_side, ii, &mut pred_u);
6052+ interintra_blend(v, cpx, cpy, chroma_side, ii, &mut pred_v);
6053+ }
6054+
5934 if skip {6055 if skip {
5935 y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);6056 y.reconstruct_mc(px, py, side, &pred_y, &vec![0i32; side * side]);
5936 u.reconstruct_mc(6057 u.reconstruct_mc(
@@ -6723,13 +6844,23 @@ fn decode_inter_block8(
6723 // `is_interintra_allowed_bsize`-eligible, single-ref-only branch6844 // `is_interintra_allowed_bsize`-eligible, single-ref-only branch
6724 // (compound already returned above), GLOBALMV already refused6845 // (compound already returned above), GLOBALMV already refused
6725 // (round 3), so the only real gate left is the header enable bit.6846 // (round 3), so the only real gate left is the header enable bit.
6847+ let mut interintra_mode: Option<u8> = None;
6726 if enable_interintra_compound && !skip_mode {6848 if enable_interintra_compound && !skip_mode {
6727 let interintra = dec.symbol(&mut cdfs.interintra[SIZE_GROUP_8]) == 1;6849 let interintra = dec.symbol(&mut cdfs.interintra[SIZE_GROUP_8]) == 1;
6728 if interintra {6850 if interintra {
6729- return Err(unsupported(6851+ // lane-interintra r1: same read pair as the 16/32 site;
6730- "an interintra-compound block (interintra == 1, inter+intra \6852+ // wedge cdf row = BLOCK_8X8 (index 3), read on block size
6731- blended prediction unimplemented)",6853+ // alone, never the `enable_interintra_wedge` seq bit.
6732- ));6854+ let ii = dec.symbol(&mut cdfs.interintra_mode[SIZE_GROUP_8]) as u8;
6855+ let wedge = dec.symbol(&mut cdfs.wedge_interintra[3]) == 1;
6856+ if wedge {
6857+ return Err(unsupported(
6858+ "a wedge-interintra block (use_wedge_interintra == 1, \
6859+ wedge-masked blending unimplemented)",
6860+ ));
6861+ }
6862+ INTERINTRA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
6863+ interintra_mode = Some(ii);
6733 }6864 }
6734 }6865 }
6735 // lane-motionmode round 3: `read_motion_mode` (spec 5.11.24) at the6866 // lane-motionmode round 3: `read_motion_mode` (spec 5.11.24) at the
@@ -6741,6 +6872,7 @@ fn decode_inter_block8(
6741 // refusal (warp needs `av1_findSamples`, not ported at either leaf).6872 // refusal (warp needs `av1_findSamples`, not ported at either leaf).
6742 let motion_mode_eligible = switchable_motion_mode6873 let motion_mode_eligible = switchable_motion_mode
6743 && !skip_mode6874 && !skip_mode
6875+ && interintra_mode.is_none()
6744 && (!overlappable_above(grid, mi_row, mi_col, 2, mi_cols as usize, 1).is_empty()6876 && (!overlappable_above(grid, mi_row, mi_col, 2, mi_cols as usize, 1).is_empty()
6745 || !overlappable_left(grid, mi_row, mi_col, 2, mi_rows as usize, 1).is_empty());6877 || !overlappable_left(grid, mi_row, mi_col, 2, mi_rows as usize, 1).is_empty());
6746 let mut obmc_selected = false;6878 let mut obmc_selected = false;
@@ -6785,7 +6917,9 @@ fn decode_inter_block8(
6785 MiInfo {6917 MiInfo {
6786 is_inter: true,6918 is_inter: true,
6787 ref_frame: LAST_FRAME,6919 ref_frame: LAST_FRAME,
6788- ref_frame1: None,6920+ // INTRA_FRAME marker for interintra blocks -- keeps
6921+ // them out of warp-sample gathering (see 16/32 site).
6922+ ref_frame1: interintra_mode.map(|_| 0),
6789 mv1: None,6923 mv1: None,
6790 mv,6924 mv,
6791 is_new_mv,6925 is_new_mv,
@@ -6859,6 +6993,14 @@ fn decode_inter_block8(
6859 )?;6993 )?;
6860 }6994 }
6861 6995
6996+ // Non-wedge interintra blend, mutually exclusive with OBMC (the
6997+ // motion_mode symbol is not read for an interintra block).
6998+ if let Some(ii) = interintra_mode {
6999+ interintra_blend(y, px, py, SIDE, ii, &mut pred_y);
7000+ interintra_blend(u, cpx, cpy, CHROMA_SIDE, ii, &mut pred_u);
7001+ interintra_blend(v, cpx, cpy, CHROMA_SIDE, ii, &mut pred_v);
7002+ }
7003+
6862 if skip {7004 if skip {
6863 y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]);7005 y.reconstruct_mc(px, py, SIDE, &pred_y, &vec![0i32; SIDE * SIDE]);
6864 u.reconstruct_mc(7006 u.reconstruct_mc(
crates/ec-av1/src/mvstack.rsmodified+4 -0
@@ -1293,6 +1293,10 @@ fn process_compound_ref_mv_candidate(
1293 Some((candidate.ref_frame, candidate.mv)),1293 Some((candidate.ref_frame, candidate.mv)),
1294 candidate1294 candidate
1295 .ref_frame11295 .ref_frame1
1296+ // An interintra neighbour stores INTRA_FRAME (0) here; libaom's
1297+ // ref-diff scan requires `can_rf > INTRA_FRAME`
1298+ // (process_compound_ref_mv_candidate), so it contributes nothing.
1299+ .filter(|&rf1| rf1 > 0)
1296 .map(|rf1| (rf1, candidate.mv1.unwrap_or((0, 0)))),1300 .map(|rf1| (rf1, candidate.mv1.unwrap_or((0, 0)))),
1297 ];1301 ];
1298 for (candidate_ref, candidate_mv) in slots.into_iter().flatten() {1302 for (candidate_ref, candidate_mv) in slots.into_iter().flatten() {
crates/ec-av1/src/stream.rsmodified+194 -2
@@ -3468,12 +3468,189 @@ mod tests {
3468 );3468 );
3469 }3469 }
3470 3470
3471+ /// lane-interintra r1: `--enable-interintra-comp=1` streams must DECODE
3472+ /// pixel-exact -- the interintra flag/mode/wedge-flag syntax and the
3473+ /// non-wedge smooth blend are ported. A refusal naming interintra fails
3474+ /// the gate UNLESS it is the wedge refusal (`use_wedge_interintra == 1`
3475+ /// is r2, and this recipe encodes with wedge off so it must not fire
3476+ /// either); warp/obmc are enabled and supported; refusals for OTHER
3477+ /// named capabilities (screen content tools) still skip that seed. The
3478+ /// sweep must actually exercise interintra (`interintra_hits > 0`).
3479+ #[test]
3480+ fn a_real_aomenc_stream_with_interintra_decodes_pixel_exact() {
3481+ const NAME: &str = "a_real_aomenc_stream_with_interintra_decodes_pixel_exact";
3482+ let _gate_lock = lock_gate_counters();
3483+ if !have_ffmpeg() {
3484+ eprintln!("SKIP {NAME}: no ffmpeg");
3485+ return;
3486+ }
3487+ if !have_aomenc() {
3488+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
3489+ return;
3490+ }
3491+ let (width, height, frame_count) = (64usize, 64usize, 24usize);
3492+ let mut named_refusals = 0u32;
3493+ let mut matched = 0u32;
3494+ let n_attempts: u32 = std::env::var("EC_INTERINTRA_GATE_ATTEMPTS")
3495+ .ok()
3496+ .and_then(|s| s.parse().ok())
3497+ .unwrap_or(40);
3498+ for attempt in 0..n_attempts {
3499+ let seed = 42 + attempt;
3500+ let duration = frame_count as f64 / 25.0;
3501+ let source =
3502+ format!("gradients=size={width}x{height}:seed={seed}:duration={duration}:rate=25");
3503+ let y4m = Command::new("ffmpeg")
3504+ .args([
3505+ "-v",
3506+ "error",
3507+ "-f",
3508+ "lavfi",
3509+ "-i",
3510+ &source,
3511+ "-pix_fmt",
3512+ "yuv420p",
3513+ "-f",
3514+ "yuv4mpegpipe",
3515+ "-",
3516+ ])
3517+ .stdin(Stdio::null())
3518+ .stdout(Stdio::piped())
3519+ .stderr(Stdio::piped())
3520+ .output()
3521+ .expect("ffmpeg failed to run");
3522+ assert!(
3523+ y4m.status.success(),
3524+ "ffmpeg fixture: {}",
3525+ String::from_utf8_lossy(&y4m.stderr)
3526+ );
3527+ let args: Vec<&str> = vec![
3528+ "--codec=av1",
3529+ "--passes=1",
3530+ "--end-usage=q",
3531+ "--cq-level=45",
3532+ "--cpu-used=0",
3533+ "--kf-max-dist=1000",
3534+ "--threads=1",
3535+ "--row-mt=0",
3536+ "--auto-alt-ref=1",
3537+ "--lag-in-frames=16",
3538+ "--enable-fwd-kf=0",
3539+ "--enable-order-hint=1",
3540+ "--enable-warped-motion=1",
3541+ "--enable-obmc=1",
3542+ "--tune-content=default",
3543+ "--enable-masked-comp=0",
3544+ "--enable-interintra-comp=1",
3545+ "--enable-onesided-comp=0",
3546+ "--enable-interintra-wedge=0",
3547+ "--enable-smooth-interintra=1",
3548+ "--enable-rect-partitions=0",
3549+ "--enable-ab-partitions=0",
3550+ "--enable-1to4-partitions=0",
3551+ "--enable-filter-intra=0",
3552+ "--enable-smooth-intra=0",
3553+ "--enable-paeth-intra=0",
3554+ "--enable-directional-intra=0",
3555+ "--enable-angle-delta=0",
3556+ "--enable-tx-size-search=0",
3557+ "--enable-cdef=0",
3558+ "--enable-restoration=0",
3559+ "--max-partition-size=32",
3560+ "--min-partition-size=32",
3561+ "--enable-palette=0",
3562+ "--enable-intrabc=0",
3563+ "--enable-cfl-intra=0",
3564+ "--enable-ref-frame-mvs=0",
3565+ "--obu",
3566+ "-o",
3567+ "-",
3568+ "-",
3569+ ];
3570+ let mut child = Command::new(aomenc_path())
3571+ .args(&args)
3572+ .stdin(Stdio::piped())
3573+ .stdout(Stdio::piped())
3574+ .stderr(Stdio::piped())
3575+ .spawn()
3576+ .expect("aomenc failed to start");
3577+ child
3578+ .stdin
3579+ .take()
3580+ .expect("aomenc stdin")
3581+ .write_all(&y4m.stdout)
3582+ .expect("writing y4m to aomenc");
3583+ let out = child.wait_with_output().expect("aomenc failed to run");
3584+ assert!(
3585+ out.status.success(),
3586+ "aomenc refused the fixture: {}",
3587+ String::from_utf8_lossy(&out.stderr)
3588+ );
3589+ let stream = out.stdout;
3590+ let frames = match decode_stream(&stream) {
3591+ Err(e) => {
3592+ let msg = e.to_string();
3593+ assert!(
3594+ msg.contains("unsupported"),
3595+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
3596+ );
3597+ assert!(
3598+ !msg.contains("warp"),
3599+ "{NAME} refused on warp (seed {seed}) -- warp decode is ported, this \
3600+ refusal must not exist: {msg}"
3601+ );
3602+ assert!(
3603+ !msg.contains("interintra"),
3604+ "{NAME} refused on interintra (seed {seed}) -- non-wedge interintra \
3605+ is ported and this recipe encodes with wedge off: {msg}"
3606+ );
3607+ named_refusals += 1;
3608+ eprintln!("seed {seed} refusal (non-warp capability): {msg}");
3609+ continue;
3610+ }
3611+ Ok(frames) => frames,
3612+ };
3613+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
3614+ assert_eq!(frames.len(), frame_count);
3615+ let mismatched = frames
3616+ .iter()
3617+ .zip(&ffmpeg_frames)
3618+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
3619+ if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
3620+ std::fs::write(&path, &stream).expect("writing pinned stream");
3621+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
3622+ }
3623+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
3624+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})");
3625+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
3626+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
3627+ }
3628+ matched += 1;
3629+ }
3630+ assert!(
3631+ matched > 0,
3632+ "{NAME}: every attempt refused on other capabilities; the gate never exercised warp"
3633+ );
3634+ assert!(
3635+ crate::decode::interintra_hits() > 0,
3636+ "{NAME}: {matched} matches but zero interintra blocks fired -- the gate decodes \
3637+ these streams without ever taking interintra, so it proves nothing"
3638+ );
3639+ eprintln!(
3640+ "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches out of {n_attempts}, interintra_hits={}",
3641+ crate::decode::interintra_hits()
3642+ );
3643+ }
3644+
3645+
3471 /// Pinned streams captured by `EC_AV1_GATE_DUMP` off3646 /// Pinned streams captured by `EC_AV1_GATE_DUMP` off
3472 /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each3647 /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each
3473 /// one is a former mismatch, kept as a regression pin (warp-mismatch:3648 /// one is a former mismatch, kept as a regression pin (warp-mismatch:
3474 /// the WARPED_CAUSAL interp-read suppression; warp-flake-7: the same3649 /// the WARPED_CAUSAL interp-read suppression; warp-flake-7: the same
3475 /// suppression for skip_mode blocks; warp-flake-5: mvstack entry3650 /// suppression for skip_mode blocks; warp-flake-5: mvstack entry
3476- /// clamping). `EC_AV1_GATE_DUMP_PIN` overrides to a single stream.3651+ /// clamping; ii-flake-1..8: interintra neighbours excluded from
3652+ /// warp-sample gathering, ref_frame[1] == INTRA_FRAME in the mi grid).
3653+ /// `EC_AV1_GATE_DUMP_PIN` overrides to a single stream.
3477 /// Deterministic and static -- `#[ignore]`d because the gitignored3654 /// Deterministic and static -- `#[ignore]`d because the gitignored
3478 /// fixtures dir may be absent; run manually.3655 /// fixtures dir may be absent; run manually.
3479 #[test]3656 #[test]
@@ -3486,7 +3663,22 @@ mod tests {
3486 let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures");3663 let fixtures = concat!(env!("CARGO_MANIFEST_DIR"), "/../../fixtures");
3487 let paths: Vec<String> = match std::env::var("EC_AV1_GATE_DUMP_PIN") {3664 let paths: Vec<String> = match std::env::var("EC_AV1_GATE_DUMP_PIN") {
3488 Ok(p) => vec![p],3665 Ok(p) => vec![p],
3489- Err(_) => ["warp-mismatch", "warp-flake-5", "warp-flake-7"]3666+ Err(_) => [
3667+ "warp-mismatch",
3668+ "warp-flake-5",
3669+ "warp-flake-7",
3670+ "ii-flake-1",
3671+ "ii-flake-2",
3672+ "ii-flake-3",
3673+ "ii-flake-5",
3674+ "ii-flake-6",
3675+ "ii-flake-7",
3676+ "ii-flake-8",
3677+ // switchable_interp missing from reset_counts (counter
3678+ // saturation slowed the adaptation rate) -- unrelated to
3679+ // interintra, caught by the same gate.
3680+ "ii-flake-9",
3681+ ]
3490 .iter()3682 .iter()
3491 .map(|n| format!("{fixtures}/{n}.obu"))3683 .map(|n| format!("{fixtures}/{n}.obu"))
3492 .collect(),3684 .collect(),
lanes/interintra-r1.charter.mdadded+64 -0
@@ -0,0 +1,64 @@
1+# lane-interintra r1 charter — implement non-wedge interintra prediction (decode)
2+
3+## Where you are
4+Worktree /home/user/Documents/Code/Rust/edith_codecs-interintra, branch lane-interintra @ 8f90552.
5+Build/test ONLY: `env CARGO_TARGET_DIR=$HOME/.cache/cargo-target-interintra cargo test -p ec-av1 --release --lib <name> -- --nocapture`
6+Never plain workspace cargo test; never touch other worktrees; never push; fixtures/ is a symlink — never write into it except NEW pinned .obu streams captured by a gate.
7+
8+## Current state (do not re-derive)
9+- The interintra SYMBOL is consumed and interintra==1 is a NAMED refusal at
10+ crates/ec-av1/src/decode.rs:5645-5654 (single-ref path, side 16/32, gated
11+ enable_interintra_compound && !skip_mode). This round replaces the refusal with the port.
12+- Warp/OBMC/skip_mode/interp-suppression all landed and merged — leave them alone.
13+- Reference: libaom at /tmp/libaom-src (decodemv.c read_interintra_mode_info ~1100,
14+ reconinter.c av1_build_interintra_predictor / combine_interintra,
15+ reconintra.c av1_build_intra_predictors_for_interintra). Patched aomdec (EC_TRACE2 prints)
16+ builds in /tmp/libaom-build; libaom examples/inspect exists there for ground truth
17+ (wrap OBU in IVF first: ffmpeg -i x.obu -c copy x.ivf). ffmpeg is the pixel oracle.
18+
19+## Scope, r1 = NON-WEDGE interintra only
20+1. Syntax (decodemv.c read_interintra_mode_info): after interintra==1 read
21+ interintra_mode (4-ary, interintra_mode_cdf[size_group]); if seq
22+ enable_interintra_wedge && bsize in wedge-allowed set: read wedge_interintra flag —
23+ if THAT reads 1, keep a NAMED refusal ("wedge interintra unimplemented") for r2;
24+ wedge flag 0 → non-wedge path below. CDFs: interintra_mode + wedge_interintra flags
25+ exist in libaom's default tables — add to cdf.rs/cdf_state.rs mirroring how the
26+ interintra flag CDF was added (grep cdfs.interintra for the pattern; remember CDF
27+ adaptation: new tables join the adapt map the same way).
28+2. Semantics: ref_frame[1] = INTRA_FRAME. CRITICAL cross-cutting sweep (class
29+ tx-class-cross-cutting + neighbour-votes-all-its-fields): interintra blocks are
30+ single-ref for mvstack purposes but their neighbour RECORD carries ref1=INTRA_FRAME
31+ in libaom — grep every context gathered from ref1/compound-ness (comp_inter ctx,
32+ comp_ref ctx, filter ctx ref-match) and match libaom's read of an interintra
33+ neighbour. motion_mode is NOT read for interintra blocks (ref_frame[1]==INTRA_FRAME
34+ fails is_motion_variation_allowed) — the current code reads motion_mode after the
35+ refusal site; make interintra==1 skip that read exactly as libaom does.
36+3. Prediction (reconinter.c): build the intra predictor for the block's interintra mode
37+ (II_DC/II_V/II_H/II_SMOOTH map to DC/V/H/SMOOTH intra preds with
38+ use_filter_intra=0, from the block's own above/left recon like a normal intra block),
39+ then combine_interintra: weighted blend of inter and intra preds with the
40+ ii_weights_1d table (mode-dependent direction), all planes (chroma at subsampled
41+ size; interintra applies to chroma too — check av1_build_interintra_predictor plane loop).
42+4. Gate: clone the warp gate shape (stream.rs a_real_aomenc_stream_with_warped_motion_
43+ refuses_or_matches, ~3311): new test a_real_aomenc_stream_with_interintra_decodes_
44+ pixel_exact with aomenc flags from that gate BUT --enable-interintra-comp=1
45+ --enable-interintra-wedge=0 --enable-smooth-interintra=1, warp/obmc ON (they are
46+ supported now); non-wedge interintra refusals FORBIDDEN, wedge refusal allowed
47+ (should not fire with wedge=0), EC_AV1_GATE_DUMP self-pin on mismatch, and assert the
48+ interintra counter fired (add an INTERINTRA_HITS atomic like WARP_SELECTED_HITS).
49+5. Any pixel mismatch: pin the stream (cp into fixtures/), diff with
50+ /tmp/libaom-build/examples/inspect + patched aomdec EC_TRACE2, range-ladder first
51+ (TRACE part32_pre rng= exists under EC_AV1_TRACE; aomdec prints EC_PART rng=):
52+ ranges exact everywhere = prediction-side; divergent = consumption. Fix, rerun.
53+
54+## Done criteria
55+1. New interintra gate green with interintra blocks actually fired (counter > 0), run 3x.
56+2. Existing suite: `cargo test -p ec-av1 --release --lib` 217+ passed, 0 failed.
57+3. All work committed to lane-interintra (`wip(av1): interintra r1 ...`), even on HANDOFF.
58+4. REPORT FILE lanes/interintra-r1.report.md, verdict FIRST line, evidence excerpts.
59+
60+## Hard rules
61+<=60 tool calls. AT CALL 45: commit whatever compiles + write the report as HANDOFF.
62+Charter-sized: if the port cannot fit, land syntax+semantics (entropy-exact, prediction
63+still refused by name) as r1 and hand prediction to r2 — an entropy-exact refusal is
64+mergeable progress; a half-blended prediction is not.
lanes/interintra-r1.report.mdadded+62 -0
@@ -0,0 +1,62 @@
1+# lane-interintra r1 report
2+
3+VERDICT: PASS — non-wedge interintra decodes pixel-exact; two defects found and fixed en route.
4+
5+## What landed (commit 277b9a0 on lane-interintra)
6+1. **Interintra syntax + prediction** (charter scope): interintra flag →
7+ interintra_mode (4-ary, size-group CDF) → wedge flag (bsize-row CDF;
8+ wedge==1 remains a NAMED refusal for r2). Non-wedge blend
9+ `(mask*intra + (64-mask)*inter + 32) >> 6` with ii_weights1d
10+ (II_DC=const 32, II_V/H/SMOOTH from the 1-D falloff, scale 128/side),
11+ all planes, on both the 16/32 single-ref path and the 8x8 leaf.
12+ motion_mode is not read for interintra blocks. New CDFs joined
13+ cdf.rs/cdf_state.rs including reset_counts and per-frame save/restore.
14+2. **Defect 1 (ii-flake-1..8): interintra neighbours donated warp samples.**
15+ libaom `av1_findSamples` (mvref_common.c:1155) requires
16+ `ref_frame[1] == NONE_FRAME`; an interintra neighbour carries
17+ ref1=INTRA_FRAME and is excluded. Our mi grid recorded it as plain
18+ single-ref → extra warp sample → invalid projection → translation
19+ fallback → pixel drift on the next WARPED_CAUSAL block. Fix: grid
20+ records `ref_frame1 = Some(0)` for interintra blocks (both grid.set
21+ sites); `find_samples`' existing `ref_frame1.is_none()` filter then
22+ matches libaom, and `num_proj_ref` (same function) with it. The
23+ mvstack compound ref-diff scan gained a `rf1 > 0` guard mirroring
24+ libaom's `can_rf > INTRA_FRAME`; all other ref_frame1 consumers compare
25+ against real refs 1..7 or require mv1 and are inert to the marker.
26+3. **Defect 2 (ii-flake-9, NOT interintra): `switchable_interp` missing
27+ from `Cdfs::reset_counts`.** libaom zeroes every CDF counter when the
28+ adapted context is saved at frame end (`av1_reset_cdf_symbol_counters`,
29+ decodeframe.c:5588). Ours never reset this one table's counters, so
30+ after >15 accumulated reads the update rate slowed to >>5 while aom
31+ stayed at >>4; the rows drifted a few counts apart and the filter read
32+ flaked only on read-dense streams. Localization: range ladder exact
33+ into the block, post_motion_mode range equal, post_interp_filter range
34+ divergent; per-read CDF dumps showed equal values but step +9 (ours) vs
35+ +16 (aom) on ctx 8. Field-list audit (script vs struct): no other Cdfs
36+ field is missing from reset_counts; MvComponentCdfs fully covered.
37+
38+## Evidence
39+- Pinned streams: 11/11 byte-exact in one run (`pinned_warp_stream_decodes_pixel_exact`,
40+ fixtures warp-mismatch, warp-flake-5/7, ii-flake-1,2,3,5,6,7,8,9).
41+- Interintra gate `a_real_aomenc_stream_with_interintra_decodes_pixel_exact`:
42+ 12/12 hammer clean post-fix (23–33 exact of 40 seeds, rest =
43+ screen-content refusals; interintra_hits 11–22 per run; before the
44+ fixes: 7/8 runs failed).
45+- Warp gate 3/3 post-fix (counter reset touches all switchable-filter streams).
46+- Full `cargo test -p ec-av1 --release --lib`: 218 passed, 0 failed.
47+
48+## Verification note
49+Cross-provider seats exhausted/stalling (opencode-go monthly, kimi-code 5h,
50+zai flash timeouts); orchestrator verified source-level against libaom C
51+directly (decodemv.c read_interintra_mode_info, reconinter.c
52+combine_interintra, mvref_common.c av1_findSamples,
53+entropy.c av1_reset_cdf_symbol_counters) — same fallback as warp close,
54+documented per standing rule.
55+
56+## Classes
57+- Defect 1 = neighbour-votes-all-its-fields + symbol-consumption-gap's
58+ prediction-side kin (range ladder exact ⇒ prediction defect).
59+- Defect 2 = NEW CLASS: adaptation-state half of the CDF contract —
60+ values right, counter wrong; presents as a late, content-dependent
61+ rotating flake exactly like a consumption gap but with an exact range
62+ ladder up to the divergent read. Memory written: cdf-counter-not-reset.