forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on mainFiltered to crates/ec-av1/src/restoration.rsClear filter

2026-11-23

2026-10-23

Restore edith_codecs after local data loss (2026-10-23)Ahmet Kaan Gümüş · b7434a2
Restore edith_codecs after local data loss (2026-10-23)

On 2026-10-23 an automated agent ran `rm -rf $HOME` and deleted the local
repository with all of its history. This commit restores the working tree
from the newest surviving copy, the host-c server lane mirror. That mirror
matches local main as of the testcut Phase 2 reports, including the tool
cache, the nextest fast profile and changed-crates.sh. The history before
this commit was not recovered.

2026-09-28

lane-av1422warp r33: reviewer rework -- OBMC snap, hot-path env, two docs, one wrong numberAhmet Kaan Gümüş · 4e1fb23
lane-av1422warp r33: reviewer rework -- OBMC snap, hot-path env, two docs, one wrong number

Reviewer FAIL addressed, all five findings.

P2 (a4532a41) OBMC PAIR-MERGE SNAP. The snap was clamped on the wrong
value. libaom (obmc.h:44-46) snaps the pair index `& ~1` UNCONDITIONALLY
and reads at `snap + 1`; only the REPORTED offset
(`above_mi_col - mi_col`) is negative, and it feeds
`av1_setup_build_prediction_by_above_pred` while the READ feeds
`above_filter.get(mi_col + src4)` and the MiInfo itself. Clamping the
snapped index to `mi_col`/`mi_row` silenced the underflow and in exchange
read the neighbour one column RIGHT of libaom's, then stepped past
`mi_col + 1` entirely. Both sites now keep the snap and clamp only the
offset. The tuple is `usize`, so libaom's -1 is carried as 0; that is
noted in the code rather than glossed.

New gate the_obmc_pair_merge_snap_reads_libaoms_neighbour_not_one_to_the_
right pins the snapped READ against a synthetic grid with distinguishable
neighbours at the pair's even half, odd half, and the column to the right.
Mutation-proven both ways. It is necessary because NO STREAM IN THE CORPUS
exercises this branch: a1.obu's 1338 traced OBMC neighbours are identical
before and after the fix, since its 4-wide pair never starts on an odd
edge.

P2 HOT-PATH ENV LOOKUP. `SymbolDecoder::symbol` called
`std::env::var_os("EC_SYMR")` on every symbol read of every stream,
production formats included. Now `envflags::env_flag!("EC_SYMR")`, one
LazyLock per call site (the ecdump_armed precedent at msac.rs:1059).
Proved byte-identical: same build, both forms, identical 246735-line
EC_SYMR traces.

P3 MI_SIZE DOC. The doc claimed "MI_SIZE (aom_scale.h)" and 8. libaom's
MI_SIZE is 4 (av1/common/enums.h:39-40) and lives in enums.h. Renamed
MI_SIZE_8PX; both its doc and read_lr's are restated in 8-pixel terms,
with why the value is double libaom's (its denom is a pixel count, so
numerator and denominator already sit on opposite scales) and the paired
trace named as the authority. The rename is so nobody corrects it to 4.

P3 TOP-HALF CENSUS WAS AN UPPER BOUND, AND 248 WAS WRONG.
top_half_warp_hits incremented on "either slot's model > TRANSLATION"
alone, omitting `is_globalmv && side >= 8`, so it counted blocks that are
not global-mv blocks. It now increments on `is_global_mv0 || is_global_mv1`
-- libaom's own `is_global_mv_block` -- with the census moved below their
definition. CORRECTED UPPER-HALF FIGURE: 3 warp, 3 compound. Not 248.
Frame-global figures unchanged (compound_warp 25, compound_warp_8 18,
rotzoom_gm_warp 84, lr_wiener 22, lr_sgrproj 10). The gate doc and the
lift section are corrected; 248 was never a count of anything real.

P3 ACCESSOR DOCS. Both claimed a committed reader that does not exist and
cannot: with the header refusal standing no committed test decodes a 4:2:2
stream. Both now say so.

NO CHANGE to the 4:2:2 refusal, which stays unconditional. NO committed
bypass. Stream still 246735/246735 paired and 16/16 pixel-exact.
lane-av1422warp: fix the 4:2:2 loop-restoration corner bug; pin the coverage witnessAhmet Kaan Gümüş · 7373100
lane-av1422warp: fix the 4:2:2 loop-restoration corner bug; pin the coverage witness

The 4:2:2 sequence header refusal is UNCHANGED and unconditional. This
commits the fix that makes a second 4:2:2 coverage witness decode
pixel-exact through the env-gated probe bypass, and pins that witness.

THE DEFECT. Two errors in the per-superblock restoration-unit range that
had been cancelling each other:

1. `read_lr` derived the ROW corners from the COLUMN axis. libaom's
   `av1_loop_restoration_corners_in_sb` (restoration.c:1303-1338) steps
   rows by `MI_SIZE >> subsampling_y` and columns by `MI_SIZE >>
   subsampling_x` -- the axes are not symmetric. This decoder had one
   `mi_size = 4 >> subsampling_x` for both, on a base of 4 where
   libaom's `MI_SIZE` is 8. At 4:2:2 (ss_x 1, ss_y 0) that made the row
   range 4x too small, so `rrow0 == rrow1` -- an empty range, zero
   `read_lr_unit` calls -- wherever libaom reads a chroma unit.

2. The 128x128 superblock's mode-info extent was passed as `SB_MI * 2`,
   and the two 64px call sites carried the same half-mi convention. Both
   are 2x too large.

The two cancelled exactly at 4:2:0 (4*32 == 8*16), which is why 4:2:0 and
4:4:4 decoded byte-exact while carrying the bug and why the 4:2:0 evidence
was never evidence of correctness here. At 4:2:2 the cancellation breaks,
because the row term stops following the column axis.

A third, smaller correction: the `read_lr` call is the ONE consumer that
turns a superblock's mode-info origin into ABSOLUTE frame space (it
divides by the restoration-unit size, a real pixel count), and it was
handed `(sb_r & !1) * SB_MI` -- twice the true mi row, since `sb_r`
indexes 64px superblocks. The partition decode is self-consistent with
that value (relative offsets only), which is why the 128 path decoded
correctly everywhere else; the origin is corrected only where it is
converted to absolute frame space.

EVIDENCE. The entropy stream pairs bit-for-bit against the instrumented
oracle -- 246735 symbol reads on each side, no divergence anywhere in the
stream, not merely at the window this lane spent nine rounds narrowing.
All 16 frames pixel-exact vs `aomdec --rawvideo` (2359296 bytes, sha256
4bfc2395e5ca6ea178f606e6b1ced773e26fc2d85bc3a6cdb63a402939aeb203 both
sides). 4:2:0 control byte-exact, 4:4:4 LR witness byte-identical to its
pre-lane decode, both previously pinned 4:2:2 witnesses pixel-exact. LR
gate family 12/12. Scoped battery over 420/444/inter/superres/cdef 118
passed, 0 failed, 7 ignored.

The wide gate is pin + refuse-by-name, the established 4:2:2 pattern: with
the header refusal standing, no committed test can decode a 4:2:2 stream,
because the bypass that would allow it must never be committed. The
exactness and engagement figures live in the gate's doc comment with the
encode recipe. Mutation-proven both ways -- a flipped fixture byte panics
"bytes drifted", a wrong refusal string panics "must refuse by name".

ENGAGEMENT, measured above the vertical midpoint on the exact stream.
Every pre-existing warp counter is frame-global, so this adds
`top_half_warp_hits` and `top_half_compound_hits`: 248 upper-half blocks
on a non-TRANSLATION global-motion model, 3 upper-half GLOBAL_GLOBALMV
compound blocks. Frame-globally: compound_warp 25, compound_warp_8 18,
rotzoom_gm_warp 84, lr_wiener 22, lr_sgrproj 10, cdef_idx 53,
part128_split 95.

Fixture: crates/ec-av1/fixtures/422_residual_compound_warp_16f.obu,
38845 bytes, sha256
d78e2afb43ce311d3d82335a945c6f80f62db4537966d881c1349a68b3aecb95, fnv1a64
0x0e73a51e2cc0c424.

2026-09-24

Merge 7f2c85c5 (lane-av1-444 10-bit film fix) into main: keep 12-bit compound MC and 4:4:4 chroma portAhmet Kaan Gümüş · c5a3cd1
Merge 7f2c85c5 (lane-av1-444 10-bit film fix) into main: keep 12-bit compound MC and 4:4:4 chroma port

- decode.rs: unify on the lane's ss-aware mv_to_q4(pos, mv, ss) signature;
  main's luma=false call sites become ss_x(fctx)/ss_y(fctx) (identical math
  for 4:2:0), luma=true becomes 0. Intrabc chroma arm keeps main's structure
  with ss-aware MVs. Compound intermediate calls pass fctx and use the lane's
  chroma_side sizing (444-native, degenerates to 420 behavior).
- encode.rs, refusal_inventory.rs, restoration.rs, stream.rs, tile.rs:
  auto-merged clean by git, both sides retained.
- Verified: a_10bit_128sb_film_frames_with_warp_cdef_and_interintra_decode_pixel_exact
  and a_10bit_film_frames_with_small_side_globalmv_and_rect_warp_reach_decode_pixel_exact
  both PASS (not skipped) on this merge.
lane-av112bit: lift the 12-bit gate to the witnessed setAhmet Kaan Gümüş · 0531387
lane-av112bit: lift the 12-bit gate to the witnessed set

The blanket bit-depth-12 refusal (hdr report section 4.2) becomes four
named refusals, each pinned by a real aomenc --bit-depth=12 stream:
warp, compound inter blocks, film grain, and screen content tools
(palette/intrabc). Everything else 12-bit is lifted behind two
byte-exact-vs-ffmpeg witnesses: a key frame and a key+inter sequence
with sub-pixel motion, CDEF and loop restoration ON (cdef_idx and
Wiener/SGR unit counters hard-asserted; a new MC_SUBPEL_HITS counter
proves the frame's own round_0/round_1 ran).

The rounding rule is libaom convolve.h:81..86 verbatim: round_0 +=
bd - 10, non-compound round_1 -= bd - 10 (mc.rs round_pair, threaded
through scalar and SIMD passes, the identity fast paths, the scaled
walk, and the compound combines' post-rounds; the Wiener pair likewise).
Wiener's intermediate clamp keeps the corpus-proven constant structure
- the exact per-sample C transform moved the 10-bit 128-sb film gate
and is recorded as the lane's open half in lanes/av112bit.report.md.

8/10-bit regression: the three 10-bit film fixture gates, the 10-bit
key/inter/grain gates and 8-bit spot arms all green; refusal_inventory
and gate_coverage updated and green. Fixtures av112bit-{key,inter}.obu
committed with sha256 provenance in the report.

2026-09-23

ec-av1: 4:4:4 luma byte-exact, chroma WIP (lane-av1-444)Ahmet Kaan Gümüş · d6b7cc7
ec-av1: 4:4:4 luma byte-exact, chroma WIP (lane-av1-444)

Sequence header refuses only 4:2:2 now (ss_x != ss_y); 4:4:4 and 4:2:0
proceed. Chroma plane size, tx size, CFL window, loop-filter chroma step
and the 8x8 leaf's chroma unit follow ss_x/ss_y; an 8x8 leaf at 4:4:4
reads 8x8 chroma. Restoration chroma unit size follows ss_x.

Square profile-1 recipe: luma IDENTICAL vs aomdec+ffmpeg both frames
(0/16384 diffs); chroma 37389/98304 diffs, first at U (112,0) inside the
64x64 block at (64,0) which takes the single-TU arm but codes four
TX_32X32 chroma units at 4:4:4 (av1_get_max_uv_txsize). 420 square arm
still IDENTICAL. 4:2:2 stays a named refusal. Full suite not run.

2026-09-06

2026-09-05

perf(av1): loop restoration joins the per-superblock-row filter pipelineAhmet Kaan Gümüş · 013daf3
perf(av1): loop restoration joins the per-superblock-row filter pipeline

Restoration-unit row r writes out rows v_start..v_end, reads post-CDEF
rows only inside that span and the post-deblock snapshot at most two rows
past v_end, so it is ready as soon as CDEF band (v_end-1)/64 is done --
the same pipeline iteration, right after that band's CDEF. The snapshot
condition ((v_end+1)/64 <= k-2) is implied, the two row indices being at
most one band apart.

apply_loop_restoration_plane grows an RU-row range; the whole-frame form
is unchanged and stays for the fallback path (superres, key frames,
EC_AV1_PIPE_FILTERS=0). Byte-exact on the 16 gate hashes.
perf(av1): the compound vertical pass runs the whole block per callAhmet Kaan Gümüş · f2203de
perf(av1): the compound vertical pass runs the whole block per call

vpass_row takes the block's row count too, and the compound kernel
accumulates straight into its i32 destination and rounds it in one
sweep, dropping the per-row accumulator round trip along with the
per-row tap setup. Byte-exact: all four gate streams hash to their
references.
perf(av1): MC hoists the interior row test and fuses whole-pel-horizontal blocks onto the referenceAhmet Kaan Gümüş · 37ae497
perf(av1): MC hoists the interior row test and fuses whole-pel-horizontal blocks onto the reference

The unscaled horizontal pass tested the vertical clamp, the interior
window, the slice bounds, the tap narrowing and the SIMD level once per
row; when the whole footprint is inside the reference -- the common case
-- every one of those has the same answer for all rows, so the test is
hoisted and the loop is a walk of the stride.

A whole-pel horizontal position makes the horizontal pass the identity
tap, whose intermediate is exactly `s << 4`, so the vertical pass is the
same 8-tap sum taken straight off the reference rows with the taps
scaled by 16. Both the single and the compound kernel now take that
path for interior blocks, which drops the intermediate entirely; the
vertical kernels gained a source-stride parameter to read it.

Byte-exact: all four gate streams hash to their references.
perf(av1): 16-bit motion-compensation intermediate, vertical pass on maddAhmet Kaan Gümüş · ad664df
perf(av1): 16-bit motion-compensation intermediate, vertical pass on madd

The separable inter filter kept its horizontal output in `i32`, so the
vertical pass spent one `mullo_epi32` per tap per 8 columns and moved
twice the bytes it had to. The intermediate provably fits `i16` at the
bit depths this decoder accepts -- a phase's positive taps sum to at
most 156, so `Round2(1023 * 156, 3)` is 19948, and 12-bit (where
`InterRound0` itself changes) is refused in stream.rs. With the buffer
narrowed, a row PAIR interleaved by `unpack_epi16` is exactly
`madd_epi16`'s shape: two taps of 16 columns per instruction.

The horizontal kernels store through `packs_epi32`, whose saturation is
unreachable on a motion-compensation path (the new
`horizontal_intermediate_fits_i16` enumerates every filter kind, table
and phase to prove it) and composes with the wiener clamp on the
restoration path, whose bounds are inside `i16` at 8- and 10-bit.

-3.7% instructions on the 4K segment (553.2 -> 532.7 G at one thread);
all four gate hashes unchanged.
perf(av1): sgrproj box sums in i32 over a contiguous row, (A,B) map under AVX2Ahmet Kaan Gümüş · 9c6f09f
perf(av1): sgrproj box sums in i32 over a contiguous row, (A,B) map under AVX2

`compute_ab` fetched every window sample through `lr_sample` -- a
stripe-boundary decision plus a column clamp per element -- and carried
both box sums as `i64`. A sample is at most `2^bd - 1 <= 4095`, so the
widest window sum of squares is `25 * 4095^2 == 419M`: the sums fit `i32`
with room to spare, and the column clamp is a pure function of the
column, so one contiguous per-row copy with the plane edge replicated
serves the whole accumulate pass branch-free.

On top of that the per-grid-point `(A[k], B[k])` map -- the part a
previous lane measured as the real cost -- becomes a straight-line pass
over two row arrays, so it runs eight points at a time under AVX2:
lane-wise the same arithmetic, with the only two products that exceed 32
bits (`p * s` and `(256 - A) * one_by_x * b`) formed in 64-bit even/odd
halves and packed back after their rounding shift, and `av1_x_by_xplus1`
read by gather. `ab_point` stays the scalar reference for the tail and
for every non-AVX2 target.

Byte-exact: all four gate streams hash identically to the parent at 1 and
4 threads. instructions:u on the 4K restoration segment 602.650 G ->
597.501 G (-0.86%; -0.29% from the sums, -0.57% from the AVX2 map).

2026-09-04

perf(av1): parallelise the in-frame filter chain (deblock, CDEF, LR, film grain)Ahmet Kaan Gümüş · 63e598c
perf(av1): parallelise the in-frame filter chain (deblock, CDEF, LR, film grain)

`EC_AV1_FILTER_THREADS` (default 1, so the shipped behaviour is unchanged)
splits every post-decode filter stage across `std:🧵:scope` workers,
each along an axis whose writes are disjoint:

* deblock: 16-row bands for the vertical-edge pass (a vertical edge writes
  columns x0-7..x0+5 of its OWN 4 rows) and 16-column bands for the
  horizontal one (rows y0-7..y0+6 of its own 4 columns); the horizontal pass
  still runs after the whole vertical pass of that plane, spec 7.14 order.
* CDEF: mi ROW bands. Every unit reads only the pre-CDEF snapshots and
  writes its own 8x8 luma / 4x4 chroma square.
* loop restoration: restoration-unit row bands. The RU row walk is resolved
  into a row list first (a short remainder is swallowed by the previous
  row), and row `r`'s write range starts where row `r-1`'s ended.
* film grain: 32-pixel block rows. A row's noise comes from
  `Rng::line(y * 2, seed)` alone, and the one carry across rows -- the
  line buffers -- is rebuilt by replaying exactly ONE preceding row with
  its pixel writes suppressed.

`FrameCtx` stays `!Sync`; a worker gets `filter_ctx_copy`'s copy of the
fields the filter chain reads (bit depth, segmentation, superres, grain bit
depth). The aliasing that the band arithmetic proves and the borrow checker
cannot is confined to `par::Shared` (one `#[allow(unsafe_code)]` module).

Gated byte-exact: the new
`a_real_stream_filters_identically_with_one_and_four_filter_threads`
compares every output plane of a 10-bit CDEF+LR stream and of a film-grain
stream at 1 vs 4 filter threads, with per-stage firing counters asserted;
the four perf6 stream hashes are equal at 1 and at 4 filter threads.

seg4k 272 frames: 34.99 s -> 31.33 s (7.77 -> 8.68 fps), seg4k_lr 32.13 s ->
27.31 s at 4 filter threads (interleaved medians of 3, 12-core box under
load 6.5). Single-threaded cost: +1.6% instructions (607.34 G -> 617.18 G on
seg4k), mostly CDEF losing alias facts through the raw-pointer-derived
`&mut`.
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.
refactor(av1): the 38 per-frame decode-state thread_locals become one FrameCtxAhmet Kaan Gümüş · b9a9498
refactor(av1): the 38 per-frame decode-state thread_locals become one FrameCtx

Every per-frame/per-stream decode state in ec-av1 lived in a thread_local!
static, so a decode was a function of the calling THREAD's history rather
than of the bitstream, and a worker thread saw empty state -- the blocker
for frame-parallel decoding.

All 38 (SB128, BIT_DEPTH, SUPERRES, CDEF_*, DELTA_Q_*/DELTA_LF_*,
CURRENT_Q_IDX, QUANT_DELTAS, the 9 SEG* maps, TX_SELECT_INTER,
REDUCED_TX_SET_INTER, ENABLE_FILTER_INTRA_INTER, PALETTE_PRED, INTRABC_*,
LUMA_TX_TYPE, INTRA_IN_INTER_MODE, INTER_STRIP_CHROMA, INTER_LAST_MC,
ENABLE_EDGE_FILTER, LAST_FRAME_WIDE_MARGIN, REACH_SB_PX, GRAIN_BIT_DEPTH)
are now fields of decode::FrameCtx, owned by decode_stream_with and threaded
as `fctx: &FrameCtx` down the decode call graph (~1200 call sites).

The fields keep the Cell/RefCell interior mutability the statics had, so
every read/write site is byte-identical and this is a pure ownership move;
Cell/RefCell also make FrameCtx !Sync on purpose -- one context per decoding
thread, never shared. The scratch pools, gate hit counters and trace
switches stay thread_local by design.
perf(av1): sgrproj box sums slide down the grid as well as across itAhmet Kaan Gümüş · c80d9e9
perf(av1): sgrproj box sums slide down the grid as well as across it

`compute_ab` (3.6% self time at 4K, the remaining loop-restoration cost now
that Wiener runs on the MC kernels) recomputed each grid row's column sums
from scratch, so every source sample was read -- through `lr_sample`'s
stripe-boundary test, the expensive part -- (2r+1) times. Consecutive grid
rows share all but two source rows: subtract the row leaving the window, add
the one entering it. The horizontal sum slides the same way, one add and one
subtract per grid point instead of 2r+1 adds.

Exact, not approximate: i64 addition is associative and subtracting a row
that was added back is exact, and `lr_sample` is a pure function of its
(row, col).

Charter asked for an AVX2 kernel over the per-pixel A/B arithmetic; the
sliding window removes strictly more work in a quarter of the lines, so it
took that rung first. seg4k_lr 35.49 s -> 35.02 s, seg4k 36.45 s -> 36.27 s
(medians of 3 interleaved pairs each); byte-exact on all four inputs.
perf(av1): Wiener restoration runs on the motion-compensation kernelsAhmet Kaan Gümüş · 91d30fe
perf(av1): Wiener restoration runs on the motion-compensation kernels

`apply_loop_restoration_plane` was 6.3% of a 4K decode's self time, and
Wiener owns most of it: on the two 4K probe inputs Wiener units cover
82% and 95% of all restored pixels (instrumented, then reverted).

Its two passes ARE `mc.rs`'s: a 7-tap `i16` convolution over contiguous
samples rounded by `Round2(_, 3) == INTER_ROUND_0`, then a 7-tap `i32`
one rounded by `Round2(_, 11) == INTER_ROUND_1`. Zeroing an eighth tap
makes both `mc::hpass_contig`/`mc::vpass_row` calls exactly -- so this
reuses those AVX2/SSE kernels rather than growing a third copy of the
same convolution.

That also removes the horizontal pass's real cost: it called
`lr_sample` (stripe-boundary substitution plus a column clamp) once per
tap, seven times per output. Which buffer and row a sample comes from
depends only on the row, so `lr_sample` is now that resolution
(`lr_src_row`) plus its clamp, and the pass resolves it once per row and
convolves straight over the plane -- only a unit touching the plane's
left or right edge still copies through the clamp.

4K decode 40.6 s -> 35.7 s and the LR-heavy 4K input 40.1 s -> 34.1 s
(interleaved medians of 3 against this lane's base), byte-exact on all
four probe inputs.
perf(av1): loop restoration stops re-reading its clamp and re-allocatingAhmet Kaan Gümüş · a88f7f4
perf(av1): loop restoration stops re-reading its clamp and re-allocating

`apply_loop_restoration_plane` is 5.95% of a 4K decode's self time after
the CDEF kernel landed, and two of its costs are pure overhead:

* both stripe kernels read `decode::sample_max()` -- a thread-local plus
  a shift -- once per OUTPUT SAMPLE, to clamp with. The bound is the
  frame's, so it is now resolved once per stripe.
* `apply_wiener_stripe`'s horizontal-pass intermediate and `compute_ab`'s
  two (A, B) grids were freshly allocated per stripe (~70 KB each for a
  64-wide sgrproj unit, two per stripe), so every page also faulted in on
  first touch. Both are reused thread-local scratch buffers now, the way
  lane-perf6 already did for the whole-plane buffers. Every entry of each
  is written before it is read, so the resize fill value never shows.

No arithmetic changed. Byte-exact on all four gate inputs (seg1080,
seg4k, seg4k_lr, palette). Interleaved medians 3x: seg4k_lr 40.47 s ->
39.59 s (-2.2%), seg4k 41.53 -> 41.22 s, 1080p 11.08 -> 10.83 s.
perf(av1): separable box sums in the sgrproj a/b passAhmet Kaan Gümüş · ac194aa
perf(av1): separable box sums in the sgrproj a/b pass

`compute_ab` summed every grid point's own (2r+1)x(2r+1) window from
scratch, so each source sample went through `lr_sample` -- whose
stripe-boundary substitution is the expensive part -- (2r+1) times more
often than necessary. One column-sum pass per grid row reads each sample
once and the point's box is then (2r+1) adds of those i64 column sums;
integer addition is exact and associative, so every total is unchanged.
The per-point bit-depth read is hoisted out with it.

Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 59.37 s -> 46.15 s
(1.286x, from 1.252x at the previous step), LR-heavy 4K cut 57.21 s ->
50.47 s (1.134x).
perf(av1): pool the post-filter plane buffers instead of allocating per frameAhmet Kaan Gümüş · 583ed90
perf(av1): pool the post-filter plane buffers instead of allocating per frame

Each frame allocated a pre-CDEF snapshot of all three planes, a
post-deblock snapshot of all three when loop restoration is active, and
one fresh `cdef.to_vec()` destination per restored plane: ~25 MB of
multi-megabyte `Vec`s per frame at 4K, every one of them served by a
fresh `mmap` whose pages then fault in on first touch, and returned to
the allocator at the end of the frame. `PLANE_SCRATCH` hands the same
buffers back out; `apply_loop_restoration_plane` now fills a caller-owned
`out` buffer (refilled from `cdef` on entry, same "never filter in place"
contract) which the caller swaps into the plane and returns to the pool.

Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 60.48 s -> 49.55 s
(1.221x, from 1.156x at the previous step), LR-heavy 4K cut 59.95 s ->
54.16 s, 1080p 11.14 s. Peak RSS 417 MB -> 466 MB, the retained pool.
perf(av1): snapshot the remaining per-pixel EC_* env readsAhmet Kaan Gümüş · 2baca5a
perf(av1): snapshot the remaining per-pixel EC_* env reads

`restoration.rs`'s three `EC_LR_CALL_DUMP` guards sit inside the sgrproj
per-pixel loops (`compute_ab`, the combine tap) and `warp.rs`'s
`EC_MC_TRACE` on the per-MC-call warp entry; each was a live `getenv` +
`strlen` + `CStr` validation, 17.75% of `decode_probe`'s self time at 4K.
Same predicates, served by `envflags::env_flag!` (one `LazyLock<bool>`
per call site). `motion_field.rs`'s two `EC_TRACE_TPL` reads move with
them. `tile.rs`'s two sites stay: :34 already caches into an atomic and
:3002 is test-only.

Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 55.31 s -> 48.53 s
(interleaved medians of 3), 1080p 10.54 s -> 9.83 s.
fix(av1): superres upscales between CDEF and loop restoration, not after LRAhmet Kaan Gümüş · 08a2542
fix(av1): superres upscales between CDEF and loop restoration, not after LR

Spec 7.16 (libaom `superres_post_decode`, called in `decodeframe.c` between
`av1_cdef_frame` and `av1_loop_restoration_filter_frame`): the horizontal
upscale runs after CDEF and BEFORE loop restoration. This decoder ran the
whole filter chain on the downscaled frame and upscaled last, in `stream.rs`,
so under superres loop restoration filtered downscaled pixels through a unit
grid sized from the downscaled width.

Three widths were wrong, all in the same class (`wrong-stage-width`: each
plane width in the filter chain is either the downscaled one -- deblock, CDEF
and the mi grid -- or the upscaled one -- everything loop restoration does):

* `RestorationGrid::new` sized its unit counts from `frame_width`; libaom
  sizes them with `av1_get_upsampled_plane_size` (upscaled width).
* `read_lr`'s unit corners divided downscaled mi columns by the unit size;
  `av1_loop_restoration_corners_in_sb` scales by `superres_denom /
  SCALE_NUMERATOR` (`mi_to_num_x`/`denom_x`) when the frame is scaled.
* The pixel filters ran on downscaled planes. Both the post-CDEF frame and
  the post-deblock frame LR substitutes at stripe boundaries are now upscaled
  first (libaom's `save_deblock_boundary_lines` runs
  `av1_upscale_normative_rows` over its saved rows when the frame is scaled).

`decode::set_superres` carries the state per frame, like `set_bit_depth`, and
the reconstruction buffer's own real columns past `frame_width` stay the
upscale's right margin -- the `take_last_frame_wide_margin` hand-off to
`stream.rs` is gone with the late upscale it fed.

Gate: `fixtures/superres_kf_cdef_lr_64x64.obu`, a real aomenc key frame with
CDEF and loop restoration under `--superres-denominator=12`, was 1873 wrong
samples (max 7) and is now byte-exact against ffmpeg.

Residual, pinned ignored: `fixtures/superres_alltools_sb128_320x180.obu` (10
frames, all tools, sb128, cpu-used=4) went from 37315 wrong samples/max 171
to 1620/max 11 -- what is left is CHROMA ONLY (luma exact in all 10 frames)
and survives `--enable-cdef=0 --enable-restoration=0`, so it is a
scaled-reference chroma prediction defect, not filtering.

2026-09-02

test(av1): gate loop restoration's frame-edge stripe shapes -- stripe 0 and the partial bottom stripeAhmet Kaan Gümüş · 8c352b6
test(av1): gate loop restoration's frame-edge stripe shapes -- stripe 0 and the partial bottom stripe

The chartered defect (a 1920x792 10-bit AV1 key frame wrong in rows 0..7) does
not reproduce at this base: 11/11 decodable key frames of that stream decode
0-sample-exact against ffmpeg, so no fix was needed. What was missing was the
gate: every LR gate size so far was a whole multiple of 64 rows at --sb-size=64,
so the 56-row first stripe (RESTORATION_UNIT_OFFSET==8) and the truncated last
stripe -- the only two stripes whose boundary rows come from the frame's own
top/bottom row instead of the deblocked plane -- were never asserted to have run.

- restoration.rs: LR_STRIPE0_HITS / LR_LAST_STRIPE_HITS counters, bumped in
  filter_restoration_unit for a non-None filter on a stripe starting at plane
  row 0, resp. a truncated stripe ending at plane_h.
- stream.rs: new 10-bit gate, real aomenc --sb-size=128 --enable-restoration=1
  --cpu-used=0, 256x152 cq15 / 384x216 cq15 / 256x152 cq25, 16 seeds each, all
  frames vs ffmpeg, both counters hard-asserted per compared attempt: 48/48
  pixel-exact, stripe0 108, last-stripe 108.
- stream.rs: the 8-bit LR gate moves 192x128 -> 192x152 (128's stripe shapes are
  a subset) and asserts the same two counters: 40/40 pixel-exact.

2026-09-01

fix(av1): 10-bit loop restoration, diffwtd mask and warp all ran with 8-bit constantsAhmet Kaan Gümüş · 42752a0
fix(av1): 10-bit loop restoration, diffwtd mask and warp all ran with 8-bit constants

lane-hbdinter r1. The charter's premise (a 10-bit inter frame 2 mismatch)
did NOT reproduce with the tool-restricted inter recipe; widening the
recipe to real loop restoration did, and the defect turned out to be
bit-depth-wide, not inter-specific -- it fires on the KEY frame too, and
lane-hbd's 10-bit gate simply had `--enable-restoration=0`.

Four sites carried hardcoded 8-bit constants, all checked against the
oracle source (~/.cache/aom-oracle/src):

- restoration.rs `compute_ab`: libaom `restoration.c:660-662` scales the
  box sums back to the 8-bit range before forming `p`
  (`a = Round2(A, 2*(bd-8))`, `b = Round2(B, bd-8)`; `B[k]` keeps the raw
  sum). We never did -> wrong `z`, wrong blend factor at 10-bit. This is
  the site the gate attributes the mismatch to (ablation below).
- restoration.rs `apply_wiener_stripe`: the horizontal intermediate was
  clamped to a fixed `[0, 8191]`, i.e. `WIENER_CLAMP_LIMIT(3, bd=8) - 1`
  (`convolve.h:43`), in this crate's *unbiased* domain. Correct bounds are
  the libaom limit shifted down by its `1 << (bd + 3)` bias. At 8-bit
  neither end is reachable (which is why every 8-bit gate passed); at
  10-bit the top of the range is 16368, so most Wiener intermediates were
  truncated.
- mc.rs `diffwtd_mask`: libaom `reconinter.c:307` rounds the CONV_BUF
  difference by `INTER_POST_ROUND + (bd - 8)`; we used the constant 4.
- warp.rs `warp_affine`: `const BD: i32 = 8` fed both offset terms and the
  final `sum - (1<<(bd-1)) - (1<<bd)` (tip from lane-gmaffine, confirmed
  against `av1_warp_affine_c`).

Non-compound sub-pel MC needs no change: libaom only shifts round_0/round_1
when `bd + FILTER_BITS - round_0 + 2 > 16` (`convolve.h:83`), which is
12-bit only -- 10-bit keeps 3/11 and 3/7.

Gate: `a_real_aomenc_10bit_inter_sequence_decodes_pixel_exact` (stream.rs)
-- real aomenc yuv420p10le, 128x64, 16 frames, forward P frames, deblock +
loop restoration on, hard-asserting the new `mc::inter_pred_hits` counter,
`deblock_hits`, and a non-RESTORE_NONE LR filter, comparing all 16 frames
against ffmpeg's own 10-bit decode. Green with the fix; reverting only the
`compute_ab` scaling turns it red at frame 0 (V plane, sample 52: ours 289,
ffmpeg 288).

cargo test -p ec-av1 --lib: 268 passed, 0 failed, 23 ignored (664s).

2026-08-30

fix(av1): SGR_X_BY_XPLUS1 mistranscription (av1_x_by_xplus1[101] and [165..=169])Ahmet Kaan Gümüş · 09e8afa
fix(av1): SGR_X_BY_XPLUS1 mistranscription (av1_x_by_xplus1[101] and [165..=169])

Call-unique debug dump (gated on the pinned stream's own decoded xqd ==
[-16,-32], not a reused coordinate) traced r6's 3110-vs-3109 divergence to
the dense-arm "u" tap's A value: our compute_ab produced (254,303) for
z=101 where libaom's real table gives (253,454). The 9-byte input window
was already correct (r7); the bug was in the const table itself, off by
one at index 101 and short 5 entries in the 254 run at 165..=169.
Regenerated both SGR tables straight from
~/.cache/aom-oracle/src/av1/common/restoration.c to rule out any other
slip (SGR_ONE_BY_X already matched exactly). Pinned stream
fixtures/lr-sgr-r7.obu now decodes pixel-exact on all three planes.
feat(av1): lane-lr r3 step 1 -- real aomenc LR gate, proves read_lr firesAhmet Kaan Gümüş · 74cb98d
feat(av1): lane-lr r3 step 1 -- real aomenc LR gate, proves read_lr fires

Adds a_real_aomenc_stream_with_restoration_reads_lr_symbols_correctly
(stream.rs): --enable-restoration=1 --sb-size=64 aomenc stream over a
multi-superblock (192x128 = 3x2 SB) gradients fixture, cq-level=15 (r2's
sibling gates' usual cq=45 never landed uses_lr=true for this content --
sampled live). Self-pins WIENER_HITS/SGRPROJ_HITS/SWITCHABLE_HITS
thread-local counters in restoration.rs's read_lr_unit and hard-asserts
their sum > 0.

Building the gate found the real r2 gap: the stream.rs uses_lr refusal
ran BEFORE the tile-decode call, so decode_key_frame_tile_with_cdfs/
decode_inter_frame_tile_with_cdfs (and therefore read_lr) were NEVER
invoked through decode_stream -- 40/40 gate attempts hit the refusal with
zero read_lr_unit hits before this fix. Moved the check to run AFTER the
tile decode succeeds, so it now proves the superblock walk survives
read_lr (no desync) before refusing on the true remaining gap. Refusal
string text unchanged ("a frame with loop restoration enabled (the
per-unit lr symbols are read but the Wiener/self-guided filters are not
yet applied to pixels)"), only its position in decode_stream moved.

Verified: cargo test -p ec-av1 -- 236 passed / 0 failed, 17 ignored,
EC_AV1_REQUIRE_AOMENC=1. New gate alone: 39 LR refusals, 0 other
refusals out of 40 attempts, wiener_hits=19 sgrproj_hits=72
switchable_hits=0 (this fixture's RD never picked frame-level
Switchable, only fixed Wiener/Sgrproj -- both arms proven live).

Next (r3 step 2): apply_loop_restoration pass after apply_cdef, Wiener
first (stripe boundary save/restore trap per charter), then SGR, then
drop this refusal.
feat(av1): msac-flavoured LR subexp/recenter port + Wiener/SGR read_lr_unit primitives (unwired)Ahmet Kaan Gümüş · 4c75e5c
feat(av1): msac-flavoured LR subexp/recenter port + Wiener/SGR read_lr_unit primitives (unwired)

Ports decode_subexp/decode_unsigned_subexp_with_ref/decode_signed_subexp_with_ref
to the msac SymbolDecoder (k is a per-tap parameter here, not global motion's
fixed 3), plus read_wiener_filter/read_sgrproj_filter and the SGR params table,
all from libaom decodeframe.c/restoration.c. Pinned via roundtrip against a
hand-written encode-side mirror (SymbolEncoder has no LR writer of its own).
Not yet called from decode.rs -- stream.rs's whole-frame refusal is unchanged.