forge
Explore
Log in

Don't you dare go Hollow

Derive the key-frame skip context

Browse files at this commit

0b6be1696580c16b8f1347c9784e2c0eca20e802Ahmet Kaan GümüşParent: ae78393
  • fix
    • derive the key-frame skip context
    • refuse a split-transform rect strip
Show full message
fix(av1): derive the key-frame skip context; refuse a split-transform rect strip

Two defects an adversarial source review found in the intra HORZ/VERT strip
merge, both confirmed against libaom.

The key-frame intra path read `skip` from `cdfs.skip[0]` unconditionally, while
av1_get_skip_txfm_context (pred_common.h:175-181) is above_skip + left_skip.
That was latent -- key frames rarely skip -- but the rect strips are skip-only,
so every strip this decoder accepts guarantees a skip=1 neighbour, and the
second strip of a HORZ pair would have read the wrong CDF row and desynced the
rest of the tile. Fixed at all three intra call sites, not just the rect one:
the defect is the class, and the pre-existing square site is now load-bearing.
The context comes off the mi skip grid, which every path already fills, with an
absent neighbour contributing 0 the way an absent above_mi/left_mi does.

Second, tx_depth was read and then ignored: the predictor ran over the whole
strip regardless, where libaom predicts per transform unit with each unit
taking its edges from the previous unit's reconstruction. That is a silent
pixel mismatch, and it violates this change's own skip-only contract, so a
split transform now refuses by name until the per-TU loop is ported.

Full lib suite 224 passed / 0 failed -- the skip-context fix is inert for every
existing stream, as it must be.
crates/ec-av1/src/decode.rsmodified+27 -7
@@ -1140,6 +1140,16 @@ impl Neighbours {
1140 .unwrap_or(false)1140 .unwrap_or(false)
1141 }1141 }
1142 1142
1143+ /// The `skip_txfm` context of a block whose top-left mi cell is
1144+ /// `(mi_r, mi_c)`: libaom `av1_get_skip_txfm_context`
1145+ /// (`pred_common.h:175-181`) is `above_mi->skip_txfm + left_mi->skip_txfm`,
1146+ /// with an absent neighbour contributing 0. The mi grid is per tile, so
1147+ /// row/column 0 is a tile edge and has no neighbour on that axis.
1148+ fn skip_txfm_ctx(&self, mi_r: usize, mi_c: usize) -> usize {
1149+ usize::from(mi_r > 0 && self.skip_at(mi_r - 1, mi_c))
1150+ + usize::from(mi_c > 0 && self.skip_at(mi_r, mi_c - 1))
1151+ }
1152+
1143 fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool {1153 fn is_skip_txfm(&self, mi_r: usize, mi_c: usize) -> bool {
1144 (0..2).all(|rr| {1154 (0..2).all(|rr| {
1145 (0..2).all(|cc| {1155 (0..2).all(|cc| {
@@ -1562,6 +1572,7 @@ fn read_intra_mode_rect(
1562 bw: usize,1572 bw: usize,
1563 bh: usize,1573 bh: usize,
1564 enable_filter_intra: bool,1574 enable_filter_intra: bool,
1575+ skip_ctx: usize,
1565 ) -> Result<(1576 ) -> Result<(
1566 bool,1577 bool,
1567 usize,1578 usize,
@@ -1571,7 +1582,7 @@ fn read_intra_mode_rect(
1571 Option<(i32, i32)>,1582 Option<(i32, i32)>,
1572 Option<usize>,1583 Option<usize>,
1573 )> {1584 )> {
1574- let skip = dec.symbol(&mut cdfs.skip[0]) != 0;1585+ let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
1575 let above_ctx = INTRA_MODE_CTX[above_mode];1586 let above_ctx = INTRA_MODE_CTX[above_mode];
1576 let left_ctx = INTRA_MODE_CTX[left_mode];1587 let left_ctx = INTRA_MODE_CTX[left_mode];
1577 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);1588 let mode = dec.symbol(&mut cdfs.kf_y_mode[above_ctx][left_ctx]);
@@ -1696,6 +1707,7 @@ fn decode_block_rect(
1696 bw,1707 bw,
1697 bh,1708 bh,
1698 enable_filter_intra,1709 enable_filter_intra,
1710+ neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
1699 )?;1711 )?;
1700 if filter_intra.is_some() {1712 if filter_intra.is_some() {
1701 // `predict_filter_intra` (spec 7.11.2.3) is square-only in this1713 // `predict_filter_intra` (spec 7.11.2.3) is square-only in this
@@ -1717,12 +1729,17 @@ fn decode_block_rect(
1717 let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);1729 let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
1718 if depth != 0 {1730 if depth != 0 {
1719 TX_DEPTH_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);1731 TX_DEPTH_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
1732+ // A split transform is predicted per transform unit, each taking its
1733+ // edges from the previous unit's reconstruction (the square path's own
1734+ // per-TU loop does exactly that). Predicting the whole strip in one
1735+ // shot would silently produce different pixels, so refuse by name
1736+ // until that loop is ported for rect strips.
1737+ return Err(unsupported(
1738+ "a HORZ/VERT intra strip with a split transform (per-unit rect \
1739+ prediction is not ported)",
1740+ ));
1720 }1741 }
1721- let (tx_w, tx_h) = match depth {1742+ let (tx_w, tx_h) = (bw, bh);
1722- 0 => (bw, bh),
1723- 1 => (16, 16),
1724- _ => (8, 8),
1725- };
1726 if !skip {1743 if !skip {
1727 return Err(unsupported(1744 return Err(unsupported(
1728 "a non-skip HORZ/VERT intra strip needs a rectangular transform \1745 "a non-skip HORZ/VERT intra strip needs a rectangular transform \
@@ -1806,6 +1823,7 @@ fn read_intra_mode(
1806 cfl: bool,1823 cfl: bool,
1807 side: usize,1824 side: usize,
1808 enable_filter_intra: bool,1825 enable_filter_intra: bool,
1826+ skip_ctx: usize,
1809 ) -> Result<(1827 ) -> Result<(
1810 bool,1828 bool,
1811 usize,1829 usize,
@@ -1816,7 +1834,7 @@ fn read_intra_mode(
1816 Option<usize>,1834 Option<usize>,
1817 )> {1835 )> {
1818 let trace = std::env::var_os("EC_AV1_TRACE").is_some();1836 let trace = std::env::var_os("EC_AV1_TRACE").is_some();
1819- let skip = dec.symbol(&mut cdfs.skip[0]) != 0;1837+ let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
1820 if trace {1838 if trace {
1821 eprintln!("TRACE skip value={}", skip as i32);1839 eprintln!("TRACE skip value={}", skip as i32);
1822 }1840 }
@@ -2354,6 +2372,7 @@ fn decode_block(
2354 cfl,2372 cfl,
2355 side,2373 side,
2356 enable_filter_intra,2374 enable_filter_intra,
2375+ neighbours.skip_txfm_ctx(r * (SUB / MI), c * (SUB / MI)),
2357 )?;2376 )?;
2358 // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED`2377 // `predict` panics outside `DC_PRED..=PAETH_PRED` (0..=12); `UV_CFL_PRED`
2359 // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the2378 // (13) predicts as `DC_PRED` with the [`cfl_scaled`] nudge carrying the
@@ -2667,6 +2686,7 @@ fn decode_leaf8(
2667 true,2686 true,
2668 8,2687 8,
2669 enable_filter_intra,2688 enable_filter_intra,
2689+ neighbours.skip_txfm_ctx(leaf_mi.0, leaf_mi.1),
2670 )?;2690 )?;
2671 let uv_predict_mode = if uv_mode == UV_CFL_PRED {2691 let uv_predict_mode = if uv_mode == UV_CFL_PRED {
2672 DC_PRED2692 DC_PRED