Commits
Commits on
052d1d3f81ff6b9e7c09b93b58c5e772d825fcb3Filtered to crates/ec-av1/src/transform.rsClear filter2026-09-29
lanes: classify the ignored ec-av1 probes, un-ignore the 1080p tile gateAhmet Kaan Gümüş · 408e7cf
lanes: classify the ignored ec-av1 probes, un-ignore the 1080p tile gate
lane-av1probes. The release triage dispositioned the 15 process-global gates
and skipped the probe/benchmark set; that set was a black box. This lands the
classification and the three fixes it found.
Measured (release, one cargo invocation per test name, EC_AV1_REQUIRE_FFMPEG=1
EC_AV1_REQUIRE_AOMENC=1 EC_REQUIRE_FIXTURES=1, TMPDIR off the tmpfs) on server
host-a and on the workstation for the real-library rows: 38 ignored
non-gate items at base 745c60e7 -- 32 REAL DIAGNOSTIC VALUE, 5 STAGING, 1
ROBUST-RED, 0 DEAD WEIGHT, 0 decoder defects. Nothing in the set is dead; what
was broken is the REASON TEXT, which is what this commit fixes.
1. UN-IGNORE a_1080p_multi_tile_stream_decodes_sample_exact_through_both_decoders.
It was ignored only for its wall ("1080p encode: minutes") and is the only
1080p arm in the ignored set that ASSERTS. Plain release run on this tree:
1080p 2x1/2x2/4x2 tiles, 84488/84208/84685 bytes, all sample-exact, ok in
27.39 s. The check is a per-frame first-differing-luma-sample comparison
against ffmpeg, not a length or non-empty smoke. Both skippable halves route
through the crate's EXISTING probes (h264_clip_frames -> have_ffmpeg() +
clip.exists(), and have_ffmpeg() for the ffmpeg arm); no new presence-check
shape. Ignore count 51 -> 50.
2. REASON REWRITES, 11 items whose reason misdescribed them. The wall
benchmarks now carry their measured wall and their host floor
(tile_search_wall_1080p TIMED OUT at 2400 s on a 4-core server and takes
1243 s on 12 cores); filter_stage_wall_film says it measures the BARS
fixture without EC_AV1_WALL_CLIP; the four bare #[ignore] scratch probes
name their env vars, including the three geometry vars of
scratch_isolate_pinned_mismatch whose 64/64/1 default is wrong for every
real pin; sweep_rectx_recipes stops carrying a lane label;
tpl_intra_denominator_histogram stops claiming film fixtures it never
opens; the two prune_k sweeps say they are local-run because their clip
paths are hard-coded /home/user absolutes; probe_split says it panics on
its own lossless synthetic rows.
3. stage_timing_breakdown_inter printed "motion search (NEWMV) 17.82ms (of
which interpolation 148.63ms)" -- a sub-number larger than its parent. Both
timers were always real; the print's attribution was wrong. Bucket 0 times
only the NEWMV/GLOBAL sub-search (stage_since(0) fires after
find_best_new_mv and the global-MV search), and bucket 1 is EVERY
mc::predict call including a committed block's final prediction, which runs
outside any bucket-0 region. Bucket 1 is now its own top-level row with the
overlap quantified and explicitly not added to the total; the residual is
labelled for what it contains. The accounting closes: 107.27 + 157.56 =
264.83 ms against a 264.82 ms wall.
No decoder logic changed: every source edit is a #[ignore] reason, a doc
comment, or the one eprintln block above.lossless WHT: a non-4x4 unit is reconstructed as a 4x4 raster, not asserted awayAhmet Kaan Gümüş · c465d06
lossless WHT: a non-4x4 unit is reconstructed as a 4x4 raster, not asserted away
libaom cannot code a lossless transform unit that is not 4x4: read_tx_mode
(decodeframe.c:140) returns ONLY_4X4 for a coded_lossless frame before it
looks at the tx_mode symbol, read_tx_size (:1117) returns TX_4X4 before it
looks at a tree, get_vartx_max_txsize (blockd.h:1447) returns TX_4X4 for
EVERY plane of a lossless block, and of idct.c's highbd_inv_txfm_add_*_c only
highbd_inv_txfm_add_4x4_c carries a lossless branch -- the rest fall through
to the IDCT, because there is no non-4x4 lossless inverse transform to
dispatch to. So a non-4x4 lossless unit is this decoder's own transform-unit
geometry being wrong, and neither refusing nor papering over it is what the
reference does: the honest total is the raster of 4x4 WHT units libaom's
lossless geometry would have produced for that footprint.
MEASURED, not assumed: the premise that a RELEASE build "silently runs a
wrong-shape transform" is REFUTED. On the two independent 4:4:4 lossless
witnesses the debug build stops at decode.rs:2787
`debug_assert_eq!((self.w, self.h), (4, 4))` with `left: (8, 4)`, and the
RELEASE build dies one frame later with an opaque
`range end index 8 out of range for slice of length 0` -- it panics, it does
not mis-transform. The defect is real either way: a debug-only assert was the
only thing naming the invariant, and release's failure message named neither
lossless nor the transform.
decode.rs
- TxParams::run: the debug-only shape assert (and the debug-only
`tx_type == DctDct` assert on an argument the WHT never reads) are
replaced by a counted call into the shape-total entry. Counted by
LOSSLESS_WHT_SPLIT_UNITS, which must read 0 on any stream whose lossless
unit geometry is right.
- decode_intrabc_rect: a LOSSLESS rect intra-BC block's chroma plane block
is now `bw >> ss_x` by `bh >> ss_y` (av1_get_max_uv_txsize is
ss_size_lookup[bsize], no halving of its own -- at 4:4:4 that is the
block's own footprint) walked as a (cw/4)*(ch/4) PLANE-MAJOR raster of
TX_4X4 units through the existing read_inter_chroma_lossless, with the
per-unit coefficient contexts replayed over the whole-block
record_split_luma_rect_mi (class override-slot-on-one-arm, the same one
decode_rect_split's ll_chroma_units replay exists for). Counted by the
exclusive INTRABC_RECT_LOSSLESS_CHROMA4_HITS. Scoped to `lossless` on
purpose: the 4:2:0 halving is right at 4:2:0, and zero pinned fixtures
decode a LOSSLESS intrabc rect block, so no green pin moves.
transform.rs
- dequant_and_inverse_wht: the shape-total lossless entry. 4x4 is the same
single call it always was, so the lossless fast path is bit-for-bit
unchanged; any other shape is the raster of 4x4 WHT units over a
row-major w-wide grid, zero-filled on a partial tile, empty-grid marker
preserved. No shape panics and no shape returns a buffer its caller
cannot index.
MEASURED: the pinned witness (fixtures/ll444_sb64_1to4_lossless.obu, 51107 B,
sha256 fdb64679.., testsrc2 256x256 yuv444p10le, aomenc --lossless=1
--profile=1 --i444 --enable-1to4-partitions=1 --min-partition-size=4
--max-partition-size=64 --sb-size=64 --enable-intrabc=1) went from a RELEASE
panic / DEBUG Golomb-tail refusal to 2 decoded frames, 24576 lossless WHT
units and 0 non-4x4 ones. 43 named lossless / 4:4:4 / intrabc-rect gates stay
green (21 `lossless`, 16 `444`, 5 `intrabc_rect`, 1
`rect16x4_chroma_reach`), in release.
The gate's pixel arm is a measured per-frame, per-plane exact PREFIX, not an
exactness claim: frame 0 is byte-exact to sample 32992 of 65536 on all three
planes and frame 1 to 55008 (Y) / 9378 (U,V). The residual forks are a
separate defect, named with their coordinates in lanes/whtshape.report.md r3.2026-09-24
2026-09-08
fix(av1 decoder): dequantize a rectangular intra transform unit with the block's segment quantizer, not the frame'sAhmet Kaan Gümüş · cd170cb
fix(av1 decoder): dequantize a rectangular intra transform unit with the block's segment quantizer, not the frame's The rect intra paths passed FrameCtx::current_q_idx where every square path passes block_q_idx, so a block in a segment carrying SEG_LVL_ALT_Q was dequantized with the frame's own index. Only a frame edge forces rectangular partitions in the reference encoders' streams, so this showed up as a bottom-straddle-only mismatch: the whole 1920x792 reference ladder (libaom and rav1e, 8 points) now decodes sample-exact against ffmpeg, as does a 384x152 straddle repro.
2026-09-07
test(av1): the typed round trip covers 32x32 (IDTX); an le16 arm for the inter searchAhmet Kaan Gümüş · 5c1d094
test(av1): the typed round trip covers 32x32 (IDTX); an le16 arm for the inter search The unconditional inter arm loses 20+ BD points on both synthetic bars rows of the 12-frame gate while film A gains 0.2; libaom's own census never codes IDTX at 32x32, so EC_AV1_TXSET_INTER=le16 offers the two-type set at 16x16 and below only.
feat(av1): search an intra luma transform unit's own tx_typeAhmet Kaan Gümüş · 2fd2ac4
feat(av1): search an intra luma transform unit's own tx_type The writer coded DCT_DCT for every luma transform unit ever written -- the symbol was a constant -- while the five-type reduced-set alphabet (TX_SET_INTRA_2: IDTX, DCT_DCT, ADST_ADST, ADST_DCT, DCT_ADST) was already the CDF it wrote into. The search now offers that set per intra luma unit, priced through the same RDOQ'd trial path (the tx_type symbol included, coeff_bits_typed), and the writer names the chosen type through the decoder's own symbol map (decode::tx_type_symbol, keyed by the CDF's alphabet width, so the two cannot drift). The forward transform gains the FLIPADST family as well: a flipped axis is the plain ADST basis over the mirrored residual, which is what the decoder's ud_flip/lr_flip undoes. All sixteen types now round trip.
feat(av1): rate-distortion optimised quantisation behind a preset leverAhmet Kaan Gümüş · 4cc1d86
feat(av1): rate-distortion optimised quantisation behind a preset lever The deadzone quantiser rounded every coefficient blind to what its level costs; every reference has the pass that decides that against the entropy coder (libaom av1_optimize_txb, rav1e optimize_txb). tile::rdoq walks the scan in reverse and lowers each level one step at a time while the bits it gives back outweigh the squared error it adds, pricing every candidate through the same coeff_bits/write_coeffs the search and the writer use, so no second cost model can drift from the writer. Applied inside the trial loop (trial_typed, code_from_prediction), so the reconstruction, the price and the written levels are all the pass's grid. EC_AV1_RDOQ=0 restores the plain quantiser and the byte pins.
feat(av1): lossless key frames decode exact; lossless inter refused by nameAhmet Kaan Gümüş · 1e1a080
feat(av1): lossless key frames decode exact; lossless inter refused by name Key/intra-only lossless frames decode sample-exact at 8 and 10 bit (64x64, 256x128 8-bit, 192x96 10-bit libaom -crf 0 streams, 0 sample diffs vs ffmpeg). The inter path's luma leaves are synthesized as TX_4X4 but its chroma plane is still one transform per block, so a lossless INTER frame is refused by name and the refusal inventory carries it. The old refusal gate becomes a_lossless_libaom_key_frame_decodes_sample_exact.
feat(av1): a lossless key frame decodes sample-exactAhmet Kaan Gümüş · b0db8e9
feat(av1): a lossless key frame decodes sample-exact The rect strip readers take the per-transform-unit walk on a lossless frame (depth_to_tx_wh returns TX_4X4 before it looks at the block), their chroma is coded as 4x4 units plane-major with get_txb_ctx's +10 offset rows, and the Walsh-Hadamard orientation is pinned by measurement. A 64x64 libaom -crf 0 key frame now decodes sample-exact against ffmpeg (6488 entropy steps identical to aomdec's EC_TRACE_COEFF, 0 sample diffs).
feat(av1): lossless decode groundwork -- WHT, TX_4X4 forcing, CfL narrowingAhmet Kaan Gümüş · f0a5a15
feat(av1): lossless decode groundwork -- WHT, TX_4X4 forcing, CfL narrowing The 4x4 Walsh-Hadamard inverse (libaom av1_iwht4x4_16_add_c) with its own round-trip test, a per-frame CodedLossless flag replacing the refusal (a frame mixing lossless and lossy segments is still refused by name), the TX_4X4 forcing in the square and 8x8-leaf intra readers, no tx_type symbol (libaom read_tx_type: qindex 0 returns early), DCT_DCT on every plane, the is_cfl_allowed narrowing to a 4x4 chroma plane block, and the +10 chroma txb_skip rows at TX_4X4 that only a lossless frame reaches.
2026-09-06
test(av1): pin the typed forward transform bit-identical to its strided formAhmet Kaan Gümüş · e70dd64
test(av1): pin the typed forward transform bit-identical to its strided form Compares raw bit patterns, not an epsilon: the contiguous-basis rewrite is exact only because it moved the loop over the outputs and left each output's term order alone, so a reassociation would surface here as a last-place difference. Covers every non-flipped non-DCT type at 4/8/16/32, with an all-zero residual and a half-zero-rows residual so both skips are walked.
perf(av1): exact integer SAD/SSE and a vectorizable typed forward basisAhmet Kaan Gümüş · fae8c1b
perf(av1): exact integer SAD/SSE and a vectorizable typed forward basis Two byte-exact rewrites on the encoder search's hottest loops, both proved by the enc_probe FNV set on the three gate clips at four q points. `Plane::block_sad`/`block_sse` replace four hand-rolled `f64` accumulations that ran an integer division and remainder per sample to recover (row, col) from a flat index. The sums they replace are whole numbers far below 2^28, so `f64` held every partial sum exactly and neither the order of the adds nor the accumulator type can change the result. `forward_transform_2d_typed`'s two matmuls summed over a strided basis, which no vectorizer can touch. `axis_basis_t` caches the transposed basis so the pass is contiguous in the basis index and strided in nothing; each lane's terms stay in the same order, so the levels are unchanged. The row pass now also records which rows it filled, and the column pass walks only those. 1080p ladder, 12 frames, 4 q points: 111.09e9 -> 101.65e9 instructions:u (-8.5%, ABAB x2).
perf(av1): the forward transform skips an all-zero residual, and the quantizer stops dividing per coefficientAhmet Kaan Gümüş · eca6458
perf(av1): the forward transform skips an all-zero residual, and the quantizer stops dividing per coefficient A census of the BD gate's own ladder (12 frames, four quality points): 4.14M DCT_DCT forward transforms (67% 4x4, 24% 8x8, 6% 16x16, 2% 32x32) of which 72% carry an all-zero residual, and 1.86M non-DCT ones (77% 4x4, 23% 8x8) of which 68% do. The fixed-point path skipped those row by row and column by column but still allocated the row buffer; the f64 analysis basis the non-DCT types use had no skip at all and ran both matmuls over zeros. Both now return early -- exactly, since a row of zeros contributes only `0.0 * b` terms and a sum of zeros is `+0.0` -- and `quantize` walks rows and columns instead of recovering them with a division per coefficient. Byte-exact: 1080p gate ladder unchanged (same FNV-1a per stream); 6.61s -> 6.24s.
perf(av1): ten headroom bits under the forward network, measured on BDAhmet Kaan Gümüş · 636712f
perf(av1): ten headroom bits under the forward network, measured on BD Six bits of headroom left the fixed-point network's rounding worth 3.9 BD points on screen capture against libaom. Ten put the coefficient resolution at 1/256 of a unit of the `8 * orthonormal` scale a level is formed on, which is where the BD gate stops moving -- 13 bits measures identical -- and stays under 2^27 for a 12-bit residual through two 64-point passes. BD-rate vs libaom 216.6/233.5/289.8 (base 216.4/235.5/289.2), vs rav1e 157.4/175.9/138.1 (base 157.8/178.3/141.1), 1080p/2160p/screen: six of the eight numbers improve, screen-vs-libaom is +0.6 and 1080p-vs-libaom +0.2. Also measured and REVERTED: the row pass's `Vec` in a thread-local scratch, as the inverse transform's is, +5.0% instructions -- reusing the buffer needs a `memset` where a fresh allocation is already zeroed, and that zeroing is what the all-zero-row skip reads. Noted at the function.
perf(av1): form the levels off the forward transform's own fixed pointAhmet Kaan Gümüş · 1be1614
perf(av1): form the levels off the forward transform's own fixed point `forward_and_quantize` transformed into a `Vec<f64>` of coefficients and then read it back to quantize. With the network already in fixed point the column pass can hand each column straight to the level formation while it is still in `t`, so the coefficient buffer and the pass over it are gone -- and a 64-point transform's uncoded columns (everything outside the top-left 32x32 the syntax carries) are not transformed at all. 209.0 G -> 178.9 G instructions:u on the sequence bench (-14.4%). Two eight-wide column passes were measured and REVERTED: the `[i32; 8]` Lane over eight columns is +3.4%, an in-place whole-buffer column pass +2.3%. Both lose the per-column zero skip and the register-resident level formation, which this encoder's mostly-small transforms live on. Noted at the call site.
perf(av1): the encoder's forward DCT is the decoder's network, transposedAhmet Kaan Gümüş · eb8e099
perf(av1): the encoder's forward DCT is the decoder's network, transposed The forward transform was an f64 FFT (Complex math, per-row/column) and had become the encoder's single largest cost -- `transform::dct1d` 23.6% of the profile. It is replaced by the transpose of the decoder's own fixed-point butterfly network: a network's transpose is that network run backwards with each elementary matrix transposed, and all of this one's elements are symmetric except the unflipped rotation, whose transpose is the same rotation at the negated angle. So the forward body IS the inverse's stages reversed, its unflipped angles negated, its bit-reversal moved to the end -- generated from the inverse's source, then measured. Only the quantized levels reach the decoder, so a forward transform owes a good analysis basis, not a specified one; the gain the levels are formed on is measured from the network (`forward_gain`, sqrt(n/2) per pass) rather than asserted, and the residual carries six headroom bits so the network's own rounding stays well under one unit of the 8x orthonormal scale a level is formed on. -13.1% instructions:u on the sequence bench (209.0 G -> 181.6 G).
Merge branch 'lane-av1speed' (715aa56a): encoder motion search reads the reference picture's u16 plane (was converting the whole plane per searched block), fft twiddles cached, trial scratch on the stack, NEWMV equal to NEARESTMV reuses its trials, integer SAD and a symbol price table; -45.6% encoder instructions with byte-identical output; key-frame top-K pruning and partition breakout measured as quality dead-ends and left inertAhmet Kaan Gümüş · 0e574b5Browse files
feat(av1): chroma searches its own uv_mode instead of coding DC unconditionallyAhmet Kaan Gümüş · b0a80f3
feat(av1): chroma searches its own uv_mode instead of coding DC unconditionally Both chroma planes were predicted DC_PRED at every block because that is all the tile writer coded. They now search the seven modes that read no further than the row directly above and the column directly to the left -- DC, V, H, SMOOTH, SMOOTH_V, SMOOTH_H, PAETH -- which is exactly the set a chroma block coded with `Reach::none()` may offer; the eight directional modes read past that and UV_CFL_PRED needs its own alpha syntax. A chroma block never codes a tx_type symbol: the decoder derives it from the chroma mode (`Intra_Mode_To_Tx_Type`, spec 9.3), so a non-DC uv_mode moves chroma onto an ADST-bearing transform. The forward half of that is new here and measured off the decoder's own inverse network -- a unit coefficient through `inverse_1d` IS the basis function it synthesises -- rather than written out, which is safe because only the levels and the derived type reach the decoder: the reconstruction the search scores still comes back through the exact inverse. BD-rate vs libaom 234.0/260.3/318.5 -> 216.4/235.5/289.2 and vs rav1e 171.9/203.2/155.3 -> 157.8/178.3/141.1 (1080p/2160p/screen), down on all three against both references. Wall 9.8s -> ~11.1s per clip ladder. The gate's own ffmpeg-decodes-sample-exact assertion holds, so the writer's uv_mode and angle_delta_uv syntax and the derived chroma transform agree with a real decoder. Fire counts printed per clip: DC wins 79.1/84.1/43.8%, PAETH 7.1/6.6/29.0%, H 3.3/2.5/16.6%.
perf(av1): cached FFT stage twiddles, stack scratch for a motion-compensated trialAhmet Kaan Gümüş · 56cc232
perf(av1): cached FFT stage twiddles, stack scratch for a motion-compensated trial Two allocation/libm costs on the encoder's hottest paths, neither of which changes a single output byte: - `fft`'s stage twiddle depends only on the stage length, so its two `sincos` calls per stage per call become one lazily-built table of the seven values that exist (`__sincos_fma` was 9% of the encoder profile). - `mc_trial` heap-allocated a `u16` prediction and a `u8` copy of it for every candidate trial; both are at most 32x32 and now live on the stack. instructions:u on the 24-frame 1280x720 sequence bench: 283.6G -> 263.5G (-7.1%); output bytes unchanged (64931), BD-rate unchanged on all three gate clips.
2026-09-05
perf(av1): answer 'this unit coded nothing' by pointer, not by scanning its gridAhmet Kaan Gümüş · 7002e78
perf(av1): answer 'this unit coded nothing' by pointer, not by scanning its grid The zero grid is now shared (previous commit), so is_zero_grid recognises it with one pointer compare. The dequantizer's all-zero test and the neighbour state's cul_level sum both walked the whole grid for the 60% of transform units that code no coefficient -- the sum has no early exit at all. -1.2% instructions:u at 1 thread, -0.7% at (16,4,2); byte-exact.
perf(av1): put the AVX2 feature on the Lane methods themselvesAhmet Kaan Gümüş · b848139
perf(av1): put the AVX2 feature on the Lane methods themselves The column pass measured -3.7% instructions when the network was `#[inline(always)]`d into the `target_feature` wrapper -- and then measured FLAT again after an unrelated refactor moved the size dispatch into its own `target_feature` function: the generic network stopped landing inside an AVX2 context, and with it every `_mm256_*` went back to being an out-of-line call (9.5% + 3.7% of the profile, 65 `vpmuldq` in the binary against 339 now). Relying on inlining to carry the feature is what was fragile. `Lane`'s two methods are `unsafe fn` now -- the only form rustc lets an impl carry `#[target_feature]` -- so the AVX2 impl compiles its intrinsics inline no matter how its callers are arranged. The scalar impls require nothing of their callers, and `M256` values still exist only inside the feature-detected `simd::column_pass_dct`. seg4k at one thread: 523.15 -> 502.36 G instructions:u (-3.97%), stable across runs. All 12 gate hashes unchanged.
test(av1): the AVX2 column pass against the scalar network over the full i32 rangeAhmet Kaan Gümüş · 1b7f343
test(av1): the AVX2 column pass against the scalar network over the full i32 range The intrinsics claim exact 64-bit products, so the gate sweeps `i32::MIN`/ `MAX`, both clamp boundaries at every `r` the decoder uses (16/18/20) and uniform full-range noise at every size, not only the dequantizer's own bound -- a single differing lane would be a silent pixel drift on whatever stream first reached it.
perf(av1): explicit AVX2 inverse-DCT column pass, and an empty all-zero residualAhmet Kaan Gümüş · ef53b7e
perf(av1): explicit AVX2 inverse-DCT column pass, and an empty all-zero residual The eight-wide column pass lane-tx introduced went through `[i32; 8]`, which LLVM never vectorised (the butterfly products are 64-bit). This adds an explicit AVX2 `Lane` impl -- `_mm256_mul_epi32` on the even/odd halves, so every product is exact in 64 bits and the pass is byte-exact with the scalar network on every input, not only on conformant ones -- dispatched off `mc::simd_level()`, with the scalar impl kept as the reference. `inverse_dct_n` is `#[inline(always)]` because the AVX2 instantiation has to land inside the `target_feature` wrapper: without it every `_mm256_*` stayed an out-of-line call and the "SIMD" pass measured 5.6% WORSE. Second, the 60% of transform units that carry no coefficient now return an EMPTY residual instead of `w * h` zeros: the reconstruction loops expand the marker against one static zero block, so the per-unit zero `Vec`, its `to_vec` clone into the recorded op, and (for a deferred unit) the coefficient-grid clone all disappear. seg4k at one thread: 523.1 -> 503.5 G instructions:u (-3.7%), min-of-5 cycles:u 142.1 -> 136.4 G. All 12 gate hashes unchanged.
perf(av1): monomorphise the inverse DCT per size, take the column pass eight columns at a time, skip all-zero transform unitsAhmet Kaan Gümüş · 484b7c3
perf(av1): monomorphise the inverse DCT per size, take the column pass eight columns at a time, skip all-zero transform units The inverse transform was ~10% of a 4K decode. Three measured steps, all byte-exact (12/12 gate hashes at 1/4/16 threads unchanged): - the spec's one generic butterfly network is now monomorphised on `N = log2(size)`, so every size guard, every `brev` fold and every butterfly angle is a compile-time constant instead of per-call work (-1.03%); - the column pass runs eight neighbouring columns through one network (a `Lane` trait with an `i32` and an `[i32; 8]` impl, so the network itself is still written once), turning the strided per-column gather into a contiguous load (-2.67%); - 60% of the transform units on the 4K perf segment carry no coefficient at all (3.46M of 5.7M, measured with a temporary histogram): a zero level grid dequantizes to zero and inverse-transforms to zero, so one scan replaces the dequantization and both passes (-1.55%). Together 559.05 -> 530.19 G instructions:u at one thread on the 4K segment, -5.16%. Two steps measured flat and are not here: compiling the eight-wide network a second time with AVX2 enabled (LLVM emits the same scalar code either way -- the i64 butterfly products do not vectorise, so an explicit vpmuldq kernel is the remaining lever), and an in-place bit-reversal permute.
2026-09-04
Merge branch 'lane-perf10' (6316b059): reference planes borrowed instead of copied nine times per inter frame (PlaneBuf data as Cow), DC-only column broadcast in the inverse transform, DCT network on fixed arrays; conflict with the banded deblock resolved by forcing the output plane owned once before banding; byte-exact at 1 and 4 filter threads on four inputsAhmet Kaan Gümüş · 1a45793Browse files
perf(av1): run the inverse DCT network on a fixed-size scratch arrayAhmet Kaan Gümüş · e428d82
perf(av1): run the inverse DCT network on a fixed-size scratch array Every butterfly, Hadamard and permutation of the spec's DCT network indexes the 64-entry scratch with a computed index, and on a `&mut [i32]` each one carried its own bounds check against a length the optimiser could not see. The network now runs on `&mut [i32; 64]`, which discharges them against the constant length; `inverse_dct` keeps its slice-taking signature as a wrapper for callers outside the 2D driver, and `inverse_1d` calls the fixed-size body directly. Byte-exact on seg1080/seg4k/seg4k_lr/palette_screen_witness. seg1080 189.06 G instructions (was 190.19 G, -0.59%); seg4k 599.04 G (was 602.71 G, -0.61%).
perf(av1): broadcast the column transform when the row pass leaves one constant rowAhmet Kaan Gümüş · 7086b91
perf(av1): broadcast the column transform when the row pass leaves one constant row The dominant inter residual is DC-only: the row pass then writes a single non-zero row that is constant along its length, and the column pass runs the same `inverse_1d` on the same input vector once per column, `w` times over. `inverse_transform_2d_typed_wh` now counts the non-zero rows the row pass produced and whether the first of them is constant. When there is at most one such row, one column transform is run and its output broadcast across each output row -- byte-identical to the `w` transforms it replaces (`inverse_1d` is a pure function of its input), and the per-column gather goes with them. Byte-exact on seg1080/seg4k/seg4k_lr/palette_screen_witness. seg1080 190.19 G instructions (was 193.75 G, -1.84%); seg4k 602.71 G (was 604.37 G, -0.28%).
chore(av1): clear the ec-av1 compiler warnings (300 -> 0 on the release lib)Ahmet Kaan Gümüş · 16efbd9
chore(av1): clear the ec-av1 compiler warnings (300 -> 0 on the release lib) No arithmetic, control flow or public signature changes; the four perf6 decode hashes are byte-identical. - gate-counter accessors and other test-only items carry `#[allow(dead_code)]` with the reason on the line (they are read from the `#[cfg(test)]` gates, which the plain lib build cannot see); - `///` blocks sitting on `thread_local!`/macro invocations become `//` (rustc never attached them to anything); - `cdf.rs` tables and the `InterpFilterKind` variants get a one-line doc; - unused locals/params prefixed `_` where the value is genuinely unused; dead initializers dropped where the compiler proves every read is preceded by an assignment; - `decode_key_frame_tile` import is now `#[cfg(test)]` (its only user). Left standing on purpose, as findings rather than hidden warnings: `stream.rs` census counters `other` and `rect_residual_refusals` are incremented and never read back by their gates.
perf(av1): dequantize into a reused buffer, with the loop invariants hoistedAhmet Kaan Gümüş · 32f9ae5
perf(av1): dequantize into a reused buffer, with the loop invariants hoisted `dequant_wh` was a `map`/`collect` building a fresh `Vec<i32>` per transform unit (7.8% self time, the third-hottest symbol in the decode profile), and inside it every coefficient repeated the whole per-coefficient spec function: two quantizer-table lookups with their own clamps, the area denominator's match, and the bound shift -- all of which depend on the transform, not on the coefficient. `dequant_wh_into` hoists them and writes a caller-owned buffer, which the one hot caller (`dequant_and_inverse_typed_wh`) keeps thread-local. A zero level dequantizes to zero for every parameter set, so the all-but-EOB tail of a grid now costs a compare rather than a 64-bit multiply and divide. The arithmetic on a non-zero level is untouched; `dequant_wh` keeps its `Vec` signature for the other callers. `buffered_dequant_matches_the_per_coefficient_form` checks the buffered form against `dequant_coeff_wh` over six transform shapes, three bit depths, three quantizer/delta sets and both level signs. Byte-exact: `EC_PROBE_OUT16` dumps cmp IDENTICAL against the lane's baseline binary on 1080p 10-bit, 2160p HDR and the 8-bit palette fixture. Interleaved medians against the previous commit: 1080p 13.46 s -> 12.15 s, 4K 67.11 s -> 63.38 s.
perf(av1): inverse transform without per-call allocation or runtime bit-reversalAhmet Kaan Gümüş · ee4e975
perf(av1): inverse transform without per-call allocation or runtime bit-reversal `perf annotate` of `inverse_dct` (12.3% self time) opened every call with a `malloc`/`memcpy` pair -- `permute`'s `Vec` -- and then spent its hottest single instruction in the inlined `brev` bit-fold, recomputed per butterfly index. `cos128` was a four-way branch per butterfly, and the 2D driver (7.6% self) allocated two more `Vec`s per transform unit while looking up `row_shift_wh` through a match once per output sample. All four are now compile-time or loop-invariant: `brev` and the whole-circle cosine are const tables, `permute` copies into a stack array, the row pass writes a thread-local scratch it fully overwrites, and the shift is hoisted. The row and column passes also skip an all-zero vector, which is exact rather than approximate -- every butterfly and Hadamard of zeros is zero and `Round2(0, n)` is zero at every `n` -- and is what makes rows 32..64 of a 64-point transform, and the tail of any EOB-limited block, free. `a_zero_vector_transforms_to_zero` pins that property per 1D transform and end to end. Byte-exact: `EC_PROBE_OUT16` dumps cmp IDENTICAL against the pre-change binary on a 299-frame 1080p 10-bit segment, a 4 s 2160p HDR segment and the 8-bit palette fixture. Interleaved medians: 1080p 16.72 s -> 13.74 s (17.9 -> 21.8 fps), 4K 78.74 s -> 70.05 s.
2026-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.