forge
Explore
Log in

Don't you dare go Hollow

wip(sbrect10): r1 state

Browse files at this commit

94706bf9f28abff101cd231212ea8299c53e78ecAhmet Kaan GümüşParent: e122a2d
crates/ec-av1/src/decode.rsmodified+51 -4
@@ -1772,6 +1772,20 @@ pub(crate) fn wii_hits() -> usize {
1772 WII_HITS.with(|c| c.get())1772 WII_HITS.with(|c| c.get())
1773 }1773 }
1774 1774
1775+// lane-sbrect10 r1: how many INTRA blocks read `uv_mode` off the 13-symbol
1776+// NO-CFL alphabet *because their size excludes CFL* (libaom `is_cfl_allowed`:
1777+// wide <= 32 && high <= 32). The witness that a gate stream really carries a
1778+// 64-axis intra block -- the shape whose 14-symbol read desynced every inter
1779+// frame carrying one.
1780+thread_local! {
1781+ static NOCFL_UV_MODE_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
1782+}
1783+
1784+/// Current value of [`NOCFL_UV_MODE_HITS`].
1785+pub(crate) fn nocfl_uv_mode_hits() -> usize {
1786+ NOCFL_UV_MODE_HITS.with(|c| c.get())
1787+}
1788+
1775 // lane-inter4 r4: how many 16x8/8x16 INTER LEAVES actually ran the OBMC1789 // lane-inter4 r4: how many 16x8/8x16 INTER LEAVES actually ran the OBMC
1776 // blend -- the gate's proof that `--enable-obmc=1` reached this shape (the1790 // blend -- the gate's proof that `--enable-obmc=1` reached this shape (the
1777 // r3 refusal's replacement: prefilt frames are bit-exact vs an instrumented1791 // r3 refusal's replacement: prefilt frames are bit-exact vs an instrumented
@@ -5361,6 +5375,17 @@ fn read_intra_mode_rect(
5361 }5375 }
5362 };5376 };
5363 }5377 }
5378+ // lane-sbrect10 r1: libaom `is_cfl_allowed` (blockd.h) is
5379+ // `block_size_wide <= 32 && block_size_high <= 32` -- enforce it HERE, at
5380+ // the one point every rect caller routes through, so no call site can
5381+ // offer the 14-symbol CFL alphabet on a 64-axis block (class
5382+ // wrong-alphabet-same-value: same value, wrong interval, silent desync).
5383+ let cfl = if cfl && bw.max(bh) > 32 {
5384+ NOCFL_UV_MODE_HITS.with(|c| c.set(c.get() + 1));
5385+ false
5386+ } else {
5387+ cfl
5388+ };
5364 // Same `intra_segment_id` placement as the square reader above.5389 // Same `intra_segment_id` placement as the square reader above.
5365 let (seg_w_mi, seg_h_mi) = (bw / 4, bh / 4);5390 let (seg_w_mi, seg_h_mi) = (bw / 4, bh / 4);
5366 if seg_id_pre_skip() {5391 if seg_id_pre_skip() {
@@ -8296,6 +8321,14 @@ fn read_intra_mode(
8296 }8321 }
8297 };8322 };
8298 }8323 }
8324+ // lane-sbrect10 r1: `is_cfl_allowed`'s <=32 bound, enforced at the single
8325+ // point every square caller routes through (see `read_intra_mode_rect`).
8326+ let cfl = if cfl && side > 32 {
8327+ NOCFL_UV_MODE_HITS.with(|c| c.set(c.get() + 1));
8328+ false
8329+ } else {
8330+ cfl
8331+ };
8299 // spec 5.11.6 `intra_frame_mode_info`: `intra_segment_id` is read BEFORE8332 // spec 5.11.6 `intra_frame_mode_info`: `intra_segment_id` is read BEFORE
8300 // `skip` when `SegIdPreSkip`, and after it otherwise.8333 // `skip` when `SegIdPreSkip`, and after it otherwise.
8301 let (seg_w_mi, seg_h_mi) = (side / 4, side / 4);8334 let (seg_w_mi, seg_h_mi) = (side / 4, side / 4);
@@ -18037,13 +18070,27 @@ fn decode_inter_block(
18037 // directional intra-in-inter block was refused above.18070 // directional intra-in-inter block was refused above.
18038 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);18071 let (nb_above_mode, nb_left_mode) = neighbours.modes_above_left(r, c);
18039 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);18072 let smooth_neighbor = is_smooth_mode(nb_above_mode) || is_smooth_mode(nb_left_mode);
18040- let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);18073+ // lane-sbrect10 r1 (class wrong-alphabet-same-value, second instance
18074+ // after lane-sbpart r3's rect strips): `is_cfl_allowed` (libaom
18075+ // `blockd.h` -- `block_size_wide[bsize] <= 32 && block_size_high[bsize]
18076+ // <= 32`, spec 5.11.5) caps CFL at 32x32, so a 64x64 intra block inside
18077+ // an INTER frame reads the 13-symbol `uv_mode_no_cfl` alphabet. Reading
18078+ // the 14-symbol CFL one gave the same DC_PRED VALUE but narrowed the
18079+ // arithmetic coder by the wrong interval, desyncing the tile from this
18080+ // block on.
18081+ let cfl_allowed = write_w.max(write_h) <= 32;
18082+ if !cfl_allowed {
18083+ NOCFL_UV_MODE_HITS.with(|c| c.set(c.get() + 1));
18084+ }
18085+ let uv_mode = if cfl_allowed {
18086+ dec.symbol(&mut cdfs.uv_mode_cfl[mode])
18087+ } else {
18088+ dec.symbol(&mut cdfs.uv_mode_no_cfl[mode])
18089+ };
18041 if (9..=12).contains(&uv_mode) {18090 if (9..=12).contains(&uv_mode) {
18042 SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));18091 SMOOTH_UV_HITS.with(|c| c.set(c.get() + 1));
18043 }18092 }
18044- let alpha = if uv_mode == DC_PRED {18093+ let alpha = if cfl_allowed && uv_mode == UV_CFL_PRED {
18045- None
18046- } else if uv_mode == UV_CFL_PRED {
18047 Some(read_cfl_alphas(dec, cdfs))18094 Some(read_cfl_alphas(dec, cdfs))
18048 } else {18095 } else {
18049 None18096 None
crates/ec-av1/src/stream.rsmodified+161 -7
@@ -6568,13 +6568,16 @@ mod tests {
6568 // refusal it names is GONE (this round codes a 64-px transform axis as6568 // refusal it names is GONE (this round codes a 64-px transform axis as
6569 // its truncated low-32 corner), and a 10-bit sweep of this exact6569 // its truncated low-32 corner), and a 10-bit sweep of this exact
6570 // recipe now reaches the arm -- 2 pixel-exact attempts, 2 64x32 and 26570 // recipe now reaches the arm -- 2 pixel-exact attempts, 2 64x32 and 2
6571- // 32x64 strips, 2 of them carrying a coded 64-axis residual. It stays6571+ // 32x64 strips, 2 of them carrying a coded 64-axis residual.
6572- // 8-bit here for a DIFFERENT, newly exposed reason: 10-bit attempt 146572+ // lane-sbrect10 r1 closed the newly exposed 10-bit defect r14 r2
6573- // (cq 61, horizontal split, motion step 12) mismatches ffmpeg while6573+ // parked this arm on (10-bit attempt 14, cq 61, horizontal split,
6574- // decoding ZERO superblock-level rect strips and zero 64-axis6574+ // motion step 12 -- it mismatched ffmpeg while decoding ZERO rect
6575- // residual units, i.e. a defect of some other shape that this gate6575+ // strips): a 64x64 INTRA block inside an inter frame read `uv_mode`
6576- // must not absorb. See lanes/r14-r2.report.md.6576+ // off the 14-symbol CFL-allowed alphabet, which libaom's
6577- for bit_depth in [8u32] {6577+ // `is_cfl_allowed` caps at 32x32 -- same DC_PRED value, wrong
6578+ // interval narrowing, tile desynced from that block on. Both depths
6579+ // run now.
6580+ for bit_depth in [8u32, 10u32] {
6578 let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) =6581 let (mut named_refusals, mut matched, mut out_of_scope, mut oos_mismatch) =
6579 (0u32, 0u32, 0u32, 0u32);6582 (0u32, 0u32, 0u32, 0u32);
6580 let (mut horz_proved, mut vert_proved) = (0usize, 0usize);6583 let (mut horz_proved, mut vert_proved) = (0usize, 0usize);
@@ -6729,6 +6732,157 @@ mod tests {
6729 }6732 }
6730 }6733 }
6731 6734
6735+ /// lane-sbrect10 r1: a 64x64 INTRA block inside an INTER frame, whose
6736+ /// `uv_mode` alphabet libaom's `is_cfl_allowed` (`blockd.h`: `wide <= 32
6737+ /// && high <= 32`) narrows to the 13-symbol NO-CFL table. Reading the
6738+ /// 14-symbol CFL one produced the same `DC_PRED` value with the wrong
6739+ /// interval narrowing, so the tile desynced from that block on and the
6740+ /// frame decoded silently wrong (class `wrong-alphabet-same-value`; found
6741+ /// as the "another shape" mismatch the superblock rect gate above had to
6742+ /// park its 10-bit arm on).
6743+ ///
6744+ /// The counter `nocfl_uv_mode_hits` proves the shape fired in EVERY
6745+ /// compared attempt, and every decode-order frame is compared against
6746+ /// ffmpeg -- an attempt that mismatches fails, it never SKIPs.
6747+ #[test]
6748+ fn a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet() {
6749+ const NAME: &str =
6750+ "a_real_aomenc_inter_frame_with_a_64x64_intra_block_reads_the_no_cfl_uv_alphabet";
6751+ let _gate_lock = lock_gate_counters();
6752+ if !have_ffmpeg() {
6753+ eprintln!("SKIP {NAME}: no ffmpeg");
6754+ return;
6755+ }
6756+ if !have_aomenc() {
6757+ eprintln!("SKIP {NAME}: no aomenc at {}", aomenc_path().display());
6758+ return;
6759+ }
6760+ let (width, height, frame_count) = (192usize, 128usize, 6usize);
6761+ for bit_depth in [8u32, 10u32] {
6762+ let (mut named_refusals, mut matched, mut carried_none) = (0u32, 0u32, 0u32);
6763+ let mut total_hits = 0usize;
6764+ for attempt in 0..16u32 {
6765+ // The sibling superblock-rect gate's own grid (its 10-bit
6766+ // attempt 14 -- cq 61, horizontal split, motion step 12 -- is
6767+ // the stream that exposed the defect); which superblock the RD
6768+ // hands an intra 64x64 block moves with the quantiser and the
6769+ // depth, so both orientations x four quantisers x two motion
6770+ // steps run here too.
6771+ let vertical_split = attempt % 2 == 1;
6772+ let cq = [58, 52, 45, 61][(attempt / 2 % 4) as usize];
6773+ let sp = 8 + (attempt / 8) * 4;
6774+ let geq = if vertical_split {
6775+ format!("if(lt(Y,64), 40+mod(floor((X+N*{sp})/32)*90,200), 200)")
6776+ } else {
6777+ format!("if(lt(X,64), 40+mod(floor((Y+N*{sp})/32)*90,200), 200)")
6778+ };
6779+ let duration = frame_count as f64 / 25.0;
6780+ let source = format!(
6781+ "color=c=gray:s={width}x{height}:d={duration}:r=25,format=gray,\
6782+ geq=lum='{geq}',format=yuv420p"
6783+ );
6784+ let pix_fmt = if bit_depth == 10 { "yuv420p10le" } else { "yuv420p" };
6785+ let y4m = Command::new("ffmpeg")
6786+ .args([
6787+ "-v", "error", "-f", "lavfi", "-i", &source, "-t", &duration.to_string(),
6788+ "-pix_fmt", pix_fmt, "-strict", "-1", "-f", "yuv4mpegpipe", "-",
6789+ ])
6790+ .stdin(Stdio::null())
6791+ .stdout(Stdio::piped())
6792+ .stderr(Stdio::piped())
6793+ .output()
6794+ .expect("ffmpeg failed to run");
6795+ assert!(
6796+ y4m.status.success(),
6797+ "{NAME}: ffmpeg refused the {bit_depth}-bit fixture: {}",
6798+ String::from_utf8_lossy(&y4m.stderr)
6799+ );
6800+ let cq_arg = format!("--cq-level={cq}");
6801+ let depth_arg = format!("--bit-depth={bit_depth}");
6802+ let input_depth_arg = format!("--input-bit-depth={bit_depth}");
6803+ let args: Vec<&str> = vec![
6804+ "--codec=av1", "--passes=1", "--end-usage=q", &cq_arg, "--cpu-used=0",
6805+ "--threads=1", "--row-mt=0", "--sb-size=64", &depth_arg, &input_depth_arg,
6806+ "--enable-restoration=0", "--enable-palette=0", "--deltaq-mode=0",
6807+ "--enable-filter-intra=0", "--enable-cfl-intra=0", "--enable-intrabc=0",
6808+ "--enable-tx-size-search=0", "--lag-in-frames=0",
6809+ "--enable-rect-partitions=1", "--enable-ab-partitions=0",
6810+ "--enable-1to4-partitions=1", "--min-partition-size=32",
6811+ "--max-partition-size=64",
6812+ "--obu", "-o", "-", "-",
6813+ ];
6814+ let mut child = Command::new(aomenc_path())
6815+ .args(&args)
6816+ .stdin(Stdio::piped())
6817+ .stdout(Stdio::piped())
6818+ .stderr(Stdio::piped())
6819+ .spawn()
6820+ .expect("aomenc failed to start");
6821+ child
6822+ .stdin
6823+ .take()
6824+ .expect("aomenc stdin")
6825+ .write_all(&y4m.stdout)
6826+ .expect("writing y4m to aomenc");
6827+ let out = child.wait_with_output().expect("aomenc failed to run");
6828+ assert!(
6829+ out.status.success(),
6830+ "aomenc refused the fixture: {}",
6831+ String::from_utf8_lossy(&out.stderr)
6832+ );
6833+ let stream = out.stdout;
6834+ let before = crate::decode::nocfl_uv_mode_hits();
6835+ let frames = match decode_stream(&stream) {
6836+ Err(e) => {
6837+ let msg = e.to_string();
6838+ assert!(
6839+ msg.contains("unsupported"),
6840+ "{NAME} failed outright, not a named refusal ({bit_depth}-bit, \
6841+ attempt {attempt}): {msg}"
6842+ );
6843+ named_refusals += 1;
6844+ eprintln!("{bit_depth}-bit attempt {attempt} refusal: {msg}");
6845+ continue;
6846+ }
6847+ Ok(frames) => frames,
6848+ };
6849+ let hits = crate::decode::nocfl_uv_mode_hits() - before;
6850+ let ffmpeg_frames = if bit_depth == 10 {
6851+ ffmpeg_decode_sequence_10bit(&stream, width, height, frame_count)
6852+ } else {
6853+ ffmpeg_decode_sequence(&stream, width, height, frame_count)
6854+ };
6855+ assert_eq!(frames.len(), frame_count);
6856+ if hits == 0 {
6857+ // No 64-axis intra block in this stream: still compared
6858+ // (a mismatch here is a defect, never a pass), just not
6859+ // proof of this gate's shape.
6860+ carried_none += 1;
6861+ }
6862+ for (i, (got, want)) in frames.iter().zip(&ffmpeg_frames).enumerate() {
6863+ assert_eq!(got.y, want.y, "{NAME} frame {i} luma vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})");
6864+ assert_eq!(got.u, want.u, "{NAME} frame {i} U vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})");
6865+ assert_eq!(got.v, want.v, "{NAME} frame {i} V vs ffmpeg (attempt {attempt}, {bit_depth}-bit, hits={hits})");
6866+ }
6867+ if hits > 0 {
6868+ matched += 1;
6869+ total_hits += hits;
6870+ }
6871+ }
6872+ eprintln!(
6873+ "{NAME} ({bit_depth}-bit): {named_refusals} named refusals, {matched} pixel-exact \
6874+ attempts carrying a >32 intra block ({total_hits} no-CFL uv_mode reads), \
6875+ {carried_none} attempts carried none"
6876+ );
6877+ assert!(
6878+ matched > 0 && total_hits > 0,
6879+ "{NAME} ({bit_depth}-bit): no attempt decoded an intra block above 32x32, so the \
6880+ no-CFL uv_mode alphabet was never exercised -- gate proved nothing \
6881+ ({named_refusals} refusals, {carried_none} attempts carried none)"
6882+ );
6883+ }
6884+ }
6885+
6732 /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT`6886 /// lane-inter4 r2: the 32x32-level inter `PARTITION_HORZ`/`PARTITION_VERT`
6733 /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r16887 /// strips (32x16 / 16x32) carrying a REAL residual -- the capability r1
6734 /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs6888 /// found missing ("a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs