forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 214cdf2befd543569feaaaf45888fe80e40318dfFiltered to crates/ec-av1/src/transform.rsClear filter

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.