Commits
Commits on
5a2f5efe3a0771ac7ca43d57bdf63c19a7b75ff6Filtered to crates/ec-av1/src/transform.rsClear filter2026-08-30
fix(av1): thread per-plane quantizer deltas (delta_q_y_dc/u_dc/u_ac/v_dc/v_ac) into dequantAhmet Kaan Gümüş · 8560456
fix(av1): thread per-plane quantizer deltas (delta_q_y_dc/u_dc/u_ac/v_dc/v_ac) into dequant Spec 5.9.12/7.12.2: these were parsed by ec-av1-syntax and used for nothing but the lossless[] check. Threaded QuantDeltas through dequant_coeff_wh/ dequant_wh/dequant_and_inverse_typed(_wh) and all 8 decode.rs leaf call sites, plane-correct (Y has no AC delta). decode_stream's 5 call sites now pass header.quantization.delta_q_*; convenience wrappers pass ::default(). Plain 4-arg dequant/dequant_coeff/dequant_and_inverse (~20 external callers in tile.rs/encode.rs/transform.rs) unchanged. Blast radius measured, not assumed: EC_AV1_TRACE now prints the 5 deltas at parse time. Measured zero on the r10 pinned repro (seed42.obu, base_q_idx 180) and on every stream the scoped decode::/quant::/transform:: suites exercise (27/27 green) -- no gate was passing "for the wrong reason". Charter's 81-vs-76 defect is NOT this: deltas are genuinely zero for seed42, disproven by measurement per the charter's own fallback clause. Pinned repro currently panics on an unrelated pre-existing gap (32x32 partition value=4, later superblock, same shape as the r9 part32-AB dead-end) before it can even reach the pixel comparison. Report names the next suspect (CURRENT_Q_IDX per-superblock delta-q state / segmentation qindex) with a one-line instrumentation step, left for the next round. Red: pinned_sbpart_stream_decodes_pixel_exact still fails (pre-existing, unrelated gap, not a regression from this diff).
wip(av1): rectangular inverse transform + libaom dump harness (in progress)Ahmet Kaan Gümüş · 1a9fc2c
wip(av1): rectangular inverse transform + libaom dump harness (in progress) Committed by the orchestrator: the builder hit its turn cap mid-verification.
2026-08-28
wip(av1): reduced_tx_set=false inter tx sets -- CDFs + inverse transforms, NOT WIRED YETAhmet Kaan Gümüş · 8dbd683
wip(av1): reduced_tx_set=false inter tx sets -- CDFs + inverse transforms, NOT WIRED YET
Compiles clean; NOT YET reachable from any decode path (dying-words WIP,
budget exhausted mid-lane -- entropy layer is done, threading is not).
What this round did (root cause from r1: cdf_state.rs TxbSet::Luma16Inter/
Luma8Inter hardcode the reduced_tx_set=true 2-symbol table; a real aomenc
stream with reduced_tx_set=false needs wider sets there):
1. Transcribed from /tmp/libaom-src (entropymode.c:369-403, entropymode.h:
169-185, blockd.h:1036-1122, common_data.h:149-159, av1_txfm.h:169-207,
txb_common.h:32-47, aom_dsp/txfm_common.h:52-68):
- av1_ext_tx_set_lookup[is_inter=1][tx_size_sqr==TX_16X16] gives, for a
16x16 inter block, EXT_TX_SET_DTT9_IDTX_1DDCT (12 symbols) -- NOT
DTT4_IDTX_1DDCT as the r1 handoff guessed (right symbol count, wrong
set name); for 8x8 (and 4x4) inter, EXT_TX_SET_ALL16 (16 symbols).
- New cdf.rs tables INTER_TX_TYPE_SET2_16 (TX_16X16 row of
default_inter_ext_tx_cdf[EXT_TX_SET_DTT9_IDTX_1DDCT]) and
INTER_TX_TYPE_SET1_8 (TX_8X8 row of
default_inter_ext_tx_cdf[EXT_TX_SET_ALL16]), transcribed verbatim.
- New cdf_state.rs storage (inter_tx_type_16_set2, inter_tx_type_8_set1),
reset1-wired (adaptation) and seeded from the new cdf.rs tables in
Cdfs::new -- both join the existing reset sweep so a forwarded-CDF
frame carries them too (av1-cdffwd-three-bugs class: nothing here is a
new table left off the forwarding/reset map).
- New TxbSet::Luma16InterSet1/Luma8InterSet1 variants + txb() match arms.
2. Coverage check (tx-class-cross-cutting class, repo memory) -- swept
every libaom array indexed by tx_type/tx_set for the new TxType members
this needs (FLIPADST_DCT, DCT_FLIPADST, FLIPADST_FLIPADST, ADST_FLIPADST,
FLIPADST_ADST, V_ADST, H_ADST, V_FLIPADST, H_FLIPADST -- 9 new variants):
- transform.rs: TxType gained the 9 variants + from_symbol_set2_12 (12-
symbol table, av1_ext_tx_inv[EXT_TX_SET_DTT9_IDTX_1DDCT]) +
from_symbol_all16 (16-symbol, av1_ext_tx_inv[EXT_TX_SET_ALL16]).
- axes(): FLIPADST reads the *same* 1D ADST kernel as ADST (common_data.h
vtx_tab/htx_tab map both FLIPADST_1D and ADST_1D to the identical
butterfly network) -- no new 1D transform to port, confirmed against
av1_inv_txfm2d.c's inv_txfm2d_add_c (lines 234-316): the flip is pure
post-processing (lr_flip reverses which column the column-pass reads,
ud_flip reverses which output row the result lands in), never a
different arithmetic kernel. Added TxType::flip() and rewired
inverse_transform_2d_typed to read from an un-mutated `residual`
buffer into a separate `out` buffer under the flip (the naive in-place
version has a real RAW hazard: for side/2 columns, a flipped write at
iteration j clobbers a source column iteration side-1-j will read
later -- caught before it shipped, not left as a corner-cut).
- decode.rs TxClass::of: V_ADST/V_FLIPADST -> Vert, H_ADST/H_FLIPADST ->
Horiz (txb_common.h's tx_type_to_class table), matching V_DCT/H_DCT's
existing treatment -- coefficient scan/context tables are already
generic over TxClass, not TxType, so no further surface needed there.
- decode.rs read_coeffs: CDF-length dispatch (already the crate's own
idiom, doc'd at the read site) extended from 2-way to 4-way: 17 slots
-> from_symbol_all16, 13 -> from_symbol_set2_12, 8 -> from_symbol_set1,
else -> from_symbol (unchanged 2-/5-symbol sets).
3. NOT DONE (why this is WIP, not a fix): no call site actually threads
reduced_tx_set into TxbSet::Luma16InterSet1/Luma8InterSet1 selection.
decode_inter_frame_tile_with_cdfs (decode.rs:6197) does not even take a
reduced_tx_set parameter -- the entire inter tile path hardcodes the
reduced (2-symbol) inter tables today, unconditionally. Wiring needs:
- reduced_tx_set: bool added to decode_inter_frame_tile/_with_cdfs
(decode.rs:6147/6197) and its caller (stream.rs, frame-header
reduced_tx_set bit -- already parsed for the key-frame/intra path,
needs finding/threading for inter frames too).
- threaded through decode_inter_block (4259) and decode_inter_block8
(5384) as a new parameter, to their four call sites (6399, 6465,
6535, 7307).
- TxbSet::Luma16Inter -> Luma16InterSet1 and Luma8Inter ->
Luma8InterSet1 selection gated on !reduced_tx_set at decode.rs:6484,
7326 (Luma16*) and 5746, 5940 (Luma8*) -- mirroring txbset_for's
existing reduced_tx_set match, but for the inter call sites which
currently have no such helper.
- the pinned repro (cdfflake-stream-seed45.bin) will not go green
until this wiring lands; not run this round since the desync path
is still unreached.
Intra ext-tx (default_intra_ext_tx_cdf) was NOT re-checked for the same
hardcoding this round -- r8's comment (Luma8Set1/Luma4Set1 exist) says
intra's reduced_tx_set split is already handled at 8x8/4x4, and 16x16
intra is DCT_IDTX-set-only regardless of the flag per
av1_get_ext_tx_set_type (`tx_size_sqr == TX_16X16` branch skips the
`use_reduced_set` check for BOTH is_inter values) -- so intra should
already be correct, but this was reasoned, not re-verified against
entropymode.c line by line this round.
Also unaddressed (pre-existing, r1-noted gap): no Luma4Inter path exists
at all in this crate -- an inter TX_4X4 transform (also EXT_TX_SET_ALL16
under reduced_tx_set=false, TX_4X4 row of the same CDF, not yet
transcribed) has nowhere to decode to. Out of this round's scope.2026-08-27
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).
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.
feat(av1): decode ADST_ADST/ADST_DCT/DCT_ADST/IDTX intra transformsAhmet Kaan Gümüş · a170052
feat(av1): decode ADST_ADST/ADST_DCT/DCT_ADST/IDTX intra transforms Ports av1_iadst4/8/16 and av1_iidentity4/8/16/32 from libaom's own av1_inv_txfm1d.c (stage-for-stage, not hand-derived), wires TxType through read_coeffs -> dequant_and_inverse_typed, and lifts the DCT_DCT-only refusal for TX_SET_INTRA_2's five members. Axis convention (row=htx_tab, col=vtx_tab) read directly off libaom's av1_inv_txfm2d.c tables and gated by an asymmetric-input test. Reference vectors for the 1D ports came from a C probe linked against libaom's own build/decoder-debug/libaom.a, not memory.
perf(av1): replace the forward DCT's matmul with an FFT factorizationAhmet Kaan Gümüş · 5bfacbb
perf(av1): replace the forward DCT's matmul with an FFT factorization forward_transform_2d ran an O(n^2) dot product against a cached DCT-II basis per row and column, on every RD trial. Replaced with Makhoul's FFT-based DCT-II reduction (O(n log n)), with the twist table and FFT stage twiddles precomputed per size and the 1D transform working on fixed-size stack buffers -- both measured necessary; a first cut with runtime cos/sin and heap Vec scratch was slower than the matmul it replaced. The old matmul is kept under #[cfg(test)] as the differential oracle for a new fast_forward_matches_the_naive_matmul test. All existing transform tests, including the quantizer roundtrip and 64x64 coded- quarter tests, pass unchanged.
perf(av1): cache the forward DCT basis; make it contiguous, both bit-exactAhmet Kaan Gümüş · 91b85b5
perf(av1): cache the forward DCT basis; make it contiguous, both bit-exact Added stage_timing_breakdown (a perf probe, #[ignore]d like the existing sweeps): 1920x1080 13-mode key frame was 3.97s. forward_and_quantize alone was 32.25us/call at 32x32, more than inverse+entropy combined -- because dct_basis() recomputed side*side cosines from scratch on every single mode trial, size-invariant work redone thousands of times a frame. Two levers, both exact (same summation order, so identical bits out): - dct_basis is now built once per transform size and cached (OnceLock), not recomputed per trial. - forward_transform_2d's two matrix passes are written as contiguous dot products (row of residual/basis, then a transposed row pass) instead of one strided index loop, so the optimizer can vectorize them. forward_and_quantize: 32.25us -> 15.38us per 32x32 call. 1920x1080 13-mode key frame: 3.97s -> 1.78s (2.2x). 3840x2160: 10.60s -> 7.08s (1.5x). cargo test -p ec-av1 --release: 129 passed, 0 failed, 5 ignored (the new probe). All streams stay byte-identical to their own reconstruction.
2026-08-25
feat(av1): forward transform and quantizer, gated end to end through ffmpegAhmet Kaan Gümüş · 5f0963e
feat(av1): forward transform and quantizer, gated end to end through ffmpeg AV1 specifies only the inverse transform, so the encoder half is written against a measurement of it: one dequantized coefficient at a time comes back out as its orthonormal basis function scaled by dq_denom(side)/8, at every size and position. The dequantizer's own denominator cancels that, leaving a size-independent level = 8 * orthonormal(residual) / q. The gates are the roundtrip error (must be the quantizer and nothing else), the 64x64 band limit (only the top-left 32x32 is coded), and an end-to-end picture that ffmpeg decodes sample-exactly into what the encoder reconstructed. A transposed column pass and the previous, coarser gain constant are both killed.
feat(av1): dequantization and the inverse DCTAhmet Kaan Gümüş · 6a83833
feat(av1): dequantization and the inverse DCT An encoder that cannot say what the decoder will show cannot choose coefficients by what they cost against what they are worth. This adds the decode-side arithmetic to ec-av1: the dequantizer of spec 7.12.3 and the inverse DCT of 7.13, written from the specification's own butterfly stage list so that one network serves every size from 4 to 64. The gate is agreement with a real decoder, sample for sample: two key frames whose first block carries coefficients from DC to the far corner decode under ffmpeg to exactly 128 plus the residual this code computes, over all 1024 and 4096 samples. Beneath that sit the two tables of decoder-pinned DC residuals the tile tests already carried, all 28 levels of each, plus structural gates for the transpose, the sign rounding, and the row shifts of the four sizes the frame syntax cannot reach. Mutation-checked: a cosine table entry off by one, and an 8x8 row shift off by one, each fail a named test.