forge
Explore
Log in

Don't you dare go Hollow

8x8 leaf reads the CFL-allowed uv_mode CDF, threads its mode forward

Browse files at this commit

e3b2c93e44a508a266cb435fba0292d8fe4e4a0eAhmet Kaan GümüşParent: 3a1f168
  • fix
    • 8x8 leaf reads the CFL-allowed uv_mode CDF, threads its mode forward
Show full message
fix(av1): 8x8 leaf reads the CFL-allowed uv_mode CDF, threads its mode forward

write_leaf8 hardcoded cfl:false for write_intra_mode's chroma-mode CDF, but
is_cfl_allowed (spec 5.11.5) is true up to 32x32 -- every other write_block
caller at 16x16 and up already passes true. The narrower uv_mode_no_cfl
alphabet is one symbol short of uv_mode_cfl, so even an identical DC_PRED
decision consumed a different amount of arithmetic range and derailed the
stream from that leaf onward.

record()'s above_mode/left_mode write is also a no-op at an 8x8 leaf's own
side (side/SUB == 0), and write_leaf8 only called record_mi, never updating
those coarse arrays -- so a second straddling 16x16 quadrant stacked above
or left of the first (outside r11's same-call prev_leaf override) read
whatever stale mode sat in that slot. Fixed by writing the leaf's own mode
into above_mode[c]/left_mode[r] directly.

Full suite still 134/0/10; the straddle round-trip stays ignored -- a
residual divergence now shows up one leaf further in (leaf(2,8) reads its
own luma coefficient block at the wrong tx size), not yet isolated to a
single symbol.
crates/ec-av1/src/encode.rsmodified+30 -5
@@ -3889,12 +3889,37 @@ mod tests {
3889 /// eset/size slot). Both fixes are provably correct against libaom3889 /// eset/size slot). Both fixes are provably correct against libaom
3890 /// source and each closed part of the gap (leaf0's `eob` went from a3890 /// source and each closed part of the gap (leaf0's `eob` went from a
3891 /// desynced 36 to a near-miss 3, writer's real eob is 7), but a residual3891 /// desynced 36 to a near-miss 3, writer's real eob is 7), but a residual
3892- /// divergence remains in the `EOB_PT` symbol's decoded value despite an3892+ /// divergence remained in the `EOB_PT` symbol's decoded value despite an
3893- /// aligned bit cost -- next candidate: `eob_pt_64_luma`'s CDF3893+ /// aligned bit cost. r12 traced that residual with a fresh dual-trace
3894- /// adaptation state, exercised nowhere else. Ignored rather than3894+ /// (do not reuse r11's committed logs, which predate its own fixes) and
3895- /// deleted, so the class stays named and the gate stays green.3895+ /// found two more real bugs, both now fixed: (3) `write_leaf8` hardcoded
3896+ /// `cfl: false` for `write_intra_mode`'s chroma-mode CDF choice, but
3897+ /// `is_cfl_allowed` (spec 5.11.5) is true for any block `<= 32x32` --
3898+ /// every other `write_block` caller at 16x16 and up already passes
3899+ /// `true`; the narrower `uv_mode_no_cfl` alphabet is one symbol short of
3900+ /// `uv_mode_cfl`, so even an identical `DC_PRED` decision consumed a
3901+ /// different amount of arithmetic range and derailed everything after
3902+ /// it. (4) `record()`'s `above_mode`/`left_mode` write is a no-op at an
3903+ /// 8x8 leaf's own side (`side / SUB == 0` for `SUB` = 16), and
3904+ /// `write_leaf8` called only `record_mi` (the coefficient-context half),
3905+ /// never updating those coarse arrays itself -- so a *second* straddling
3906+ /// 16x16 quadrant stacked above or left of the first (never covered by
3907+ /// r11's same-call `prev_leaf` override, which only threads state
3908+ /// between the two leaves of one shared quadrant) read whatever stale
3909+ /// mode sat in that slot before either leaf ran. Fixed by writing the
3910+ /// leaf's own mode into `above_mode[c]`/`left_mode[r]` directly. Fixing
3911+ /// (3) alone shrank the tell drift after leaf(0,8) from a decoder
3912+ /// `eob_pt=3` (wrong) vs the writer's real `eob_pt=4` down to a `tell`
3913+ /// offset of a single unit; fixing (3)+(4) together still leaves a
3914+ /// residual divergence one leaf further in -- the decoder now reads
3915+ /// leaf(2,8)'s own luma coefficient block as `txs_ctx=1` (a 32-sample
3916+ /// transform) where the writer intends `TX_8X8` (`txs_ctx=2`), meaning
3917+ /// something *before* this leaf's own `EC_TXBSKIP`/`EC_TXTYPE` still
3918+ /// desyncs the stream by exactly the width of one earlier symbol -- not
3919+ /// yet isolated to a single named symbol. Ignored rather than deleted,
3920+ /// so the class stays named and the gate stays green.
3896 #[test]3921 #[test]
3897- #[ignore = "lane-av1-rect r11: 8x8-leaf path desyncs dav1d; EOB_PT for Luma8 still wrong"]3922+ #[ignore = "lane-av1-rect r12: 8x8-leaf path desyncs dav1d; leaf(2,8) reads the wrong tx size"]
3898 fn a_single_axis_straddle_round_trips_through_ffmpeg() {3923 fn a_single_axis_straddle_round_trips_through_ffmpeg() {
3899 if !have_ffmpeg() {3924 if !have_ffmpeg() {
3900 eprintln!("SKIP a_single_axis_straddle_round_trips_through_ffmpeg: no ffmpeg");3925 eprintln!("SKIP a_single_axis_straddle_round_trips_through_ffmpeg: no ffmpeg");
crates/ec-av1/src/tile.rsmodified+16 -2
@@ -1337,7 +1337,6 @@ fn write_block(
1337 /// in 4x4 mode-info units, which is what its coefficient context (finer than1337 /// in 4x4 mode-info units, which is what its coefficient context (finer than
1338 /// [`SUB`]) is kept and read at.1338 /// [`SUB`]) is kept and read at.
1339 #[allow(clippy::too_many_arguments)]1339 #[allow(clippy::too_many_arguments)]
1340-#[allow(clippy::too_many_arguments)]
1341 fn write_leaf8(1340 fn write_leaf8(
1342 enc: &mut SymbolEncoder,1341 enc: &mut SymbolEncoder,
1343 cdfs: &mut Cdfs,1342 cdfs: &mut Cdfs,
@@ -1363,7 +1362,14 @@ fn write_leaf8(
1363 left_mode = pmode;1362 left_mode = pmode;
1364 }1363 }
1365 }1364 }
1366- let mode = write_intra_mode(enc, cdfs, block, above_mode, left_mode, false);1365+ // An 8x8 leaf is well within `is_cfl_allowed`'s <=32x32 bound (spec
1366+ // 5.11.5), so it reads the CFL-allowed `uv_mode_cfl` CDF -- like every
1367+ // other `write_block` caller at 16x16 and up -- not the narrower
1368+ // no-CFL one: r12 lane-av1-rect, this leaf's own `cfl: false` was the
1369+ // true first divergence (a differently-sized alphabet under the same
1370+ // DC_PRED decision desyncs the coder even though the decoded mode is
1371+ // unchanged).
1372+ let mode = write_intra_mode(enc, cdfs, block, above_mode, left_mode, true);
1367 let planes = [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4];1373 let planes = [TxbSet::Luma8, TxbSet::Chroma4, TxbSet::Chroma4];
1368 write_block_planes(1374 write_block_planes(
1369 enc,1375 enc,
@@ -1375,6 +1381,14 @@ fn write_leaf8(
1375 mode,1381 mode,
1376 );1382 );
1377 neighbours.record_mi(leaf_mi, 8, grids);1383 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;
1378 mode1392 mode
1379 }1393 }
1380 1394