forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 052d1d3f81ff6b9e7c09b93b58c5e772d825fcb3Filtered to crates/ec-vp8/src/decode.rsClear filter

2026-09-12

Revert "ec-vp8 perf: idct_add_into -- fused strided reconstruct + AVX2 kernel"Ahmet Kaan Gümüş · bb830d8
Revert "ec-vp8 perf: idct_add_into -- fused strided reconstruct + AVX2 kernel"

This reverts commit 4d6a9f2729070667f54554f1489603e0d29d0824.
ec-vp8 perf: idct_add_into -- fused strided reconstruct + AVX2 kernelAhmet Kaan Gümüş · abc2cab
ec-vp8 perf: idct_add_into -- fused strided reconstruct + AVX2 kernel

idct_add_into (28% of the post-MC-decode profile) now runs through
transform::idct_add_strided: the prediction gather, the transform, the
clamp-add and the strided stores in one function, with an explicit
std::arch::x86_64 AVX2 kernel dispatched off a shared LazyLock probe and
the scalar path kept as the libvpx transcription and lane-for-lane
oracle.

The kernel preserves the module's precision contract in full: the
butterflies are the scalar i32 arithmetic lane-parallel (products exact,
|i16 * 35468| < 2^31), and the only narrowing points are the oracle's
short stores -- pass one's tmp and pass two's residual -- implemented as
low-16-bit truncations via shuffle_epi8, never saturation. Coefficients
transpose to column groups (rows woven by unpack_epi16), pass one's
store-pattern transpose hands row groups to pass two, and the final
clamp is explicit max 0 / min 255 in i32 before a saturating pack that
never fires beyond the clamp. The equivalence test pushes coefficients
to the i16 rails precisely because the network is exact for every input.

Witness suite: 58 lib (new: simd-vs-scalar equivalence over rails +
random, four stride shapes) + 4 header_parse + 4 keyframe_exact + 3
stream_exact, byte-exact, debug and release. Zero warnings.
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 M4: public whole-stream API (ec-av1 decode_stream shape)Ahmet Kaan Gümüş · 93dee5c
ec-vp8 M4: public whole-stream API (ec-av1 decode_stream shape)

stream::decode_stream(IVF bytes) -> Result<Vec<Picture>> collects every
shown picture; stream::decode_stream_with hands each picture to a sink
(picture, decode_idx, IVF pts) the moment it exists. Hidden frames
(show_frame == 0) update the reference state and produce no sink call.
Container envelope (DKIF magic, VP80 fourcc, framing arithmetic) is
validated as ec_core::Error variants, not panics. Picture gains Clone.

Witness tests/stream_exact.rs: decode_stream byte-exact vs ffmpeg on
ALL 12 IVF fixtures (every frame, all planes) + malformed-container
errors. Suite: 55 lib + 4 header_parse + 4 keyframe_exact + 2
stream_exact, zero rustc warnings.
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: long MV components read bits 9,8,7,6,5,4 (mvlong_width=10) — bit 9 was missingAhmet Kaan Gümüş · d5796e3
ec-vp8 M3: long MV components read bits 9,8,7,6,5,4 (mvlong_width=10) — bit 9 was missing

RFC 6386 §17.1 and libvpx read SIX long-form bits (9 down to 4) before
the sometimes-implicit bit 3; the port read only five (8..4), so every
large motion vector decoded as garbage while short MVs and ZEROMV
stayed correct. gop-160x96 frame 1: 51% -> 95.3% pixel match; frames
0-3 of gop and clip-obs now byte-exact vs ffmpeg. Remaining divergence
from frame 4 onward is the next M3 target.
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.