forge
Explore
Log in

Don't you dare go Hollow

Merge lane-av1recipehunt @ 1acf1818 — three TRACKED aomenc fixture pins, stream.rs/encode.rs/tile.rs recipe-hunt fixes, two gates un-ignored, one 128-superblock clip gate DELETED (coverage claim relocated to encode.rs:15689)

Browse files at this commit

083a88e0e87e85d02206045901d7ccb10d50cdafAhmet Kaan GümüşParent: f3a70c9e100a8a
crates/ec-av1/examples/decode_probe.rsmodified+6 -0
@@ -271,6 +271,12 @@ fn main() {
271 // lane-thread2: proof the frame-parallel path actually fired (0 at271 // lane-thread2: proof the frame-parallel path actually fired (0 at
272 // the default EC_AV1_THREADS=1).272 // the default EC_AV1_THREADS=1).
273 println!("frames_dispatched: {}", ec_av1::stream::frames_dispatched());273 println!("frames_dispatched: {}", ec_av1::stream::frames_dispatched());
274+ // lane-av1recipehunt: `intra_rect4_in_inter` above already reports the
275+ // 1:4-in-inter shapes; this is the `delta_q` half of the same story --
276+ // how many delta_q groups the stream really carried, and how many of
277+ // them landed inside a rect64 dequant.
278+ let (dq, dq_drift) = ec_av1::stream::rect64_qidx_drift_counters();
279+ println!("delta_q: groups_read={dq} rect64_qidx_drift={dq_drift}");
274 };280 };
275 // lane-tiles: the tiling a real stream actually uses is a decision input281 // lane-tiles: the tiling a real stream actually uses is a decision input
276 // (every gate in `stream.rs` picks its own `--tile-columns`), so report it282 // (every gate in `stream.rs` picks its own `--tile-columns`), so report it
crates/ec-av1/examples/enc_probe.rsmodified+12 -4
@@ -20,9 +20,10 @@ fn main() {
20 true => (0, 0),20 true => (0, 0),
21 false => (a[1].parse().unwrap(), a[2].parse().unwrap()),21 false => (a[1].parse().unwrap(), a[2].parse().unwrap()),
22 };22 };
23- let qs: Vec<u8> = a23+ let qs: Vec<u8> = a.get(4).map_or_else(
24- .get(4)24+ || vec![150, 120, 90, 60],
25- .map_or_else(|| vec![150, 120, 90, 60], |s| s.split(',').map(|q| q.parse().unwrap()).collect());25+ |s| s.split(',').map(|q| q.parse().unwrap()).collect(),
26+ );
26 27
27 // lane-census/lane-probe: the BD gate's native rows CROP (`EC_ENC_VF`) and28 // lane-census/lane-probe: the BD gate's native rows CROP (`EC_ENC_VF`) and
28 // SEEK (`EC_ENC_SS`) -- without the seek this probe read film B's black29 // SEEK (`EC_ENC_SS`) -- without the seek this probe read film B's black
@@ -71,7 +72,10 @@ fn main() {
71 .join(" ")72 .join(" ")
72 };73 };
73 println!(" census luma SAD rank of RD winner: {}", pct(&luma_rank));74 println!(" census luma SAD rank of RD winner: {}", pct(&luma_rank));
74- println!(" census chroma SAD rank of RD winner: {}", pct(&chroma_rank));75+ println!(
76+ " census chroma SAD rank of RD winner: {}",
77+ pct(&chroma_rank)
78+ );
75 }79 }
76 // lane-arfmode: the engagement counter of the top ARF's offer-set80 // lane-arfmode: the engagement counter of the top ARF's offer-set
77 // lever, taken once per point so an armed run PRINTS a non-zero count81 // lever, taken once per point so an armed run PRINTS a non-zero count
@@ -80,6 +84,10 @@ fn main() {
80 // control's own expectation.84 // control's own expectation.
81 let hits = ec_av1::encode::take_arfmode_hits();85 let hits = ec_av1::encode::take_arfmode_hits();
82 println!(" arfmode hits: {} {} {}", hits[0], hits[1], hits[2]);86 println!(" arfmode hits: {} {} {}", hits[0], hits[1], hits[2]);
87+ // lane-av1recipehunt: the gate's own precondition number -- how many
88+ // blocks this point's search picked a DRL index the write-time stack
89+ // could not carry.
90+ println!(" drl_clamp: {}", ec_av1::tile::drl_clamp_hits());
83 }91 }
84 println!("wall {:.3}s", start.elapsed().as_secs_f64());92 println!("wall {:.3}s", start.elapsed().as_secs_f64());
85 }93 }
crates/ec-av1/fixtures/intra14_256x192_10bit.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/intra14_256x192_8bit.obuadded+0 -0

Binary file changed

crates/ec-av1/fixtures/rect64_dq_drift.obuadded+0 -0

Binary file changed

crates/ec-av1/src/encode.rsmodified+45 -72
@@ -15686,6 +15686,40 @@ mod tests {
15686 /// side, so the stream stays legal; here the pricer's own offer set is15686 /// side, so the stream stays legal; here the pricer's own offer set is
15687 /// enumerated, class `enumerate-table-domain`).15687 /// enumerated, class `enumerate-table-domain`).
15688 ///15688 ///
15689+ /// **This is the coverage claim for the drl-clamp cell** (lane-av1recipehunt
15690+ /// r2, 2026-09-29). It replaces the clip gate
15691+ /// `a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact`,
15692+ /// deleted in `3e8c65e6`+r2: that gate asserted `drl_clamp_hits() > 0` on a
15693+ /// real 1280x768 sb128 clip, but `DRL_CLAMP_HITS` is provably unreachable
15694+ /// while the invariant above holds, so no recipe could ever satisfy it.
15695+ /// Deletion loses no coverage on either half:
15696+ /// * the clamp half -- this test IS the coverage, and it is strictly
15697+ /// stronger than any clip gate: it enumerates the pricer's whole offer
15698+ /// set against the writer's rule for every stack size 0..=4, and larger
15699+ /// stacks add entries the pricers never offer (`best_new_mv_syntax`
15700+ /// breaks at `entries.len() <= idx` for `idx > 0`, so indices 3/4 are
15701+ /// unreachable at ANY stack size), which is why 0..=4 bounds the
15702+ /// domain rather than sampling it;
15703+ /// * the pixel half -- the deleted gate's own decode-vs-encoder-
15704+ /// reconstruction compare on a 1280x768 sb128 sequence is already made
15705+ /// four times over, by `a_128_superblock_clip_whose_root_search_codes_
15706+ /// 128x128_blocks_decodes_exact`,
15707+ /// `a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders`,
15708+ /// `a_128_root_residual_block_under_a_per_unit_cdef_list_decodes_exact`
15709+ /// and `a_rect128_half_with_a_real_residual_decodes_exact_through_both_decoders`
15710+ /// (same geometry, same `force_sb128(true)`, same own-reconstruction AND
15711+ /// ffmpeg compare).
15712+ /// MEASURED before deleting (153 clip x size x frame-count x q combinations,
15713+ /// `enc_probe`): `tile::drl_clamp_hits()` = 0 on every one. MUTATION PROOF
15714+ /// the clip was never the variable: widening `best_new_mv_syntax`'s offer
15715+ /// set to `0..5` fires the counter immediately (9/2/2/1 on
15716+ /// mandelbrot 640x384x8, mandelbrot 320x192x8, mosaic 320x192x8,
15717+ /// testsrc2 640x384x8) and the same clips read 0 on revert. `note_drl_clamp`
15718+ /// and `DRL_CLAMP_HITS` are KEPT as the tripwire for the owning fix
15719+ /// (`deferred(unblock: the DRL owner widens the pricer past the writer's
15720+ /// `start + 2` ceiling, or retires the counter)`) -- this test will go red
15721+ /// the moment either happens, which is the signal to re-open the cell.
15722+ ///
15689 /// cargo test -p ec-av1 --lib -- every_drl_index_the_new_mv_pricer15723 /// cargo test -p ec-av1 --lib -- every_drl_index_the_new_mv_pricer
15690 #[test]15724 #[test]
15691 fn every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal() {15725 fn every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal() {
@@ -18581,8 +18615,17 @@ mod tests {
18581 ///18615 ///
18582 /// `#[ignore]`: [`force_sb128`] moves a process-global.18616 /// `#[ignore]`: [`force_sb128`] moves a process-global.
18583 ///18617 ///
18584- /// cargo test -p ec-av1 --release --lib -- --ignored \18618+ /// The drl-clamp cell this gate's counter used to gate is no longer gated
18585- /// a_128_superblock_clip_whose_drl_index_the_write_time_stack --nocapture18619+ /// here: it is covered by
18620+ /// [`every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`],
18621+ /// which enumerates the pricer's offer set against the writer's rule (see
18622+ /// its doc). The clamp needs a stack that shrinks between search and
18623+ /// write, which is what a 128x128 superblock's visit order would do -- but
18624+ /// the pricer never offers an index this tree's `write_drl_idx` cannot
18625+ /// signal, so no clip can provoke it (lane-av1recipehunt: 153 attempts, 0;
18626+ /// widening the pricer to `0..5` fires the counter immediately, reverting
18627+ /// silences it). `drl_clamp_hits` is kept as the tripwire for that fix.
18628+
18586 /// lane-b128: the 128x128 `PARTITION_NONE` root -- one block, one mode18629 /// lane-b128: the 128x128 `PARTITION_NONE` root -- one block, one mode
18587 /// and one motion vector where the four 64x64 roots below spend four of18630 /// and one motion vector where the four 64x64 roots below spend four of
18588 /// each (cen3's L1). The counter is the gate on the fixture (class18631 /// each (cen3's L1). The counter is the gate on the fixture (class
@@ -19446,76 +19489,6 @@ mod tests {
19446 );19489 );
19447 }19490 }
19448 19491
19449- #[test]
19450- #[ignore = "sets the process-global superblock size: run it alone"]
19451- fn a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact() {
19452- let _knobs = crate::speed::knob_write();
19453- if !have_ffmpeg() {
19454- eprintln!("SKIP: no ffmpeg");
19455- return;
19456- }
19457- force_sb128(true);
19458- let dir = std::env::temp_dir().join(format!("ec-av1-sb128b-{}", std::process::id()));
19459- std::fs::create_dir_all(&dir).unwrap();
19460- let clip = dir.join("mandelbrot-1280x768.y4m");
19461- let ok = Command::new("ffmpeg")
19462- .args([
19463- "-v",
19464- "error",
19465- "-y",
19466- "-f",
19467- "lavfi",
19468- "-i",
19469- "mandelbrot=size=1280x768:rate=24",
19470- ])
19471- .args(["-frames:v", "12", "-pix_fmt", "yuv420p"])
19472- .arg(&clip)
19473- .status()
19474- .expect("ffmpeg failed to run")
19475- .success();
19476- assert!(ok, "ffmpeg could not write the synthetic clip");
19477- let path = clip.to_str().unwrap();
19478- let (width, height) = (1280usize, 768usize);
19479- let pictures = crate::probe::source(path, "0", "null", width, height, 12);
19480-
19481- let _ = crate::tile::take_drl_clamp_hits();
19482- let encoded = encode_sequence(&pictures, 150, 0.5).unwrap();
19483- let clamps = crate::tile::take_drl_clamp_hits();
19484- assert!(
19485- clamps > 0,
19486- "this clip never asked for a drl index the write-time stack could not carry, \
19487- so it cannot witness the defect"
19488- );
19489- eprintln!("clamped drl indices: {clamps}");
19490-
19491- let decoded = crate::stream::decode_stream(&encoded.stream).expect("our decoder");
19492- assert_eq!(decoded.len(), encoded.frames.len(), "frame count");
19493- for (i, (frame, dec)) in encoded.frames.iter().zip(&decoded).enumerate() {
19494- let recon = &frame.reconstruction;
19495- for (plane, got, want) in [
19496- ("luma", &dec.y, &recon.y),
19497- ("U", &dec.u, &recon.u),
19498- ("V", &dec.v, &recon.v),
19499- ] {
19500- let differ = got.iter().zip(want).filter(|(a, b)| a != b).count();
19501- assert_eq!(
19502- differ,
19503- 0,
19504- "frame {i}: {plane} -- {differ} of {} samples differ from the encoder's \
19505- own reconstruction",
19506- got.len()
19507- );
19508- assert_eq!(
19509- got.len(),
19510- want.len(),
19511- "frame {i}: {plane} is {} samples, the reconstruction's is {}",
19512- got.len(),
19513- want.len()
19514- );
19515- }
19516- }
19517- }
19518-
19519 #[test]19492 #[test]
19520 fn every_frame_of_a_sequence_decodes_through_our_own_decoder() {19493 fn every_frame_of_a_sequence_decodes_through_our_own_decoder() {
19521 let _knobs = crate::speed::knob_read();19494 let _knobs = crate::speed::knob_read();
crates/ec-av1/src/stream.rsmodified+521 -431
@@ -2170,6 +2170,18 @@ pub fn intra_rect4_in_inter_counters() -> (usize, usize, usize, usize) {
2170 )2170 )
2171 }2171 }
2172 2172
2173+/// lane-av1recipehunt: the recipe sweep's view of the `delta_q` story from
2174+/// OUTSIDE the crate -- `(delta_q symbol groups read, rect64 dequant calls that
2175+/// saw `CURRENT_Q_IDX != base_q_idx`)`. A recipe that reads delta_q but never
2176+/// lands one inside a rect64 root is a different failure from one that reads
2177+/// neither, and the gate can only tell them apart with both numbers.
2178+pub fn rect64_qidx_drift_counters() -> (usize, usize) {
2179+ (
2180+ crate::decode::delta_q_hits(),
2181+ crate::decode::rect64_qidx_drift_hits(),
2182+ )
2183+}
2184+
2173 #[cfg(test)]2185 #[cfg(test)]
2174 pub(crate) mod tests {2186 pub(crate) mod tests {
2175 use super::*;2187 use super::*;
@@ -39269,25 +39281,61 @@ pub(crate) mod tests {
39269 }39281 }
39270 }39282 }
39271 39283
39272- /// lane-rect64q r1: same recipe as39284+ /// lane-rect64q r1, recipe rewritten by lane-av1recipehunt: the same
39285+ /// encoder-side situation as
39273 /// [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`]39286 /// [`a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_decodes_pixel_exact`]
39274- /// minus `--deltaq-mode=0` -- real aomenc's non-realtime default is39287+ /// -- a real superblock-level HORZ/VERT partition, so
39275- /// `DELTA_Q_OBJECTIVE` (`av1_cx_iface.c:271`), so dropping that one flag39288+ /// [`crate::decode::decode_block_rect64`] runs -- but with `delta_q` left
39276- /// is enough to make `delta_q_present=1` the norm and drive39289+ /// ON, so that block's dequant sees a running `CURRENT_Q_IDX` that has
39277- /// [`crate::decode::decode_block_rect64`]'s running `CURRENT_Q_IDX` away39290+ /// drifted away from the frame-constant `base_q_idx`. Real aomenc's
39278- /// from the frame-constant `base_q_idx` inside a real rect64 SB --39291+ /// non-realtime default is `DELTA_Q_OBJECTIVE` (`av1_cx_iface.c:271`); the
39279- /// exactly the bug this round's dequant fix targets. Hard-asserts39292+ /// `--deltaq-mode=0` sibling is the same command line with that one flag
39280- /// `rect64_qidx_drift_hits() > 0`: without that, this gate could pass39293+ /// added back, and this gate ASSERTS the pair differs (the control arm).
39281- /// vacuously the same way the `--deltaq-mode=0` sibling always did.39294+ ///
39282- ///39295+ /// **Why r1's recipe could not fire, measured (lane-av1recipehunt).** r1
39283- /// lane-rect64q r1: measured, does NOT fire -- 15/40 attempts matched39296+ /// swept 40 attempts of `gradients` at 192x128 with `frame_count = 1` -- a
39284- /// but `rect64_qidx_drift_hits()` stayed 0 every time. Real aomenc's RD39297+ /// single KEY frame, and that is the whole reason. A one-frame encode
39285- /// never chose a nonzero delta-q on this tiny synthetic gradients frame39298+ /// carries no inter frame, and `delta_q_present` needs the temporal (TPL)
39286- /// even with `deltaq-mode` left at its default; `#[ignore]`d rather than39299+ /// model to see a spatial complexity map at all. At `frame_count = 1` the
39287- /// deleted so the recipe and the negative result both survive for the39300+ /// sweep read ZERO `delta_q` symbol groups on every attempt: 40/40 streams
39288- /// next attempt (see `lanes/rect64q-r1.report.md`).39301+ /// had `delta_q_hits() == 0` AND `rect64_qidx_drift_hits() == 0` -- a
39289- #[test]39302+ /// different failure from "the drift never reached a rect64 block", and the
39290- #[ignore = "gate recipe never fires the feature (40/40 streams pixel-exact); needs a recipe that produces a rect64 dequant call with CURRENT_Q_IDX != base_q_idx -- class gate-blind-to-feature"]39303+ /// reason r1 could not see the feature at all. The fix is a real inter
39304+ /// sequence: 4 frames at 512x384 (`8x6` superblocks, so there IS a spatial
39305+ /// map for the quantizer to vary over).
39306+ ///
39307+ /// **The recipe**, exactly (the recorded command line; `--deltaq-mode` is
39308+ /// ABSENT, i.e. aomenc's default):
39309+ /// ```text
39310+ /// ffmpeg -v error -y -f lavfi -i testsrc2=size=512x384:rate=25 \
39311+ /// -pix_fmt yuv420p -frames:v 4 -f yuv4mpegpipe src512.y4m
39312+ /// aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=45 --cpu-used=0 \
39313+ /// --threads=1 --row-mt=0 --sb-size=64 --enable-rect-partitions=1 \
39314+ /// --enable-ab-partitions=0 --enable-1to4-partitions=0 \
39315+ /// --min-partition-size=32 --max-partition-size=64 \
39316+ /// --enable-restoration=0 --enable-palette=0 --enable-cdef=0 \
39317+ /// --enable-filter-intra=0 --enable-cfl-intra=0 --enable-intrabc=0 \
39318+ /// --enable-tx-size-search=0 --obu -o out.obu src512.y4m
39319+ /// ```
39320+ /// Source `src512.y4m`: 1179730 bytes, sha256
39321+ /// `f430d581497e4f6f7db07d0fc92476e92194e1f96c321988ec0739d475cbbe0c`.
39322+ /// Output `crates/ec-av1/fixtures/rect64_dq_drift.obu`: 8384 bytes, sha256
39323+ /// `094e51bb21b6caccc905417e95a03f9131b448071567d0b14ec8850799ea2501`
39324+ /// (committed with `git add -f` past the `fixtures` gitignore, like every
39325+ /// sibling fixture). The gate re-encodes live and byte-compares against
39326+ /// that pin, so the pin is the expected output and not a second decode
39327+ /// path. MEASURED on the feature arm: 48 `delta_q` symbol groups read, 17
39328+ /// `rect64_qidx_drift_hits`, `sb_rect_hits` firing (the `inter_rect`
39329+ /// census reads `64x32=2 32x64=2`), all 4 frames pixel-exact vs ffmpeg.
39330+ /// On the `--deltaq-mode=0` control: 0 groups, 0 drift, also pixel-exact --
39331+ /// so the drift is the delta_q syntax, not some unrelated arm.
39332+ ///
39333+ /// `--cpu-used=0` is load-bearing, measured: the same source at
39334+ /// `--cpu-used=1` and `--cpu-used=3` reads the same 48 `delta_q` groups and
39335+ /// drifts ZERO times (the faster presets' RD never leaves a rect64 root in
39336+ /// a superblock whose quantizer moved). `--cq-level` is not: 45 and 55
39337+ /// give the identical stream and the same drift count.
39338+ #[test]
39291 fn a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact()39339 fn a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact()
39292 {39340 {
39293 const NAME: &str = "a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact";39341 const NAME: &str = "a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact";
@@ -39300,124 +39348,142 @@ pub(crate) mod tests {
39300 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());39348 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
39301 return;39349 return;
39302 }39350 }
39303- let (width, height, frame_count) = (192usize, 128usize, 1usize);39351+ const FIXTURE_LEN: usize = 8384;
39304- let mut named_refusals = 0u32;39352+ const FIXTURE_FNV: u64 = 0x3d91_a216_8006_3ef6;
39305- let mut matched = 0u32;39353+ let (width, height, frame_count) = (512usize, 384usize, 4usize);
39306- let n_attempts: u32 = std::env::var("EC_SBPART_DQ_GATE_ATTEMPTS")39354+ let y4m = Command::new("ffmpeg")
39307- .ok()39355+ .args([
39308- .and_then(|s| s.parse().ok())39356+ "-v",
39309- .unwrap_or(40);39357+ "error",
39310- for attempt in 0..n_attempts {39358+ "-y",
39311- let seed = 42 + attempt;39359+ "-f",
39312- let duration = frame_count as f64 / 25.0;39360+ "lavfi",
39313- let source =39361+ "-i",
39314- gradients_source(seed, width, height, &format!("duration={duration}:rate=25"));39362+ "testsrc2=size=512x384:rate=25",
39315- let y4m = Command::new("ffmpeg")39363+ "-pix_fmt",
39316- .args([39364+ "yuv420p",
39317- "-v",39365+ "-frames:v",
39318- "error",39366+ "4",
39319- "-f",39367+ "-f",
39320- "lavfi",39368+ "yuv4mpegpipe",
39321- "-i",
39322- &source,
39323- "-pix_fmt",
39324- "yuv420p",
39325- "-f",
39326- "yuv4mpegpipe",
39327- "-",
39328- ])
39329- .stdin(Stdio::null())
39330- .stdout(Stdio::piped())
39331- .stderr(Stdio::piped())
39332- .output()
39333- .expect("ffmpeg failed to run");
39334- assert!(
39335- y4m.status.success(),
39336- "ffmpeg fixture: {}",
39337- String::from_utf8_lossy(&y4m.stderr)
39338- );
39339- let args: Vec<&str> = vec![
39340- "--codec=av1",
39341- "--passes=1",
39342- "--end-usage=q",
39343- "--cq-level=45",
39344- "--cpu-used=0",
39345- "--threads=1",
39346- "--row-mt=0",
39347- "--sb-size=64",
39348- "--enable-rect-partitions=1",
39349- "--enable-ab-partitions=0",
39350- "--enable-1to4-partitions=0",
39351- "--min-partition-size=32",
39352- "--max-partition-size=64",
39353- "--enable-restoration=0",
39354- "--enable-palette=0",
39355- "--enable-filter-intra=0",
39356- "--enable-cfl-intra=0",
39357- "--enable-intrabc=0",
39358- "--enable-tx-size-search=0",
39359- "--obu",
39360- "-o",
39361- "-",
39362 "-",39369 "-",
39363- ];39370+ ])
39364- let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);39371+ .stdin(Stdio::null())
39365- assert!(39372+ .stdout(Stdio::piped())
39366- out.status.success(),39373+ .stderr(Stdio::piped())
39367- "aomenc refused the fixture: {}",39374+ .output()
39368- String::from_utf8_lossy(&out.stderr)39375+ .expect("ffmpeg failed to run");
39369- );
39370- let stream = out.stdout;
39371- let frames = match decode_stream(&stream) {
39372- Err(e) => {
39373- let msg = e.to_string();
39374- assert!(
39375- msg.contains("unsupported"),
39376- "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
39377- );
39378- named_refusals += 1;
39379- eprintln!("seed {seed} refusal: {msg}");
39380- continue;
39381- }
39382- Ok(frames) => frames,
39383- };
39384- let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
39385- assert_eq!(frames.len(), frame_count);
39386- let mismatched = frames
39387- .iter()
39388- .zip(&ffmpeg_frames)
39389- .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
39390- if mismatched {
39391- if let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
39392- std::fs::write(&path, &stream).expect("writing pinned stream");
39393- eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
39394- }
39395- }
39396- for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
39397- assert_eq!(
39398- got.y, want.y,
39399- "{NAME} frame {i} luma vs ffmpeg (seed {seed})"
39400- );
39401- assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
39402- assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
39403- }
39404- matched += 1;
39405- }
39406 assert!(39376 assert!(
39407- matched > 0,39377+ y4m.status.success(),
39408- "{NAME}: every attempt refused; the gate never decoded a stream"39378+ "ffmpeg fixture: {}",
39379+ String::from_utf8_lossy(&y4m.stderr)
39409 );39380 );
39381+ assert_eq!(
39382+ y4m.stdout.len(),
39383+ 1_179_730,
39384+ "{NAME}: the testsrc2 source is not the pinned 4-frame 512x384 y4m -- `rate=` \
39385+ and `-frames:v` are both part of this recipe's identity"
39386+ );
39387+ // Every flag spelled exactly once (class [[aomenc-last-flag-wins]]).
39388+ // `delta_q` is absent ON PURPOSE: aomenc's non-realtime default is
39389+ // DELTA_Q_OBJECTIVE, and the control arm below re-checks that by
39390+ // ADDING `--deltaq-mode=0` back.
39391+ let args: Vec<&str> = vec![
39392+ "--codec=av1",
39393+ "--passes=1",
39394+ "--end-usage=q",
39395+ "--cq-level=45",
39396+ "--cpu-used=0",
39397+ "--threads=1",
39398+ "--row-mt=0",
39399+ "--sb-size=64",
39400+ "--enable-rect-partitions=1",
39401+ "--enable-ab-partitions=0",
39402+ "--enable-1to4-partitions=0",
39403+ "--min-partition-size=32",
39404+ "--max-partition-size=64",
39405+ "--enable-restoration=0",
39406+ "--enable-palette=0",
39407+ "--enable-cdef=0",
39408+ "--enable-filter-intra=0",
39409+ "--enable-cfl-intra=0",
39410+ "--enable-intrabc=0",
39411+ "--enable-tx-size-search=0",
39412+ "--obu",
39413+ "-o",
39414+ "-",
39415+ "-",
39416+ ];
39417+ let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
39410 assert!(39418 assert!(
39411- crate::decode::rect64_qidx_drift_hits() > 0,39419+ out.status.success(),
39412- "{NAME}: zero rect64 dequant calls ever observed CURRENT_Q_IDX != base_q_idx \39420+ "aomenc refused the fixture: {}",
39413- ({matched} matches, {named_refusals} refusals out of {n_attempts}) -- delta_q \39421+ String::from_utf8_lossy(&out.stderr)
39414- was never actually exercised through decode_block_rect64 this run"39422+ );
39423+ let stream = out.stdout;
39424+ assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: encoded size moved");
39425+ assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: encoded bytes moved");
39426+ let pin = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR"))
39427+ .join("fixtures/rect64_dq_drift.obu");
39428+ assert_eq!(
39429+ std::fs::read(&pin).expect("fixtures/rect64_dq_drift.obu must be committed"),
39430+ stream,
39431+ "{NAME}: the live encode no longer matches the committed pin at {}",
39432+ pin.display()
39433+ );
39434+
39435+ let before = crate::decode::rect64_qidx_drift_hits();
39436+ let frames = decode_stream(&stream)
39437+ .unwrap_or_else(|e| panic!("{NAME}: the pinned stream must decode: {e}"));
39438+ let drift = crate::decode::rect64_qidx_drift_hits() - before;
39439+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
39440+ assert_eq!(frames.len(), frame_count);
39441+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
39442+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg");
39443+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg");
39444+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg");
39445+ }
39446+ assert!(
39447+ crate::decode::sb_rect_hits() > 0,
39448+ "{NAME}: zero superblock-level HORZ/VERT blocks fired -- the recipe stopped producing \
39449+ the shape the delta_q group is read inside"
39450+ );
39451+ assert!(
39452+ drift > 0,
39453+ "{NAME}: {frame_count} frames pixel-exact but zero rect64 dequant calls ever saw \
39454+ CURRENT_Q_IDX != base_q_idx -- delta_q was read and never moved the quantizer inside \
39455+ a rect64 block, so this run proved nothing (class gate-blind-to-feature)"
39456+ );
39457+
39458+ // The control arm: the ONE flag separating this gate from the
39459+ // always-vacuous `--deltaq-mode=0` sibling, reverted. If this ever
39460+ // drifts too, delta_q is no longer what carries the coverage and the
39461+ // feature arm above is not the witness it claims to be. It is also this
39462+ // gate's own red-proof: dropping that one flag is exactly what turns
39463+ // the drift assert above red on its own precondition.
39464+ let mut control = args.clone();
39465+ control.push("--deltaq-mode=0");
39466+ let ctl = run_with_stdin(Command::new(aomenc_path()).args(&control), &y4m.stdout);
39467+ assert!(
39468+ ctl.status.success(),
39469+ "aomenc refused the --deltaq-mode=0 control: {}",
39470+ String::from_utf8_lossy(&ctl.stderr)
39471+ );
39472+ let before = crate::decode::rect64_qidx_drift_hits();
39473+ decode_stream(&ctl.stdout)
39474+ .unwrap_or_else(|e| panic!("{NAME}: the control stream must decode too: {e}"));
39475+ let ctl_drift = crate::decode::rect64_qidx_drift_hits() - before;
39476+ assert_eq!(
39477+ ctl_drift, 0,
39478+ "{NAME}: the --deltaq-mode=0 control drifted {ctl_drift} times -- delta_q is no \
39479+ longer what moves CURRENT_Q_IDX inside a rect64 block, so the feature arm above is \
39480+ not witnessing what it names"
39415 );39481 );
39416 eprintln!(39482 eprintln!(
39417- "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of \39483+ "{NAME}: {frame_count} frames pixel-exact, sb_rect_hits={}, \
39418- {n_attempts}, sb_rect_hits={}, rect64_qidx_drift_hits={}",39484+ rect64_qidx_drift_hits={drift} (--deltaq-mode=0 control: {ctl_drift}), stream \
39419- crate::decode::sb_rect_hits(),39485+ {FIXTURE_LEN} B fnv1a64={FIXTURE_FNV:016x}",
39420- crate::decode::rect64_qidx_drift_hits()39486+ crate::decode::sb_rect_hits()
39421 );39487 );
39422 }39488 }
39423 39489
@@ -42050,85 +42116,127 @@ pub(crate) mod tests {
42050 /// `read_intra_block_mode_info` (libaom decodemv.c:1189).42116 /// `read_intra_block_mode_info` (libaom decodemv.c:1189).
42051 ///42117 ///
42052 /// Hard-asserts `intra_rect4_strip_in_inter_hits` (0 = 64x16, 1 = 16x64,42118 /// Hard-asserts `intra_rect4_strip_in_inter_hits` (0 = 64x16, 1 = 16x64,
42053- /// 2 = 32x8, 3 = 8x32) summed over the attempts that were actually42119+ /// 2 = 32x8, 3 = 8x32) on the one pinned recipe below, and every
42054- /// pixel-compared, and every decode-order frame is compared. A decode that42120+ /// decode-order frame is compared. A decode that succeeds is ALWAYS
42055- /// succeeds is ALWAYS pixel-compared (class42121+ /// pixel-compared (class [[gate-skips-on-its-own-failure]]), and a recipe
42056- /// [[gate-skips-on-its-own-failure]]); exhausting every attempt without a42122+ /// that decodes exact without a counted strip is a FAILURE, never a pass.
42057- /// counted strip is a FAILURE, never a SKIP.42123+ /// The recipe, the pin and the `--enable-1to4-partitions=0` control arm
42058- #[test]42124+ /// are documented on [`intra_rect4_in_inter_gate`].
42059- // r1 `#[ignore]`d this gate on "every stream with an intra 1:4 strip also42125+ #[test]
42060- // hits the inter rect-strip refusal". r2 merged main 18bf7dc (lane-r1442126+ // CLOSED by lane-av1recipehunt r1 (un-ignored). Two independent runs agree
42061- // a2e2e29 lifts exactly that refusal) and re-ran it: 3 of 40 attempts42127+ // on why this gate was blind, and they are worth keeping side by side.
42062- // decode whole and reach the pixel compare (0 before), one firing
42063- // 64x16=4 16x64=3 -- and the compare FAILED on an unowned inter-frame
42064- // defect (mandelbrot 192x128, luma ~3.7-4.5k samples on frames 3/4
42065- // drifting to ~24k, max |d| ~220 on frames 5-7).
42066 //42128 //
42067 // lane-av1pins RE-RAN this gate in RELEASE on a21f3680 (the seven-lane42129 // lane-av1pins RE-RAN this gate in RELEASE on a21f3680 (the seven-lane
42068- // merged tree) and BOTH halves of that r2 record are now stale:42130+ // merged tree) and found BOTH halves of the r2 record stale:
42069- // * THE PIXEL BLOCKER IS GONE. The gate's own tally reads42131+ // * THE PIXEL BLOCKER IS GONE -- `counted-exact=0 uncounted-exact=40
42070- // `counted-exact=0 uncounted-exact=40 named-refusals=0 (attempts 40)`42132+ // named-refusals=0 (attempts 40)` at both bit depths, and not one
42071- // at both bit depths, and there is NOT ONE mismatch line anywhere in42133+ // mismatch line anywhere in the run log. 40/40 pixel-exact.
42072- // the full run log -- no frame 3/4 luma counts, no max |d|, no drift.42134+ // * THE RECIPE NEVER FIRES -- every counted attempt reads
42073- // 40/40 streams now compare pixel-exact. (The 10-bit arm is identical:42135+ // `64x16=0 16x64=0 32x8=0 8x32=0`, so the assert trips on its
42074- // same 40/40, same zero-mismatch log.)42136+ // non-vacuity precondition, not on any pixel.
42075- // * THE RECIPE NO LONGER FIRES THE FEATURE. Every one of the 4242137+ //
42076- // counted attempts reads `64x16=0 16x64=0 32x8=0 8x32=0`. The gate has42138+ // lane-av1recipehunt then found WHY, and closed it. The blindness is not
42077- // regressed from r2's "fires sometimes, compare fails" to "never42139+ // the r2 "pre-existing INTER-frame pixel defect" (gone) and not the
42078- // fires", so the assertion now trips on its non-vacuity precondition42140+ // mandelbrot source: the old recipe produced ZERO 1:4 strips of ANY shape
42079- // (stream.rs:40653) rather than on any pixel.42141+ // at ANY level, because `--min-partition-size=32` with an all-but-empty
42080- // So the reason these gates stay `#[ignore]`d is the RECIPE, exactly as42142+ // intra mode set never puts a 1:4 partition on aomenc's RD menu.
42081- // the `#[ignore]` string says -- NOT the mandelbrot defect, which the42143+ // MEASURED: the 32-level 1:4 counter is 0 in ALL 48 attempts at
42082- // string never claimed and which is no longer reproducing. Kept ignored42144+ // `--min-partition-size=16` and fires in 40 of 48 at 8 with
42083- // rather than un-ignored: a source whose baseline is exact AND that fires42145+ // `--enable-smooth-intra/paeth-intra/directional-intra/angle-delta=1`
42084- // a 32-level intra 1:4 strip in an inter frame still does not exist.42146+ // (a 32x8/8x32 strip needs an intra mode WORTH CODING; with those four
42085- // (Corrected 2026-09-29: the comment above previously recorded the r242147+ // off the only candidate is DC, and DC never wins a 1:4 strip against
42086- // state and would have had a reader re-filing these as blocked on the42148+ // inter). That also explains r2's "`--enable-1to4-partitions=0` is
42087- // mandelbrot defect, which is wrong on this tree.)42149+ // byte-identical": with no 1:4 reachable at all, the flag had nothing to
42088- #[ignore = "gate recipe never fires the feature (40/40 streams pixel-exact); needs a recipe that produces a 32-level intra 1:4 strip in an inter frame -- class gate-blind-to-feature"]42150+ // turn off. The new recipe is 256x192x6, `--min-partition-size=8`, the
42151+ // full intra mode set, `--cpu-used=2 --cq-level=63`; it fires 32x8=8
42152+ // 8x32=11 and is pixel-exact on all 6 frames. See
42153+ // [`intra_rect4_in_inter_gate`] for the pin and the flag control arm.
42089 fn a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact() {42154 fn a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact() {
42090 intra_rect4_in_inter_gate(8);42155 intra_rect4_in_inter_gate(8);
42091 }42156 }
42092 42157
42093 /// The 10-bit arm (both of the user's films are `yuv420p10le`).42158 /// The 10-bit arm (both of the user's films are `yuv420p10le`).
42094 #[test]42159 #[test]
42095- // r1 `#[ignore]`d this gate on "every stream with an intra 1:4 strip also42160+ // CLOSED by lane-av1recipehunt r1 (un-ignored), same recipe and same two
42096- // hits the inter rect-strip refusal". r2 merged main 18bf7dc (lane-r1442161+ // reasons as the 8-bit arm above: lane-av1pins' RELEASE re-run showed the
42097- // a2e2e29 lifts exactly that refusal) and re-ran it: 3 of 40 attempts42162+ // pixel blocker gone and the recipe never firing, and the root cause is
42098- // decode whole and reach the pixel compare (0 before), one firing42163+ // `--min-partition-size=32` plus the pruned intra mode set, not the
42099- // 64x16=4 16x64=3 -- and the compare FAILED on an unowned inter-frame42164+ // mandelbrot source. The 10-bit cell fires 32x8=12 8x32=7 and is
42100- // defect (mandelbrot 192x128, luma ~3.7-4.5k samples on frames 3/442165+ // pixel-exact on all 6 frames.
42101- // drifting to ~24k, max |d| ~220 on frames 5-7).
42102- //
42103- // lane-av1pins RE-RAN this gate in RELEASE on a21f3680 (the seven-lane
42104- // merged tree) and BOTH halves of that r2 record are now stale:
42105- // * THE PIXEL BLOCKER IS GONE. The gate's own tally reads
42106- // `counted-exact=0 uncounted-exact=40 named-refusals=0 (attempts 40)`
42107- // at both bit depths, and there is NOT ONE mismatch line anywhere in
42108- // the full run log -- no frame 3/4 luma counts, no max |d|, no drift.
42109- // 40/40 streams now compare pixel-exact. (The 10-bit arm is identical:
42110- // same 40/40, same zero-mismatch log.)
42111- // * THE RECIPE NO LONGER FIRES THE FEATURE. Every one of the 42
42112- // counted attempts reads `64x16=0 16x64=0 32x8=0 8x32=0`. The gate has
42113- // regressed from r2's "fires sometimes, compare fails" to "never
42114- // fires", so the assertion now trips on its non-vacuity precondition
42115- // (stream.rs:40653) rather than on any pixel.
42116- // So the reason these gates stay `#[ignore]`d is the RECIPE, exactly as
42117- // the `#[ignore]` string says -- NOT the mandelbrot defect, which the
42118- // string never claimed and which is no longer reproducing. Kept ignored
42119- // rather than un-ignored: a source whose baseline is exact AND that fires
42120- // a 32-level intra 1:4 strip in an inter frame still does not exist.
42121- // (Corrected 2026-09-29: the comment above previously recorded the r2
42122- // state and would have had a reader re-filing these as blocked on the
42123- // mandelbrot defect, which is wrong on this tree.)
42124- #[ignore = "gate recipe never fires the feature (40/40 streams pixel-exact); needs a recipe that produces a 32-level intra 1:4 strip in an inter frame -- class gate-blind-to-feature"]
42125 fn a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact_10bit() {42166 fn a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact_10bit() {
42126 intra_rect4_in_inter_gate(10);42167 intra_rect4_in_inter_gate(10);
42127 }42168 }
42128 42169
42170+ /// The one recipe both 1:4-in-inter arms run, rewritten by
42171+ /// lane-av1recipehunt. What changed, and why the old sweep could not fire:
42172+ ///
42173+ /// * `--min-partition-size=32` -> **`8`**. This is the flag that was
42174+ /// holding the shape off the menu entirely. MEASURED over 96 encodes
42175+ /// (10-bit, 192x128 and 256x192, `--cpu-used` 0..5, cq 63/55, this
42176+ /// crate's full intra mode set): at `mps=16` the 32-level 1:4 counter is
42177+ /// **0 in all 48 attempts**, at `mps=8` it fires in 40 of 48. The old
42178+ /// comment's "min size 16 so the 16x16-level 1:4 is out of reach" was
42179+ /// protecting against a refusal that no longer fires -- `mps=8` reaches
42180+ /// the 8- and 16-level strips too, and on this content the RD takes
42181+ /// neither (the `inter16_1to4` and `rect4_32` inter counters confirm the
42182+ /// only 1:4 partitions in the stream are the 32-level ones this gate
42183+ /// asserts).
42184+ /// * the intra mode set: `--enable-smooth-intra/paeth-intra/
42185+ /// directional-intra/angle-delta` `0` -> **`1`**. A 8x32 or 32x8 strip
42186+ /// has four usable intra modes with these on; with them off the only
42187+ /// candidate is DC, and DC never wins a 1:4 strip against inter.
42188+ /// * the 40-attempt content/preset/cq seed sweep -> one pinned cell at
42189+ /// 256x192, 6 frames, `--cpu-used=2 --cq-level=63`. A sweep hides a
42190+ /// recipe that works; a pin makes it a precondition.
42191+ ///
42192+ /// The 8-bit arm's `hue=s=0` and `-t 0.32` are dropped: they only fixed
42193+ /// ffmpeg's own frame count across the sweep, and the frame count is now
42194+ /// pinned by `-frames:v 6` (6 decode-order frames, `kf-min-dist=1000`, so
42195+ /// frame 0 is the only key frame and every counted strip is in an INTER
42196+ /// frame).
42197+ ///
42198+ /// **The recipe**, exactly (the recorded command lines):
42199+ /// ```text
42200+ /// ffmpeg -v error -y -f lavfi \
42201+ /// -i mandelbrot=size=256x192:start_scale=5.0:end_scale=0.004:end_pts=8:rate=25 \
42202+ /// -pix_fmt yuv420p -frames:v 6 -f yuv4mpegpipe - # 10-bit: yuv420p10le + -strict -1
42203+ /// aomenc [--cpu-used=2 --input-bit-depth=10 -b 10] --codec=av1 --passes=1 --end-usage=q \
42204+ /// --cpu-used=2 --cq-level=63 --threads=1 --row-mt=0 \
42205+ /// --enable-rect-partitions=1 --enable-1to4-partitions=1 \
42206+ /// --min-partition-size=8 --max-partition-size=64 --enable-tx-size-search=0 \
42207+ /// --enable-filter-intra=1 --enable-intra-edge-filter=1 --enable-smooth-intra=1 \
42208+ /// --enable-paeth-intra=1 --enable-directional-intra=1 --enable-angle-delta=1 \
42209+ /// --lag-in-frames=0 --auto-alt-ref=0 --kf-min-dist=1000 --kf-max-dist=1000 \
42210+ /// --enable-order-hint=0 --enable-warped-motion=0 --enable-obmc=0 \
42211+ /// --enable-masked-comp=0 --enable-interintra-comp=0 --enable-dist-wtd-comp=0 \
42212+ /// --enable-diff-wtd-comp=0 --enable-onesided-comp=0 --enable-interintra-wedge=0 \
42213+ /// --enable-smooth-interintra=0 --enable-ab-partitions=0 --enable-cdef=0 \
42214+ /// --enable-restoration=0 --enable-palette=0 --enable-intrabc=0 \
42215+ /// --enable-cfl-intra=0 --enable-ref-frame-mvs=0 --obu -o - -
42216+ /// ```
42217+ /// Sources: 8-bit 442462 bytes, sha256
42218+ /// `e4b46799b180a0d3e138caa18b2738c035e349219490313db664814a3eae9ec2`;
42219+ /// 10-bit 884828 bytes, sha256
42220+ /// `b7e0602e0bfc7a7f6813f40bb3989ec7574e5fbbfbf190298b9ab5b625156030`.
42221+ /// Outputs, committed with `git add -f` past the `fixtures` gitignore:
42222+ /// * `fixtures/intra14_256x192_8bit.obu`, 35179 bytes, sha256
42223+ /// `5e50eb6d4492e806a2803988d92bd47f069ca54e02c06344d5500c6b72deb861`
42224+ /// (fnv1a64 `0x86f8d1e5a221162a`) -- MEASURED `32x8=8 8x32=11`,
42225+ /// `64x16=0 16x64=0`, all 6 frames pixel-exact vs ffmpeg.
42226+ /// * `fixtures/intra14_256x192_10bit.obu`, 34727 bytes, sha256
42227+ /// `ab6fae0a256af6410e8200f10827a3e965dee7b2d7ab63710e94968bddab23a2`
42228+ /// (fnv1a64 `0xecf9455bc20d60f0`) -- MEASURED `32x8=12 8x32=7`,
42229+ /// all 6 frames pixel-exact vs ffmpeg.
42230+ ///
42231+ /// The gate re-encodes live and byte-compares against the pin, so the pin
42232+ /// is the expected output and not a second decode path. The control arm
42233+ /// re-runs the SAME command line with `--enable-1to4-partitions=0` and
42234+ /// requires the counter to stay at 0 -- that single flag is what carries
42235+ /// the coverage, and asserting it is also this gate's own red-proof.
42129 fn intra_rect4_in_inter_gate(bit_depth: u32) {42236 fn intra_rect4_in_inter_gate(bit_depth: u32) {
42130 const NAME: &str =42237 const NAME: &str =
42131 "a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact";42238 "a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact";
42239+ let _gate_lock = lock_gate_counters();
42132 if !have_ffmpeg() {42240 if !have_ffmpeg() {
42133 eprintln!("SKIP {NAME}: no ffmpeg");42241 eprintln!("SKIP {NAME}: no ffmpeg");
42134 return;42242 return;
@@ -42137,250 +42245,232 @@ pub(crate) mod tests {
42137 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());42245 eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
42138 return;42246 return;
42139 }42247 }
42140- let (width, height, frame_count) = (192usize, 128usize, 8usize);42248+ let (width, height, frame_count) = (256usize, 192usize, 6usize);
42141- let mut refusals: Vec<String> = Vec::new();42249+ let (src_len, src_sha, pin_name, pin_len, pin_fnv) = if bit_depth == 10 {
42142- let mut uncounted_exact = 0u32;42250+ (
42143- let mut compared = 0u32;42251+ 884_828usize,
42144- let mut shapes = [0usize; 4];42252+ "b7e0602e0bfc7a7f6813f40bb3989ec7574e5fbbfbf190298b9ab5b625156030",
42145- for attempt in 0..40u32 {42253+ "fixtures/intra14_256x192_10bit.obu",
42146- let seed = 42 + attempt;42254+ 34_727usize,
42147- // Same source class as the 2:1 sibling gate: a FAST mandelbrot42255+ 0xecf9_455b_c20d_60f0u64,
42148- // zoom (`end_scale`/`end_pts`) so consecutive frames share almost42256+ )
42149- // no content and aomenc's RD codes blocks INTRA inside INTER42257+ } else {
42150- // frames, with `--kf-min-dist=1000` forbidding a new key frame.42258+ (
42151- let source = format!(42259+ 442_462usize,
42152- "mandelbrot=size={width}x{height}:start_scale={}:end_scale=0.004:end_pts=8:rate=25",42260+ "e4b46799b180a0d3e138caa18b2738c035e349219490313db664814a3eae9ec2",
42153- 5.0 - f64::from(attempt) * 0.0642261+ "fixtures/intra14_256x192_8bit.obu",
42154- );42262+ 35_179usize,
42155- let y4m = Command::new("ffmpeg")42263+ 0x86f8_d1e5_a221_162au64,
42156- .args([42264+ )
42157- "-v",42265+ };
42158- "error",42266+ let mut source_args: Vec<&str> = vec![
42159- "-f",42267+ "-v",
42160- "lavfi",42268+ "error",
42161- "-i",42269+ "-y",
42162- &source,42270+ "-f",
42163- "-vf",42271+ "lavfi",
42164- "hue=s=0",42272+ "-i",
42165- "-pix_fmt",42273+ "mandelbrot=size=256x192:start_scale=5.0:end_scale=0.004:end_pts=8:rate=25",
42166- if bit_depth == 10 {42274+ "-pix_fmt",
42167- "yuv420p10le"42275+ ];
42168- } else {42276+ source_args.push(if bit_depth == 10 {
42169- "yuv420p"42277+ "yuv420p10le"
42170- },42278+ } else {
42171- "-strict",42279+ "yuv420p"
42172- "-1",42280+ });
42173- "-t",42281+ source_args.extend(["-frames:v", "6"]);
42174- "0.32",42282+ if bit_depth == 10 {
42175- "-f",42283+ // yuv420p10le is not an official yuv4mpegpipe format on this ffmpeg
42176- "yuv4mpegpipe",42284+ source_args.extend(["-strict", "-1"]);
42177- "-strict",42285+ }
42178- "-1",42286+ source_args.extend(["-f", "yuv4mpegpipe", "-"]);
42179- "-",42287+ let y4m = Command::new("ffmpeg")
42180- ])42288+ .args(&source_args)
42181- .stdin(Stdio::null())42289+ .stdin(Stdio::null())
42182- .stdout(Stdio::piped())42290+ .stdout(Stdio::piped())
42183- .stderr(Stdio::piped())42291+ .stderr(Stdio::piped())
42184- .output()42292+ .output()
42185- .expect("ffmpeg failed to run");42293+ .expect("ffmpeg failed to run");
42186- assert!(42294+ assert!(
42187- y4m.status.success(),42295+ y4m.status.success(),
42188- "ffmpeg fixture: {}",42296+ "ffmpeg fixture: {}",
42189- String::from_utf8_lossy(&y4m.stderr)42297+ String::from_utf8_lossy(&y4m.stderr)
42190- );42298+ );
42191- let depth_args: &[&str] = if bit_depth == 10 {42299+ assert_eq!(
42192- &["-b", "10", "--input-bit-depth=10"]42300+ y4m.stdout.len(),
42193- } else {42301+ src_len,
42194- &[]42302+ "{NAME} ({bit_depth}-bit): the mandelbrot source is not the pinned 6-frame y4m -- \
42195- };42303+ `rate=`, `end_pts` and `-frames:v` are all part of this recipe's identity"
42196- // MEASURED (r1, 40 attempts): `--cpu-used=0` makes aomenc pick42304+ );
42197- // 128x128 superblocks on this frame size, which decode_stream42305+ eprintln!("{NAME} ({bit_depth}-bit): source y4m sha256 {src_sha}");
42198- // refuses by name, so the preset sweep starts at 1.42306+ let mut args: Vec<&str> = Vec::new();
42199- let cpu = format!("--cpu-used={}", 1 + attempt % 4);42307+ if bit_depth == 10 {
42200- // The higher the quantiser the more 1:4 intra strips inside inter42308+ args.extend(["-b", "10", "--input-bit-depth=10"]);
42201- // frames, so the sweep walks cq 63 first.42309+ }
42202- let cq = format!(42310+ // Every flag spelled exactly once (class [[aomenc-last-flag-wins]]).
42203- "--cq-level={}",42311+ args.extend([
42204- [63u32, 55, 45, 35][(attempt / 4) as usize % 4]42312+ "--codec=av1",
42205- );42313+ "--passes=1",
42206- let out = run_with_stdin(42314+ "--end-usage=q",
42207- Command::new(aomenc_path())42315+ "--cpu-used=2",
42208- .args(depth_args)42316+ "--cq-level=63",
42209- .arg(&cpu)42317+ "--threads=1",
42210- .arg(&cq)42318+ "--row-mt=0",
42211- .args([42319+ "--enable-rect-partitions=1",
42212- // Every flag spelled exactly once (class42320+ // The feature this gate is about, and the flag the control arm
42213- // [[aomenc-last-flag-wins]]). These are what the gate is42321+ // below reverts.
42214- // about: 1:4 partitions ON, min size 16 so the 16x16-level42322+ "--enable-1to4-partitions=1",
42215- // 1:4 (refused elsewhere) is out of reach.42323+ // 8, not 16 or 32: MEASURED, the 32-level 1:4 counter is 0 in all
42216- "--enable-rect-partitions=1",42324+ // 48 attempts at 16 and fires in 40 of 48 at 8.
42217- "--enable-1to4-partitions=1",42325+ "--min-partition-size=8",
42218- // MEASURED (r1): at `--min-partition-size=16` aomenc codes42326+ "--max-partition-size=64",
42219- // 16x16-level 1:4 partitions (16x4/4x16 strips), which the42327+ "--enable-tx-size-search=0",
42220- // inter partition path refuses by name (another lane's42328+ // A 1:4 strip needs an intra mode worth coding: with these four
42221- // surface) in 12/40 attempts. 32 keeps this gate's two42329+ // off the only candidate is DC and it never wins.
42222- // reachable levels -- the 32-level 32x8/8x32 and the42330+ "--enable-filter-intra=1",
42223- // superblock-level 64x16/16x64 -- and nothing else.42331+ "--enable-intra-edge-filter=1",
42224- "--min-partition-size=32",42332+ "--enable-smooth-intra=1",
42225- "--max-partition-size=64",42333+ "--enable-paeth-intra=1",
42226- // MEASURED (r1): with tx-size search ON, 8/40 attempts stop42334+ "--enable-directional-intra=1",
42227- // at the 2:1 strip's own split-tx refusal (merge-cross-product,42335+ "--enable-angle-delta=1",
42228- // another lane's surface) before a 1:4 strip is reached.42336+ // Single reference and one key frame, so every counted strip is
42229- "--enable-tx-size-search=0",42337+ // inside an INTER frame.
42230- "--enable-filter-intra=1",42338+ "--lag-in-frames=0",
42231- "--enable-intra-edge-filter=1",42339+ "--auto-alt-ref=0",
42232- "--codec=av1",42340+ "--kf-min-dist=1000",
42233- "--passes=1",42341+ "--kf-max-dist=1000",
42234- "--end-usage=q",42342+ "--enable-order-hint=0",
42235- "--lag-in-frames=0",42343+ "--enable-warped-motion=0",
42236- "--auto-alt-ref=0",42344+ "--enable-obmc=0",
42237- "--kf-min-dist=1000",42345+ "--enable-masked-comp=0",
42238- "--kf-max-dist=1000",42346+ "--enable-interintra-comp=0",
42239- "--threads=1",42347+ "--enable-dist-wtd-comp=0",
42240- "--row-mt=0",42348+ "--enable-diff-wtd-comp=0",
42241- "--enable-order-hint=0",42349+ "--enable-onesided-comp=0",
42242- "--enable-warped-motion=0",42350+ "--enable-interintra-wedge=0",
42243- "--enable-obmc=0",42351+ "--enable-smooth-interintra=0",
42244- "--enable-masked-comp=0",42352+ "--enable-ab-partitions=0",
42245- "--enable-interintra-comp=0",42353+ "--enable-cdef=0",
42246- "--enable-dist-wtd-comp=0",42354+ "--enable-restoration=0",
42247- "--enable-diff-wtd-comp=0",42355+ // Ledger dead-end (lane-r14): a NEW gate spelling
42248- "--enable-onesided-comp=0",42356+ // `--enable-cfl-intra=1` retires that tool from
42249- "--enable-interintra-wedge=0",42357+ // `NEVER_EXERCISED_8BIT` on the flag alone while no CfL
42250- "--enable-smooth-interintra=0",42358+ // hit counter exists to assert -- so it stays 0 here.
42251- "--enable-ab-partitions=0",42359+ // Palette stays 0 for the same class of reason: this arm
42252- "--enable-smooth-intra=0",42360+ // refuses a screen-content frame whole, so a palette flag
42253- "--enable-paeth-intra=0",42361+ // would buy no coverage.
42254- "--enable-directional-intra=0",42362+ "--enable-palette=0",
42255- "--enable-angle-delta=0",42363+ "--enable-intrabc=0",
42256- "--enable-cdef=0",42364+ "--enable-cfl-intra=0",
42257- "--enable-restoration=0",42365+ "--enable-ref-frame-mvs=0",
42258- // Ledger dead-end (lane-r14): a NEW gate spelling42366+ "--obu",
42259- // `--enable-cfl-intra=1` retires that tool from42367+ "-o",
42260- // `NEVER_EXERCISED_8BIT` on the flag alone while no CfL42368+ "-",
42261- // hit counter exists to assert -- so it stays 0 here.42369+ "-",
42262- // Palette stays 0 for the same class of reason: this arm42370+ ]);
42263- // refuses a screen-content frame whole, so a palette flag42371+ let out = run_with_stdin(Command::new(aomenc_path()).args(&args), &y4m.stdout);
42264- // would buy no coverage.42372+ assert!(
42265- "--enable-palette=0",42373+ out.status.success(),
42266- "--enable-intrabc=0",42374+ "aomenc refused the fixture: {}",
42267- "--enable-cfl-intra=0",42375+ String::from_utf8_lossy(&out.stderr)
42268- "--enable-ref-frame-mvs=0",42376+ );
42269- "--obu",42377+ let stream = out.stdout;
42270- "-o",42378+ assert_eq!(
42271- "-",42379+ stream.len(),
42272- "-",42380+ pin_len,
42273- ]),42381+ "{NAME} ({bit_depth}-bit): encoded size moved"
42274- &y4m.stdout,42382+ );
42275- );42383+ assert_eq!(
42276- assert!(42384+ fnv1a64(&stream),
42277- out.status.success(),42385+ pin_fnv,
42278- "aomenc refused the fixture: {}",42386+ "{NAME} ({bit_depth}-bit): encoded bytes moved"
42279- String::from_utf8_lossy(&out.stderr)42387+ );
42280- );42388+ let pin = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(pin_name);
42281- let stream = out.stdout;42389+ assert_eq!(
42282- let before: Vec<usize> = (0..4)42390+ std::fs::read(&pin).unwrap_or_else(|e| panic!("{pin_name} must be committed: {e}")),
42283- .map(decode::intra_rect4_strip_in_inter_hits)42391+ stream,
42284- .collect();42392+ "{NAME} ({bit_depth}-bit): the live encode no longer matches the committed pin"
42285- let frames = match decode_stream(&stream) {42393+ );
42286- Ok(frames) => frames,42394+
42287- Err(e) => {42395+ let before: Vec<usize> = (0..4)
42288- let msg = e.to_string();42396+ .map(decode::intra_rect4_strip_in_inter_hits)
42289- assert!(42397+ .collect();
42290- msg.contains("unsupported"),42398+ let frames = decode_stream(&stream)
42291- "intra-1:4-in-inter decode failed outright (seed {seed}): {msg}"42399+ .unwrap_or_else(|e| panic!("{NAME} ({bit_depth}-bit): the pin must decode: {e}"));
42400+ let delta: Vec<usize> = (0..4)
42401+ .map(|k| decode::intra_rect4_strip_in_inter_hits(k) - before[k])
42402+ .collect();
42403+ let ffmpeg_frames = if bit_depth == 10 {
42404+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
42405+ } else {
42406+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
42407+ };
42408+ assert_eq!(frames.len(), frame_count);
42409+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
42410+ for (plane, (g, w)) in [
42411+ ("Y", (&got.y, &want.y)),
42412+ ("U", (&got.u, &want.u)),
42413+ ("V", (&got.v, &want.v)),
42414+ ] {
42415+ let stride = if plane == "Y" { width } else { width / 2 };
42416+ if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) {
42417+ eprintln!(
42418+ "{NAME} ({bit_depth}-bit): frame {i} {plane} first diff at ({}, {})",
42419+ at % stride,
42420+ at / stride
42292 );42421 );
42293- refusals.push(format!("seed {seed} {cpu} {cq}: {msg}"));
42294- continue;
42295- }
42296- };
42297- let delta: Vec<usize> = (0..4)
42298- .map(|k| decode::intra_rect4_strip_in_inter_hits(k) - before[k])
42299- .collect();
42300- let ffmpeg_frames = if bit_depth == 10 {
42301- ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
42302- } else {
42303- ffmpeg_decode_sequence(&stream, width, height, frame_count)
42304- };
42305- assert_eq!(frames.len(), frame_count);
42306- eprintln!(
42307- "intra14 gate {bit_depth}-bit seed={seed} {cpu} {cq}: intra 1:4 strips in inter \
42308- frames 64x16={} 16x64={} 32x8={} 8x32={}",
42309- delta[0], delta[1], delta[2], delta[3]
42310- );
42311- for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
42312- for (plane, (g, w)) in [
42313- ("Y", (&got.y, &want.y)),
42314- ("U", (&got.u, &want.u)),
42315- ("V", (&got.v, &want.v)),
42316- ] {
42317- let stride = if plane == "Y" { width } else { width / 2 };
42318- if let Some(at) = g.iter().zip(w.iter()).position(|(a, b)| a != b) {
42319- let maxd = g
42320- .iter()
42321- .zip(w.iter())
42322- .map(|(a, b)| i32::from(*a).abs_diff(i32::from(*b)))
42323- .max()
42324- .unwrap_or(0);
42325- eprintln!(
42326- "intra14 gate {bit_depth}-bit seed={seed}: frame {i} {plane} first \
42327- diff at ({}, {}) got {} want {} ({} samples differ, max |d|={maxd})",
42328- at % stride,
42329- at / stride,
42330- g[at],
42331- w[at],
42332- g.iter().zip(w.iter()).filter(|(a, b)| a != b).count(),
42333- );
42334- }
42335- assert_eq!(g, w, "{plane} vs ffmpeg (seed {seed}, frame {i})");
42336 }42422 }
42337- }42423+ assert_eq!(g, w, "{plane} vs ffmpeg (frame {i})");
42338- compared += 1;
42339- if delta.iter().all(|d| *d == 0) {
42340- uncounted_exact += 1;
42341- refusals.push(format!(
42342- "seed {seed} {cpu} {cq}: decoded and pixel-compared, but no intra 1:4 strip on \
42343- the inter path"
42344- ));
42345- }
42346- for k in 0..4 {
42347- shapes[k] += delta[k];
42348- }
42349- // Both LEVELS (32 and 64) is the bar; orientation is whichever the
42350- // encoder picks.
42351- if shapes[0] + shapes[1] > 0 && shapes[2] + shapes[3] > 0 {
42352- break;
42353 }42424 }
42354 }42425 }
42355- gate_buckets(
42356- NAME,
42357- compared - uncounted_exact,
42358- uncounted_exact,
42359- refusals.len() - uncounted_exact as usize,
42360- );
42361- eprintln!(
42362- "{NAME} ({bit_depth}-bit): compared {compared} streams, intra 1:4 strips in inter \
42363- frames: 64x16={} 16x64={} 32x8={} 8x32={}; refusals:\n{}",
42364- shapes[0],
42365- shapes[1],
42366- shapes[2],
42367- shapes[3],
42368- refusals.join("\n")
42369- );
42370 assert!(42426 assert!(
42371- compared > 0,42427+ delta[2] + delta[3] > 0,
42372- "{NAME} ({bit_depth}-bit): every attempt hit a named refusal -- nothing was \42428+ "{NAME} ({bit_depth}-bit): {frame_count} frames pixel-exact but no 32-level intra 1:4 \
42373- pixel-compared:\n{}",42429+ strip (32x8/8x32) fired (64x16={} 16x64={} 32x8={} 8x32={}) -- the recipe stopped \
42374- refusals.join("\n")42430+ producing the shape this gate names (class gate-blind-to-feature)",
42431+ delta[0],
42432+ delta[1],
42433+ delta[2],
42434+ delta[3]
42375 );42435 );
42436+
42437+ // The control arm: the one flag that is this gate's feature, reverted.
42438+ // If it ever fires too, 1:4 is no longer what puts these strips on the
42439+ // RD menu and the feature arm above is not the witness it claims to be.
42440+ // It is also this gate's own red-proof.
42441+ let mut control = args.clone();
42442+ let at = control
42443+ .iter()
42444+ .position(|a| *a == "--enable-1to4-partitions=1")
42445+ .expect("the feature flag is in the recipe");
42446+ control[at] = "--enable-1to4-partitions=0";
42447+ let ctl = run_with_stdin(Command::new(aomenc_path()).args(&control), &y4m.stdout);
42376 assert!(42448 assert!(
42377- shapes[2] + shapes[3] > 0,42449+ ctl.status.success(),
42378- "{NAME} ({bit_depth}-bit): no 32-level intra 1:4 strip (32x8/8x32) fired over \42450+ "aomenc refused the --enable-1to4-partitions=0 control: {}",
42379- {compared} compared streams (64x16={} 16x64={} 32x8={} 8x32={})",42451+ String::from_utf8_lossy(&ctl.stderr)
42380- shapes[0],42452+ );
42381- shapes[1],42453+ let ctl_before: Vec<usize> = (0..4)
42382- shapes[2],42454+ .map(decode::intra_rect4_strip_in_inter_hits)
42383- shapes[3]42455+ .collect();
42456+ decode_stream(&ctl.stdout)
42457+ .unwrap_or_else(|e| panic!("{NAME}: the control stream must decode too: {e}"));
42458+ let ctl_delta: Vec<usize> = (0..4)
42459+ .map(|k| decode::intra_rect4_strip_in_inter_hits(k) - ctl_before[k])
42460+ .collect();
42461+ assert_eq!(
42462+ ctl_delta, [0; 4],
42463+ "{NAME} ({bit_depth}-bit): the --enable-1to4-partitions=0 control fired \
42464+ 64x16={} 16x64={} 32x8={} 8x32={} -- 1:4 partitions are no longer what produce these \
42465+ strips, so the feature arm above is not witnessing what it names",
42466+ ctl_delta[0], ctl_delta[1], ctl_delta[2], ctl_delta[3]
42467+ );
42468+ gate_buckets(NAME, 1, 0, 0);
42469+ eprintln!(
42470+ "{NAME} ({bit_depth}-bit): {frame_count} frames pixel-exact, intra 1:4 strips in inter \
42471+ frames 64x16={} 16x64={} 32x8={} 8x32={} (--enable-1to4-partitions=0 control: \
42472+ 0/0/0/0), stream {pin_len} B fnv1a64={pin_fnv:016x}",
42473+ delta[0], delta[1], delta[2], delta[3]
42384 );42474 );
42385 }42475 }
42386 42476
crates/ec-av1/src/tile.rsmodified+30 -38
@@ -12,16 +12,16 @@
12 use std::cell::RefCell;12 use std::cell::RefCell;
13 #[cfg(test)]13 #[cfg(test)]
14 use std::collections::BTreeMap;14 use std::collections::BTreeMap;
15-use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
16 use std::sync::LazyLock;15 use std::sync::LazyLock;
16+use std::sync::atomic::{AtomicU64, AtomicUsize, Ordering};
17 17
18 use ec_core::{Error, Result};18 use ec_core::{Error, Result};
19 19
20 use crate::cdf;20 use crate::cdf;
21 use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables};21 use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables};
22-use crate::decode::{txfm_partition_ctx_rect, TXFM_CTX_INIT};22+use crate::decode::{TXFM_CTX_INIT, txfm_partition_ctx_rect};
23 use crate::msac::SymbolEncoder;23 use crate::msac::SymbolEncoder;
24-use crate::mvstack::{find_mv_stack, mv16, MiGrid, MiInfo, NO_REF1};24+use crate::mvstack::{MiGrid, MiInfo, NO_REF1, find_mv_stack, mv16};
25 use crate::transform::TxType;25 use crate::transform::TxType;
26 26
27 // ---------------------------------------------------------------------------27 // ---------------------------------------------------------------------------
@@ -1637,10 +1637,10 @@ fn write_compound_ref_frames(
1637 (ref0, ref1): (i8, i8),1637 (ref0, ref1): (i8, i8),
1638 ) -> Result<()> {1638 ) -> Result<()> {
1639 use crate::mvstack::{1639 use crate::mvstack::{
1640- comp_reference_type_ctx, single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx,1640+ ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME,
1641- single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, uni_comp_ref_p1_ctx,1641+ LAST3_FRAME, comp_reference_type_ctx, single_ref_p1_ctx, single_ref_p2_ctx,
1642- ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME,1642+ single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx,
1643- LAST_FRAME,1643+ uni_comp_ref_p1_ctx,
1644 };1644 };
1645 let a = (above_ref > 0).then_some(above_ref);1645 let a = (above_ref > 0).then_some(above_ref);
1646 let l = (left_ref > 0).then_some(left_ref);1646 let l = (left_ref > 0).then_some(left_ref);
@@ -1819,7 +1819,10 @@ fn write_compound_block(
1819 if crate::envflags::env_flag!("EC_TRACE_MODE") {1819 if crate::envflags::env_flag!("EC_TRACE_MODE") {
1820 eprintln!(1820 eprintln!(
1821 "EC_WCOMP mi_row={mi_row} mi_col={mi_col} mode={mode} ref0={} ref1={ref1} ctx={ctx} new_mv_ctx={} ref_mv_ctx={} stack={}",1821 "EC_WCOMP mi_row={mi_row} mi_col={mi_col} mode={mode} ref0={} ref1={ref1} ctx={ctx} new_mv_ctx={} ref_mv_ctx={} stack={}",
1822- info.ref_frame, stack.new_mv_ctx, stack.ref_mv_ctx, stack.entries.len()1822+ info.ref_frame,
1823+ stack.new_mv_ctx,
1824+ stack.ref_mv_ctx,
1825+ stack.entries.len()
1823 );1826 );
1824 }1827 }
1825 enc.symbol(mode, &mut cdfs.inter_compound_mode[ctx]);1828 enc.symbol(mode, &mut cdfs.inter_compound_mode[ctx]);
@@ -5889,7 +5892,7 @@ fn scan_of(side: usize) -> &'static Vec<u16> {
5889 /// DECODER's own table so the two cannot drift, cached per size and class.5892 /// DECODER's own table so the two cannot drift, cached per size and class.
5890 fn class_scan_of(side: usize, class: crate::decode::TxClass) -> &'static [u16] {5893 fn class_scan_of(side: usize, class: crate::decode::TxClass) -> &'static [u16] {
5891 static SCANS: LazyLock<[[Vec<u16>; 2]; 4]> = LazyLock::new(|| {5894 static SCANS: LazyLock<[[Vec<u16>; 2]; 4]> = LazyLock::new(|| {
5892- use crate::decode::{class_scan_table, TxClass};5895+ use crate::decode::{TxClass, class_scan_table};
5893 [TX4, TX8, TX16, TX32].map(|side| {5896 [TX4, TX8, TX16, TX32].map(|side| {
5894 [5897 [
5895 class_scan_table(side, TxClass::Horiz),5898 class_scan_table(side, TxClass::Horiz),
@@ -6966,11 +6969,7 @@ pub(crate) fn intra_inter_ctx(
6966 /// `CLASS0_SIZE << (class + 2)` (spec 3), the magnitude an `MV_CLASS_n`6969 /// `CLASS0_SIZE << (class + 2)` (spec 3), the magnitude an `MV_CLASS_n`
6967 /// component's own bits start counting from; class zero starts at zero.6970 /// component's own bits start counting from; class zero starts at zero.
6968 fn mv_class_base(class: usize) -> i32 {6971 fn mv_class_base(class: usize) -> i32 {
6969- if class == 0 {6972+ if class == 0 { 0 } else { 2i32 << (class + 2) }
6970- 0
6971- } else {
6972- 2i32 << (class + 2)
6973- }
6974 }6973 }
6975 6974
6976 /// The class a pre-offset magnitude `z` (`|diff| - 1`) falls in — the inverse6975 /// The class a pre-offset magnitude `z` (`|diff| - 1`) falls in — the inverse
@@ -7096,9 +7095,9 @@ fn write_single_ref(
7096 REF_HITS[(ref_frame.max(1) - 1) as usize % 7]7095 REF_HITS[(ref_frame.max(1) - 1) as usize % 7]
7097 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);7096 .fetch_add(1, std::sync::atomic::Ordering::Relaxed);
7098 use crate::mvstack::{7097 use crate::mvstack::{
7098+ ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME,
7099 single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx,7099 single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx,
7100- single_ref_p5_ctx, single_ref_p6_ctx, ALTREF2_FRAME, ALTREF_FRAME, BWDREF_FRAME,7100+ single_ref_p5_ctx, single_ref_p6_ctx,
7101- GOLDEN_FRAME, LAST2_FRAME, LAST3_FRAME,
7102 };7101 };
7103 let above = (above_ref > 0).then_some(above_ref);7102 let above = (above_ref > 0).then_some(above_ref);
7104 let left = (left_ref > 0).then_some(left_ref);7103 let left = (left_ref > 0).then_some(left_ref);
@@ -7196,10 +7195,15 @@ fn note_drl_clamp(target: usize, signalled: usize, entries: usize) {
7196 }7195 }
7197 }7196 }
7198 7197
7199-/// Takes and clears [`DRL_CLAMP_HITS`], for a gate's own before/after delta.7198+/// Reads [`DRL_CLAMP_HITS`] -- the tripwire for the DRL owner's fix. It is
7200-#[cfg(test)]7199+/// provably zero while `every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`
7201-pub(crate) fn take_drl_clamp_hits() -> usize {7200+/// (encode.rs) holds: the pricer never offers an index this walk cannot signal,
7202- DRL_CLAMP_HITS.swap(0, std::sync::atomic::Ordering::Relaxed)7201+/// so no clip can move it (lane-av1recipehunt, 153 attempts, plus a mutation
7202+/// proof that widening the pricer's offer set does). The clip gate that used
7203+/// to wait on it is deleted; this counter stays so that widening the pricer
7204+/// is loud instead of silent. `EC_AV1_TRACE=1` prints each hit.
7205+pub fn drl_clamp_hits() -> usize {
7206+ DRL_CLAMP_HITS.load(std::sync::atomic::Ordering::Relaxed)
7203 }7207 }
7204 7208
7205 fn note_inter_mode(mode: usize, drl: usize) {7209 fn note_inter_mode(mode: usize, drl: usize) {
@@ -7335,7 +7339,7 @@ fn write_inter_mode(
7335 enc.symbol(1, &mut cdfs.new_mv[stack.new_mv_ctx]); // not NEWMV7339 enc.symbol(1, &mut cdfs.new_mv[stack.new_mv_ctx]); // not NEWMV
7336 enc.symbol(1, &mut cdfs.zero_mv[stack.zero_mv_ctx]); // not GLOBALMV7340 enc.symbol(1, &mut cdfs.zero_mv[stack.zero_mv_ctx]); // not GLOBALMV
7337 enc.symbol(1, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // NEARMV7341 enc.symbol(1, &mut cdfs.ref_mv[stack.ref_mv_ctx]); // NEARMV
7338- // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24).7342+ // `RefMvIdx` starts at 1 for NEARMV (spec 5.11.24).
7339 let idx = idx.max(1);7343 let idx = idx.max(1);
7340 let signalled = write_drl_idx(enc, cdfs, stack, 1, idx);7344 let signalled = write_drl_idx(enc, cdfs, stack, 1, idx);
7341 let mv = stack.entries.get(signalled).map_or(stack.near_mv, |e| e.mv);7345 let mv = stack.entries.get(signalled).map_or(stack.near_mv, |e| e.mv);
@@ -8954,8 +8958,8 @@ mod tests {
8954 use crate::sequence::sequence_header_obu;8958 use crate::sequence::sequence_header_obu;
8955 use ec_av1_syntax::sequence::SequenceHeader;8959 use ec_av1_syntax::sequence::SequenceHeader;
8956 use ec_av1_syntax::{8960 use ec_av1_syntax::{
8957- FrameHeader, FrameType, LoopFilterParams, QuantizationParams, TileInfo, TxMode,8961+ FrameHeader, FrameType, LoopFilterParams, PRIMARY_REF_NONE, QuantizationParams, TileInfo,
8958- PRIMARY_REF_NONE,8962+ TxMode,
8959 };8963 };
8960 use std::process::{Command, Stdio};8964 use std::process::{Command, Stdio};
8961 8965
@@ -10594,11 +10598,7 @@ mod tests {
10594 .map(|&v| {10598 .map(|&v| {
10595 let m = f64::from(v).abs() + 0.5;10599 let m = f64::from(v).abs() + 0.5;
10596 let l = if m < 1.0 { 0 } else { m.floor() as i32 };10600 let l = if m < 1.0 { 0 } else { m.floor() as i32 };
10597- if v < 0.0 {10601+ if v < 0.0 { -l } else { l }
10598- -l
10599- } else {
10600- l
10601- }
10602 })10602 })
10603 .collect();10603 .collect();
10604 let before = levels.clone();10604 let before = levels.clone();
@@ -10657,11 +10657,7 @@ mod tests {
10657 .map(|&v| {10657 .map(|&v| {
10658 let m = f64::from(v).abs() + 0.5;10658 let m = f64::from(v).abs() + 0.5;
10659 let l = if m < 1.0 { 0 } else { m.floor() as i32 };10659 let l = if m < 1.0 { 0 } else { m.floor() as i32 };
10660- if v < 0.0 {10660+ if v < 0.0 { -l } else { l }
10661- -l
10662- } else {
10663- l
10664- }
10665 })10661 })
10666 .collect();10662 .collect();
10667 let bits = rdoq(10663 let bits = rdoq(
@@ -11158,11 +11154,7 @@ mod tests {
11158 (d << 3) | (fr << 1) | 111154 (d << 3) | (fr << 1) | 1
11159 };11155 };
11160 let mag = mv_class_base(class) + local as i32 + 1;11156 let mag = mv_class_base(class) + local as i32 + 1;
11161- if sign == 1 {11157+ if sign == 1 { -mag } else { mag }
11162- -mag
11163- } else {
11164- mag
11165- }
11166 }11158 }
11167 11159
11168 /// Decodes one superblock a [`sb_coeff_inter_frame_tile`] payload wrote,11160 /// Decodes one superblock a [`sb_coeff_inter_frame_tile`] payload wrote,
lanes/av1recipehunt.report.mdadded+550 -0
@@ -0,0 +1,550 @@
1+# lane-av1recipehunt report
2+
3+Three `#[ignore]`d ec-av1 gates whose RECIPE never provoked the feature. Two are
4+CLOSED with a pinned, red-proved fixture. One is UNPRODUCIBLE for a structural
5+reason that no recipe can move, proved by mutation.
6+
7+Branch `lane-av1recipehunt`, base `a21f3680`. Oracle
8+`~/.cache/aom-oracle/build/aomenc` (aom `v3.13.3-7-g9bb526a`), ffmpeg
9+`/usr/bin/ffmpeg`. Every number below was measured in RELEASE on this tree; the
10+row format is `recipe | parsed feature evidence | counter before | counter after
11+| pixel verdict`.
12+
13+Method: hunt deliberately from the code path out, not by random sweep. For each
14+gate, first read the DECODE-path counter that the gate's own precondition assert
15+consumes, then work out which encoder-side knob can move it, then sweep only
16+that knob. Reachability is asserted from the real read (`decode_probe` prints
17+each counter from the decode path; `enc_probe` prints the writer-side one), never
18+from a mirror call site, and every firing recipe is additionally pixel-compared.
19+
20+---
21+
22+## Gate 1 -- `a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact`
23+
24+**Verdict: UNPRODUCIBLE. The gate stays `#[ignore]`d.**
25+
26+### Baseline (run unmodified, RELEASE)
27+
28+```
29+thread 'encode::tests::a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact'
30+panicked at crates/ec-av1/src/encode.rs:19484:9:
31+this clip never asked for a drl index the write-time stack could not carry, so it cannot witness the defect
32+test result: FAILED. 0 passed; 1 failed; ... finished in 32.25s
33+```
34+
35+`assert!(clamps > 0)` with `clamps = crate::tile::take_drl_clamp_hits()` after
36+63.93 s (32.25 s here) of real encoding of mandelbrot 1280x768x12 at q 150 with
37+`force_sb128(true)`.
38+
39+### Why no recipe exists
40+
41+`DRL_CLAMP_HITS` is bumped by `tile::write_inter_mode` (and the two compound
42+walks) only when the SEARCH chose a `ref_mv_idx` the write-time stack could not
43+signal. On this tree the search's offer set is inside the signalable range in
44+every mode:
45+
46+| mode | search's offer set | writer's signalable ceiling | gap |
47+|---|---|---|---|
48+| `NEWMV` | `best_new_mv_syntax`, `for idx in 0..3` -> {0,1,2} | `write_drl_idx(..., start=0, ...)`: `idx < start + 2` -> 2 | none |
49+| `NEARMV` | `for idx in 1..=2` (both search arms) | `start=1`, `idx < 3`, plus `entries.len() > idx + 1` | none: the search offers `idx` only when `entries.get(idx).is_some()`, i.e. `entries.len() > idx`, and the walk stops one entry later -- the bounds coincide at every stack size |
50+| `NEARESTMV` / `GLOBALMV` | no DRL | n/a | n/a |
51+| compound (`write_compound_block`) | every compound `InterInfo` the search builds hardcodes `ref_mv_idx: 0` | walks start at 0/1 | none |
52+
53+This is not inference. The tree already ASSERTS it, over stack sizes 0..=4, in
54+`encode::tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`:
55+for every index either pricer offers, `tile::signalled_drl_idx(entries, start, idx)
56+== idx`. That test and this gate are two readings of one invariant, and it is
57+still green on this tree (verified). The counter this gate waits on can never
58+leave zero.
59+
60+### Attempt table -- 153 combinations, every one `drl_clamp = 0`
61+
62+Driven by `enc_probe` (`tile::drl_clamp_hits()` printed per encode point).
63+
64+| recipe | parsed feature evidence | clamps before | clamps after | pixel verdict |
65+|---|---|---|---|---|
66+| mandelbrot 320x192x8 q150 (the gate's own clip class, small) | search picks DRL idx 2 (35x, traced) | 0 | 0 | n/a (encode-side) |
67+| mandelbrot 640x384x8 q150 | search picks DRL idx 2 (163x, traced) | 0 | 0 | n/a |
68+| mandelbrot 640x384x12 q110 / q150 / q200 | idx 2 chosen | 0 | 0 | n/a |
69+| mandelbrot 1280x768x8 q110 / q150 / q200 (the gate's EXACT clip) | idx 2 chosen | 0 | 0 | n/a |
70+| mandelbrot 1280x768x12 q150 (the gate's exact point) | idx 2 chosen | 0 | 0 | n/a |
71+| testsrc2 320x192 / 640x384 / 1280x768 x 8/12, q 110/150/200 | idx 2 chosen (27x on 640x384) | 0 | 0 | n/a |
72+| white noise 320x192 / 640x384 x 8/12, q 60/110/150/200 | idx 0 only (drl_index histogram 108/0/0/0 -- the write-time stack never reaches 3 entries) | 0 | 0 | n/a |
73+| scrolling hard bands 320x192x8 | idx 0 only | 0 | 0 | n/a |
74+| 4x4 mandelbrot mosaic, per-tile independent drift, 320x192 / 640x384 x 8/12 | idx 2 chosen (35x) | 0 | 0 | n/a |
75+| 4-px luminance bands, both axes, 192x128, mps 8/16, cpu 0..6 | idx 2 chosen | 0 | 0 | n/a |
76+| panning field + a faster band inside it, 640x384x10/16, b=32/64, q 100/150/200 | idx 2 chosen | 0 | 0 | n/a |
77+| diagonal band on a pan, 640x384x10/16, b=32/64, q 100/150/200 | idx 2 chosen | 0 | 0 | n/a |
78+| three independently moving bands, 320x192x10/16, b=32/64, q 100/150/200 | idx 2 chosen | 0 | 0 | n/a |
79+| alternating hard 32x32 tiles (whole tiles re-predict from wherever the identical tile last was), 640x384x10, q 150 | idx 2 chosen | 0 | 0 | n/a |
80+| q ladder 60 / 150 / 220 on one clip (three encode points in a run) | idx 2 chosen | 0 | 0 / 0 / 0 | n/a |
81+
82+A trace on `best_new_mv_syntax` is the decisive negative: the search DOES choose
83+DRL index 2, often (163 times on mandelbrot 640x384x8). Index 2 is exactly what
84+the writer signals, so it is a legal pick, not a clamp. The instrument I built
85+for the hunt (`tile::drl_index_histogram`, reading `DRL_HITS`) was REMOVED before
86+commit: it records the SIGNALLED index, which is downstream of the clamp and
87+structurally cannot show 3+, so it cannot separate "the search never asked" from
88+"it asked and the stack could not carry it". Shipping it would have been a
89+misleading instrument.
90+
91+### Mutation proof -- the recipe was never the problem
92+
93+`best_new_mv_syntax`'s offer set widened `for idx in 0..3` -> `0..5`, i.e.
94+letting the search ask for index 3/4 that the 2-step walk cannot signal:
95+
96+| recipe (identical command line, only the offer set differs) | clamps |
97+|---|---|
98+| mandelbrot 640x384x8 q150 | **9** |
99+| mandelbrot 320x192x8 q150 | **2** |
100+| mandelbrot mosaic 320x192x8 q150 | **2** |
101+| testsrc2 640x384x8 q150 | **1** |
102+| white noise 320x192x8 q150 | 0 |
103+| alternating hard tiles 640x384x10 q150 | **1** |
104+| all of the above, mutation reverted | 0 |
105+
106+Same clips, same presets, only the pricer's offer ceiling moved. The binding
107+constraint is the ceiling, which no clip can move. Mutation reverted and
108+`git diff` on `encode.rs` is empty apart from this lane's doc comment.
109+
110+### Disposition
111+
112+`#[ignore]` kept -- un-ignoring it would ship a gate that can never pass. The
113+gate's doc comment now carries the whole finding (the per-mode table, the
114+existing invariant test that proves it, the 153-row measurement, the mutation
115+proof, and the owning fix) so the next lane does not repeat the sweep.
116+
117+**Owning fix, not this lane's to make** (the DRL code is another lane's surface,
118+and the DRL index range is the AV1 spec's, not ours): either widen the search's
119+offer set to the spec's own DRL range so the clamp becomes reachable and this
120+gate can witness it, or delete the three dead `note_drl_clamp` sites and this
121+gate with them. `deferred(unblock: DRL owner widens `best_new_mv_syntax`'s offer
122+set past the writer's `start + 2` ceiling, or retires the counter)`.
123+
124+---
125+
126+## Gate 2 -- `a_real_aomenc_stream_with_a_superblock_level_horz_vert_partition_and_delta_q_decodes_pixel_exact`
127+
128+**Verdict: CLOSED. Un-ignored, pinned, red-proved.**
129+
130+### Baseline (run unmodified, RELEASE)
131+
132+```
133+a_real_aomenc_stream_..._and_delta_q_decodes_pixel_exact: zero rect64 dequant calls
134+ever observed CURRENT_Q_IDX != base_q_idx (40 matches, 0 refusals out of 40) --
135+delta_q was never actually exercised through decode_block_rect64 this run
136+```
137+
138+### Root cause of the blindness
139+
140+r1 swept 40 attempts of `gradients` at 192x128 with `frame_count = 1`. That is a
141+single KEY frame, and it is the whole reason. `delta_q_present` needs the
142+temporal (TPL) model to see a spatial complexity map at all; a one-frame encode
143+has no inter frame to carry it. Measured over 120 sweep arms at 192x128 /
144+256x192 / 320x256 / 512x384, 4 and 10 frames, cpu 0/1/3, cq 45/55, five source
145+classes: at `frame_count = 1` EVERY arm read `delta_q_hits() == 0` AND
146+`rect64_qidx_drift_hits() == 0`. A different failure from "the drift never
147+reached a rect64 block", and the reason r1 could not see the feature at all.
148+
149+### The recipe that fires
150+
151+`testsrc2` 512x384, **4 frames**, `--cpu-used=0`, `delta_q` left at aomenc's
152+default. Exactly:
153+
154+```
155+ffmpeg -v error -y -f lavfi -i testsrc2=size=512x384:rate=25 \
156+ -pix_fmt yuv420p -frames:v 4 -f yuv4mpegpipe src512.y4m
157+aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=45 --cpu-used=0 \
158+ --threads=1 --row-mt=0 --sb-size=64 --enable-rect-partitions=1 \
159+ --enable-ab-partitions=0 --enable-1to4-partitions=0 \
160+ --min-partition-size=32 --max-partition-size=64 \
161+ --enable-restoration=0 --enable-palette=0 --enable-cdef=0 \
162+ --enable-filter-intra=0 --enable-cfl-intra=0 --enable-intrabc=0 \
163+ --enable-tx-size-search=0 --obu -o out.obu src512.y4m
164+```
165+
166+* source `src512.y4m`: 1179730 bytes, sha256
167+ `f430d581497e4f6f7db07d0fc92476e92194e1f96c321988ec0739d475cbbe0c`
168+* output `crates/ec-av1/fixtures/rect64_dq_drift.obu`: **8384 bytes**, sha256
169+ `094e51bb21b6caccc905417e95a03f9131b448071567d0b14ec8850799ea2501`, fnv1a64
170+ `0x3d91a21680063ef6` (committed with `git add -f` past the `fixtures`
171+ gitignore, like every sibling fixture)
172+
173+### Attempt table (representative; the sweep was 120 arms)
174+
175+| recipe | parsed feature evidence | drift before | drift after | pixel verdict |
176+|---|---|---|---|---|
177+| testsrc2 512x384 **1 frame** cpu0 q45 (r1's shape) | `delta_q_present` absent, 0 groups | 0 | 0 | n/a (no feature) |
178+| testsrc2 512x384 4 frames cpu0 q45 | 48 `delta_q` groups; `inter_rect: 64x32=2 32x64=2` | 0 | **17** | **EXACT** all 4 frames |
179+| testsrc2 512x384 10 frames cpu0 q45 | 134 groups | 0 | 16 | EXACT |
180+| testsrc2 256x192 4 frames cpu0 q45 | 12 groups | 0 | 6 | EXACT |
181+| testsrc2 256x192 10 frames cpu0 q45 | 55 groups | 0 | 6 | EXACT |
182+| testsrc2 192x128 4 frames cpu0 q45 | 6 groups | 0 | 2 | EXACT |
183+| testsrc2 192x128 10 frames cpu0 q45 | 30 groups | 0 | 2 | EXACT |
184+| grad42 512x384 4 / 10 frames cpu0 q45 | 48 / 68 groups | 0 | 8 / 15 | EXACT |
185+| grad43 512x384 4 / 10 frames cpu0 q45 | 48 / 76 groups | 0 | 4 / 17 | EXACT |
186+| smptebars 512x384 4 / 10 frames cpu0 q45 | 48 groups | 0 | 6 / 5 | EXACT |
187+| **same source, `--cpu-used=1`** | 48-134 groups | 0 | **0** | EXACT |
188+| **same source, `--cpu-used=3`** | 48-138 groups | 0 | **0** | EXACT |
189+| **same source, `--deltaq-mode=0` (control)** | **0 groups** | 0 | **0** | EXACT |
190+| same source, `--cq-level=55` | 48 groups | 0 | 17 | EXACT (byte-identical to cq 45) |
191+| a "zone"/checkerboard source, every size and preset | 0 groups | 0 | 0 | EXACT (no delta_q at all) |
192+| smptebars / zone at `--cq-level=30` and `55` | 0 groups | 0 | 0 | EXACT |
193+
194+`--cpu-used=0` is load-bearing and measured: at `--cpu-used=1` and `3` the same
195+source reads the same 48 `delta_q` groups and drifts ZERO times -- the faster
196+presets' RD never leaves a rect64 root in a superblock whose quantizer moved.
197+`--cq-level` is not load-bearing.
198+
199+Note for whoever reads the census: a 192x128 SINGLE-frame testsrc2 at cpu 0 is
200+NOT pixel-exact on this tree (2177 differing bytes), and so is the 25-frame
201+512x384 one (2190). That is a pre-existing intra-frame defect, unrelated to
202+`delta_q` (the `--deltaq-mode=0` arm at the same size shows the same count), and
203+it is why the recipe uses a 4-frame 512x384 cell rather than either of those.
204+
205+### Red-proof
206+
207+The gate's own control arm re-runs the same command line with `--deltaq-mode=0`
208+and requires the drift to stay at 0. Run explicitly, by reverting the
209+feature-bearing flag INTO the feature arm (and relaxing the byte pin so the
210+precondition is what fires, not the byte identity):
211+
212+```
213+thread 'stream::tests::a_real_aomenc_stream_..._and_delta_q_decodes_pixel_exact'
214+panicked at crates/ec-av1/src/stream.rs:37752:9:
215+...: 4 frames pixel-exact but zero rect64 dequant calls ever saw CURRENT_Q_IDX !=
216+base_q_idx -- delta_q was read and never moved the quantizer inside a rect64 block,
217+so this run proved nothing (class gate-blind-to-feature)
218+test result: FAILED. 0 passed; 1 failed
219+```
220+
221+The pixel compare passed in that run; only the precondition went red. Both
222+temporary edits reverted; green again immediately after.
223+
224+### Green
225+
226+```
227+...: 4 frames pixel-exact, sb_rect_hits=40, rect64_qidx_drift_hits=17
228+(--deltaq-mode=0 control: 0), stream 8384 B fnv1a64=3d91a21680063ef6
229+test result: ok. 1 passed
230+```
231+
232+Runtime 1.7 s (r1's 40-arm sweep was the 60 s+ version).
233+
234+---
235+
236+## Gate 3 -- `a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact` (+ `_10bit`)
237+
238+**Verdict: CLOSED, both arms. Un-ignored, pinned, red-proved.**
239+
240+### Baseline (run unmodified, RELEASE, both arms)
241+
242+```
243+a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact: no 32-level
244+intra 1:4 strip (32x8/8x32) fired over 40 compared streams (64x16=0 16x64=0 32x8=0 8x32=0)
245+```
246+Same text for the `_10bit` arm. 40/40 streams pixel-compared, zero mismatches.
247+
248+### Root cause of the blindness, and the stale comment
249+
250+The 22-line comment above the `#[ignore]` blamed a pre-existing inter-frame
251+pixel defect (frames 3-7 drifting to ~24k samples, max |d| ~220). **That is
252+stale: the pixel blocker cleared.** What actually kept the gate blind is a
253+second, purely mechanical fact the comment never mentions -- and its own
254+conclusion ("the 1:4 shape is not the discriminator either") was measuring the
255+wrong arm:
256+
257+* `--min-partition-size=32` with an all-but-empty intra mode set
258+ (`--enable-smooth-intra/paeth-intra/directional-intra/angle-delta` all `0`)
259+ never puts a 1:4 partition on aomenc's RD menu at all. Measured: at
260+ `--min-partition-size=16` the 32-level 1:4 counter is **0 in all 48** attempts
261+ (10-bit, 192x128 and 256x192, `--cpu-used` 0..5, cq 63/55); at
262+ `--min-partition-size=8` with the intra mode tools on it fires in **40 of 48**.
263+* A 32x8/8x32 strip needs an intra mode worth coding. With the four tools off
264+ the only candidate is DC, and DC never wins a 1:4 strip against inter.
265+
266+So both the old `--min-partition-size=32` (protecting against a 16x4/4x16
267+refusal that no longer fires -- at `mps=8` the RD takes neither the 8- nor the
268+16-level 1:4 on this content, confirmed by the `inter16_1to4` and `rect4_32`
269+inter counters staying at 0) and the four intra-mode flags were holding the
270+shape off the menu. r2's `--enable-1to4-partitions=0` "byte-identical stream"
271+observation is explained by the same thing: with no 1:4 partitions reachable at
272+all, the flag had nothing to turn off.
273+
274+### The recipe that fires
275+
276+mandelbrot zoom, **256x192, 6 frames**, `--cpu-used=2 --cq-level=63`,
277+`--min-partition-size=8`, the full intra mode set. Exactly:
278+
279+```
280+ffmpeg -v error -y -f lavfi \
281+ -i mandelbrot=size=256x192:start_scale=5.0:end_scale=0.004:end_pts=8:rate=25 \
282+ -pix_fmt yuv420p -frames:v 6 -f yuv4mpegpipe - # 10-bit: yuv420p10le + -strict -1
283+aomenc [--cpu-used=2 --input-bit-depth=10 -b 10] --codec=av1 --passes=1 --end-usage=q \
284+ --cpu-used=2 --cq-level=63 --threads=1 --row-mt=0 \
285+ --enable-rect-partitions=1 --enable-1to4-partitions=1 \
286+ --min-partition-size=8 --max-partition-size=64 --enable-tx-size-search=0 \
287+ --enable-filter-intra=1 --enable-intra-edge-filter=1 --enable-smooth-intra=1 \
288+ --enable-paeth-intra=1 --enable-directional-intra=1 --enable-angle-delta=1 \
289+ --lag-in-frames=0 --auto-alt-ref=0 --kf-min-dist=1000 --kf-max-dist=1000 \
290+ --enable-order-hint=0 --enable-warped-motion=0 --enable-obmc=0 \
291+ --enable-masked-comp=0 --enable-interintra-comp=0 --enable-dist-wtd-comp=0 \
292+ --enable-diff-wtd-comp=0 --enable-onesided-comp=0 --enable-interintra-wedge=0 \
293+ --enable-smooth-interintra=0 --enable-ab-partitions=0 --enable-cdef=0 \
294+ --enable-restoration=0 --enable-palette=0 --enable-intrabc=0 \
295+ --enable-cfl-intra=0 --enable-ref-frame-mvs=0 --obu -o - -
296+```
297+
298+* 8-bit source: 442462 bytes, sha256 `e4b46799b180a0d3e138caa18b2738c035e349219490313db664814a3eae9ec2`
299+* 10-bit source: 884828 bytes, sha256 `b7e0602e0bfc7a7f6813f40bb3989ec7574e5fbbfbf190298b9ab5b625156030`
300+* `crates/ec-av1/fixtures/intra14_256x192_8bit.obu`: **35179 bytes**, sha256
301+ `5e50eb6d4492e806a2803988d92bd47f069ca54e02c06344d5500c6b72deb861`, fnv1a64
302+ `0x86f8d1e5a221162a`
303+* `crates/ec-av1/fixtures/intra14_256x192_10bit.obu`: **34727 bytes**, sha256
304+ `ab6fae0a256af6410e8200f10827a3e965dee7b2d7ab63710e94968bddab23a2`, fnv1a64
305+ `0xecf9455bc20d60f0`
306+
307+### Attempt table (grid v2: 576 arms, 0 hits; grid v3: 2520 streams carrying SOME 1:4, 54 hits)
308+
309+| recipe | parsed feature evidence | 64x16 / 16x64 / 32x8 / 8x32 | pixel verdict |
310+|---|---|---|---|
311+| **grid v2, the gate's own recipe** (mandelbrot 192x128x8, zoom `start_scale` 3.0/4.4/5.0, cq 63/55/45, cpu 1-4, flagsets `bare`/`intratools`/`screen`/`screen16`, 6 sources x 2 sizes) | NO 1:4 partition of any level in any stream -- `rect4_32`, `inter16_1to4` and `intra_rect4_in_inter` all 0 | 0/0/0/0 | EXACT on all 64 arms |
312+| banded 4-px content, STATIC in T, mps 8, cpu 0..6 | 241 B stream -- every inter frame SKIPs, no partitions at all | 0/0/0/0 | EXACT |
313+| 4-px bands that MOVE, mps 8, cpu 0 | `rect32x8_inter_tu: 32x8=1` -- a 32-level 1:4 strip, but INTER | 0/0/0/0 | EXACT |
314+| 4-px bands that move, mps 8, cpu 4 | `rect4_32: horz=4` / `vert=8` -- 1:4 again, INTER | 0/0/0/0 | EXACT |
315+| 4-px bands jumping 37/97/173 px per frame, mps 8/32, cq 63, cpu 0/2/4 | 1:4 present, INTER | 0/0/0/0 | EXACT |
316+| grid v2 with `--min-partition-size=8` and the intra tools ON, plain mandelbrot 192x128x6, cpu 2, cq 63 | **`intra_rect4_in_inter: 32x8=4 8x32=8`** | 0/0/**4**/**8** | **EXACT** |
317+| same, cpu 3, cq 63 | 32x8=4 8x32=8 | 0/0/4/8 | EXACT |
318+| same, cpu 2, cq 45 | 8x32=7 | 0/0/0/7 | EXACT |
319+| same, cpu 3, cq 45 | 8x32=10 | 0/0/0/10 | EXACT |
320+| 10-bit, 192x128, `--min-partition-size=8`, cpu 0, cq 63 | 32x8=4 8x32=11 | 0/0/4/11 | EXACT |
321+| **10-bit, 192x128, `--min-partition-size=16`, cpu 0..5, cq 63/55** (24 arms) | **ZERO 1:4 at any level** | 0/0/0/0 | EXACT |
322+| **10-bit, 256x192, `--min-partition-size=8`, cpu 0..5, cq 63/55** (24 arms) | fires at every preset 0-4, never at 5 | varies | EXACT |
323+| **`--enable-1to4-partitions=0` control, 8-bit** | `intra_rect4_in_inter` all 0, 20205 B vs 35179 B | 0/0/0/0 | EXACT |
324+| **CHOSEN: 8-bit 256x192x6 cpu2 q63 mps8** | 32x8=8 8x32=11 | 0/0/**8**/**11** | **EXACT** all 6 frames |
325+| **CHOSEN: 10-bit 256x192x6 cpu2 q63 mps8** | 32x8=12 8x32=7 | 0/0/**12**/**7** | **EXACT** all 6 frames |
326+
327+`--min-partition-size=8` vs `16` is the single load-bearing flag: 0/48 vs 40/48.
328+
329+One methodology note, recorded because it nearly cost the hunt: grid v3's
330+`scene-cut` source builder reused `[0:v]` for BOTH concat halves, so the
331+"second scene" argument had no effect and six nominally different rows produced
332+byte-identical results. The real driver was `mps=8` + the intra mode set, not the
333+scene cut. The chosen recipe is the plain source with no concat at all.
334+
335+### Red-proof
336+
337+The gate's own control arm re-runs the same command line with
338+`--enable-1to4-partitions=0` and requires all four counters to stay at 0. Run
339+explicitly, by reverting that flag INTO the feature arm (and relaxing the byte
340+pin so the precondition is what fires, not the byte identity):
341+
342+```
343+thread 'stream::tests::a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact'
344+panicked at crates/ec-av1/src/stream.rs:40677:9:
345+... (8-bit): 6 frames pixel-exact but no 32-level intra 1:4 strip (32x8/8x32) fired
346+(64x16=0 16x64=0 32x8=0 8x32=0) -- the recipe stopped producing the shape this gate names
347+(class gate-blind-to-feature)
348+test result: FAILED. 0 passed; 1 failed
349+```
350+
351+All 6 frames still compared pixel-exact in that run; only the precondition went
352+red. Both temporary edits reverted.
353+
354+### Green
355+
356+```
357+...(8-bit): 6 frames pixel-exact, intra 1:4 strips in inter frames 64x16=0 16x64=0 32x8=8 8x32=11 (--enable-1to4-partitions=0 control: 0/0/0/0), stream 35179 B fnv1a64=86f8d1e5a221162a
358+...(10-bit): 6 frames pixel-exact, intra 1:4 strips in inter frames 64x16=0 16x64=0 32x8=12 8x32=7 (--enable-1to4-partitions=0 control: 0/0/0/0), stream 34727 B fnv1a64=ecf9455bc20d60f0
359+test result: ok. 3 passed; 0 failed
360+```
361+
362+2.3 s and 2.1 s per arm (r1's 40-arm sweep was 60 s+ each).
363+
364+---
365+
366+## What changed in the tree
367+
368+* `stream.rs`: gate 2 and the two gate-3 arms rewritten around a pinned recipe
369+ with a byte pin (len + fnv1a64 + equality against the committed fixture), a
370+ hard precondition assert on the decode-path counter, a full pixel compare, and
371+ a feature-flag control arm. All three un-ignored. The stale 22-line comment on
372+ the 1:4 pair is replaced by the measurement that actually explains them.
373+* `encode.rs`: gate 1's doc comment now carries the structural finding, the
374+ existing invariant test that proves it, the 153-row measurement, the mutation
375+ proof and the owning fix. The gate and its `#[ignore]` are unchanged.
376+* `tile.rs`: `pub fn drl_clamp_hits()` -- a non-destructive read of
377+ `DRL_CLAMP_HITS` (the `#[cfg(test)]` `take_drl_clamp_hits` clears), so a
378+ recipe sweep can read the gate's own precondition from outside the test
379+ binary.
380+* `stream.rs`: `pub fn rect64_qidx_drift_counters() -> (usize, usize)` --
381+ `(delta_q groups read, rect64 dequant calls that saw CURRENT_Q_IDX !=
382+ base_q_idx)`. The pair is the point: a recipe that reads no `delta_q` at all
383+ and a recipe that reads it but never moves the quantizer inside a rect64 block
384+ are different failures, and gate 2 was the first of those.
385+* `examples/decode_probe.rs`: prints that pair.
386+* `examples/enc_probe.rs`: prints `tile::drl_clamp_hits()`.
387+* Three fixtures committed under `crates/ec-av1/fixtures/` with `git add -f`.
388+
389+## Hazards hit, worth the next lane's time
390+
391+* **A shared `CARGO_TARGET_DIR` is not safe for a probe-driven hunt.**
392+ `~/.cache/cargo-target` was overwritten mid-sweep by a sibling lane's build
393+ and the probe binary silently lost its new counter lines -- a sweep that reads
394+ counters can be measuring an instrument that no longer exists. Give each lane
395+ its own target dir (`~/.cache/cargo-target-<lane>`).
396+* **A counter placed downstream of the event it names is not an instrument.**
397+ The first thing built for gate 1 was a histogram of the DRL index each block
398+ *coded*, read off `DRL_HITS`. It records the SIGNALLED index, so it is
399+ structurally incapable of showing the 3+ bucket and cannot distinguish "the
400+ search never asked" from "it asked and could not be carried". It was removed
401+ rather than shipped. The trace that did work was on the SEARCH's choice
402+ (`best_new_mv_syntax`), upstream of the writer.
403+* **`cargo test` under `scripts/memguard-runner.sh` collides on transient
404+ systemd scopes** ("Unit run-pNNNN.scope was already loaded or has a fragment
405+ file") when runs overlap. It is a runner failure, not a test failure; retry.
406+* **A 10-bit pixel compare needs `EC_PROBE_OUT16`, not `EC_PROBE_OUT`.**
407+ `EC_PROBE_OUT` writes u8 and every sample then differs from ffmpeg's
408+ `yuv420p10le` raw -- a 220438-byte "defect" that is purely a dump-format
409+ mismatch.
410+
411+---
412+
413+# r2 -- gate 1 disposed of, and the three pins re-verified on merged main
414+
415+Base moved: rebased onto `aa0ac8c2` ("lanes: merge-wave-2 clean-checkout
416+census"), 58 commits past this lane's original `a21f3680`. One conflict, in the
417+two 1:4 gates' comment slot, and it is worth recording because **two lanes
418+reached the same two facts independently**: `lane-av1pins` had already re-run
419+both 1:4 gates in RELEASE on the seven-lane tree and recorded that the pixel
420+blocker was gone and the recipe never fired; this lane then found why and closed
421+them. Both records are kept side by side in the resolved comment rather than
422+either being dropped -- `lane-av1pins`' measurement is the merge-main evidence
423+that the stale mandelbrot-defect claim was dead, and this lane's is the
424+mechanism.
425+
426+## Gate 1: DELETED, and the coverage claim moved to where it is asserted
427+
428+**Decision: delete.** The evidence that decided it, in the order it was
429+gathered:
430+
431+1. **The precondition is unreachable**, not merely unprovoked -- established in
432+ r1 (per-mode offer-set table, the existing invariant test, 153 attempts, and
433+ the `0..3 -> 0..5` mutation proof).
434+2. **The pixel half is not unique to the gate.** The deleted test's second half
435+ -- decode the encoded stream and compare every frame/plane against the
436+ encoder's own reconstruction, on a 1280x768 `force_sb128(true)` sequence --
437+ is already made **four times over** at the same geometry by
438+ `a_128_superblock_clip_whose_root_search_codes_128x128_blocks_decodes_exact`,
439+ `a_128_root_block_with_a_real_residual_decodes_exact_through_both_decoders`,
440+ `a_128_root_residual_block_under_a_per_unit_cdef_list_decodes_exact` and
441+ `a_rect128_half_with_a_real_residual_decodes_exact_through_both_decoders`
442+ (all four verified: same `force_sb128(true)`, same own-reconstruction
443+ compare, same ffmpeg compare).
444+
445+So deletion loses no coverage on **either** half. That is the point on which
446+"delete vs keep" turned: had the pixel compare been unique, keeping the test
447+with a fact-stating ignore string would have been the honest call, because
448+`#[ignore]` is cheap and a deleted unique assertion is not recoverable from the
449+report. It was not unique, so the gate was pure dead weight in `--list`.
450+
451+**Why the surviving invariant test is strictly better coverage, not a
452+substitute.** It enumerates the pricer's whole offer set against
453+`signalled_drl_idx` for stack sizes 0..=4, and 0..=4 bounds the DOMAIN rather
454+than sampling it: `best_new_mv_syntax` breaks at `entries.len() <= idx` for
455+`idx > 0`, so indices 3 and 4 are unreachable at *any* stack size, and a stack
456+larger than 4 only adds entries neither pricer offers. A clip gate could only
457+ever have sampled that space; this test closes it.
458+
459+**Where the disposition is visible.** The cell is not tracked in
460+`gate_coverage.rs` or `refusal_inventory.rs` (grepped: no `drl_clamp`,
461+`sb128b` or `write_time_stack` entry in either), so the claim lives on the test
462+that now carries the coverage, at
463+**`crates/ec-av1/src/encode.rs:15689`**, in
464+`every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal`'s doc
465+comment. It names the deleted gate, both substitutes, the measurement and the
466+mutation proof. A second pointer was added at
467+**`crates/ec-av1/src/encode.rs:18618`** on the sb128 gate whose own doc had a
468+`cargo test` run-line still naming the deleted test -- a stale instruction left
469+by the deletion, caught by grepping for the name after the cut.
470+
471+### GENERAL RULE -- when a dead gate may be deleted, and when it may not
472+
473+> A gate whose precondition is unreachable is dead weight ONLY when BOTH of its
474+> halves are covered elsewhere. Here the pixel half is covered four times at
475+> the same geometry with the same own-reconstruction compare, and the
476+> precondition is covered by an invariant test that BOUNDS THE DOMAIN (stack
477+> sizes 0..=4) rather than sampling it -- `best_new_mv_syntax` breaks at
478+> `entries.len() <= idx`, so indices 3/4 are unreachable at any stack size.
479+> Had the pixel compare been unique, keeping the test with a fact-stating
480+> ignore string would have been the honest call; a deleted unique assertion is
481+> not recoverable from a report.
482+
483+The asymmetry is the whole rule. `#[ignore]` is nearly free -- a gate that
484+cannot fire is inert, and its doc comment still tells the next lane what was
485+tried. Deletion is not free and is not reversible from prose: once the function
486+is gone, the only surviving record of what it asserted is this report, and
487+nobody re-derives a coverage claim from a report. So the bar for deletion is
488+not "the assert cannot fire"; it is "the assert cannot fire AND everything
489+else the test did is provably done elsewhere". Check every other assertion in
490+the doomed test before cutting it, not just the one that is broken.
491+
492+### GENERAL RULE -- a deletion leaves references behind
493+
494+> Grep the name you removed, after you remove it.
495+
496+Cutting `a_128_superblock_clip_whose_drl_index_the_write_time_stack_cannot_carry_decodes_exact`
497+left a live `cargo test ... --nocapture` run-line in a sibling gate's doc
498+comment (`encode.rs:18619`) pointing at a test that no longer exists -- a
499+reviewer following it would get an empty run and a filter matching nothing,
500+with nothing in the output to say the gate had been retired on purpose. The
501+deletion looked complete because the symbol search came back with only the two
502+doc mentions I had written myself. It took grepping the bare name (not the
503+`fn` signature) to find the stale instruction. Same class as the other
504+doc-drift traps in this repo: a rename or removal is not done until the
505+prose points at what now exists.
506+
507+**What was deliberately NOT removed.** `note_drl_clamp` and `DRL_CLAMP_HITS`
508+stay. They are unreachable today, but they are the tripwire for the owning fix
509+(`deferred(unblock: the DRL owner widens `best_new_mv_syntax`'s offer set past
510+the writer's `start + 2` ceiling, or retires the counter)`): the invariant test
511+goes red the instant the offer set is widened, and `tile::drl_clamp_hits()`
512+(printed by `enc_probe`) then shows the clamp on real content. Deleting the
513+counter would have made the fix silent. The `#[cfg(test)]`
514+`take_drl_clamp_hits()` had no reader left and WAS removed -- the
515+non-destructive `drl_clamp_hits()` is the accessor that survives.
516+
517+## Re-verification of the three pins on merged main
518+
519+Run on the rebased tree at `aa0ac8c2` + this lane, RELEASE, **plain pass (no
520+`--ignored`)**, with a private `CARGO_TARGET_DIR=$HOME/.cache/cargo-target-rh`
521+and `touch` on the three edited sources first (the census/source-scan trap).
522+
523+```
524+test encode::tests::every_drl_index_the_new_mv_pricer_offers_is_one_the_writer_can_signal ... ok
525+a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact (8-bit): 6 frames
526+ pixel-exact, intra 1:4 strips in inter frames 64x16=0 16x64=0 32x8=8 8x32=11
527+ (--enable-1to4-partitions=0 control: 0/0/0/0), stream 35179 B fnv1a64=86f8d1e5a221162a
528+test stream::tests::a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact ... ok
529+a_real_aomenc_stream_..._horz_vert_partition_and_delta_q_decodes_pixel_exact: 4 frames
530+ pixel-exact, sb_rect_hits=40, rect64_qidx_drift_hits=17 (--deltaq-mode=0 control: 0),
531+ stream 8384 B fnv1a64=3d91a21680063ef6
532+test stream::tests::..._and_delta_q_decodes_pixel_exact ... ok
533+a_real_aomenc_inter_sequence_with_an_intra_1to4_strip_decodes_pixel_exact_10bit (10-bit):
534+ 6 frames pixel-exact, intra 1:4 strips in inter frames 64x16=0 16x64=0 32x8=12 8x32=7
535+ (--enable-1to4-partitions=0 control: 0/0/0/0), stream 34727 B fnv1a64=ecf9455bc20d60f0
536+test stream::tests::..._1to4_strip_decodes_pixel_exact_10bit ... ok
537+test result: ok. 4 passed; 0 failed; 0 ignored; 0 measured; 737 filtered out; finished in 4.71s
538+```
539+
540+* **`0 ignored`** -- the three gates now run in a plain pass, as they must once
541+ the recipes carry the coverage.
542+* Every pin byte-identical to r1 after the rebase onto 58 new commits:
543+ 8384 B / `3d91a21680063ef6`, 35179 B / `86f8d1e5a221162a`,
544+ 34727 B / `ecf9455bc20d60f0`. Wave 2 did not perturb aomenc's output on any
545+ of these three cells, which is the point of pinning.
546+* Each gate printed its self-evidencing line with the counter AND its control
547+ arm in the same line, so a reader can see from one line that the precondition
548+ fires and that the feature flag is what fires it.
549+* `cargo check --release -p ec-av1 --all-targets` clean on the rebased tree, no
550+ warnings.