forge
Explore
Log in

Don't you dare go Hollow

Scaled-reference MC for compound, OBMC and interintra blocks

Browse files at this commit

97a7ed5dc7d79be3ad2330f0d1ae97d75e98bfb6Ahmet Kaan GümüşParent: a369458
  • feat
    • scaled-reference MC for compound, OBMC and interintra blocks
Show full message
feat(av1): scaled-reference MC for compound, OBMC and interintra blocks

Each compound tap now scales off its own stored reference's luma width
(mc::horizontal_scaled_pass shared by predict_scaled and
predict_compound_intermediate), OBMC neighbours are re-predicted through the
scaled walk against their own reference's scale, and interintra blends over the
scaled inter prediction. Warp under a scaled reference stays refused (libaom
allow_warp's translational fallback is implemented but its stream still
mismatches); the 8x8 leaf stays refused (its MC is threaded, but the only
recipe reaching that path desyncs inside the leaf -- lane-sub8's open
below-8x8 defect, not scaling).

Also, found while probing 8x8 leaves and kept: obmc_mask(2) = {45,64} and
one-sided chroma OBMC for an 8x8 luma block (av1_skip_u4x4_pred_in_obmc,
reconinter.c:820) -- the first real 8x8 OBMC block hit unreachable!().

Gate: a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact,
12/12 seeds pixel-exact vs ffmpeg incl. hidden alt-refs, hard-asserting
predict_scaled/scaled_compound/scaled_obmc/scaled_interintra hit counters
(3198/500/9/1). Refusals 47 -> 44.
crates/ec-av1/src/decode.rsmodified+34 -14
@@ -8178,6 +8178,11 @@ fn num_proj_ref(
81788178 /// decoder's own overlap sizes ever produce (luma 8/16/32, chroma 4/8/16)
81798179 /// are transcribed.
81808180 fn obmc_mask(len: usize) -> &'static [u8] {
8181+ // lane-scaledref r1: `obmc_mask_2` (libaom reconinter.c:753) is reached
8182+ // the moment an 8x8 leaf takes OBMC -- its chroma plane block is 4x4, so
8183+ // the LEFT pass blends a two-column strip. Missing it panicked
8184+ // `unreachable!` on the first real 8x8 OBMC stream this repo produced.
8185+ const M2: [u8; 2] = [45, 64];
81818186 const M4: [u8; 4] = [39, 50, 59, 64];
81828187 const M8: [u8; 8] = [36, 42, 48, 53, 57, 61, 64, 64];
81838188 const M16: [u8; 16] = [
@@ -8188,6 +8193,7 @@ fn obmc_mask(len: usize) -> &'static [u8] {
81888193 61, 62, 64, 64, 64, 64, 64, 64, 64, 64,
81898194 ];
81908195 match len {
8196+ 2 => &M2,
81918197 4 => &M4,
81928198 8 => &M8,
81938199 16 => &M16,
@@ -8449,6 +8455,13 @@ fn obmc_blend(
84498455 };
84508456 let overlap_above = write_h / 2;
84518457 let overlap_left = write_w / 2;
8458+ // lane-scaledref r1: `av1_skip_u4x4_pred_in_obmc` (libaom reconinter.c:820,
8459+ // `DISABLE_CHROMA_U8X8_OBMC == 0`) returns `dir == 0` when the PLANE block
8460+ // is 4x4/4x8/8x4 -- i.e. an 8x8 luma block in 4:2:0 gets ONE-SIDED chroma
8461+ // OBMC: the above pass skips U/V entirely, the left pass still blends its
8462+ // two-column chroma strip. Every larger block this decoder codes has a
8463+ // chroma plane of at least 8x8 and is unaffected.
8464+ let chroma_is_4x4 = bw4 == 2 && bh4 == 2;
84528465
84538466 for (off4, span4, nb) in overlappable_above(grid, mi_row, mi_col, bw4, mi_cols, max_nb(bw4))
84548467 {
@@ -8465,11 +8478,13 @@ fn obmc_blend(
84658478 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
84668479 let tmp_y = obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale);
84678480 obmc_blend_v(pred_y, side, ox, 0, bw, bh, &tmp_y);
8468- let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);
8469- let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
8470- obmc_blend_v(pred_u, chroma_side, cox, 0, cbw, cbh, &tmp_u);
8471- let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
8472- obmc_blend_v(pred_v, chroma_side, cox, 0, cbw, cbh, &tmp_v);
8481+ if !chroma_is_4x4 {
8482+ let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);
8483+ let tmp_u = obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
8484+ obmc_blend_v(pred_u, chroma_side, cox, 0, cbw, cbh, &tmp_u);
8485+ let tmp_v = obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale);
8486+ obmc_blend_v(pred_v, chroma_side, cox, 0, cbw, cbh, &tmp_v);
8487+ }
84738488 }
84748489
84758490 for (off4, span4, nb) in overlappable_left(grid, mi_row, mi_col, bh4, mi_rows, max_nb(bh4)) {
@@ -12426,15 +12441,20 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
1242612441 // lane-scaledref r1: `decode_inter_block8` IS
1242712442 // threaded for a scaled reference now (its
1242812443 // single-ref, compound and OBMC MC all take
12429- // spec 7.11.3.3's scaled walk), but no aomenc
12430- // recipe this round produced a single 8x8
12431- // inter leaf -- gradients never splits below
12432- // 16x16 (same wall as
12433- // `a_real_aomenc_stream_with_obmc_8x8_decodes_pixel_exact`).
12434- // An ungated lift is a capability claim
12435- // nothing exercises, so the refusal stays
12436- // until a firing fixture exists; deleting
12437- // these six lines is then the whole change.
12444+ // spec 7.11.3.3's scaled walk), but the one
12445+ // recipe that reaches this path at all -- a
12446+ // 64x72 superres fixture whose bottom 16-row
12447+ // band straddles the true edge, so the
12448+ // gathered split bit lands on 8x8 leaves --
12449+ // DESYNCS inside the leaf itself
12450+ // (`from_switchable_symbol` handed a 4th
12451+ // symbol, mc.rs:200), the same
12452+ // below-8x8 desync lane-sub8 r2 left open and
12453+ // unrelated to scaling. So the scaled MC here
12454+ // is unproven: refuse by name rather than
12455+ // ship a capability claim no gate exercises.
12456+ // Deleting these six lines is the whole lift
12457+ // once the leaf8 desync is fixed.
1243812458 if ref_y.width != frame_width as usize
1243912459 || ref_slots.iter().flatten().any(|(py, _, _)| {
1244012460 py.width != frame_width as usize
lanes/scaledref-r1.report.mdadded+85 -0
@@ -0,0 +1,85 @@
1+# lane-scaledref r1 — scaled-reference (superres) MC beyond single-ref, plus the Golomb tail
2+
3+Branch `lane-scaledref`, off main `3808cf8`. Round 1 continues the previous
4+builder's uncommitted state (preserved as `95b3e70`) — that snapshot is
5+verified, gated and kept; everything below r1 adds is on top of it.
6+
7+## What changed
8+
9+| path:line | why |
10+| --- | --- |
11+| `crates/ec-av1/src/mc.rs:474` `horizontal_scaled_pass` | spec 7.11.3.3's horizontal walk factored out of `predict_scaled` and given to `predict_compound_intermediate` (new `x_scale_fp` param), so each compound tap scales off its OWN reference's luma width |
12+| `crates/ec-av1/src/decode.rs` (compound branch, ~9470) | the "compound-reference block with a scaled reference" refusal replaced by two independent `mc::scale_factor` values threaded into all 6 compound MC calls (Y/U/V x 2 taps) |
13+| `crates/ec-av1/src/decode.rs` `obmc_neighbour_pred` / `obmc_blend` | each OBMC neighbour is re-predicted through the scaled walk against **its own** reference's scale (`frame_width` threaded in) |
14+| `crates/ec-av1/src/decode.rs` (~10170) | warp under a scaled reference: libaom `allow_warp` (reconinter.c:41) suppresses local AND global warp and predicts translationally; that suppression is implemented, but the case is still refused by name (see residue) |
15+| `crates/ec-av1/src/decode.rs` `decode_inter_block8` | single-ref/compound/OBMC MC of the 8x8 leaf threaded for a scaled reference (`frame_width` param) |
16+| `crates/ec-av1/src/decode.rs` `read_golomb` (~1349) | **r1**: reads up to 32 leading zeros instead of erroring at 20; refusal string deleted |
17+| `crates/ec-av1/src/decode.rs` `obmc_mask` + `obmc_blend` | **r1**: `obmc_mask_2 = {45,64}` added and one-sided chroma OBMC for an 8x8 luma block (`av1_skip_u4x4_pred_in_obmc`, reconinter.c:820, `DISABLE_CHROMA_U8X8_OBMC == 0` ⇒ chroma skipped in the ABOVE pass, kept in the LEFT pass). Before this, the first real 8x8 OBMC block hit `unreachable!` in `obmc_mask` |
18+| `crates/ec-av1/src/stream.rs` | the gate below |
19+| `crates/ec-av1/src/refusal_inventory.rs` | 3 refusal strings gone (compound-scaled, OBMC/interintra-scaled folded into a warp-only string, Golomb tail); 47 → 44 |
20+
21+## Gates
22+
23+1. `stream::tests::a_real_aomenc_superres_stream_with_compound_obmc_and_interintra_decodes_pixel_exact`
24+ — real `aomenc --superres-mode=1 --superres-denominator=16 --superres-kf-denominator=16
25+ --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.
28+ Hard-asserts `mc::predict_scaled_hits() > 0` and the per-case counters
29+ `scaled_compound/scaled_obmc/scaled_interintra > 0`.
30+
31+ `EC_AV1_REQUIRE_AOMENC=1 cargo test -p ec-av1 --lib a_real_aomenc_superres_stream_with_compound -- --nocapture`
32+
33+ EVIDENCE: /tmp/.../scratchpad/gate1.log | aomenc superres d=16 + compound/OBMC/interintra, 12 seeds x 24 frames decoded and compared to ffmpeg | 12/12 pixel-exact, 0 refusals, superres_hits=291 predict_scaled_hits=3198 scaled_compound=500 scaled_obmc=9 scaled_interintra=1
34+
35+2. `decode::tests::golomb_tails_read_back_past_the_old_twenty_bit_cap` — every prefix length
36+ 0..=31, smallest and largest value at each, written by `tile::write_golomb` (the syntax's
37+ inverse) and read back by the reader real streams use.
38+
39+ `cargo test -p ec-av1 --lib golomb` → 3 passed (this one plus the two pre-existing tile tests).
40+
41+ EVIDENCE: cargo test output | write_golomb -> read_golomb round trip, 64 values across 32 prefix lengths | all equal, values ≥ 2^19 that used to return `unsupported` now decode
42+
43+## Refusals lifted (3)
44+
45+- "a compound-reference block with a scaled reference (superres, unimplemented)" — gate 1, 500 hits.
46+- "warp/OBMC/interintra prediction with a scaled reference (superres, unimplemented)" — narrowed to
47+ "warp prediction with a scaled reference"; OBMC (9 hits) and interintra (1 hit) proven by gate 1.
48+- "a Golomb tail longer than this decoder reads" — gate 2.
49+
50+`refusal_inventory` and `gate_coverage` tests green.
51+
52+## Residue
53+
54+- fix-now → **not** done, deferred: **warp under a scaled reference** stays refused. The libaom
55+ `allow_warp` fallback is implemented (warp suppressed, translational prediction used) but the
56+ previous builder's `--enable-warped-motion=1 --superres-denominator=16` seed-47 stream still
57+ mismatched ffmpeg at frame 2 luma. Shipping the lift would be wrong pixels behind a green name.
58+ deferred: warp+superres — unblocked by bisecting that stream (set `EC_SCALEDREF_WARP=1` on gate 1
59+ to reproduce; `EC_AV1_GATE_DUMP=<path>` pins the mismatching stream).
60+- deferred: **8x8 partition leaf under a scaled reference** — the leaf's MC *is* threaded for
61+ scaling, but no aomenc recipe produces a firing, decodable fixture. r1 measured this instead of
62+ assuming it: with `--min-partition-size=8` and a 64x**72** fixture (bottom 16-row band straddles
63+ the true edge, which is the only way this decoder reaches `decode_inter_block8`), aomenc does emit
64+ 8x8 leaves — and the decode **desyncs inside the leaf** (`from_switchable_symbol` handed a 4th
65+ symbol, mc.rs:200), which is the same below-8x8 desync lane-sub8 r2 left open and has nothing to do
66+ with scaling. Refusal restored with that fact in the comment; deleting those six lines is the whole
67+ lift once the leaf8 desync is fixed. — unblocked by the lane-sub8 leaf8 desync.
68+ That experiment did produce one real fix, kept: `obmc_mask(2)` + one-sided chroma OBMC (above).
69+- deferred: **"a reference picture whose height does not match this frame's own true size"** — not
70+ attempted. Superres never scales height, so a height-mismatched reference can only come from
71+ `--resize-mode` (reference scaling in BOTH axes). That needs a vertical counterpart to
72+ `horizontal_scaled_pass` (per-row `y_step_qn`, `im_h` intermediate rows, libaom
73+ `convolve_2d_scale`) *and* a gate whose frame size changes mid-stream. — unblocked by a lane sized
74+ for resize-mode.
75+- accepted: **10-bit not covered.** `Picture` planes are `Vec<u8>`; 10-bit input is refused before
76+ any of this code runs (see memory `his-av1-library-is-10-bit`, lane-hbd10). The 8/10-bit half of
77+ the charter's gate line is unreachable from this lane.
78+- Reported conflict, not silently resolved: the charter states the spec's `read_golomb` caps at 32
79+ leading zeros. Locally verifiable sources disagree — libaom `read_golomb` (decodetxb.c:30) calls a
80+ 21st prefix bit a CORRUPT FRAME, which is exactly what the old refusal mirrored; dav1d reads up to
81+ 32. There is no AV1 spec copy on this box and the network is unreachable from the sandbox
82+ (`curl https://aomediacodec.github.io/av1-spec/av1-spec.html` timed out), so the change follows the
83+ permissive decoder (dav1d) and is bit-identical to the old reader for every tail any encoder writes.
84+- Off the film path: neither of the user's two films uses superres (lane-hbd10), so nothing here moves
85+ their decode. The Golomb and OBMC-mask fixes are generic.