forge
Explore
Log in

Don't you dare go Hollow

CDEF gate -- real aomenc stream, cdef_idx_hits hard-asserted

Browse files at this commit

24f08c282d011a47d6a042b431ddbefc9bf415c8Ahmet Kaan GümüşParent: 09db227
  • feat
    • CDEF gate -- real aomenc stream, cdef_idx_hits hard-asserted
Show full message
feat(av1): CDEF gate -- real aomenc stream, cdef_idx_hits hard-asserted

lane-realworld r2: verified bd61617's suite green (232/0), then wrote
a_real_aomenc_stream_with_cdef_decodes_pixel_exact. Multi-SB frame
required (single 64x64-SB fixtures the other gates use structurally
can never produce cdef_bits>0 -- nothing to differentiate); 128x64 (2
SBs) at --cpu-used=4 --aq-mode=0 --deltaq-mode=0 avoids two
pre-existing unrelated gaps this lane doesn't own: cpu-used=0 pushes
aomenc's RD into SB-level partition types (HORZ_4/VERT_B) this
decoder's intra part64 match doesn't cover, and cpu-used>=1's default
aq-mode writes delta_q/delta_lf (this lane's own next step).
cdef_idx_hits() hard-asserted > 0 (24-40 hits per run, matched
40/40 pixel-exact).
crates/ec-av1/src/stream.rsmodified+197 -0
@@ -4656,6 +4656,203 @@ mod tests {
46564656 );
46574657 }
46584658
4659+ /// lane-realworld r2: `read_cdef` (spec 5.11.56) ported -- per-superblock
4660+ /// `cdef_idx`, wired at all five `skip`-decode sites, `apply_cdef` looks
4661+ /// up strength through the grid instead of a hardcoded `[0]`. Structure
4662+ /// copied from `a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact`
4663+ /// but `--enable-cdef=1` (the one thing that gate turns off) and every
4664+ /// *other* filter/mode feature this lane doesn't touch disabled, so a
4665+ /// mismatch here can only be attributed to CDEF. `cdef_idx_hits()` is a
4666+ /// hard assert -- a run that never reads a real cdef_idx symbol proves
4667+ /// nothing (class `gate-blind-to-feature`).
4668+ #[test]
4669+ fn a_real_aomenc_stream_with_cdef_decodes_pixel_exact() {
4670+ const NAME: &str = "a_real_aomenc_stream_with_cdef_decodes_pixel_exact";
4671+ let _gate_lock = lock_gate_counters();
4672+ if !have_ffmpeg() {
4673+ eprintln!("SKIP {NAME}: no ffmpeg");
4674+ return;
4675+ }
4676+ if !have_aomenc() {
4677+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
4678+ return;
4679+ }
4680+ // cdef_bits selects among PER-SUPERBLOCK strengths -- a single-SB
4681+ // 64x64 frame (the other gates' size) gives aomenc nothing to
4682+ // differentiate, so it always writes bits=0 and cdef_idx is never
4683+ // read. 128x64 = 2 SBs is the minimum that lets aomenc's RD ever
4684+ // pick bits > 0. Multi-SB content at --cpu-used=0 (every other
4685+ // gate's setting) makes aomenc pick PARTITION_HORZ_4/VERT_B etc.
4686+ // at the top SB level regardless of the ab/1to4-partitions=0
4687+ // flags below (a real gap: this decoder's intra part64 match only
4688+ // covers NONE/SPLIT, and the inter path blindly assumes SPLIT --
4689+ // both pre-existing, out of this lane's scope); --cpu-used=4
4690+ // avoids that RD path entirely and needs --aq-mode=0
4691+ // --deltaq-mode=0 to keep delta_q/delta_lf (next lane step) off.
4692+ let (width, height, frame_count) = (128usize, 64usize, 24usize);
4693+ let mut named_refusals = 0u32;
4694+ let mut matched = 0u32;
4695+ let n_attempts: u32 = std::env::var("EC_CDEF_GATE_ATTEMPTS")
4696+ .ok()
4697+ .and_then(|s| s.parse().ok())
4698+ .unwrap_or(40);
4699+ for attempt in 0..n_attempts {
4700+ let seed = 42 + attempt;
4701+ let duration = frame_count as f64 / 25.0;
4702+ // mandelbrot's ringing-prone hard edges are what CDEF's RD
4703+ // search targets; flat gradients (charter's first guess) may
4704+ // never make aomenc choose cdef_bits > 0.
4705+ let source = format!(
4706+ "mandelbrot=size={width}x{height}:rate=25:start_x={sx}:start_y={sy}",
4707+ sx = -0.6 + 0.005 * (attempt as f64),
4708+ sy = -0.4 + 0.005 * (attempt as f64)
4709+ );
4710+ let y4m = Command::new("ffmpeg")
4711+ .args([
4712+ "-v",
4713+ "error",
4714+ "-f",
4715+ "lavfi",
4716+ "-i",
4717+ &source,
4718+ "-t",
4719+ &duration.to_string(),
4720+ "-pix_fmt",
4721+ "yuv420p",
4722+ "-f",
4723+ "yuv4mpegpipe",
4724+ "-",
4725+ ])
4726+ .stdin(Stdio::null())
4727+ .stdout(Stdio::piped())
4728+ .stderr(Stdio::piped())
4729+ .output()
4730+ .expect("ffmpeg failed to run");
4731+ assert!(
4732+ y4m.status.success(),
4733+ "ffmpeg fixture: {}",
4734+ String::from_utf8_lossy(&y4m.stderr)
4735+ );
4736+ let args: Vec<&str> = vec![
4737+ "--codec=av1",
4738+ "--passes=1",
4739+ "--end-usage=q",
4740+ "--cq-level=45",
4741+ "--cpu-used=4",
4742+ "--aq-mode=0",
4743+ "--deltaq-mode=0",
4744+ "--kf-max-dist=1000",
4745+ "--threads=1",
4746+ "--row-mt=0",
4747+ "--auto-alt-ref=1",
4748+ "--lag-in-frames=16",
4749+ "--enable-fwd-kf=0",
4750+ "--enable-order-hint=1",
4751+ // r2: a starved inter toolset (everything below off) pushes
4752+ // aomenc's RD toward exotic partition shapes (HORZ_4/VERT_B
4753+ // etc.) at the SB(64) level even with those partition
4754+ // flags off -- this decoder's part64 8/9/10-way arms and
4755+ // the inter path's blind SPLIT assumption don't cover that;
4756+ // keeping the same rich toolset the (working, ab/1to4-off)
4757+ // masked-compound gate uses avoids it.
4758+ "--enable-warped-motion=1",
4759+ "--enable-global-motion=0",
4760+ "--enable-obmc=1",
4761+ "--tune-content=default",
4762+ "--enable-masked-comp=1",
4763+ "--enable-dist-wtd-comp=0",
4764+ "--enable-interintra-comp=1",
4765+ "--enable-onesided-comp=0",
4766+ "--enable-interintra-wedge=0",
4767+ "--enable-smooth-interintra=1",
4768+ "--enable-rect-partitions=0",
4769+ "--enable-ab-partitions=0",
4770+ "--enable-1to4-partitions=0",
4771+ "--enable-filter-intra=0",
4772+ "--enable-smooth-intra=0",
4773+ "--enable-paeth-intra=0",
4774+ "--enable-directional-intra=0",
4775+ "--enable-angle-delta=0",
4776+ "--enable-tx-size-search=0",
4777+ "--enable-cdef=1",
4778+ "--enable-restoration=0",
4779+ "--max-partition-size=32",
4780+ "--min-partition-size=32",
4781+ "--enable-palette=0",
4782+ "--enable-intrabc=0",
4783+ "--enable-cfl-intra=0",
4784+ "--enable-ref-frame-mvs=0",
4785+ "--obu",
4786+ "-o",
4787+ "-",
4788+ "-",
4789+ ];
4790+ let mut child = Command::new(aomenc_path())
4791+ .args(&args)
4792+ .stdin(Stdio::piped())
4793+ .stdout(Stdio::piped())
4794+ .stderr(Stdio::piped())
4795+ .spawn()
4796+ .expect("aomenc failed to start");
4797+ child
4798+ .stdin
4799+ .take()
4800+ .expect("aomenc stdin")
4801+ .write_all(&y4m.stdout)
4802+ .expect("writing y4m to aomenc");
4803+ let out = child.wait_with_output().expect("aomenc failed to run");
4804+ assert!(
4805+ out.status.success(),
4806+ "aomenc refused the fixture: {}",
4807+ String::from_utf8_lossy(&out.stderr)
4808+ );
4809+ let stream = out.stdout;
4810+ let frames = match decode_stream(&stream) {
4811+ Err(e) => {
4812+ let msg = e.to_string();
4813+ assert!(
4814+ msg.contains("unsupported"),
4815+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
4816+ );
4817+ assert!(
4818+ !msg.contains("cdef"),
4819+ "{NAME} refused on cdef (seed {seed}) -- cdef_idx decode is ported: {msg}"
4820+ );
4821+ named_refusals += 1;
4822+ eprintln!("seed {seed} refusal: {msg}");
4823+ continue;
4824+ }
4825+ Ok(frames) => frames,
4826+ };
4827+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
4828+ assert_eq!(frames.len(), frame_count);
4829+ let mismatched = frames
4830+ .iter()
4831+ .zip(&ffmpeg_frames)
4832+ .any(|(got, want)| got.y != want.y || got.u != want.u || got.v != want.v);
4833+ if mismatched && let Ok(path) = std::env::var("EC_AV1_GATE_DUMP") {
4834+ std::fs::write(&path, &stream).expect("writing pinned stream");
4835+ eprintln!("EC_AV1_GATE_DUMP: wrote mismatching stream (seed {seed}) to {path}");
4836+ }
4837+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
4838+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})");
4839+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
4840+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
4841+ }
4842+ matched += 1;
4843+ }
4844+ assert!(
4845+ crate::decode::cdef_idx_hits() > 0,
4846+ "{NAME}: zero cdef_idx blocks fired ({matched} matches, {named_refusals} other \
4847+ refusals out of {n_attempts}) -- gate proved nothing this run"
4848+ );
4849+ eprintln!(
4850+ "{NAME}: {named_refusals} other-capability refusals, {matched} pixel-exact matches \
4851+ out of {n_attempts}, cdef_idx_hits={}",
4852+ crate::decode::cdef_idx_hits()
4853+ );
4854+ }
4855+
46594856 /// Pinned streams captured by `EC_AV1_GATE_DUMP` off
46604857 /// `a_real_aomenc_stream_with_warped_motion_refuses_or_matches` -- each
46614858 /// one is a former mismatch, kept as a regression pin (warp-mismatch: