forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on dfeffbcebd64426ceeebbf03214c8d6fe57282d6Filtered to crates/ec-vp8/src/header.rsClear filter

2026-09-12

ec-vp8 perf: per-bool env lookups were 46% of decode profileAhmet Kaan Gümüş · 1a98a0f
ec-vp8 perf: per-bool env lookups were 46% of decode profile

std::env::var_os ran per bool read (bool.rs read_bool) and per MB
(decode.rs reconstruct) — each call takes std's ENV lock and allocates;
perf showed 46% of samples in getenv/__strlen. OnceLock::get_or_init
was no better (closure re-entry still hit the env path). Now both flags
resolve once per process into an AtomicU8 (relaxed load-only hot path).

Before -> after (decode MP/s): gop-160x96 32->82, clip-obs 51->122,
altref 16->55, gop-1280x720 137->211, big-obs-2560x1320 121->175
(35.7 -> 51.9 fps). Full witness suite byte-exact green.
ec-vp8 M3: inter frames byte-exact vs ffmpeg on ALL fixturesAhmet Kaan Gümüş · 80115ee
ec-vp8 M3: inter frames byte-exact vs ffmpeg on ALL fixtures

Four bugs fixed this pass:
- inter-frame B_PRED subblock modes used the keyframe context table
  (KF_BMODE_PROB[a][l]); libvpx decodemv.c:467 reads fc.bmode_prob —
  the FLAT vp8_bmode_prob {120,90,79,133,87,85,80,111,151}, no context
- MC interpolation filter is per-frame from the tag version bits
  (vp8_setup_version): version 0 = six-tap for BOTH planes; chroma was
  hardcoded bilinear. Version 3 fullpixel_mask (~7) added to the chroma
  MV derivation
- SPLITMV chroma: quadrants are 4x4 CHROMA pixels at 4-px offsets; the
  old loop predicted 8x8 at 8-px offsets, so the residual add read the
  top-left quadrant's prediction for all four quadrants (whole-MB modes
  masked the bug; every SPLITMV MB got wrong chroma)
- key frame with refresh_entropy==0 now reverts to DEFAULTS (libvpx
  inits fc before lfc=fc), not the pre-keyframe context

keyframe_exact now witnesses full streams: gop/clip-obs/altref added as
interframe_streams_match_ffmpeg; suite 55 lib + 4 header_parse + 4
keyframe_exact green, zero rustc warnings. Model fixed to match libvpx
(inter ymode/uv defaults 112/86/140/37 + 162/101/204, flat inter bmode)
ec-vp8 M3 debugging: inter census localization — model extended to inter frames, divergence pinned to MB(2,7) census countAhmet Kaan Gümüş · 1c98b09
ec-vp8 M3 debugging: inter census localization — model extended to inter frames, divergence pinned to MB(2,7) census count

vp8ref_model.py now parses inter frames (refresh header, prob_intra/
last/gf, ymode/uv/MV updates, per-MB inter mode records with the
census, SPLITMV, per-row tokens) with B/G/CNT/SP/IMB traces mirroring
the Rust decoder's. Two model bugs fixed on the way (inter partition-0
offset is byte 3 not 10; clamp_mv2 wrote the clamped row into the
column slot). Rust gained CNT (census result) and SP (SPLITMV subset)
traces plus STAGE markers in the header parse.

Result: model and Rust B streams agree read-for-read through frame 1's
mode records up to MB(2,7), where the census diverges: model
cnt=[0,2,2,3] vs rust cnt=[0,3,2,3] with IDENTICAL neighbour states
(above=r1c7 NEAREST mv (-138,-100), left=r2c6 SPLITMV bmi15
(-134,-76), aboveleft=r1c6 mv (-138,-100) — rows 0-1 parse identically
on both sides). The above-left +1 lands in cnt[NEAREST] (rust) vs
cnt[NEAR] (model) — one of the two census implementations mishandles
the above-left same-as-previous comparison; libvpx decodemv.c:307-361
is the arbiter to re-read next session. Pixel state: gop frame 1 at
51% vs ffmpeg before this divergence was understood.
ec-vp8 M3 WIP: full inter-frame pipeline decodes; walled on one mode-record divergenceAhmet Kaan Gümüş · 10ef9be
ec-vp8 M3 WIP: full inter-frame pipeline decodes; walled on one mode-record divergence

Lands: inter mode/MV parse (prob_intra/last/gf, mv_ref census port of
libvpx read_mb_modes_mv incl. the dead CNT_SPLITMV merge, SPLITMV with
mbsplit leader/fill tables, NEAREST/NEAR clamps, NEW/SPLIT best-MV
deltas), chroma MV derivation (round-half-away mv/2 whole-MB; sum/8
SPLITMV), motion compensation in new mc.rs (6-tap luma + bilinear
chroma + 32px border extension; 6 unit tests plus 31,000-case
differential fuzz vs verbatim libvpx filter.c/extend.c - byte-identical;
chroma whole-MB path re-clamps unconditionally per reconinter.c:336),
reference buffer management in libvpx swap_frame_buffers order
(copy_arf, copy_gf, refresh_gf, refresh_arf, refresh_last), entropy
save/restore gated on refresh_entropy (probs only, like libvpx fc/lfc),
persisted segment map, inter LF levels with ref/mode deltas and
skip_lf inner-edge rule, EC_VP8_TRACE B-line per-read tracing in
BoolDecoder mirroring scripts/vp8ref_model.py.

State: inter frames decode end-to-end with no desync error; gop frame 1
matches ffmpeg 51% (frame 0 100%), diverging from MB(0,5) rightward -
one remaining mode-record/token divergence. Next: diff the B streams
(python3 scripts/vp8ref_model.py vs EC_VP8_TRACE=1) to localize it;
the python model still needs the inter-frame header/mode extension.

Suite: 55 lib (incl. 6 mc) + 4 header_parse + webp witness green;
keyframe_exact 1/3 (2 cases need the M3 fix to pass).
ec-vp8: two partition-0 desync bugs fixed (M2 debugging state)Ahmet Kaan Gümüş · d9a9866
ec-vp8: two partition-0 desync bugs fixed (M2 debugging state)

BUG 1 (found by decision-trace diff vs a python dixie model): the MV
probability update loop ran on KEY frames - dixie/libvpx parse it only
for interframes. On key frames the 38 extra bool reads desynced the
whole partition-0 parse. Moved inside the !is_keyframe branch.

BUG 2: decode_keyframe created a FRESH bool decoder over partition 0
for the per-MB mode records - re-reading the partition from its start.
FrameHeader::parse now returns its partition-0 decoder so the mode
records CONTINUE from where the header stopped (dixie decode_frame
shares one decoder).

Result: single-MB 16x16 black q0 fixture now decodes BYTE-EXACT vs
ffmpeg (chroma and luma). Multi-MB fixtures still diverge: decision
traces (python dixie model scripts side /tmp/vp8ref.py vs EC_VP8_TRACE)
match to decision 2562 and split at 2563 inside the token walk of
MB(0,1) block 0 (ref consults prob 11, rust prob 4 at the same stream
position) - a coefficient-context/bookkeeping difference in the multi-MB
token pass that is now precisely localized for the next session.
Debug tooling retained: EC_VP8_TRACE decision trace, EC_VP8_DEBUG
per-MB coeff dump, examples/dbg_first.rs.
ec-vp8 M2 WIP: full key-frame decode pipeline (tokens/intra/transform/loopfilter/reconstruct) — unit tests 100% green, ffmpeg exactness witnesses RED (luma bug)Ahmet Kaan Gümüş · 5b0ae03
ec-vp8 M2 WIP: full key-frame decode pipeline (tokens/intra/transform/loopfilter/reconstruct) — unit tests 100% green, ffmpeg exactness witnesses RED (luma bug)

- tokens.rs: RFC 6386 sec 13 coefficient decoding (GetCoeffs port: bands,
  3-context model, EOB-skip-after-zero, dequant-on-write, Y2-first block
  order, dixie skip-MB context reset with Y2 preservation).
- modes.rs: all mode/MV trees + tables (kf/inter ymode, bmode, uv,
  mv_ref, sub_mv_ref, SPLITMV partitions with RFC enum-value indexing).
- decode.rs: per-row pipeline (modes -> tokens -> reconstruct), bordered
  planes (127/129), above-right synthesis, B_PRED interleaved
  predict+residual (reconstructed-pixel chaining), Y2 WHT DC override,
  per-MB LF level (dixie double-clamp), LF post-pass via loopfilter.
- loopfilter.rs + intra.rs + transform.rs: subagent kernels, rustc-verified
  vs libvpx C (differential fuzz: 400k IDCT/WHT vectors, 20k intra streams,
  dixie-table-exact LF limits).
- FIX along the way: per-MB-row token left-context reset (dixie
  reset_row_context) was missing.
- tests/keyframe_exact.rs: ffmpeg byte-compare witnesses — FAILING: single
  16x16 black q0 frame decodes chroma exact but luma ~99-130 vs 16 (B_PRED
  MB, coeffs plausible); suspected in luma pred/apply path, NOT yet
  localized. Debug: EC_VP8_DEBUG=1 dump + examples/dbg_first.
- 49 lib + 4 header tests green; zero warnings in lib.
ec-vp8 M1: bool arithmetic decoder, frame tag + full first-partition header parsing, RFC-transcribed tablesAhmet Kaan Gümüş · 5233d88
ec-vp8 M1: bool arithmetic decoder, frame tag + full first-partition header parsing, RFC-transcribed tables

- bool.rs: RFC 6386 section 7.3 decoder (read_bool/literal/signed_literal/
  maybe_signed/prob7/tree incl. the EOB-skipping token-tree form), plus a
  test-only reference bool encoder; round-trip tests at probability
  extremes, long LCG streams, literals to 19 bits, tree paths.
- frame.rs: 3-byte LE frame tag, key-frame start code + dimensions/scaling,
  MB geometry.
- header.rs: complete partition-1 header in dixie field order — colour
  space/clamping, segmentation (with cross-frame state), loop filter
  type/level/sharpness/deltas, token partition size table, quant indices,
  reference refresh/copies/sign-bias, coefficient probability updates,
  mb_no_skip_coeff, inter prob_intra/last/gf + ymode/uv/MV probability
  updates. PersistedState carries entropy/segmentation/filter deltas
  across frames and resets at key frames.
- tables.rs: GENERATED verbatim from the RFC text by
  scripts/extract_vp8_tables.py (element counts asserted): default + update
  coefficient probs, kf_bmode_prob, coeff_bands, dequant lookups, Pcat1-6
  (sentinel kept), default + update MV probs.
- scripts/gen_vp8_fixtures.sh: libvpx-encoded IVF witnesses (6 sizes/q,
  60-frame GOP, 8-token-partition vector via local vpxenc, WebP still).
- Witness: real vpxenc/ffmpeg-produced streams parse with exact tiling of
  partition sizes, correct dims (incl. 76x52 non-MB-aligned), 8 partitions;
  VP8-in-WebP still decodes its header. 12 tests green, zero warnings.