forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 552edc4cede0dfd9bebbc4e344242802802d15ccFiltered to crates/ec-av1/src/mc.rsClear filter

2026-09-04

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): AVX2 luma film-grain rowAhmet Kaan Gümüş · a620a4d
perf(av1): AVX2 luma film-grain row

`add_noise_to_block` was 7% of a 1080p decode's self time, and its luma arm
is the larger half: one scaling-LUT read, one multiply, a `Round2` and a
clip per sample. AVX2 does eight at a time -- the LUT read is a
`vpgatherdd`, the rest is the same i32 arithmetic -- and every other CPU
runs the scalar loop, which stays the reference. The gather index is
clamped to the LUT's last entry so the load cannot leave the table; the
scalar form indexes unclamped (it would panic), and the LUT spans the whole
sample range the grain bit depth allows, so the two agree wherever the
scalar one does not panic.

Pinned against the scalar row over 8/10/12-bit sample and LUT ranges, every
`grain_scaling_minus_8` shift, restricted and full clip ranges, and row
lengths covering the 8-lane body plus every tail. Interleaved medians,
1080p: 10.51 s -> 10.40 s (11.01 s at the lane's base). Byte-exact on all
three probe inputs.
perf(av1): explicit SIMD for both motion-compensation passesAhmet Kaan Gümüş · 66498f4
perf(av1): explicit SIMD for both motion-compensation passes

The two separable-filter inner loops were 18.7% of a 1080p decode's self
time after lane-perf4 (`vpass_row` 10.4%, `horizontal_pass_unscaled`
8.3%). Both are now hand-vectorised with `std::arch::x86_64` intrinsics
behind a level detected once per process (`OnceLock`): AVX2 where the CPU
has it, SSE4.1 otherwise, and the existing scalar loops everywhere else --
they stay the reference implementation, not a dead fallback.

The horizontal pass's `_mm*_madd_epi16` sums two taps of one output per
lane, so even and odd output columns accumulate separately and are
interleaved back into order (`unpack` + `permute2x128`); 16 outputs per
AVX2 iteration, 8 per SSE2 one, a 4-column tail scalar. The vertical pass
stays i32 (`mullo_epi32` + `add_epi32`), as 12-bit needs. Rounding is
unchanged in both: the same `Round2` add-then-arithmetic-shift.

This is why the crate is now `deny(unsafe_code)` rather than `forbid`:
intrinsics are unsafe by signature. The exception is confined to `mc`'s
`simd` module and its two dispatch sites, each with its own
`#[allow(unsafe_code)]` and documented in the crate header, and every
kernel is pinned lane-for-lane against the scalar function it replaces
over all widths, all 16 phases, both tables of all four filter kinds and
the 8/10/12-bit ranges.

Interleaved medians, 1080p: 11.07 s -> 10.51 s (horizontal pass alone was
11.37 -> 11.24; the vertical pass is where the win is). 4K 57.59 -> 57.12.
Byte-exact on all three probe inputs.
feat(av1): all three scaled-reference (superres) refusals lifted -- 8x8 leaf, sub-8x8, warpAhmet Kaan Gümüş · 421ae92
feat(av1): all three scaled-reference (superres) refusals lifted -- 8x8 leaf, sub-8x8, warp

The 8x8-leaf guard's own comment blamed a below-8x8 desync ("a 4th symbol
out of a 3-symbol alphabet"). That premise was stale: deleting the guard
decodes the pinned --superres-denominator=12 stream straight through to the
NEXT refusal. One wrong alphabet was behind all three.

Root cause (class wrong-alphabet-same-value / branch-dropped-as-unreachable):
decode_inter_block8 read the 3-symbol motion_mode row under a SCALED
reference, where libaom motion_mode_allowed makes WARPED_CAUSAL eligible
only if (num_proj_ref >= 1 && (allow_warped_motion && !av1_is_scaled(sf))) --
so the alphabet shrinks to the 2-symbol obmc one (with OBMC off, no symbol
at all). The 16x16+ path already had `&& !ref_is_scaled`; the leaf's own
comment asked whoever lifted the refusal to add it, and nobody could reach
the code to notice. First-bad without it: 96x96 denom-12 warped stream,
decode-order frame 3, luma (15,54), 7652 samples wrong, max 155.

Lifted, each byte-exact vs ffmpeg with its own hit counter:
* "an 8x8 partition leaf under a scaled reference"
* "a sub-8x8 inter block under a scaled reference" (both sub8 readers)
* "warp prediction with a scaled reference" -- its translational fallback
  was already implemented and the refusal sat in FRONT of it (class
  refusal-short-circuits-its-own-code); the r1 mismatch that kept it alive
  was the strip chroma piece below, not the fallback.

Same-shape sweep of "every caller that computes a scaled start position":
* mc::predict_maybe_scaled -- the one dispatch the sub-8x8 luma/chroma
  callers now share instead of hardcoding the unscaled walk.
* the 16x4/4x16 strip's sub-8x8 chroma piece was SKIPPED entirely under a
  scaled reference (silent wrong pixels, no refusal); it now rebuilds from
  the PREVIOUS strip's own reference and that reference's own scale factor.
* allow_warp's scale bail-out was missing at the 8x8-leaf single-ref warp
  and at both compound warp sites (PER SLOT: one tap can be scaled while
  its sibling still warps).

Gate: real_superres_streams_with_sub8_leaf8_and_warp_decode_pixel_exact --
two 96x96 denom-12 streams, every unrelated tool off, pixel-exact vs ffmpeg;
arm A hard-asserts scaled leaf8 + sub8 hits, arm B asserts a WARPED_CAUSAL
eligibility was suppressed by scale. The r27 census now asserts none of the
three strings can come back. Inventory rows removed.
perf(av1): whole-pel axes skip the pass they do not needAhmet Kaan Gümüş · c8bf4a0
perf(av1): whole-pel axes skip the pass they do not need

A motion vector with a whole-pel component still ran the full two-pass
filter. Fraction 0 is the identity tap, so each axis has an exact shortcut:
Round2(128 * s, InterRound0) == 16 * s horizontally, and vertically
Round2(128 * a, InterRound1) == Round2(a, InterRound1 - 7) (== a for the
compound round), which also means the 3 rows above and 4 below the block
never have to be filtered -- a 4-tall chroma block drops from 11 horizontal
rows to 4.

Byte-exact: 1080p 10-bit and 2160p HDR EC_PROBE_OUT16 dumps both cmp
identical to the pre-lane binary. Interleaved medians on the 1080p segment,
6 pairs against the previous commit: 19.08 s -> 17.42 s (faster in 5 of 6).
perf(av1): horizontal MC taps multiply at 16 bitsAhmet Kaan Gümüş · dcac6b3
perf(av1): horizontal MC taps multiply at 16 bits

The interior horizontal row had auto-vectorised, but into pmuludq/pshufd
chains: an i32 x i32 lane multiply is three instructions on SSE2. A tap is
|x| <= 128 and a sample is bounded by the bit depth (<= 4095 at 12-bit), so
narrowing both factors to i16 before the widening multiply gives exactly the
same products and one instruction per pair.

Byte-exact: 1080p 10-bit and 2160p HDR EC_PROBE_OUT16 dumps both cmp
identical to the pre-lane binary. Interleaved medians on the 1080p segment:
22.25 s base -> 16.64 s.
perf(av1): unscaled compound MC leaves the scaled walkAhmet Kaan Gümüş · 8c7cbe4
perf(av1): unscaled compound MC leaves the scaled walk

horizontal_scaled_pass was 14% of decode self time, and almost none of that
was scaling: every compound prediction routed through it whatever the
reference's scale, so an unscaled block paid a per-column integer-position
derivation, a per-column filter-phase lookup, a column-major read of the
reference and a per-tap clamp.

At REF_NO_SCALE that walk reduces algebraically to the fixed x0/xfrac split
(pos_x_q10 == x_q4 * 64 + 32 makes int_pel == x_q4 / 16 and
(x_qn & 1023) >> 6 == x_q4 % 16 for every column), so a new horizontal_pass
router sends it to the contiguous unscaled pass and leaves the general walk
for superres. Both vertical passes now accumulate tap-major over contiguous
slices and reuse the thread-local scratch, as the single-reference one does.

Byte-exact: 1080p 10-bit (299 frames) and 2160p HDR EC_PROBE_OUT16 dumps
both cmp identical to the pre-lane binary. Interleaved medians on the 1080p
segment: 23.39 s base -> 18.21 s (12.8 -> 16.4 fps).
perf(av1): unscaled MC does one contiguous horizontal pass, no per-call allocAhmet Kaan Gümüş · 62f159c
perf(av1): unscaled MC does one contiguous horizontal pass, no per-call alloc

predict_with_filters_kern spent 17% of decode self time in a doubly nested
per-sample loop: every tap re-read the filter table, every sample went
through the Clip3 edge helper, and each call allocated its own (h+7)-row
intermediate.

Restructured dav1d style, keeping the rounding chain untouched: taps are
fetched once into a [i32; 8]; a row whose whole 8-tap footprint is inside
the reference's true extent is one contiguous slice walked with windows(8)
(the clamped form stays for edge rows and is what a past-the-edge motion
vector still takes); the vertical pass accumulates tap-major over two
contiguous i32 slices and skips the zero taps the 4-tap kernels carry; the
whole-pel case copies a row at a time. The intermediate is a thread-local
scratch buffer instead of a per-call Vec.

Byte-exact: EC_PROBE_OUT16 dumps of a 299-frame 1080p 10-bit segment and a
4 s 2160p HDR segment both cmp identical to the pre-change binary.
Interleaved medians on the 1080p segment: 22.61 s -> 20.66 s.
perf(av1): read every EC_* debug flag once instead of per blockAhmet Kaan Gümüş · ba458d2
perf(av1): read every EC_* debug flag once instead of per block

`std::env::var*` is a getenv + strlen + CStr validation on every call, and
this crate reads its trace flags from per-block, per-TU and per-MC-call
paths -- 11.6% of a 1080p10 decode's self time went to that, with the two
worst sites inside the motion-compensation kernels themselves.

Nothing in the crate or its tests calls `set_var`, so each name is a
process constant. New `envflags` module: `env_flag!(NAME)` keeps one
`LazyLock<bool>` per CALL SITE (atomic load after the first call, no
hashing), `envflags::var` serves the value sites from a single snapshot of
the environment. Semantics are unchanged at every site -- `is_some()`,
`is_none()` and the `Result<String, VarError>` shape are preserved -- and
the decoder's output is byte-identical.

160 sites in decode.rs, 2 in mc.rs. Header/tool-lookup sites that run once
per stream are left alone. 1080p10 299-frame segment, interleaved medians
of 3: 24.47 s -> 22.03 s (12.2 -> 13.6 fps), output byte-exact.
(cherry picked from commit 318e0cce54fe7697a2d23c02d3b0d385f0e1401a)

2026-09-02

Merge branch 'lane-mc64' (2be1f92): pinned 192x128 stream with a 64x64 intra block in an inter frameAhmet Kaan Gümüş · 361f8be
Merge branch 'lane-mc64' (2be1f92): pinned 192x128 stream with a 64x64 intra block in an inter frame

Adds crates/ec-av1/fixtures/av1_192x128_8bit_intra64_in_inter.obu and its gate,
plus the EC_MC_TRACE rung. Conflicts: kept main's per-var dump_stage_idx over
the lane's single-counter stage_dump_idx, and main's sub-8x8 strip chroma
footprint (the lane branched before it) with the lane's MC trace line.

Gates: pinned_rect_stream (1), refusal_inventory (3), gate_coverage (9),
base_ctx_rect_offsets (1) -- 14 passed, 0 failed.
fix(av1): rect inter blocks picked the 4-tap chroma kernel from the square prediction buffer, not the blockAhmet Kaan Gümüş · 759e688
fix(av1): rect inter blocks picked the 4-tap chroma kernel from the square prediction buffer, not the block

decode_inter_block predicts a rectangular block over its enclosing square
buffer (side x side, chroma_side x chroma_side; write_w/write_h govern only
the pixel write). The narrow-block decision lived in mc::predict_with_filters
and read that buffer's dimensions, while libaom
av1_get_interp_filter_params_with_block_size takes it per axis from the
prediction block's own w/h -- so the chroma of an 8x16 / 16x8 inter block
(4x8 / 8x4) used the 8-tap kernel where libaom uses the 4-tap one. Luma is
never <= 4 wide on this path, which is why such streams decoded luma-exact
and differed by +-1 on scattered chroma samples (lane-interedge r1's 192x128
control, no frame-edge node, cdef/LR off).

mc gains predict_with_filters_kern / predict_scaled_kern /
predict_compound_intermediate_kern (old entry points delegate with kern =
block dims) plus a RECT_NARROW_KERN_HITS counter; decode_inter_block's 12
prediction calls pass write_w/write_h and write_chroma_w/write_chroma_h.

New gate a_real_aomenc_rect_inter_block_predicts_chroma_with_the_narrow_kernel_pixel_exact:
real aomenc mandelbrot 192x128 and 128x192, 8- and 10-bit, cq 20/32/45,
6 frames, lag-in-frames=0, every decode-order frame compared on Y, U and V;
12/12 arms exact, narrow-kernel counter nonzero at both depths and in both
orientations. Same recipe mismatched chroma in all arms before the fix.
fix(av1): per-frame stage dumps + MC trace, and re-localise the 192x128 frame-2 mismatch to a 64x64 INTRA blockAhmet Kaan Gümüş · f866759
fix(av1): per-frame stage dumps + MC trace, and re-localise the 192x128 frame-2 mismatch to a 64x64 INTRA block

EC_AV1_POSTDEBLOCK_DUMP/EC_AV1_POSTCDEF_DUMP wrote .f0 for every frame, so any
per-frame filter-stage bisection silently compared the last decoded frame; they
are now keyed on the decode-order picture index like the prefilt dump.

EC_MC_TRACE prints every mc::predict_with_filters / predict_compound_intermediate
/ warp_affine call with its q4 position, block size, subpel fractions and kernels,
placed before the whole-pel fast path, plus EC_IB at decode_inter_block entry and
is_inter/skip on EC_MODE -- an absent MC call is now visible.

With that: the 192x128 8-bit stream's frame-2 luma-only mismatch at px(128,64) is
a 64x64 PARTITION_NONE INTRA block in an inter frame, not the inter NEWMV block
the charter described (that mv belongs to frame 1's split superblock, which is
exact). Zero MC calls for the block in either decoder; chroma bit-exact, so the
64-length luma transform is the suspect. Stream pinned as a fixture because its
aomenc recipe does not reproduce it.

2026-09-01

fix(av1): a prediction block 4 or fewer samples wide reads the REGULAR narrow subpel kernel under EIGHTTAP_SHARP too -- spec 7.11.3.4 filterIdx sends EIGHTTAP and EIGHTTAP_SHARP to filter index 4, and libaom's av1_interp_4tap[MULTITAP_SHARP] is av1_sub_pel_filters_4 (filter.h:239-244, comment "For w<=4, MULTITAP_SHARP is the same as EIGHTTAP_REGULAR"); we used the 8-tap sharp table there, invisible above 4 samples so it only bit 4-wide chroma. Cherry-picked from lane-gmaffine 3bb10f1; unit test pins all four narrow mappings (regular->4, smooth->4smooth, sharp->4, bilinear->bilinear).Ahmet Kaan Gümüş · 53b4e56
fix(av1): a prediction block 4 or fewer samples wide reads the REGULAR narrow subpel kernel under EIGHTTAP_SHARP too -- spec 7.11.3.4 filterIdx sends EIGHTTAP and EIGHTTAP_SHARP to filter index 4, and libaom's av1_interp_4tap[MULTITAP_SHARP] is av1_sub_pel_filters_4 (filter.h:239-244, comment "For w<=4, MULTITAP_SHARP is the same as EIGHTTAP_REGULAR"); we used the 8-tap sharp table there, invisible above 4 samples so it only bit 4-wide chroma. Cherry-picked from lane-gmaffine 3bb10f1; unit test pins all four narrow mappings (regular->4, smooth->4smooth, sharp->4, bilinear->bilinear).
fix(av1): combine_compound folded two shifts libaom keeps separateAhmet Kaan Gümüş · cc39f29
fix(av1): combine_compound folded two shifts libaom keeps separate

libaom's `av1_highbd_dist_wtd_convolve_2d_c` (and its lowbd twin) applies a
TRUNCATING `>> DIST_PRECISION_BITS` to the weighted sum and only then
`ROUND_POWER_OF_TWO(.., round_bits)`. We folded both into `Round2(sum, 8)`,
which rounds one LSB high whenever `(sum >> 4) + 8` is one below a multiple
of 16 and the dropped low 4 bits are non-zero. Bit-depth independent (the
CONV_BUF round_offset cancels exactly in this crate's unbiased intermediate
domain), so it is a rare off-by-one at any depth -- raised by lane-cwarp's
measurement that 10-bit compound still mismatches frame 1 luma while
single-reference 10-bit is 6/6 exact. Unverified against that fixture.

cargo test -p ec-av1 --lib -j3 compound: 16 passed, 0 failed, 73.58s
(includes the real-aomenc 8-bit compound and masked-compound gates).
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

Merge branch 'main' into lane-superresAhmet Kaan Gümüş · 17c9a9c
Merge branch 'main' into lane-superres

Resolves the scaled-MC conflict in decode.rs in favour of the lane's
structure, and widens predict_scaled to u16 for main's high-bit-depth
sample type (fixture included).

Lane state after the merge: 264 passed, 1 failed -- the lane's own gate
a_real_aomenc_key_and_inter_superres_sequence_decodes_pixel_exact. That
is the lane's deliverable, not merge fallout, so this does not go to
main yet.
feat(av1): u16 widen compiles clean, 263/263 tests pass, 8-bit output bit-exactAhmet Kaan Gümüş · 35100f3
feat(av1): u16 widen compiles clean, 263/263 tests pass, 8-bit output bit-exact

Closes the 42-error checkpoint from r1's saved diff. decode.rs/warp.rs/mc.rs
call sites widened through OBMC and interintra blend chains; encode.rs and
motion.rs's own buffers stay u8 (encoder is 8-bit only this round) with a
local u16 round-trip box (intra_predict_u8 in encode.rs, inline conversion
in mc_trial and motion::search_traced_from_step) at their 4 call sites into
the now-widened intra::predict/mc::predict. bit_depth != 8 refusal
untouched, no 10-bit gate added.
feat(av1): mc::predict_scaled + frame_width threaded through decode_inter_blockAhmet Kaan Gümüş · bc2ef3d
feat(av1): mc::predict_scaled + frame_width threaded through decode_inter_block

mc::predict_scaled/scale_factor/REF_NO_SCALE per r8's derived spec 7.11.3.3
algorithm (horizontal-only scaled sampling grid, vertical pass untouched);
pinned at REF_NO_SCALE reproducing predict_with_filters bit-exact for every
subpel fraction and block width 4/8/16. decode_inter_block gains a
frame_width: usize parameter (18 call sites end allow_screen_content_tools,
one test call site ends false,), not yet consumed -- prediction and refusal
wiring is next.

2026-08-28

feat(av1): port the DIFFWTD masked-compound blend (comp_group_idx==1), wedge still refusedAhmet Kaan Gümüş · ddb5bef
feat(av1): port the DIFFWTD masked-compound blend (comp_group_idx==1), wedge still refused

diffwtd_mask/blend_masked_compound in mc.rs, algebraically re-derived onto
this crate's unbiased predict_compound_intermediate domain (libaom's
round_offset bias cancels exactly in both the mask diff and the blend
weight sum, proven in the doc comments -- no offset bookkeeping needed).
Both comp_group_idx==1 decode.rs sites now build+apply the real blend for
COMPOUND_DIFFWTD; COMPOUND_WEDGE still refuses by name (wedge codebook out
of r2 scope per the charter's mergeable-partial fallback). Fixed a real
latent bug while wiring this in: compound_idx was read unconditionally,
missing libaom's comp_group_idx==0 outer gate (dead code before this round
since the masked path always errored earlier).

Gate a_real_aomenc_stream_with_masked_compound_decodes_pixel_exact flipped
to hard assert (masked_compound_hits() > 0) with DIFFWTD refusals now
forbidden; hammered 8/8 green, zero pixel mismatches. Full ec-av1 lib
suite: 220 passed, 0 failed, 17 ignored.
feat(av1): compound CONV_BUF blend + distance-weight assign, not wired yetAhmet Kaan Gümüş · 181a784
feat(av1): compound CONV_BUF blend + distance-weight assign, not wired yet

mc.rs: predict_compound_intermediate (round_1=7, no clip, mirrors libaom's
COMPOUND_ROUND1_BITS path) and combine_compound (spec 7.11.3.15 weighted
average, shift = InterPostRound + DIST_PRECISION_BITS) -- pinned against a
whole-pel identity case that round-trips exactly through both stages.

compound.rs (new): dist_wtd_comp_weight_assign, a pure port of libaom's
av1_dist_wtd_comp_weight_assign (quant_dist_weight/quant_dist_lookup_table
search), tested standalone against hand-worked order-hint cases.

Neither is wired into decode.rs yet -- comp_group_idx/compound_idx reads,
Neighbours compound_idx tracking, and the reconstruction call sites are
still open (see HANDOFF).

2026-08-27

feat(av1): interpolation filters beyond REGULAR, incl. per-block SWITCHABLEAhmet Kaan Gümüş · 10f24e6
feat(av1): interpolation filters beyond REGULAR, incl. per-block SWITCHABLE

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

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

Adds a permanent gate (crates/ec-av1/src/stream.rs) that shells out to a
real standalone aomenc build (ffmpeg's own libaom-av1 wrapper on this box
doesn't expose enable-tx-size-search/loopfilter-control through
-aom-params), asserts the use_filter_intra symbol actually fired via a new
process-global counter (decode::filter_intra_hits), and checks pixel-exact
luma/U/V against ffmpeg's own decode of the identical bytes. The
encoder's screen-content-tools decision is a real internal PSNR trial,
occasionally flips even with palette/intrabc off; the test skips (not
fails) the still-unsupported-gap runs the same way the existing CDEF gate
test does.
fix(av1): 4-tap subpel filters for blocks 4 wide or tallAhmet Kaan Gümüş · aad8b59
fix(av1): 4-tap subpel filters for blocks 4 wide or tall

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

Closes the 640x360 inter straddle sequence's frame-2 U-plane desync; the
whole sequence now round-trips through ffmpeg pixel-exact.
perf(av1): bypass sub-pel filtering for whole-pel motion predictionAhmet Kaan Gümüş · ef383d9
perf(av1): bypass sub-pel filtering for whole-pel motion prediction

Profiled the inter path (stage_timing_breakdown_inter, 720p GOP): 403 of a
408ms motion-search bucket was crate::mc::predict, almost entirely from the
search's own whole-pel log/diamond stage. SUBPEL_FILTERS[0] is the identity
tap and both rounding shifts are exactly that filter's gain, so the two
8-tap passes reproduce the reference sample byte-for-byte at zero fraction
(integer_mv_is_identity already pinned this) -- a clamped direct copy is
bit-identical, not an approximation. Motion search bucket 408.55ms ->
181.85ms, frame total 818.88ms -> 585.24ms, same 997 output bytes.
perf(av1): stop repricing an inter block's chroma trial 13 times overAhmet Kaan Gümüş · cc09bf2
perf(av1): stop repricing an inter block's chroma trial 13 times over

An inter frame's intra-candidate loop in search_inter_block always coded
both chroma planes as DC_PRED, independent of which of the 13 luma modes
the loop was on -- so the identical transform/quantize/coeff_bits call
ran twelve times for nothing on every inter block. Hoist it out of the
loop and clone the one result in (bit-identical: same call, same inputs,
same output, verified by the full 129-test suite and an equal output
byte count on the stage_timing_breakdown_inter probe, 1356 bytes before
and after).

Also add stage_timing_breakdown_inter, an #[ignore]d probe that breaks
one inter frame's time into motion search / mc::predict / transform+
quantize / coeff_bits buckets, which is how this was found: transform+
quantize was the largest bucket (454.78ms of 980.36ms), not motion
search (267.26ms, of which 257.01ms is genuine sub-pel interpolation
work already spent inside the diamond search).

1280x720 inter frame: 980.36ms -> 772.05ms (-21%).
fix(av1): clamp inter MC reads to the reference's true extent, not its coding strideAhmet Kaan Gümüş · 8d520ef
fix(av1): clamp inter MC reads to the reference's true extent, not its coding stride

sequence_round_trips_at_a_non_multiple_size (160x96) failed on inter-frame
chroma/luma content: a spec decoder's reference buffer holds exactly
FrameWidth x FrameHeight (mi_cols*4 x mi_rows*4) -- a superblock's partition
stops early at has_cols/has_rows and never codes syntax for padding
columns/rows beyond the true edge, so those samples are never part of the
decoded picture. MC's Clip3 (spec 7.11.3.4) must clamp reference reads to
that true extent, replicating the true edge, not to this crate's own
padded-to-SUPERBLOCK coding surface.

`mc::sample`/`mc::predict` used one width/height pair for both the buffer's
row stride and the Clip3 clamp bound, conflating the two; split into a
`stride` param (the buffer's real row length, unchanged) plus
`true_width`/`true_height` (the clamp bound, now `Plane::true_width`/
`true_height` at the call site) threaded through `motion::search` and
`encode::mc_trial`.

Gate: 126 passed/1 failed/4 ignored -> 127 passed/0 failed/4 ignored.

2026-08-26

feat(av1): sub-pel motion compensation (spec 7.11.3, EIGHTTAP regular)Ahmet Kaan Gümüş · 082d993
feat(av1): sub-pel motion compensation (spec 7.11.3, EIGHTTAP regular)

Two-stage separable 8-tap filter, InterRound0=3/InterRound1=11 for
8-bit non-compound per spec 7.11.3.2, edge samples clamped rather than
read out of range. Not yet wired into encode.rs (later lane).