forge
Explore
Log in

Don't you dare go Hollow

wip(part32): intra 32x32 AB arms (HORZ_A/HORZ_B/VERT_A/VERT_B) decode, gated 40/40 pixel-exact, all 4 hit counters fire

Browse files at this commit

6137e93e2b0aa21f406e6c6ac2b48436575e9124Ahmet Kaan GümüşParent: d21774e
crates/ec-av1/src/decode.rsmodified+327 -0
@@ -787,6 +787,38 @@ pub(crate) fn partab_hits() -> usize {
787 PARTAB_HITS.with(|c| c.get())787 PARTAB_HITS.with(|c| c.get())
788 }788 }
789 789
790+// lane-part32 r1: how many 32x32 quadrants decoded each INTRA AB/4-way arm,
791+// one counter per arm rather than one shared total -- the gate hard-asserts
792+// each of these individually nonzero so a recipe that only ever fires
793+// HORZ_A can't silently stand in for the whole set.
794+thread_local! {
795+ static INTRA_HORZ_A_HITS: std::cell::Cell<usize> =
796+ const { std::cell::Cell::new(0) };
797+ static INTRA_HORZ_B_HITS: std::cell::Cell<usize> =
798+ const { std::cell::Cell::new(0) };
799+ static INTRA_VERT_A_HITS: std::cell::Cell<usize> =
800+ const { std::cell::Cell::new(0) };
801+ static INTRA_VERT_B_HITS: std::cell::Cell<usize> =
802+ const { std::cell::Cell::new(0) };
803+}
804+
805+/// Current value of [`INTRA_HORZ_A_HITS`].
806+pub(crate) fn intra_horz_a_hits() -> usize {
807+ INTRA_HORZ_A_HITS.with(|c| c.get())
808+}
809+/// Current value of [`INTRA_HORZ_B_HITS`].
810+pub(crate) fn intra_horz_b_hits() -> usize {
811+ INTRA_HORZ_B_HITS.with(|c| c.get())
812+}
813+/// Current value of [`INTRA_VERT_A_HITS`].
814+pub(crate) fn intra_vert_a_hits() -> usize {
815+ INTRA_VERT_A_HITS.with(|c| c.get())
816+}
817+/// Current value of [`INTRA_VERT_B_HITS`].
818+pub(crate) fn intra_vert_b_hits() -> usize {
819+ INTRA_VERT_B_HITS.with(|c| c.get())
820+}
821+
790 // How many [`read_inter_compound_mode`] reads actually happened822 // How many [`read_inter_compound_mode`] reads actually happened
791 // (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own823 // (lane-av1comp) -- proves a `COMPOUND_REFERENCE` block reached its own
792 // `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound824 // `compound_mode` symbol (past `comp_mode`/`comp_ref` and the compound
@@ -7277,6 +7309,301 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
7277 tx_select,7309 tx_select,
7278 )?;7310 )?;
7279 }7311 }
7312+ PARTITION_HORZ_A => {
7313+ // lane-part32 r1: two 16x16 squares on top +
7314+ // a true 32x16 strip below (mirrors
7315+ // decode_inter_block's cd6cb6d HORZ_A: TL,
7316+ // TR, bottom strip).
7317+ INTRA_HORZ_A_HITS.with(|c| c.set(c.get() + 1));
7318+ decode_block(
7319+ &mut dec,
7320+ &mut cdfs,
7321+ &mut neighbours,
7322+ at32,
7323+ SUB,
7324+ TxbSet::Luma16,
7325+ TxbSet::Chroma8,
7326+ TX16,
7327+ TX8,
7328+ (&scan16, &scan8),
7329+ true,
7330+ &mut y,
7331+ &mut u,
7332+ &mut v,
7333+ base_q_idx,
7334+ enable_filter_intra,
7335+ allow_screen_content_tools,
7336+ allow_intrabc,
7337+ &scan32,
7338+ &scan16,
7339+ &scan8,
7340+ &scan4,
7341+ tx_select,
7342+ reduced_tx_set,
7343+ )?;
7344+ decode_block(
7345+ &mut dec,
7346+ &mut cdfs,
7347+ &mut neighbours,
7348+ (at32.0, at32.1 + 1),
7349+ SUB,
7350+ TxbSet::Luma16,
7351+ TxbSet::Chroma8,
7352+ TX16,
7353+ TX8,
7354+ (&scan16, &scan8),
7355+ true,
7356+ &mut y,
7357+ &mut u,
7358+ &mut v,
7359+ base_q_idx,
7360+ enable_filter_intra,
7361+ allow_screen_content_tools,
7362+ allow_intrabc,
7363+ &scan32,
7364+ &scan16,
7365+ &scan8,
7366+ &scan4,
7367+ tx_select,
7368+ reduced_tx_set,
7369+ )?;
7370+ decode_block_rect(
7371+ &mut dec,
7372+ &mut cdfs,
7373+ &mut neighbours,
7374+ (at32.0 + 1, at32.1),
7375+ 32,
7376+ 16,
7377+ &mut y,
7378+ &mut u,
7379+ &mut v,
7380+ enable_filter_intra,
7381+ allow_screen_content_tools,
7382+ base_q_idx,
7383+ tx_select,
7384+ )?;
7385+ }
7386+ PARTITION_HORZ_B => {
7387+ // lane-part32 r1: a true 32x16 strip on top +
7388+ // two 16x16 squares below (mirrors HORZ_A
7389+ // with the strip/squares order flipped, same
7390+ // shape as libaom decode_partition's HORZ_B).
7391+ INTRA_HORZ_B_HITS.with(|c| c.set(c.get() + 1));
7392+ decode_block_rect(
7393+ &mut dec,
7394+ &mut cdfs,
7395+ &mut neighbours,
7396+ at32,
7397+ 32,
7398+ 16,
7399+ &mut y,
7400+ &mut u,
7401+ &mut v,
7402+ enable_filter_intra,
7403+ allow_screen_content_tools,
7404+ base_q_idx,
7405+ tx_select,
7406+ )?;
7407+ decode_block(
7408+ &mut dec,
7409+ &mut cdfs,
7410+ &mut neighbours,
7411+ (at32.0 + 1, at32.1),
7412+ SUB,
7413+ TxbSet::Luma16,
7414+ TxbSet::Chroma8,
7415+ TX16,
7416+ TX8,
7417+ (&scan16, &scan8),
7418+ true,
7419+ &mut y,
7420+ &mut u,
7421+ &mut v,
7422+ base_q_idx,
7423+ enable_filter_intra,
7424+ allow_screen_content_tools,
7425+ allow_intrabc,
7426+ &scan32,
7427+ &scan16,
7428+ &scan8,
7429+ &scan4,
7430+ tx_select,
7431+ reduced_tx_set,
7432+ )?;
7433+ decode_block(
7434+ &mut dec,
7435+ &mut cdfs,
7436+ &mut neighbours,
7437+ (at32.0 + 1, at32.1 + 1),
7438+ SUB,
7439+ TxbSet::Luma16,
7440+ TxbSet::Chroma8,
7441+ TX16,
7442+ TX8,
7443+ (&scan16, &scan8),
7444+ true,
7445+ &mut y,
7446+ &mut u,
7447+ &mut v,
7448+ base_q_idx,
7449+ enable_filter_intra,
7450+ allow_screen_content_tools,
7451+ allow_intrabc,
7452+ &scan32,
7453+ &scan16,
7454+ &scan8,
7455+ &scan4,
7456+ tx_select,
7457+ reduced_tx_set,
7458+ )?;
7459+ }
7460+ PARTITION_VERT_A => {
7461+ // lane-part32 r1: mirror of HORZ_A with
7462+ // width/height swapped (TL, BL, right 16x32
7463+ // strip).
7464+ INTRA_VERT_A_HITS.with(|c| c.set(c.get() + 1));
7465+ decode_block(
7466+ &mut dec,
7467+ &mut cdfs,
7468+ &mut neighbours,
7469+ at32,
7470+ SUB,
7471+ TxbSet::Luma16,
7472+ TxbSet::Chroma8,
7473+ TX16,
7474+ TX8,
7475+ (&scan16, &scan8),
7476+ true,
7477+ &mut y,
7478+ &mut u,
7479+ &mut v,
7480+ base_q_idx,
7481+ enable_filter_intra,
7482+ allow_screen_content_tools,
7483+ allow_intrabc,
7484+ &scan32,
7485+ &scan16,
7486+ &scan8,
7487+ &scan4,
7488+ tx_select,
7489+ reduced_tx_set,
7490+ )?;
7491+ decode_block(
7492+ &mut dec,
7493+ &mut cdfs,
7494+ &mut neighbours,
7495+ (at32.0 + 1, at32.1),
7496+ SUB,
7497+ TxbSet::Luma16,
7498+ TxbSet::Chroma8,
7499+ TX16,
7500+ TX8,
7501+ (&scan16, &scan8),
7502+ true,
7503+ &mut y,
7504+ &mut u,
7505+ &mut v,
7506+ base_q_idx,
7507+ enable_filter_intra,
7508+ allow_screen_content_tools,
7509+ allow_intrabc,
7510+ &scan32,
7511+ &scan16,
7512+ &scan8,
7513+ &scan4,
7514+ tx_select,
7515+ reduced_tx_set,
7516+ )?;
7517+ decode_block_rect(
7518+ &mut dec,
7519+ &mut cdfs,
7520+ &mut neighbours,
7521+ (at32.0, at32.1 + 1),
7522+ 16,
7523+ 32,
7524+ &mut y,
7525+ &mut u,
7526+ &mut v,
7527+ enable_filter_intra,
7528+ allow_screen_content_tools,
7529+ base_q_idx,
7530+ tx_select,
7531+ )?;
7532+ }
7533+ PARTITION_VERT_B => {
7534+ // lane-part32 r1: a true 16x32 strip on the
7535+ // left + two 16x16 squares on the right
7536+ // (libaom decode_partition VERT_B: left
7537+ // strip, TR, BR).
7538+ INTRA_VERT_B_HITS.with(|c| c.set(c.get() + 1));
7539+ decode_block_rect(
7540+ &mut dec,
7541+ &mut cdfs,
7542+ &mut neighbours,
7543+ at32,
7544+ 16,
7545+ 32,
7546+ &mut y,
7547+ &mut u,
7548+ &mut v,
7549+ enable_filter_intra,
7550+ allow_screen_content_tools,
7551+ base_q_idx,
7552+ tx_select,
7553+ )?;
7554+ decode_block(
7555+ &mut dec,
7556+ &mut cdfs,
7557+ &mut neighbours,
7558+ (at32.0, at32.1 + 1),
7559+ SUB,
7560+ TxbSet::Luma16,
7561+ TxbSet::Chroma8,
7562+ TX16,
7563+ TX8,
7564+ (&scan16, &scan8),
7565+ true,
7566+ &mut y,
7567+ &mut u,
7568+ &mut v,
7569+ base_q_idx,
7570+ enable_filter_intra,
7571+ allow_screen_content_tools,
7572+ allow_intrabc,
7573+ &scan32,
7574+ &scan16,
7575+ &scan8,
7576+ &scan4,
7577+ tx_select,
7578+ reduced_tx_set,
7579+ )?;
7580+ decode_block(
7581+ &mut dec,
7582+ &mut cdfs,
7583+ &mut neighbours,
7584+ (at32.0 + 1, at32.1 + 1),
7585+ SUB,
7586+ TxbSet::Luma16,
7587+ TxbSet::Chroma8,
7588+ TX16,
7589+ TX8,
7590+ (&scan16, &scan8),
7591+ true,
7592+ &mut y,
7593+ &mut u,
7594+ &mut v,
7595+ base_q_idx,
7596+ enable_filter_intra,
7597+ allow_screen_content_tools,
7598+ allow_intrabc,
7599+ &scan32,
7600+ &scan16,
7601+ &scan8,
7602+ &scan4,
7603+ tx_select,
7604+ reduced_tx_set,
7605+ )?;
7606+ }
7280 _ => {7607 _ => {
7281 return Err(unsupported(format!(7608 return Err(unsupported(format!(
7282 "a 32x32 partition type this decoder does not code (value={part32})"7609 "a 32x32 partition type this decoder does not code (value={part32})"
crates/ec-av1/src/stream.rsmodified+179 -0
@@ -5728,6 +5728,185 @@ mod tests {
5728 );5728 );
5729 }5729 }
5730 5730
5731+ /// lane-part32 r1: an INTRA (key-frame-only) 32x32 quadrant that reads
5732+ /// PARTITION_HORZ_A/HORZ_B/VERT_A/VERT_B (values 4/5/6/7) must decode
5733+ /// pixel-exact, and each arm's own hit counter must fire -- mirrors
5734+ /// lane-partab's INTER AB gate (`a_real_aomenc_stream_with_ab_partitions_decodes_pixel_exact`)
5735+ /// almost verbatim (same bounds -- `--min-partition-size=16
5736+ /// --max-partition-size=32` keeps the split at or below 32x32 and out of
5737+ /// the still-unlanded SB(64)-level AB territory the sbpart gate found)
5738+ /// but single key frame, `--enable-ab-partitions=1`, and every intra
5739+ /// tool this decoder doesn't need for the AB shape itself
5740+ /// (filter-intra/smooth/paeth/directional/angle-delta/cfl/palette/
5741+ /// intrabc) off so an unrelated intra refusal never masks this one. The
5742+ /// four `value={4,5,6,7}` INTRA 32x32 refusal strings are FORBIDDEN once
5743+ /// this arm is reached; HORZ_4/VERT_4 (8/9) stay named refusals (out of
5744+ /// this round's scope).
5745+ #[test]
5746+ fn a_real_aomenc_intra_stream_with_ab_partitions_decodes_pixel_exact() {
5747+ const NAME: &str = "a_real_aomenc_intra_stream_with_ab_partitions_decodes_pixel_exact";
5748+ let _gate_lock = lock_gate_counters();
5749+ if !have_ffmpeg() {
5750+ eprintln!("SKIP {NAME}: no ffmpeg");
5751+ return;
5752+ }
5753+ if !have_aomenc() {
5754+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
5755+ return;
5756+ }
5757+ let (width, height, frame_count) = (64usize, 64usize, 1usize);
5758+ let mut named_refusals = 0u32;
5759+ let mut matched = 0u32;
5760+ let n_attempts: u32 = std::env::var("EC_PART32_GATE_ATTEMPTS")
5761+ .ok()
5762+ .and_then(|s| s.parse().ok())
5763+ .unwrap_or(40);
5764+ for attempt in 0..n_attempts {
5765+ let seed = 42 + attempt;
5766+ let source = format!(
5767+ "mandelbrot=size={width}x{height}:start_scale={}:rate=25",
5768+ 5.0 - f64::from(attempt) * 0.06
5769+ );
5770+ let y4m = Command::new("ffmpeg")
5771+ .args([
5772+ "-v",
5773+ "error",
5774+ "-f",
5775+ "lavfi",
5776+ "-i",
5777+ &source,
5778+ "-vf",
5779+ "hue=s=0",
5780+ "-pix_fmt",
5781+ "yuv420p",
5782+ "-t",
5783+ "0.04",
5784+ "-f",
5785+ "yuv4mpegpipe",
5786+ "-",
5787+ ])
5788+ .stdin(Stdio::null())
5789+ .stdout(Stdio::piped())
5790+ .stderr(Stdio::piped())
5791+ .output()
5792+ .expect("ffmpeg failed to run");
5793+ assert!(
5794+ y4m.status.success(),
5795+ "ffmpeg fixture: {}",
5796+ String::from_utf8_lossy(&y4m.stderr)
5797+ );
5798+ let args: Vec<&str> = vec![
5799+ "--codec=av1",
5800+ "--passes=1",
5801+ "--end-usage=q",
5802+ "--cq-level=45",
5803+ "--cpu-used=0",
5804+ "--kf-max-dist=0",
5805+ "--threads=1",
5806+ "--row-mt=0",
5807+ "--sb-size=64",
5808+ "--enable-rect-partitions=1",
5809+ "--enable-ab-partitions=1",
5810+ "--enable-1to4-partitions=0",
5811+ "--min-partition-size=16",
5812+ "--max-partition-size=32",
5813+ "--enable-filter-intra=0",
5814+ "--enable-smooth-intra=0",
5815+ "--enable-paeth-intra=0",
5816+ "--enable-directional-intra=0",
5817+ "--enable-angle-delta=0",
5818+ "--enable-tx-size-search=0",
5819+ "--enable-cdef=0",
5820+ "--enable-restoration=0",
5821+ "--enable-palette=0",
5822+ "--enable-intrabc=0",
5823+ "--enable-cfl-intra=0",
5824+ "--obu",
5825+ "-o",
5826+ "-",
5827+ "-",
5828+ ];
5829+ let mut child = Command::new(aomenc_path())
5830+ .args(&args)
5831+ .stdin(Stdio::piped())
5832+ .stdout(Stdio::piped())
5833+ .stderr(Stdio::piped())
5834+ .spawn()
5835+ .expect("aomenc failed to start");
5836+ child
5837+ .stdin
5838+ .take()
5839+ .expect("aomenc stdin")
5840+ .write_all(&y4m.stdout)
5841+ .expect("writing y4m to aomenc");
5842+ let out = child.wait_with_output().expect("aomenc failed to run");
5843+ assert!(
5844+ out.status.success(),
5845+ "aomenc refused the fixture: {}",
5846+ String::from_utf8_lossy(&out.stderr)
5847+ );
5848+ let stream = out.stdout;
5849+ let frames = match decode_stream(&stream) {
5850+ Err(e) => {
5851+ let msg = e.to_string();
5852+ assert!(
5853+ msg.contains("unsupported"),
5854+ "{NAME} failed outright, not a named refusal (seed {seed}): {msg}"
5855+ );
5856+ for v in [4, 5, 6, 7] {
5857+ assert!(
5858+ !msg.contains(&format!(
5859+ "a 32x32 partition type this decoder does not code (value={v})"
5860+ )),
5861+ "{NAME} refused an INTRA AB partition (value={v}, seed {seed}) -- \
5862+ all four AB arms are ported, this refusal is forbidden: {msg}"
5863+ );
5864+ }
5865+ named_refusals += 1;
5866+ eprintln!("seed {seed} refusal: {msg}");
5867+ continue;
5868+ }
5869+ Ok(frames) => frames,
5870+ };
5871+ let ffmpeg_frames = ffmpeg_decode_sequence(&stream, width, height, frame_count);
5872+ assert_eq!(frames.len(), frame_count);
5873+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
5874+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (seed {seed})");
5875+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (seed {seed})");
5876+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (seed {seed})");
5877+ }
5878+ matched += 1;
5879+ }
5880+ assert!(
5881+ matched > 0,
5882+ "{NAME}: every attempt refused; the gate never decoded a stream"
5883+ );
5884+ eprintln!(
5885+ "{NAME}: {named_refusals} named refusals, {matched} pixel-exact matches out of \
5886+ {n_attempts}, horz_a={} horz_b={} vert_a={} vert_b={}",
5887+ crate::decode::intra_horz_a_hits(),
5888+ crate::decode::intra_horz_b_hits(),
5889+ crate::decode::intra_vert_a_hits(),
5890+ crate::decode::intra_vert_b_hits(),
5891+ );
5892+ assert!(
5893+ crate::decode::intra_horz_a_hits() > 0,
5894+ "{NAME}: HORZ_A never fired across {n_attempts} attempts"
5895+ );
5896+ assert!(
5897+ crate::decode::intra_horz_b_hits() > 0,
5898+ "{NAME}: HORZ_B never fired across {n_attempts} attempts"
5899+ );
5900+ assert!(
5901+ crate::decode::intra_vert_a_hits() > 0,
5902+ "{NAME}: VERT_A never fired across {n_attempts} attempts"
5903+ );
5904+ assert!(
5905+ crate::decode::intra_vert_b_hits() > 0,
5906+ "{NAME}: VERT_B never fired across {n_attempts} attempts"
5907+ );
5908+ }
5909+
5731 /// lane-maskcomp r2 / lane-wedge r3: `--enable-masked-comp=1` streams5910 /// lane-maskcomp r2 / lane-wedge r3: `--enable-masked-comp=1` streams
5732 /// must consume `compound_type`/`wedge_idx`/`wedge_sign`/`mask_type`5911 /// must consume `compound_type`/`wedge_idx`/`wedge_sign`/`mask_type`
5733 /// entropy-exact AND build the real blend, DIFFWTD or WEDGE --5912 /// entropy-exact AND build the real blend, DIFFWTD or WEDGE --