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 {
121121 /// below 16x16 (lane-rectx, `decode_leaf_rect`'s own leaf, one level
122122 /// under [`LumaRect32x16`](TxbSet::LumaRect32x16)): `get_txsize_entropy_ctx`
123123 /// reduces this 2:1 rect size to `TX_16X16` too, so this shares every
124- /// table [`Luma16`](TxbSet::Luma16) does -- INCLUDING its mode-indexed
125- /// `tx_type` CDF, the same adapted table object -- except `eob_pt`, which
124+ /// table [`Luma16`](TxbSet::Luma16) does except two: its mode-indexed
125+ /// `tx_type` CDF, which is the *8x8* row's (see
126+ /// [`LumaRect16x8Set1`](TxbSet::LumaRect16x8Set1)), and `eob_pt`, which
126127 /// reads the true 128-position [`crate::cdf::EOB_PT_128_LUMA`] rather
127128 /// than `Luma16`'s 256-position one. Unlike
128129 /// [`LumaRect32x16`](TxbSet::LumaRect32x16), this size DOES carry a
129- /// `tx_type` symbol: `av1_get_ext_tx_set_type`'s `use_reduced_set` branch
130- /// returns `EXT_TX_SET_DTT4_IDTX` for every `tx_size_sqr_up == TX_16X16`
131- /// regardless of the real (non-square) `tx_size`, the same set
132- /// `Luma16`'s own read already uses -- confirmed against
133- /// `av1/common/blockd.h`'s `av1_get_ext_tx_set_type` before landing,
134- /// see `decode_block_rect`'s own doc comment for the desync this gap
135- /// left when it was still unhandled.
130+ /// `tx_type` symbol: `av1_get_ext_tx_set_type` (`av1/common/blockd.h`)
131+ /// sees `tx_size_sqr_up == TX_16X16`, so intra reads
132+ /// `EXT_TX_SET_DTT4_IDTX` under `reduced_tx_set` and
133+ /// `EXT_TX_SET_DTT4_IDTX_1DDCT` without it (`tx_size_sqr` is `TX_8X8`
134+ /// here, not `TX_16X16`) -- this variant is the reduced arm, its
135+ /// `Set1` sibling the other.
136136 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,
137148 /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx):
138149 /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the
139150 /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of
@@ -1476,7 +1487,19 @@ impl Cdfs {
14761487 base_eob: &mut self.base_eob_luma_16,
14771488 br: &mut self.br_luma_16,
14781489 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()),
14801503 eob_pt_class1: None,
14811504 },
14821505 TxbSet::ChromaRect8x4 => TxbTables {
crates/ec-av1/src/decode.rsmodified+86 -19
@@ -1655,6 +1655,11 @@ fn read_coeffs_rect(
16551655 if all_zero {
16561656 return Ok((grid, TxType::DctDct));
16571657 }
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+ }
16581663 let mut tx_type = default_tx_type;
16591664 if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() {
16601665 // Mirrors [`read_coeffs`]'s own `tx_type` read: the CDF row's width
@@ -1675,7 +1680,15 @@ fn read_coeffs_rect(
16751680 "a non-2D tx class on a rectangular transform (never expected at this size)",
16761681 ));
16771682 }
1683+ if trace {
1684+ let (rng, _) = dec.debug_state();
1685+ eprintln!("EC_COEFF_STEP tag=tx_type rng={rng}");
1686+ }
16781687 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+ }
16791692 let mut levels = vec![0i32; w * h];
16801693 for scan_idx in (0..eob).rev() {
16811694 let pos = scan[scan_idx] as usize;
@@ -1704,6 +1717,10 @@ fn read_coeffs_rect(
17041717 level
17051718 };
17061719 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+ }
17071724 }
17081725 for &pos in &scan[..eob] {
17091726 let level = levels[pos as usize];
@@ -3534,6 +3551,7 @@ fn decode_leaf_rect(
35343551 allow_screen_content_tools: bool,
35353552 base_q_idx: u8,
35363553 tx_select: bool,
3554+ reduced_tx_set: bool,
35373555 ) -> Result<usize> {
35383556 let _ = base_q_idx;
35393557 if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {
@@ -3626,7 +3644,12 @@ fn decode_leaf_rect(
36263644 (&SCAN_8X16, &SCAN_4X8)
36273645 };
36283646 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);
36303653 let (l_levels, luma_tx_type) = read_coeffs_rect(
36313654 dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct,
36323655 )?;
@@ -5200,6 +5223,31 @@ fn decode_block(
52005223 /// at. Returns the mode this leaf decoded, for the caller's own
52015224 /// `prev_leaf`/final mode-writeback bookkeeping.
52025225 #[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+
52035251 fn decode_leaf8(
52045252 dec: &mut SymbolDecoder,
52055253 cdfs: &mut Cdfs,
@@ -5207,7 +5255,7 @@ fn decode_leaf8(
52075255 outer_at: (usize, usize),
52085256 leaf_mi: (usize, usize),
52095257 scans: (&[u16], &[u16]),
5210- prev_leaf: Option<((usize, usize), usize)>,
5258+ prev_leaves: &[((usize, usize), usize)],
52115259 y: &mut PlaneBuf,
52125260 u: &mut PlaneBuf,
52135261 v: &mut PlaneBuf,
@@ -5221,7 +5269,18 @@ fn decode_leaf8(
52215269 let (r, c) = outer_at;
52225270 let mut above_mode = neighbours.above_mode[c];
52235271 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 {
52255284 if pc == leaf_mi.1 && leaf_mi.0 == pr + 2 {
52265285 above_mode = pmode;
52275286 } else if pr == leaf_mi.0 && leaf_mi.1 == pc + 2 {
@@ -7023,7 +7082,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
70237082 at16,
70247083 top_right,
70257084 (&scan8, &scan4),
7026- None,
7085+ &[],
70277086 &mut y,
70287087 &mut u,
70297088 &mut v,
@@ -7041,7 +7100,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
70417100 at16,
70427101 bot_right,
70437102 (&scan8, &scan4),
7044- Some((top_right, mode_tr)),
7103+ &[(top_right, mode_tr)],
70457104 &mut y,
70467105 &mut u,
70477106 &mut v,
@@ -7086,6 +7145,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
70867145 allow_screen_content_tools,
70877146 base_q_idx,
70887147 tx_select,
7148+ reduced_tx_set,
70897149 )?;
70907150 let mode_bot = decode_leaf_rect(
70917151 &mut dec,
@@ -7103,6 +7163,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
71037163 allow_screen_content_tools,
71047164 base_q_idx,
71057165 tx_select,
7166+ reduced_tx_set,
71067167 )?;
71077168 neighbours.above_mode[sc] = mode_bot;
71087169 neighbours.left_mode[sr] = mode_bot;
@@ -7132,6 +7193,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
71327193 allow_screen_content_tools,
71337194 base_q_idx,
71347195 tx_select,
7196+ reduced_tx_set,
71357197 )?;
71367198 let mode_right = decode_leaf_rect(
71377199 &mut dec,
@@ -7149,6 +7211,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
71497211 allow_screen_content_tools,
71507212 base_q_idx,
71517213 tx_select,
7214+ reduced_tx_set,
71527215 )?;
71537216 neighbours.above_mode[sc] = mode_right;
71547217 neighbours.left_mode[sr] = mode_right;
@@ -7168,7 +7231,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
71687231 // the one or two the edge leaves.
71697232 let (mi_row0, mi_col0) =
71707233 (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();
71727235 for i in 0..4 {
71737236 let (mr, mc) =
71747237 (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2);
@@ -7193,7 +7256,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
71937256 at16,
71947257 leaf_mi,
71957258 (&scan8, &scan4),
7196- prev_leaf,
7259+ &done,
71977260 &mut y,
71987261 &mut u,
71997262 &mut v,
@@ -7204,12 +7267,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
72047267 tx_select,
72057268 reduced_tx_set,
72067269 )?;
7207- prev_leaf = Some((leaf_mi, leaf_mode));
7208- }
7209- if let Some((_, mode)) = prev_leaf {
7210- neighbours.above_mode[sc] = mode;
7211- neighbours.left_mode[sr] = mode;
7270+ done.push((leaf_mi, leaf_mode));
72127271 }
7272+ write_back_split_modes(
7273+ &mut neighbours,
7274+ &done,
7275+ (mi_row0 as usize, mi_col0 as usize),
7276+ (sr, sc),
7277+ );
72137278 continue;
72147279 }
72157280 // The true edge falls inside this 16x16
@@ -7242,7 +7307,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
72427307 .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2))
72437308 .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols)
72447309 .collect();
7245- let mut prev_leaf: Option<((usize, usize), usize)> = None;
7310+ let mut done: Vec<((usize, usize), usize)> = Vec::new();
72467311 for (mr, mc) in leaf_positions {
72477312 let leaf_mi = (mr as usize, mc as usize);
72487313 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
@@ -7264,7 +7329,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
72647329 at16,
72657330 leaf_mi,
72667331 (&scan8, &scan4),
7267- prev_leaf,
7332+ &done,
72687333 &mut y,
72697334 &mut u,
72707335 &mut v,
@@ -7275,7 +7340,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
72757340 tx_select,
72767341 reduced_tx_set,
72777342 )?;
7278- prev_leaf = Some((leaf_mi, leaf_mode));
7343+ done.push((leaf_mi, leaf_mode));
72797344 }
72807345 // `record()`'s `above_mode`/`left_mode`
72817346 // write is a no-op at an 8x8 leaf's own
@@ -7283,10 +7348,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
72837348 // 16x16 slot's leaves are done, from the
72847349 // last leaf (mirrors the writer's r15
72857350 // fix).
7286- if let Some((_, mode)) = prev_leaf {
7287- neighbours.above_mode[sc] = mode;
7288- neighbours.left_mode[sr] = mode;
7289- }
7351+ write_back_split_modes(
7352+ &mut neighbours,
7353+ &done,
7354+ (mi_row0 as usize, mi_col0 as usize),
7355+ (sr, sc),
7356+ );
72907357 }
72917358 }
72927359 PARTITION_HORZ => {
crates/ec-av1/src/stream.rsmodified+184 -55
@@ -5328,79 +5328,208 @@ mod tests {
53285328 result.as_ref().map(|f| f.len()).map_err(|e| e.to_string())
53295329 );
53305330 }
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)).
53315352 #[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";
53335356 let _gate_lock = lock_gate_counters();
5334- if !have_ffmpeg() || !have_aomenc() {
5335- eprintln!("SKIP: no tools");
5357+ if !have_ffmpeg() {
5358+ eprintln!("SKIP {NAME}: no ffmpeg");
5359+ return;
5360+ }
5361+ if !have_aomenc() {
5362+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
53365363 return;
53375364 }
5338- let cases = vec![(64usize, 64usize, 24u32, 0.4f64)];
5339- let mut found = false;
5340- for (width, height, cq, seed_off) in cases {
5365+ let (width, height) = (64usize, 64usize);
5366+ let y4m = Command::new("ffmpeg")
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 {
53415472 let y4m = Command::new("ffmpeg")
53425473 .args([
53435474 "-v", "error", "-f", "lavfi", "-i",
5344- &format!("mandelbrot=size={width}x{height}:start_x={seed_off}"),
5475+ &start_x,
53455476 "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-",
53465477 ])
53475478 .stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped())
5348- .output().expect("ffmpeg failed to run");
5479+ .output().expect("ffmpeg");
53495480 assert!(y4m.status.success());
5350- let mut child = Command::new(aomenc_path())
5351- .args([
5352- "--threads=1", "--row-mt=0", "--sb-size=64", "--cpu-used=4", "--end-usage=q",
5353- &format!("--cq-level={cq}"), "--passes=1",
5354- "--enable-ab-partitions=0", "--enable-1to4-partitions=0",
5355- "--enable-tx-size-search=0", "--min-partition-size=8",
5356- "--max-partition-size=32", "--kf-max-dist=0",
5357- "--obu", "-o", "-", "-",
5358- ])
5359- .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped())
5360- .spawn().expect("aomenc failed to start");
5361- child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap();
5362- let out = child.wait_with_output().unwrap();
5363- assert!(out.status.success());
5364- let stream = out.stdout;
5365- let before = crate::decode::rect_leaf_coeff_hits();
5366- let result = decode_stream(&stream);
5367- let delta = crate::decode::rect_leaf_coeff_hits() - before;
5368- if delta > 0 {
5369- if let Ok(frames) = &result {
5370- let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len());
5371- let mismatched = frames.iter().zip(&ffmpeg_frames).filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count();
5372- eprintln!(
5373- "HIT {width}x{height} cq={cq} off={seed_off}: rect_leaf_coeff_hits+={delta} mismatched={mismatched}/{}",
5374- frames.len()
5375- );
5376- // debug: locate first y mismatch
5377- if let (Some(got), Some(want)) = (frames.first(), ffmpeg_frames.first()) {
5378- 'outer: for row in 0..height {
5379- for col in 0..width {
5380- let gi = row * width + col;
5381- if got.y[gi] != want.y[gi] {
5382- eprintln!(
5383- "first Y mismatch at ({col},{row}): got={} want={}",
5384- got.y[gi], want.y[gi]
5385- );
5386- break 'outer;
5481+ let (width, height) = if start_x.contains("128x128") { (128usize, 128usize) } else { (64usize, 64usize) };
5482+ for cq in [16u32, 20, 24, 28, 32, 40, 50] {
5483+ for rtx in ["0"] {
5484+ let mut child = Command::new(aomenc_path())
5485+ .args([
5486+ "--codec=av1", "--passes=1", "--end-usage=q",
5487+ &format!("--cq-level={cq}"), "--cpu-used=4", "--threads=1",
5488+ "--row-mt=0", "--sb-size=64", "--kf-max-dist=0",
5489+ "--enable-rect-partitions=1", "--enable-ab-partitions=0",
5490+ "--enable-1to4-partitions=0", "--enable-tx-size-search=0",
5491+ "--enable-cdef=0", "--enable-restoration=0",
5492+ &format!("--reduced-tx-type-set={rtx}"),
5493+ "--min-partition-size=8", "--max-partition-size=32",
5494+ "--obu", "-o", "-", "-",
5495+ ])
5496+ .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped())
5497+ .spawn().expect("aomenc");
5498+ child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap();
5499+ let out = child.wait_with_output().unwrap();
5500+ assert!(out.status.success());
5501+ let stream = out.stdout;
5502+ let before = crate::decode::rect_leaf_coeff_hits();
5503+ let res = decode_stream(&stream);
5504+ let fired = crate::decode::rect_leaf_coeff_hits() - before;
5505+ match res {
5506+ Err(e) => eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} REFUSED {e}"),
5507+ Ok(frames) => {
5508+ let want = ffmpeg_decode_sequence(&stream, width, height, frames.len());
5509+ let bad = frames.iter().zip(&want)
5510+ .filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count();
5511+ eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} frames={} mismatched={bad}", frames.len());
5512+ let (g, w) = (&frames[0], &want[0]);
5513+ for br in 0..height / 8 {
5514+ let mut line = String::new();
5515+ for bc in 0..width / 8 {
5516+ let mut n = 0;
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}"));
53875525 }
5526+ eprintln!(" blk8 row{br}: {line}");
53885527 }
53895528 }
53905529 }
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- );
54005530 }
54015531 }
54025532 }
5403- eprintln!("found pixel-exact firing case: {found}");
54045533 }
54055534
54065535 /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0