forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 8dbd683068d7f87f21dcc4ed1dfdca786d82c52bFiltered to crates/ec-av1/src/msac.rsClear filter

2026-08-28

wip(av1): root-cause cdfflake-stream-seed45 pin -- reduced_tx_set=false inter tx_type gapAhmet Kaan Gümüş · dcd3feb
wip(av1): root-cause cdfflake-stream-seed45 pin -- reduced_tx_set=false inter tx_type gap

Bisected the pinned frame-2 mismatch (cdfflake-stream-seed45.bin, 359/4096
luma px, worst delta 6, right-edge block). Added scratch instrumentation
(env-gated, zero behavior change): scratch_dump_prefilt in decode.rs
(EC_AV1_PREFILT_DUMP_OURS, mirrors the instrumented aomdec's own
EC_AV1_PREFILT_DUMP) and an EC_RNG per-symbol trace in msac.rs
(SymbolDecoder::symbol_fixed), matching libaom's aom_dsp/entdec.c format
exactly (rng_before/rng_after/nsyms/symbol, shared global counter).

Verdict: PIXEL-PATH, not entropy garbage-cascade in the usual sense --
pre-deblock buffers already differ (497/4096 luma mismatches at frame 2,
rows 48-63 cols 32-63, exactly the mi(12,8)/mi(12,12) 16x16x2 region),
proving the defect is in reconstruction, but the root symbol-level cause
IS a real entropy divergence: gdb-bisected via `EC_RNG` + a conditional
breakpoint on od_ec_decode_cdf_q15 in the instrumented aomdec build to
n=787, which resolves (backtrace) to av1_read_tx_type ->
decodetxb.c:read_coeffs_txb, nsyms=12 -- libaom's EXT_TX_SET_DTT4_IDTX_1DDCT,
selected by av1_get_ext_tx_set_type(TX_16X16, is_inter=1,
use_reduced_set=0) (blockd.h:1097, av1_ext_tx_set_lookup[1][1]). Our
decoder read a 2-symbol table (nsyms=2) at the same point instead.

Root cause: cdf_state.rs's TxbSet::Luma16Inter (and Luma8Inter) are
hardcoded to the *reduced_tx_set=true* 2-symbol EXT_TX_SET_DCT_IDTX table
only (doc comments there already say so explicitly); this crate's own
writer always emits reduced_tx_set=true so the gap never showed up on a
round-trip test. A real aomenc stream with reduced_tx_set=false (this
pin) hits an inter 16x16 block whose tx_type this decoder cannot read at
all -- it silently misreads a binary CDF where the real bitstream encoded
a 12-way EXT_TX_SET_DTT4_IDTX_1DDCT symbol, desyncing the rest of the
frame's own coefficient reads (491 more luma reads through the tile) and
poisoning the CDFs forwarded into frame 3.

Same-shape sibling gaps found by reading av1_get_ext_tx_set_type
(NOT yet fixed, name only): 8x8 inter + reduced_tx_set=false wants
EXT_TX_SET_ALL16 (16-symbol), also unimplemented (Luma8Inter is likewise
reduced-only per its own doc comment). 32x32+/64x64 inter are fine
(EXT_TX_SET_DCT_IDTX unconditionally regardless of reduced_tx_set, per
blockd.h:1101-1102) -- Luma32Inter's existing 2-symbol table is already
correct there.

NOT fixed this round (budget): needs a new TxbSet::Luma16InterSet1
(12-symbol CDF, transcribed from libaom entropymode.c
default_inter_ext_tx_cdf[EXT_TX_SET_DTT4_IDTX_1DDCT][TX_16X16], + the
EXT_TX_SET_DTT4_IDTX_1DDCT symbol->TxType mapping from
av1_ext_tx_used/inter table), wired into decode_inter_block's TxbSet
selection (currently hardcoded to TxbSet::Luma16Inter at every call site,
e.g. decode.rs:6484) gated on `!reduced_tx_set`, and the same for
TxbSet::Luma8InterSet1 (16-symbol EXT_TX_SET_ALL16). Dying words: pull
default_inter_ext_tx_cdf's 16x16-DTT4_IDTX_1DDCT row (12 probs) and the
matching tx_type index table from
/tmp/libaom-src/av1/common/av1_entropymode.c +
av1/common/enums.h(EXT_TX_SET_DTT4_IDTX_1DDCT symbol order), add the two
TxbSet variants + a reduced_tx_set-gated select at every `16 =>` /
`8 if reduced_tx_set` dispatch site feeding an inter block, then rerun
scratch_isolate_pinned_mismatch on cdfflake-stream-seed45.bin to confirm
4/4 frames byte-exact, then remove scratch_dump_prefilt/EC_RNG (or leave
as documented scratch, orchestrator's call), then the cdf-forwarding gate
5x + full ec-av1 --lib suite 3x.
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.