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