forge
Explore
Log in

Don't you dare go Hollow

Thread the last leaf's mode past the whole straddling quadrant

Browse files at this commit

d02638da5ff12dc601c19791293626fa92868074Ahmet Kaan GümüşParent: a9fbebe
  • fix
    • thread the last leaf's mode past the whole straddling quadrant
Show full message
fix(av1): thread the last leaf's mode past the whole straddling quadrant

write_leaf8's above_mode[c]/left_mode[r] forced write (r12) ran once per
leaf inside the quadrant's leaf loop, so the first leaf's write clobbered
the true external neighbour mode a second leaf of the *same* straddling
16x16 still needed to read on its non-adjacency axis. Move the write out
of write_leaf8 to run once, after the whole leaf loop, from the last
(bottom/right-most) leaf. a_single_axis_straddle_round_trips_through_ffmpeg
now decodes clean; un-ignored. Lifted the RD-cost guard that kept leaf8
splits from competing on cost (now decoder-proven); full gate 136/0/9.
crates/ec-av1/src/encode.rsmodified+44 -12
@@ -1820,13 +1820,13 @@ pub(crate) fn encode_key_frame_inner(
1820 1820
1821 // A split whose subs are all whole 16x16 is a real quality1821 // A split whose subs are all whole 16x16 is a real quality
1822 // alternative to `whole`, exactly as before; a split1822 // alternative to `whole`, exactly as before; a split
1823- // carrying an 8x8-leaf sub is only ever forced (`!whole_1823+ // carrying an 8x8-leaf sub was, through r14, only ever
1824- // legal`), never chosen on cost -- the leaf path is new this1824+ // forced (`!whole_legal`), never chosen on cost, because the
1825- // round and not yet proven against a real decoder (see the1825+ // leaf path was not yet proven against a real decoder. r15
1826- // r7 handoff), so it must not regress a size that already1826+ // closed that gap (`a_single_axis_straddle_round_trips_
1827- // had a legal, working whole-32x32 alternative.1827+ // through_ffmpeg` decodes clean), so the guard is lifted:
1828- let has_leaf8 = split.iter().any(|b| b.eight.is_some());1828+ // leaf8 splits now compete on cost like any other split.
1829- if !whole_legal || (split_blocks && !has_leaf8 && cost_split < cost_whole) {1829+ if !whole_legal || (split_blocks && cost_split < cost_whole) {
1830 modes.extend_from_slice(&split_modes);1830 modes.extend_from_slice(&split_modes);
1831 blocks.push(Quadrant::Split(split));1831 blocks.push(Quadrant::Split(split));
1832 } else {1832 } else {
@@ -3322,6 +3322,31 @@ mod tests {
3322 );3322 );
3323 }3323 }
3324 3324
3325+ /// The r15 fix at production size: three 640x360 key frames (inter is
3326+ /// still refused at this size, per the test above, so this stands in for
3327+ /// the charter's "3-frame sequence" using three independent key frames of
3328+ /// shifted content), each proven decoder-clean through ffmpeg rather than
3329+ /// only encoder-clean.
3330+ #[test]
3331+ fn a_640x360_half_straddle_round_trips_through_ffmpeg_across_three_frames() {
3332+ if !have_ffmpeg() {
3333+ eprintln!(
3334+ "SKIP a_640x360_half_straddle_round_trips_through_ffmpeg_across_three_frames: \
3335+ no ffmpeg"
3336+ );
3337+ return;
3338+ }
3339+ let (width, height) = (640usize, 360usize);
3340+ for shift in [0i64, 7, 19] {
3341+ let picture = panned_test_card(width, height, shift);
3342+ let encoded = encode_key_frame(&picture, 100, 0.5).unwrap();
3343+ let decoded = ffmpeg_decode(&encoded.stream, width, height);
3344+ assert_eq!(decoded.y, encoded.reconstruction.y, "shift {shift}: luma");
3345+ assert_eq!(decoded.u, encoded.reconstruction.u, "shift {shift}: U");
3346+ assert_eq!(decoded.v, encoded.reconstruction.v, "shift {shift}: V");
3347+ }
3348+ }
3349+
3325 /// One frame of a real clip, scaled to a whole number of 32x32 blocks.3350 /// One frame of a real clip, scaled to a whole number of 32x32 blocks.
3326 fn clip_frame(clip: &str, skip: &str, width: usize, height: usize) -> Picture {3351 fn clip_frame(clip: &str, skip: &str, width: usize, height: usize) -> Picture {
3327 let out = Command::new("ffmpeg")3352 let out = Command::new("ffmpeg")
@@ -3929,12 +3954,19 @@ mod tests {
3929 /// transform) where the writer intends `TX_8X8` (`txs_ctx=2`), meaning3954 /// transform) where the writer intends `TX_8X8` (`txs_ctx=2`), meaning
3930 /// something *before* this leaf's own `EC_TXBSKIP`/`EC_TXTYPE` still3955 /// something *before* this leaf's own `EC_TXBSKIP`/`EC_TXTYPE` still
3931 /// desyncs the stream by exactly the width of one earlier symbol -- not3956 /// desyncs the stream by exactly the width of one earlier symbol -- not
3932- /// yet isolated to a single named symbol. Ignored rather than deleted,3957+ /// yet isolated to a single named symbol. r15 found the last bug: the
3933- /// so the class stays named and the gate stays green.3958+ /// header fix from r14 explained the rng skew fully, and the remaining
3959+ /// desync (still past `mi_row=4`) was `write_leaf8`'s (4) fix itself --
3960+ /// its `above_mode[c]`/`left_mode[r]` forced write ran *inside* the leaf
3961+ /// loop, once per leaf, so the first leaf's write clobbered the true
3962+ /// external neighbour mode the second leaf of the *same* straddling
3963+ /// quadrant still needed for its non-adjacency axis (a column-straddle
3964+ /// case: two leaves share one `outer_at` column index, so leaf 1's
3965+ /// write to `left_mode[r]` overwrote the real western neighbour before
3966+ /// leaf 2 read it). Fixed by moving the write out of `write_leaf8` and
3967+ /// doing it once, after the whole leaf loop, from the last (bottom/
3968+ /// right-most) leaf's mode. The stream now round-trips through ffmpeg.
3934 #[test]3969 #[test]
3935- #[ignore = "lane-av1-rect r14: leaf(0,8)'s rng now matches through several further \
3936- leaves after the reduced_tx_set header fix; residual desync moved past \
3937- mi_row=4, not yet isolated to a named symbol"]
3938 fn a_single_axis_straddle_round_trips_through_ffmpeg() {3970 fn a_single_axis_straddle_round_trips_through_ffmpeg() {
3939 if !have_ffmpeg() {3971 if !have_ffmpeg() {
3940 eprintln!("SKIP a_single_axis_straddle_round_trips_through_ffmpeg: no ffmpeg");3972 eprintln!("SKIP a_single_axis_straddle_round_trips_through_ffmpeg: no ffmpeg");
crates/ec-av1/src/tile.rsmodified+19 -8
@@ -1248,6 +1248,25 @@ pub fn sb_coeff_key_frame_tile(
1248 )1248 )
1249 });1249 });
1250 }1250 }
1251+ // `record()`'s `above_mode`/`left_mode`
1252+ // write is a no-op at an 8x8 leaf's own
1253+ // side (`side / SUB == 0`), so the next
1254+ // 16x16 quadrant beyond this straddling
1255+ // one would otherwise see whatever stale
1256+ // mode sat here before it: force the
1257+ // write once the whole quadrant's leaves
1258+ // are done, from the last (bottom/right-
1259+ // most) leaf -- lane-av1-rect r15: doing
1260+ // this *inside* `write_leaf8`, once per
1261+ // leaf, let the first leaf's write
1262+ // clobber the true external neighbour a
1263+ // second leaf of the *same* quadrant
1264+ // still needed to read on its
1265+ // non-adjacency axis.
1266+ if let Some((_, mode)) = prev_leaf {
1267+ neighbours.above_mode[at.1] = mode;
1268+ neighbours.left_mode[at.0] = mode;
1269+ }
1251 }1270 }
1252 }1271 }
1253 }1272 }
@@ -1381,14 +1400,6 @@ fn write_leaf8(
1381 mode,1400 mode,
1382 );1401 );
1383 neighbours.record_mi(leaf_mi, 8, grids);1402 neighbours.record_mi(leaf_mi, 8, grids);
1384- // `record()`'s `above_mode`/`left_mode` write is a no-op at this side
1385- // (`side / SUB == 0` for an 8x8 leaf), so the next 16x16 quadrant that
1386- // reads this outer cell -- one straddling quadrant stacked above/left of
1387- // another, never touched by `prev_leaf`'s same-call override -- would
1388- // otherwise see whatever stale mode sat there before this leaf: force
1389- // the write here instead (r12 lane-av1-rect, leaf(2,8)'s mode desync).
1390- neighbours.above_mode[c] = mode;
1391- neighbours.left_mode[r] = mode;
1392 mode1403 mode
1393 }1404 }
1394 1405