forge
Explore
Log in

Don't you dare go Hollow

wip(part32): r4 capped at 75 turns -- SB-level HORZ/VERT 64 work in progress, uncommitted state preserved by orchestrator

Browse files at this commit

ad9ad14e849960a458a1541bf7e6375b78045bfaAhmet Kaan GümüşParent: 621d55b
crates/ec-av1/src/cdf.rsmodified+29 -11
@@ -266,18 +266,36 @@ pub const EOB_PT_128_CHROMA_Q3: [u16; 9] = [
266266 24313, 26062, 28385, 30107, 31217, 31898, 32345, 32768, 0,
267267 ];
268268
269-/// `av1_default_eob_multi512_cdfs[*][1][*]` (`token_cdfs.h:874-901`,
270-/// lane-sbpart): the end-of-block group of a CHROMA transform with 512 coded
271-/// positions -- what a 32x16/16x32 chroma transform has (the chroma plane of
272-/// an intra `PARTITION_HORZ`/`VERT` 64x32/32x64 superblock strip, whose luma
273-/// coefficients truncate to the 64x64-superblock's own 32x32 corner-scan
274-/// (`TxbSet::Luma64`) but whose *chroma* plane, at 32x16, is small enough
275-/// that no truncation applies). Unlike every other `EOB_PT_*` table here,
276-/// libaom's default is the exact same flat distribution at all four
277-/// q-contexts and both `eob_multi_size` selectors (`token_cdfs.h` rows), so
278-/// one constant covers every q-context -- no `_Q0`/`_Q1`/`_Q3` siblings.
269+/// `av1_default_eob_multi512_cdfs[2][1][0]` (`token_cdfs.h:874-901`,
270+/// lane-part32 r4): the end-of-block group of a CHROMA transform with 512
271+/// coded positions -- what a 32x16/16x32 chroma transform has (the chroma
272+/// plane of an intra `PARTITION_HORZ`/`VERT` 64x32/32x64 superblock strip,
273+/// whose luma coefficients truncate to the 64x64-superblock's own 32x32
274+/// corner-scan (`TxbSet::Luma64`) but whose *chroma* plane, at 32x16, is
275+/// small enough that no truncation applies).
276+///
277+/// lane-sbpart originally transcribed the `[1][1]` row -- the
278+/// `TX_CLASS_HORIZ`/`VERT` (1D) sibling, whose default IS the flat
279+/// `3277, 6554, ...` ramp at every q-context -- and wrote that flatness into
280+/// this comment as a property of the whole table. The 2D row this decoder
281+/// actually reads is q-dependent like every other `EOB_PT_*` family, so a
282+/// real `--cq-level=45` stream (q-context 3) read the wrong CDF and desynced
283+/// the tile at the first 32x16 chroma transform of the first SB-level
284+/// HORZ/VERT strip.
279285 pub const EOB_PT_512_CHROMA: [u16; 11] = [
280- 3277, 6554, 9830, 13107, 16384, 19661, 22938, 26214, 29491, 32768, 0,
286+ 12015, 14769, 19588, 22052, 24222, 25812, 27300, 29219, 32114, 32768, 0,
287+];
288+/// [`EOB_PT_512_CHROMA`], q-context 0 (`base_q_idx` 0..=20).
289+pub const EOB_PT_512_CHROMA_Q0: [u16; 11] = [
290+ 5095, 6446, 9996, 13354, 16017, 17986, 20919, 26129, 29140, 32768, 0,
291+];
292+/// [`EOB_PT_512_CHROMA`], q-context 1 (`base_q_idx` 21..=60).
293+pub const EOB_PT_512_CHROMA_Q1: [u16; 11] = [
294+ 7265, 9979, 15819, 19250, 21780, 23846, 26478, 28396, 31811, 32768, 0,
295+];
296+/// [`EOB_PT_512_CHROMA`], q-context 3 (`base_q_idx` 121..=255).
297+pub const EOB_PT_512_CHROMA_Q3: [u16; 11] = [
298+ 21093, 23043, 25742, 27658, 29097, 29716, 30073, 30820, 31956, 32768, 0,
281299 ];
282300
283301 /// `Default_Dc_Sign_Cdf[2][0]` (spec 9.4): the sign of a luma DC coefficient,
crates/ec-av1/src/cdf_state.rsmodified+7 -3
@@ -1010,9 +1010,13 @@ impl Cdfs {
10101010 cdf::EOB_PT_128_CHROMA,
10111011 cdf::EOB_PT_128_CHROMA_Q3,
10121012 ),
1013- // Flat default at every q-context (see the constant's own doc
1014- // comment) -- no `pick()` needed.
1015- eob_pt_512_chroma: cdf::EOB_PT_512_CHROMA,
1013+ eob_pt_512_chroma: pick(
1014+ q_ctx,
1015+ cdf::EOB_PT_512_CHROMA_Q0,
1016+ cdf::EOB_PT_512_CHROMA_Q1,
1017+ cdf::EOB_PT_512_CHROMA,
1018+ cdf::EOB_PT_512_CHROMA_Q3,
1019+ ),
10161020 eob_extra_luma_32: pick(
10171021 q_ctx,
10181022 cdf::EOB_EXTRA_LUMA_32_Q0,
crates/ec-av1/src/decode.rsmodified+149 -5
@@ -758,6 +758,21 @@ pub(crate) fn sb_rect_hits() -> usize {
758758 SB_RECT_HITS.with(|c| c.get())
759759 }
760760
761+// lane-part32 r4: how many superblock-level AB blocks (`PARTITION_HORZ_A`/
762+// `_B`/`VERT_A`/`_B` at 64x64 -- two 32x32 squares plus one 64x32/32x64
763+// strip) fired. Real aomenc picks these at 64 even with
764+// `--enable-ab-partitions=0` (lane-sbpart r2's own measurement), so this is
765+// the counter the gate hard-asserts.
766+thread_local! {
767+ static SB_AB_HITS: std::cell::Cell<usize> =
768+ const { std::cell::Cell::new(0) };
769+}
770+
771+/// Current value of [`SB_AB_HITS`].
772+pub(crate) fn sb_ab_hits() -> usize {
773+ SB_AB_HITS.with(|c| c.get())
774+}
775+
761776 // lane-rect64q r1: how many of [`decode_block_rect64`]'s three per-plane
762777 // dequant calls actually observed `CURRENT_Q_IDX != base_q_idx` -- proof the
763778 // running-vs-stale-snapshot bug this round fixed is exercised by a gate, not
@@ -1370,7 +1385,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) ->
13701385 (TxClass::TwoD, _) | (_, None) => coding.eob_pt,
13711386 (_, Some(class1)) => class1,
13721387 };
1373- if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() && eob_pt.len() == 12 {
1388+ if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {
13741389 let (range, value) = dec.debug_state();
13751390 eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?} range={range} value={value}");
13761391 }
@@ -1647,8 +1662,16 @@ fn read_coeffs_rect(
16471662 sign_ctx: usize,
16481663 default_tx_type: TxType,
16491664 ) -> Result<(Vec<i32>, TxType)> {
1665+ let ec_trace_coeff = std::env::var_os("EC_TRACE_COEFF").is_some();
16501666 let mut grid = vec![0i32; w * h];
16511667 let all_zero = dec.symbol(&mut coding.txb_skip[skip_ctx]) == 1;
1668+ if ec_trace_coeff {
1669+ let (rng, _) = dec.debug_state();
1670+ eprintln!(
1671+ "EC_COEFF_STEP tag=all_zero ctx={skip_ctx} all_zero={} rng={rng}",
1672+ all_zero as i32
1673+ );
1674+ }
16521675 if all_zero {
16531676 return Ok((grid, TxType::DctDct));
16541677 }
@@ -1664,16 +1687,35 @@ fn read_coeffs_rect(
16641687 ));
16651688 }
16661689 let eob = read_eob(dec, coding, TxClass::TwoD);
1690+ if ec_trace_coeff {
1691+ let (rng, _) = dec.debug_state();
1692+ eprintln!("EC_COEFF_STEP tag=eob eob={eob} rng={rng}");
1693+ }
16671694 let mut levels = vec![0i32; w * h];
16681695 for scan_idx in (0..eob).rev() {
16691696 let pos = scan[scan_idx] as usize;
16701697 let (row, col) = (pos / w, pos % w);
16711698 let level = if scan_idx == eob - 1 {
16721699 let ctx = eob_coeff_ctx(scan_idx, w * h);
1673- dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1
1700+ let l = dec.symbol(&mut coding.base_eob[ctx]) as i32 + 1;
1701+ if ec_trace_coeff {
1702+ let (rng, _) = dec.debug_state();
1703+ eprintln!(
1704+ "EC_COEFF_STEP tag=base_eob c={scan_idx} pos={pos} ctx={ctx} level={} rng={rng}",
1705+ l - 1
1706+ );
1707+ }
1708+ l
16741709 } else {
16751710 let ctx = base_ctx_rect(&levels, w, h, row, col);
1676- dec.symbol(&mut coding.base[ctx]) as i32
1711+ let l = dec.symbol(&mut coding.base[ctx]) as i32;
1712+ if ec_trace_coeff {
1713+ let (rng, _) = dec.debug_state();
1714+ eprintln!(
1715+ "EC_COEFF_STEP tag=base c={scan_idx} pos={pos} ctx={ctx} level={l} rng={rng}"
1716+ );
1717+ }
1718+ l
16771719 };
16781720 let level = if level > NUM_BASE_LEVELS {
16791721 let ctx = br_ctx_rect(&levels, w, h, row, col);
@@ -1681,6 +1723,12 @@ fn read_coeffs_rect(
16811723 let mut sent = 0;
16821724 loop {
16831725 let k = dec.symbol(&mut coding.br[ctx]) as i32;
1726+ if ec_trace_coeff {
1727+ let (rng, _) = dec.debug_state();
1728+ eprintln!(
1729+ "EC_COEFF_STEP tag=br c={scan_idx} pos={pos} ctx={ctx} k={k} rng={rng}"
1730+ );
1731+ }
16841732 level += k;
16851733 sent += BR_STEP;
16861734 if k < BR_STEP || sent >= COEFF_BASE_RANGE {
@@ -1693,6 +1741,10 @@ fn read_coeffs_rect(
16931741 };
16941742 levels[pos] = level;
16951743 }
1744+ if ec_trace_coeff {
1745+ let (rng, _) = dec.debug_state();
1746+ eprintln!("EC_COEFF_STEP tag=after_bases rng={rng}");
1747+ }
16961748 for &pos in &scan[..eob] {
16971749 let level = levels[pos as usize];
16981750 if level == 0 {
@@ -4499,6 +4551,15 @@ impl PlaneBuf {
44994551 smooth_neighbor: bool,
45004552 ) {
45014553 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);
4554+ if std::env::var_os("EC_DEBUG_EDGES").is_some() {
4555+ eprintln!(
4556+ "EDGES x={x} y={y} bw={bw} bh={bh} mode={mode} above={:?} left_len={:?} left0={:?} corner={corner:?} tx0={} ty0={} truew={} trueh={}",
4557+ above.as_ref().map(|a| (a.len(), a[0])),
4558+ left.as_ref().map(|l| l.len()),
4559+ left.as_ref().map(|l| l[0]),
4560+ self.tile_x0, self.tile_y0, self.true_width, self.true_height
4561+ );
4562+ }
45024563 let mut prediction = vec![0u16; bw * bh];
45034564 if let Some(fi_mode) = filter_intra {
45044565 crate::intra::predict_filter_intra(
@@ -7688,10 +7749,93 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
76887749 tx_select,
76897750 )?;
76907751 }
7752+ PARTITION_HORZ_A | PARTITION_HORZ_B | PARTITION_VERT_A | PARTITION_VERT_B => {
7753+ // lane-part32 r4: the four superblock-level AB arms, each
7754+ // two 32x32 squares plus one 64x32/32x64 strip, in
7755+ // libaom's own `decode_partition` order (decodeframe.c:
7756+ // HORZ_A = TL, TR, bottom strip; HORZ_B = top strip, BL,
7757+ // BR; VERT_A = TL, BL, right strip; VERT_B = left strip,
7758+ // TR, BR). The pieces are exactly the ones already proven
7759+ // by the `PARTITION_NONE`-under-SPLIT (32x32 square) and
7760+ // `PARTITION_HORZ`/`VERT` (rect64 strip) arms above.
7761+ SB_AB_HITS.with(|c| c.set(c.get() + 1));
7762+ macro_rules! square32 {
7763+ ($at:expr) => {
7764+ decode_block(
7765+ &mut dec,
7766+ &mut cdfs,
7767+ &mut neighbours,
7768+ $at,
7769+ BLOCK,
7770+ TxbSet::Luma32,
7771+ TxbSet::Chroma16,
7772+ TX32,
7773+ TX16,
7774+ (&scan32, &scan16),
7775+ true,
7776+ &mut y,
7777+ &mut u,
7778+ &mut v,
7779+ base_q_idx,
7780+ enable_filter_intra,
7781+ allow_screen_content_tools,
7782+ allow_intrabc,
7783+ &scan32,
7784+ &scan16,
7785+ &scan8,
7786+ &scan4,
7787+ tx_select,
7788+ reduced_tx_set,
7789+ )?
7790+ };
7791+ }
7792+ macro_rules! strip64 {
7793+ ($at:expr, $bw:expr, $bh:expr) => {
7794+ decode_block_rect64(
7795+ &mut dec,
7796+ &mut cdfs,
7797+ &mut neighbours,
7798+ $at,
7799+ $bw,
7800+ $bh,
7801+ &mut y,
7802+ &mut u,
7803+ &mut v,
7804+ enable_filter_intra,
7805+ allow_screen_content_tools,
7806+ base_q_idx,
7807+ tx_select,
7808+ )?
7809+ };
7810+ }
7811+ let (br, bc) = (at.0 + 2, at.1 + 2);
7812+ match part {
7813+ PARTITION_HORZ_A => {
7814+ square32!(at);
7815+ square32!((at.0, bc));
7816+ strip64!((br, at.1), 64, 32);
7817+ }
7818+ PARTITION_HORZ_B => {
7819+ strip64!(at, 64, 32);
7820+ square32!((br, at.1));
7821+ square32!((br, bc));
7822+ }
7823+ PARTITION_VERT_A => {
7824+ square32!(at);
7825+ square32!((br, at.1));
7826+ strip64!((at.0, bc), 32, 64);
7827+ }
7828+ _ => {
7829+ strip64!(at, 32, 64);
7830+ square32!((at.0, bc));
7831+ square32!((br, bc));
7832+ }
7833+ }
7834+ }
76917835 _ => {
76927836 return Err(unsupported(
7693- "a superblock-level partition type other than NONE or SPLIT (this \
7694- decoder's intra tile path codes only those two at 64x64)",
7837+ "a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, \
7838+ four 64x16/16x64 strips)",
76957839 ));
76967840 }
76977841 }
crates/ec-av1/src/refusal_inventory.rsmodified+1 -1
@@ -47,7 +47,7 @@ const REFUSALS: &[&str] = &[
4747 "a superblock-level HORZ/VERT strip with a split transform (per-unit rect prediction is not ported)",
4848 "a tx_type symbol outside its CDF's own set: {t}",
4949 "an INTER 32x32 partition type this decoder does not code (value={part32})",
50- "a superblock-level partition type other than NONE or SPLIT (this decoder's intra tile path codes only those two at 64x64)",
50+ "a superblock-level 1:4 partition (PARTITION_HORZ_4/VERT_4 at 64x64, four 64x16/16x64 strips)",
5151 "a HORZ/VERT intra strip in a screen-content frame (palette syntax is consumed for square blocks only)",
5252 "a HORZ/VERT intra strip with a split transform (per-unit rect prediction is not ported)",
5353 "a block that actually uses a palette (UV) -- reconstruction is out of scope",
crates/ec-av1/src/stream.rsmodified+161 -0
@@ -9512,6 +9512,167 @@ mod tests {
95129512 );
95139513 }
95149514
9515+ /// lane-part32 r4: a real `aomenc` stream whose superblock-level
9516+ /// partition decision is one of the four AB arms (`PARTITION_HORZ_A`/
9517+ /// `_B`/`VERT_A`/`_B` at 64x64: two 32x32 squares plus one 64x32/32x64
9518+ /// strip) must decode pixel-exact. Same recipe as the HORZ/VERT sibling
9519+ /// above with `--enable-ab-partitions=1`; `sb_ab_hits() > 0` is a HARD
9520+ /// assert, so a run where aomenc's RD never picked an AB arm fails
9521+ /// rather than passing vacuously.
9522+ #[test]
9523+ fn a_real_aomenc_stream_with_a_superblock_level_ab_partition_decodes_pixel_exact() {
9524+ const NAME: &str =
9525+ "a_real_aomenc_stream_with_a_superblock_level_ab_partition_decodes_pixel_exact";
9526+ let _gate_lock = lock_gate_counters();
9527+ if !have_ffmpeg() {
9528+ eprintln!("SKIP {NAME}: no ffmpeg");
9529+ return;
9530+ }
9531+ if !have_aomenc() {
9532+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
9533+ return;
9534+ }
9535+ let (width, height, frame_count) = (192usize, 128usize, 1usize);
9536+ let mut named_refusals = 0u32;
9537+ let mut matched = 0u32;
9538+ let n_attempts: u32 = std::env::var("EC_SBAB_GATE_ATTEMPTS")
9539+ .ok()
9540+ .and_then(|s| s.parse().ok())
9541+ .unwrap_or(40);
9542+ for attempt in 0..n_attempts {
9543+ let seed = 42 + attempt;
9544+ let duration = frame_count as f64 / 25.0;
9545+ let source =
9546+ gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));
9547+ let y4m = Command::new("ffmpeg")
9548+ .args([
9549+ "-v",
9550+ "error",
9551+ "-f",
9552+ "lavfi",
9553+ "-i",
9554+ &source,
9555+ "-pix_fmt",
9556+ "yuv420p",
9557+ "-f",
9558+ "yuv4mpegpipe",
9559+ "-",
9560+ ])
9561+ .stdin(Stdio::null())
9562+ .stdout(Stdio::piped())
9563+ .stderr(Stdio::piped())
9564+ .output()
9565+ .expect("ffmpeg failed to run");
9566+ assert!(
9567+ y4m.status.success(),
9568+ "ffmpeg fixture: {}",
9569+ String::from_utf8_lossy(&y4m.stderr)
9570+ );
9571+ let args: Vec<&str> = vec![
9572+ "--codec=av1",
9573+ "--passes=1",
9574+ "--end-usage=q",
9575+ "--cq-level=45",
9576+ "--cpu-used=0",
9577+ "--threads=1",
9578+ "--row-mt=0",
9579+ "--sb-size=64",
9580+ "--enable-rect-partitions=1",
9581+ "--enable-ab-partitions=1",
9582+ "--enable-1to4-partitions=0",
9583+ "--min-partition-size=32",
9584+ "--max-partition-size=64",
9585+ "--enable-restoration=0",
9586+ "--enable-palette=0",
9587+ "--deltaq-mode=0",
9588+ "--enable-filter-intra=0",
9589+ "--enable-cfl-intra=0",
9590+ "--enable-intrabc=0",
9591+ "--enable-tx-size-search=0",
9592+ "--obu",
9593+ "-o",
9594+ "-",
9595+ "-",
9596+ ];
9597+ let mut child = Command::new(aomenc_path())
9598+ .args(&args)
9599+ .stdin(Stdio::piped())
9600+ .stdout(Stdio::piped())
9601+ .stderr(Stdio::piped())
9602+ .spawn()
9603+ .expect("aomenc failed to start");
9604+ child
9605+ .stdin
9606+ .take()
9607+ .expect("aomenc stdin")
9608+ .write_all(&y4m.stdout)
9609+ .expect("writing y4m to aomenc");
9610+ let out = child.wait_with_output().expect("aomenc failed to run");
9611+ assert!(
9612+ out.status.success(),
9613+ "aomenc refused the fixture: {}",
9614+ String::from_utf8_lossy(&out.stderr)
9615+ );
9616+ let stream = out.stdout;
9617+ let frames = match decode_stream(&stream) {
9618+ Err(e) => {
9619+ let msg = e.to_string();
9620+ assert!(
9621+ msg.contains("unsupported"),
9622+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
9623+ );
9624+ // r2: `--enable-ab-partitions=0` does NOT stop aomenc
9625+ // choosing an SB-level HORZ_A/HORZ_B/VERT_A/VERT_B
9626+ // (`partition_w64` value 4-7) even with
9627+ // `--min/max-partition-size=32/64` -- a real, separate
9628+ // encoder quirk (AB-at-64 is a different, unlanded
9629+ // capability, lane-partab's territory is 32x32 and
9630+ // below only) discovered live this round, not this
9631+ // lane's HORZ/VERT gap. Only NONE/SPLIT/HORZ/VERT
9632+ // (values 0-3) are this gate's territory; a real
9633+ // HORZ/VERT (1/2) must still decode pixel-exact, which
9634+ // `sb_rect_hits() > 0` below hard-proves.
9635+ named_refusals += 1;
9636+ eprintln!("seed {seed} refusal: {msg}");
9637+ continue;
9638+ }
9639+ Ok(frames) => frames,
9640+ };
9641+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
9642+ assert_eq!(frames.len(), frame_count);
9643+ let mismatched = frames
9644+ .iter()
9645+ .zip(&ffmpeg_frames)
9646+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
9647+ if mismatched {
9648+ if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
9649+ std::fs::write(&path, &stream).expect("writing pinned stream");
9650+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
9651+ }
9652+ }
9653+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
9654+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})");
9655+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
9656+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
9657+ }
9658+ matched += 1;
9659+ }
9660+ assert!(
9661+ matched > 0,
9662+ "{NAME}: every attempt refused; the gate never decoded a stream"
9663+ );
9664+ assert!(
9665+ crate::decode::sb_ab_hits() > 0,
9666+ "{NAME}: zero superblock-level AB blocks fired ({matched} matches, \
9667+ {named_refusals} refusals out of {n_attempts}) -- gate proved nothing this run"
9668+ );
9669+ eprintln!(
9670+ "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of \
9671+ {n_attempts}, sb_ab_hits={}",
9672+ crate::decode::sb_ab_hits()
9673+ );
9674+ }
9675+
95159676 /// lane-part32 r2: prints the exact mismatch geometry (block coords,
95169677 /// got/want pixels) of the pinned seed-42 stream captured off
95179678 /// `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`