forge
Explore
Log in

Don't you dare go Hollow

Decode a real (non-straddle) SPLIT of a 16x16 leaf, fix the whole-64x64-superblock dequant scale

Browse files at this commit

761f32ceafcb28be4300599768960dda5f49fadcAhmet Kaan GümüşParent: 24df967
  • fix
    • decode a real (non-straddle) SPLIT of a 16x16 leaf, fix the whole-64x64-superblock dequant scale
Show full message
fix(av1dec): decode a real (non-straddle) SPLIT of a 16x16 leaf, fix the whole-64x64-superblock dequant scale

decode_stream on real libaom-produced streams hit "partition below 16x16"
on over half of a cpu/crf sweep -- the key-frame tile decoder only handled
SPLIT-to-8x8 when the true frame edge forced it (lane-av1-rect straddle
case), refusing the same split when RD picked it on an interior 16x16.
Reuses the already-tested decode_leaf8 recursion unconditionally instead.

Separately, that fix exposed a live bug in the TX_64X64 zero-pad path:
read_plane built a tx_side x tx_side (32x32) dequant grid and called
dequant_and_inverse/reconstruct with tx_side, both wrong -- dqDenom
(spec 7.12.3) is keyed by the true 64 transform size, not the 32x32
coded corner, and only a quarter of the block was ever reconstructed.
The corner now goes into the top-left of a side x side (64x64) grid,
inverse-transformed and reconstructed at the true size.

gate: cargo test -p ec-av1 --release -- 155 passed, 0 failed, 10 ignored (unchanged from baseline)
crates/ec-av1/src/decode.rsmodified+76 -28
@@ -237,9 +237,9 @@ fn read_coeffs(
237237 if let Some(tx_type) = coding.tx_type.as_deref_mut() {
238238 let t = dec.symbol(tx_type);
239239 if t != 1 {
240- return Err(unsupported(
241- "a transform type other than DCT_DCT (round 2: inter/other intra tx sets)",
242- ));
240+ return Err(unsupported(format!(
241+ "a transform type other than DCT_DCT (round 2: inter/other intra tx sets), symbol {t}"
242+ )));
243243 }
244244 }
245245
@@ -655,16 +655,20 @@ fn read_plane(
655655 let levels = if tx_side == side {
656656 grid
657657 } else {
658- let mut full = vec![0i32; tx_side * tx_side];
659- for row in 0..side {
660- full[row * tx_side..][..side].copy_from_slice(&grid[row * side..][..side]);
658+ // `grid` is `tx_side x tx_side` (the coded corner); `dequant_and_inverse`
659+ // wants the true `side x side` transform, with dqDenom (spec 7.12.3)
660+ // keyed by that true size, not the coded corner's -- so the corner
661+ // goes into the top-left of a `side`-sized grid, not the reverse.
662+ let mut full = vec![0i32; side * side];
663+ for row in 0..tx_side {
664+ full[row * side..][..tx_side].copy_from_slice(&grid[row * tx_side..][..tx_side]);
661665 }
662666 full
663667 };
664- let residual = dequant_and_inverse(&levels, tx_side, 8, i32::from(base_q_idx));
665- plane.reconstruct(x, y, tx_side, predict_mode, reach, &residual);
668+ let residual = dequant_and_inverse(&levels, side, 8, i32::from(base_q_idx));
669+ plane.reconstruct(x, y, side, predict_mode, reach, &residual);
666670 Ok(if tx_side == side {
667- residual_grid_placeholder(&levels, tx_side)
671+ residual_grid_placeholder(&levels, side)
668672 } else {
669673 levels
670674 })
@@ -1075,28 +1079,72 @@ pub fn decode_key_frame_tile(
10751079 let ctx16 = neighbours.partition_ctx(at16, SUB);
10761080 if has_cols16 && has_rows16 {
10771081 let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]);
1078- if part16 != PARTITION_NONE {
1082+ if part16 == PARTITION_NONE {
1083+ decode_block(
1084+ &mut dec,
1085+ &mut cdfs,
1086+ &mut neighbours,
1087+ at16,
1088+ SUB,
1089+ TxbSet::Luma16,
1090+ TxbSet::Chroma8,
1091+ TX16,
1092+ TX8,
1093+ (&scan16, &scan8),
1094+ true,
1095+ &mut y,
1096+ &mut u,
1097+ &mut v,
1098+ base_q_idx,
1099+ )?;
1100+ continue;
1101+ }
1102+ if part16 != PARTITION_SPLIT {
10791103 return Err(unsupported(
1080- "a partition below 16x16 (this encoder never writes one)",
1104+ "a partition below 16x16 other than a clean split (this encoder never writes one)",
10811105 ));
10821106 }
1083- decode_block(
1084- &mut dec,
1085- &mut cdfs,
1086- &mut neighbours,
1087- at16,
1088- SUB,
1089- TxbSet::Luma16,
1090- TxbSet::Chroma8,
1091- TX16,
1092- TX8,
1093- (&scan16, &scan8),
1094- true,
1095- &mut y,
1096- &mut u,
1097- &mut v,
1098- base_q_idx,
1099- )?;
1107+ // A real (non-straddle) SPLIT of a
1108+ // whole 16x16 into four 8x8 leaves --
1109+ // the same recursion the straddle
1110+ // path below already runs when the
1111+ // true frame edge forces it, just
1112+ // over all four positions instead of
1113+ // the one or two the edge leaves.
1114+ let (mi_row0, mi_col0) =
1115+ (sr as u32 * SUB_MI, sc as u32 * SUB_MI);
1116+ let mut prev_leaf: Option<((usize, usize), usize)> = None;
1117+ for i in 0..4 {
1118+ let (mr, mc) =
1119+ (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2);
1120+ let leaf_mi = (mr as usize, mc as usize);
1121+ let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
1122+ let part8 =
1123+ dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
1124+ if part8 != PARTITION_NONE {
1125+ return Err(unsupported(
1126+ "a partition below 8x8 (this encoder never writes one)",
1127+ ));
1128+ }
1129+ let leaf_mode = decode_leaf8(
1130+ &mut dec,
1131+ &mut cdfs,
1132+ &mut neighbours,
1133+ at16,
1134+ leaf_mi,
1135+ (&scan8, &scan4),
1136+ prev_leaf,
1137+ &mut y,
1138+ &mut u,
1139+ &mut v,
1140+ base_q_idx,
1141+ )?;
1142+ prev_leaf = Some((leaf_mi, leaf_mode));
1143+ }
1144+ if let Some((_, mode)) = prev_leaf {
1145+ neighbours.above_mode[sc] = mode;
1146+ neighbours.left_mode[sr] = mode;
1147+ }
11001148 continue;
11011149 }
11021150 // The true edge falls inside this 16x16