From 0457feb553ba00229c586e2da98fdbe4241930d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Tue, 1 Sep 2026 21:33:37 +0300 Subject: [PATCH] wip(rectx): session restart -- uncommitted builder state preserved by orchestrator --- crates/ec-av1/src/cdf_state.rs | 43 ++++-- crates/ec-av1/src/decode.rs | 105 ++++++++++++--- crates/ec-av1/src/stream.rs | 239 +++++++++++++++++++++++++-------- 3 files changed, 303 insertions(+), 84 deletions(-) diff --git a/crates/ec-av1/src/cdf_state.rs b/crates/ec-av1/src/cdf_state.rs index c9b37ff5..a230b324 100644 --- a/crates/ec-av1/src/cdf_state.rs +++ b/crates/ec-av1/src/cdf_state.rs @@ -121,19 +121,30 @@ pub(crate) enum TxbSet { /// below 16x16 (lane-rectx, `decode_leaf_rect`'s own leaf, one level /// under [`LumaRect32x16`](TxbSet::LumaRect32x16)): `get_txsize_entropy_ctx` /// reduces this 2:1 rect size to `TX_16X16` too, so this shares every - /// table [`Luma16`](TxbSet::Luma16) does -- INCLUDING its mode-indexed - /// `tx_type` CDF, the same adapted table object -- except `eob_pt`, which + /// table [`Luma16`](TxbSet::Luma16) does except two: its mode-indexed + /// `tx_type` CDF, which is the *8x8* row's (see + /// [`LumaRect16x8Set1`](TxbSet::LumaRect16x8Set1)), and `eob_pt`, which /// reads the true 128-position [`crate::cdf::EOB_PT_128_LUMA`] rather /// than `Luma16`'s 256-position one. Unlike /// [`LumaRect32x16`](TxbSet::LumaRect32x16), this size DOES carry a - /// `tx_type` symbol: `av1_get_ext_tx_set_type`'s `use_reduced_set` branch - /// returns `EXT_TX_SET_DTT4_IDTX` for every `tx_size_sqr_up == TX_16X16` - /// regardless of the real (non-square) `tx_size`, the same set - /// `Luma16`'s own read already uses -- confirmed against - /// `av1/common/blockd.h`'s `av1_get_ext_tx_set_type` before landing, - /// see `decode_block_rect`'s own doc comment for the desync this gap - /// left when it was still unhandled. + /// `tx_type` symbol: `av1_get_ext_tx_set_type` (`av1/common/blockd.h`) + /// sees `tx_size_sqr_up == TX_16X16`, so intra reads + /// `EXT_TX_SET_DTT4_IDTX` under `reduced_tx_set` and + /// `EXT_TX_SET_DTT4_IDTX_1DDCT` without it (`tx_size_sqr` is `TX_8X8` + /// here, not `TX_16X16`) -- this variant is the reduced arm, its + /// `Set1` sibling the other. LumaRect16x8, + /// [`LumaRect16x8`](TxbSet::LumaRect16x8)'s `reduced_tx_set: false` + /// counterpart (lane-rectx r3), the same split + /// [`Luma8Set1`](TxbSet::Luma8Set1) has to [`Luma8`](TxbSet::Luma8) -- + /// and it is deliberately those two tables, not the 16x16 row: libaom's + /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][square_tx_size]` with + /// `square_tx_size = txsize_sqr_map[tx_size]`, which for `TX_16X8`/ + /// `TX_8X16` is `TX_8X8`, NOT the `txsize_sqr_up_map` `TX_16X16` the + /// txb-skip/base/br tables use (`get_txsize_entropy_ctx`). r2 read the + /// 16x16 row's five-symbol reduced CDF here and desynced on the very + /// first coded rect leaf. + LumaRect16x8Set1, /// The chroma 8x4/4x8 transform under the same leaf (lane-rectx): /// [`Chroma8`](TxbSet::Chroma8)'s tables except `eob_pt`, which reads the /// true 32-position [`crate::cdf::EOB_PT_32_CHROMA`] instead of @@ -1476,7 +1487,19 @@ impl Cdfs { base_eob: &mut self.base_eob_luma_16, br: &mut self.br_luma_16, dc_sign: &mut self.dc_sign_luma, - tx_type: Some(self.intra_tx_type_16[mode].as_mut_slice()), + tx_type: Some(self.intra_tx_type_8[mode].as_mut_slice()), + eob_pt_class1: None, + }, + TxbSet::LumaRect16x8Set1 => TxbTables { + side: 16, + txb_skip: &mut self.txb_skip_luma_16, + eob_pt: &mut self.eob_pt_128_luma, + eob_extra: &mut self.eob_extra_luma_16, + base: &mut self.base_luma_16, + base_eob: &mut self.base_eob_luma_16, + br: &mut self.br_luma_16, + dc_sign: &mut self.dc_sign_luma, + tx_type: Some(self.intra_tx_type_8_set1[mode].as_mut_slice()), eob_pt_class1: None, }, TxbSet::ChromaRect8x4 => TxbTables { diff --git a/crates/ec-av1/src/decode.rs b/crates/ec-av1/src/decode.rs index 93d32391..8759a6cb 100644 --- a/crates/ec-av1/src/decode.rs +++ b/crates/ec-av1/src/decode.rs @@ -1655,6 +1655,11 @@ fn read_coeffs_rect( if all_zero { return Ok((grid, TxType::DctDct)); } + let trace = std::env::var_os("EC_TRACE_COEFF").is_some(); + if trace { + let (rng, _) = dec.debug_state(); + eprintln!("EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero=0 rng={rng}"); + } let mut tx_type = default_tx_type; if let Some(tx_type_cdf) = coding.tx_type.as_deref_mut() { // Mirrors [`read_coeffs`]'s own `tx_type` read: the CDF row's width @@ -1675,7 +1680,15 @@ fn read_coeffs_rect( "a non-2D tx class on a rectangular transform (never expected at this size)", )); } + if trace { + let (rng, _) = dec.debug_state(); + eprintln!("EC_COEFF_STEP tag=tx_type rng={rng}"); + } let eob = read_eob(dec, coding, TxClass::TwoD); + if trace { + let (rng, _) = dec.debug_state(); + eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={rng}"); + } let mut levels = vec![0i32; w * h]; for scan_idx in (0..eob).rev() { let pos = scan[scan_idx] as usize; @@ -1704,6 +1717,10 @@ fn read_coeffs_rect( level }; levels[pos] = level; + if trace { + let (rng, _) = dec.debug_state(); + eprintln!("EC_COEFF_STEP tag=base c={scan_idx} pos={pos} level={level} rng={rng}"); + } } for &pos in &scan[..eob] { let level = levels[pos as usize]; @@ -3534,6 +3551,7 @@ fn decode_leaf_rect( allow_screen_content_tools: bool, base_q_idx: u8, tx_select: bool, + reduced_tx_set: bool, ) -> Result { let _ = base_q_idx; if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() { @@ -3626,7 +3644,12 @@ fn decode_leaf_rect( (&SCAN_8X16, &SCAN_4X8) }; let around = neighbours.around_mi_rect(leaf_mi, bw, bh); - let mut luma_coding = cdfs.txb(TxbSet::LumaRect16x8, mode); + let luma_set = if reduced_tx_set { + TxbSet::LumaRect16x8 + } else { + TxbSet::LumaRect16x8Set1 + }; + let mut luma_coding = cdfs.txb(luma_set, mode); let (l_levels, luma_tx_type) = read_coeffs_rect( dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct, )?; @@ -5200,6 +5223,31 @@ fn decode_block( /// at. Returns the mode this leaf decoded, for the caller's own /// `prev_leaf`/final mode-writeback bookkeeping. #[allow(clippy::too_many_arguments)] +/// The coarse 16x16 `above_mode`/`left_mode` cells a four-way SPLIT of one +/// 16x16 parent leaves behind (lane-rectx r3). The next block DOWN reads +/// `above_mode[col]`, and its true above neighbour is the mi directly above +/// its own top-left corner -- the parent's BOTTOM-LEFT leaf, not the last one +/// decoded; the next block RIGHT reads `left_mode[row]`, whose true left +/// neighbour is the parent's TOP-RIGHT leaf. Writing the z-order last leaf +/// (bottom-right) into both, as this path did, is right only when all four +/// leaves happen to share a mode. `done` may be short at the true frame edge +/// (the straddle caller filters positions off the frame), so each side falls +/// back to the last leaf actually decoded. +fn write_back_split_modes( + neighbours: &mut Neighbours, + done: &[((usize, usize), usize)], + parent_mi: (usize, usize), + slot: (usize, usize), +) { + let (sr, sc) = slot; + let Some(&(_, last)) = done.last() else { + return; + }; + let find = |mi: (usize, usize)| done.iter().find(|&&(at, _)| at == mi).map(|&(_, m)| m); + neighbours.above_mode[sc] = find((parent_mi.0 + 2, parent_mi.1)).unwrap_or(last); + neighbours.left_mode[sr] = find((parent_mi.0, parent_mi.1 + 2)).unwrap_or(last); +} + fn decode_leaf8( dec: &mut SymbolDecoder, cdfs: &mut Cdfs, @@ -5207,7 +5255,7 @@ fn decode_leaf8( outer_at: (usize, usize), leaf_mi: (usize, usize), scans: (&[u16], &[u16]), - prev_leaf: Option<((usize, usize), usize)>, + prev_leaves: &[((usize, usize), usize)], y: &mut PlaneBuf, u: &mut PlaneBuf, v: &mut PlaneBuf, @@ -5221,7 +5269,18 @@ fn decode_leaf8( let (r, c) = outer_at; let mut above_mode = neighbours.above_mode[c]; let mut left_mode = neighbours.left_mode[r]; - if let Some(((pr, pc), pmode)) = prev_leaf { + // lane-rectx r3: EVERY sibling leaf already decoded inside this 16x16 + // parent, not just the previous one in z-order. A four-way SPLIT's + // bottom-left leaf has the TOP-LEFT leaf directly above it (the previous + // leaf is the top-right one, which is neither above nor left of it), and + // the bottom-right leaf has two live siblings at once -- top-right above, + // bottom-left to the left. Passing only the z-order predecessor left both + // reading the coarse 16x16 `above_mode`/`left_mode` cell, i.e. a mode + // from the block ABOVE THE PARENT, and the `kf_y_mode` CDF row that + // indexes desynced the tile at the third leaf of every real SPLIT + // (measured against the instrumented aomdec: same decoded value, wrong + // range -- `EC_ISTEP mi_row=6 mi_col=0 name=mode` rng 46476 vs 37546). + for &((pr, pc), pmode) in prev_leaves { if pc == leaf_mi.1 && leaf_mi.0 == pr + 2 { above_mode = pmode; } else if pr == leaf_mi.0 && leaf_mi.1 == pc + 2 { @@ -7023,7 +7082,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( at16, top_right, (&scan8, &scan4), - None, + &[], &mut y, &mut u, &mut v, @@ -7041,7 +7100,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( at16, bot_right, (&scan8, &scan4), - Some((top_right, mode_tr)), + &[(top_right, mode_tr)], &mut y, &mut u, &mut v, @@ -7086,6 +7145,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; let mode_bot = decode_leaf_rect( &mut dec, @@ -7103,6 +7163,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; neighbours.above_mode[sc] = mode_bot; neighbours.left_mode[sr] = mode_bot; @@ -7132,6 +7193,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; let mode_right = decode_leaf_rect( &mut dec, @@ -7149,6 +7211,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( allow_screen_content_tools, base_q_idx, tx_select, + reduced_tx_set, )?; neighbours.above_mode[sc] = mode_right; neighbours.left_mode[sr] = mode_right; @@ -7168,7 +7231,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // the one or two the edge leaves. let (mi_row0, mi_col0) = (sr as u32 * SUB_MI, sc as u32 * SUB_MI); - let mut prev_leaf: Option<((usize, usize), usize)> = None; + let mut done: Vec<((usize, usize), usize)> = Vec::new(); for i in 0..4 { let (mr, mc) = (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2); @@ -7193,7 +7256,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( at16, leaf_mi, (&scan8, &scan4), - prev_leaf, + &done, &mut y, &mut u, &mut v, @@ -7204,12 +7267,14 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( tx_select, reduced_tx_set, )?; - prev_leaf = Some((leaf_mi, leaf_mode)); - } - if let Some((_, mode)) = prev_leaf { - neighbours.above_mode[sc] = mode; - neighbours.left_mode[sr] = mode; + done.push((leaf_mi, leaf_mode)); } + write_back_split_modes( + &mut neighbours, + &done, + (mi_row0 as usize, mi_col0 as usize), + (sr, sc), + ); continue; } // The true edge falls inside this 16x16 @@ -7242,7 +7307,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( .map(|i| (mi_row0 + (i / 2) * 2, mi_col0 + (i % 2) * 2)) .filter(|&(mr, mc)| mr < mi_rows && mc < mi_cols) .collect(); - let mut prev_leaf: Option<((usize, usize), usize)> = None; + let mut done: Vec<((usize, usize), usize)> = Vec::new(); for (mr, mc) in leaf_positions { let leaf_mi = (mr as usize, mc as usize); let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8); @@ -7264,7 +7329,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( at16, leaf_mi, (&scan8, &scan4), - prev_leaf, + &done, &mut y, &mut u, &mut v, @@ -7275,7 +7340,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( tx_select, reduced_tx_set, )?; - prev_leaf = Some((leaf_mi, leaf_mode)); + done.push((leaf_mi, leaf_mode)); } // `record()`'s `above_mode`/`left_mode` // write is a no-op at an 8x8 leaf's own @@ -7283,10 +7348,12 @@ pub(crate) fn decode_key_frame_tile_with_cdfs( // 16x16 slot's leaves are done, from the // last leaf (mirrors the writer's r15 // fix). - if let Some((_, mode)) = prev_leaf { - neighbours.above_mode[sc] = mode; - neighbours.left_mode[sr] = mode; - } + write_back_split_modes( + &mut neighbours, + &done, + (mi_row0 as usize, mi_col0 as usize), + (sr, sc), + ); } } PARTITION_HORZ => { diff --git a/crates/ec-av1/src/stream.rs b/crates/ec-av1/src/stream.rs index 6e4d5ef1..a6143468 100644 --- a/crates/ec-av1/src/stream.rs +++ b/crates/ec-av1/src/stream.rs @@ -5328,79 +5328,208 @@ mod tests { result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) ); } + /// lane-rectx r3: a real `aomenc` stream whose 16x16-level + /// `PARTITION_HORZ`/`PARTITION_VERT` strips are CODED (non-skip), i.e. + /// carry genuine `TX_16X8`/`TX_8X16` luma coefficients and their + /// `TX_8X4`/`TX_4X8` chroma halves through [`decode_leaf_rect`]'s + /// lane-rectx arm -- the refusal "a coded (non-skip) HORZ/VERT rect strip + /// below 16x16" this round lifts. `--min-partition-size=8 + /// --max-partition-size=32 --enable-rect-partitions=1` is what makes + /// aomenc reach for a 16x8 leaf at all; mandelbrot at `cq-level=24` is + /// what makes those leaves non-skip (a gradient fixture codes them all + /// away). `--reduced-tx-type-set=1` pins the five-symbol + /// `EXT_TX_SET_DTT4_IDTX` alphabet: without it aomenc also writes + /// `V_DCT`/`H_DCT`, whose 1D tx classes [`read_coeffs_rect`] still + /// refuses by name (see the r3 report's open residue), so a `=0` run + /// would prove nothing about the 2D path it does support. + /// + /// r2 shipped this path unproven; it was wrong. `TxbSet::LumaRect16x8` + /// read its `tx_type` symbol from the 16x16 row, but libaom's + /// `read_tx_type` indexes `intra_ext_tx_cdf[eset][txsize_sqr_map[tx_size]]` + /// and `txsize_sqr_map[TX_16X8] == TX_8X8` -- a five-symbol CDF where a + /// seven-symbol one belonged, desyncing at the FIRST coded rect leaf + /// (whole frame wrong from pixel (0,0)). #[test] - fn scratch_probe_rectx_mandelbrot() { + fn a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact() { + const NAME: &str = + "a_real_aomenc_stream_with_a_coded_rect_strip_below_16x16_decodes_pixel_exact"; let _gate_lock = lock_gate_counters(); - if !have_ffmpeg() || !have_aomenc() { - eprintln!("SKIP: no tools"); + if !have_ffmpeg() { + eprintln!("SKIP {NAME}: no ffmpeg"); + return; + } + if !have_aomenc() { + eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display()); return; } - let cases = vec![(64usize, 64usize, 24u32, 0.4f64)]; - let mut found = false; - for (width, height, cq, seed_off) in cases { + let (width, height) = (64usize, 64usize); + let y4m = Command::new("ffmpeg") + .args([ + "-v", + "error", + "-f", + "lavfi", + "-i", + &format!("mandelbrot=size={width}x{height}:start_x=0.4"), + "-pix_fmt", + "yuv420p", + "-t", + "1", + "-vframes", + "1", + "-f", + "yuv4mpegpipe", + "-", + ]) + .stdin(Stdio::null()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .output() + .expect("ffmpeg failed to run"); + assert!(y4m.status.success(), "ffmpeg fixture: {}", String::from_utf8_lossy(&y4m.stderr)); + let encode = || { + let mut child = Command::new(aomenc_path()) + .args([ + "--codec=av1", + "--passes=1", + "--end-usage=q", + "--cq-level=24", + "--cpu-used=4", + "--threads=1", + "--row-mt=0", + "--sb-size=64", + "--kf-max-dist=0", + "--enable-rect-partitions=1", + "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", + "--enable-tx-size-search=0", + "--reduced-tx-type-set=1", + "--min-partition-size=8", + "--max-partition-size=32", + "--obu", + "-o", + "-", + "-", + ]) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .stderr(Stdio::piped()) + .spawn() + .expect("aomenc failed to start"); + child + .stdin + .take() + .expect("aomenc stdin") + .write_all(&y4m.stdout) + .expect("writing y4m to aomenc"); + let out = child.wait_with_output().expect("aomenc failed to run"); + assert!( + out.status.success(), + "aomenc refused the fixture: {}", + String::from_utf8_lossy(&out.stderr) + ); + out.stdout + }; + // The fixture rule: an encoder output is only a pin if it reproduces. + let stream = encode(); + assert_eq!(stream, encode(), "{NAME}: aomenc output is not reproducible for this recipe"); + let before = crate::decode::rect_leaf_coeff_hits(); + let frames = decode_stream(&stream) + .unwrap_or_else(|e| panic!("{NAME}: decode failed, not a pixel mismatch: {e}")); + let fired = crate::decode::rect_leaf_coeff_hits() - before; + assert!( + fired > 0, + "{NAME}: the stream decoded but no coded (non-skip) rect leaf fired -- \ + the gate proves nothing" + ); + let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); + assert_eq!(frames.len(), 1, "{NAME}: expected one key frame"); + assert_eq!(ffmpeg_frames.len(), frames.len(), "{NAME}: ffmpeg frame count"); + for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() { + assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg ({fired} coded rect leaves)"); + assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg"); + assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg"); + } + eprintln!("{NAME}: pixel-exact, rect_leaf_coeff_hits={fired}"); + } + + #[test] + #[ignore = "lane-rectx r3 scratch sweep"] + fn sweep_rectx_recipes() { + let _gate_lock = lock_gate_counters(); + let srcs: Vec = vec![ + "mandelbrot=size=64x64:start_x=0.4".into(), + "mandelbrot=size=64x64:start_x=-0.6".into(), + "mandelbrot=size=64x64:start_x=0.1".into(), + "mandelbrot=size=128x128:start_x=0.4".into(), + "mandelbrot=size=128x128:start_x=-0.6".into(), + "testsrc2=size=64x64".into(), + "testsrc2=size=128x128".into(), + "rgbtestsrc=size=64x64".into(), + "smptebars=size=128x128".into(), + ]; + for start_x in srcs { let y4m = Command::new("ffmpeg") .args([ "-v", "error", "-f", "lavfi", "-i", - &format!("mandelbrot=size={width}x{height}:start_x={seed_off}"), + &start_x, "-pix_fmt", "yuv420p", "-t", "1", "-vframes", "1", "-f", "yuv4mpegpipe", "-", ]) .stdin(Stdio::null()).stdout(Stdio::piped()).stderr(Stdio::piped()) - .output().expect("ffmpeg failed to run"); + .output().expect("ffmpeg"); assert!(y4m.status.success()); - let mut child = Command::new(aomenc_path()) - .args([ - "--threads=1", "--row-mt=0", "--sb-size=64", "--cpu-used=4", "--end-usage=q", - &format!("--cq-level={cq}"), "--passes=1", - "--enable-ab-partitions=0", "--enable-1to4-partitions=0", - "--enable-tx-size-search=0", "--min-partition-size=8", - "--max-partition-size=32", "--kf-max-dist=0", - "--obu", "-o", "-", "-", - ]) - .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped()) - .spawn().expect("aomenc failed to start"); - child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap(); - let out = child.wait_with_output().unwrap(); - assert!(out.status.success()); - let stream = out.stdout; - let before = crate::decode::rect_leaf_coeff_hits(); - let result = decode_stream(&stream); - let delta = crate::decode::rect_leaf_coeff_hits() - before; - if delta > 0 { - if let Ok(frames) = &result { - let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frames.len()); - let mismatched = frames.iter().zip(&ffmpeg_frames).filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count(); - eprintln!( - "HIT {width}x{height} cq={cq} off={seed_off}: rect_leaf_coeff_hits+={delta} mismatched={mismatched}/{}", - frames.len() - ); - // debug: locate first y mismatch - if let (Some(got), Some(want)) = (frames.first(), ffmpeg_frames.first()) { - 'outer: for row in 0..height { - for col in 0..width { - let gi = row * width + col; - if got.y[gi] != want.y[gi] { - eprintln!( - "first Y mismatch at ({col},{row}): got={} want={}", - got.y[gi], want.y[gi] - ); - break 'outer; + let (width, height) = if start_x.contains("128x128") { (128usize, 128usize) } else { (64usize, 64usize) }; + for cq in [16u32, 20, 24, 28, 32, 40, 50] { + for rtx in ["0"] { + let mut child = Command::new(aomenc_path()) + .args([ + "--codec=av1", "--passes=1", "--end-usage=q", + &format!("--cq-level={cq}"), "--cpu-used=4", "--threads=1", + "--row-mt=0", "--sb-size=64", "--kf-max-dist=0", + "--enable-rect-partitions=1", "--enable-ab-partitions=0", + "--enable-1to4-partitions=0", "--enable-tx-size-search=0", + "--enable-cdef=0", "--enable-restoration=0", + &format!("--reduced-tx-type-set={rtx}"), + "--min-partition-size=8", "--max-partition-size=32", + "--obu", "-o", "-", "-", + ]) + .stdin(Stdio::piped()).stdout(Stdio::piped()).stderr(Stdio::piped()) + .spawn().expect("aomenc"); + child.stdin.take().unwrap().write_all(&y4m.stdout).unwrap(); + let out = child.wait_with_output().unwrap(); + assert!(out.status.success()); + let stream = out.stdout; + let before = crate::decode::rect_leaf_coeff_hits(); + let res = decode_stream(&stream); + let fired = crate::decode::rect_leaf_coeff_hits() - before; + match res { + Err(e) => eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} REFUSED {e}"), + Ok(frames) => { + let want = ffmpeg_decode_sequence(&stream, width, height, frames.len()); + let bad = frames.iter().zip(&want) + .filter(|(g, w)| g.y != w.y || g.u != w.u || g.v != w.v).count(); + eprintln!("x={start_x} cq={cq} rtx={rtx} fired={fired} frames={} mismatched={bad}", frames.len()); + let (g, w) = (&frames[0], &want[0]); + for br in 0..height / 8 { + let mut line = String::new(); + for bc in 0..width / 8 { + let mut n = 0; + for row in br * 8..br * 8 + 8 { + for col in bc * 8..bc * 8 + 8 { + if g.y[row * width + col] != w.y[row * width + col] { + n += 1; + } + } + } + line.push_str(&format!("{n:4}")); } + eprintln!(" blk8 row{br}: {line}"); } } } - if mismatched == 0 { - found = true; - break; - } - } else { - eprintln!( - "{width}x{height} cq={cq} off={seed_off}: rect_leaf_coeff_hits+={delta} result={:?}", - result.as_ref().map(|f| f.len()).map_err(|e| e.to_string()) - ); } } } - eprintln!("found pixel-exact firing case: {found}"); } /// lane-rectgate r1: every prior gate pins `--enable-rect-partitions=0