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 commit4 changed files +407 -22
- crates/ec-av1/src/decode.rs +103 -12
- crates/ec-av1/src/encode.rs +187 -2
- crates/ec-av1/src/stream.rs +4 -1
- crates/ec-av1/src/tile.rs +113 -7
crates/ec-av1/src/decode.rsmodified+103 -12
| @@ -8288,7 +8288,7 @@ impl Neighbours { | ||
| 8288 | 8288 | /// `intra_ext_tx_cdf` row a luma transform reads. A filter-intra block's |
| 8289 | 8289 | /// `mode` is always `DC_PRED`, so the row comes from the FILTER-INTRA mode |
| 8290 | 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 | 8292 | const FIMODE_TO_INTRADIR: [usize; 5] = [DC_PRED, V_PRED, H_PRED, D157_PRED, DC_PRED]; |
| 8293 | 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 | 8296 | /// A block-size class index into [`cdf::FILTER_INTRA`]/`Cdfs::filter_intra`, |
| 8297 | 8297 | /// or `None` when `side` is past `av1_filter_intra_allowed_bsize`'s <=32 |
| 8298 | 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 | 8300 | match side { |
| 8301 | 8301 | 4 => Some(0), |
| 8302 | 8302 | 8 => Some(1), |
| @@ -33480,7 +33480,9 @@ pub(crate) fn decode_inter_frame_tile( | ||
| 33480 | 33480 | loop_filter, allow_high_precision_mv, force_integer_mv, interp_fixed, |
| 33481 | 33481 | enable_dual_filter, reference_select, tx_select, |
| 33482 | 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 | 33534 | // `false` here desynced every stream this crate's encoder writes with the |
| 33533 | 33535 | // warp knob on: the same stale-header class as the parameter above. |
| 33534 | 33536 | allow_warped_motion: bool, |
| 33537 | + // lane-fintra: see [`decode_inter_frame_tiles_lr`]'s own parameter. | |
| 33538 | + enable_filter_intra: bool, | |
| 33535 | 33539 | fctx: &crate::decode::FrameCtx, |
| 33536 | 33540 | ) -> Result<Picture> { |
| 33537 | 33541 | let single_tile = TileInfo { |
| @@ -33562,6 +33566,7 @@ pub(crate) fn decode_inter_frame_tile_lr( | ||
| 33562 | 33566 | allow_screen_content_tools, |
| 33563 | 33567 | switchable_motion_mode, |
| 33564 | 33568 | allow_warped_motion, |
| 33569 | + enable_filter_intra, | |
| 33565 | 33570 | fctx, |
| 33566 | 33571 | ) |
| 33567 | 33572 | } |
| @@ -33603,6 +33608,12 @@ pub(crate) fn decode_inter_frame_tiles_lr( | ||
| 33603 | 33608 | // `false` here desynced every stream this crate's encoder writes with the |
| 33604 | 33609 | // warp knob on: the same stale-header class as the parameter above. |
| 33605 | 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 | 33617 | fctx: &crate::decode::FrameCtx, |
| 33607 | 33618 | ) -> Result<Picture> { |
| 33608 | 33619 | decode_inter_frame_tile_with_cdfs( |
| @@ -33641,10 +33652,7 @@ pub(crate) fn decode_inter_frame_tiles_lr( | ||
| 33641 | 33652 | allow_warped_motion, |
| 33642 | 33653 | allow_screen_content_tools, |
| 33643 | 33654 | DeltaParams::default(), |
| 33644 | - // `enable_filter_intra`: this crate's own encoder never writes the | |
| 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, | |
| 33655 | + enable_filter_intra, | |
| 33648 | 33656 | None, |
| 33649 | 33657 | fctx, |
| 33650 | 33658 | ) |
| @@ -37632,7 +37640,10 @@ mod tests { | ||
| 37632 | 37640 | base_q_idx, |
| 37633 | 37641 | w as u32, |
| 37634 | 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 | 37647 | &cdef, |
| 37637 | 37648 | &loop_filter, |
| 37638 | 37649 | tx_select, |
| @@ -38002,7 +38013,10 @@ mod tests { | ||
| 38002 | 38013 | encoded.base_q_idx, |
| 38003 | 38014 | coded_w, |
| 38004 | 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 | 38020 | &encoded.cdef, |
| 38007 | 38021 | &encoded.loop_filter, |
| 38008 | 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 | 38097 | /// The key frame the encoder writes carries `tx_mode == TxMode::Select`, |
| 38022 | 38098 | /// and that header bit is load-bearing for a decode of its tile: read as a |
| 38023 | 38099 | /// `TxMode::Largest` frame the very first block misses its `tx_depth` |
| @@ -38046,7 +38122,10 @@ mod tests { | ||
| 38046 | 38122 | encoded.base_q_idx, |
| 38047 | 38123 | width as u32, |
| 38048 | 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 | 38129 | &encoded.cdef, |
| 38051 | 38130 | &encoded.loop_filter, |
| 38052 | 38131 | tx_select, |
| @@ -38131,7 +38210,10 @@ mod tests { | ||
| 38131 | 38210 | key.base_q_idx, |
| 38132 | 38211 | width as u32, |
| 38133 | 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 | 38217 | &key.cdef, |
| 38136 | 38218 | &key.loop_filter, |
| 38137 | 38219 | key.tx_select, |
| @@ -38197,6 +38279,9 @@ mod tests { | ||
| 38197 | 38279 | // the warp bit must be the one it wrote too (lane-av1obmc2); |
| 38198 | 38280 | // the encoder only sets it under `EC_AV1_WARP`. |
| 38199 | 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 | 38285 | fctx, |
| 38201 | 38286 | ) |
| 38202 | 38287 | .unwrap(); |
| @@ -38480,7 +38565,10 @@ mod tests { | ||
| 38480 | 38565 | key.base_q_idx, |
| 38481 | 38566 | coded_w, |
| 38482 | 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 | 38572 | &key.cdef, |
| 38485 | 38573 | &key.loop_filter, |
| 38486 | 38574 | key.tx_select, |
| @@ -38535,6 +38623,9 @@ mod tests { | ||
| 38535 | 38623 | // the warp bit must be the one it wrote too (lane-av1obmc2); |
| 38536 | 38624 | // the encoder only sets it under `EC_AV1_WARP`. |
| 38537 | 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 | 38629 | fctx, |
| 38539 | 38630 | ) |
| 38540 | 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 | 799 | /// Pads one plane to `(padded_width, padded_height)` by repeating its last |
| 760 | 800 | /// row and column, so the block coder always sees a whole number of blocks. |
| 761 | 801 | /// [`crop_plane`] undoes this on the way back out. |
| @@ -982,6 +1022,20 @@ pub(crate) fn force_screen(value: Option<bool>) { | ||
| 982 | 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 | 1039 | pub(crate) fn arm_seq_screen(on: bool) { |
| 986 | 1040 | SEQ_SCREEN.with(|c| c.set(on)); |
| 987 | 1041 | } |
| @@ -1183,7 +1237,11 @@ pub(crate) fn key_frame_headers_colour( | ||
| 1183 | 1237 | max_frame_width: w, |
| 1184 | 1238 | max_frame_height: h, |
| 1185 | 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 | 1245 | enable_intra_edge_filter: false, |
| 1188 | 1246 | enable_order_hint: true, |
| 1189 | 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 | 3996 | // Chroma searches its own mode over [`CHROMA_MODES`], one symbol for both |
| 3864 | 3997 | // planes; what it costs still counts towards the partition decision. |
| 3865 | 3998 | let ([u, v], uv_mode, chroma_cost, palette_uv, cfl_alphas) = |
| @@ -3898,6 +4031,7 @@ fn code_square( | ||
| 3898 | 4031 | tx_depth, |
| 3899 | 4032 | palette, |
| 3900 | 4033 | palette_uv, |
| 4034 | + filter_intra, | |
| 3901 | 4035 | cfl_alphas, |
| 3902 | 4036 | angle_delta_y: angle_delta as i8, |
| 3903 | 4037 | ..BlockCoeffs::default() |
| @@ -3975,6 +4109,20 @@ fn cfl_on() -> bool { | ||
| 3975 | 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 | 4126 | /// Reads [`UV_MODE_HITS`] and zeroes it, so a gate can attribute the counts |
| 3979 | 4127 | /// to its own encode. |
| 3980 | 4128 | #[cfg(test)] |
| @@ -5086,6 +5234,7 @@ fn code_square_inter( | ||
| 5086 | 5234 | BlockCoeffs { |
| 5087 | 5235 | angle_delta_y: 0, |
| 5088 | 5236 | cfl_alphas: None, |
| 5237 | + filter_intra: None, | |
| 5089 | 5238 | luma: coeffs(&levels, side), |
| 5090 | 5239 | u: coeffs(&u_new.levels, side / 2), |
| 5091 | 5240 | v: coeffs(&v_new.levels, side / 2), |
| @@ -5121,6 +5270,7 @@ fn code_square_inter( | ||
| 5121 | 5270 | (BlockCoeffs { |
| 5122 | 5271 | angle_delta_y: 0, |
| 5123 | 5272 | cfl_alphas: None, |
| 5273 | + filter_intra: None, | |
| 5124 | 5274 | luma: coeffs(&levels, side), |
| 5125 | 5275 | u: coeffs(&u.levels, side / 2), |
| 5126 | 5276 | v: coeffs(&v.levels, side / 2), |
| @@ -6223,6 +6373,7 @@ pub(crate) fn encode_key_frame_inner( | ||
| 6223 | 6373 | crate::tile::arm_lr(64, lr_horz, lr_vert, units.to_vec()); |
| 6224 | 6374 | let mut cdfs = start_cdfs.0.clone(); |
| 6225 | 6375 | crate::tile::arm_screen(screen); |
| 6376 | + crate::tile::arm_filter_intra(filter_intra_on()); | |
| 6226 | 6377 | crate::tile::arm_intrabc(allow_intrabc); |
| 6227 | 6378 | crate::tile::arm_pricing_cdfs(None, false); |
| 6228 | 6379 | let bytes = crate::tile::sb_coeff_key_frame_tile_cdfs( |
| @@ -7829,6 +7980,7 @@ fn search_inter_block( | ||
| 7829 | 7980 | BlockCoeffs { |
| 7830 | 7981 | angle_delta_y: 0, |
| 7831 | 7982 | cfl_alphas: None, |
| 7983 | + filter_intra: None, | |
| 7832 | 7984 | luma: coeffs(&levels, BLOCK), |
| 7833 | 7985 | u: coeffs(&best.u.levels, BLOCK / 2), |
| 7834 | 7986 | v: coeffs(&best.v.levels, BLOCK / 2), |
| @@ -9079,6 +9231,7 @@ pub(crate) fn encode_inter_frame( | ||
| 9079 | 9231 | crate::tile::arm_warped_motion(warped_motion); |
| 9080 | 9232 | crate::tile::arm_order_hints(order_hint_bits, order_hint, order_hints); |
| 9081 | 9233 | crate::tile::arm_screen(screen); |
| 9234 | + crate::tile::arm_filter_intra(filter_intra_on()); | |
| 9082 | 9235 | let mut cdfs = start_cdfs.0.clone(); |
| 9083 | 9236 | crate::tile::arm_pricing_cdfs(Some(&cdfs), screen); |
| 9084 | 9237 | // Each tile's own MV grid: a candidate scan never reaches past |
| @@ -9205,6 +9358,7 @@ pub(crate) fn encode_inter_frame( | ||
| 9205 | 9358 | h.allow_screen_content_tools, |
| 9206 | 9359 | switchable_motion_mode, |
| 9207 | 9360 | h.allow_warped_motion, |
| 9361 | + seq.enable_filter_intra, | |
| 9208 | 9362 | fctx, |
| 9209 | 9363 | ) |
| 9210 | 9364 | }, |
| @@ -10083,6 +10237,7 @@ mod tests { | ||
| 10083 | 10237 | let residual_block = BlockCoeffs { |
| 10084 | 10238 | angle_delta_y: 0, |
| 10085 | 10239 | cfl_alphas: None, |
| 10240 | + filter_intra: None, | |
| 10086 | 10241 | luma: vec![Coeff { |
| 10087 | 10242 | row: 0, |
| 10088 | 10243 | col: 0, |
| @@ -10882,6 +11037,11 @@ mod tests { | ||
| 10882 | 11037 | eprintln!("SKIP every_mode_decodes_to_what_the_encoder_predicted: no ffmpeg"); |
| 10883 | 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 | 11045 | // 128 wide is a whole number of superblocks and 160 is not: the last |
| 10886 | 11046 | // superblock of a 160-wide row is half a one, whose blocks have no |
| 10887 | 11047 | // above-right samples inside the frame at all. |
| @@ -10992,6 +11152,10 @@ mod tests { | ||
| 10992 | 11152 | // these synthetic two-colour pictures losslessly under every arm and |
| 10993 | 11153 | // leave nothing to compare (see [`force_screen`]). |
| 10994 | 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 | 11159 | let mut points: Vec<(f64, f64)> = [110u8, 90, 70] |
| 10996 | 11160 | .iter() |
| 10997 | 11161 | .map(|&q| { |
| @@ -12840,8 +13004,14 @@ mod tests { | ||
| 12840 | 13004 | // so every block taking either codes different syntax and different |
| 12841 | 13005 | // coefficients -- 8194 -> 7321 at q=150 and 28285 -> 27285 at q=60. |
| 12842 | 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 | 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 | 13015 | for (q, bytes, hash) in pins { |
| 12846 | 13016 | let encoded = encode_sequence(&source, q, 0.5).unwrap(); |
| 12847 | 13017 | assert_eq!( |
| @@ -13963,6 +14133,7 @@ mod tests { | ||
| 13963 | 14133 | let _ = crate::tile::take_palette_uv_hits(); |
| 13964 | 14134 | let _ = crate::tile::take_intrabc_hits(); |
| 13965 | 14135 | let _ = take_intrabc_search(); |
| 14136 | + let _ = crate::tile::take_filter_intra_hits(); | |
| 13966 | 14137 | // The sequence path itself codes the pyramid now |
| 13967 | 14138 | // (lane-av1pyrdef), and prints what it requested and what the |
| 13968 | 14139 | // content gate left effective. |
| @@ -14009,6 +14180,20 @@ mod tests { | ||
| 14009 | 14180 | search[1], |
| 14010 | 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 | 14197 | let (aom, aom_wall) = external_ladder(&source, cw, ch, "libaom-av1", &aom_points); |
| 14013 | 14198 | let (rav1e, rav1e_wall) = external_ladder(&source, cw, ch, "librav1e", &rav1e_points); |
| 14014 | 14199 | assert_monotone(&format!("{name}: ours"), &ours); |
crates/ec-av1/src/stream.rsmodified+4 -1
| @@ -2993,7 +2993,10 @@ pub(crate) mod tests { | ||
| 2993 | 2993 | encoded.base_q_idx, |
| 2994 | 2994 | width as u32, |
| 2995 | 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 | 3000 | &encoded.cdef, |
| 2998 | 3001 | &encoded.loop_filter, |
| 2999 | 3002 | encoded.tx_select, |
crates/ec-av1/src/tile.rsmodified+113 -7
| @@ -343,6 +343,81 @@ fn intrabc_armed() -> bool { | ||
| 343 | 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 | 421 | /// How many blocks this writer coded `use_intrabc == 1`, and the histogram of |
| 347 | 422 | /// their DV magnitudes in full pels (index 1..=6 = 1, 2, 4, 8, 16, 32 pels |
| 348 | 423 | /// and up, by the larger component) -- the fire count a gate prints so that |
| @@ -935,6 +1010,7 @@ impl Drop for CdefIdxGuard { | ||
| 935 | 1010 | REFERENCE_SELECT.with(|c| c.set(false)); |
| 936 | 1011 | MOTION_MODE.with(|c| c.set(false)); |
| 937 | 1012 | INTRABC.with(|c| c.set(false)); |
| 1013 | + FILTER_INTRA.with(|c| c.set(false)); | |
| 938 | 1014 | INTRABC_GRID.with(|c| *c.borrow_mut() = None); |
| 939 | 1015 | ORDER_HINTS.with(|c| c.set((7, 0, [0; 7]))); |
| 940 | 1016 | } |
| @@ -1452,6 +1528,14 @@ pub struct BlockCoeffs { | ||
| 1452 | 1528 | /// [`UV_CFL_PRED`]; at least one of the pair is nonzero, since the joint |
| 1453 | 1529 | /// sign symbol has no (ZERO, ZERO) value. |
| 1454 | 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 | 1539 | /// This block's `angle_delta_y` (spec `read_intra_angle_info`, -3..=3), |
| 1456 | 1540 | /// zero for every non-directional luma mode -- which is what |
| 1457 | 1541 | /// [`Default`] gives, and what every writer coded before lane-av1cfl. |
| @@ -3446,6 +3530,7 @@ fn write_intra_mode( | ||
| 3446 | 3530 | neighbours, |
| 3447 | 3531 | block.palette.as_ref(), |
| 3448 | 3532 | block.palette_uv.as_ref(), |
| 3533 | + block.filter_intra, | |
| 3449 | 3534 | mode, |
| 3450 | 3535 | uv_mode, |
| 3451 | 3536 | mi, |
| @@ -3474,12 +3559,18 @@ fn write_palette_syntax( | ||
| 3474 | 3559 | neighbours: &mut Neighbours, |
| 3475 | 3560 | palette: Option<&PaletteY>, |
| 3476 | 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 | 3567 | mode: usize, |
| 3478 | 3568 | uv_mode: usize, |
| 3479 | 3569 | mi: (usize, usize), |
| 3480 | 3570 | side: usize, |
| 3481 | 3571 | ) { |
| 3482 | 3572 | if !screen_armed() { |
| 3573 | + write_filter_intra(enc, cdfs, mode, side, false, filter_intra); | |
| 3483 | 3574 | return; |
| 3484 | 3575 | } |
| 3485 | 3576 | let palette = palette.filter(|_| mode == DC_PRED); |
| @@ -3509,6 +3600,7 @@ fn write_palette_syntax( | ||
| 3509 | 3600 | enc.symbol(n - 2, &mut cdfs.palette_uv_size[bsize_ctx]); |
| 3510 | 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 | 3604 | // Both colour-index maps come after BOTH colour lists, in plane order |
| 3513 | 3605 | // (`av1_visit_palette` runs from the caller, past `filter_intra`). |
| 3514 | 3606 | if let Some(pal) = palette { |
| @@ -3527,6 +3619,10 @@ fn write_palette_syntax( | ||
| 3527 | 3619 | ); |
| 3528 | 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 | 3627 | neighbours.pending_palette = palette.map(|p| (p.size, p.colors)); |
| 3532 | 3628 | neighbours.pending_palette_uv = palette_uv.map(|p| (p.size, p.u_colors)); |
| @@ -3629,6 +3725,10 @@ fn write_block( | ||
| 3629 | 3725 | at_mi, |
| 3630 | 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 | 3732 | let split = if tx_select { |
| 3633 | 3733 | let tx = write_luma_select( |
| 3634 | 3734 | enc, |
| @@ -3638,7 +3738,7 @@ fn write_block( | ||
| 3638 | 3738 | side, |
| 3639 | 3739 | usize::from(block.tx_depth), |
| 3640 | 3740 | &grids[0], |
| 3641 | - mode, | |
| 3741 | + tx_mode, | |
| 3642 | 3742 | all_scans, |
| 3643 | 3743 | )?; |
| 3644 | 3744 | tx < side |
| @@ -3652,7 +3752,7 @@ fn write_block( | ||
| 3652 | 3752 | grids, |
| 3653 | 3753 | &scans, |
| 3654 | 3754 | &neighbours.around(at, side), |
| 3655 | - mode, | |
| 3755 | + tx_mode, | |
| 3656 | 3756 | tx_select, |
| 3657 | 3757 | ); |
| 3658 | 3758 | neighbours.record_planes(at, side, mode, grids, !split); |
| @@ -3724,6 +3824,9 @@ fn write_leaf8( | ||
| 3724 | 3824 | // unchanged). |
| 3725 | 3825 | let mode = write_intra_mode(enc, cdfs, neighbours, block, above_mode, left_mode, true, leaf_mi, 8); |
| 3726 | 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 | 3830 | let split = if tx_select { |
| 3728 | 3831 | let tx = write_luma_select( |
| 3729 | 3832 | enc, |
| @@ -3733,7 +3836,7 @@ fn write_leaf8( | ||
| 3733 | 3836 | 8, |
| 3734 | 3837 | usize::from(block.tx_depth), |
| 3735 | 3838 | &grids[0], |
| 3736 | - mode, | |
| 3839 | + tx_mode, | |
| 3737 | 3840 | all_scans, |
| 3738 | 3841 | )?; |
| 3739 | 3842 | tx < 8 |
| @@ -3747,7 +3850,7 @@ fn write_leaf8( | ||
| 3747 | 3850 | grids, |
| 3748 | 3851 | &scans, |
| 3749 | 3852 | &neighbours.around_mi(leaf_mi, 8), |
| 3750 | - mode, | |
| 3853 | + tx_mode, | |
| 3751 | 3854 | tx_select, |
| 3752 | 3855 | ); |
| 3753 | 3856 | neighbours.record_mi_planes(leaf_mi, 8, grids, !split); |
| @@ -5811,7 +5914,7 @@ pub(crate) fn sb_coeff_inter_frame_tile_cdfs( | ||
| 5811 | 5914 | if (V_PRED..=D67_PRED).contains(&uv_mode) { |
| 5812 | 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 | 5918 | // Intra: no vote, but still a coded cell -- mvstack's |
| 5816 | 5919 | // extended-scan coverage must see it (module doc). |
| 5817 | 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 | 5924 | &mut neighbours, |
| 5822 | 5925 | block.palette.as_ref(), |
| 5823 | 5926 | block.palette_uv.as_ref(), |
| 5927 | + block.filter_intra, | |
| 5824 | 5928 | mode, |
| 5825 | 5929 | uv_mode, |
| 5826 | 5930 | (mi_row, mi_col), |
| @@ -6052,7 +6156,7 @@ fn write_inter_frame_leaf( | ||
| 6052 | 6156 | if (V_PRED..=D67_PRED).contains(&uv_mode) { |
| 6053 | 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 | 6160 | // Intra: no vote, but still a coded cell -- mvstack's extended-scan |
| 6057 | 6161 | // coverage must see it (module doc). |
| 6058 | 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 | 6166 | neighbours, |
| 6063 | 6167 | block.palette.as_ref(), |
| 6064 | 6168 | block.palette_uv.as_ref(), |
| 6169 | + block.filter_intra, | |
| 6065 | 6170 | mode, |
| 6066 | 6171 | uv_mode, |
| 6067 | 6172 | (mi_row, mi_col), |
| @@ -6299,7 +6404,7 @@ fn write_inter_frame_leaf8( | ||
| 6299 | 6404 | if (V_PRED..=D67_PRED).contains(&uv_mode) { |
| 6300 | 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 | 6408 | // Intra: no vote, but still a coded cell -- mvstack's extended-scan |
| 6304 | 6409 | // coverage must see it (module doc). |
| 6305 | 6410 | let (mi_row, mi_col) = leaf_mi; |
| @@ -6309,6 +6414,7 @@ fn write_inter_frame_leaf8( | ||
| 6309 | 6414 | neighbours, |
| 6310 | 6415 | block.palette.as_ref(), |
| 6311 | 6416 | block.palette_uv.as_ref(), |
| 6417 | + block.filter_intra, | |
| 6312 | 6418 | mode, |
| 6313 | 6419 | uv_mode, |
| 6314 | 6420 | leaf_mi, |