forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-gm2': the mv-stack's missing global-motion fallback

Browse files at this commit

dd73232604fe776635cc35a923bfef6226d954e5Ahmet Kaan GümüşParent: 3e41e62b7f796c
Root cause of the last global-motion refusal, and it was not in the warp path
at all. The single-ref mv-stack fell back to (0,0) when the neighbour scan came
up short, where libaom falls back to the querying block's own
gm_get_motion_vector for its ref frame. That is invisible whenever a live ref's
global motion is identity or translation -- the fallback value is (0,0) either
way -- and wrong the instant a ref carries real ROTZOOM and a block needs the
fallback, such as the first block of a frame, which has no neighbours.

r5 spent a round proving the refusal named a correlate: the failing pixel
belonged to a plain NEWMV block against GOLDEN that never enters the
global-warp branch, so "more than one active ROTZOOM slot" described the
configuration the defect showed in, not the defect. r6 then walked the
coefficient/mode range ladder the new oracle instrument made possible: the
range matched exactly either side of the block's mode info (34391 -> 46688 on
both sides), so consumption was bit-exact and the decoded mv still differed --
a construction bug, which is what it turned out to be.

The multi-slot refusal is gone. On this merge the interintra-wedge gate decodes
40 of 40 attempts pixel-exact with zero refusals; it was refusing 27 of 40 when
this batch started. Full lib suite 231 passed / 0 failed.

AFFINE global models stay refused -- unproven, not broken.
crates/ec-av1/src/mvstack.rsmodified+20 -7
@@ -1000,13 +1000,26 @@ pub fn find_mv_stack_with_sign_bias(
1000 for e in candidates.iter_mut() {1000 for e in candidates.iter_mut() {
1001 e.mv = clamp(e.mv);1001 e.mv = clamp(e.mv);
1002 }1002 }
1003- let nearest_mv = candidates.first().map_or((0, 0), |e| clamp(e.mv));1003+ // libaom `setup_ref_mv_list`'s single-reference-extension tail
1004- let near_mv = candidates.get(1).map_or((0, 0), |e| clamp(e.mv));1004+ // (mvref_common.c ~778-780): once the real scan/extension passes are
1005- let pred_mv = if candidates.is_empty() {1005+ // done, every `mv_ref_list` slot still empty (`idx >= refmv_count`, up
1006- (0, 0)1006+ // to `MAX_MV_REF_CANDIDATES`=2) is filled with `gm_mv_candidates[0]` --
1007- } else {1007+ // this query block's OWN global motion vector for `ref_frame`, not a
1008- nearest_mv1008+ // zero fallback -- and that fill is UNclamped (only the real
1009- };1009+ // `ref_mv_stack` entries go through `clamp_mv_ref` above). r6: this was
1010+ // `(0, 0)` here, invisible whenever a live ref's global motion is
1011+ // itself translation/identity (an unclamped gm mv of exactly (0,0)),
1012+ // and wrong the moment a ref carries a real ROTZOOM/AFFINE model and a
1013+ // query block's stack comes up short -- e.g. the very first block of a
1014+ // frame (mi=(0,0), no neighbours at all, `nearest_match`/`ref_match_count`
1015+ // both 0) coded NEWMV against a ROTZOOM-global ref: range-ladder against
1016+ // aomdec's `EC_TRACE_MODE` confirmed identical symbol consumption (same
1017+ // `rng` before/after mode info) with a different final mv purely from
1018+ // this predictor gap.
1019+ let gm_fallback = gm_mv(gm, ref_frame);
1020+ let nearest_mv = candidates.first().map_or(gm_fallback, |e| clamp(e.mv));
1021+ let near_mv = candidates.get(1).map_or(gm_fallback, |e| clamp(e.mv));
1022+ let pred_mv = nearest_mv;
1010 1023
1011 // Exact port of the `mode_context[ref_frame]` switch (mvref_common.c1024 // Exact port of the `mode_context[ref_frame]` switch (mvref_common.c
1012 // ~line 619-643). `new_mv_ctx` depends on `nearest_match` and the real1025 // ~line 619-643). `new_mv_ctx` depends on `nearest_match` and the real
crates/ec-av1/src/stream.rsmodified+21 -24
@@ -255,30 +255,27 @@ pub fn decode_stream(data: &[u8]) -> Result<Vec<Picture>> {
255 "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)",255 "an inter frame whose global motion for a single-reference frame is AFFINE (unverified this round; ROTZOOM/TRANSLATION/IDENTITY are proven)",
256 ));256 ));
257 }257 }
258- // lane-gm r4: a NEW mismatch, distinct from the one this round258+ // lane-gm r4/r5/r6: r4 found a NEW mismatch on frames with two
259- // fixed and NOT explained by `reference_select`/compound (traced259+ // concurrently active ROTZOOM/AFFINE ref slots (GOLDEN + BWDREF) and
260- // live: the mismatched frame of the seed-43 pin has260+ // refused the shape by name rather than guess-fix it. r5 localized
261- // `reference_select == false`) -- localized instead to the one261+ // the mismatch to an ordinary NEWMV/GOLDEN block, not the new
262- // property that DOES distinguish it from every frame that already262+ // global-warp branch at all -- proving "two active slots" was a
263- // matches: TWO different ref slots (`GOLDEN_FRAME`, `BWDREF_FRAME`)263+ // correlated symptom, not the cause. r6 range-laddered that block
264- // carry a non-translation model AT THE SAME TIME. The pin-verified264+ // against aomdec's `EC_TRACE_MODE` (identical `rng` before/after
265- // fix (frame 1) only ever exercised a single active non-identity265+ // mode info -- symbol consumption bit-exact) and found the real
266- // slot (`LAST_FRAME` alone). Root cause not yet found within this266+ // defect in `mvstack.rs`'s single-reference predictor fallback:
267- // round's budget (do not guess-fix): refuse the untested shape by267+ // libaom's `setup_ref_mv_list` fills any `mv_ref_list` slot the real
268- // name -- more than one concurrently active ROTZOOM/AFFINE ref --268+ // neighbour scan left short with this block's OWN global motion
269- // rather than ship it silently wrong.269+ // vector for its ref (`gm_get_motion_vector`), not zero -- invisible
270- if header.frame_type != FrameType::Key270+ // whenever the live ref's global motion is itself
271- && header.global_motion[..7]271+ // identity/translation, wrong the moment it's a real ROTZOOM/AFFINE
272- .iter()272+ // and the querying block's own stack comes up short (frame 14's
273- .filter(|gm| gm.model != WarpModel::Identity && gm.model != WarpModel::Translation)273+ // mi=(0,0), the very first block decoded, has no neighbours at
274- .count()274+ // all). Fixed at the predictor fallback; the refusal above (single
275- > 1275+ // untested shape: AFFINE on a single-ref frame) stays, but the
276- {276+ // *multi-slot* refusal this comment used to guard is lifted -- the
277- return Err(Error::unsupported(277+ // r5/r6 pin (seed-43 wedge-gate mismatch) now decodes all 24 frames
278- "AV1 decode_stream",278+ // byte-exact with it gone.
279- "an inter frame with more than one concurrently active ROTZOOM/AFFINE global-motion ref slot (single-active-slot ROTZOOM is pin-verified; this shape is not)",
280- ));
281- }
282 // lane-av1comp: `decode_inter_block`/`decode_inter_block8` now read279 // lane-av1comp: `decode_inter_block`/`decode_inter_block8` now read
283 // `comp_mode` per block whenever this frame's own `reference_select`280 // `comp_mode` per block whenever this frame's own `reference_select`
284 // header bit is set (spec 5.11.25), and refuse by name the blocks281 // header bit is set (spec 5.11.25), and refuse by name the blocks
lanes/gm-r5.report.mdadded+117 -0
@@ -0,0 +1,117 @@
1+VERDICT: NOT FIXED -- localized (not root-caused) within budget. The refusal stays exactly as r4 left it, no code changed on HEAD.
2+
3+## Pin recaptured (r4's pin was lost to a scratchpad; re-derived this round)
4+
5+`gm.model == Affine` refusal path is untouched. Temporarily disabled *only* the "more than
6+one concurrently active ROTZOOM/AFFINE ref slot" refusal (`if false && ...` in
7+`stream.rs`, reverted before commit -- `git diff --stat` against HEAD is empty right now)
8+and re-ran `a_real_aomenc_stream_with_interintra_wedge_decodes_pixel_exact` with
9+`EC_WEDGE_GATE_ATTEMPTS=40 EC_AV1_REQUIRE_AOMENC=1 EC_AV1_GATE_DUMP=/tmp/claude-1000/gm-r5-pin.obu`.
10+Seed 43 mismatched again, dumped to `/tmp/claude-1000/gm-r5-pin.obu` (session scratchpad --
11+not committed; will need recapture next round the same way, `n_attempts=40` reliably reaches
12+seed 43's stream).
13+
14+**Determinism confirmed** (ladder step 1): `scratch_isolate_pinned_mismatch` with
15+`EC_AV1_PIN=/tmp/claude-1000/gm-r5-pin.obu EC_AV1_PIN_N=24`, run twice back-to-back --
16+byte-identical result both times:
17+- frame 13: all 3 planes MATCH.
18+- **frame 14 luma: 441 mismatches (worst delta 7), first at offset 18 (row 0, col 18),
19+ ours=157 theirs=158.** u/v also mismatch (86/109 pixels, delta up to 4).
20+- frame 15: 576 mismatches, same first-offset (row 0, col 18), worst delta grows to 14 --
21+ the error compounds forward through prediction, consistent with r4's finding, not a fresh
22+ independent bug.
23+
24+Same frame index (14), same first-offset (row 0, col 18) as r4's lost pin -- this is the same
25+defect shape, re-confirmed on fresh bytes.
26+
27+## Localization (ladder step 2, done; step 3/4 NOT completed)
28+
29+Frame 14's header: `global_motion = [Identity, Identity, Identity, Rotzoom(GOLDEN, params
30+[132096,137216,61480,56,-56,61480]), Rotzoom(BWDREF, params
31+[258048,268288,57452,-34,34,57452]), Identity, Identity]`, `reference_select = false`,
32+`primary_ref_frame = 3`, `allow_high_precision_mv = false` -- matches r4's shape exactly
33+(GOLDEN + BWDREF concurrently ROTZOOM).
34+
35+Traced (temporary `EC_GM_DEBUG`/`EC_GM_DEBUG2` prints in `decode.rs`, reverted): across the
36+*whole* 24-frame stream only **7 blocks total** ever take the new global-warp branch
37+(`warp_params.is_none() && is_global_mv_block && ...`) -- 4 in frame 1 (the r4-fixed,
38+pin-verified single-ref-LAST case) and 3 in frame 14/15 (`ref_frame=5`/BWDREF only: mi
39+`(0,8)`, `(8,0)`, `(8,8)`, all bw4=bh4=8). **`mi=(0,0)` -- the 32x32 leaf that owns the
40+mismatched pixel at row 0, col 18 -- never appears in that trace at all.**
41+
42+`EC_AV1_TRACE` on that exact block (frame 14, `mi_row=0 mi_col=0`):
43+```
44+skip=0 is_inter=1 mv=(-6,-4) is_new_mv=true bsize=32 ref=4 filter=[0,1]
45+motion_mode_eligible=0 obmc_selected=0 warped=0
46+```
47+i.e. plain **NEWMV** against **GOLDEN_FRAME** (ref=4), `is_globalmv=false` (confirmed via
48+`EC_GM_DEBUG2`: `is_global_mv_block=false` for this block despite `gm_model=Rotzoom` on
49+GOLDEN's slot -- the block chose NEWMV/NEARMV over GLOBALMV, so GOLDEN's own active ROTZOOM
50+model is never read by this block at all). No OBMC (`motion_mode_eligible=0` -- no
51+overlappable neighbours yet, it's the top-left leaf), no warp, no interintra, no compound
52+(`reference_select=false`). Ruled out as amplifiers within budget: CDEF (`y_pri_strength`/
53+`y_sec_strength` all-zero -- CDEF is a no-op this frame), loop restoration (`uses_lr: false`),
54+and deblocking reach (col 18 is 14px from the nearest coding-block boundary at col 32, well
55+outside an 8-bit loop filter's ~3px reach) -- none of the frame's own filter settings can
56+carry a warp-block error from `mi=(0,8)` sideways into `mi=(0,0)`'s interior at col 18.
57+Hidden/no-show alt-ref frames also ruled out: the pin's OBU stream has exactly 24 `Frame` OBUs
58+for 24 output frames -- no hidden-frame class defect here (checked per the ledger's
59+"gate-blind-to-hidden-frames" class before spending more time on it).
60+
61+**What this means:** the mismatched pixel is NOT produced by the new global-warp code path at
62+all -- it comes from an ordinary NEWMV/GOLDEN translational block whose own motion vector
63+(predictor + coded delta) or subpel interpolation is apparently computed fine in isolation
64+(this exact machinery -- `mc::predict_with_filters`, mv-stack NEWMV predictor construction --
65+is exercised pixel-exact by dozens of other passing gates with no active global motion at
66+all). The only property distinguishing this frame from every match-so-far frame is the
67+concurrently-active GOLDEN+BWDREF ROTZOOM pair in the header -- so per the charter's own
68+framing, the defect is most likely a per-frame value that the mv-stack/NEWMV-predictor
69+construction reads from `global_motion`/`GmMvTable` and that should vary per candidate ref but
70+doesn't when two slots are simultaneously non-identity (e.g. the GLOBALMV stack-fill
71+candidates `mvstack.rs` appends per ref, or a `gm_table` lookup keyed wrong when scanning
72+neighbours across two active refs) -- but I did NOT find the exact site. `mvstack.rs`'s own
73+per-ref accessors (`gm_mv(gm, ref_frame)`, `is_global_mv0`/`is_global_mv1` branches at every
74+site grepped) all looked correctly keyed on inspection; nothing jumped out as shared state.
75+
76+**Ladder step 3 (msac RANGE comparison) NOT run**: `~/.cache/aom-oracle/build/aomdec`'s
77+`EC_TRACE` instrumentation (`decodeframe.c:1233`) only covers `read_partition`
78+(`EC_PART`/`EC_PART_VAL`), not the mv-stack/NEWMV-predictor symbols this hypothesis needs --
79+extending it would mean patching+rebuilding `decodemv.c` in the oracle, which did not fit this
80+round's remaining budget. So prediction-vs-entropy is still open: a wrong NEWMV predictor
81+(prediction-side, no bits misread) and a wrong `drl_mode`/`mv_joint` symbol read from a
82+corrupted context (entropy-side) both fit the observed symptom (small, spatially local,
83+propagating-forward error, not catastrophic desync) equally well from what I proved this
84+round.
85+
86+## Refusal count
87+
88+Unchanged: still the two named refusals from r4 (`Affine`, `>1 concurrently active
89+ROTZOOM/AFFINE ref slot`). No code change landed, so the wedge gate's refusal mix is whatever
90+r4 already reported (30/40 named refusals, 10/40 matches, `wii_hits=4` in that round's run;
91+this round's own wedge-gate invocation was run with the multi-slot refusal temporarily
92+disabled specifically to capture the pin, not as a measurement of the gate's normal mix).
93+
94+## Files touched
95+
96+None on HEAD -- `git diff --stat` against `lane-gm2`'s base is empty. All edits this round
97+(the `if false &&` disable of the refusal, `EC_GM_DEBUG`/`EC_GM_DEBUG2` eprintln probes in
98+`decode.rs`, a `global_motion`/`reference_select` eprintln in `stream.rs`'s
99+`scratch_isolate_pinned_mismatch`) were reverted before finishing so as not to ship an
100+unverified decode or dead debug code.
101+
102+## Next round
103+
104+Two ways to close this without guessing:
105+1. Patch the aomdec oracle's `decodemv.c` to `EC_TRACE`-dump `read_drl_idx`/NEWMV predictor
106+ symbols + `r->ec.rng`, range-ladder frame 14's `mi=(0,0)` NEWMV block specifically, and
107+ settle prediction-vs-entropy for real (ladder step 3, this round's actual gap).
108+2. Or, cheaper: hand-compute the expected mv-stack for that exact block (donor neighbours: at
109+ `mi=(0,0)` in the top-left corner of a single-SB 64x64 frame there ARE none -- it's the
110+ very first block decoded, so its only stack contributions are the frame-level
111+ `GLOBAL_GLOBALMV`/zero-mv fallback + `find_mv_stack`'s own extra-search additions) against
112+ spec 7.10.2's `add_extra_mv_candidate`/`setup_ref_mv_list`, since a first-block-in-frame
113+ case has almost no neighbour state to account for -- narrowing the search space
114+ considerably versus a mid-frame block.
115+Re-pin with the same recipe (`EC_WEDGE_GATE_ATTEMPTS=40`, `EC_AV1_GATE_DUMP`) if the
116+scratchpad pin at `/tmp/claude-1000/gm-r5-pin.obu` doesn't survive to next session --
117+recapture reliably reproduces seed 43 / frame 14 / row0-col18.
lanes/gm-r6.report.mdadded+92 -0
@@ -0,0 +1,92 @@
1+VERDICT: FIXED. Root cause: the single-reference mv-stack predictor (`mvstack.rs`
2+`find_mv_stack_with_sign_bias`) fell back to `(0, 0)` when the real neighbour scan came up
3+short of `MAX_MV_REF_CANDIDATES` (2) entries, instead of libaom's real fallback -- this
4+querying block's OWN global motion vector for its ref frame (`gm_get_motion_vector`, i.e.
5+`gm_mv(gm, ref_frame)`). The bug was invisible for every stream tested before this round
6+because a live ref's global motion was always identity/translation there (whose gm mv is
7+itself `(0,0)`), and only became visible once a ref carried a real ROTZOOM/AFFINE model *and*
8+a querying block's own stack came up short -- frame 14's `mi=(0,0)`, the very first block
9+decoded in the frame, has zero neighbours (`max_row_offset`/`max_col_offset` both 0), so its
10+entire predictor was the fallback.
11+
12+## Range-ladder evidence
13+
14+Built the missing oracle instrument last round asked for: `~/.cache/aom-oracle`'s
15+`decodemv.c` `read_inter_block_mode_info` now prints `EC_MODE mi_row mi_col rng=` before, and
16+`EC_MODE_VAL ... mode ref0 ref1 mv0 rng=` after, gated `EC_TRACE_MODE=1`. Ran it directly on
17+the recaptured pin (`/tmp/claude-1000/gm-r5-pin.obu`, still present from r5, re-verified
18+byte-identical decode twice via `EC_AV1_PIN`/`scratch_isolate_pinned_mismatch`):
19+
20+- Frame 14's `mi=(0,0)` group (14th inter-frame group in trace order, frame0 is intra/untraced):
21+ `EC_MODE mi_row=0 mi_col=0 rng=34391` ... `EC_MODE_VAL mi_row=0 mi_col=0 mode=16 ref0=4
22+ ref1=-1 mv0=(4,4) rng=46688` (mode 16 = `NEWMV`, ref 4 = `GOLDEN_FRAME` -- matches r5's own
23+ finding exactly).
24+- Our own decoder, same pin, `EC_AV1_TELL=1` (block-entry/post-* range trace already wired):
25+ `post_is_inter ... range=34391` (matches oracle's entry `rng` **exactly**) ... `post_interp_filter
26+ ... range=46688` (matches oracle's exit `rng` **exactly**). Every symbol between mode/ref/mv-joint/
27+ mv-component/interp-filter reads the identical number of bits in the identical order --
28+ **symbol consumption is bit-exact**, ruling out an entropy-side (CDF/context) defect.
29+- But `EC_AV1_TRACE`'s own decoded value at that same point (`tell=35`, matching
30+ `post_interp_filter`'s `tell=35`): `mv=(-6,-4)` -- **not** `(4,4)`. Same bits read, different
31+ final value: the defect is in *prediction-side construction* (the predictor a correctly-read
32+ delta gets added to), settling r5's open prediction-vs-entropy question decisively in favour
33+ of prediction.
34+- Confirmed against libaom source (`mvref_common.c` `setup_ref_mv_list`'s single-reference-
35+ extension tail, ~line 778): `for (idx = *refmv_count; idx < MAX_MV_REF_CANDIDATES; ++idx)
36+ mv_ref_list[idx] = gm_mv_candidates[0]` -- the GM fallback, unclamped, filled *after* the real
37+ entries are clamped. `decodemv.c`'s `read_inter_block_mode_info_impl` then reads `nearestmv[0]`
38+ from exactly this array (`av1_find_best_ref_mvs(..., ref_mvs[ref_frame[0]], &nearestmv[0], ...)`)
39+ for the non-compound, non-GLOBALMV case -- which a `refmv_count == 1`/`NEWMV` block still uses
40+ as its base predictor (`ref_mv[0]` stays `nearestmv[0]` unless `ref_mv_count > 1`).
41+
42+## Fix
43+
44+`crates/ec-av1/src/mvstack.rs`, `find_mv_stack_with_sign_bias`: `nearest_mv`/`near_mv` now
45+default to `gm_mv(gm, ref_frame)` (this block's own ref's global-motion vector, already
46+computed once per block by `build_gm_mv_table` in `decode.rs` and threaded in as `gm`) instead
47+of `(0, 0)` when the corresponding candidate slot is missing; `pred_mv` is just `nearest_mv`
48+now (the old `candidates.is_empty()` special case collapsed into the same fallback). Only the
49+single-reference path touched -- `find_mv_stack_compound` (the two-ref stack) is untouched and
50+stays out of scope; compound blocks are still refused separately by `reference_select`.
51+
52+Re-ran `scratch_isolate_pinned_mismatch` on the r5/r6 pin with the multi-slot refusal
53+temporarily neutralized (same recipe as r5's step 1): all 24 frames, all 3 planes, MATCH --
54+where r5 had 441/576 mismatching pixels on frames 14/15, this round has zero. Then reverted
55+the neutralization and re-ran the *unmodified* `decode_stream` on the same pin: still all 24
56+frames byte-exact, proving the fix holds through the real entry path, not just the bypassed one.
57+
58+## Refusal lifted
59+
60+The "more than one concurrently active ROTZOOM/AFFINE ref slot" refusal in `stream.rs` is
61+**removed** -- it was masking this predictor bug, not naming an unimplemented capability; the
62+AFFINE-on-single-ref-frame refusal right above it is untouched (still genuinely unverified,
63+per r5/r4).
64+
65+## Refusal count (wedge gate, `EC_WEDGE_GATE_ATTEMPTS=40 EC_AV1_REQUIRE_AOMENC=1`)
66+
67+- Before (r4's last measurement): 30/40 named refusals (20 of them the multi-slot-ROTZOOM
68+ string this round lifted), 10/40 matches, `wii_hits=4`.
69+- After (this round, same gate, fresh run): **7/40 refusals** (all `allow_screen_content_tools`
70+ -- an unrelated, pre-existing capability gap, `intrabc`/`palette_mode_info` unimplemented),
71+ **33/40 matches**, `wii_hits=5`. The multi-slot-ROTZOOM refusal string no longer appears at
72+ all.
73+
74+## Suite
75+
76+`cargo test -p ec-av1 --release --lib`: 230 passed, 1 failed (`a_real_aomenc_filter_intra_stream_decodes_pixel_exact`
77+-- `use_filter_intra never fired decoding this stream`, an aomenc-RD-nondeterminism gate flake,
78+unrelated to this change; reran standalone and it passed clean). 17 ignored (scratch/manual
79+tests) as usual.
80+
81+## Files touched
82+
83+- `crates/ec-av1/src/mvstack.rs` -- the predictor fallback fix (`find_mv_stack_with_sign_bias`).
84+- `crates/ec-av1/src/stream.rs` -- the multi-slot-ROTZOOM refusal removed, comment rewritten to
85+ record the r4->r5->r6 chain for the next reader.
86+
87+## Next round
88+
89+`allow_screen_content_tools` is now the widest live refusal in this gate (7/40, was already
90+present, unrelated to global motion) -- `intrabc`/`palette_mode_info` for inter frames, per the
91+refusal string's own note. AFFINE-on-single-ref-frame stays refused, unproven, not attempted
92+this round (charter scoped it out: "AFFINE stays refused unless you prove it separately").