forge
Explore
Log in

Don't you dare go Hollow

vp9odd: lane report (odd extents, byte-exactness tables, caller census)

Browse files at this commit

38b3c463f464099cb18fe72ed89b80ecf50932b4Ahmet Kaan GümüşParent: 73605cd
lanes/vp9odd.report.mdadded+235 -0
@@ -0,0 +1,235 @@
1+# Lane vp9odd: VP9 odd coded extents (chroma ceils at (w+1)/2)
2+
3+Branch `lane-vp9-odd`, base `main e910d25b`. Crate scope: `crates/ec-vp9`.
4+Worktree `/home/user/Documents/Code/Rust/edith_codecs-vp9odd`, private
5+`CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9odd`.
6+
7+Deliverable: the named `vp9 inter odd frame dimensions` refusal is removed and
8+odd-width / odd-height streams decode byte-identically to a libvpx 1.15.0
9+oracle. Root cause: the decoder stored/cropped 4:2:0 chroma at `floor(w/2)`
10+while libvpx stores and crops at `uv_crop_width = (w+1)/2` (CEIL). Unifying on
11+ceil in the inter predictor's reference extent and in `crop_picture` fixes it.
12+
13+## Baseline (milestone 0)
14+
15+ $ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9odd cargo test -p ec-vp9
16+ 20 test binaries, 0 failed, 0 ignored (pre-fix; 21 after the new witness)
17+
18+Pre-existing warnings (unchanged, present at base): `modes.rs` unused
19+`partition_probs` / `x_mis` / `y_mis` + `read_partition`, `tables/mod.rs`
20+`TM_PRED` (5).
21+
22+## Fail-pre-fix witness (milestone 1)
23+
24+The refusal fires on any odd coded extent once a reference slot already holds
25+an odd-sized frame. `$HOME/.cache/vp9pix/refusal_odd.ivf` (patched keyframe +
26+an inter frame that inherits the odd size) reproduces it:
27+
28+ $ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9odd \
29+ INTER_IVF=$HOME/.cache/vp9pix/refusal_odd.ivf \
30+ EC_VP9_PIXDUMP=/tmp/our_ro.pix \
31+ cargo test -q -p ec-vp9 --test scratch_pixdump -- --nocapture
32+ PIXFRAME input=0 shown=0 322x242 321x241
33+ PIXERR input=1: unsupported: vp9 inter odd frame dimensions (321x241: the
34+ reference chroma planes of an odd-sized frame are stored at floor(w/2)
35+ but the predictor reads libvpx's uv_crop_width = (w+1)/2)
36+
37+That string is gone after the fix (step: rerun the same command; frame 1 now
38+decodes).
39+
40+## Root cause
41+
42+- inter predictor (`decode.rs::inter_predict_plane`): `RefPlane.width/height`
43+ used `coded >> s` for chroma -> `floor(w/2)`. libvpx's border/inside test
44+ uses `uv_crop_width = (w+1)/2`, so the last chroma column/row was treated as
45+ outside the frame and border-clipped.
46+- returned picture (`decode.rs::crop_picture`): chroma cropped + `uv_stride`
47+ at `w/2` / `h/2` -> a floor dump that is one column/row short of libvpx's
48+ `vpx_image` (which carries `ceil(d_w/2) x ceil(d_h/2)`).
49+- `Planes::dims` (the internal buffer stride) is unaffected: the scratch/reference
50+ buffers are 64-aligned, so `aw/2` already equals `ceil` and covers the extra
51+ sample. Only the *readable/cropped* extents were wrong.
52+
53+## Change (milestone 2)
54+
55+`crates/ec-vp9/src/decode.rs` only:
56+
57+- `inter_predict_plane`: `width: (ref_frame.width as usize + s) >> s`,
58+ `height: (ref_frame.height as usize + s) >> s` (luma `s = 0` unchanged,
59+ chroma ceil).
60+- `crop_picture`: `let (cw, chh) = ((w + 1) / 2, (h + 1) / 2)` for U/V crop
61+ and `uv_stride`.
62+- delete the `hdr.width % 2 != 0 || hdr.height % 2 != 0` refusal block and its
63+ module-doc sentence.
64+
65+No mi-grid or bitstream change: the coded size only affects plane storage/crop,
66+so the tile syntax is untouched. The loop filter keeps its existing MI-aligned
67+extents (`vw = mi_cols*8`, `uv_h = vh/2`) and the unbounded chroma column groups;
68+an odd stream writes the same overhang the even path already did.
69+
70+## Byte-exactness (milestone 3)
71+
72+Oracle: `$HOME/.cache/vp9pix/drv_pix2` (new), a libvpx pixel dumper that uses
73+the CODED size (`img->d_w/d_h`) and the vpx_image chroma convention
74+(`ceil(w/2) x ceil(h/2)`). It is byte-identical to the frozen oracle on the
75+even 1080p entry stream:
76+
77+ $ PIXDUMP=/tmp/o1_frozen.pix $HOME/.cache/vp9pix/drv_pix inter1.ivf
78+ $ PIXDUMP=/tmp/o1_new.pix $HOME/.cache/vp9pix/drv_pix2 inter1.ivf
79+ $ cmp /tmp/o1_frozen.pix /tmp/o1_new.pix # identical
80+
81+and ffmpeg's rawvideo output equals it on an odd stream too, so ffmpeg is a
82+valid odd oracle (used by the in-repo witness).
83+
84+Comparator: `$HOME/.cache/vp9pix/pixcmp2.py <oracle> <ours> <w> <h>` (ceil
85+chroma; exact for even and odd). Sweep driver: `sweep2.sh <worktree> <stream>
86+<w> <h>` (oracle dump + our dump + `pixcmp2.py`).
87+
88+### Odd stream generation
89+
90+libvpx-vp9's encoder rounds an odd source through its scaler, so odd fixtures
91+are an even `322x242` (or `1920x1080`, `320x240`) encode whose keyframe's
92+uncompressed-header size fields are patched to the odd target and whose IVF
93+container size is rewritten:
94+
95+ $ ffmpeg -v error -y -f lavfi -i testsrc2=size=322x242:rate=24:duration=0.5 \
96+ -c:v libvpx-vp9 -g 999 -auto-alt-ref 0 -crf 30 -deadline good \
97+ -cpu-used 4 -pix_fmt yuv420p -f ivf /tmp/src322g.ivf
98+ $ python3 $HOME/.cache/vp9pix/patch_kf_size.py /tmp/src322g.ivf \
99+ /tmp/odd_321x241.ivf 321 241
100+
101+The patch flips the 16-bit `width-1` / `height-1` fields at bit 36 of the
102+keyframe (profile 0, 8-bit, 4:2:0, `error_resilient = 0`: 8 header bits +
103+24-bit sync + 3 `color_space` + 1 `color_range`). 322<->321 and 242<->241 are
104+mi-grid invariant (both ceil to 41x31 mi units), so the tile data stays valid
105+and every later frame inherits the odd size through `found_ref`.
106+
107+### Results (all frames, loop filter ON)
108+
109+| stream | coded | frames | result |
110+|---|---|---|---|
111+| testsrc2 patched | 321x241 | 12 | **all byte-identical** |
112+| testsrc2 patched | 321x242 (odd width) | 12 | **all byte-identical** |
113+| testsrc2 patched | 322x241 (odd height) | 12 | **all byte-identical** |
114+| testsrc2 patched, `-tile-columns 1` | 321x241 | 12 | **all byte-identical** |
115+| real 1080p corpus patched | 1919x1079 | 48 | **all byte-identical** |
116+| real altref corpus patched | 319x239 | 60 | **all byte-identical** |
117+
118+Real-content odd witnesses: `vp9-1080p-23.976-8bit.ivf` (single keyframe) and
119+`vp9-superframe-altref.ivf` patched at frame 0, so the whole stream is odd.
120+
121+Loop filter is active on the odd streams (verified: `EC_VP9_SKIP_LF=1` changes
122+the output of `odd_321x241`, so the odd chroma/row extents pass through the
123+filter byte-exactly).
124+
125+### Even corpus re-sweep (no regression)
126+
127+| stream | frames | result |
128+|---|---|---|
129+| `inter1.ivf` 1080p | 3 | **all byte-identical** |
130+| `inter.ivf` 1080p (2 tile cols) | 3 | **all byte-identical** |
131+| `vp9-1080p-23.976-8bit.ivf` | 48 | **all byte-identical** |
132+| `vp9-2160p-23.976-8bit.ivf` | 48 | **all byte-identical** |
133+| `vp9-superframe-altref.ivf` | 60 | **all byte-identical** |
134+
135+## Regression witness (milestone 4)
136+
137+`crates/ec-vp9/tests/odd_dimensions_exact.rs` (3 tests: odd width, odd height,
138+both). It generates the even `322x242` GOP with ffmpeg, patches the keyframe
139+size fields, decodes with our decoder and compares every shown frame byte-for-
140+byte against ffmpeg's libvpx rawvideo, asserting the coded size and the ceil
141+chroma length/stride on every frame.
142+
143+ $ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9odd \
144+ cargo test -p ec-vp9 --test odd_dimensions_exact
145+ test result: ok. 3 passed; 0 failed
146+
147+Non-vacuity (temporarily restoring the floor layout: `>> s` and `w/2, h/2`):
148+
149+ odd_width_matches_ffmpeg FAILED
150+ odd_height_matches_ffmpeg FAILED
151+ odd_width_and_height_matches_ffmpeg FAILED
152+ (panic at odd_dimensions_exact.rs:132, the ceil chroma length assert)
153+ inter_pixels_exact (even) 2 passed # even path unaffected
154+
155+Fixed layout: the 3 odd tests pass and the even tests still pass.
156+
157+## Caller-migration census (milestone 5)
158+
159+The returned plane layout is `ec_vp9::decode::Picture`. Census of every
160+in-workspace reader:
161+
162+- **Dependency edges**: no crate declares a dependency on `ec-vp9`. The only
163+ edge is `ec-hw -> ec-vp9-syntax` (untouched). `tools/` (`ec-bench`, `oracle`)
164+ does not reference `ec-vp9`. No `ec_vp9::` path is used outside
165+ `crates/ec-vp9/`.
166+- **Inside the crate**: `crop_picture` is the sole producer of `Picture`;
167+ readers are the tests. `keyframe_exact.rs` / `inter_pixels_exact.rs` use
168+ even dims (`(w/2)*(h/2)` == ceil) and are unaffected;
169+ `scratch_realsweep.rs` only prints `pic.uv_stride`; `scratch_pixdump.rs`
170+ dumps `pic.{y,u,v}` and is now ceil-correct by construction.
171+
172+Conclusion: zero external consumers; no shim or dual layout needed. The only
173+layout change is `Picture.uv_stride`/chroma length for odd coded extents.
174+
175+## Gates
176+
177+ $ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9odd cargo test -p ec-vp9
178+ exit=0 - 21 test binaries, 0 failed, 0 ignored (baseline 20; +1 witness)
179+
180+Warning parity: 5 pre-existing warnings, none added, none from the new file.
181+
182+## Deferred / not touched
183+
184+- **frame-72 desync on `vp9-1080p-60-8bit.ivf`** — owned by the sibling lane;
185+ not touched here. It is even-dimension and orthogonal to this change.
186+- `$HOME/.cache/vp9pix/refusal_odd.ivf` is no longer a valid refusal witness:
187+ libvpx itself reports `Corrupt frame detected` on its frame 1, so it was a
188+ refusal-only probe. The permanent witness now generates its own odd stream.
189+- No resync/`show_existing_frame`-specific odd test; the odd path reuses the
190+ same `crop_picture` used by the show-existing return, covered indirectly by
191+ the sweeps.
192+
193+## Repro (all commands)
194+
195+ # build + suite
196+ cd /home/user/Documents/Code/Rust/edith_codecs-vp9odd
197+ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9odd cargo test -p ec-vp9
198+
199+ # odd witness (self-generating)
200+ CARGO_TARGET_DIR=$HOME/.cache/cargo-target-vp9odd cargo test -p ec-vp9 \
201+ --test odd_dimensions_exact
202+
203+ # odd real-content sweep (any stream)
204+ $HOME/.cache/vp9pix/sweep2.sh $PWD /tmp/rc_1919x1079.ivf 1919 1079
205+
206+ # rebuild the odd-aware oracle if needed
207+ gcc -O2 -I $HOME/.cache/vp9pix/libvpx-hdr/src \
208+ $HOME/.cache/vp9pix/drv_pix2.c -o $HOME/.cache/vp9pix/drv_pix2 \
209+ /usr/lib64/libvpx.so.9 -lm -lpthread
210+
211+## VERDICT
212+
213+GATE 1 - `cargo test -p ec-vp9` green (21 binaries, 0 failed, 0 ignored):
214+**PASS**.
215+GATE 2 - odd-width, odd-height and both decode byte-exactly vs libvpx 1.15.0,
216+and the full even corpus re-sweeps all-identical: **PASS**.
217+GATE 3 - the named `vp9 inter odd frame dimensions` refusal is gone (pre-fix
218+string captured above) and the fix is non-vacuous (floor layout fails the odd
219+witness): **PASS**.
220+GATE 4 - caller-migration census complete (zero external consumers):
221+**PASS**.
222+GATE 5 - committed to `lane-vp9-odd`, clean tree, no push: `e8152b9b`:
223+**PASS**.
224+
225+## MERGE-SIDE FOLLOW-UPS
226+
227+- Create-list: `crates/ec-vp9/src/decode.rs`,
228+ `crates/ec-vp9/tests/odd_dimensions_exact.rs`, this report. No other file.
229+- The `$HOME/.cache/vp9pix` assets added here (`drv_pix2.c`/`drv_pix2`,
230+ `pixcmp2.py`, `patch_kf_size.py`, `sweep2.sh`, `libvpx-hdr/`) are outside the
231+ repo; the in-repo witness is self-contained (ffmpeg + a pure-Rust patch).
232+- The odd-aware oracle links against the system libvpx 1.15.0
233+ (`/usr/lib64/libvpx.so.9`), byte-identical to the frozen oracle on even
234+ content; `libvpx-devel` is not installed, so the headers come from a
235+ `v1.15.0` source checkout.