forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-fintra' (88c5ef0f): filter intra as an intra-search candidate, default on; enable_filter_intra threaded through every raw decode of the encoder's own tiles

Browse files at this commit

9b5376d7bbf7ddbfcd274cfcaf2a7dabf7ed77f7Ahmet Kaan GümüşParent: f60b30248bcb5c
Native table: film A +53.2/+23.4 -> +52.8/+23.3, film B +81.5/+46.5 ->
+81.0/+46.1, screen flat. Pins 7373 / 27074. Six gate decodes passed a
literal false for the header bit (stale-header class, swept).
crates/ec-av1/src/decode.rsmodified+103 -12
@@ -8288,7 +8288,7 @@ impl Neighbours {
8288 /// `intra_ext_tx_cdf` row a luma transform reads. A filter-intra block's8288 /// `intra_ext_tx_cdf` row a luma transform reads. A filter-intra block's
8289 /// `mode` is always `DC_PRED`, so the row comes from the FILTER-INTRA mode8289 /// `mode` is always `DC_PRED`, so the row comes from the FILTER-INTRA mode
8290 /// instead (the defect commit 1a89ed9 fixed at the square sites).8290 /// instead (the defect commit 1a89ed9 fixed at the square sites).
8291-fn fi_tx_row(mode: usize, filter_intra: Option<usize>) -> usize {8291+pub(crate) fn fi_tx_row(mode: usize, filter_intra: Option<usize>) -> usize {
8292 const FIMODE_TO_INTRADIR: [usize; 5] = [DC_PRED, V_PRED, H_PRED, D157_PRED, DC_PRED];8292 const FIMODE_TO_INTRADIR: [usize; 5] = [DC_PRED, V_PRED, H_PRED, D157_PRED, DC_PRED];
8293 filter_intra.map_or(mode, |fi| FIMODE_TO_INTRADIR[fi])8293 filter_intra.map_or(mode, |fi| FIMODE_TO_INTRADIR[fi])
8294 }8294 }
@@ -8296,7 +8296,7 @@ fn fi_tx_row(mode: usize, filter_intra: Option<usize>) -> usize {
8296 /// A block-size class index into [`cdf::FILTER_INTRA`]/`Cdfs::filter_intra`,8296 /// A block-size class index into [`cdf::FILTER_INTRA`]/`Cdfs::filter_intra`,
8297 /// or `None` when `side` is past `av1_filter_intra_allowed_bsize`'s <=328297 /// or `None` when `side` is past `av1_filter_intra_allowed_bsize`'s <=32
8298 /// bound (spec `filter_intra_mode_info` never reads a symbol there).8298 /// bound (spec `filter_intra_mode_info` never reads a symbol there).
8299-fn filter_intra_size_class(side: usize) -> Option<usize> {8299+pub(crate) fn filter_intra_size_class(side: usize) -> Option<usize> {
8300 match side {8300 match side {
8301 4 => Some(0),8301 4 => Some(0),
8302 8 => Some(1),8302 8 => Some(1),
@@ -33480,7 +33480,9 @@ pub(crate) fn decode_inter_frame_tile(
33480 loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed,33480 loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed,
33481 enable_dual_filter, reference_select, tx_select,33481 enable_dual_filter, reference_select, tx_select,
33482 &LoopRestorationParams::default(), initial_cdfs, NO_SIGN_BIAS, false,33482 &LoopRestorationParams::default(), initial_cdfs, NO_SIGN_BIAS, false,
33483- switchable_motion_mode, false, fctx,33483+ // `enable_filter_intra`: as the `false`s beside it, this convenience
33484+ // entry names a stream written without the sequence bit (lane-fintra).
33485+ switchable_motion_mode, false, false, fctx,
33484 )33486 )
33485 }33487 }
33486 33488
@@ -33532,6 +33534,8 @@ pub(crate) fn decode_inter_frame_tile_lr(
33532 // `false` here desynced every stream this crate's encoder writes with the33534 // `false` here desynced every stream this crate's encoder writes with the
33533 // warp knob on: the same stale-header class as the parameter above.33535 // warp knob on: the same stale-header class as the parameter above.
33534 allow_warped_motion: bool,33536 allow_warped_motion: bool,
33537+ // lane-fintra: see [`decode_inter_frame_tiles_lr`]'s own parameter.
33538+ enable_filter_intra: bool,
33535 fctx: &crate::decode::FrameCtx,33539 fctx: &crate::decode::FrameCtx,
33536 ) -> Result<Picture> {33540 ) -> Result<Picture> {
33537 let single_tile = TileInfo {33541 let single_tile = TileInfo {
@@ -33562,6 +33566,7 @@ pub(crate) fn decode_inter_frame_tile_lr(
33562 allow_screen_content_tools,33566 allow_screen_content_tools,
33563 switchable_motion_mode,33567 switchable_motion_mode,
33564 allow_warped_motion,33568 allow_warped_motion,
33569+ enable_filter_intra,
33565 fctx,33570 fctx,
33566 )33571 )
33567 }33572 }
@@ -33603,6 +33608,12 @@ pub(crate) fn decode_inter_frame_tiles_lr(
33603 // `false` here desynced every stream this crate's encoder writes with the33608 // `false` here desynced every stream this crate's encoder writes with the
33604 // warp knob on: the same stale-header class as the parameter above.33609 // warp knob on: the same stale-header class as the parameter above.
33605 allow_warped_motion: bool,33610 allow_warped_motion: bool,
33611+ // lane-fintra: this sequence header's own `enable_filter_intra` bit (spec
33612+ // 5.5.2). Hard-coded `false` here until this lane -- the same stale-header
33613+ // class as `switchable_motion_mode`/`allow_warped_motion` above: the
33614+ // encoder's own trial decode desyncs at the first intra-in-inter DC_PRED
33615+ // block the moment its sequence header sets the bit.
33616+ enable_filter_intra: bool,
33606 fctx: &crate::decode::FrameCtx,33617 fctx: &crate::decode::FrameCtx,
33607 ) -> Result<Picture> {33618 ) -> Result<Picture> {
33608 decode_inter_frame_tile_with_cdfs(33619 decode_inter_frame_tile_with_cdfs(
@@ -33641,10 +33652,7 @@ pub(crate) fn decode_inter_frame_tiles_lr(
33641 allow_warped_motion,33652 allow_warped_motion,
33642 allow_screen_content_tools,33653 allow_screen_content_tools,
33643 DeltaParams::default(),33654 DeltaParams::default(),
33644- // `enable_filter_intra`: this crate's own encoder never writes the33655+ enable_filter_intra,
33645- // sequence bit (`encode.rs`), so no intra-in-inter block of a stream
33646- // reaching this entry point reads a `use_filter_intra` symbol.
33647- false,
33648 None,33656 None,
33649 fctx,33657 fctx,
33650 )33658 )
@@ -37632,7 +37640,10 @@ mod tests {
37632 base_q_idx,37640 base_q_idx,
37633 w as u32,37641 w as u32,
37634 h as u32,37642 h as u32,
37635- false,37643+ // lane-fintra: the sequence bit the encoder wrote this tile under
37644+ // (stale-header class -- a hard-coded `false` here reads one symbol
37645+ // short at the first DC_PRED block once the search offers filter intra).
37646+ crate::encode::filter_intra_on(),
37636 &cdef,37647 &cdef,
37637 &loop_filter,37648 &loop_filter,
37638 tx_select,37649 tx_select,
@@ -38002,7 +38013,10 @@ mod tests {
38002 encoded.base_q_idx,38013 encoded.base_q_idx,
38003 coded_w,38014 coded_w,
38004 coded_h,38015 coded_h,
38005- false,38016+ // lane-fintra: the sequence bit the encoder wrote this tile under
38017+ // (stale-header class -- a hard-coded `false` here reads one symbol
38018+ // short at the first DC_PRED block once the search offers filter intra).
38019+ crate::encode::filter_intra_on(),
38006 &encoded.cdef,38020 &encoded.cdef,
38007 &encoded.loop_filter,38021 &encoded.loop_filter,
38008 encoded.tx_select,38022 encoded.tx_select,
@@ -38018,6 +38032,68 @@ mod tests {
38018 }38032 }
38019 }38033 }
38020 38034
38035+ /// lane-fintra: the encoder's own filter-intra blocks, read back by BOTH
38036+ /// decoders. Two claims in one gate: the stream really exercises the tool
38037+ /// (the decoder's own `use_filter_intra == 1` counter moves, class
38038+ /// `gate-blind-to-feature` -- a feature that never fires is not measured),
38039+ /// and every sample of the frame that carries them matches ffmpeg's
38040+ /// (class `fixture-proves-symbol-not-signal`: the symbol alone would not
38041+ /// prove the recursive predictor, the tx_type row or the syntax position
38042+ /// between the palette colours and the colour-index maps).
38043+ #[test]
38044+ fn a_filter_intra_key_frame_decodes_pixel_exact_through_ffmpeg() {
38045+ let fctx = &crate::decode::FrameCtx::new();
38046+ if !crate::encode::filter_intra_on() {
38047+ eprintln!("SKIP a_filter_intra_key_frame...: EC_AV1_FILTER_INTRA=0");
38048+ return;
38049+ }
38050+ if !have_ffmpeg() {
38051+ eprintln!("SKIP a_filter_intra_key_frame...: no ffmpeg");
38052+ return;
38053+ }
38054+ let (width, height) = (128usize, 128usize);
38055+ // Smooth, slowly curving content: what the recursive filter modes are
38056+ // for, and what a plain directional prediction leaves residual on.
38057+ let mut picture = crate::encode::Picture::grey(width, height);
38058+ for row in 0..height {
38059+ for col in 0..width {
38060+ let v = 128.0
38061+ + 60.0 * ((row as f64) / 9.0).sin() * ((col as f64) / 11.0).cos()
38062+ + 8.0 * ((row + col) as f64 / 3.0).sin();
38063+ picture.y[row * width + col] = v.clamp(0.0, 255.0) as u16;
38064+ }
38065+ }
38066+ let encoded = crate::encode::encode_key_frame_with_ctx(&picture, 100, 0.5, fctx).unwrap();
38067+ let (coded_w, coded_h) = ffprobe_size(&encoded.stream);
38068+ let before = filter_intra_hits();
38069+ let ours = decode_key_frame_tile_lr(
38070+ &encoded.tile,
38071+ encoded.mi_cols,
38072+ encoded.mi_rows,
38073+ encoded.base_q_idx,
38074+ coded_w,
38075+ coded_h,
38076+ crate::encode::filter_intra_on(),
38077+ &encoded.cdef,
38078+ &encoded.loop_filter,
38079+ encoded.tx_select,
38080+ true,
38081+ encoded.screen,
38082+ encoded.allow_intrabc,
38083+ &encoded.loop_restoration,
38084+ fctx,
38085+ )
38086+ .unwrap();
38087+ let fired = filter_intra_hits() - before;
38088+ assert!(fired > 0, "no block took filter intra -- the gate is blind to the feature");
38089+ eprintln!("a_filter_intra_key_frame: {fired} filter-intra blocks");
38090+ let ffmpeg_decoded = ffmpeg_decode(&encoded.stream, coded_w as usize, coded_h as usize);
38091+ assert_eq!(ours.y, ffmpeg_decoded.y, "luma vs ffmpeg");
38092+ assert_eq!(ours.u, ffmpeg_decoded.u, "U vs ffmpeg");
38093+ assert_eq!(ours.v, ffmpeg_decoded.v, "V vs ffmpeg");
38094+ assert_eq!(ours.y, encoded.reconstruction.y, "luma vs the encoder's own reconstruction");
38095+ }
38096+
38021 /// The key frame the encoder writes carries `tx_mode == TxMode::Select`,38097 /// The key frame the encoder writes carries `tx_mode == TxMode::Select`,
38022 /// and that header bit is load-bearing for a decode of its tile: read as a38098 /// and that header bit is load-bearing for a decode of its tile: read as a
38023 /// `TxMode::Largest` frame the very first block misses its `tx_depth`38099 /// `TxMode::Largest` frame the very first block misses its `tx_depth`
@@ -38046,7 +38122,10 @@ mod tests {
38046 encoded.base_q_idx,38122 encoded.base_q_idx,
38047 width as u32,38123 width as u32,
38048 height as u32,38124 height as u32,
38049- false,38125+ // lane-fintra: the sequence bit the encoder wrote this tile under
38126+ // (stale-header class -- a hard-coded `false` here reads one symbol
38127+ // short at the first DC_PRED block once the search offers filter intra).
38128+ crate::encode::filter_intra_on(),
38050 &encoded.cdef,38129 &encoded.cdef,
38051 &encoded.loop_filter,38130 &encoded.loop_filter,
38052 tx_select,38131 tx_select,
@@ -38131,7 +38210,10 @@ mod tests {
38131 key.base_q_idx,38210 key.base_q_idx,
38132 width as u32,38211 width as u32,
38133 height as u32,38212 height as u32,
38134- false,38213+ // lane-fintra: the sequence bit the encoder wrote this tile under
38214+ // (stale-header class -- a hard-coded `false` here reads one symbol
38215+ // short at the first DC_PRED block once the search offers filter intra).
38216+ crate::encode::filter_intra_on(),
38135 &key.cdef,38217 &key.cdef,
38136 &key.loop_filter,38218 &key.loop_filter,
38137 key.tx_select,38219 key.tx_select,
@@ -38197,6 +38279,9 @@ mod tests {
38197 // the warp bit must be the one it wrote too (lane-av1obmc2);38279 // the warp bit must be the one it wrote too (lane-av1obmc2);
38198 // the encoder only sets it under `EC_AV1_WARP`.38280 // the encoder only sets it under `EC_AV1_WARP`.
38199 crate::encode::warp_on(),38281 crate::encode::warp_on(),
38282+ // lane-fintra: the sequence bit the encoder wrote this tile
38283+ // under -- same stale-header class as the warp bit above.
38284+ crate::encode::filter_intra_on(),
38200 fctx,38285 fctx,
38201 )38286 )
38202 .unwrap();38287 .unwrap();
@@ -38480,7 +38565,10 @@ mod tests {
38480 key.base_q_idx,38565 key.base_q_idx,
38481 coded_w,38566 coded_w,
38482 coded_h,38567 coded_h,
38483- false,38568+ // lane-fintra: the sequence bit the encoder wrote this tile under
38569+ // (stale-header class -- a hard-coded `false` here reads one symbol
38570+ // short at the first DC_PRED block once the search offers filter intra).
38571+ crate::encode::filter_intra_on(),
38484 &key.cdef,38572 &key.cdef,
38485 &key.loop_filter,38573 &key.loop_filter,
38486 key.tx_select,38574 key.tx_select,
@@ -38535,6 +38623,9 @@ mod tests {
38535 // the warp bit must be the one it wrote too (lane-av1obmc2);38623 // the warp bit must be the one it wrote too (lane-av1obmc2);
38536 // the encoder only sets it under `EC_AV1_WARP`.38624 // the encoder only sets it under `EC_AV1_WARP`.
38537 crate::encode::warp_on(),38625 crate::encode::warp_on(),
38626+ // lane-fintra: the sequence bit the encoder wrote this tile
38627+ // under -- same stale-header class as the warp bit above.
38628+ crate::encode::filter_intra_on(),
38538 fctx,38629 fctx,
38539 )38630 )
38540 .unwrap();38631 .unwrap();
crates/ec-av1/src/encode.rsmodified+187 -2
@@ -756,6 +756,46 @@ fn intra_predict_u8(
756 }756 }
757 }757 }
758 758
759+/// [`intra_predict_u8`] for recursive filter intra (spec 7.11.2.3): the same
760+/// `u8` box around [`crate::intra::predict_filter_intra`], whose `mode` is one
761+/// of the five `FILTER_INTRA_MODES` rather than an ordinary intra mode.
762+fn filter_intra_predict_u8(
763+ mode: usize,
764+ above: Option<&[u8]>,
765+ left: Option<&[u8]>,
766+ corner: Option<u8>,
767+ side: usize,
768+ dst: &mut [u8], fctx: &crate::decode::FrameCtx,
769+) {
770+ let mut above_buf = [0u16; 2 * BLOCK];
771+ let mut left_buf = [0u16; 2 * BLOCK];
772+ let widen = |src: &[u8], buf: &mut [u16; 2 * BLOCK]| {
773+ for (d, &v) in buf[..src.len()].iter_mut().zip(src) {
774+ *d = u16::from(v);
775+ }
776+ };
777+ if let Some(a) = above {
778+ widen(a, &mut above_buf);
779+ }
780+ if let Some(l) = left {
781+ widen(l, &mut left_buf);
782+ }
783+ let mut dst16 = [0u16; BLOCK * BLOCK];
784+ let n = side * side;
785+ crate::intra::predict_filter_intra(
786+ mode,
787+ above.map(|a| &above_buf[..a.len()]),
788+ left.map(|l| &left_buf[..l.len()]),
789+ corner.map(u16::from),
790+ side,
791+ side,
792+ &mut dst16[..n], fctx,
793+ );
794+ for (d, &v) in dst.iter_mut().zip(dst16[..n].iter()) {
795+ *d = v as u8;
796+ }
797+}
798+
759 /// Pads one plane to `(padded_width, padded_height)` by repeating its last799 /// Pads one plane to `(padded_width, padded_height)` by repeating its last
760 /// row and column, so the block coder always sees a whole number of blocks.800 /// row and column, so the block coder always sees a whole number of blocks.
761 /// [`crop_plane`] undoes this on the way back out.801 /// [`crop_plane`] undoes this on the way back out.
@@ -982,6 +1022,20 @@ pub(crate) fn force_screen(value: Option<bool>) {
982 SCREEN_FORCE.with(|c| c.set(value));1022 SCREEN_FORCE.with(|c| c.set(value));
983 }1023 }
984 1024
1025+// lane-fintra: [`force_screen`] for the filter-intra candidate, so a MODE
1026+// ablation can measure the mode search alone. Setting it also clears the
1027+// sequence header's own `enable_filter_intra` bit, so the stream the arm
1028+// writes is exactly the one this encoder wrote before the lane.
1029+#[cfg(test)]
1030+thread_local! {
1031+ static FILTER_INTRA_FORCE: std::cell::Cell<Option<bool>> = const { std::cell::Cell::new(None) };
1032+}
1033+
1034+#[cfg(test)]
1035+pub(crate) fn force_filter_intra(value: Option<bool>) {
1036+ FILTER_INTRA_FORCE.with(|c| c.set(value));
1037+}
1038+
985 pub(crate) fn arm_seq_screen(on: bool) {1039 pub(crate) fn arm_seq_screen(on: bool) {
986 SEQ_SCREEN.with(|c| c.set(on));1040 SEQ_SCREEN.with(|c| c.set(on));
987 }1041 }
@@ -1183,7 +1237,11 @@ pub(crate) fn key_frame_headers_colour(
1183 max_frame_width: w,1237 max_frame_width: w,
1184 max_frame_height: h,1238 max_frame_height: h,
1185 use_128x128_superblock: false,1239 use_128x128_superblock: false,
1186- enable_filter_intra: false,1240+ // lane-fintra: the encoder's intra search offers the five recursive
1241+ // filter-intra modes on eligible blocks, so the sequence bit is set
1242+ // whenever that search is on (`EC_AV1_FILTER_INTRA=0` switches both
1243+ // off and restores the streams this encoder wrote before the lane).
1244+ enable_filter_intra: filter_intra_on(),
1187 enable_intra_edge_filter: false,1245 enable_intra_edge_filter: false,
1188 enable_order_hint: true,1246 enable_order_hint: true,
1189 order_hint_bits: 7,1247 order_hint_bits: 7,
@@ -3860,6 +3918,81 @@ fn code_square(
3860 }3918 }
3861 }3919 }
3862 3920
3921+ // The five recursive filter-intra modes (spec 5.11.14), priced against
3922+ // whatever the mode, transform-depth and palette searches settled on --
3923+ // the same "one candidate loop after the incumbent is known" shape the
3924+ // palette above uses. A block that takes one is `DC_PRED` with no palette
3925+ // by construction (`av1_filter_intra_allowed`), and its luma transform
3926+ // types are coded from `fimode_to_intradir`'s row (`crate::tile::tx_row`).
3927+ //
3928+ // corner-cut, ceiling named: the candidate is only ever priced at
3929+ // `tx_depth` 0 (one transform over the whole block), so a block whose
3930+ // ordinary intra winner wanted a SPLIT transform is compared against a
3931+ // handicapped filter-intra arm -- and only 19-44% of this encoder's intra
3932+ // blocks code depth 0. Upgrade path: predict per transform unit inside
3933+ // [`Plane::code_tx_depth`] (the decoder already reads `filter_intra` per
3934+ // unit, decode.rs:11835) and run the depth search under the winning
3935+ // filter mode.
3936+ let mut filter_intra: Option<u8> = None;
3937+ if filter_intra_on()
3938+ && palette.is_none()
3939+ && let Some(class) = crate::decode::filter_intra_size_class(side)
3940+ {
3941+ let row = &cdf::FILTER_INTRA[class];
3942+ // With the sequence bit on, EVERY `DC_PRED` block without a luma
3943+ // palette carries the flag, so the incumbent pays its zero before the
3944+ // comparison -- otherwise the candidate is charged a bit the block
3945+ // spends either way (class `price-the-narrowing-not-the-table`).
3946+ if mode == DC_PRED {
3947+ cost += search.lambda * symbol_bits(row, 0);
3948+ }
3949+ let one_bits = symbol_bits(row, 1);
3950+ let kept = luma.snapshot(x, y, side);
3951+ let (mut above_buf, mut left_buf) = ([0u8; 2 * BLOCK], [0u8; 2 * BLOCK]);
3952+ let (above, left, corner) =
3953+ luma.edges_into(x, y, side, at.reach, &mut above_buf, &mut left_buf);
3954+ let mut prediction = vec![0u8; side * side];
3955+ for fi in 0..5u8 {
3956+ filter_intra_predict_u8(
3957+ usize::from(fi),
3958+ above,
3959+ left,
3960+ corner,
3961+ side,
3962+ &mut prediction, fctx,
3963+ );
3964+ let trial = luma.code_from_prediction(
3965+ x,
3966+ y,
3967+ side,
3968+ &prediction,
3969+ false,
3970+ search.base_q_idx,
3971+ search.deadzone,
3972+ luma_set,
3973+ );
3974+ let cost_f = trial.sse
3975+ + search.lambda
3976+ * (trial.bits
3977+ + mode_bits[DC_PRED as usize]
3978+ + one_bits
3979+ + symbol_bits(&cdf::FILTER_INTRA_MODE, usize::from(fi))
3980+ + if tx_select { tx_depth_bits(side, 0) } else { 0.0 });
3981+ if cost_f < cost {
3982+ cost = cost_f;
3983+ mode = DC_PRED;
3984+ angle_delta = 0;
3985+ tx_depth = 0;
3986+ luma_coeffs = coeffs(&trial.levels, side);
3987+ luma.commit(x, y, side, &trial);
3988+ filter_intra = Some(fi);
3989+ }
3990+ }
3991+ if filter_intra.is_none() {
3992+ luma.restore(x, y, side, &kept);
3993+ }
3994+ }
3995+
3863 // Chroma searches its own mode over [`CHROMA_MODES`], one symbol for both3996 // Chroma searches its own mode over [`CHROMA_MODES`], one symbol for both
3864 // planes; what it costs still counts towards the partition decision.3997 // planes; what it costs still counts towards the partition decision.
3865 let ([u, v], uv_mode, chroma_cost, palette_uv, cfl_alphas) =3998 let ([u, v], uv_mode, chroma_cost, palette_uv, cfl_alphas) =
@@ -3898,6 +4031,7 @@ fn code_square(
3898 tx_depth,4031 tx_depth,
3899 palette,4032 palette,
3900 palette_uv,4033 palette_uv,
4034+ filter_intra,
3901 cfl_alphas,4035 cfl_alphas,
3902 angle_delta_y: angle_delta as i8,4036 angle_delta_y: angle_delta as i8,
3903 ..BlockCoeffs::default()4037 ..BlockCoeffs::default()
@@ -3975,6 +4109,20 @@ fn cfl_on() -> bool {
3975 *ON.get_or_init(|| std::env::var("EC_AV1_CFL").as_deref() != Ok("0"))4109 *ON.get_or_init(|| std::env::var("EC_AV1_CFL").as_deref() != Ok("0"))
3976 }4110 }
3977 4111
4112+/// Whether the intra search offers the five recursive filter-intra modes at
4113+/// all, and with them whether the sequence header sets `enable_filter_intra`
4114+/// (`EC_AV1_FILTER_INTRA=0` switches both off, which is how the lane measured
4115+/// its own on/off pair -- and how every byte pin written before it still
4116+/// reproduces).
4117+pub(crate) fn filter_intra_on() -> bool {
4118+ #[cfg(test)]
4119+ if let Some(forced) = FILTER_INTRA_FORCE.with(std::cell::Cell::get) {
4120+ return forced;
4121+ }
4122+ static ON: std::sync::OnceLock<bool> = std::sync::OnceLock::new();
4123+ *ON.get_or_init(|| std::env::var("EC_AV1_FILTER_INTRA").as_deref() != Ok("0"))
4124+}
4125+
3978 /// Reads [`UV_MODE_HITS`] and zeroes it, so a gate can attribute the counts4126 /// Reads [`UV_MODE_HITS`] and zeroes it, so a gate can attribute the counts
3979 /// to its own encode.4127 /// to its own encode.
3980 #[cfg(test)]4128 #[cfg(test)]
@@ -5086,6 +5234,7 @@ fn code_square_inter(
5086 BlockCoeffs {5234 BlockCoeffs {
5087 angle_delta_y: 0,5235 angle_delta_y: 0,
5088 cfl_alphas: None,5236 cfl_alphas: None,
5237+ filter_intra: None,
5089 luma: coeffs(&levels, side),5238 luma: coeffs(&levels, side),
5090 u: coeffs(&u_new.levels, side / 2),5239 u: coeffs(&u_new.levels, side / 2),
5091 v: coeffs(&v_new.levels, side / 2),5240 v: coeffs(&v_new.levels, side / 2),
@@ -5121,6 +5270,7 @@ fn code_square_inter(
5121 (BlockCoeffs {5270 (BlockCoeffs {
5122 angle_delta_y: 0,5271 angle_delta_y: 0,
5123 cfl_alphas: None,5272 cfl_alphas: None,
5273+ filter_intra: None,
5124 luma: coeffs(&levels, side),5274 luma: coeffs(&levels, side),
5125 u: coeffs(&u.levels, side / 2),5275 u: coeffs(&u.levels, side / 2),
5126 v: coeffs(&v.levels, side / 2),5276 v: coeffs(&v.levels, side / 2),
@@ -6223,6 +6373,7 @@ pub(crate) fn encode_key_frame_inner(
6223 crate::tile::arm_lr(64, lr_horz, lr_vert, units.to_vec());6373 crate::tile::arm_lr(64, lr_horz, lr_vert, units.to_vec());
6224 let mut cdfs = start_cdfs.0.clone();6374 let mut cdfs = start_cdfs.0.clone();
6225 crate::tile::arm_screen(screen);6375 crate::tile::arm_screen(screen);
6376+ crate::tile::arm_filter_intra(filter_intra_on());
6226 crate::tile::arm_intrabc(allow_intrabc);6377 crate::tile::arm_intrabc(allow_intrabc);
6227 crate::tile::arm_pricing_cdfs(None, false);6378 crate::tile::arm_pricing_cdfs(None, false);
6228 let bytes = crate::tile::sb_coeff_key_frame_tile_cdfs(6379 let bytes = crate::tile::sb_coeff_key_frame_tile_cdfs(
@@ -7829,6 +7980,7 @@ fn search_inter_block(
7829 BlockCoeffs {7980 BlockCoeffs {
7830 angle_delta_y: 0,7981 angle_delta_y: 0,
7831 cfl_alphas: None,7982 cfl_alphas: None,
7983+ filter_intra: None,
7832 luma: coeffs(&levels, BLOCK),7984 luma: coeffs(&levels, BLOCK),
7833 u: coeffs(&best.u.levels, BLOCK / 2),7985 u: coeffs(&best.u.levels, BLOCK / 2),
7834 v: coeffs(&best.v.levels, BLOCK / 2),7986 v: coeffs(&best.v.levels, BLOCK / 2),
@@ -9079,6 +9231,7 @@ pub(crate) fn encode_inter_frame(
9079 crate::tile::arm_warped_motion(warped_motion);9231 crate::tile::arm_warped_motion(warped_motion);
9080 crate::tile::arm_order_hints(order_hint_bits, order_hint, order_hints);9232 crate::tile::arm_order_hints(order_hint_bits, order_hint, order_hints);
9081 crate::tile::arm_screen(screen);9233 crate::tile::arm_screen(screen);
9234+ crate::tile::arm_filter_intra(filter_intra_on());
9082 let mut cdfs = start_cdfs.0.clone();9235 let mut cdfs = start_cdfs.0.clone();
9083 crate::tile::arm_pricing_cdfs(Some(&cdfs), screen);9236 crate::tile::arm_pricing_cdfs(Some(&cdfs), screen);
9084 // Each tile's own MV grid: a candidate scan never reaches past9237 // Each tile's own MV grid: a candidate scan never reaches past
@@ -9205,6 +9358,7 @@ pub(crate) fn encode_inter_frame(
9205 h.allow_screen_content_tools,9358 h.allow_screen_content_tools,
9206 switchable_motion_mode,9359 switchable_motion_mode,
9207 h.allow_warped_motion,9360 h.allow_warped_motion,
9361+ seq.enable_filter_intra,
9208 fctx,9362 fctx,
9209 )9363 )
9210 },9364 },
@@ -10083,6 +10237,7 @@ mod tests {
10083 let residual_block = BlockCoeffs {10237 let residual_block = BlockCoeffs {
10084 angle_delta_y: 0,10238 angle_delta_y: 0,
10085 cfl_alphas: None,10239 cfl_alphas: None,
10240+ filter_intra: None,
10086 luma: vec![Coeff {10241 luma: vec![Coeff {
10087 row: 0,10242 row: 0,
10088 col: 0,10243 col: 0,
@@ -10882,6 +11037,11 @@ mod tests {
10882 eprintln!("SKIP every_mode_decodes_to_what_the_encoder_predicted: no ffmpeg");11037 eprintln!("SKIP every_mode_decodes_to_what_the_encoder_predicted: no ffmpeg");
10883 return;11038 return;
10884 }11039 }
11040+ // A mode ablation measures the MODE search: a filter-intra block is
11041+ // coded `DC_PRED` whatever mode the arm forces, so it would fail the
11042+ // "the encoder coded something else" check for a reason that is not
11043+ // about the mode search at all.
11044+ force_filter_intra(Some(false));
10885 // 128 wide is a whole number of superblocks and 160 is not: the last11045 // 128 wide is a whole number of superblocks and 160 is not: the last
10886 // superblock of a 160-wide row is half a one, whose blocks have no11046 // superblock of a 160-wide row is half a one, whose blocks have no
10887 // above-right samples inside the frame at all.11047 // above-right samples inside the frame at all.
@@ -10992,6 +11152,10 @@ mod tests {
10992 // these synthetic two-colour pictures losslessly under every arm and11152 // these synthetic two-colour pictures losslessly under every arm and
10993 // leave nothing to compare (see [`force_screen`]).11153 // leave nothing to compare (see [`force_screen`]).
10994 force_screen(Some(false));11154 force_screen(Some(false));
11155+ // Same reason, for the filter-intra candidate: it wins blocks under
11156+ // BOTH arms of a mode ablation and so cancels the difference the
11157+ // ablation measures (class `gate-recipe-confound`).
11158+ force_filter_intra(Some(false));
10995 let mut points: Vec<(f64, f64)> = [110u8, 90, 70]11159 let mut points: Vec<(f64, f64)> = [110u8, 90, 70]
10996 .iter()11160 .iter()
10997 .map(|&q| {11161 .map(|&q| {
@@ -12840,8 +13004,14 @@ mod tests {
12840 // so every block taking either codes different syntax and different13004 // so every block taking either codes different syntax and different
12841 // coefficients -- 8194 -> 7321 at q=150 and 28285 -> 27285 at q=60.13005 // coefficients -- 8194 -> 7321 at q=150 and 28285 -> 27285 at q=60.
12842 // `EC_AV1_CFL=0` / `EC_AV1_ANGLE=0` restore each half.13006 // `EC_AV1_CFL=0` / `EC_AV1_ANGLE=0` restore each half.
13007+ // Re-taken on lane-fintra: the sequence header sets
13008+ // `enable_filter_intra`, so every DC_PRED intra block of at most
13009+ // 32x32 without a luma palette carries a `use_filter_intra` flag and
13010+ // the blocks that take one code a filter-intra mode, a different
13011+ // prediction and different coefficients -- 7321 -> 7373 at q=150 and
13012+ // 27285 -> 27074 at q=60. `EC_AV1_FILTER_INTRA=0` restores these.
12843 let pins: [(u8, usize, u64); 2] =13013 let pins: [(u8, usize, u64); 2] =
12844- [(150, 7321, 0x34e2_e4e0_d7c5_09f3), (60, 27285, 0xbfd2_41af_dcac_a0c6)];13014+ [(150, 7373, 0xd0af_b890_28bc_cfbf), (60, 27074, 0x8324_0e9f_5971_e4e7)];
12845 for (q, bytes, hash) in pins {13015 for (q, bytes, hash) in pins {
12846 let encoded = encode_sequence(&source, q, 0.5).unwrap();13016 let encoded = encode_sequence(&source, q, 0.5).unwrap();
12847 assert_eq!(13017 assert_eq!(
@@ -13963,6 +14133,7 @@ mod tests {
13963 let _ = crate::tile::take_palette_uv_hits();14133 let _ = crate::tile::take_palette_uv_hits();
13964 let _ = crate::tile::take_intrabc_hits();14134 let _ = crate::tile::take_intrabc_hits();
13965 let _ = take_intrabc_search();14135 let _ = take_intrabc_search();
14136+ let _ = crate::tile::take_filter_intra_hits();
13966 // The sequence path itself codes the pyramid now14137 // The sequence path itself codes the pyramid now
13967 // (lane-av1pyrdef), and prints what it requested and what the14138 // (lane-av1pyrdef), and prints what it requested and what the
13968 // content gate left effective.14139 // content gate left effective.
@@ -14009,6 +14180,20 @@ mod tests {
14009 search[1],14180 search[1],
14010 search[2],14181 search[2],
14011 );14182 );
14183+ // gate-blind-to-feature: how often the five recursive filter-intra
14184+ // modes actually won a block over this clip's four encodes -- a
14185+ // tool that never fires is not measured by the row above it.
14186+ let fi = crate::tile::take_filter_intra_hits();
14187+ eprintln!(
14188+ "{name}: filter intra on={} blocks {} (modes DC={} V={} H={} D157={} PAETH={})",
14189+ filter_intra_on(),
14190+ fi[0],
14191+ fi[1],
14192+ fi[2],
14193+ fi[3],
14194+ fi[4],
14195+ fi[5],
14196+ );
14012 let (aom, aom_wall) = external_ladder(&source, cw, ch, "libaom-av1", &aom_points);14197 let (aom, aom_wall) = external_ladder(&source, cw, ch, "libaom-av1", &aom_points);
14013 let (rav1e, rav1e_wall) = external_ladder(&source, cw, ch, "librav1e", &rav1e_points);14198 let (rav1e, rav1e_wall) = external_ladder(&source, cw, ch, "librav1e", &rav1e_points);
14014 assert_monotone(&format!("{name}: ours"), &ours);14199 assert_monotone(&format!("{name}: ours"), &ours);
crates/ec-av1/src/stream.rsmodified+4 -1
@@ -2993,7 +2993,10 @@ pub(crate) mod tests {
2993 encoded.base_q_idx,2993 encoded.base_q_idx,
2994 width as u32,2994 width as u32,
2995 height as u32,2995 height as u32,
2996- false,2996+ // lane-fintra: the sequence bit the encoder wrote this tile under
2997+ // (stale-header class -- a hard-coded `false` here reads one symbol
2998+ // short at the first DC_PRED block once the search offers filter intra).
2999+ crate::encode::filter_intra_on(),
2997 &encoded.cdef,3000 &encoded.cdef,
2998 &encoded.loop_filter,3001 &encoded.loop_filter,
2999 encoded.tx_select,3002 encoded.tx_select,
crates/ec-av1/src/tile.rsmodified+113 -7
@@ -343,6 +343,81 @@ fn intrabc_armed() -> bool {
343 INTRABC.with(std::cell::Cell::get)343 INTRABC.with(std::cell::Cell::get)
344 }344 }
345 345
346+thread_local! {
347+ /// This SEQUENCE header's `enable_filter_intra` (spec 5.5.2), armed
348+ /// exactly like [`SCREEN`]: with it every DC_PRED intra block of at most
349+ /// 32x32 that took no luma palette carries a `use_filter_intra` symbol
350+ /// after the palette colours and before the colour-index maps (decode.rs
351+ /// `read_intra_mode`), so a tile written without it and read with it
352+ /// desyncs at the first such block.
353+ static FILTER_INTRA: std::cell::Cell<bool> = const { std::cell::Cell::new(false) };
354+}
355+
356+/// Arms the sequence's `enable_filter_intra` bit for the next tile written on
357+/// this thread; cleared by [`CdefIdxGuard`] when that writer returns.
358+pub(crate) fn arm_filter_intra(on: bool) {
359+ FILTER_INTRA.with(|c| c.set(on));
360+}
361+
362+fn filter_intra_armed() -> bool {
363+ FILTER_INTRA.with(std::cell::Cell::get)
364+}
365+
366+/// How many blocks this writer coded `use_filter_intra == 1`, and the
367+/// histogram of the five `filter_intra_mode`s (index 1..=5) -- the fire count
368+/// a gate prints so that "filter intra is on" is a measurement rather than a
369+/// claim (class `gate-blind-to-feature`). Index 0 is the block count.
370+static FILTER_INTRA_HITS: [std::sync::atomic::AtomicUsize; 6] =
371+ [const { std::sync::atomic::AtomicUsize::new(0) }; 6];
372+
373+/// Reads [`FILTER_INTRA_HITS`] and zeroes it, so a gate can attribute the
374+/// counts to its own encode.
375+#[cfg(test)]
376+pub(crate) fn take_filter_intra_hits() -> [usize; 6] {
377+ std::array::from_fn(|i| FILTER_INTRA_HITS[i].swap(0, std::sync::atomic::Ordering::Relaxed))
378+}
379+
380+/// `filter_intra_mode_info` (spec 5.11.14) written out, mirrored symbol for
381+/// symbol from decode.rs `read_intra_mode`: a `use_filter_intra` flag on every
382+/// DC_PRED block whose sides `av1_filter_intra_allowed_bsize` admits (both <=
383+/// 32, [`crate::decode::filter_intra_size_class`]) and that took no luma
384+/// palette (`av1_filter_intra_allowed`, reconintra.h:77), then the chosen mode
385+/// of five. Sits between the palette COLOUR lists and the colour-index maps,
386+/// where libaom reads it (`av1_visit_palette` runs after
387+/// `read_filter_intra_mode_info`).
388+fn write_filter_intra(
389+ enc: &mut SymbolEncoder,
390+ cdfs: &mut Cdfs,
391+ mode: usize,
392+ side: usize,
393+ has_palette_y: bool,
394+ filter_intra: Option<u8>,
395+) {
396+ if !filter_intra_armed() || mode != DC_PRED || has_palette_y {
397+ debug_assert!(filter_intra.is_none(), "no `use_filter_intra` symbol exists here");
398+ return;
399+ }
400+ let Some(class) = crate::decode::filter_intra_size_class(side) else {
401+ debug_assert!(filter_intra.is_none(), "past av1_filter_intra_allowed_bsize");
402+ return;
403+ };
404+ enc.symbol(usize::from(filter_intra.is_some()), &mut cdfs.filter_intra[class]);
405+ if let Some(fi) = filter_intra {
406+ enc.symbol(usize::from(fi), &mut cdfs.filter_intra_mode);
407+ FILTER_INTRA_HITS[0].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
408+ FILTER_INTRA_HITS[usize::from(fi) + 1].fetch_add(1, std::sync::atomic::Ordering::Relaxed);
409+ }
410+}
411+
412+/// The coefficient-table row a block's luma transform types are coded from:
413+/// `fimode_to_intradir[filter_intra_mode]` for a filter-intra block, its own
414+/// luma mode otherwise (class `filter-intra tx_type row`, decode.rs
415+/// [`crate::decode::fi_tx_row`]). The block still PUBLISHES `DC_PRED` as its
416+/// neighbour mode -- libaom's `mbmi->mode` is unchanged by filter intra.
417+fn tx_row(mode: usize, filter_intra: Option<u8>) -> usize {
418+ crate::decode::fi_tx_row(mode, filter_intra.map(usize::from))
419+}
420+
346 /// How many blocks this writer coded `use_intrabc == 1`, and the histogram of421 /// How many blocks this writer coded `use_intrabc == 1`, and the histogram of
347 /// their DV magnitudes in full pels (index 1..=6 = 1, 2, 4, 8, 16, 32 pels422 /// their DV magnitudes in full pels (index 1..=6 = 1, 2, 4, 8, 16, 32 pels
348 /// and up, by the larger component) -- the fire count a gate prints so that423 /// and up, by the larger component) -- the fire count a gate prints so that
@@ -935,6 +1010,7 @@ impl Drop for CdefIdxGuard {
935 REFERENCE_SELECT.with(|c| c.set(false));1010 REFERENCE_SELECT.with(|c| c.set(false));
936 MOTION_MODE.with(|c| c.set(false));1011 MOTION_MODE.with(|c| c.set(false));
937 INTRABC.with(|c| c.set(false));1012 INTRABC.with(|c| c.set(false));
1013+ FILTER_INTRA.with(|c| c.set(false));
938 INTRABC_GRID.with(|c| *c.borrow_mut() = None);1014 INTRABC_GRID.with(|c| *c.borrow_mut() = None);
939 ORDER_HINTS.with(|c| c.set((7, 0, [0; 7])));1015 ORDER_HINTS.with(|c| c.set((7, 0, [0; 7])));
940 }1016 }
@@ -1452,6 +1528,14 @@ pub struct BlockCoeffs {
1452 /// [`UV_CFL_PRED`]; at least one of the pair is nonzero, since the joint1528 /// [`UV_CFL_PRED`]; at least one of the pair is nonzero, since the joint
1453 /// sign symbol has no (ZERO, ZERO) value.1529 /// sign symbol has no (ZERO, ZERO) value.
1454 pub cfl_alphas: Option<(i32, i32)>,1530 pub cfl_alphas: Option<(i32, i32)>,
1531+ /// This block's `filter_intra_mode` (spec 5.11.14, 0..=4) when it is
1532+ /// coded with recursive filter intra, or `None`. `Some` only on a DC_PRED
1533+ /// luma block of at most 32x32 with no luma palette, on a sequence whose
1534+ /// header set `enable_filter_intra` ([`arm_filter_intra`]); the block's
1535+ /// luma transform types are then coded from
1536+ /// `fimode_to_intradir[filter_intra_mode]`'s row ([`tx_row`]) while its
1537+ /// neighbour mode stays `DC_PRED`.
1538+ pub filter_intra: Option<u8>,
1455 /// This block's `angle_delta_y` (spec `read_intra_angle_info`, -3..=3),1539 /// This block's `angle_delta_y` (spec `read_intra_angle_info`, -3..=3),
1456 /// zero for every non-directional luma mode -- which is what1540 /// zero for every non-directional luma mode -- which is what
1457 /// [`Default`] gives, and what every writer coded before lane-av1cfl.1541 /// [`Default`] gives, and what every writer coded before lane-av1cfl.
@@ -3446,6 +3530,7 @@ fn write_intra_mode(
3446 neighbours,3530 neighbours,
3447 block.palette.as_ref(),3531 block.palette.as_ref(),
3448 block.palette_uv.as_ref(),3532 block.palette_uv.as_ref(),
3533+ block.filter_intra,
3449 mode,3534 mode,
3450 uv_mode,3535 uv_mode,
3451 mi,3536 mi,
@@ -3474,12 +3559,18 @@ fn write_palette_syntax(
3474 neighbours: &mut Neighbours,3559 neighbours: &mut Neighbours,
3475 palette: Option<&PaletteY>,3560 palette: Option<&PaletteY>,
3476 palette_uv: Option<&PaletteUv>,3561 palette_uv: Option<&PaletteUv>,
3562+ // lane-fintra: this block's chosen `filter_intra_mode`, or `None`. Written
3563+ // here rather than by the caller because its symbol sits BETWEEN the
3564+ // palette colour lists and the colour-index maps (decode.rs
3565+ // `read_intra_mode`), which is inside this function.
3566+ filter_intra: Option<u8>,
3477 mode: usize,3567 mode: usize,
3478 uv_mode: usize,3568 uv_mode: usize,
3479 mi: (usize, usize),3569 mi: (usize, usize),
3480 side: usize,3570 side: usize,
3481 ) {3571 ) {
3482 if !screen_armed() {3572 if !screen_armed() {
3573+ write_filter_intra(enc, cdfs, mode, side, false, filter_intra);
3483 return;3574 return;
3484 }3575 }
3485 let palette = palette.filter(|_| mode == DC_PRED);3576 let palette = palette.filter(|_| mode == DC_PRED);
@@ -3509,6 +3600,7 @@ fn write_palette_syntax(
3509 enc.symbol(n - 2, &mut cdfs.palette_uv_size[bsize_ctx]);3600 enc.symbol(n - 2, &mut cdfs.palette_uv_size[bsize_ctx]);
3510 write_palette_colors_uv(enc, &pal.u_colors[..n], &pal.v_colors[..n], &uv_cache);3601 write_palette_colors_uv(enc, &pal.u_colors[..n], &pal.v_colors[..n], &uv_cache);
3511 }3602 }
3603+ write_filter_intra(enc, cdfs, mode, side, palette.is_some(), filter_intra);
3512 // Both colour-index maps come after BOTH colour lists, in plane order3604 // Both colour-index maps come after BOTH colour lists, in plane order
3513 // (`av1_visit_palette` runs from the caller, past `filter_intra`).3605 // (`av1_visit_palette` runs from the caller, past `filter_intra`).
3514 if let Some(pal) = palette {3606 if let Some(pal) = palette {
@@ -3527,6 +3619,10 @@ fn write_palette_syntax(
3527 );3619 );
3528 note_palette_uv(n);3620 note_palette_uv(n);
3529 }3621 }
3622+ } else {
3623+ // Below `av1_allow_palette`'s size bound there is no palette syntax at
3624+ // all, but `av1_filter_intra_allowed_bsize` still admits the block.
3625+ write_filter_intra(enc, cdfs, mode, side, false, filter_intra);
3530 }3626 }
3531 neighbours.pending_palette = palette.map(|p| (p.size, p.colors));3627 neighbours.pending_palette = palette.map(|p| (p.size, p.colors));
3532 neighbours.pending_palette_uv = palette_uv.map(|p| (p.size, p.u_colors));3628 neighbours.pending_palette_uv = palette_uv.map(|p| (p.size, p.u_colors));
@@ -3629,6 +3725,10 @@ fn write_block(
3629 at_mi,3725 at_mi,
3630 side,3726 side,
3631 );3727 );
3728+ // The coefficient tables read `fimode_to_intradir[filter_intra_mode]`'s
3729+ // row on a filter-intra block; the neighbour publication below still gets
3730+ // the block's own `DC_PRED` ([`tx_row`]).
3731+ let tx_mode = tx_row(mode, block.filter_intra);
3632 let split = if tx_select {3732 let split = if tx_select {
3633 let tx = write_luma_select(3733 let tx = write_luma_select(
3634 enc,3734 enc,
@@ -3638,7 +3738,7 @@ fn write_block(
3638 side,3738 side,
3639 usize::from(block.tx_depth),3739 usize::from(block.tx_depth),
3640 &grids[0],3740 &grids[0],
3641- mode,3741+ tx_mode,
3642 all_scans,3742 all_scans,
3643 )?;3743 )?;
3644 tx < side3744 tx < side
@@ -3652,7 +3752,7 @@ fn write_block(
3652 grids,3752 grids,
3653 &scans,3753 &scans,
3654 &neighbours.around(at, side),3754 &neighbours.around(at, side),
3655- mode,3755+ tx_mode,
3656 tx_select,3756 tx_select,
3657 );3757 );
3658 neighbours.record_planes(at, side, mode, grids, !split);3758 neighbours.record_planes(at, side, mode, grids, !split);
@@ -3724,6 +3824,9 @@ fn write_leaf8(
3724 // unchanged).3824 // unchanged).
3725 let mode = write_intra_mode(enc, cdfs, neighbours, block, above_mode, left_mode, true, leaf_mi, 8);3825 let mode = write_intra_mode(enc, cdfs, neighbours, block, above_mode, left_mode, true, leaf_mi, 8);
3726 let planes = [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4];3826 let planes = [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4];
3827+ // As [`write_block`]: the coefficient row follows the filter-intra mode,
3828+ // the mode this leaf publishes (and returns to the next leaf) does not.
3829+ let tx_mode = tx_row(mode, block.filter_intra);
3727 let split = if tx_select {3830 let split = if tx_select {
3728 let tx = write_luma_select(3831 let tx = write_luma_select(
3729 enc,3832 enc,
@@ -3733,7 +3836,7 @@ fn write_leaf8(
3733 8,3836 8,
3734 usize::from(block.tx_depth),3837 usize::from(block.tx_depth),
3735 &grids[0],3838 &grids[0],
3736- mode,3839+ tx_mode,
3737 all_scans,3840 all_scans,
3738 )?;3841 )?;
3739 tx < 83842 tx < 8
@@ -3747,7 +3850,7 @@ fn write_leaf8(
3747 grids,3850 grids,
3748 &scans,3851 &scans,
3749 &neighbours.around_mi(leaf_mi, 8),3852 &neighbours.around_mi(leaf_mi, 8),
3750- mode,3853+ tx_mode,
3751 tx_select,3854 tx_select,
3752 );3855 );
3753 neighbours.record_mi_planes(leaf_mi, 8, grids, !split);3856 neighbours.record_mi_planes(leaf_mi, 8, grids, !split);
@@ -5811,7 +5914,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
5811 if (V_PRED..=D67_PRED).contains(&uv_mode) {5914 if (V_PRED..=D67_PRED).contains(&uv_mode) {
5812 enc.symbol(ANGLE_DELTA_ZERO, &mut cdfs.angle_delta[uv_mode - V_PRED]);5915 enc.symbol(ANGLE_DELTA_ZERO, &mut cdfs.angle_delta[uv_mode - V_PRED]);
5813 }5916 }
5814- mode_for_tx = mode;5917+ mode_for_tx = tx_row(mode, block.filter_intra);
5815 // Intra: no vote, but still a coded cell -- mvstack's5918 // Intra: no vote, but still a coded cell -- mvstack's
5816 // extended-scan coverage must see it (module doc).5919 // extended-scan coverage must see it (module doc).
5817 let (mi_row, mi_col) = (r32 as usize * 8, c32 as usize * 8);5920 let (mi_row, mi_col) = (r32 as usize * 8, c32 as usize * 8);
@@ -5821,6 +5924,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs(
5821 &mut neighbours,5924 &mut neighbours,
5822 block.palette.as_ref(),5925 block.palette.as_ref(),
5823 block.palette_uv.as_ref(),5926 block.palette_uv.as_ref(),
5927+ block.filter_intra,
5824 mode,5928 mode,
5825 uv_mode,5929 uv_mode,
5826 (mi_row, mi_col),5930 (mi_row, mi_col),
@@ -6052,7 +6156,7 @@ fn write_inter_frame_leaf(
6052 if (V_PRED..=D67_PRED).contains(&uv_mode) {6156 if (V_PRED..=D67_PRED).contains(&uv_mode) {
6053 enc.symbol(ANGLE_DELTA_ZERO, &mut cdfs.angle_delta[uv_mode - V_PRED]);6157 enc.symbol(ANGLE_DELTA_ZERO, &mut cdfs.angle_delta[uv_mode - V_PRED]);
6054 }6158 }
6055- mode_for_tx = mode;6159+ mode_for_tx = tx_row(mode, block.filter_intra);
6056 // Intra: no vote, but still a coded cell -- mvstack's extended-scan6160 // Intra: no vote, but still a coded cell -- mvstack's extended-scan
6057 // coverage must see it (module doc).6161 // coverage must see it (module doc).
6058 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);6162 let (mi_row, mi_col) = (r * SUB_MI as usize, c * SUB_MI as usize);
@@ -6062,6 +6166,7 @@ fn write_inter_frame_leaf(
6062 neighbours,6166 neighbours,
6063 block.palette.as_ref(),6167 block.palette.as_ref(),
6064 block.palette_uv.as_ref(),6168 block.palette_uv.as_ref(),
6169+ block.filter_intra,
6065 mode,6170 mode,
6066 uv_mode,6171 uv_mode,
6067 (mi_row, mi_col),6172 (mi_row, mi_col),
@@ -6299,7 +6404,7 @@ fn write_inter_frame_leaf8(
6299 if (V_PRED..=D67_PRED).contains(&uv_mode) {6404 if (V_PRED..=D67_PRED).contains(&uv_mode) {
6300 enc.symbol(ANGLE_DELTA_ZERO, &mut cdfs.angle_delta[uv_mode - V_PRED]);6405 enc.symbol(ANGLE_DELTA_ZERO, &mut cdfs.angle_delta[uv_mode - V_PRED]);
6301 }6406 }
6302- mode_for_tx = mode;6407+ mode_for_tx = tx_row(mode, block.filter_intra);
6303 // Intra: no vote, but still a coded cell -- mvstack's extended-scan6408 // Intra: no vote, but still a coded cell -- mvstack's extended-scan
6304 // coverage must see it (module doc).6409 // coverage must see it (module doc).
6305 let (mi_row, mi_col) = leaf_mi;6410 let (mi_row, mi_col) = leaf_mi;
@@ -6309,6 +6414,7 @@ fn write_inter_frame_leaf8(
6309 neighbours,6414 neighbours,
6310 block.palette.as_ref(),6415 block.palette.as_ref(),
6311 block.palette_uv.as_ref(),6416 block.palette_uv.as_ref(),
6417+ block.filter_intra,
6312 mode,6418 mode,
6313 uv_mode,6419 uv_mode,
6314 leaf_mi,6420 leaf_mi,