forge
Explore
Log in

Don't you dare go Hollow

Lane-av1444edge r3 -- the FIRST 4:4:4 superres cell, with the header assert the phantom cell failed

Browse files at this commit

2bc3af64f8d8baf63797532986bd46b38907bfdfAhmet Kaan GümüşParent: ac21620
  • test
    • lane-av1444edge r3 -- the FIRST 4:4:4 superres cell, with the header assert the phantom cell failed
Show full message
test(av1): lane-av1444edge r3 -- the FIRST 4:4:4 superres cell, with the header assert the phantom cell failed

Closes the last hand-quoted thing this lane was handed. §6.6 of
`lanes/av1formatsweep.report.md` left "4:4:4 superres at 10/12 bits" on
the not-measured list and §6.2 mislabelled the 8-bit cell; r2 established
the real 4:4:4 superres cell is exact but had no gate, and this is it.

The cell: 256x128 upscaled, coded 171x128, `denom = 12`, 4:4:4 8-bit
lossy cq-20. 14808 B, sha256
450caa3e31526a8973b9f64d5030a2f11b87bd60fac07aef121cb62af9bf85ff,
reproducible byte-for-byte from the quoted recipe.

Why the header assertions are the point. The sweep's cell passed
`--superres-mode=1` with no denominator; libaom's energy heuristic chose
8, every frame header read `use_superres=false denom=8`, and a whole
matrix cell was an unscaled stream wearing a superres label. So the gate
parses the headers and asserts, per frame: `use_superres`, `superres_denom
== 12`, `upscaled_width == 256`, and the CODED size 171x128 -- and then
re-derives `FrameWidth == (UpscaledWidth*8 + denom/2)/denom` rather than
only comparing literals, so a re-pinned fixture cannot satisfy the numbers
while the scaled-size arithmetic moves under them. A stream that stops
being scaled goes red on a header assertion instead of quietly becoming a
differently-shaped exactness claim.

The pixel arm also asserts the frame comes back at 256x128 and not 171,
and that both chroma planes are full resolution, so a decoder that
upscaled only luma fails on shape rather than passing the byte compare on
quarter-size planes. Non-vacuity: `superres_hits` (measured 4) and
`mc::predict_scaled_hits` (measured 2130) as DELTAS, so the upscaler and
scaled inter prediction are both known to have run.

Scope, stated honestly: this is the FIRST 4:4:4 superres cell in the
crate, not a broadening of an existing family. All eight pre-existing
superres gates are 4:2:0, checked rather than repeated -- the two pinned
fixtures parse `ss (1,1)` from their own sequence headers
(superres_kf_cdef_lr_64x64.obu 8-bit, superres_alltools_sb128_320x180.obu
10-bit) and the six live-aomenc gates all feed a `yuv420p` /
`yuv420p10le` source.

Green: 4/4 decode-order frames byte-exact vs aomdec, 4 upscales, 2130
scaled MC blocks, no SKIP.

Red before, three mutations, all reverted:
* tap alignment (`superres.rs`, the upscale filter's `base` shifted one
  column) -- the strong one: decode-order frame 0 differs at byte 5 (ours
  76 vs oracle 74), 37726 bytes differ, with BOTH counters still non-zero,
  so the red is on the pixel compare and not on a counter assertion.
* `set_superres` handed the CODED width where the upscaled width belongs
  -- red on `predict_scaled_hits == 0`, i.e. the gate catches a mis-sized
  superres state through the counter, before the compare is reached.
* the upscale step derived from `out_width` for both ends (a 1:1 scale) --
  red, but as an index-out-of-bounds panic inside `upscale_row` rather
  than a pixel mismatch. Recorded because it is the weaker kind of red: it
  proves the step feeds the sample index, not that the byte compare
  discriminates.
crates/ec-av1/fixtures/444_lossy_superres_256x128_d12.obuadded+0 -0

Binary file changed

crates/ec-av1/src/stream.rsmodified+229 -0
@@ -7250,6 +7250,235 @@ pub(crate) mod tests {
72507250 }
72517251 }
72527252
7253+ /// lane-av1444edge r3: the FIRST 4:4:4 superres cell in the crate, and
7254+ /// the cell the chroma-format sweep's "4:4:4 superres" row was supposed
7255+ /// to be.
7256+ ///
7257+ /// **Why this gate exists at all.** §6.2 of
7258+ /// `lanes/av1formatsweep.report.md` recorded that cell as DIVERGENT from
7259+ /// frame 2 with a first wrong sample of Y(192,0). It was never a superres
7260+ /// cell: the recipe passed `--superres-mode=1` and no denominator, so
7261+ /// libaom's `get_superres_denom_for_qindex`
7262+ /// (`av1/encoder/superres_scale.c:143`) chose 8, and all four frame
7263+ /// headers of that stream read `use_superres=false denom=8`. Nothing was
7264+ /// ever scaled; it was a plain 4:4:4 lossy cq-20 stream, and its
7265+ /// divergence was the same H1 class as the 130x122 cell beside it (see
7266+ /// `lanes/av1444edge.report.md` §2). That is the trap this gate is built
7267+ /// to make impossible to repeat: it asserts the scaled geometry from the
7268+ /// PARSED HEADERS, so a future flag or heuristic change that silently
7269+ /// unsizes the stream makes the gate red on a header assertion instead of
7270+ /// turning into a differently-shaped exactness claim.
7271+ ///
7272+ /// **This is the only 4:4:4 superres coverage here.** All eight
7273+ /// pre-existing superres gates are 4:2:0, checked rather than assumed:
7274+ /// the two pinned fixtures parse `ss (1,1)` from their own sequence
7275+ /// headers (`superres_kf_cdef_lr_64x64.obu` 8-bit,
7276+ /// `superres_alltools_sb128_320x180.obu` 10-bit) and the six live-aomenc
7277+ /// gates all feed a `yuv420p` / `yuv420p10le` source. So this cell's
7278+ /// claim is scoped honestly: it is the FIRST 4:4:4 superres stream, not
7279+ /// a broadening of an existing family.
7280+ ///
7281+ /// **The recipe** (sha256
7282+ /// `450caa3e31526a8973b9f64d5030a2f11b87bd60fac07aef121cb62af9bf85ff`,
7283+ /// 14808 bytes, 4 frames, `testsrc2 256x128 rate=25` yuv444p):
7284+ /// ```text
7285+ /// ffmpeg -f lavfi -i "testsrc2=size=256x128:rate=25" -frames:v 4 \
7286+ /// -pix_fmt yuv444p -strict -1 -f yuv4mpegpipe - | \
7287+ /// aomenc --codec=av1 --passes=1 --end-usage=q --cq-level=20 --cpu-used=2 \
7288+ /// --threads=1 --row-mt=0 --lag-in-frames=0 --kf-max-dist=100 \
7289+ /// --limit=4 --superres-mode=1 --superres-denominator=12 \
7290+ /// --superres-kf-denominator=12 --obu -o - -
7291+ /// ```
7292+ /// The two denominator flags are the whole point: without them the cell
7293+ /// does not exist. Verified byte-reproducible — re-encoding this recipe
7294+ /// reproduces the pinned 14808 bytes exactly.
7295+ ///
7296+ /// **What the cell exercises.** Coded 171x128 upscaled to 256x128 at
7297+ /// `denom = 12`, so a 4:4:4 chroma plane is upscaled at FULL resolution
7298+ /// (a 4:2:0 stream halves it first, and libaom's `av1_superres_upscale`
7299+ /// takes a different path per chroma format). Measured `superres_hits` 4
7300+ /// and `mc::predict_scaled_hits` 2130 — the upscaler and scaled inter
7301+ /// prediction both run, so the cell is not passing on an unscaled
7302+ /// stream.
7303+ ///
7304+ /// Non-vacuity, four ways: the pinned bytes (length + FNV-1a); the parsed
7305+ /// headers really are `use_superres` at `denom 12` with the SCALED coded
7306+ /// size, and the coded width is re-derived from `UpscaledWidth` and the
7307+ /// denominator rather than only compared to a literal, so a re-pinned
7308+ /// fixture cannot drift past the assertion; both counters are asserted as
7309+ /// DELTAS; and every decode-order frame is compared byte-for-byte
7310+ /// through `decode_all_frames_vs_oracle`, which is what makes the
7311+ /// upscaled width on both sides a real check.
7312+ #[test]
7313+ fn a_444_lossy_superres_stream_decodes_pixel_exact() {
7314+ const NAME: &str = "a_444_lossy_superres_stream_decodes_pixel_exact";
7315+ const FIXTURE: &str = "fixtures/444_lossy_superres_256x128_d12.obu";
7316+ const FIXTURE_LEN: usize = 14808;
7317+ const FIXTURE_FNV: u64 = 0x44e0_d12f_1155_0e09;
7318+ /// Quoted so a re-pin has to be deliberate; the FNV above is what the
7319+ /// gate actually compares, this is what a human reads.
7320+ const FIXTURE_SHA256: &str =
7321+ "450caa3e31526a8973b9f64d5030a2f11b87bd60fac07aef121cb62af9bf85ff";
7322+ const UPSCALED: (usize, usize) = (256, 128);
7323+ const CODED: (usize, usize) = (171, 128);
7324+ const DENOM: u8 = 12;
7325+ const FRAMES: usize = 4;
7326+ let obu = std::path::PathBuf::from(env!("CARGO_MANIFEST_DIR")).join(FIXTURE);
7327+ let stream = std::fs::read(&obu).unwrap_or_else(|e| {
7328+ panic!(
7329+ "{NAME}: pinned fixture {} is missing ({e}) -- the gate cannot run, \
7330+ which is a failure, not a skip",
7331+ obu.display()
7332+ )
7333+ });
7334+ assert_eq!(stream.len(), FIXTURE_LEN, "{NAME}: fixture length moved");
7335+ assert_eq!(fnv1a64(&stream), FIXTURE_FNV, "{NAME}: fixture bytes moved");
7336+
7337+ // --- the header facts the CELL depends on, parsed not assumed ------
7338+ let mut parser = Av1Parser::new();
7339+ let mut pos = 0usize;
7340+ let mut seq = None;
7341+ let mut heads: Vec<FrameHeader> = Vec::new();
7342+ while pos < stream.len() {
7343+ let obu = parser
7344+ .parse_obu(&stream[pos..])
7345+ .unwrap_or_else(|e| panic!("{NAME}: aomenc OBU does not parse: {e:?}"));
7346+ if obu.total_size == 0 {
7347+ break;
7348+ }
7349+ pos += obu.total_size;
7350+ match obu.kind {
7351+ ObuKind::SequenceHeader(s) => seq = Some(s),
7352+ ObuKind::FrameHeader(h) => heads.push(*h),
7353+ ObuKind::Frame(h, _) => heads.push(*h),
7354+ _ => {}
7355+ }
7356+ }
7357+ let seq = seq.unwrap_or_else(|| panic!("{NAME}: the stream carries no sequence header"));
7358+ assert_eq!(
7359+ (
7360+ seq.color_config.subsampling_x,
7361+ seq.color_config.subsampling_y
7362+ ),
7363+ (0, 0),
7364+ "{NAME}: the stream is not 4:4:4 (ss = ({}, {}))",
7365+ seq.color_config.subsampling_x,
7366+ seq.color_config.subsampling_y
7367+ );
7368+ assert_eq!(
7369+ seq.color_config.bit_depth, 8,
7370+ "{NAME}: not the 8-bit cell this gate names"
7371+ );
7372+ assert!(
7373+ seq.enable_superres,
7374+ "{NAME}: the sequence header does not enable superres at all"
7375+ );
7376+ assert_eq!(
7377+ heads.len(),
7378+ FRAMES,
7379+ "{NAME}: {} frame headers, expected {FRAMES}",
7380+ heads.len()
7381+ );
7382+ for (i, h) in heads.iter().enumerate() {
7383+ // The assertion the phantom cell failed. Without the denominator
7384+ // flags aomenc picks 8 and this is false while the stream still
7385+ // decodes, which is how a whole sweep cell ends up mislabelled.
7386+ assert!(
7387+ h.use_superres,
7388+ "{NAME}: frame {i} has use_superres = false -- this is an UNSCALED \
7389+ stream and the gate would be measuring something other than the \
7390+ cell it names (class gate-blind-to-feature)"
7391+ );
7392+ assert_eq!(
7393+ h.superres_denom, DENOM,
7394+ "{NAME}: frame {i} denominator moved from {DENOM}"
7395+ );
7396+ assert_eq!(
7397+ (h.upscaled_width as usize, h.frame_height as usize),
7398+ (UPSCALED.0, UPSCALED.1),
7399+ "{NAME}: frame {i} upscaled size moved"
7400+ );
7401+ assert_eq!(
7402+ (h.frame_width as usize, h.frame_height as usize),
7403+ (CODED.0, CODED.1),
7404+ "{NAME}: frame {i} CODED size moved -- this is the scaled half of \
7405+ the cell and the part an unsized stream gets wrong"
7406+ );
7407+ // Re-derive rather than only compare literals, so a re-pinned
7408+ // fixture cannot satisfy the numbers above while the scaled-size
7409+ // arithmetic has moved under them.
7410+ assert_eq!(
7411+ (h.upscaled_width * 8 + u32::from(DENOM) / 2) / u32::from(DENOM),
7412+ h.frame_width,
7413+ "{NAME}: frame {i}: FrameWidth is not (UpscaledWidth*8 + denom/2)/denom -- \
7414+ the scaled size the cell rests on is not the spec's"
7415+ );
7416+ }
7417+
7418+ // --- the pixels -----------------------------------------------------
7419+ let _guard = lock_gate_counters();
7420+ let before_sr = crate::superres::superres_hits();
7421+ let before_scaled = crate::mc::predict_scaled_hits();
7422+ let frames = decode_stream(&stream).unwrap_or_else(|e| {
7423+ panic!("{NAME}: the pinned 4:4:4 superres stream was refused: {e}")
7424+ });
7425+ let scaled_up = crate::superres::superres_hits() - before_sr;
7426+ let scaled_mc = crate::mc::predict_scaled_hits() - before_scaled;
7427+ assert!(
7428+ scaled_up > 0,
7429+ "{NAME}: zero superres_hits -- the upscaler never ran (class \
7430+ gate-blind-to-feature)"
7431+ );
7432+ assert!(
7433+ scaled_mc > 0,
7434+ "{NAME}: zero predict_scaled_hits -- no inter block read a scaled reference, \
7435+ so the scaled-PREDICTION half of the cell is unexercised (class \
7436+ gate-blind-to-feature)"
7437+ );
7438+ assert_eq!(frames.len(), FRAMES, "{NAME}: decoded frame count");
7439+ for (i, f) in frames.iter().enumerate() {
7440+ // The upscale must have REPLACED the frame: a decoder that
7441+ // returned the 171-wide coded picture fails here, and without
7442+ // this check the chroma-shape assertion below could be satisfied
7443+ // by quarter-size planes.
7444+ assert_eq!(
7445+ (f.width, f.height),
7446+ UPSCALED,
7447+ "{NAME}: frame {i} came back {}x{}, not the UPSCALED {}x{}",
7448+ f.width,
7449+ f.height,
7450+ UPSCALED.0,
7451+ UPSCALED.1
7452+ );
7453+ assert_eq!(
7454+ f.u.len(),
7455+ UPSCALED.0 * UPSCALED.1,
7456+ "{NAME}: frame {i} chroma plane is {} samples; at 4:4:4 upscaled it must \
7457+ be full resolution ({}x{})",
7458+ f.u.len(),
7459+ UPSCALED.0,
7460+ UPSCALED.1
7461+ );
7462+ assert_eq!(
7463+ f.v.len(),
7464+ UPSCALED.0 * UPSCALED.1,
7465+ "{NAME}: frame {i} V plane is {} samples, expected full resolution",
7466+ f.v.len()
7467+ );
7468+ }
7469+ if aomdec_path().is_file() {
7470+ let (decoded, hidden) = decode_all_frames_vs_oracle(&stream, NAME);
7471+ eprintln!(
7472+ "{NAME}: {decoded} decode-order frame(s) ({hidden} hidden) byte-exact vs \
7473+ aomdec at {UPSCALED:?} upscaled from {CODED:?} denom {DENOM}, \
7474+ {scaled_up} upscale(s), {scaled_mc} scaled MC block(s); fixture sha256 \
7475+ {FIXTURE_SHA256}"
7476+ );
7477+ } else {
7478+ eprintln!("{NAME}: no oracle aomdec, pixel arm skipped");
7479+ }
7480+ }
7481+
72537482 /// lane-av1lrflush: the pipelined loop-restoration band release flushes
72547483 /// RU row 0 on the inter frame whose top superblock row carries a
72557484 /// 128-root rect -- the exact shape lanes/av1444sb.report.md r2 named as