forge
Explore
Log in

Don't you dare go Hollow

wip(rectx): session restart -- uncommitted builder state preserved by orchestrator

Browse files at this commit

0457feb553ba00229c586e2da98fdbe4241930d2Ahmet Kaan GümüşParent: 1122732
crates/ec-av1/src/cdf_state.rsmodified+33 -10
@@ -121,19 +121,30 @@ pub(crate) enum TxbSet {
121 /// below 16x16 (lane-rectx, `decode_leaf_rect`'s own leaf, one level121 /// below 16x16 (lane-rectx, `decode_leaf_rect`'s own leaf, one level
122 /// under [`LumaRect32x16`](TxbSet::LumaRect32x16)): `get_txsize_entropy_ctx`122 /// under [`LumaRect32x16`](TxbSet::LumaRect32x16)): `get_txsize_entropy_ctx`
123 /// reduces this 2:1 rect size to `TX_16X16` too, so this shares every123 /// reduces this 2:1 rect size to `TX_16X16` too, so this shares every
124- /// table [`Luma16`](TxbSet::Luma16) does -- INCLUDING its mode-indexed124+ /// table [`Luma16`](TxbSet::Luma16) does except two: its mode-indexed
125- /// `tx_type` CDF, the same adapted table object -- except `eob_pt`, which125+ /// `tx_type` CDF, which is the *8x8* row's (see
126+ /// [`LumaRect16x8Set1`](TxbSet::LumaRect16x8Set1)), and `eob_pt`, which
126 /// reads the true 128-position [`crate::cdf::EOB_PT_128_LUMA`] rather127 /// reads the true 128-position [`crate::cdf::EOB_PT_128_LUMA`] rather
127 /// than `Luma16`'s 256-position one. Unlike128 /// than `Luma16`'s 256-position one. Unlike
128 /// [`LumaRect32x16`](TxbSet::LumaRect32x16), this size DOES carry a129 /// [`LumaRect32x16`](TxbSet::LumaRect32x16), this size DOES carry a
129- /// `tx_type` symbol: `av1_get_ext_tx_set_type`'s `use_reduced_set` branch130+ /// `tx_type` symbol: `av1_get_ext_tx_set_type` (`av1/common/blockd.h`)
130- /// returns `EXT_TX_SET_DTT4_IDTX` for every `tx_size_sqr_up == TX_16X16`131+ /// sees `tx_size_sqr_up == TX_16X16`, so intra reads
131- /// regardless of the real (non-square) `tx_size`, the same set132+ /// `EXT_TX_SET_DTT4_IDTX` under `reduced_tx_set` and
132- /// `Luma16`'s own read already uses -- confirmed against133+ /// `EXT_TX_SET_DTT4_IDTX_1DDCT` without it (`tx_size_sqr` is `TX_8X8`
133- /// `av1/common/blockd.h`'s `av1_get_ext_tx_set_type` before landing,134+ /// here, not `TX_16X16`) -- this variant is the reduced arm, its
134- /// see `decode_block_rect`'s own doc comment for the desync this gap135+ /// `Set1` sibling the other.
135- /// left when it was still unhandled.
136 LumaRect16x8,136 LumaRect16x8,
137+ /// [`LumaRect16x8`](TxbSet::LumaRect16x8)'s `reduced_tx_set: false`
138+ /// counterpart (lane-rectx r3), the same split
139+ /// [`Luma8Set1`](TxbSet::Luma8Set1) has to [`Luma8`](TxbSet::Luma8) --
140+ /// and it is deliberately those two tables, not the 16x16 row: libaom's
141+ /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][square_tx_size]` with
142+ /// `square_tx_size = txsize_sqr_map[tx_size]`, which for `TX_16X8`/
143+ /// `TX_8X16` is `TX_8X8`, NOT the `txsize_sqr_up_map` `TX_16X16` the
144+ /// txb-skip/base/br tables use (`get_txsize_entropy_ctx`). r2 read the
145+ /// 16x16 row's five-symbol reduced CDF here and desynced on the very
146+ /// first coded rect leaf.
147+ LumaRect16x8Set1,
137 /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx):148 /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx):
138 /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the149 /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the
139 /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of150 /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of
@@ -1476,7 +1487,19 @@ impl Cdfs {
1476 base_eob: &mut self.base_eob_luma_16,1487 base_eob: &mut self.base_eob_luma_16,
1477 br: &mut self.br_luma_16,1488 br: &mut self.br_luma_16,
1478 dc_sign: &mut self.dc_sign_luma,1489 dc_sign: &mut self.dc_sign_luma,
1479- tx_type: Some(self.intra_tx_type_16[mode].as_mut_slice()),1490+ tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()),
1491+ eob_pt_class1: None,
1492+ },
1493+ TxbSet::LumaRect16x8Set1 => TxbTables {
1494+ side: 16,
1495+ txb_skip: &mut self.txb_skip_luma_16,
1496+ eob_pt: &mut self.eob_pt_128_luma,
1497+ eob_extra: &mut self.eob_extra_luma_16,
1498+ base: &mut self.base_luma_16,
1499+ base_eob: &mut self.base_eob_luma_16,
1500+ br: &mut self.br_luma_16,
1501+ dc_sign: &mut self.dc_sign_luma,
1502+ tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()),
1480 eob_pt_class1: None,1503 eob_pt_class1: None,
1481 },1504 },
1482 TxbSet::ChromaRect8x4 => TxbTables {1505 TxbSet::ChromaRect8x4 => TxbTables {
crates/ec-av1/src/decode.rsmodified+86 -19
@@ -1655,6 +1655,11 @@ fn read_coeffs_rect(
1655 if all_zero {1655 if all_zero {
1656 return Ok((grid, TxType::DctDct));1656 return Ok((grid, TxType::DctDct));
1657 }1657 }
1658+ let trace = std::env::var_os("EC_TRACE_COEFF").is_some();
1659+ if trace {
1660+ let (rng, _) = dec.debug_state();
1661+ eprintln!("EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero=0 rng={rng}");
1662+ }
1658 let mut tx_type = default_tx_type;1663 let mut tx_type = default_tx_type;
1659 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {1664 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {
1660 // Mirrors [`read_coeffs`]'s own `tx_type` read: the CDF row's width1665 // Mirrors [`read_coeffs`]'s own `tx_type` read: the CDF row's width
@@ -1675,7 +1680,15 @@ fn read_coeffs_rect(
1675 "a non-2D tx class on a rectangular transform (never expected at this size)",1680 "a non-2D tx class on a rectangular transform (never expected at this size)",
1676 ));1681 ));
1677 }1682 }
1683+ if trace {
1684+ let (rng, _) = dec.debug_state();
1685+ eprintln!("EC_COEFF_STEP tag=tx_type rng={rng}");
1686+ }
1678 let eob = read_eob(dec, coding, TxClass::TwoD);1687 let eob = read_eob(dec, coding, TxClass::TwoD);
1688+ if trace {
1689+ let (rng, _) = dec.debug_state();
1690+ eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={rng}");
1691+ }
1679 let mut levels = vec![0i32; w * h];1692 let mut levels = vec![0i32; w * h];
1680 for scan_idx in (0..eob).rev() {1693 for scan_idx in (0..eob).rev() {
1681 let pos = scan[scan_idx] as usize;1694 let pos = scan[scan_idx] as usize;
@@ -1704,6 +1717,10 @@ fn read_coeffs_rect(
1704 level1717 level
1705 };1718 };
1706 levels[pos] = level;1719 levels[pos] = level;
1720+ if trace {
1721+ let (rng, _) = dec.debug_state();
1722+ eprintln!("EC_COEFF_STEP tag=base c={scan_idx} pos={pos} level={level} rng={rng}");
1723+ }
1707 }1724 }
1708 for &pos in &scan[..eob] {1725 for &pos in &scan[..eob] {
1709 let level = levels[pos as usize];1726 let level = levels[pos as usize];
@@ -3534,6 +3551,7 @@ fn decode_leaf_rect(
3534 allow_screen_content_tools: bool,3551 allow_screen_content_tools: bool,
3535 base_q_idx: u8,3552 base_q_idx: u8,
3536 tx_select: bool,3553 tx_select: bool,
3554+ reduced_tx_set: bool,
3537 ) -> Result<usize> {3555 ) -> Result<usize> {
3538 let _ = base_q_idx;3556 let _ = base_q_idx;
3539 if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {3557 if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {
@@ -3626,7 +3644,12 @@ fn decode_leaf_rect(
3626 (&SCAN_8X16, &SCAN_4X8)3644 (&SCAN_8X16, &SCAN_4X8)
3627 };3645 };
3628 let around = neighbours.around_mi_rect(leaf_mi, bw, bh);3646 let around = neighbours.around_mi_rect(leaf_mi, bw, bh);
3629- let mut luma_coding = cdfs.txb(TxbSet::LumaRect16x8, mode);3647+ let luma_set = if reduced_tx_set {
3648+ TxbSet::LumaRect16x8
3649+ } else {
3650+ TxbSet::LumaRect16x8Set1
3651+ };
3652+ let mut luma_coding = cdfs.txb(luma_set, mode);
3630 let (l_levels, luma_tx_type) = read_coeffs_rect(3653 let (l_levels, luma_tx_type) = read_coeffs_rect(
3631 dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct,3654 dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct,
3632 )?;3655 )?;
@@ -5200,6 +5223,31 @@ fn decode_block(
5200 /// at. Returns the mode this leaf decoded, for the caller's own5223 /// at. Returns the mode this leaf decoded, for the caller's own
5201 /// `prev_leaf`/final mode-writeback bookkeeping.5224 /// `prev_leaf`/final mode-writeback bookkeeping.
5202 #[allow(clippy::too_many_arguments)]5225 #[allow(clippy::too_many_arguments)]
5226+/// The coarse 16x16 `above_mode`/`left_mode` cells a four-way SPLIT of one
5227+/// 16x16 parent leaves behind (lane-rectx r3). The next block DOWN reads
5228+/// `above_mode[col]`, and its true above neighbour is the mi directly above
5229+/// its own top-left corner -- the parent's BOTTOM-LEFT leaf, not the last one
5230+/// decoded; the next block RIGHT reads `left_mode[row]`, whose true left
5231+/// neighbour is the parent's TOP-RIGHT leaf. Writing the z-order last leaf
5232+/// (bottom-right) into both, as this path did, is right only when all four
5233+/// leaves happen to share a mode. `done` may be short at the true frame edge
5234+/// (the straddle caller filters positions off the frame), so each side falls
5235+/// back to the last leaf actually decoded.
5236+fn write_back_split_modes(
5237+ neighbours: &mut Neighbours,
5238+ done: &[((usize, usize), usize)],
5239+ parent_mi: (usize, usize),
5240+ slot: (usize, usize),
5241+) {
5242+ let (sr, sc) = slot;
5243+ let Some(&(_, last)) = done.last() else {
5244+ return;
5245+ };
5246+ let find = |mi: (usize, usize)| done.iter().find(|&&(at, _)| at == mi).map(|&(_, m)| m);
5247+ neighbours.above_mode[sc] = find((parent_mi.0 + 2, parent_mi.1)).unwrap_or(last);
5248+ neighbours.left_mode[sr] = find((parent_mi.0, parent_mi.1 + 2)).unwrap_or(last);
5249+}
5250+
5203 fn decode_leaf8(5251 fn decode_leaf8(
5204 dec: &mut SymbolDecoder,5252 dec: &mut SymbolDecoder,
5205 cdfs: &mut Cdfs,5253 cdfs: &mut Cdfs,
@@ -5207,7 +5255,7 @@ fn decode_leaf8(
5207 outer_at: (usize, usize),5255 outer_at: (usize, usize),
5208 leaf_mi: (usize, usize),5256 leaf_mi: (usize, usize),
5209 scans: (&[u16], &[u16]),5257 scans: (&[u16], &[u16]),
5210- prev_leaf: Option<((usize, usize), usize)>,5258+ prev_leaves: &[((usize, usize), usize)],
5211 y: &mut PlaneBuf,5259 y: &mut PlaneBuf,
5212 u: &mut PlaneBuf,5260 u: &mut PlaneBuf,
5213 v: &mut PlaneBuf,5261 v: &mut PlaneBuf,
@@ -5221,7 +5269,18 @@ fn decode_leaf8(
5221 let (r, c) = outer_at;5269 let (r, c) = outer_at;
5222 let mut above_mode = neighbours.above_mode[c];5270 let mut above_mode = neighbours.above_mode[c];
5223 let mut left_mode = neighbours.left_mode[r];5271 let mut left_mode = neighbours.left_mode[r];
5224- if let Some(((pr, pc), pmode)) = prev_leaf {5272+ // lane-rectx r3: EVERY sibling leaf already decoded inside this 16x16
5273+ // parent, not just the previous one in z-order. A four-way SPLIT's
5274+ // bottom-left leaf has the TOP-LEFT leaf directly above it (the previous
5275+ // leaf is the top-right one, which is neither above nor left of it), and
5276+ // the bottom-right leaf has two live siblings at once -- top-right above,
5277+ // bottom-left to the left. Passing only the z-order predecessor left both
5278+ // reading the coarse 16x16 `above_mode`/`left_mode` cell, i.e. a mode
5279+ // from the block ABOVE THE PARENT, and the `kf_y_mode` CDF row that
5280+ // indexes desynced the tile at the third leaf of every real SPLIT
5281+ // (measured against the instrumented aomdec: same decoded value, wrong
5282+ // range -- `EC_ISTEP mi_row=6 mi_col=0 name=mode` rng 46476 vs 37546).
5283+ for &((pr, pc), pmode) in prev_leaves {
5225 if pc == leaf_mi.1 && leaf_mi.0 == pr + 2 {5284 if pc == leaf_mi.1 && leaf_mi.0 == pr + 2 {
5226 above_mode = pmode;5285 above_mode = pmode;
5227 } else if pr == leaf_mi.0 && leaf_mi.1 == pc + 2 {5286 } else if pr == leaf_mi.0 && leaf_mi.1 == pc + 2 {
@@ -7023,7 +7082,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7023 at16,7082 at16,
7024 top_right,7083 top_right,
7025 (&scan8, &scan4),7084 (&scan8, &scan4),
7026- None,7085+ &[],
7027 &mut y,7086 &mut y,
7028 &mut u,7087 &mut u,
7029 &mut v,7088 &mut v,
@@ -7041,7 +7100,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7041 at16,7100 at16,
7042 bot_right,7101 bot_right,
7043 (&scan8, &scan4),7102 (&scan8, &scan4),
7044- Some((top_right, mode_tr)),7103+ &[(top_right, mode_tr)],
7045 &mut y,7104 &mut y,
7046 &mut u,7105 &mut u,
7047 &mut v,7106 &mut v,
@@ -7086,6 +7145,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7086 allow_screen_content_tools,7145 allow_screen_content_tools,
7087 base_q_idx,7146 base_q_idx,
7088 tx_select,7147 tx_select,
7148+ reduced_tx_set,
7089 )?;7149 )?;
7090 let mode_bot = decode_leaf_rect(7150 let mode_bot = decode_leaf_rect(
7091 &mut dec,7151 &mut dec,
@@ -7103,6 +7163,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7103 allow_screen_content_tools,7163 allow_screen_content_tools,
7104 base_q_idx,7164 base_q_idx,
7105 tx_select,7165 tx_select,
7166+ reduced_tx_set,
7106 )?;7167 )?;
7107 neighbours.above_mode[sc] = mode_bot;7168 neighbours.above_mode[sc] = mode_bot;
7108 neighbours.left_mode[sr] = mode_bot;7169 neighbours.left_mode[sr] = mode_bot;
@@ -7132,6 +7193,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7132 allow_screen_content_tools,7193 allow_screen_content_tools,
7133 base_q_idx,7194 base_q_idx,
7134 tx_select,7195 tx_select,
7196+ reduced_tx_set,
7135 )?;7197 )?;
7136 let mode_right = decode_leaf_rect(7198 let mode_right = decode_leaf_rect(
7137 &mut dec,7199 &mut dec,
@@ -7149,6 +7211,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7149 allow_screen_content_tools,7211 allow_screen_content_tools,
7150 base_q_idx,7212 base_q_idx,
7151 tx_select,7213 tx_select,
7214+ reduced_tx_set,
7152 )?;7215 )?;
7153 neighbours.above_mode[sc] = mode_right;7216 neighbours.above_mode[sc] = mode_right;
7154 neighbours.left_mode[sr] = mode_right;7217 neighbours.left_mode[sr] = mode_right;
@@ -7168,7 +7231,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7168 // the one or two the edge leaves.7231 // the one or two the edge leaves.
7169 let (mi_row0, mi_col0) =7232 let (mi_row0, mi_col0) =
7170 (sr as u32 * SUB_MI, sc as u32 * SUB_MI);7233 (sr as u32 * SUB_MI, sc as u32 * SUB_MI);
7171- let mut prev_leaf: Option<((usize, usize), usize)> = None;7234+ let mut done: Vec<((usize, usize), usize)> = Vec::new();
7172 for i in 0..4 {7235 for i in 0..4 {
7173 let (mr, mc) =7236 let (mr, mc) =
7174 (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2);7237 (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2);
@@ -7193,7 +7256,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7193 at16,7256 at16,
7194 leaf_mi,7257 leaf_mi,
7195 (&scan8, &scan4),7258 (&scan8, &scan4),
7196- prev_leaf,7259+ &done,
7197 &mut y,7260 &mut y,
7198 &mut u,7261 &mut u,
7199 &mut v,7262 &mut v,
@@ -7204,12 +7267,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7204 tx_select,7267 tx_select,
7205 reduced_tx_set,7268 reduced_tx_set,
7206 )?;7269 )?;
7207- prev_leaf = Some((leaf_mi, leaf_mode));7270+ done.push((leaf_mi, leaf_mode));
7208- }
7209- if let Some((_, mode)) = prev_leaf {
7210- neighbours.above_mode[sc] = mode;
7211- neighbours.left_mode[sr] = mode;
7212 }7271 }
7272+ write_back_split_modes(
7273+ &mut neighbours,
7274+ &done,
7275+ (mi_row0 as usize, mi_col0 as usize),
7276+ (sr, sc),
7277+ );
7213 continue;7278 continue;
7214 }7279 }
7215 // The true edge falls inside this 16x167280 // The true edge falls inside this 16x16
@@ -7242,7 +7307,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7242 .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2))7307 .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2))
7243 .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols)7308 .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols)
7244 .collect();7309 .collect();
7245- let mut prev_leaf: Option<((usize, usize), usize)> = None;7310+ let mut done: Vec<((usize, usize), usize)> = Vec::new();
7246 for (mr, mc) in leaf_positions {7311 for (mr, mc) in leaf_positions {
7247 let leaf_mi = (mr as usize, mc as usize);7312 let leaf_mi = (mr as usize, mc as usize);
7248 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);7313 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
@@ -7264,7 +7329,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7264 at16,7329 at16,
7265 leaf_mi,7330 leaf_mi,
7266 (&scan8, &scan4),7331 (&scan8, &scan4),
7267- prev_leaf,7332+ &done,
7268 &mut y,7333 &mut y,
7269 &mut u,7334 &mut u,
7270 &mut v,7335 &mut v,
@@ -7275,7 +7340,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7275 tx_select,7340 tx_select,
7276 reduced_tx_set,7341 reduced_tx_set,
7277 )?;7342 )?;
7278- prev_leaf = Some((leaf_mi, leaf_mode));7343+ done.push((leaf_mi, leaf_mode));
7279 }7344 }
7280 // `record()`'s `above_mode`/`left_mode`7345 // `record()`'s `above_mode`/`left_mode`
7281 // write is a no-op at an 8x8 leaf's own7346 // write is a no-op at an 8x8 leaf's own
@@ -7283,10 +7348,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7283 // 16x16 slot's leaves are done, from the7348 // 16x16 slot's leaves are done, from the
7284 // last leaf (mirrors the writer's r157349 // last leaf (mirrors the writer's r15
7285 // fix).7350 // fix).
7286- if let Some((_, mode)) = prev_leaf {7351+ write_back_split_modes(
7287- neighbours.above_mode[sc] = mode;7352+ &mut neighbours,
7288- neighbours.left_mode[sr] = mode;7353+ &done,
7289- }7354+ (mi_row0 as usize, mi_col0 as usize),
7355+ (sr, sc),
7356+ );
7290 }7357 }
7291 }7358 }
7292 PARTITION_HORZ => {7359 PARTITION_HORZ => {
crates/ec-av1/src/stream.rsmodified+184 -55
@@ -5328,79 +5328,208 @@ mod tests {
5328 result.as_ref().map(|f| f.len()).map_err(|e| e.to_string())5328 result.as_ref().map(|f| f.len()).map_err(|e| e.to_string())
5329 );5329 );
5330 }5330 }
5331+ /// lane-rectx r3: a real `aomenc` stream whose 16x16-level
5332+ /// `PARTITION_HORZ`/`PARTITION_VERT` strips are CODED (non-skip), i.e.
5333+ /// carry genuine `TX_16X8`/`TX_8X16` luma coefficients and their
5334+ /// `TX_8X4`/`TX_4X8` chroma halves through [`decode_leaf_rect`]'s
5335+ /// lane-rectx arm -- the refusal "a coded (non-skip) HORZ/VERT rect strip
5336+ /// below 16x16" this round lifts. `--min-partition-size=8
5337+ /// --max-partition-size=32 --enable-rect-partitions=1` is what makes
5338+ /// aomenc reach for a 16x8 leaf at all; mandelbrot at `cq-level=24` is
5339+ /// what makes those leaves non-skip (a gradient fixture codes them all
5340+ /// away). `--reduced-tx-type-set=1` pins the five-symbol
5341+ /// `EXT_TX_SET_DTT4_IDTX` alphabet: without it aomenc also writes
5342+ /// `V_DCT`/`H_DCT`, whose 1D tx classes [`read_coeffs_rect`] still
5343+ /// refuses by name (see the r3 report's open residue), so a `=0` run
5344+ /// would prove nothing about the 2D path it does support.
5345+ ///
5346+ /// r2 shipped this path unproven; it was wrong. `TxbSet::LumaRect16x8`
5347+ /// read its `tx_type` symbol from the 16x16 row, but libaom's
5348+ /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][txsize_sqr_map[tx_size]]`
5349+ /// and `txsize_sqr_map[TX_16X8] == TX_8X8` -- a five-symbol CDF where a
5350+ /// seven-symbol one belonged, desyncing at the FIRST coded rect leaf
5351+ /// (whole frame wrong from pixel (0,0)).
5331 #[test]5352 #[test]
5332- fn scratch_probe_rectx_mandelbrot() {5353+ fn a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact() {
5354+ const NAME: &str =
5355+ "a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact";
5333 let _gate_lock = lock_gate_counters();5356 let _gate_lock = lock_gate_counters();
5334- if !have_ffmpeg() || !have_aomenc() {5357+ if !have_ffmpeg() {
5335- eprintln!("SKIP: no tools");5358+ eprintln!("SKIP {NAME}: no ffmpeg");
5359+ return;
5360+ }
5361+ if !have_aomenc() {
5362+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
5336 return;5363 return;
5337 }5364 }
5338- let cases = vec![(64usize, 64usize, 24u32, 0.4f64)];5365+ let (width, height) = (64usize, 64usize);
5339- let mut found = false;5366+ let y4m = Command::new("ffmpeg")
5340- for (width, height, cq, seed_off) in cases {5367+ .args([
5368+ "-v",
5369+ "error",
5370+ "-f",
5371+ "lavfi",
5372+ "-i",
5373+ &format!("mandelbrot=size={width}x{height}:start_x=0.4"),
5374+ "-pix_fmt",
5375+ "yuv420p",
5376+ "-t",
5377+ "1",
5378+ "-vframes",
5379+ "1",
5380+ "-f",
5381+ "yuv4mpegpipe",
5382+ "-",
5383+ ])
5384+ .stdin(Stdio::null())
5385+ .stdout(Stdio::piped())
5386+ .stderr(Stdio::piped())
5387+ .output()
5388+ .expect("ffmpeg failed to run");
5389+ assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr));
5390+ let encode = || {
5391+ let mut child = Command::new(aomenc_path())
5392+ .args([
5393+ "--codec=av1",
5394+ "--passes=1",
5395+ "--end-usage=q",
5396+ "--cq-level=24",
5397+ "--cpu-used=4",
5398+ "--threads=1",
5399+ "--row-mt=0",
5400+ "--sb-size=64",
5401+ "--kf-max-dist=0",
5402+ "--enable-rect-partitions=1",
5403+ "--enable-ab-partitions=0",
5404+ "--enable-1to4-partitions=0",
5405+ "--enable-tx-size-search=0",
5406+ "--reduced-tx-type-set=1",
5407+ "--min-partition-size=8",
5408+ "--max-partition-size=32",
5409+ "--obu",
5410+ "-o",
5411+ "-",
5412+ "-",
5413+ ])
5414+ .stdin(Stdio::piped())
5415+ .stdout(Stdio::piped())
5416+ .stderr(Stdio::piped())
5417+ .spawn()
5418+ .expect("aomenc failed to start");
5419+ child
5420+ .stdin
5421+ .take()
5422+ .expect("aomenc stdin")
5423+ .write_all(&y4m.stdout)
5424+ .expect("writing y4m to aomenc");
5425+ let out = child.wait_with_output().expect("aomenc failed to run");
5426+ assert!(
5427+ out.status.success(),
5428+ "aomenc refused the fixture: {}",
5429+ String::from_utf8_lossy(&out.stderr)
5430+ );
5431+ out.stdout
5432+ };
5433+ // The fixture rule: an encoder output is only a pin if it reproduces.
5434+ let stream = encode();
5435+ assert_eq!(stream, encode(), "{NAME}: aomenc output is not reproducible for this recipe");
5436+ let before = crate::decode::rect_leaf_coeff_hits();
5437+ let frames = decode_stream(&stream)
5438+ .unwrap_or_else(|e| panic!("{NAME}: decode failed, not a pixel mismatch: {e}"));
5439+ let fired = crate::decode::rect_leaf_coeff_hits() - before;
5440+ assert!(
5441+ fired > 0,
5442+ "{NAME}: the stream decoded but no coded (non-skip) rect leaf fired -- \
5443+ the gate proves nothing"
5444+ );
5445+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len());
5446+ assert_eq!(frames.len(), 1, "{NAME}: expected one key frame");
5447+ assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count");
5448+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
5449+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg ({fired} coded rect leaves)");
5450+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg");
5451+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg");
5452+ }
5453+ eprintln!("{NAME}: pixel-exact, rect_leaf_coeff_hits={fired}");
5454+ }
5455+
5456+ #[test]
5457+ #[ignore = "lane-rectx r3 scratch sweep"]
5458+ fn sweep_rectx_recipes() {
5459+ let _gate_lock = lock_gate_counters();
5460+ let srcs: Vec<String> = vec![
5461+ "mandelbrot=size=64x64:start_x=0.4".into(),
5462+ "mandelbrot=size=64x64:start_x=-0.6".into(),
5463+ "mandelbrot=size=64x64:start_x=0.1".into(),
5464+ "mandelbrot=size=128x128:start_x=0.4".into(),
5465+ "mandelbrot=size=128x128:start_x=-0.6".into(),
5466+ "testsrc2=size=64x64".into(),
5467+ "testsrc2=size=128x128".into(),
5468+ "rgbtestsrc=size=64x64".into(),
5469+ "smptebars=size=128x128".into(),
5470+ ];
5471+ for start_x in srcs {
5341 let y4m = Command::new("ffmpeg")5472 let y4m = Command::new("ffmpeg")
5342 .args([5473 .args([
5343 "-v", "error", "-f", "lavfi", "-i",5474 "-v", "error", "-f", "lavfi", "-i",
5344- &format!("mandelbrot=size={width}x{height}:start_x={seed_off}"),5475+ &start_x,
5345 "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-",5476 "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-",
5346 ])5477 ])
5347 .stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped())5478 .stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped())
5348- .output().expect("ffmpeg failed to run");5479+ .output().expect("ffmpeg");
5349 assert!(y4m.status.success());5480 assert!(y4m.status.success());
5350- let mut child = Command::new(aomenc_path())5481+ let (width, height) = if start_x.contains("128x128") { (128usize, 128usize) } else { (64usize, 64usize) };
5351- .args([5482+ for cq in [16u32, 20, 24, 28, 32, 40, 50] {
5352- "--threads=1", "--row-mt=0", "--sb-size=64", "--cpu-used=4", "--end-usage=q",5483+ for rtx in ["0"] {
5353- &format!("--cq-level={cq}"), "--passes=1",5484+ let mut child = Command::new(aomenc_path())
5354- "--enable-ab-partitions=0", "--enable-1to4-partitions=0",5485+ .args([
5355- "--enable-tx-size-search=0", "--min-partition-size=8",5486+ "--codec=av1", "--passes=1", "--end-usage=q",
5356- "--max-partition-size=32", "--kf-max-dist=0",5487+ &format!("--cq-level={cq}"), "--cpu-used=4", "--threads=1",
5357- "--obu", "-o", "-", "-",5488+ "--row-mt=0", "--sb-size=64", "--kf-max-dist=0",
5358- ])5489+ "--enable-rect-partitions=1", "--enable-ab-partitions=0",
5359- .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped())5490+ "--enable-1to4-partitions=0", "--enable-tx-size-search=0",
5360- .spawn().expect("aomenc failed to start");5491+ "--enable-cdef=0", "--enable-restoration=0",
5361- child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap();5492+ &format!("--reduced-tx-type-set={rtx}"),
5362- let out = child.wait_with_output().unwrap();5493+ "--min-partition-size=8", "--max-partition-size=32",
5363- assert!(out.status.success());5494+ "--obu", "-o", "-", "-",
5364- let stream = out.stdout;5495+ ])
5365- let before = crate::decode::rect_leaf_coeff_hits();5496+ .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped())
5366- let result = decode_stream(&stream);5497+ .spawn().expect("aomenc");
5367- let delta = crate::decode::rect_leaf_coeff_hits() - before;5498+ child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap();
5368- if delta > 0 {5499+ let out = child.wait_with_output().unwrap();
5369- if let Ok(frames) = &result {5500+ assert!(out.status.success());
5370- let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len());5501+ let stream = out.stdout;
5371- let mismatched = frames.iter().zip(&ffmpeg_frames).filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count();5502+ let before = crate::decode::rect_leaf_coeff_hits();
5372- eprintln!(5503+ let res = decode_stream(&stream);
5373- "HIT {width}x{height} cq={cq} off={seed_off}: rect_leaf_coeff_hits+={delta} mismatched={mismatched}/{}",5504+ let fired = crate::decode::rect_leaf_coeff_hits() - before;
5374- frames.len()5505+ match res {
5375- );5506+ Err(e) => eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} REFUSED {e}"),
5376- // debug: locate first y mismatch5507+ Ok(frames) => {
5377- if let (Some(got), Some(want)) = (frames.first(), ffmpeg_frames.first()) {5508+ let want = ffmpeg_decode_sequence(&stream, width, height, frames.len());
5378- 'outer: for row in 0..height {5509+ let bad = frames.iter().zip(&want)
5379- for col in 0..width {5510+ .filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count();
5380- let gi = row * width + col;5511+ eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} frames={} mismatched={bad}", frames.len());
5381- if got.y[gi] != want.y[gi] {5512+ let (g, w) = (&frames[0], &want[0]);
5382- eprintln!(5513+ for br in 0..height / 8 {
5383- "first Y mismatch at ({col},{row}): got={} want={}",5514+ let mut line = String::new();
5384- got.y[gi], want.y[gi]5515+ for bc in 0..width / 8 {
5385- );5516+ let mut n = 0;
5386- break 'outer;5517+ for row in br * 8..br * 8 + 8 {
5518+ for col in bc * 8..bc * 8 + 8 {
5519+ if g.y[row * width + col] != w.y[row * width + col] {
5520+ n += 1;
5521+ }
5522+ }
5523+ }
5524+ line.push_str(&format!("{n:4}"));
5387 }5525 }
5526+ eprintln!(" blk8 row{br}: {line}");
5388 }5527 }
5389 }5528 }
5390 }5529 }
5391- if mismatched == 0 {
5392- found = true;
5393- break;
5394- }
5395- } else {
5396- eprintln!(
5397- "{width}x{height} cq={cq} off={seed_off}: rect_leaf_coeff_hits+={delta} result={:?}",
5398- result.as_ref().map(|f| f.len()).map_err(|e| e.to_string())
5399- );
5400 }5530 }
5401 }5531 }
5402 }5532 }
5403- eprintln!("found pixel-exact firing case: {found}");
5404 }5533 }
5405 5534
5406 /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=05535 /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0