forge
Explore
Log in

Don't you dare go Hollow

The straddling-edge leaves are offered compound too

Browse files at this commit

48a7da3bc24454323deebb3a038642932df4e454Ahmet Kaan GümüşParent: f2d1542
  • feat
    • the straddling-edge leaves are offered compound too
Show full message
feat(av1): the straddling-edge leaves are offered compound too

Both true-edge leaf call sites passed an empty compound stack list, so no
block along a frame edge that straddles a 32x32 boundary could ever be coded
compound. They now build the same stacks the split quadrants do, through one
helper shared by all three sites.

Invisible to the BD gate (its clips are 640x384, a whole number of 32x32
blocks): byte-identical there. Measured on the straddle round trips instead --
15 compound 16x16 and 58 compound 8x8 leaves fire at 640x360 and at the real
clip straddle size, and every straddle round trip stays sample-exact through
ffmpeg and through our own decoder.
crates/ec-av1/src/encode.rsmodified+57 -26
@@ -2856,6 +2856,49 @@ fn search_chroma(
2856 /// search, so `NEARESTMV`-or-intra is this function's deliberate first cut2856 /// search, so `NEARESTMV`-or-intra is this function's deliberate first cut
2857 /// (see `write_inter_frame_leaf`'s doc comment).2857 /// (see `write_inter_frame_leaf`'s doc comment).
2858 #[allow(clippy::too_many_arguments)]2858 #[allow(clippy::too_many_arguments)]
2859+/// The compound MV stack of each `LAST` + extra-reference pair at one leaf,
2860+/// as [`code_square_inter`] wants them: empty on a frame that codes no
2861+/// `reference_select`, or when the leaf compound candidates are switched off.
2862+/// One helper because THREE leaf call sites need it -- the split quadrants
2863+/// and, since lane-av1comp4, both straddling-edge sites, which used to pass
2864+/// `&[]` and so coded no compound block anywhere along the frame's true edge.
2865+#[allow(clippy::too_many_arguments)]
2866+fn leaf_compound_stacks<'a>(
2867+ grid: &MiGrid,
2868+ mi_row: usize,
2869+ mi_col: usize,
2870+ bw4: usize,
2871+ bh4: usize,
2872+ mi_cols: usize,
2873+ mi_rows: usize,
2874+ reference_select: bool,
2875+ golden: Option<&'a Picture>,
2876+ altref: Option<&'a Picture>,
2877+) -> Vec<(i8, &'a Picture, crate::mvstack::CompoundMvStack)> {
2878+ if !(reference_select && leaf_compound()) {
2879+ return Vec::new();
2880+ }
2881+ [
2882+ (crate::mvstack::GOLDEN_FRAME, golden),
2883+ (crate::mvstack::ALTREF_FRAME, altref),
2884+ ]
2885+ .into_iter()
2886+ .filter_map(|(r, pic)| {
2887+ pic.map(|p| {
2888+ (
2889+ r,
2890+ p,
2891+ crate::mvstack::find_mv_stack_compound(
2892+ grid, mi_row, mi_col, bw4, bh4,
2893+ (crate::mvstack::LAST_FRAME, r), mi_cols, mi_rows,
2894+ grid.sign_bias_table(), &[(0, 0); 7], None,
2895+ ),
2896+ )
2897+ })
2898+ })
2899+ .collect()
2900+}
2901+
2859 fn code_square_inter(2902 fn code_square_inter(
2860 luma: &mut Plane,2903 luma: &mut Plane,
2861 chroma: &mut [Plane; 2],2904 chroma: &mut [Plane; 2],
@@ -6093,30 +6136,10 @@ pub(crate) fn encode_inter_frame(
6093 let stack = find_mv_stack(6136 let stack = find_mv_stack(
6094 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,6137 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,
6095 );6138 );
6096- let cstacks: Vec<(i8, &Picture, crate::mvstack::CompoundMvStack)> =6139+ let cstacks = leaf_compound_stacks(
6097- if header.reference_select && leaf_compound() {6140+ &grid, mi_row, mi_col, 4, 4, mi_cols, mi_rows,
6098- [6141+ header.reference_select, golden, altref,
6099- (crate::mvstack::GOLDEN_FRAME, golden),6142+ );
6100- (crate::mvstack::ALTREF_FRAME, altref),
6101- ]
6102- .into_iter()
6103- .filter_map(|(r, pic)| {
6104- pic.map(|p| {
6105- (
6106- r,
6107- p,
6108- crate::mvstack::find_mv_stack_compound(
6109- &grid, mi_row, mi_col, 4, 4,
6110- (crate::mvstack::LAST_FRAME, r), mi_cols, mi_rows,
6111- grid.sign_bias_table(), &[(0, 0); 7], None,
6112- ),
6113- )
6114- })
6115- })
6116- .collect()
6117- } else {
6118- Vec::new()
6119- };
6120 let (leaf, leaf_cost) = code_square_inter(6143 let (leaf, leaf_cost) = code_square_inter(
6121 &mut luma,6144 &mut luma,
6122 &mut chroma,6145 &mut chroma,
@@ -6279,6 +6302,10 @@ pub(crate) fn encode_inter_frame(
6279 let stack = find_mv_stack(6302 let stack = find_mv_stack(
6280 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,6303 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,
6281 );6304 );
6305+ let cstacks = leaf_compound_stacks(
6306+ &grid, mi_row, mi_col, 4, 4, mi_cols, mi_rows,
6307+ header.reference_select, golden, altref,
6308+ );
6282 let (block, _) = code_square_inter(6309 let (block, _) = code_square_inter(
6283 &mut luma,6310 &mut luma,
6284 &mut chroma,6311 &mut chroma,
@@ -6287,7 +6314,7 @@ pub(crate) fn encode_inter_frame(
6287 &search,6314 &search,
6288 &mode_bits_table,6315 &mode_bits_table,
6289 reference,6316 reference,
6290- &stack, &[], fctx,6317+ &stack, &cstacks, fctx,
6291 );6318 );
6292 // One publication point for every coded leaf6319 // One publication point for every coded leaf
6293 // (`record_mi`): this site used to spell the vote6320 // (`record_mi`): this site used to spell the vote
@@ -6312,6 +6339,10 @@ pub(crate) fn encode_inter_frame(
6312 let stack = find_mv_stack(6339 let stack = find_mv_stack(
6313 &grid, mi_row, mi_col, 2, 2, LAST_FRAME, mi_cols, mi_rows,6340 &grid, mi_row, mi_col, 2, 2, LAST_FRAME, mi_cols, mi_rows,
6314 );6341 );
6342+ let cstacks = leaf_compound_stacks(
6343+ &grid, mi_row, mi_col, 2, 2, mi_cols, mi_rows,
6344+ header.reference_select, golden, altref,
6345+ );
6315 let (leaf, _) = code_square_inter(6346 let (leaf, _) = code_square_inter(
6316 &mut luma,6347 &mut luma,
6317 &mut chroma,6348 &mut chroma,
@@ -6320,7 +6351,7 @@ pub(crate) fn encode_inter_frame(
6320 &search,6351 &search,
6321 &mode_bits_table,6352 &mode_bits_table,
6322 reference,6353 reference,
6323- &stack, &[], fctx,6354+ &stack, &cstacks, fctx,
6324 );6355 );
6325 // Same publication point as the 16x166356 // Same publication point as the 16x16
6326 // straddling leaf above (`record_mi`).6357 // straddling leaf above (`record_mi`).