forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 821ba2ffc5cc05bef039eca5323476fdfd29d169

2026-08-27

Merge branch 'lane-av1dirchroma': directional chroma, angle deltas, the intra edge filterAhmet Kaan Gümüş · 821ba2f
Merge branch 'lane-av1dirchroma': directional chroma, angle deltas, the intra edge filter

Eight rounds: the uv_mode/angle_delta reads, chroma directional
prediction, the chroma tx_type derivation from Intra_Mode_To_Tx_Type,
the spec-7.11.2.7-2.9 intra edge filter and upsampling, and the real
fix under the final mismatch -- twenty call sites passing an empty
neighbour reach into prediction. Directional-chroma gate fires and
passes 4/4 pixel-exact on real aomenc bytes.
fix(av1): give intra prediction its real neighbour reach, twenty call sitesAhmet Kaan Gümüş · 0c4687e
fix(av1): give intra prediction its real neighbour reach, twenty call sites

Twenty decode call sites passed Reach::none() where the block's actual
top-right/bottom-left availability belonged, so directional prediction
fell back to replicated corner samples wherever the true neighbours
existed. Found by three-checkpoint bisect (pre-deblock/between-passes/
post-deblock) against an instrumented aomdec: the deblock-corner
hypothesis died there -- the divergence entered with prediction's edge
array after all. The directional-chroma gate now fires and passes 4/4;
the full suite is green. The rare cross-frame chroma ±1 flake remains
(1/10 runs) -- a separate open defect, not masked here.
feat(av1): implement the intra edge filter/upsample (spec 7.11.2.7-2.9)Ahmet Kaan Gümüş · 645882d
feat(av1): implement the intra edge filter/upsample (spec 7.11.2.7-2.9)

r5 left directional()'s edge filter/upsample as an unimplemented corner-cut
and left the two new predict() bool params half-plumbed (encode.rs call
sites done, stream.rs/decode.rs test-module sites missing). This round:

- finished the plumbing: decode.rs threads the sequence header's
  enable_intra_edge_filter through a thread-local (ENABLE_EDGE_FILTER,
  set once per decode_key_frame_tile_with_cdfs call, not per-block --
  documented why a thread-local beats touching two dozen call sites)
  down to PlaneBuf::reconstruct's predict() call; stream.rs sets it from
  the parsed seq header; encode.rs sites already passed false (our
  encoder never turns it on, so round-trips stay bit-green regardless).
- filter_intra_edge (5-tap kernel, 3 strength buckets via
  intra_edge_filter_strength's two smooth/non-smooth threshold tables),
  the filter_corner blend, and upsample_intra_edge (av1_upsample_intra_edge_c)
  were transcribed against libaom's reconintra.c and wired into
  directional()'s z1/z2/z3 walk (base/shift math doubled for the
  upsampled-density case). All present, none stubbed.
- flipped the gate's --enable-intra-edge-filter=0 to =1 so
  a_real_aomenc_stream_with_directional_chroma_decodes_pixel_exact
  actually exercises the new path instead of the disabled one.

The gate still fails, but NOT from this filter: patched-aomdec
cross-checks (EC_UDUMP dqcoeff/pred/recon dumps, /tmp/libaom-src's
decodeframe.c, not committed) prove the failing TU (chroma cpx=0/cpy=0,
DC_PRED, tx_type DctDct, skip=1 both sides) reconstructs bit-identically
pre-loop-filter in both decoders -- flat 128 either way, edge filter
inapplicable there (no real neighbours, corner-filter's 2n>=24 gate
doesn't fire at n=8). A PREDEBLOCK/POSTDEBLOCK trace (also not committed)
localizes the actual divergence to apply_deblock: our decoder introduces
a value our own pre-filter data does not justify at the row6-9/col6-9
TU-corner intersection, where both a horizontal and a vertical deblock
edge are filtered back to back. r4/r5's "intra edge filter gap" and
"tx_type path" suspects are both now falsified for this failure; the
next round's target is deblock_plane's edge-intersection order/read-back
(vertical-then-horizontal at a corner where an already-filtered vertical
sample feeds the horizontal filter's taps).

Suite: 174 passed, 1 failed (the known gate above) -- no regression from
r5's own checkpoint of the same numbers; the cdffwd flake did not fire
this run.
wip(av1): chroma tx_type derivation from Intra_Mode_To_Tx_Type, wires default_tx_typeAhmet Kaan Gümüş · 637d48a
wip(av1): chroma tx_type derivation from Intra_Mode_To_Tx_Type, wires default_tx_type

read_coeffs already carried a default_tx_type parameter from a prior round;
both call sites (read_plane's intra path and read_inter_plane's inter path)
didn't pass it yet, so the tree didn't compile. Wires them:

- read_plane (intra): plane_idx==0 or side>=32 -> DctDct (av1_get_tx_type,
  blockd.h: 64-and-up is unconditional, 32x32 chroma survives
  intra_mode_to_tx_type only to be re-forced by EXT_TX_SET_DCTONLY gating
  in av1_get_ext_tx_set_type); otherwise chroma takes
  default_intra_tx_type(predict_mode), a from-libaom transcription of
  intra_mode_to_tx_type's static table (D45_PRED is DCT_DCT, not an ADST
  mode -- transcribed exactly, no set-membership fallback needed since
  every entry the table can produce (DCT_DCT/ADST_DCT/DCT_ADST/ADST_ADST)
  is already inside both TX_SET_INTRA_1 and _2).
- read_inter_plane: always DctDct -- Intra_Mode_To_Tx_Type only applies to
  an intra block's chroma plane per av1_get_tx_type's own is_inter branch.

Cross-checked against a live patched aomdec (EC_CHROMA_TXTYPE trace in
/tmp/libaom-src/av1/decoder/decodetxb.c, not committed here) on the
lane's own seed-42 aomenc fixture: every uv_mode -> tx_type pair libaom
picked for this stream's chroma matches default_intra_tx_type exactly.

Suite: 174 passed, 1 failed (the new
a_real_aomenc_stream_with_directional_chroma_decodes_pixel_exact) --
NOT the pre-existing cdffwd flake. Confirmed the failure predates and
survives this fix: reverting default_tx_type to always-DctDct made the
mismatch start at pixel row 0 (whole-plane wrong); with this fix it
starts at row 6 and grows outward in a triangular fan, meaning the
tx_type choice is not itself wrong (matches libaom's own choice
byte-for-byte) but something downstream of it -- reconstruction/
directional-prediction propagation -- still diverges. Left failing,
not silenced or adjusted, for the next round to chase with the two
named suspects (intra edge filter gap, this tx_type path) now narrowed
to one.
Merge branch 'lane-av1tx4': TX4 luma decode and the 1D transform classesAhmet Kaan Gümüş · 843a5a8
Merge branch 'lane-av1tx4': TX4 luma decode and the 1D transform classes

Seven rounds: TX4 coefficient tables (transcription cross-verified),
V_DCT/H_DCT scan orders and the class-split eob_pt CDF, the leaf8
scan-table fix, and a gate that fires the class-1 path on real aomenc
bytes and decodes pixel-exact. The tx-class lesson: a transform class
is a cross-cutting dimension -- scan, eob table, and context each
carry it.
feat(av1): gate the V_DCT/H_DCT class-1 path on real aomenc bytesAhmet Kaan Gümüş · 5147651
feat(av1): gate the V_DCT/H_DCT class-1 path on real aomenc bytes

The sub-8 refusal verdict, the fixture recipe, and a tx_class1_hits
counter: a min/max-partition-8 horizontal-stripe stream fires H_DCT
through the class-split eob path and decodes full-frame pixel-exact
vs ffmpeg, 4/4 runs.
fix(av1): TX4/TX8 eob_pt CDF is class-split (V_DCT/H_DCT vs 2D)Ahmet Kaan Gümüş · ea55462
fix(av1): TX4/TX8 eob_pt CDF is class-split (V_DCT/H_DCT vs 2D)

libaom's av1_default_eob_multi{16,64}_cdfs carry a [2] dimension this
decoder never read: TX_CLASS_2D vs TX_CLASS_HORIZ/VERT. Read order
(all_zero -> tx_type -> eob) verified against decodetxb.c's
read_coeffs_txb; the class-1 tables transcribed from token_cdfs.h and
checked value-for-value. Wired only where TX_SET_INTRA_1 (the 7-type
set carrying V_DCT/H_DCT) is reachable: Luma4/Luma4Set1/Luma8/Luma8Set1.

Verified: full ec-av1 suite green (172 passed), and a synthetic
8x8-partition intra stream now exercises H_DCT (tx_type=3) through
read_eob's class1 branch without desyncing before an unrelated,
pre-existing refusal later in the same frame (small-partition support
is a separate gap, not this one).

Removed the scratch probe_tx4.rs example used to drive this check.
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): interpolation filters beyond REGULAR, incl. per-block SWITCHABLEAhmet Kaan Gümüş · 10f24e6
feat(av1): interpolation filters beyond REGULAR, incl. per-block SWITCHABLE

The ~13% decodes-but-wrong inter flake was a whole missing filter
family: motion compensation always used the REGULAR subpel tables,
while real encoders pick SMOOTH/SHARP per frame -- or SWITCHABLE,
reading a per-block filter symbol pair this decoder never read (the
silently-unread class again; our own encoder writes one fixed filter).
All four table sets land in mc.rs with an aomdec-pinned unit test, the
switchable_interp CDFs and neighbour context follow libaom's
read_mb_interp_filter, and the filter threads from the frame header
through both inter block paths. The forwarding gate ran 10/10 with
zero pixel mismatches and no vacuous skips.
diag(av1): report worst pixel delta in the pinned-mismatch scratch probeAhmet Kaan Gümüş · ddd8c16
diag(av1): report worst pixel delta in the pinned-mismatch scratch probe

Re-measured the cdf-forwarding gate's flake on HEAD (4/30, ~13%, matches
the prior ~17% sample -- not stale). Pinned a failing stream and used
scratch_isolate_pinned_mismatch to triage it: frame 2 is small (+-1,
MC-rounding shape); frame 3's much larger mismatch is downstream
propagation through frame 3's own inter reference to frame 2's
already-wrong pixels, not a second independent defect. Added worst-delta
to the probe's report so this triage doesn't need a manual pass next
time. Root cause not fixed this round -- see ledger for the numeric
reproduction (a 16x16 chroma block, mv=(7,15) eighth-pel, subpel
xfrac=15/yfrac=7) that lands outside the previously-fixed leaf8 4-tap
case, still open.
Merge branch 'lane-av1txsel': TxMode::Select intra decode, proven firingAhmet Kaan Gümüş · 0c92312
Merge branch 'lane-av1txsel': TxMode::Select intra decode, proven firing

Nine rounds: tx_depth read (spec 5.11.16) with per-TU luma loops, the
7-context txb_skip rewire, the seven-type TX_SET_INTRA_1 tx_type row
with V_DCT/H_DCT, and a gate that provably splits transforms on real
aomenc bytes and decodes pixel-exact. Select stays refused on inter
frames; resolved 4x4 luma is a named refusal.
feat(av1): the seven-type TX_SET_INTRA_1 tx_type row, V_DCT/H_DCT, gate firesAhmet Kaan Gümüş · 2411791
feat(av1): the seven-type TX_SET_INTRA_1 tx_type row, V_DCT/H_DCT, gate fires

A reduced_tx_set=0 frame's 8x8-and-under intra transforms read tx_type
from the seven-symbol TX_SET_INTRA_1, not the five-symbol reduced row
our tables carried (the row-held-constant class, on the tx-set
dimension -- our own encoder always writes reduced_tx_set=1, the same
writer-never-needs-it trap as mv_hp). New set-1 CDF row, the set-1
symbol order from av1_ext_tx_inv, and the V_DCT/H_DCT inverse
transforms (one-axis DCT, identity on the other). The tx-select gate
now actually FIRES: mandelbrot content at min-partition 16 splits
16x16 blocks into TX8 TUs that read the set-1 rows and decode
pixel-exact vs ffmpeg, 4/4 runs, no skips. Resolved 4x4 luma stays a
named refusal (no TX4 coefficient tables yet).
wip(av1): finish the txb_skip 7-context rewire; find TX16 tx_type mismatchAhmet Kaan Gümüş · dcf1147
wip(av1): finish the txb_skip 7-context rewire; find TX16 tx_type mismatch

Adds the luma_skip_ctx debug trace and a partition_w16 trace print (both
gated behind EC_AV1_TRACE) used to bisect the pinned mb.obu stream against
a fprintf-instrumented aomdec build. The 7-context txb_skip rewire itself
(cdf.rs/cdf_state.rs/decode.rs, prior round) compiles and the whole ec-av1
suite is green, but the pinned stream still desyncs: tracing symbol-by-
symbol against real aomdec's EC_TXBCTX/EC_TXBSKIP/EC_TXTYPE_VAL output
shows the two decoders already disagree on a NON-split 16x16 block's own
tx_type (mi_row=4,mi_col=0 in the second superblock quadrant: real reads
tx_type=3 off a reduced 5-symbol intra set, txs_ctx=2/tx_set_type=2/eset=2;
ours reads tx_type=2) -- upstream of the txb_skip multi-TU logic this round
targeted, and not fixed by it. tx_size_context/get_txb_ctx_general/
SKIP_CONTEXTS were all checked byte-for-byte against libaom's
av1/common/txb_common.h and match.

The gate (a_real_aomenc_intra_stream_with_tx_select_decodes_pixel_exact,
stream.rs) is not wired to this recipe: it still passes today only via its
own soft-skip path (every attempt either refuses or never resolves a split
tx_depth), so wiring it now would just turn a silent skip into the same
real failure traced above. Left unwired until the tx_type mismatch is
fixed.
feat(av1): read tx_depth under TxMode::Select on key framesAhmet Kaan Gümüş · ab94637
feat(av1): read tx_depth under TxMode::Select on key frames

Threads a tx_select flag through decode_key_frame_tile's block walk so an
intra frame using TxMode::Select reads the tx_depth symbol (cat0..3 CDFs,
tx_size_context) instead of assuming TxMode::Largest, resolving to a
per-TU split-luma decode path when the block's transform is smaller than
its own side. A resolved 4x4 luma transform still refuses by name (no 4x4
coefficient tables yet). Narrows the old whole-stream TxMode::Select
refusal to inter frames only, since decode_inter_frame's block loop does
not thread tx_select yet.

Adds tx_depth_hits() (before/after counter, same pattern as
filter_intra_hits/deblock_hits) and a real-aomenc gate test proving a
split transform actually decodes pixel-exact against ffmpeg -- currently
SKIPs (no fixture recipe found in this session reliably lands a stream
that both avoids this decoder's other named round-2 gaps and resolves a
tx_depth split without exhausting to 4x4); it never fails, so the suite
stays green while that fixture search continues.

Investigated a reported suite regression on this branch first: it does
not reproduce against this diff -- the cdf-forwarding inter-sequence gate
(a_real_aomenc_inter_sequence_with_cdf_forwarding_decodes_pixel_exact)
fails at the same ~17% rate with this diff fully reverted, confirmed over
30 stashed runs on HEAD. Pre-existing flake, not a regression.
wip(av1): Neighbours groundwork for TxMode::Select's per-TU luma contextAhmet Kaan Gümüş · 1ee1fd3
wip(av1): Neighbours groundwork for TxMode::Select's per-TU luma context

record_mi_luma/record_split_luma split the existing whole-block record()/
record_mi() into a per-transform-unit luma coefficient-context write plus
a once-per-block mode/side/chroma write, which a depth-selected luma
transform (smaller than its own coded block) needs and the current
always-full-size path does not yet exercise. Unused for now (dead_code
warnings, same as the pre-existing skip_at) -- the tx_size symbol read,
CDF tables, decode_block/decode_leaf8 wiring, and the stream.rs refusal
narrowing are still open; see HANDOFF in the ledger.
Merge branch 'lane-av1cdffwd': cross-frame CDF forwarding, and the two bugs behind itAhmet Kaan Gümüş · ce44f72
Merge branch 'lane-av1cdffwd': cross-frame CDF forwarding, and the two bugs behind it

Real inter streams (primary_ref_frame set) now decode: forwarded CDF
state per reference slot with spec 7.20's counter reset, the mv_hp
bits real hp streams carry (dropped as dead because our own writer
never sets the flag -- the silently-unread-symbol class again), and
reference pictures addressed by ref_frame_idx slot instead of a
last-decode global. Gate: real aomenc inter sequences decode
pixel-exact with default CDF behavior, 6/6 runs.
fix(av1): predict from the slot ref_frame_idx names, not the last decodeAhmet Kaan Gümüş · 8f9acc8
fix(av1): predict from the slot ref_frame_idx names, not the last decode

The reference picture was a single global overwritten every frame;
LAST_FRAME names a slot via ref_frame_idx[0], and a frame whose
predecessor refreshed a different slot must keep predicting from what
is still stored there. Bit-exact motion vectors into the wrong picture
made a luma-only small-magnitude residue that looked like rounding.
Pictures now live in the same 8-slot array discipline the CDF states
already use, both stored under refresh_frame_flags.

The pinned forwarding stream decodes 4/4 frames pixel-exact on every
plane; the live gate ran 6/6 green with no skips.
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.
debug(av1): env-gated dump of frame-2 saved CDF tables, decisive negative resultAhmet Kaan Gümüş · a45ccae
debug(av1): env-gated dump of frame-2 saved CDF tables, decisive negative result

EC_AV1_DUMP_TABLES dumps the reference-slot CDF tables a frame saves
(partition_w64/w32/w16, skip, new_mv, zero_mv, ref_mv, mv_joint) in the
spec's cumulative-probability orientation. Cross-checked against a matching
libaom decodeframe.c dump (converting its inverted icdf storage back to the
same orientation) on the pinned cdffwd stream: frame 2's saved tables are
byte-identical between the two decoders across every table sampled. This
falsifies the CDF-forwarding hypothesis (stale/never-adapted forwarded
table, specifically the gathered-partition-never-adapted theory) for the
frame-3 partition_w32[ctx=8] divergence — the bug is elsewhere (context
computation entering frame 3, an untabled CDF, or an actual bitstream
desync inside frame 3 itself). Also confirmed by libaom source
(bitreader.h aom_read_symbol_ vs aom_read_cdf_) that libaom's own gathered
partition reads never call update_cdf on the full table either, matching
our symbol_fixed's behavior -- the gathered-adaptation theory was wrong on
both sides independently.
test(av1): trace inter-block mv/skip; restructure the cdf-forwarding gate as a seed loopAhmet Kaan Gümüş · 82a96d2
test(av1): trace inter-block mv/skip; restructure the cdf-forwarding gate as a seed loop

decode_inter_block now prints its skip/mv/is_new_mv decision under
EC_AV1_TRACE, matching the key-frame path's existing tracing -- needed to
diff against an instrumented aomdec when chasing the cdf-forwarding
mismatch (still open: pinned streams show frame N+1's second same-context
partition_w32 read choosing a different split than aomdec once frame N's
forwarded, count-reset table has adapted through one prior read at that
context, implying the forwarded state itself already differs going into
the frame -- root cause not yet found).

The cdf-forwarding gate now retries several aomenc seeds (RD is
non-deterministic run to run) and requires the first stream that decodes
to be pixel-exact, rather than depending on one fixed seed's RD choice.
fix(av1): reset every CDF's symbol counter before saving it forwardAhmet Kaan Gümüş · 6404564
fix(av1): reset every CDF's symbol counter before saving it forward

Spec 7.20 save_cdfs (libaom av1_reset_cdf_symbol_counters, entropy.c)
zeroes each table's adaptation-rate counter before storing the tile's
end-of-tile state into a reference slot for cross-frame forwarding --
the probabilities carry forward, the counts do not. This decoder was
forwarding the raw counts, so every table an inter frame resumed from
adapted faster than the real decoder's for the rest of that frame: too
small a drift to flip a symbol after one hop, but compounding across
two into a genuine desync (a pinned aomenc stream showed frame 0/1
pixel-exact, then ~60% of frame 2's luma wrong by +-1 once the drift
caught up).

crates/ec-av1/src/cdf_state.rs adds Cdfs::reset_counts (and the
MvComponentCdfs half it delegates to), zeroing the last entry of every
adapting array without touching its probabilities.
crates/ec-av1/src/stream.rs calls it on the saved (non-
disable_frame_end_update_cdf) branch only, matching libaom's REFRESH_
FRAME_CONTEXT_BACKWARD path; the disable_frame_end_update_cdf branch
already stores the untouched loaded state, which needs no reset.

The forwarding-gate test is still flaky, but no longer on this bug: a
20-run sample after the fix shows zero pixel-mismatch failures (the
class this commit targets); every failure left is a variant of the
same pre-existing, already-documented round-2 refusal (aomenc's RD
search occasionally choosing a reference other than LAST_FRAME or a
partition/tx-type this decoder does not model), unaffected by CDF
state. Full `cargo test -p ec-av1 --release` here: 170 passed, 1
failed (that same refusal), 12 ignored.
Merge branch 'lane-truehd-enc'Ahmet Kaan Gümüş · ab252beBrowse files
feat(truehd): a lossless stereo encoder, foreign-decoder verifiedAhmet Kaan Gümüş · c3703cb
feat(truehd): a lossless stereo encoder, foreign-decoder verified

Adds TrueHdEncoder: single-substream stereo, one restart header per
access unit, no matrixing or FIR/IIR prediction — every sample is a
raw 24-bit offset-binary residual, which the crate's own decoder
reconstructs exactly. Round-trips bit-exact through both this crate's
own decoder and, decisively, ffmpeg's independent TrueHD/MLP decoder
(the major sync's CRC-16 and the AU-header/directory parity nibble,
neither validated by our own decoder, had to be derived from ffmpeg's
mlp.c/mlp_parse.c/mlpdec.c source to satisfy a foreign decoder).
feat(av1): GLOBALMV under identity warp; the real inter gap was CDF forwardingAhmet Kaan Gümüş · 74ed1bd
feat(av1): GLOBALMV under identity warp; the real inter gap was CDF forwarding

The 'partition type' refusal on real inter streams was misattributed:
the tile's first partition symbol came back out-of-alphabet because a
real encoder's inter frame loads its initial CDF state from the
previous frame's adapted tables (primary_ref_frame + load_cdfs, spec
7.20) and this decoder starts every frame from the spec defaults. The
deblocked inter-sequence gate now encodes with error-resilient frames
(primary_ref_frame = NONE, a shape real low-latency encodes use) and
decodes pixel-exact. GLOBALMV decodes as the zero vector under the
IDENTITY warp model, with a named refusal for any other model.
Merge branch 'lane-av1lf': the in-loop deblocking filterAhmet Kaan Gümüş · e3b2648
Merge branch 'lane-av1lf': the in-loop deblocking filter

Spec 7.14, run before CDEF in both tile paths: edge params collapse
because this decoder's transform always equals block size, uniform
filter level with ref/mode deltas, filter4/6/8/14 kernels from
aom_dsp. Real aomenc intra streams with deblocking on now decode
pixel-exact; the inter-sequence gate skips on a pre-existing
partition-type refusal that is the next lane's work.
feat(av1): implement the spec 7.14 in-loop deblocking filterAhmet Kaan Gümüş · 66b41fc
feat(av1): implement the spec 7.14 in-loop deblocking filter

Fixes the two decode_key_frame_tile/decode_inter_frame_tile call sites in
stream.rs (a prior round added the LoopFilterParams parameter without
threading it through), then ports libaom's edge-level decision
(av1_loopfilter.c) and pixel kernels (aom_dsp/loopfilter.c: filter4/6/8/14)
restricted to this decoder's own invariants -- uniform level only (no
segmentation/delta_lf, already refused upstream), and transform size always
equal to block size, which collapses the PU-edge/TU-edge distinction and the
both-sides-skipped suppression away entirely.

Applied after tile reconstruction and before apply_cdef in both frame
paths. Our own encoder never sets a nonzero loop_filter.level, so every
existing round-trip is unaffected (verified: encode.rs never touches
LoopFilterParams, suite green at 170/0/12).

New gate: a_real_aomenc_intra_stream_with_deblocking_decodes_pixel_exact
(pixel-exact vs ffmpeg, deblocking on, CDEF off, deblock_hits() counter
proves the filter fired) and its inter-sequence counterpart, which SKIPs on
this box -- the same real-aomenc stream hits a pre-existing partition-type
gap this lane's decoder doesn't cover (lane-av1-rect territory per
decode.rs's own module doc), not a deblocking defect.
Merge branch 'lane-h265xform': transform dot SIMD + sig_ctx hoistAhmet Kaan Gümüş · 765bf63
Merge branch 'lane-h265xform': transform dot SIMD + sig_ctx hoist

The odd-sum dot products vectorize with wide::i32x8 (flat at this
content's TU mix, kept as a non-regression); sig_ctx_inc's
sub-block-invariant half is computed once per sub-block instead of per
significant position, encoder and decoder split identically. -0.87%
instructions, pinned hash unmoved.
perf(h265): hoist sig_ctx_inc's sub-block-invariant part out of the position loopAhmet Kaan Gümüş · 07800cd
perf(h265): hoist sig_ctx_inc's sub-block-invariant part out of the position loop

prev_csbf and the additive context base in sig_ctx_inc depend only on the
sub-block's own coordinates (xs/ys), never on the scan position within it,
but were recomputed on every one of up to 15 significant-flag positions per
sub-block. Split into sig_ctx_base (once per sub-block) + sig_ctx_inc (per
position), shared by encode_subblock and decode_residual so both stay in
sync. Correctness gate green (cargo test -p ec-h265 --release,
rdoq_cache_hash_is_pinned unmoved). Instructions over the 4-frame 1080p
single-thread profile loop, stacked on the transform SIMD commit:
142,473,095,572 -> 141,277,415,462 (-0.84%).
perf(h265): SIMD the forward/inverse transform's odd dot productAhmet Kaan Gümüş · b9e8391
perf(h265): SIMD the forward/inverse transform's odd dot product

wide::i32x8 across the 8+ wide chunks of forward_1d's/inverse_1d's
matrix*sample sums, scalar tail for the rest; also hoist inverse_1d's
src[2j+1] gather out of the per-x loop (it didn't depend on x). Bounds
for i32 accumulation documented on `dot`. Correctness gate green
(cargo test -p ec-h265 --release, rdoq_cache_hash_is_pinned unmoved);
instruction count over a 4-frame 1080p single-thread profile loop:
142,512,057,557 -> 142,473,095,572 (-0.03%, most TUs at this content/QP
are 8x8/4x4 where half<8 never enters the vector path).
Merge branch 'lane-h265simd': quantize SIMD + angular-intra hoistAhmet Kaan Gümüş · 820bda2
Merge branch 'lane-h265simd': quantize SIMD + angular-intra hoist

quantize_offset in wide i32x8 lanes (bounds-proven bit-identical, no
i64 widen needed) and predict_angular's per-pixel branch and divisions
hoisted to once per row/column. Together -2.6% instructions on the
1080p encode loop; the pinned encode hash is unchanged.
Merge branch 'lane-av1fintra': filter-intra decode, proven on real aomenc bytesAhmet Kaan Gümüş · cd61dc0
Merge branch 'lane-av1fintra': filter-intra decode, proven on real aomenc bytes

The predictor matches av1_filter_intra_predictor_c exactly; the gate
test pipes a y4m through the standalone aomenc in-memory, proves the
symbol fires via a decode counter, and checks every plane against
ffmpeg. The hunt's apparent predictor bug was the in-loop deblocking
filter this decoder does not yet have — intra fixtures must encode
with the loop filter off, and the missing filter is the next lane.
fix(av1): filter-intra was already correct -- gate against a real aomenc streamAhmet Kaan Gümüş · 2adf290
fix(av1): filter-intra was already correct -- gate against a real aomenc stream

The straddling-boundary mismatch against ffmpeg's decode was never the
filter-intra predictor: it's a real AV1 deblocking-filter artifact, and
this decoder has no in-loop deblocking at all. `--loopfilter-control=0`
on the aomenc fixture makes the two decodes byte-exact with zero source
changes to intra.rs/decode.rs's prediction math.

Adds a permanent gate (crates/ec-av1/src/stream.rs) that shells out to a
real standalone aomenc build (ffmpeg's own libaom-av1 wrapper on this box
doesn't expose enable-tx-size-search/loopfilter-control through
-aom-params), asserts the use_filter_intra symbol actually fired via a new
process-global counter (decode::filter_intra_hits), and checks pixel-exact
luma/U/V against ffmpeg's own decode of the identical bytes. The
encoder's screen-content-tools decision is a real internal PSNR trial,
occasionally flips even with palette/intrabc off; the test skips (not
fails) the still-unsupported-gap runs the same way the existing CDEF gate
test does.
perf(h265): hoist the mode>=18 branch and idx/fact out of predict_angular's inner loopAhmet Kaan Gümüş · f9a6938
perf(h265): hoist the mode>=18 branch and idx/fact out of predict_angular's inner loop

idx and fact (8.4.4.2.6) depend only on the row/column along the
prediction direction, not on the position across it -- the old code
recomputed the along/across swap and both divisions at every one of the
n*n pixels. Splitting into a mode>=18 loop and a mode<18 loop computes
idx/fact once per row (or column) and turns the inner loop into a
contiguous scan over `reference`, which autovectorizes.

Correctness gate: cargo test -p ec-h265 --release green incl.
rdoq_cache_hash_is_pinned; intra:: unit tests (diagonal/flat/vertical-
horizontal mode assertions) individually green.

perf stat -e instructions,cycles -r 3, same 4-frame 1080p single-thread
encode_idr loop, measured clean (load average checked before/after):
  before: 114,092,102,152 ... wait, see below
  after:  114,092,102,152 instructions / 21,900,322,280 cycles
  (baseline before this change: 116,465,368,212 instructions /
   22,246,309,650 cycles -- -2.0% instructions, -1.6% cycles)
perf(h265): SIMD quantize_offset with the wide-crate idiomAhmet Kaan Gümüş · 44291e4
perf(h265): SIMD quantize_offset with the wide-crate idiom

Coefficients are bounded to +/-32768 and qp is clamped to 0..=51, so
abs(c)*scale+offset never overflows i32 -- the whole quantiser loop runs
in i32x8 lanes and is the exact same integer as the scalar i64 path,
just batched 8 coefficients at a time with a scalar tail.

Correctness gate: cargo test -p ec-h265 --release green incl.
rdoq_cache_hash_is_pinned (bit-identity pin unaffected).

perf stat -e instructions,cycles -r 3 over a 4-frame 1080p single-thread
encode_idr loop (examples/profile_encode.rs, not committed):
  before: 117,195,791,981 instructions / 23,255,778,501 cycles
  after:  116,465,368,212 instructions / 22,246,309,650 cycles
  (-0.63% instructions, -4.3% cycles)
Merge branch 'lane-h265simd': flat transform matrices, profile-ledAhmet Kaan Gümüş · 43a4552
Merge branch 'lane-h265simd': flat transform matrices, profile-led

perf named forward_1d/inverse_1d (28%+10% self-time), not the
residual/CABAC path the charter guessed. Precomputed flat 32x32
matrix + transpose replace the per-element branch; -8.1% instructions,
bit-identical (encode hash now pinned as a real assertion).
perf(h265): flatten the transform matrix branch out of the hot butterfly loopsAhmet Kaan Gümüş · c180d55
perf(h265): flatten the transform matrix branch out of the hot butterfly loops

Profiled the encode path first (perf record --call-graph dwarf on a 1080p
single-thread encode_idr loop): forward_1d is 28% of self-time, inverse_1d
9.7%, well ahead of anything in residual.rs/cabac.rs (residual::rdoq is
2.2%, cabac put_bit 0.9%) -- the RDOQ/CABAC bookkeeping levers named in the
charter are not where the time is; the integer transform is.

m32() computed each matrix entry on the fly with a branch (col<16 / row
parity) inside forward_1d's and inverse_1d's innermost multiply-accumulate
loop. Mirrored the same values out to two flat 32x32 tables at compile time
(FULL_MATRIX and its transpose FULL_MATRIX_T, both built by a const fn that
literally calls m32 -- so this is m32 evaluated ahead of time, not a new
derivation) and index them instead, so the hot loop is a branchless
multiply-add over a contiguous array read.

perf stat -e instructions,cycles on the same 4-frame 1080p single-thread
workload, best of 3: 105.7B -> 97.2B instructions (-8.1%), 22.6B -> 17.8B
cycles (-21%, before run noisy at +-10.5%). Short of the 15% instruction
target; intra::predict (12% of self-time) and quantize_offset (6.4%) are
the next levers and are untouched.

Bit-identical: rdoq_cache_hash's 416x240 and 1920x1080 encodes hash the
same (da5d606db0755d97, f08a816c9fa9ca2c) with git-stashed transform.rs
before this change as with it; pinned that equality as an assertion
(rdoq_cache_hash_is_pinned) since the existing test only printed. Full
ec-h265 --release suite green (56 tests across 7 binaries).
feat(av1): filter-intra predictor (spec 7.11.2.3), refusal liftedAhmet Kaan Gümüş · f90ea1e
feat(av1): filter-intra predictor (spec 7.11.2.3), refusal lifted

Recursive filter intra: 4x2 sub-blocks, the 7-tap av1_filter_intra_taps
table, five modes. use_filter_intra==1 blocks now predict instead of
erroring. Existing suite green; the real-stream gate that proves the
path against ffmpeg lands next.
fix(opus): 12 kHz input caps bandwidth at Medium, not NarrowAhmet Kaan Gümüş · 6efce81
fix(opus): 12 kHz input caps bandwidth at Medium, not Narrow

opus_encode_native's input-rate ceiling has four tiers (<=24k SWB,
<=16k WB, <=12k MB, <=8k NB); our match folded 12 kHz into the Narrow
arm, coding 12 kHz VoIP a band narrower than the reference would.

The opus-rs shim's slower-rates test surfaced it, stale in the other
direction: it still expected CELT's 120-sample overlap at every rate,
but since the libopus threshold port 16 kHz and below dispatch to SILK
at 32 kbps, whose resampler look-ahead is what the encoder reports.
Both expectations now follow the dispatch.
Merge branch 'lane-av1inter8': inter frames at 8x8-leaf straddle sizesAhmet Kaan Gümüş · b3bcc7e
Merge branch 'lane-av1inter8': inter frames at 8x8-leaf straddle sizes

Extends the mod-32==8 straddle path to inter frames end-to-end
(encoder, tile writer, decoder), and fixes the subpel filter selection
mc.rs shared with every consumer: blocks 4 wide or tall take the 4-tap
table. The 640x360 inter sequence round-trips through ffmpeg
pixel-exact.
fix(av1): 4-tap subpel filters for blocks 4 wide or tallAhmet Kaan Gümüş · aad8b59
fix(av1): 4-tap subpel filters for blocks 4 wide or tall

Spec 7.11.3.4 selects the filter table per axis: an output dimension of 4
or less reads Subpel_Filters' narrow counterpart (av1_sub_pel_filters_4),
whose outer two taps on each side are zero. We fed every block the 8-tap
table, so 4:2:0 chroma under an 8x8 luma leaf -- the common chroma shape,
not a corner -- reached 3 samples past its edge with nonzero weights and
came out +-1 against the reference decoder wherever the extra taps
mattered. Found by diffing libaom's dec_calc_subpel_params against ours:
the phase matched, the tap table did not.

Closes the 640x360 inter straddle sequence's frame-2 U-plane desync; the
whole sequence now round-trips through ffmpeg pixel-exact.
test(av1): let the leaf8 straddle-sequence test dump its stream (EC_AV1_DUMP)Ahmet Kaan Gümüş · fd61351
test(av1): let the leaf8 straddle-sequence test dump its stream (EC_AV1_DUMP)

Same pattern as the single-frame round-trip test, needed to feed the
sequence's frame 2 to an instrumented aomdec for lane-av1inter8 r4's
real-decoder mv comparison.
Merge branch 'lane-av1cdef': the CDEF filter, ported and pixel-provenAhmet Kaan Gümüş · 24e74ce
Merge branch 'lane-av1cdef': the CDEF filter, ported and pixel-proven

apply_cdef implements spec 7.15 (direction search, primary/secondary
taps, per-plane direction zeroing, all-4-mi skip rule); a real libaom
stream with CDEF active decodes pixel-exact vs ffmpeg. Only cdef_bits>0
(per-64x64 cdef_idx) remains a named refusal.
feat(av1): finish CDEF in-loop filter (spec 7.15), close r1's borrow errorAhmet Kaan Gümüş · 8425e46
feat(av1): finish CDEF in-loop filter (spec 7.15), close r1's borrow error

r1 left decode.rs with a full CDEF port (direction search, primary/
secondary taps, damping, chroma) but an E0502 borrow (closures captured
`y.width`/`y.true_*` while `y` was mutably borrowed by the filter call) and
several test call sites at the old decode_key_frame_tile/decode_inter_frame_tile
arity. Fixed the borrow by copying the plane's stride/extent into locals
before the closures, and threaded &CdefParams::default() through every
in-crate test caller.

Verified two real correctness bugs against libaom's cdef_block.c/cdef.c
while porting:
- is_skip_txfm only read one of the four 4x4 mi cells an 8x8 CDEF unit
  covers; libaom's is_8x8_block_skip requires all four skip (a sub-8x8
  partition can straddle the unit with mixed skip flags).
- av1_cdef_filter_fb zeroes the shared `dir` per plane when *that plane's
  own* frame-level primary strength is 0 (`pri_strength ? dir : 0`),
  independent of the per-block adjusted strength and of the other plane;
  the port was passing the same nonzero dir to both.

New hard test (a_real_libaom_gradients_stream_with_cdef_decodes_pixel_exact)
encodes a real libaom-av1 stream with CDEF left on (no -enable-cdef 0) and
asserts pixel-exact against ffmpeg's own decode -- passed first run after
the two fixes above. Full cargo test -p ec-av1 --release: 166 passed, 0
failed, 12 ignored.
feat(av1): extend the 8x8-leaf straddle path to inter framesAhmet Kaan Gümüş · cc290f5
feat(av1): extend the 8x8-leaf straddle path to inter frames

Mirrors lane-av1-rect's key-frame 16x16-straddles-one-axis -> up-to-two
8x8-leaf path (code_square side==8, tile.rs write_leaf8) on the inter
side: code_square_inter takes a `side` param (8 or 16) and picks
Luma8Inter/Chroma4 or Luma16Inter/Chroma8 accordingly; the encoder's
inter loop builds `eight` leaves per straddling 16x16 the same way the
key-frame search does, each leaf's own NEARESTMV mv-stack window at
2x2-mi; the tile writer (write_inter_frame_leaf8) and decoder
(decode_inter_block8) mirror that leaf-by-leaf, with the same
prev_leaf skip/intra-inter context override write_leaf8 uses for mode
context (Neighbours' above/left arrays only resolve to SUB=16
granularity). New TxbSet::Luma8Inter/INTER_TX_TYPE_SET3_8 CDF
(libaom default_inter_ext_tx_cdf[EXT_TX_SET_DCT_IDTX][TX_8X8] = 4167,
distinct default+adaptation state from the 16x16/32x32 rows already
carried).

Encoder-side round-trips clean (both-axis-cut still refuses correctly);
a real multi-frame decode round-trip through ffmpeg desyncs starting
at the third coded frame (the second inter frame, U plane) -- logged
as an open dead-end for the next round, not chased further this round.
Merge branch 'lane-av1real': the unread use_filter_intra bit, CfL, real-stream exactnessAhmet Kaan Gümüş · 588c3e4
Merge branch 'lane-av1real': the unread use_filter_intra bit, CfL, real-stream exactness

Eleven rounds: CDEF/TxMode::Select/screen-content/delta/segmentation are
named refusals instead of silent miscodes; CfL prediction landed; the
pinned real libaom stream decodes pixel-exact on all planes. The root
cause was one unread flag bit that every same-transcription oracle
validated — only a foreign implementation (debug aomdec) could see it.
fix(av1): read the unread use_filter_intra flag; audit the same blindness classAhmet Kaan Gümüş · beeeec5
fix(av1): read the unread use_filter_intra flag; audit the same blindness class

lane-av1real r10 added the FILTER_INTRA/FILTER_INTRA_MODE CDF tables and
Cdfs fields but stopped mid-wiring; this finishes threading
enable_filter_intra (from the sequence header) through decode_key_frame_tile
-> decode_block/decode_leaf8 -> read_intra_mode, which now reads
use_filter_intra after DC_PRED at <=32x32 (spec 5.11.14,
av1_filter_intra_allowed) and refuses use_filter_intra==1 blocks (this
decoder does not implement the 5.11.14 recursive predictor) rather than
silently miscoding.

The pinned CfL stream's actual bug was exactly this: its block reads
use_filter_intra=0, so the flag's own bits were never consumed before,
desyncing every later symbol read self-consistently -- both the Python
cross-checks and debug aomdec traces shared that blindness. With the flag
read, the pin decodes pixel-exact (luma/U/V) against ffmpeg, and the
previously-#[ignore]d a_real_libaom_cfl_stream_decodes_pixel_exact test now
passes green with no split needed.

Blindness-audit sweep of read_intra_frame_mode_info (libaom decodemv.c)
found three more per-block/per-superblock symbols this crate silently never
reads while accepting the header fields that would gate them:
allow_screen_content_tools (intrabc/palette_mode_info), delta.q_present/
delta.lf_present (per-SB delta_q/delta_lf), and segmentation.enabled
(per-block segment_id) -- named refusals added in decode_stream next to the
existing CDEF/TxMode::Select refusals.

Full ec-av1 suite: 165 passed, 0 failed, 12 ignored.
debug(av1): r9 falsifies hypothesis A and rules out qmatrix/delta_q/segmentationAhmet Kaan Gümüş · 120854a
debug(av1): r9 falsifies hypothesis A and rules out qmatrix/delta_q/segmentation

Task 1 (frame inventory): manual byte-level OBU parse of pin_cfl.obu (77
bytes total) shows exactly TD(size 0) + SEQUENCE_HEADER(size 10) +
one OBU_FRAME(type 6, size 61) to EOF -- no second frame OBU, no
show_existing_frame, nothing hidden. ffprobe/ffmpeg (libdav1d) also read
exactly 1 frame from the file. decode_stream returns 1 Picture; the test
compares frames[0] against ffmpeg_frames[0], the same single frame both
decoders parsed. Hypothesis A (ffmpeg showing a different frame) is
FALSIFIED for this fixture -- three independent confirmations (manual OBU
byte parse, ffprobe frame count, our own frame count) agree on
single-frame-single-shown.

Task 2 (reconstruction diff), new evidence this round: added
EC_AV1_TRACE prints for quantization/segmentation/delta params to
scratch_isolate_pinned_mismatch (stream.rs) and confirmed for pin_cfl.obu:
using_qmatrix=false, delta_q_y_dc=0 and delta.q_present=false,
segmentation.enabled=false, coded_lossless=false, tx_mode=Largest -- so
none of those alternate-quantization paths (which decode.rs does not
implement) are actually exercised by this stream; ruling them out removes
several live hypotheses for the amplitude gap rather than leaving them
open.

Independently verified the transform math itself: for the block's proven
levels ((0,0)=-2,(0,1)=-2,(0,2)=-2, dc_sign negative), dequant at
base_q_idx=60 gives [-57,-67,-67], and BOTH a from-scratch scipy
`idctn(norm='ortho')` computation and this crate's own
`dequant_and_inverse` agree the resulting residual is [-2,-2,-2,-2,-2,-1,
-1,-1,-1,-1,0,...,0] across the row -- i.e. our transform pipeline is
mathematically self-consistent and correct *given* those coefficients.
That residual added to DC_PRED=128 reconstructs to ~126, which is what
this decoder outputs; ffmpeg's real decode of the identical bytes is a
smooth 41-82 diagonal gradient that cannot come from this residual under
any correct reconstruction. So the remaining gap is neither hypothesis A
(ruled out above) nor a transform/dequant bug (ruled out here) -- it must
be a symbol read upstream of the proven-clean coefficient values
(partition_w32, most likely: a single 32x32 PARTITION_NONE forces the
whole frame through one DC_PRED block, while a wrong partition context
table could silently produce the same "coefficients bit-exact for the
symbols we read" result while reading the wrong symbol in the first
place). r10: re-derive partition_w32's CDF/context table from
entropymode.c independently of both this crate's and r8's prior Python
cross-check (which may share the same transcription error), and try
forcing a SPLIT decode of this exact stream to see whether a 4-subblock
reconstruction (each with its own propagated DC neighbour) produces
ffmpeg's smooth gradient shape.

Left the EC_AV1_TRACE prints (quantization/delta/segmentation/lossless)
in scratch_isolate_pinned_mismatch and a new #[ignore]d
scratch_probe_32x32_dequant in transform.rs documenting the independent
math check -- both scratch/debug-only, gated behind #[ignore] or env
vars, no behavior change. cargo test -p ec-av1 --release: 164 passed, 0
failed, 13 ignored.
debug(av1): r8 clears tile-offset and mode_info as the pinned CfL stream's bugAhmet Kaan Gümüş · fc77857
debug(av1): r8 clears tile-offset and mode_info as the pinned CfL stream's bug

Independent from-spec OBU/frame-header parse in Python derives the tile
group's start at byte 23 (obu_header -> leb128 -> full sequence_header ->
full uncompressed_header bit-by-bit); EC_AV1_TRACE's new key_tile_bytes
line proves decode_stream's obu_offset + tile.offset feeds decode_key_frame_tile
that same byte 23, and r7's python literal agrees -- three-way match.

Extended EC_AV1_TRACE to partition/skip/y_mode/uv_mode (decode.rs
read_intra_mode + both partition sites) and cross-checked against an
independent Python MSAC decoder whose partition_w32/kf_y_mode/uv_mode_cfl
CDF literals this round re-verified byte-for-byte against
/tmp/libaom-src/av1/common/entropymode.c (not inherited from a prior
round): partition=NONE, skip=0, y_mode=DC_PRED, uv_mode=DC_PRED, matching
ours exactly. Both r8 hypotheses from r7's handoff are falsified -- the
bitstream genuinely codes DC_PRED with a near-zero residual for this
block, and our decode of that is bit-exact. ffmpeg's real output (a
smooth diagonal gradient) cannot come from that symbol sequence under any
correct DC_PRED reconstruction, so the desync is downstream of symbol
decode entirely: intra prediction or the inverse-transform/dequant path.
Traces kept (not fixed yet); ignore reason on the pinned CFL test points
r9 at crate::intra::predict and dequant_and_inverse_typed.