forge
Explore
Log in

Don't you dare go Hollow

ec-av1: lane-av1444edge -- the inter-frame pre-filter rung did not exist, and its counter restarted

Browse files at this commit

689d3e06c0c3de84f2b61bf36812d9dc64f039abAhmet Kaan GümüşParent: e772a72
Two defects in the same measurement rung, both of which report success
while measuring nothing useful. `EC_AV1_PREFILT_WIDE_DUMP` is the only
rung that writes the pre-loop-filter reconstruction cropped to each
plane's mi-ALIGNED extent, i.e. the shape aomdec's own rung 7 writes
(`y_width`/`y_height`), so it is the rung that separates "already wrong
in reconstruction" from "introduced by a loop filter".

1. It was inlined in the KEY-frame tile path only
   (`decode_key_frame_tile_with_cdfs`). `decode_inter_frame_tile_with_cdfs`
   has no wide prefilter dump at all, so every divergence localized to an
   inter frame had no pre-filter rung on our side to compare against the
   oracle's, and the nearest usable rung (the padded `EC_AV1_PREFILT_DUMP`)
   has a different byte shape from every oracle rung. Measured cost on the
   4:4:4 lossy cells this lane was handed: `EC_AV1_POSTDEBLOCK_DUMP` /
   `EC_AV1_POSTCDEF_DUMP` came out 61440 B against the oracle's 52224 B
   (our 160x128 padded surface vs its 136x128 aligned buffer) and the
   oracle's POSTDEBLOCK wrote 3 files for a 4-frame stream, so the stage
   ladder could not be read at all. With the rung on the inter path the
   same two cells' pre-filter dumps are 52224 B and 4 files, and the
   verdict is immediate: reconstruction already diverges at the same first
   sample as the final output, so no filter is involved.

2. Its counter was a FUNCTION-LOCAL `static IDX2`. Rust gives each
   monomorphisation of the enclosing function its own copy, so the index
   restarted and every frame after the first overwrote `.f0` -- a
   per-frame bisection silently compared the last decoded frame and
   reported it as frame 0. Measured directly: before this change the rung
   wrote exactly one file for a four-frame stream.

The counter is now the shared per-var `dump_stage_idx` map the other
stage dumps already use, and the block is a shared `dump_prefilter_wide`
called from both tile paths, beside each path's existing padded
`EC_AV1_PREFILT_DUMP` so the two agree on the point they sample. No
decode-path behaviour changes: the only writes are inside the existing
`if let Ok(path) = crate::envflags::var(...)` arms, which are off unless
the env var is set.

(cherry picked from commit b2148831481f741a05830ac7014876dfc67f8d07)
crates/ec-av1/src/decode.rsmodified+49 -21
@@ -19155,6 +19155,48 @@ fn dump_stage(var: &str, y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) {
19155 }19155 }
19156 }19156 }
19157 19157
19158+/// `EC_AV1_PREFILT_WIDE_DUMP=<prefix>` -> `<prefix>.f<N>`, the pre-loop-filter
19159+/// reconstruction cropped to each plane's mi-ALIGNED true extent, byte for
19160+/// byte the shape aomdec's own rung 7 writes (`y_width`/`y_height`,
19161+/// `uv_width`/`uv_height`), so the two can be diffed directly.
19162+///
19163+/// lane-av1444edge: this used to be an inline block in the KEY-frame tile path
19164+/// only, with a FUNCTION-LOCAL `static IDX2` as its counter. Both facts were
19165+/// measurement traps, and the second one is why the first went unnoticed:
19166+/// the inter-frame path (`decode_inter_frame_tile_with_cdfs`) had no wide
19167+/// prefilter dump at all, so every 4:4:4 lossy divergence localized to an
19168+/// inter frame had no pre-filter rung to compare against and got attributed to
19169+/// reconstruction when the oracle could not see it. The `static` also restarted
19170+/// per monomorphisation, so every frame after the first overwrote `.f0` -- a
19171+/// per-frame bisection silently compared the LAST decoded frame. The counter
19172+/// is now the shared per-var [`dump_stage_idx`] map, and the call also sits on
19173+/// the inter path (skipped when the filter pipeline is active, which has
19174+/// already deblocked by the time the tile tail runs -- same condition
19175+/// `capture_filter_replay` guards itself with).
19176+fn dump_prefilter_wide(y: &PlaneBuf<'_>, u: &PlaneBuf<'_>, v: &PlaneBuf<'_>) {
19177+ let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_WIDE_DUMP") else {
19178+ return;
19179+ };
19180+ use std::io::Write;
19181+ let idx = dump_stage_idx("EC_AV1_PREFILT_WIDE_DUMP");
19182+ let crop = |plane: &PlaneBuf<'_>| -> Vec<u8> {
19183+ let mut out = Vec::with_capacity(plane.true_width * plane.true_height);
19184+ for row in 0..plane.true_height {
19185+ out.extend(
19186+ plane.data[row * plane.width..][..plane.true_width]
19187+ .iter()
19188+ .map(|&s| s as u8),
19189+ );
19190+ }
19191+ out
19192+ };
19193+ if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
19194+ let _ = f.write_all(&crop(y));
19195+ let _ = f.write_all(&crop(u));
19196+ let _ = f.write_all(&crop(v));
19197+ }
19198+}
19199+
19158 /// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no19200 /// The value [`fresh_plane`] fills with under `EC_AV1_PLANE_SENTINEL`: no
19159 /// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`,19201 /// legal sample can equal it (reconstruction clamps to `(1 << bit_depth) - 1`,
19160 /// at most 4095), so a decode that hashes identically under the flag proves19202 /// at most 4095), so a decode that hashes identically under the flag proves
@@ -34513,27 +34555,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
34513 } else {34555 } else {
34514 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);34556 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
34515 }34557 }
34516- if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_WIDE_DUMP") {34558+ dump_prefilter_wide(&y, &u, &v);
34517- use std::io::Write;
34518- static IDX2: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
34519- let idx = IDX2.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
34520- let crop_wide = |plane: &PlaneBuf<'_>| -> Vec<u8> {
34521- let mut out = Vec::with_capacity(plane.true_width * plane.true_height);
34522- for row in 0..plane.true_height {
34523- out.extend(
34524- plane.data[row * plane.width..][..plane.true_width]
34525- .iter()
34526- .map(|&s| s as u8),
34527- );
34528- }
34529- out
34530- };
34531- if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
34532- let _ = f.write_all(&crop_wide(&y));
34533- let _ = f.write_all(&crop_wide(&u));
34534- let _ = f.write_all(&crop_wide(&v));
34535- }
34536- }
34537 // lane-av1fwd: the encoder's filter search re-decodes this same key34559 // lane-av1fwd: the encoder's filter search re-decodes this same key
34538 // frame tile per candidate -- capture it once (see [`FilterReplay`]),34560 // frame tile per candidate -- capture it once (see [`FilterReplay`]),
34539 // on the shape whose tail is the two filter calls and nothing else.34561 // on the shape whose tail is the two filter calls and nothing else.
@@ -52079,6 +52101,12 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
52079 } else {52101 } else {
52080 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);52102 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
52081 }52103 }
52104+ // lane-av1444edge: the inter-frame path's mi-aligned pre-loop-filter
52105+ // dump, the rung the key-frame path has always had (see
52106+ // `dump_prefilter_wide`). Placed beside the padded `EC_AV1_PREFILT_DUMP`
52107+ // above, i.e. before the filter pipeline is released, so the two agree on
52108+ // the point in the sequence they sample.
52109+ dump_prefilter_wide(&y, &u, &v);
52082 // lane-pipefilt: release the rows still pending and wait the pipeline52110 // lane-pipefilt: release the rows still pending and wait the pipeline
52083 // out; from here the picture is deblocked and CDEF-filtered exactly as52111 // out; from here the picture is deblocked and CDEF-filtered exactly as
52084 // the whole-frame path leaves it.52112 // the whole-frame path leaves it.