forge
Explore
Log in

Don't you dare go Hollow

A warp-capable frame under a scaled reference read the 3-symbol motion_mode_cdf where libaom reads the 2-symbol obmc_cdf

Browse files at this commit

cd8ea4672c8acdffbe725a414f59a9f4f74b7420Ahmet Kaan GümüşParent: ab8a6b9
  • fix
    • a warp-capable frame under a scaled reference read the 3-symbol motion_mode_cdf where libaom reads the 2-symbol obmc_cdf
Show full message
fix(av1): a warp-capable frame under a scaled reference read the 3-symbol motion_mode_cdf where libaom reads the 2-symbol obmc_cdf

libaom motion_mode_allowed (blockd.h:1484) drops WARPED_CAUSAL eligibility when
av1_is_scaled(block_ref_scale_factors[0]), so a superres block reads obmc_cdf.
We read motion_mode_cdf: the decoded value stayed SIMPLE_TRANSLATION, so nothing
errored -- the stream decoded "OK: 24 frames" with quietly wrong pixels from the
diverged coder state (frame 1: 1342 luma pixels off, growing to |d|=18 by frame
23). The existing warp refusal could not see it (warp_params is None there).

Gate: the superres gate now runs --enable-warped-motion=1 by DEFAULT and
hard-asserts scaled_warp_suppressed_hits() > 0 -- 12/12 pixel-exact, 25 blocks
took the obmc_cdf arm only because of this fix. decode_probe gains EC_PROBE_OUT
(raw yuv420p dump), the instrument that located it. Sibling site in
decode_inter_block8 is unreachable (refused earlier) and carries a note.
crates/ec-av1/examples/decode_probe.rsmodified+14 -1
@@ -32,7 +32,20 @@ fn main() {
3232 Ok(frames) if frames.is_empty() => {
3333 println!("OK but EMPTY: no frames -- is {path} an IVF rather than a raw OBU stream?");
3434 }
35- Ok(frames) => println!("OK: {} frames decoded", frames.len()),
35+ Ok(frames) => {
36+ // EC_PROBE_OUT=<path>: dump the decoded planes as raw yuv420p so a
37+ // stream can be diffed against ffmpeg's own decode pixel by pixel.
38+ if let Ok(out) = std::env::var("EC_PROBE_OUT") {
39+ let mut buf: Vec<u8> = Vec::new();
40+ for f in &frames {
41+ for p in [&f.y, &f.u, &f.v] {
42+ buf.extend(p.iter().map(|&s| s as u8));
43+ }
44+ }
45+ std::fs::write(&out, &buf).expect("writing EC_PROBE_OUT");
46+ }
47+ println!("OK: {} frames decoded, {}x{}", frames.len(), frames[0].width, frames[0].height)
48+ }
3649 Err(e) => println!("REFUSED: {e}"),
3750 }
3851 }
crates/ec-av1/src/decode.rsmodified+47 -0
@@ -627,6 +627,22 @@ thread_local! {
627627 static SCALED_OBMC_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
628628 static SCALED_INTERINTRA_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
629629 static SCALED_BLOCK8_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
630+ static SCALED_WARP_SUPPRESSED_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
631+ static MIXED_SCALE_COMPOUND_HITS: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
632+}
633+
634+/// Current value of [`MIXED_SCALE_COMPOUND_HITS`]: compound blocks with one
635+/// scaled and one unscaled tap.
636+pub(crate) fn mixed_scale_compound_hits() -> usize {
637+ MIXED_SCALE_COMPOUND_HITS.with(|c| c.get())
638+}
639+
640+/// Current value of [`SCALED_WARP_SUPPRESSED_HITS`]: blocks that would have
641+/// read the 3-symbol `motion_mode_cdf` but read the 2-symbol `obmc_cdf`
642+/// instead because their reference is scaled (libaom `motion_mode_allowed`,
643+/// `blockd.h:1484`).
644+pub(crate) fn scaled_warp_suppressed_hits() -> usize {
645+ SCALED_WARP_SUPPRESSED_HITS.with(|c| c.get())
630646 }
631647
632648 /// Current value of [`SCALED_COMPOUND_HITS`].
@@ -9507,6 +9523,12 @@ fn decode_inter_block(
95079523 if scale0 != mc::REF_NO_SCALE || scale1 != mc::REF_NO_SCALE {
95089524 SCALED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
95099525 }
9526+ // lane-scaledref r2: the MIXED case -- one tap scaled, the other
9527+ // not -- is the one an all-frames-scaled recipe never produces,
9528+ // and the one a single shared scale factor would get wrong.
9529+ if (scale0 == mc::REF_NO_SCALE) != (scale1 == mc::REF_NO_SCALE) {
9530+ MIXED_SCALE_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
9531+ }
95109532
95119533 let mut inter0_y = vec![0i32; side * side];
95129534 mc::predict_compound_intermediate(
@@ -10016,8 +10038,27 @@ fn decode_inter_block(
1001610038 // `motion_mode_allowed` reads the 3-symbol `motion_mode_cdf`
1001710039 // instead of the 2-symbol `obmc_cdf` exactly when
1001810040 // `num_proj_ref >= 1` under `allow_warped_motion`.
10041+ // lane-scaledref r2: libaom `motion_mode_allowed`
10042+ // (`blockd.h:1484`) requires
10043+ // `!av1_is_scaled(block_ref_scale_factors[0])` for
10044+ // WARPED_CAUSAL -- under a scaled reference (superres) the
10045+ // block reads the 2-symbol `obmc_cdf`, never the 3-symbol
10046+ // `motion_mode_cdf`. Reading the wrong alphabet here narrows
10047+ // the arithmetic coder by the wrong amount and predicts the
10048+ // rest of the tile off a diverged state: it was silently
10049+ // wrong pixels (r1's `--enable-warped-motion=1` superres
10050+ // mismatch), not a desync error.
10051+ let ref_is_scaled =
10052+ mc::scale_factor(py_ref.width, frame_width) != mc::REF_NO_SCALE;
1001910053 let warp_eligible = allow_warped_motion
10054+ && !ref_is_scaled
1002010055 && num_proj_ref(grid, mi_row, mi_col, bw4, bh4, mi_cols as usize, mi_rows as usize, ref_frame) >= 1;
10056+ if allow_warped_motion
10057+ && ref_is_scaled
10058+ && num_proj_ref(grid, mi_row, mi_col, bw4, bh4, mi_cols as usize, mi_rows as usize, ref_frame) >= 1
10059+ {
10060+ SCALED_WARP_SUPPRESSED_HITS.with(|c| c.set(c.get() + 1));
10061+ }
1002110062 if warp_eligible {
1002210063 let mode = dec.symbol(&mut cdfs.motion_mode[bsize_idx]);
1002310064 match mode {
@@ -11409,6 +11450,12 @@ fn decode_inter_block8(
1140911450 // lane-warp round 1: same 3-vs-2-symbol split as the 16x16+ leaf
1141011451 // (see its own doc) -- this leaf is always `LAST_FRAME`-only
1141111452 // (grid.set below hardcodes it).
11453+ // lane-scaledref r2 sibling of the 16x16+ leaf's fix: libaom
11454+ // drops WARPED_CAUSAL eligibility (so this reads `obmc_cdf`)
11455+ // when the reference is scaled. Not gated here because an 8x8
11456+ // leaf under a scaled reference is refused before this function
11457+ // runs (see the block8 refusal below, ~12500) -- whoever lifts
11458+ // that refusal must add `&& !ref_is_scaled` here too.
1141211459 let warp_eligible = allow_warped_motion
1141311460 && num_proj_ref(grid, mi_row, mi_col, 2, 2, mi_cols as usize, mi_rows as usize, LAST_FRAME) >= 1;
1141411461 if warp_eligible {
crates/ec-av1/src/stream.rsmodified+32 -12
@@ -5079,12 +5079,21 @@ mod tests {
50795079 let on = |name: &str| {
50805080 if std::env::var(name).as_deref() == Ok("0") { "0" } else { "1" }
50815081 };
5082- // warp stays OFF: warp under a scaled reference is still refused
5083- // (its own fallback mismatches, see decode.rs) -- set
5084- // EC_SCALEDREF_WARP=1 to reproduce that residue.
5085- let warp = format!(
5086- "--enable-warped-motion={}",
5087- if std::env::var("EC_SCALEDREF_WARP").as_deref() == Ok("1") { "1" } else { "0" }
5082+ // lane-scaledref r2: warp is ON. A warp-capable frame header
5083+ // under a scaled reference is exactly the case r1 got wrong
5084+ // (the block must read the 2-symbol `obmc_cdf`, not the
5085+ // 3-symbol `motion_mode_cdf` -- libaom `motion_mode_allowed`,
5086+ // blockd.h:1484), and it decoded silently wrong pixels rather
5087+ // than refusing. `EC_SCALEDREF_WARP=0` turns it off for
5088+ // bisecting only.
5089+ let warp = format!("--enable-warped-motion={}", on("EC_SCALEDREF_WARP"));
5090+ // lane-scaledref r2: `EC_SCALEDREF_MODE=3` (qthresh) lets
5091+ // superres switch on and off per frame, so a compound block can
5092+ // reference one scaled and one unscaled reference -- the mixed
5093+ // case mode 1 (every frame scaled) never produces.
5094+ let superres_mode = format!(
5095+ "--superres-mode={}",
5096+ std::env::var("EC_SCALEDREF_MODE").unwrap_or_else(|_| "1".into())
50885097 );
50895098 let obmc = format!("--enable-obmc={}", on("EC_SCALEDREF_OBMC"));
50905099 let interintra = format!("--enable-interintra-comp={}", on("EC_SCALEDREF_II"));
@@ -5111,7 +5120,7 @@ mod tests {
51115120 // still refuses on the aligned path ("an inter partition
51125121 // below 16x16"). Denominator 12 codes 43 columns and every
51135122 // seed refused there.
5114- "--superres-mode=1",
5123+ &superres_mode,
51155124 "--superres-denominator=16",
51165125 "--superres-kf-denominator=16",
51175126 // the four combinations this round lifts (each switchable
@@ -5211,7 +5220,7 @@ mod tests {
52115220 eprintln!(
52125221 "{NAME}: {named_refusals} other-capability refusals, {matched}/{n_attempts} pixel-exact, \
52135222 superres_hits={} predict_scaled_hits={} scaled_compound={} scaled_warp_fallback={} \
5214- scaled_obmc={} scaled_interintra={} scaled_block8={}",
5223+ scaled_obmc={} scaled_interintra={} scaled_block8={} scaled_warp_suppressed={} mixed_scale_compound={}",
52155224 crate::superres::superres_hits(),
52165225 crate::mc::predict_scaled_hits(),
52175226 crate::decode::scaled_compound_hits(),
@@ -5219,6 +5228,8 @@ mod tests {
52195228 crate::decode::scaled_obmc_hits(),
52205229 crate::decode::scaled_interintra_hits(),
52215230 crate::decode::scaled_block8_hits(),
5231+ crate::decode::scaled_warp_suppressed_hits(),
5232+ crate::decode::mixed_scale_compound_hits(),
52225233 );
52235234 assert!(
52245235 matched > 0,
@@ -5228,10 +5239,19 @@ mod tests {
52285239 crate::mc::predict_scaled_hits() > 0,
52295240 "{NAME}: matched but zero predict_scaled_hits -- no block took the scaled MC path"
52305241 );
5231- // Warp and the 8x8 leaf are NOT asserted here: both stay refused this
5232- // round (warp's own fallback mismatches at seed 47, and no recipe
5233- // produced an 8x8 inter leaf at all), so their counters are
5234- // diagnostics only -- see this gate's own doc and decode.rs.
5242+ // The 8x8 leaf is NOT asserted here: it stays refused (no recipe
5243+ // produced an 8x8 inter leaf at all), so its counter is a
5244+ // diagnostic only -- see this gate's own doc and decode.rs.
5245+ // `scaled_warp_suppressed` IS asserted: it counts the blocks whose
5246+ // WARPED_CAUSAL eligibility libaom drops because the reference is
5247+ // scaled, i.e. the blocks that must read `obmc_cdf`. Zero of them
5248+ // would mean this gate's `--enable-warped-motion=1` never reached a
5249+ // warp-eligible block and proves nothing about r2's fix.
5250+ assert!(
5251+ crate::decode::scaled_warp_suppressed_hits() > 0,
5252+ "{NAME}: {matched} matches but no block had its warp eligibility \
5253+ suppressed by a scaled reference -- the warp arm proves nothing"
5254+ );
52355255 for (hits, what) in [
52365256 (crate::decode::scaled_compound_hits(), "compound with a scaled reference"),
52375257 (crate::decode::scaled_obmc_hits(), "OBMC with a scaled reference"),
lanes/scaledref-r1.report.mdmodified+4 -2
@@ -23,8 +23,10 @@ verified, gated and kept; everything below r1 adds is on top of it.
2323 1. `stream::tests::a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact`
2424 — real `aomenc --superres-mode=1 --superres-denominator=16 --superres-kf-denominator=16
2525 --auto-alt-ref=1 --lag-in-frames=25 --enable-obmc=1 --enable-interintra-comp=1
26- --enable-smooth-interintra=1`, 12 seeds x 24 frames of 64x64 moving gradients, every frame
27- (hidden alt-refs included, `decode_stream` decodes the whole OBU sequence) compared to ffmpeg.
26+ --enable-smooth-interintra=1`, 12 seeds x 24 frames of 64x64 moving gradients, every SHOWN frame
27+ compared to ffmpeg (corrected in r2: `decode_stream` pushes a picture only under
28+ `show_frame`, stream.rs:711, and `ffmpeg -f obu` emits shown frames only -- a hidden
29+ alt-ref is checked only through propagation into the frames that reference it).
2830 Hard-asserts `mc::predict_scaled_hits() > 0` and the per-case counters
2931 `scaled_compound/scaled_obmc/scaled_interintra > 0`.
3032
lanes/scaledref-r2.report.mdadded+85 -0
@@ -0,0 +1,85 @@
1+# lane-scaledref r2 — warp-capable frame under a scaled reference read the wrong motion_mode alphabet
2+
3+Branch `lane-scaledref` (HEAD back on the branch: the verifier left the worktree detached at
4+a8111dd; `git checkout lane-scaledref` restored it, both were the same commit, no work lost).
5+
6+## Verifier finding 1 — ROOT CAUSE FOUND AND FIXED (no refusal needed)
7+
8+The verifier's premise was that "motion_mode symbol reading is unaffected; only the prediction
9+falls back". That is **false**, and it is the whole defect. libaom
10+`motion_mode_allowed` (oracle source `av1/common/blockd.h:1484-1487`):
11+
12+```c
13+ if (mbmi->num_proj_ref >= 1 && allow_warped_motion &&
14+ !xd->cur_frame_force_integer_mv &&
15+ !av1_is_scaled(xd->block_ref_scale_factors[0])) {
16+ return WARPED_CAUSAL;
17+ }
18+ return OBMC_CAUSAL;
19+```
20+
21+Under a scaled reference the block reads the **2-symbol `obmc_cdf`**, never the 3-symbol
22+`motion_mode_cdf`. We read the 3-symbol one, which narrows the arithmetic decoder by the wrong
23+amount: the decoded *value* happened to stay SIMPLE_TRANSLATION, so nothing ever errored — the
24+stream decoded "OK: 24 frames" with quietly wrong pixels, exactly the silent-wrong-pixels class
25+the verifier caught. The warp guard at decode.rs ~10197 could never see it: `warp_params` is
26+`None` for those blocks (`warped=0` in EC_AV1_TRACE), so no fallback and no refusal ran.
27+
28+| path:line | why |
29+| --- | --- |
30+| `crates/ec-av1/src/decode.rs` ~10060 (`warp_eligible`) | `&& !ref_is_scaled` added (`mc::scale_factor(py_ref.width, frame_width) != REF_NO_SCALE`), libaom-exact; new `SCALED_WARP_SUPPRESSED_HITS` counts the blocks that take the `obmc_cdf` arm because of it |
31+| `crates/ec-av1/src/decode.rs` ~630 | the counter + `scaled_warp_suppressed_hits()` / `mixed_scale_compound_hits()` accessors |
32+| `crates/ec-av1/src/decode.rs` ~9515 | `MIXED_SCALE_COMPOUND_HITS`: compound blocks with exactly one scaled tap (diagnostic for finding 3) |
33+| `crates/ec-av1/src/decode.rs` ~11455 (`decode_inter_block8`) | sibling site of the same shape, comment only: an 8x8 leaf under a scaled reference is refused before this code runs, so the same `&& !ref_is_scaled` is owed by whoever lifts that refusal |
34+| `crates/ec-av1/src/stream.rs` (superres gate) | `--enable-warped-motion=1` is now the DEFAULT arm (`EC_SCALEDREF_WARP=0` only for bisecting), `--superres-mode` made settable (`EC_SCALEDREF_MODE`), and `scaled_warp_suppressed_hits() > 0` is hard-asserted so the warp arm cannot pass vacuously |
35+| `crates/ec-av1/examples/decode_probe.rs` | `EC_PROBE_OUT=<path>` dumps the decoded planes as raw yuv420p — that is the instrument that located this defect (diff vs `ffmpeg -f obu`) |
36+| `lanes/scaledref-r1.report.md` | finding 2, wording corrected (below) |
37+
38+Not changed, reported instead of silently fixed: libaom also requires `!cur_frame_force_integer_mv`
39+in that same condition and our `warp_eligible` still omits it. Left alone this round — no gate
40+covers `force_integer_mv` (screen content), and changing an alphabet choice without a gate is the
41+mistake this round is fixing. deferred: force_integer_mv warp eligibility — unblocked by a
42+screen-content gate with `cur_frame_force_integer_mv=1`.
43+
44+Refusals: **none lifted, none added**, 45 unchanged. `refusal_inventory` / `gate_coverage`
45+untouched and green (see totals). The "warp prediction with a scaled reference" refusal stays: it
46+now only guards a *global*-warp block under a scaled reference, which this recipe never produced
47+(`scaled_warp_fallback=0`).
48+
49+EVIDENCE: /tmp/.../scratchpad/warp_superres.obu + ours2.yuv vs ff.yuv | EC_PROBE_OUT decode of the verifier's pinned stream, byte-compared to `ffmpeg -f obu -pix_fmt yuv420p -f rawvideo` | before: frames 1..23 differ (frame 1: 1342 luma + 370 chroma pixels, first at (2,26), max |d| 3, growing to 18 by frame 23); after the fix: `cmp` identical, 147456/147456 bytes
50+
51+EVIDENCE: gate run, this report | `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib a_real_aomenc_superres_stream_with_compound -- --nocapture` (warp now on by default) | `0 other-capability refusals, 12/12 pixel-exact, superres_hits=291 predict_scaled_hits=3198 scaled_compound=500 scaled_warp_fallback=0 scaled_obmc=9 scaled_interintra=1 scaled_block8=0 scaled_warp_suppressed=25 mixed_scale_compound=0` — 25 blocks took the `obmc_cdf` arm only because of this fix
52+
53+## Verifier finding 2 — report correction (done)
54+
55+`lanes/scaledref-r1.report.md` line ~27 now reads "every SHOWN frame compared to ffmpeg ... a
56+hidden alt-ref is checked only through propagation" (ledger already records
57+`decode_stream` pushes only under `show_frame`, stream.rs:711).
58+
59+## Verifier finding 3 — mixed scaled/unscaled compound taps: DEFERRED, measured not assumed
60+
61+Counter `mixed_scale_compound` added and wired into the gate's print; both alternative recipes were
62+run, neither yields a gateable stream:
63+
64+- `EC_SCALEDREF_MODE=3` (qthresh): aomenc never turns superres on for this content/q —
65+ `superres_hits=0 predict_scaled_hits=0`, i.e. the whole gate goes vacuous (it fails its own
66+ `predict_scaled_hits > 0` assert, which is the assert working).
67+- `EC_SCALEDREF_MODE=2` (random denominator per frame): produces coded widths that are not
68+ multiples of 32, so the frame edge forces sub-16 partitions and the stream stops at the still-open
69+ named refusal `an 8x8 partition leaf under a scaled reference (superres, unimplemented)` at
70+ seed 42.
71+
72+deferred: mixed one-scaled-one-unscaled compound tap — unblocked by the leaf8 desync (lane-sub8),
73+which is what mode-2 recipes hit; the counter is in place so any future recipe proves the case
74+immediately. The per-tap code itself is r1's (`scale0`/`scale1` are already independent).
75+
76+## Test totals
77+
78+`EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib` (whole crate lib suite): **268 passed, 0 failed, 23 ignored**, 968s (same totals as r1, now with the warp arm of the superres gate ON). Run at the final tree.
79+
80+## Residue carried from r1 (unchanged)
81+
82+- deferred: 8x8 partition leaf under a scaled reference — unblocked by the lane-sub8 leaf8 desync.
83+- deferred: reference scaling in BOTH axes (`--resize-mode`) — unblocked by a lane sized for it.
84+- accepted: 10-bit is refused upstream (`Picture` planes are `Vec<u8>`).
85+- accepted: the Golomb-tail cap stays where r1 left it (it masks an intra-rect64 defect).