Commits
Commits on
552edc4cede0dfd9bebbc4e344242802802d15ccFiltered to crates/ec-av1/src/msac.rsClear filter2026-09-04
perf(av1): refill the arithmetic decoder a field at a time, not a bit at a timeAhmet Kaan Gümüş · bea686b
perf(av1): refill the arithmetic decoder a field at a time, not a bit at a time `SymbolDecoder::symbol_fixed` was 6.8% self time after the transform work, and most of what it does per symbol beyond the alphabet walk is `f(n)` -- the renormalisation refill, which looped once per bit, fetching, masking and shifting a byte each time. Five bytes cover any 32-bit field at any bit offset, so the whole field is now one assemble-and-shift; a byte past the end of the payload still reads as zero, exactly as the per-bit `unwrap_or(0)` did. The alphabet walk also hoists `range >> 8`, which cannot move until the symbol is chosen. `bulk_bit_reads_match_the_per_bit_form` checks the new `f` against the loop it replaced at every start offset over a 40-byte payload, every width from 0 to 32, and 16 bits past the end. Byte-exact: `EC_PROBE_OUT16` dumps hash-identical to the lane's baseline binary on 1080p 10-bit, 2160p HDR and the 8-bit palette fixture. Interleaved medians against the previous commit: 1080p 12.35 s -> 12.07 s, 4K 64.44 s -> 63.94 s.
2026-08-28
wip(av1): msac symbol_fixed hand-verified correct; real desync is a switchable_interp read aomdec never performs for this block. Round 6, capped at budget.Ahmet Kaan Gümüş · 21c8320
wip(av1): msac symbol_fixed hand-verified correct; real desync is a switchable_interp read aomdec never performs for this block. Round 6, capped at budget. COMPILES. No behaviour change: new EC_AV1_EOBPT_CDF-gated `debug_state()`/eprintln! diagnostics only (msac.rs's new `pub(crate) fn debug_state`, decode.rs's three new state prints in `read_coeffs` and `read_eob`), same pattern as every prior round's instrumentation. R6'S OWN PLAN'S STEP 1/2 (msac.rs correctness) IS NOW CLOSED, NEGATIVE: hand-derived `symbol_fixed` (msac.rs:301-329) against libaom's actual `od_ec_decode_cdf_q15` source (`/tmp/libaom-src/aom_dsp/entdec.c:204`, read fresh this round, not from memory) term-by-term for nsyms=11 specifically -- `N = nsyms - 1`, loop increments `ret` before indexing `icdf[++ret]`, `v = ((r>>8)*(icdf[ret]>>EC_PROB_SHIFT))>>(7-EC_PROB_SHIFT) + EC_MIN_PROB*(N-ret)`, loop continues `while (c < v)`. This is algebraically IDENTICAL to our `cur = (((range>>8)*(f>>EC_PROB_SHIFT)) >>(7-EC_PROB_SHIFT)) + EC_MIN_PROB*(nsyms-1-symbol)`, loop `while value < cur`. nsyms=11 is not special-cased anywhere in either implementation. r5's suspicion (1) is FALSIFIED -- do not re-open without new evidence. DECISIVE NEW EVIDENCE (this round's actual find): added a `debug_state()` accessor to `SymbolDecoder` and printed `(range, value)` before/after the `all_zero` (txb_skip) read, after the `tx_type` read, and entering `eob_pt` -- then added the SAME state to aomdec's `decodetxb.c` (`EC_AV1_EOBPT_STATE_IN`, plus `rng_before` on the existing `EC_PLANE` trace). Result: **the coder state ALREADY diverges before the `txb_skip` read even starts** -- ours enters at `range=46855`, aomdec enters at `rng_before=50720`. So r5's "CDF + symbol byte-identical at tx_type/eob_pt" was real but downstream of an earlier, silent divergence; walking back from there: Between `EC_MV` (motion vector, matches exactly: `mv=(-2,-8)` both sides) and `EC_TXBCTX`/`EC_PLANE` (first plane's coeff decode), the ONLY symbol read possible on this path is the switchable interpolation filter (`resolve_interp_filter`, decode.rs:3726 / libaom's `read_mb_interp_filter`, decodemv.c:1122). Ours takes the *real-symbol* branch (`interp_fixed == None`, i.e. the frame header says `interpolation_filter == Switchable`) and decodes `filter=[3, 3]` (BILINEAR both directions) -- a real, adapting 3-symbol CDF read. aomdec's own trace for this exact block (`mi_row=0 mi_col=0`, frame=14, ref=1, mode=NEWMV=16) shows `interp=(0,0)` (REGULAR both directions) with **no `IFILTER_DBG` line at all** -- confirmed by instrumenting `av1_is_interp_needed()`'s own three sub-conditions directly (`IFILTER_NEEDED ... skip_mode=0 motion_mode=0 mode=16 needed=1`): the function returns TRUE (the read is not skipped by the gate), yet `read_mb_interp_filter`'s OWN symbol-read branch never fires for this block, which by its source (decodemv.c:1134, `if (interp_filter != SWITCHABLE)`) is only possible if **libaom's own per-frame `features->interp_filter` is a FIXED value for frame 14, not `SWITCHABLE`** -- i.e. aomdec's `interpolation_filter` header field for THIS frame differs from what our decoder computed. CONCLUSION / R7 HANDOFF, IN ORDER: 1. This is very likely NOT an msac bug at all (closed, see above). The live suspect is `read_interpolation_filter()` (`ec-av1-syntax/src/frame.rs:1165`) or, more likely given the header bit-parsing there matches spec 5.9.10 exactly on inspection, a **frame-header/frame-index MISMATCH**: this pin's "decode-order frame 1" may not be resolving to the same underlying temporal-unit frame aomdec calls its own "frame=14" -- ties back to f952bb4's already-flagged "hidden frame" suspicion from round 3, never fully closed. Confirm by dumping `header.interpolation_filter` (and ideally `show_frame`/`frame_type`/`order_hint`) for EVERY frame header our decoder parses in this stream, aligned against aomdec's own `cm->current_frame.frame_number` sequence (add an `EC_AV1_FRAME_NUMBER`-style eprintln! to `av1_read_coeffs_txb` or the frame-header decode point on aomdec's side, matching the counters already in place) -- find the first frame where the two disagree on `interpolation_filter`, and from there whether it's a genuine off-by-one in which OBU/frame our pin harness treats as "decode-order frame 1", or a real per-frame header field ours reads as `Switchable` when it should not. 2. If frame alignment IS correct and headers genuinely disagree on this field for the SAME frame: re-derive `read_interpolation_filter` against spec 5.9.10 word-for-word once more (looks correct on this round's read, but re-check the surrounding `allow_high_precision_mv` /`force_integer_mv` order just above it, frame.rs:963-968 -- an earlier misread bit could shift every subsequent header field by one bit position without desyncing the *tile* data at all, which is exactly the shape of "everything downstream of one header field looks locally consistent but globally wrong"). 3. Once the true cause is found and fixed, re-run the pin (`EC_AV1_PIN_N=24`) for exactness, THEN full `cargo test -p ec-av1 --release` (not just `--lib`) per existing done-criteria -- a header-parsing fix is even more likely than an msac fix to touch every stream. 4. If the pin goes exact: run the three flaking gates 15x each (`compound_references`, `reference_select`, `deblocking`) and report pass counts honestly. Instrumentation added this round, env-gated (no behaviour change when unset): `SymbolDecoder::debug_state()` (msac.rs, `pub(crate)`, mirrors the existing `debug_bitpos()`), three new `EC_AV1_EOBPT_CDF`-gated state prints in decode.rs (`EC_AV1_STATE_BEFORE_TXBSKIP`, `EC_AV1_STATE_AFTER_TXBSKIP`, `EC_AV1_STATE_AFTER_TXTYPE`). External, not committed to this repo: `/tmp/libaom-src`'s `av1/decoder/decodetxb.c` (`EC_AV1_EOBPT_STATE_IN`, `rng_before` on `EC_PLANE`) and `av1/decoder/decodemv.c` (`IFILTER_NEEDED`, gated on the pre-existing `EC_IFILTER_DBG`) -- rebuilt into `/tmp/libaom-src/build/decoder-debug/aomdec`; this source tree is outside the repo and NOT reproducible from a fresh checkout, note for whoever runs r7 without the same `/tmp` state. class: sibling of [[stale-premise-lanes]] -- r4 and r5 both suspected mechanisms one level too deep (a table's forwarding, then a coder primitive) because both were proven correct in isolation without first walking the state itself backward to its true entry point; the actual divergence sits one whole syntax element earlier (a per-block symbol read that should not have fired at all), in territory ([[hidden frame]] frame-index resolution) an even earlier round (f952bb4) already named and left open.
wip(av1): r6 -- sweep clean, class sweep clean, CURRENT_OP scaffolding removedAhmet Kaan Gümüş · a3b0b8a
wip(av1): r6 -- sweep clean, class sweep clean, CURRENT_OP scaffolding removed Sweep: both wide gates (reference_select, compound_references) 10/10 green, all pixel-exact, no defect found. Old pins re-verified: av1blend- r1-mismatch.obu 24/24 MATCH (already closed by r6/r7's ref_ctx fix, not a new result); cdfflake-stream-seed45.bin still mismatches at frame 2 (359/4096 luma, worst delta 6) -- unrelated cdf-forwarding defect, NOT closed by the mvstack fix. Charter's "comp_group_idx==0 refusal" premise did not match HEAD 8f08e06: only a comp_group_idx==1 (wedge/diffwtd) refusal exists, which is a genuinely-unsupported blend type the charter itself says must stay masked. No comp_group_idx==0/compound_idx refusal exists anywhere in decode.rs -- that path is already live and unmasked, and the sweep confirms it is currently defect-free. Nothing to unmask. Class sweep (neighbour votes all its fields): every remaining site (single_ref/comp_ref/comp_bwdref/uni_comp_ref ctx family, reference_mode_ctx, comp_reference_type_ctx, get_comp_group_idx_context, get_comp_index_context, switchable_interp_ctx, the either-ref filter_ctx checks) already threads both compound slots correctly -- verified against mvstack.rs/decode.rs source, no new bug found. Cleanup (partial, budget-bound): removed msac.rs's EC_RNG trace block and the CURRENT_OP thread_local plus all 102 call sites in decode.rs that set it. tile.rs's separate, older EC_RNG trace (lane-av1truesize, still load-bearing for the encoder side) is untouched -- out of this lane's scope. Still owed: EC_AV1_SREF_DUMP/EC_AV1_COMPIDX_DUMP/ EC_AV1_COMPOUND_DEBUG/BITPOS_BLK_START blocks, r17_dump/ R17_DUMP_FRAME_IDX (EC_AV1_PREFILT/POSTFILT_DUMP), and scratch_* #[ignore] tests beyond the two pin-repro tools -- next round. cargo test -p ec-av1 --lib: 214 passed/0 failed/19 ignored (individual runs); one flaked FAILED in a full-suite run reproduced green in isolation -- pre-existing aomenc-RD-nondeterminism flake class, not a regression from this change.
fix(av1): single-ref mvstack scan votes a compound neighbour's second slotAhmet Kaan Gümüş · 2b9615f
fix(av1): single-ref mvstack scan votes a compound neighbour's second slot Named read #538 (EC_RNG global trace): L5039, the new_mv symbol in decode_inter_block16's single-ref path, fed a new_mv_ctx computed from find_mv_stack_with_sign_bias. Its row/col/corner scans and the single-ref extension pass (process_single_ref_mv_candidate) matched a neighbour on info.ref_frame alone, silently dropping the vote whenever a compound-coded neighbour's match sat in its second slot (ref_frame1/mv1) -- the third instance of the neighbour-votes-all-its- fields class. Frame 10 (decode order) has reference_select=true, so a compound neighbour is live next to the diverging single-ref query. Added single_ref_match() (mirrors libaom's add_ref_mv_candidate `for ref in 0..1+is_compound`), used by scan_row/scan_col/scan_corner/ scan_top_right; extended process_single_ref_mv_candidate to donate both of a compound candidate's slots instead of just the first. Proof: av1idx-refsel-pin.obu (20 frames) now 60/60 plane-MATCH against ffmpeg (0 mismatches), 3x. Full ec-av1 --lib suite 214/0/19 green. Also: added a CURRENT_OP thread-local (msac.rs) plus a per-call-site tag before every dec.symbol()/symbol_fixed() read in decode.rs (r5 scratch instrumentation, EC_RNG=1 trace now prints op=L<line>), and a reference_select/primary_ref_frame field on the EC_AV1_SREF_DUMP print (stream.rs) used to confirm frame 10's header state.
2026-08-27
fix(av1): V_DCT/H_DCT coefficient scan order + TX4 leaf8 scan table mixupAhmet Kaan Gümüş · 700543b
fix(av1): V_DCT/H_DCT coefficient scan order + TX4 leaf8 scan table mixup Two real desync causes past r3's tx-class context-derivation fix: 1. read_coeffs always read coefficients in the default zigzag scan regardless of tx_type. libaom's V_DCT/H_DCT classes use Mrow_Scan/ Mcol_Scan instead (scan.c av1_scan_orders index 10/11) -- decoded here as class_scan_table: V_DCT's class-scan is our grid's own natural row-major order (0..N), H_DCT's is that walk transposed. base_ctx/br_ctx's row/col-offset formulas (r3's fix) were already correct; only the scan order feeding position/row/col into them was wrong. 2. decode_leaf8's TX4 split loop (an 8x8 leaf's tx_depth=1 case) read its four 4x4 luma transform units with `scans.0` -- the leaf's own *8x8* scan table (64 entries) -- instead of `scans.1` (the 4x4 table), so `pos` values up to 63 got written into a 16-cell grid. Pre-existing bug, only reachable/visible once (1) stopped eating the stream earlier. 5-scale probe (examples/probe_tx4.rs, /tmp/tx4work/s*.obu) moved past every prior refusal point to new, later ones (scale 1.5 now refuses on "a directional chroma mode (round 2)" instead of an angle_delta/partition desync) -- real progress, not yet clean; next round needs the same trace-correlation to chase the remaining divergence(s). Suite green 172/172.
feat(av1): read the mv_hp/class0_hp bits real hp streams carryAhmet Kaan Gümüş · e192a62
feat(av1): read the mv_hp/class0_hp bits real hp streams carry The dropped-as-dead half-pel MV CDFs (our own writer never sets allow_high_precision_mv) were silently unread on foreign streams whose headers set the flag -- every later symbol shifted one bit, the same silently-unread-symbol shape as use_filter_intra. Tables restored, reads gated on the frame header's flag, plumbed through the inter tile path. On the pinned forwarding stream frame 3's desync drops from 2618 wrong luma pixels (worst 35) to 541 (all within 1, chroma exact) -- entropy now aligned, a luma-only reconstruction residue remains.
Merge branch 'lane-av1-rect': mod-32==8 key frames — the 8x8-leaf straddle pathAhmet Kaan Gümüş · e05f550
Merge branch 'lane-av1-rect': mod-32==8 key frames — the 8x8-leaf straddle path Fifteen rounds: side-8 CDF layer (TX_8X8/TX_4X4, partition_w8), Reach and scan tables for 8x8 leaves, mi-precise partition/mode contexts, the CFL alphabet, reduced_tx_set declared in the key-frame header, and the leaf mode-neighbour write moved out of the per-leaf loop. 640x360-class key frames now encode and round-trip through ffmpeg bit-exact; the 8x8-leaf split competes on RD cost; 40x40-class both-axes sizes still refuse.
fix(av1): declare reduced_tx_set in the key-frame header; rng in tracesAhmet Kaan Gümüş · a9fbebe
fix(av1): declare reduced_tx_set in the key-frame header; rng in traces The writer coded 8x8-leaf tx types against TX_SET_INTRA_2 tables while the header's reduced_tx_set:false told decoders to read TX_SET_INTRA_1 — a 7-vs-5-symbol alphabet skew that shifts the arithmetic coder's range with no symbol value ever differing. All existing sizes still round-trip bit-exact (16x16 resolves to the same 5-symbol set under both headers). Straddle test stays ignored: a further divergence remains past leaf(0,8).
feat(av1): begin a software key-frame decoder (round 1)Ahmet Kaan Gümüş · e6eadb9
feat(av1): begin a software key-frame decoder (round 1) Promotes msac's test-only SymbolDecoder to a real, non-test decoder (the inverse of SymbolEncoder, already spec-derived and roundtrip tested), and adds crates/ec-av1/src/decode.rs: a from-spec reader that mirrors tile.rs's sb_coeff_key_frame_tile symbol order (partition tree through 64x64/32x32/16x16, coefficient base/base-range/EOB/Golomb/sign syntax, CDF adaptation) without importing from tile.rs, which a sibling lane is editing concurrently. Round 1 scope: key frames only, DC_PRED blocks only, unskipped, and frames a whole number of 64x64 superblocks -- everything else refuses with a named error rather than miscoding. Within that scope, real encoder output (encode_key_frame_with_modes forced to DC_PRED, two sizes, real quantised AC/DC residual) decodes byte-exact against the encoder's own reconstruction. Encoded gains three pub(crate) fields (tile, mi_cols, mi_rows, base_q_idx) so a decoder test can reach the raw tile payload without re-deriving it from the OBU stream. Deferred to round 2: non-DC_PRED intra modes (needs the directional edge-reach plumbing), inter frames, skipped blocks, and the partial-superblock/gathered-CDF true-edge path.
2026-08-26
Merge branch 'lane-av1-size': pad-to-32 with cropped reconstructionsAhmet Kaan Gümüş · 77b8ab9
Merge branch 'lane-av1-size': pad-to-32 with cropped reconstructions The merge exposed a latent mvstack defect the two lanes could only trip together: real inter residuals (lane-av1-desync) on padded content (lane-av1-size) hit a block whose ref_mv context libaom derives from a diagonal corner probe our reduction never ran. Folded into this merge: - port libaom's scan_blk_mbmi(-1,-1) corner probe; ref_mv_ctx now splits (nearest_match, ref_match_count) exactly as mvref_common.c does - fix the REF_CAT_LEVEL DRL boost comparison (was trivially true); weights are boosted in place before the corner probe can add an unboosted entry - SymbolEncoder::tell(), the od_ec_enc_tell mirror the hunt relied on Gate: cargo test -p ec-av1 --release = 116 passed, 5 ignored.
feat(av1): inter tile writer sb_coeff_inter_frame_tileAhmet Kaan Gümüş · 302d3c4
feat(av1): inter tile writer sb_coeff_inter_frame_tile Flat 32x32-block-grid writer for inter frames: skip -> is_inter (ctx from above/left skip+inter tracking) -> intra path (Y_MODE by size group, not KF_Y_MODE) or inter path (single_ref chain, find_mv_stack, read_inter_mode NEWMV/NEARESTMV, DRL idx 0 only, mv_joint + per component symbols) -> existing coefficient path. Widens SymbolDecoder::symbol to pub(crate) for cross-module roundtrip tests. One-line encode.rs fix required for BlockCoeffs' two new fields (skip, inter) via ..BlockCoeffs::default() at its one non-spread construction site. Corner-cuts (documented in tile.rs): whole-superblock frames only, DRL always index 0, allow_high_precision_mv=0 assumed (validated, not silently rounded), InterMode limited to NearestMv/NewMv.
2026-08-25
feat(av1): the mode search prices its coefficients through the writer's CDFsAhmet Kaan Gümüş · 870ed18
feat(av1): the mode search prices its coefficients through the writer's CDFs The mode search costed the mode symbol exactly and the levels with a magnitude estimate. Now the levels go through write_coeffs on a throwaway encoder, so a trial is ranked by the bits the tile writer will really spend on it: end-of-block position, base levels, base range, signs and the Golomb tail, under the block's own contexts. The bit account prices the interval narrowing each symbol performs rather than its table entry, because the coder's eight-bit range multiply and its EC_MIN_PROB floor put the table entry 8% off the bytes actually written. Worth -1.19% BD-rate on a 1080p film frame and -0.20% on a screen capture against the estimate; LAMBDA_SCALE stays 0.1, re-swept.
feat(av1): the Golomb tail carries levels the base range cannot reachAhmet Kaan Gümüş · 0eba770
feat(av1): the Golomb tail carries levels the base range cannot reach The base and base-range syntax reach level fourteen between them, and until now the writer refused anything above it. The spec carries the rest as a Golomb tail — the remainder plus one, as its bit length in unary followed by its own bits — written after the coefficient's sign rather than beside its level, which is where `write_golomb` now puts it. The refusal moves up to the largest level the spec's twenty-bit reader can read back. Two gates. The spec's own `read_golomb`, written from the pseudocode, must hand back the level that was asked for over the whole range, which fails the moment the tail is a bit long, a bit short, or written against the wrong base. And ffmpeg must decode a run of DC levels either side of the threshold into a run of steadily brighter blocks, with the negatives of the same levels steadily darker, which fails if the tail lands in the wrong place in the syntax.
feat(av1): symbol coder for tile payloadsAhmet Kaan Gümüş · a580965
feat(av1): symbol coder for tile payloads AV1 specifies only the decoding process for its multi-symbol arithmetic coder, so the writer is derived as the inverse of section 8.2: it narrows the same interval decode_symbol tracks and flushes the shortest prefix that pins the interval down whatever bytes follow. CDF adaptation follows section 8.3.2, and CDFs are stored in the specification's own orientation (cumulative, 1 << 15 total, counter in the last entry) so the code reads against the spec text rather than against a decoder's internal complement. Covers the adaptive multi-symbol write, the fixed-CDF write, and L(n) literals; the flush handles carry propagation through the precarry buffer. Gated by a decoder written separately from the section 8.2 pseudocode: alphabets of 2..=16 symbols roundtrip over 4000 adaptive symbols each, 2000 mixed-width literals roundtrip, a 3000-item interleaving of both roundtrips, and a 1-in-256 stream is asserted to cost under a quarter bit per symbol so a backwards interval narrowing cannot pass. This is the primitive every AV1 tile payload is written through; the OBU writers so far cover only the headers around it.