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(
28562856 /// search, so `NEARESTMV`-or-intra is this function's deliberate first cut
28572857 /// (see `write_inter_frame_leaf`'s doc comment).
28582858 #[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+
28592902 fn code_square_inter(
28602903 luma: &mut Plane,
28612904 chroma: &mut [Plane; 2],
@@ -6093,30 +6136,10 @@ pub(crate) fn encode_inter_frame(
60936136 let stack = find_mv_stack(
60946137 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,
60956138 );
6096- let cstacks: Vec<(i8, &Picture, crate::mvstack::CompoundMvStack)> =
6097- if header.reference_select && leaf_compound() {
6098- [
6099- (crate::mvstack::GOLDEN_FRAME, golden),
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- };
6139+ let cstacks = leaf_compound_stacks(
6140+ &grid, mi_row, mi_col, 4, 4, mi_cols, mi_rows,
6141+ header.reference_select, golden, altref,
6142+ );
61206143 let (leaf, leaf_cost) = code_square_inter(
61216144 &mut luma,
61226145 &mut chroma,
@@ -6279,6 +6302,10 @@ pub(crate) fn encode_inter_frame(
62796302 let stack = find_mv_stack(
62806303 &grid, mi_row, mi_col, 4, 4, LAST_FRAME, mi_cols, mi_rows,
62816304 );
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+ );
62826309 let (block, _) = code_square_inter(
62836310 &mut luma,
62846311 &mut chroma,
@@ -6287,7 +6314,7 @@ pub(crate) fn encode_inter_frame(
62876314 &search,
62886315 &mode_bits_table,
62896316 reference,
6290- &stack, &[], fctx,
6317+ &stack, &cstacks, fctx,
62916318 );
62926319 // One publication point for every coded leaf
62936320 // (`record_mi`): this site used to spell the vote
@@ -6312,6 +6339,10 @@ pub(crate) fn encode_inter_frame(
63126339 let stack = find_mv_stack(
63136340 &grid, mi_row, mi_col, 2, 2, LAST_FRAME, mi_cols, mi_rows,
63146341 );
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+ );
63156346 let (leaf, _) = code_square_inter(
63166347 &mut luma,
63176348 &mut chroma,
@@ -6320,7 +6351,7 @@ pub(crate) fn encode_inter_frame(
63206351 &search,
63216352 &mode_bits_table,
63226353 reference,
6323- &stack, &[], fctx,
6354+ &stack, &cstacks, fctx,
63246355 );
63256356 // Same publication point as the 16x16
63266357 // straddling leaf above (`record_mi`).