forge
Explore
Log in

Don't you dare go Hollow

wip: per-axis dump extent + synthetic census control

Browse files at this commit

835a1543f149756e212a066fa65ec75a1a2f99a5Ahmet Kaan GümüşParent: 9fe4968
crates/ec-av1/src/decode.rsmodified+32 -3
@@ -21138,19 +21138,36 @@ fn dump_stage16(
21138 v: &PlaneBuf<'_>,21138 v: &PlaneBuf<'_>,
21139 fw: usize,21139 fw: usize,
21140 fh: usize,21140 fh: usize,
21141+ ss_x: usize,
21142+ ss_y: usize,
21141 ) {21143 ) {
21142 use std::io::Write;21144 use std::io::Write;
21143 // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by21145 // lane-sbrect10 r2 / lane-cdef r1 (one shared helper): index the dump by
21144 // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed21146 // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed
21145 // `.f0` name kept only the LAST frame, so a mid-sequence divergence could21147 // `.f0` name kept only the LAST frame, so a mid-sequence divergence could
21146- // not be read out at all.21148+ // not be read at all.
21149+ //
21150+ // lane-unwritten-dep: the chroma extent is PER-AXIS subsampling, not
21151+ // `div_ceil(2)` on both. The hardcoded pair was a 4:2:0 assumption and it
21152+ // was load-bearing: on a 64x64 4:2:2 frame (ss_x = 1, ss_y = 0) it wrote
21153+ // 32x32 chroma per plane where the frame carries 32x64, so HALF of each
21154+ // chroma plane appeared in NO stage dump at all. A stage bisect that reads
21155+ // "identical pre-deblock, differs post-deblock" off these dumps is then
21156+ // measuring the dump's blind spot, not the pipeline's: the samples it could
21157+ // not see are exactly the region where the 4:2:2 witness's output diverges
21158+ // (chroma rows 30..63, 2048 samples). `round_ss` is the same rounding the
21159+ // decoder's own plane extents use, and it matches the oracle's
21160+ // `uv_crop_width` / `uv_crop_height` per axis.
21161+ // ONE file per frame: `dump_stage_idx` advances on every call, so creating
21162+ // the file inside the plane loop would write three files per frame and
21163+ // shift every later frame's index.
21147 if let Ok(path) = crate::envflags::var(var)21164 if let Ok(path) = crate::envflags::var(var)
21148 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))21165 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))
21149 {21166 {
21150 for (p, w, h) in [21167 for (p, w, h) in [
21151 (y, fw, fh),21168 (y, fw, fh),
21152- (u, fw.div_ceil(2), fh.div_ceil(2)),21169+ (u, round_ss(fw, ss_x), round_ss(fh, ss_y)),
21153- (v, fw.div_ceil(2), fh.div_ceil(2)),21170+ (v, round_ss(fw, ss_x), round_ss(fh, ss_y)),
21154 ] {21171 ] {
21155 for row in 0..h {21172 for row in 0..h {
21156 let mut bytes = Vec::with_capacity(w * 2);21173 let mut bytes = Vec::with_capacity(w * 2);
@@ -37512,6 +37529,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
37512 &v,37529 &v,
37513 frame_width as usize,37530 frame_width as usize,
37514 frame_height as usize,37531 frame_height as usize,
37532+ ss_x(fctx),
37533+ ss_y(fctx),
37515 );37534 );
37516 if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {37535 if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {
37517 use std::io::Write;37536 use std::io::Write;
@@ -37594,6 +37613,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
37594 &v,37613 &v,
37595 frame_width as usize,37614 frame_width as usize,
37596 frame_height as usize,37615 frame_height as usize,
37616+ ss_x(fctx),
37617+ ss_y(fctx),
37597 );37618 );
37598 apply_cdef(37619 apply_cdef(
37599 &mut y,37620 &mut y,
@@ -37614,6 +37635,8 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
37614 &v,37635 &v,
37615 frame_width as usize,37636 frame_width as usize,
37616 frame_height as usize,37637 frame_height as usize,
37638+ ss_x(fctx),
37639+ ss_y(fctx),
37617 );37640 );
37618 capture_stages(&y, &u, &v, deblocked.as_ref(), fctx);37641 capture_stages(&y, &u, &v, deblocked.as_ref(), fctx);
37619 // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called37642 // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called
@@ -55796,6 +55819,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
55796 &v,55819 &v,
55797 frame_width as usize,55820 frame_width as usize,
55798 frame_height as usize,55821 frame_height as usize,
55822+ ss_x(fctx),
55823+ ss_y(fctx),
55799 );55824 );
55800 if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {55825 if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {
55801 use std::io::Write;55826 use std::io::Write;
@@ -55898,6 +55923,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
55898 &v,55923 &v,
55899 frame_width as usize,55924 frame_width as usize,
55900 frame_height as usize,55925 frame_height as usize,
55926+ ss_x(fctx),
55927+ ss_y(fctx),
55901 );55928 );
55902 if !pipelined {55929 if !pipelined {
55903 apply_cdef(55930 apply_cdef(
@@ -55920,6 +55947,8 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
55920 &v,55947 &v,
55921 frame_width as usize,55948 frame_width as usize,
55922 frame_height as usize,55949 frame_height as usize,
55950+ ss_x(fctx),
55951+ ss_y(fctx),
55923 );55952 );
55924 capture_stages(&y, &u, &v, deblocked.as_ref(), fctx);55953 capture_stages(&y, &u, &v, deblocked.as_ref(), fctx);
55925 // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called55954 // spec 7.16 (libaom `superres_post_decode`, decodeframe.c: called
crates/ec-av1/src/stream.rsmodified+107 -54
@@ -48167,47 +48167,45 @@ exit 0
48167 /// lane-unwritten-dep: the UNWRITTEN-SAMPLE census at the point the output is48167 /// lane-unwritten-dep: the UNWRITTEN-SAMPLE census at the point the output is
48168 /// taken, over the real film fixtures that carry hidden alt-refs.48168 /// taken, over the real film fixtures that carry hidden alt-refs.
48169 ///48169 ///
48170- /// What this pins, and why the pre-deblock census could not: the tile walk's48170+ /// SCOPE, stated rather than implied: the census is taken where
48171- /// pre-deblock scan sees a plane BEFORE deblock/CDEF/LR, and the loop filter48171+ /// `EC_AV1_FINAL_DUMP` writes, which is BEFORE `apply_grain`. The claim is
48172- /// READS neighbours to decide an edge. So an unwritten sample changes its48172+ /// therefore over the PRE-GRAIN planes -- which is also the claim that matters
48173- /// neighbour's filtered value even when the unwritten sample itself is48173+ /// most, because those exact bytes are what the reference bank stores and what
48174- /// overwritten afterwards -- the hole is invisible pre-deblock and gone from48174+ /// every later frame predicts from. Film grain synthesises from that pre-grain
48175- /// the plane by the time anyone looks again. Measured on48175+ /// frame plus the grain parameters and does not read the plane buffer, so it
48176- /// `440_request_is_422` (8-bit, 64x64, a 4:2:2 header over a 4:2:0 tile,48176+ /// cannot introduce a hole. The claim is NOT "the caller's final grained
48177- /// which lane/av1unwritten refuses): the pre-deblock dump is BYTE-IDENTICAL48177+ /// picture has no hole" and is not asserted.
48178- /// between an uninitialised and a `PLANE_SENTINEL`-filled run -- zero sentinel48178+ ///
48179- /// samples either way -- while the final output differs by 1986 bytes, all in48179+ /// NON-VACUITY, the part that makes this gate worth having: a census is only a
48180- /// the U/V planes' rows 30..63 of 64. The stage dump localises the entry48180+ /// measurement if it CAN report non-zero. The control is a SYNTHETIC positive
48181- /// exactly: `EC_AV1_PREFILT_DUMP16` identical, `EC_AV1_POSTDEBLOCK_DUMP16`48181+ /// -- the census is handed planes with a known number of sentinel samples and
48182- /// differing by 26 bytes. `EC_AV1_DEBUG_SKIP_DEBLOCK=1` does NOT remove it,48182+ /// must report exactly that number. It deliberately does NOT use a fixture:
48183- /// because skipping deblock leaves the same neighbours unwritten for CDEF.48183+ /// the corpus's one witness with a real hole (`440_request_is_422`) is REFUSED
48184- ///48184+ /// by lane/av1unwritten, so a fixture-carried control goes red on merge for a
48185- /// This gate therefore counts at the SAME point `EC_AV1_FINAL_DUMP` writes,48185+ /// reason unrelated to this gate. A synthetic control cannot be refused and
48186- /// which makes the claim the one a reader actually cares about: no sample the48186+ /// cannot change behaviour when a lane lands. It is proven by mutation in the
48187- /// tile walk never wrote survives into the frame the caller receives.48187+ /// same run: neutering `census_unwritten_final` reds it (lane report §5).
48188- ///
48189- /// NON-VACUITY, and it is the part that makes this gate worth having: the
48190- /// census is only a measurement because it CAN report non-zero. The control
48191- /// below is the same measurement on the one fixture in the corpus where a
48192- /// hole really does reach the output, and it is asserted NON-ZERO (32 samples,
48193- /// measured). A census that silently read zero everywhere would fail it.
48194 ///48188 ///
48195 /// The four film fixtures are the corpus's real 10-bit streams with hidden48189 /// The four film fixtures are the corpus's real 10-bit streams with hidden
48196 /// alt-refs -- the shapes where a hidden frame's unwritten region would feed48190 /// alt-refs -- the shapes where a hidden frame's unwritten region would feed
48197 /// a later DISPLAYED frame through the reference bank, which is the only way48191 /// a later DISPLAYED frame through the reference bank, which is the only way
48198 /// an unwritten sample could reach output on a stream that decodes correctly.48192 /// an unwritten sample could reach output on a stream that decodes correctly.
48199- /// All four measure 0.48193+ /// All four measure 0 here AND 0 on the pre-deblock census.
48200 ///48194 ///
48201- /// Measured on `8d6998d7` with a provenance-verified probe48195+ /// Measured on `8d6998d7` with a provenance-verified probe (`strings` on the
48202- /// (`strings` on the binary names only this worktree; the fixture sha256s are48196+ /// binary names only this worktree; reelb_arf sha256 `7f3b060da5aa9c53`,
48203- /// `7f3b060da5aa9c53` for reelb_arf, `c9e721088766163b` for reelb_rect64):48197+ /// reelb_rect64 `c9e721088766163b`):
48204 ///48198 ///
48205 /// ```text48199 /// ```text
48206- /// 440_request_is_422 FINAL_UNWRITTEN 32 frames=1 <- control, non-zero48200+ /// pre-deblock census (u16, whole plane, 0xDEAD counted per frame)
48207- /// reelb_arf_witness FINAL_UNWRITTEN 0 frames=3748201+ /// 440_request_is_422 224 <- also lane/av1unwritten's own number
48208- /// reelb_rect64_intra16x4_witness FINAL_UNWRITTEN 0 frames=3348202+ /// reelb_arf_witness 0
48209- /// gm_small_side_witness FINAL_UNWRITTEN 0 frames=3348203+ /// reelb_rect64_intra16x4_witness 0
48210- /// reelc_sb128_inter_witness FINAL_UNWRITTEN 0 frames=1548204+ /// this gate (pre-grain, at the output point)
48205+ /// reelb_arf_witness 0
48206+ /// reelb_rect64_intra16x4_witness 0
48207+ /// gm_small_side_witness 0
48208+ /// reelc_sb128_inter_witness 0
48211 /// ```48209 /// ```
48212 #[test]48210 #[test]
48213 fn the_frame_the_caller_receives_carries_no_unwritten_plane_sample() {48211 fn the_frame_the_caller_receives_carries_no_unwritten_plane_sample() {
@@ -48250,32 +48248,68 @@ exit 0
48250 })48248 })
48251 };48249 };
48252 48250
48253- // Non-vacuity FIRST: the census must be able to report non-zero, or every48251+ // Non-vacuity FIRST, and SYNTHETIC on purpose (see the doc comment): the
48254- // zero below would be meaningless.48252+ // census is handed planes with a known number of sentinel samples and must
48255- let control = census("440_request_is_422");48253+ // report exactly that number. No fixture is involved, so this cannot be
48256- assert!(48254+ // affected by lane/av1unwritten refusing `440_request_is_422` on merge.
48257- control > 0,48255+ // The fill is env-gated, so even this runs in the child.
48258- "{NAME}: the census reports 0 even on the one fixture whose output DOES depend \48256+ let synthetic = census_synthetic();
48259- on unwritten plane memory (measured 32) -- the census is blind or the sentinel \48257+ assert_eq!(
48260- fill is not live, so every assertion below would be vacuous"48258+ synthetic, 7,
48259+ "{NAME}: the census reported {synthetic} for planes carrying exactly 7 sentinel \
48260+ samples -- the census is not measuring what it claims, so every zero below is \
48261+ meaningless (class: census-silently-blind)"
48261 );48262 );
48262 48263
48263- for (fixture, frames) in [48264+ for fixture in [
48264- ("reelb_arf_witness", 37usize),48265+ "reelb_arf_witness",
48265- ("reelb_rect64_intra16x4_witness", 33),48266+ "reelb_rect64_intra16x4_witness",
48266- ("gm_small_side_witness", 33),48267+ "gm_small_side_witness",
48267- ("reelc_sb128_inter_witness", 15),48268+ "reelc_sb128_inter_witness",
48268 ] {48269 ] {
48269 let n = census(fixture);48270 let n = census(fixture);
48270 assert_eq!(48271 assert_eq!(
48271 n, 0,48272 n, 0,
48272- "{NAME}: {fixture} hands the caller {n} samples the tile walk never wrote \48273+ "{NAME}: {fixture} hands the caller {n} samples the tile walk never wrote"
48273- (class: a hole the loop filter read)"
48274 );48274 );
48275- let _ = frames; // frame count is asserted inside the child
48276 }48275 }
48277 }48276 }
48278 48277
48278+ /// Runs the census child with `UWDEP_CENSUS_FIXTURE` UNSET, which makes it
48279+ /// take the synthetic-positive path: hand [`census_unwritten_final`] planes
48280+ /// with a known number of `PLANE_SENTINEL` values and report what it counted.
48281+ /// This is the non-vacuity control, and it is a direct function-level check
48282+ /// rather than a decode, so no fixture's decode behaviour can change it.
48283+ fn census_synthetic() -> usize {
48284+ const NAME: &str = "the_frame_the_caller_receives_carries_no_unwritten_plane_sample";
48285+ let exe = std::env::current_exe().expect("test binary path");
48286+ let out = std::process::Command::new(exe)
48287+ .args([
48288+ "--exact",
48289+ "stream::tests::uwdep_child_unwritten_census",
48290+ "--nocapture",
48291+ ])
48292+ .env("EC_AV1_PLANE_SENTINEL", "1")
48293+ .env("UWDEP_CENSUS_SYNTHETIC", "1")
48294+ .env_remove("UWDEP_CENSUS_FIXTURE")
48295+ .output()
48296+ .expect("running the census child");
48297+ let text = format!(
48298+ "{}{}",
48299+ String::from_utf8_lossy(&out.stdout),
48300+ String::from_utf8_lossy(&out.stderr),
48301+ );
48302+ text.lines()
48303+ .find_map(|l| l.strip_prefix("UWDEP_CENSUS "))
48304+ .and_then(|v| v.split_whitespace().next().and_then(|n| n.parse().ok()))
48305+ .unwrap_or_else(|| {
48306+ panic!(
48307+ "{NAME}: the census child reported no synthetic count (child said: {:?})",
48308+ text.trim()
48309+ )
48310+ })
48311+ }
48312+
48279 /// The child half of48313 /// The child half of
48280 /// [`the_frame_the_caller_receives_carries_no_unwritten_plane_sample`]: decodes48314 /// [`the_frame_the_caller_receives_carries_no_unwritten_plane_sample`]: decodes
48281 /// the fixture named in `UWDEP_CENSUS_FIXTURE` with the sentinel fill live and48315 /// the fixture named in `UWDEP_CENSUS_FIXTURE` with the sentinel fill live and
@@ -48285,6 +48319,30 @@ exit 0
48285 /// in-process counter -- which no external binary could read.48319 /// in-process counter -- which no external binary could read.
48286 #[test]48320 #[test]
48287 fn uwdep_child_unwritten_census() {48321 fn uwdep_child_unwritten_census() {
48322+ assert!(
48323+ std::env::var_os("EC_AV1_PLANE_SENTINEL").is_some(),
48324+ "the census child ran without EC_AV1_PLANE_SENTINEL, so the fill was never live \
48325+ and the count is meaningless"
48326+ );
48327+ // The non-vacuity control: no decode, no fixture, just the census over
48328+ // planes with a KNOWN number of sentinel samples. 3 + 4 + 0 = 7.
48329+ if std::env::var_os("UWDEP_CENSUS_SYNTHETIC").is_some() {
48330+ const S: u16 = 0xDEAD;
48331+ let mut a = vec![7u16; 16];
48332+ let mut b = vec![7u16; 16];
48333+ let c = vec![7u16; 8];
48334+ for s in a.iter_mut().take(3) {
48335+ *s = S;
48336+ }
48337+ for s in b.iter_mut().take(4) {
48338+ *s = S;
48339+ }
48340+ let _ = decode::take_final_unwritten_samples();
48341+ decode::census_unwritten_final(&a, &b, &c);
48342+ let n = decode::take_final_unwritten_samples();
48343+ println!("UWDEP_CENSUS {n} synthetic=1");
48344+ return;
48345+ }
48288 let Ok(fixture) = std::env::var("UWDEP_CENSUS_FIXTURE") else {48346 let Ok(fixture) = std::env::var("UWDEP_CENSUS_FIXTURE") else {
48289 // Not a census run: the parent invokes this test by name, so being48347 // Not a census run: the parent invokes this test by name, so being
48290 // reached without the variable means a normal suite run.48348 // reached without the variable means a normal suite run.
@@ -48297,11 +48355,6 @@ exit 0
48297 let _ = decode::take_final_unwritten_samples();48355 let _ = decode::take_final_unwritten_samples();
48298 let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{fixture} refused: {e}"));48356 let frames = decode_stream(&stream).unwrap_or_else(|e| panic!("{fixture} refused: {e}"));
48299 let n = decode::take_final_unwritten_samples();48357 let n = decode::take_final_unwritten_samples();
48300- assert!(
48301- std::env::var_os("EC_AV1_PLANE_SENTINEL").is_some(),
48302- "the census child ran without EC_AV1_PLANE_SENTINEL, so the fill was never live \
48303- and the count is meaningless"
48304- );
48305 println!("UWDEP_CENSUS {n} frames={}", frames.len());48358 println!("UWDEP_CENSUS {n} frames={}", frames.len());
48306 }48359 }
48307 48360