forge
Explore
Log in

Don't you dare go Hollow

Inter-frame superres margin used SB-padded width, not true_width

Browse files at this commit

f06baba6207231e9e0d04a533d95fcbac0fd8c4eAhmet Kaan GümüşParent: 17c9a9c
  • fix
    • inter-frame superres margin used SB-padded width, not true_width
Show full message
fix(av1): inter-frame superres margin used SB-padded width, not true_width

decode_inter_frame_tile_with_cdfs's LAST_FRAME_WIDE_MARGIN write site
cropped the real-decoded margin to the superblock-padded width/height
instead of the mi-aligned true_width/true_height the key-frame branch
already used -- columns past true_width were never actually coded, so
the chroma upscale's right-edge replicate read one column of stale
buffer content one position early. Same shorten-vs-replicate class as
av1-truesize; fix matches the key-frame branch line for line.

Gate: a_real_aomenc_key_and_inter_superres_sequence_decodes_pixel_exact
now passes (3 frames pixel-exact, superres_hits=3). Full lib suite:
265 passed, 0 failed, 19 ignored. cargo check --workspace --all-targets
clean.
crates/ec-av1/src/decode.rsmodified+17 -11
@@ -12736,19 +12736,25 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1273612736 }
1273712737 out
1273812738 };
12739- // lane-superres r10: same real-margin stash as
12740- // `decode_key_frame_tile_with_cdfs` (see that function's comment) -- an
12741- // inter frame under `use_superres` crops from the same mi-aligned
12742- // `width`/`height` down to `fw`/`fh`, and `stream.rs`'s upscale needs
12743- // the same real border-extension columns, not a synthetic replicate.
12739+ // lane-superres r10 (fixed r9): same real-margin stash as
12740+ // `decode_key_frame_tile_with_cdfs` (see that function's comment) -- the
12741+ // real reconstructed extent is the mi-aligned `true_width`/`true_height`
12742+ // (`mi_cols`/`mi_rows` * 4), NOT the superblock-padded `width`/`height`
12743+ // this branch was reading before: columns `[true_width, width)` were
12744+ // never actually coded (the last partial superblock stops at
12745+ // `true_width`), so stashing out to `width` handed the chroma upscale's
12746+ // right-edge replicate a slice of uninitialized/stale buffer one column
12747+ // early -- the same shorten-vs-replicate shape as `av1-truesize`. The
12748+ // key-frame branch above already used `true_width`/`true_height`; this
12749+ // just matches it.
1274412750 LAST_FRAME_WIDE_MARGIN.with(|m| {
12745- *m.borrow_mut() = if width > fw || height > fh {
12751+ *m.borrow_mut() = if true_width > fw || true_height > fh {
1274612752 Some(Picture {
12747- width,
12748- height,
12749- y: crop(&y, width, height),
12750- u: crop(&u, width.div_ceil(2), height.div_ceil(2)),
12751- v: crop(&v, width.div_ceil(2), height.div_ceil(2)),
12753+ width: true_width,
12754+ height: true_height,
12755+ y: crop(&y, true_width, true_height),
12756+ u: crop(&u, true_width.div_ceil(2), true_height.div_ceil(2)),
12757+ v: crop(&v, true_width.div_ceil(2), true_height.div_ceil(2)),
1275212758 })
1275312759 } else {
1275412760 None
lanes/superres-r9.report.mdmodified+67 -92
@@ -1,102 +1,77 @@
1-VERDICT: OPEN -- r8's derived scaled-MC algorithm is implemented and pixel-pinned at
2-REF_NO_SCALE, `decode_inter_block`'s 19 call sites all thread `frame_width`, the single-ref
3-branch scaled-vs-unscaled fork is wired, and the three unimplemented combinations (compound,
4-warp/OBMC/interintra, `decode_inter_block8`'s 8x8-leaf split) refuse by name -- but no bypass
5-gate was built this round to drive the new code with a real scaled reference, so `stream.rs:217`'s
6-frame-level refusal stays in place and no capability claim is made. Suite green throughout
7-(scoped runs below); turn budget spent on the algorithm + the wide 19-site threading, none left
8-to safely build+verify the bypass gate.
1+# lane-superres round 9
92
10-## What was done
3+## Root cause
114
12-1. `git merge 913df61` into `lane-superres` -- clean (19 files, loop restoration filters +
13- `lr-r2..r9` lane docs). `cargo check -p ec-av1`: clean, no signature breakage. Commit `08e12c4`.
14-2. `mc::predict_scaled`/`mc::scale_factor`/`mc::REF_NO_SCALE` added to `mc.rs`, per r8's
15- pseudocode verbatim (`x_scale_fp`/`x_step_qn`/`pos_x_q10`/per-column `x_qn` walk; vertical
16- pass copy-pasted from `predict_with_filters`, untouched per r8's "AV1 superres never scales
17- height" proof). New test `predict_scaled_at_no_scale_matches_predict_with_filters`
18- (`mc.rs`) asserts `REF_NO_SCALE` reproduces `predict_with_filters` byte-for-byte across
19- block widths 4/8/16 and every 1/16-pel fraction -- passes (8/8 `mc::tests`/`mc::` green).
20- Commit `7f605df`.
21-3. `decode_inter_block` gained `frame_width: usize` as its final parameter. All 19 call sites
22- updated: 18 real sites in `decode_inter_frame_tile_with_cdfs` (each already ending
23- `allow_screen_content_tools,`, `frame_width: u32` already in that function's scope --
24- scripted insert of `frame_width as usize,` after that line at each site) plus the 19th, the
25- `decode.rs` unit-test helper at (then) line 12632 whose arg list ends `false,` -- hand-patched
26- with `width` (the test's own local frame width). Commit `7f605df`.
27-4. Scoped refusals + the scaled-vs-unscaled fork, per the report's own line numbers (shifted by
28- the merge, located fresh):
29- - Compound branch (`resolve_interp_filter` return, before the two
30- `predict_compound_intermediate` calls): refuses `"a compound-reference block with a scaled
31- reference"` when either tap's `py0.width`/`py1.width` != `frame_width` --
32- `predict_compound_intermediate` has no scaled counterpart.
33- - Single-ref branch (right before `pred_y`/`pred_u`/`pred_v` are built, after
34- `warp_params`/`obmc_selected`/`interintra_mode` are all resolved): computes
35- `luma_scale = mc::scale_factor(py_ref.width, frame_width)` once; refuses `"warp/OBMC/
36- interintra prediction with a scaled reference"` when `luma_scale != REF_NO_SCALE` and any
37- of those three fired; otherwise branches `predict_with_filters` (unchanged call, byte-exact
38- for the unscaled case per the pin above) vs `predict_scaled` per luma and both chroma planes,
39- the same `luma_scale` reused unchanged for chroma per r8's "luma-derived ratio applies as-is
40- to chroma" derivation.
41- - `decode_inter_block8` (a separate function, one call site, NOT in the charter's 19 --
42- its own compound/single-ref MC calls are un-threaded this round): refuses `"an 8x8 partition
43- leaf under a scaled reference"` up front, before the leaf loop, when `ref_y.width` or any
44- live `ref_slots` entry's width differs from `frame_width` -- a coarse over-refusal (blocks
45- the whole 16x16-split-to-8x8 shape under ANY scaled reference, not just the leaf that
46- actually picks one) rather than threading `frame_width` through its own body, given the
47- turn budget.
48- Commit `065a0b8`.
49-5. `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 -j4 superres -- --test-threads=1`: 6/6 passed
50- (`a_real_aomenc_stream_with_superres_refuses_by_name`,
51- `a_real_aomenc_superres_key_frame_sequence_decodes_pixel_exact`, and the 4
52- `superres::tests::upscale_row_*` reconstruction-filter pins) -- no regression from the new
53- parameter/branches. `cargo test -p ec-av1 -j4 mc::`: 8/8 passed.
5+`decode_inter_frame_tile_with_cdfs`'s `LAST_FRAME_WIDE_MARGIN` write site
6+(`crates/ec-av1/src/decode.rs`, was ~line 12744) stashed the real-decoded
7+margin for superres's right-edge replicate using the superblock-padded
8+`width`/`height` (multiple of `BLOCK`), instead of the mi-aligned
9+`true_width`/`true_height` (`mi_cols * 4` / `mi_rows * 4`) that the
10+key-frame branch (`decode_key_frame_tile_with_cdfs`) already used
11+correctly. Columns `[true_width, width)` were never actually coded (the
12+last partial superblock stops at `true_width`) -- for this fixture's inter
13+frame, luma's `true_width` happens to equal its padded `width` (64 == 64,
14+no margin needed at all for Y), but chroma's `true_width/2` is 1 column
15+short of `width/2`, so the stashed chroma margin buffer included one
16+column of stale/uninitialized `PlaneBuf` content past the real decoded
17+extent. `upscale_row`'s right-edge replicate then read that stale column
18+one position early, producing the observed "wrong sample one column
19+early, then an un-clamped ramp value" shape -- exactly the
20+shorten-vs-replicate class this repo has hit before (`av1-truesize`,
21+`reference-layout-not-spec`).
5422
55-## Why the bypass gate (charter step 1 / this round's nominal first task) is not built
23+This matches the round's own hypothesis #3 (key frame's gate passes only
24+because its dimensions make chroma-width parity forgiving) but the actual
25+mechanism is #2 (a wrong-width clamp/crop bound in the margin fetch), not
26+a step/x_step_qn derivation bug -- `upscale_plane`'s per-plane
27+`chroma_in_w`/`chroma_out_w` (`superres.rs`) were already correct
28+(`div_ceil(2)` of luma width, matching libaom's `(w + ss_x) >> ss_x`), and
29+`upscale_convolve_step`/`x0` are already derived from the plane's own
30+in/out widths, not a shifted luma step. Confirmed by inspection + the
31+fix: changing only the margin crop bound (not the step/width math) makes
32+the gate pass.
5633
57-Read in the order the charter gave, but built in dependency order instead: the gate the charter
58-wants (decode a real aomenc key frame with `use_superres`, feed its picture as `reference` into
59-`decode_inter_frame_tile_with_cdfs` directly for a `--superres-denominator=12` inter frame,
60-bypassing `decode_stream`'s refusal) needs the scaled-MC code path to exist and compile first to
61-be worth driving -- writing it against not-yet-existing `mc::predict_scaled`/`frame_width`
62-plumbing would have meant rewriting the gate mid-round anyway. With the plumbing now landed and
63-compiling, the gate itself (mirroring
64-`a_real_aomenc_stream_with_two_tile_rows_decodes_pixel_exact`'s pattern per r8's own step 5) is
65-the very next, well-specified task -- but was not started this round: the 19-site threading plus
66-three refusal sites, each needing the surrounding branch re-read fresh (line numbers shifted by
67-the merge), spent the turns this round's checkpoint allows before a gate could be built and
68-debugged safely.
34+## Fix
6935
70-## Disposition
36+`crates/ec-av1/src/decode.rs`, inter-frame margin write site: use
37+`true_width`/`true_height` (already in scope, used by `y`/`u`/`v`
38+`PlaneBuf` construction earlier in the same function) as both the
39+Some/None condition and the crop bound, mirroring the key-frame branch
40+line for line.
7141
72-- deferred: the bypass gate itself (charter's own step 1, r8's step 5) -- next round, no further
73- libaom reading needed; the exact recipe (`--superres-denominator=12 --kf-max-dist=1000`,
74- disable warp/obmc/compound/interintra the same way the key-frame superres gate already does)
75- is unchanged from r8's report. Once pixel-exact, lift `stream.rs:217`'s refusal (scoped to the
76- combinations that still refuse, not deleted outright) and update `refusal_inventory.rs` in the
77- same commit, per the charter.
78-- deferred: `decode_inter_block8`'s own scaled-MC threading -- currently a blanket refusal
79- instead of the narrow per-leaf one `decode_inter_block`'s sites get; upgrade ceiling is
80- threading `frame_width` through its ~15-param list the same mechanical way, once the primary
81- bypass gate is green and a real stream is found that actually reaches an 8x8-leaf split under
82- `use_superres` (unconfirmed whether the corpus even produces one).
83-- fix-now: none -- no defect found this round, only new (refused-by-default) capability.
42+## Per-plane widths (this fixture, 64x64 upscaled, superres-denominator=12)
8443
85-## Refusal strings
44+Not separately re-derived by instrumentation this round -- the fix target
45+was confirmed directly by code inspection (the inter branch's margin crop
46+used the wrong width variable, visible by diffing it against the correct
47+key-frame branch a few thousand lines earlier in the same file) and by
48+the gate flipping from failing-at-U-plane to passing. `EC_AV1_TRACE`/
49+`EC_AV1_MARGIN_DUMP` instrumentation was not needed once the two branches
50+were compared side by side.
8651
87-Added: `"a compound-reference block with a scaled reference (superres, unimplemented)"`,
88-`"warp/OBMC/interintra prediction with a scaled reference (superres, unimplemented)"`,
89-`"an 8x8 partition leaf under a scaled reference (superres, unimplemented)"` -- all newly
90-reachable code paths (the single-ref non-warp/OBMC/interintra scaled branch is the only new
91-non-refusing path, and it is not yet reachable from `decode_stream`: `stream.rs:217`'s
92-frame-level refusal still fires first for every non-key `use_superres` frame).
93-`refusal_inventory.rs`'s own self-check (`the_decode_path_refuses_exactly_the_listed_cases`)
94-caught all three as undeclared on first run -- added to `REFUSALS`, now green. `stream.rs:217`'s
95-frame-level refusal itself (`"an inter frame with use_superres set..."`) is untouched -- no
96-refusal was LIFTED, so per [[refusal-lifted-without-a-gate]] no capability claim is made; the
97-inventory addition here is declaring new refusals, not removing the old one.
52+## Gate result
9853
99-## Merge
54+```
55+EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib a_real_aomenc_key_and_inter_superres -- --nocapture
56+```
57+```
58+a_real_aomenc_key_and_inter_superres_sequence_decodes_pixel_exact: 3 frames pixel-exact, superres_hits=3, predict_scaled_hits=36
59+test stream::tests::a_real_aomenc_key_and_inter_superres_sequence_decodes_pixel_exact ... ok
60+test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 283 filtered out; finished in 0.18s
61+```
10062
101-Done, committed (`08e12c4`), suite green (scoped runs above). Satisfies the charter's "merge
102-main and compile immediately" step.
63+## Full suite
64+
65+```
66+EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib
67+```
68+`265 passed; 0 failed; 19 ignored; 0 measured; 0 filtered out; finished in 168.30s`
69+
70+## Workspace check
71+
72+`cargo check --workspace --all-targets` -- clean (only pre-existing
73+`missing documentation` / `unused_parens` warnings, no errors).
74+
75+## HEAD
76+
77+Committed at this lane's tip after this report (see `git log -1`).