forge
Explore
Log in

Don't you dare go Hollow

Sub-8x8 and inter blocks never cleared the palette neighbour bands

Browse files at this commit

66e8f70fda09c108e8a575646f93935f3ace23faAhmet Kaan GümüşParent: 8c86470
  • fix
    • sub-8x8 and inter blocks never cleared the palette neighbour bands
Show full message
fix(av1): sub-8x8 and inter blocks never cleared the palette neighbour bands

A palette-Y block left its size and colours standing in the mi-granular
above/left palette bands: the sub-8x8 leaves and every inter block reader
published skip/lf/mode state but no palette state, while libaom's mi grid
carries palette_size 0 in exactly those cells. The next intra block then read
palette_y_mode off CDF row 1 where libaom reads row 0, decoded a palette libaom
never coded and skipped the use_filter_intra symbol a palette block has none of
-- one symbol short, tile desynced (class cdf-row-held-constant).

Measured on an instrumented aomdec: key frame block mi(76,88), ctx 0 vs ours 1.

external_ladder now decodes every reference ladder point through decode_stream
and asserts it sample-exact against ffmpeg.
lanes/dkey.report.mdadded+92 -0
@@ -0,0 +1,92 @@
1+# lane-dkey — palette state never cleared by sub-8x8 / inter blocks
2+
3+## Root cause (closed, measured)
4+
5+`crates/ec-av1/src/decode.rs`: the mi-granular above/left **palette bands**
6+(`Neighbours::above_palette_size/colors`, `left_palette_*`) were written ONLY by
7+the >=8x8 intra readers. Every other block reader — the sub-8x8 leaves
8+(`decode_leaf_split4`, `decode_leaf_rect8`, `decode_intra_sub8_leaf`,
9+`decode_inter_sub8_split4`, `decode_inter_sub8_rect2`) and the inter block
10+readers (`decode_inter_block`, `decode_inter_block8`) — left the previous
11+block's palette size/colours standing in those cells. libaom's mi grid says
12+`palette_size == 0` there (`av1_allow_palette` needs BLOCK_8X8 and up; an inter
13+block has no palette at all), so the NEXT block's `av1_get_palette_mode_ctx`
14+and `av1_get_palette_cache` read 0 where ours read the stale neighbour.
15+
16+**Class: `cdf-row-held-constant`** (a context read off a table row libaom never
17+selects), with the same shape as `trial-map-not-restored`: state published by
18+one block path and never cleared by the paths that cannot produce it.
19+
20+## First differing symbol (measured, two instrumented decoders)
21+
22+Synthetic 1920x1024 libaom stream (`-cpu-used 6 -crf 35 -g 12`, dark
23+screen-content-detected source), KEY frame, block **mi(76,88)**, BLOCK_16X16,
24+DC_PRED:
25+
26+* both decoders identical through `skip/cdef/dq/mode/angle_y/uv_mode/angle_uv`
27+ (`rng=41844`);
28+* aomdec `EC_PALSYN_AOM mi=76,88 bsize=6 mode=0 uv=0 ctx=0 y=0` — palette ctx 0,
29+ no palette, then `EC_ISTEP name=use_filter_intra val=0 rng=57408`;
30+* ours `TRACE pre_palette_y_mode bsize_ctx=2 mode_ctx=1` → `palette_y_mode
31+ value=1` → decoded a 2-colour palette and its whole colour-index map, and
32+ then **skipped the `use_filter_intra` symbol** (a palette-Y block has none).
33+* the stale `mode_ctx=1` came from the 8x8 palette block at mi(72,88); the 4x4
34+ group at mi(74,88) between them published nothing.
35+
36+One symbol short → tile desync → whole-frame mismatch from that block on.
37+
38+## Fix
39+
40+Publish the block's own zeros from every reader that cannot code palette, at
41+the same footprint it publishes skip/lf state (7 sites, `record_palette_y_rect`
42+/ `record_palette_uv_rect` with `size = 0`). `decode_block_128rect` already did
43+exactly this ("the unconditional stamp clears any stale neighbour palette
44+state, as every other block path does") — the comment was true of the >=8x8
45+paths only.
46+
47+## Sweep
48+
49+`fill_skip_grid*` (every leaf block publishes it) vs `record_palette_*` over
50+all 16 block readers: 9 readers had skip but no palette publication. Fixed the
51+7 that provably code no palette. **Remaining, deferred:** `decode_rect_split`,
52+`decode_leaf_rect`, `decode_block_rect4`, `decode_rect4_16_strip` and
53+`decode_intra_rect_in_inter` are >=8x8 intra readers that CAN code palette
54+(`decode_intra_rect_in_inter` reads `palette_y_mode` at decode.rs:10131) and
55+publish nothing — the mirror defect (a real palette block invisible to its
56+neighbours). Needs each reader's decoded palette threaded to the tail.
57+
58+## Verification
59+
60+* synthetic gate stream: ours vs `ffmpeg`'s own decode — **byte-exact**
61+ (before the fix: all 12 frames differ from sample 491904, mi(76,88)).
62+* film B, libaom `-cpu-used 6 -crf 5 -g 48`, 48 frames: the KEY frame's
63+ `EC_IMODE` trace is now **identical to aomdec for all 15774 blocks** — the
64+ charter's "first divergent intra block mi(184,344)" premise is STALE, that
65+ desync is gone. crf 5 still fails, now in an INTER frame ("a Golomb tail
66+ longer than this decoder reads", last block read mi(124,412)); narrowed and
67+ deferred below.
68+
69+## Files
70+
71+* `crates/ec-av1/src/decode.rs` — the 7 zero-stamps (2 in the key-frame sub8
72+ readers, 5 in the inter/sub8 readers).
73+* `crates/ec-av1/src/encode.rs` — `external_ladder` now decodes EVERY reference
74+ ladder point through `decode_stream` and asserts sample-exactness against
75+ ffmpeg, naming encoder/params/frame/plane/sample (the assertion that would
76+ have caught both this and the `force_integer_mv` defect).
77+* `crates/ec-av1/src/motion_field.rs` — `EC_INTMV` trace print when
78+ `force_integer_mv` rounding actually changes a projected candidate.
79+
80+## OPEN / deferred
81+
82+1. **crf 5 inter-frame Golomb refusal** — key frame is exact now; the failure
83+ is in an inter frame (`EC_MM` trace, last read mi(124,412)). Unblocks: diff
84+ aomdec `EC_MODE`/`EC_STACK` against our `EC_MM` from the first inter frame.
85+2. **The palette-publishing mirror gap** above (5 readers).
86+3. **The sensitive `force_integer_mv` fixture**: a 1920x1024 source with a
87+ textured patch moving 2.5 px per duplicate-pair (half-pel motion, exact
88+ duplicate frames) makes libaom round 72 projected candidates
89+ (`EC_TRACE_TPL` → `EC_INTMV`), and the stream STILL decodes byte-exact with
90+ the fix stubbed (`if false &&`): the rounded candidates never change a coded
91+ block's mv. Sensitivity needs the rounded candidate to win a
92+ NEARESTMV/NEARMV slot.