Commits
Commits on
16ae97f167b73e3f520b090e4ff471d07d669b7f2026-09-04
Merge branch 'lane-t900' (f90d83a1): intrabc under 128x128 superblocks (fallback DV keyed on the sequence SB size) and palette blocks with residual on superblock-level strips (chroma palette override on the non-skip arm); both refusals lifted and gatedAhmet Kaan Gümüş · 16ae97fBrowse files
fix(av1): a non-skip palette block on a superblock-level strip lost its UV predictionAhmet Kaan Gümüş · 3a302e7
fix(av1): a non-skip palette block on a superblock-level strip lost its UV prediction
`decode_block_rect64` built the UV-palette prediction buffers and
installed them into the PALETTE_PRED slot only in its `skip` arm. The
non-skip arm reconstructed both chroma planes straight from
`reconstruct_rect`'s edge prediction, so a palette block with a real
residual on a 64x32/32x64 strip decoded its luma exactly and both
chroma planes wrong -- which is why the shape was refused by name
("corner-cropped luma coefficients not ported for palette", a
misattribution: the corner crop was never the defect).
FIRST BAD: testsrc2 128x128 10-bit cq55 `--tune-content=screen
--enable-palette=1 --min-partition-size=8 --sb-size=64 --tile-columns=1
--enable-tx-size-search=0`, the 32x64 strip at px=96: luma byte-exact,
U/V each 512 samples wrong over the block's 16x32 chroma footprint.
Installing the per-plane override right before each chroma
`reconstruct_rect`, exactly as the `skip` arm does, makes the frame
byte-exact against ffmpeg.
Class: an override slot installed on one arm of a skip/non-skip split.
Swept every palette+residual reconstruct path in decode.rs (rect, rect4,
rect_split, leaf_rect, leaf8, block, inter_block, inter_block8): this
was the only site missing the install.
The gate that documented the refusal now asserts zero refusals and a
non-zero superblock-strip palette count; inventory row deleted.feat(av1): intrabc under a 128x128 superblock decodes by defaultAhmet Kaan Gümüş · c4ca926
feat(av1): intrabc under a 128x128 superblock decodes by default `av1_find_ref_dv` (mvref_common.c) takes `mib_size` -- the sequence's superblock size in mi units -- so under `use_128x128_superblock` the fallback block vector is one 128-px superblock up, or 128 + INTRABC_DELAY_PIXELS to the left on the tile's first superblock row. `read_intrabc_dv` hardcoded the 64-px superblock, which is why the frame-header refusal "intrabc under a 128x128 superblock" existed. Reading it off `sb_mi_cur` lifts the refusal: all four arms of r33's census (`--sb-size=128 --tune-content=screen --enable-intrabc=1`, both `--enable-tx-size-search` settings, cq 30/45, 2x2-tiled 128x96 bars at 256x192) now decode pixel-exact against ffmpeg, so the r33 census is replaced by the un-ignored witness it pinned, which additionally asserts a non-zero decoded-intrabc-block count so a stream that stopped using intrabc cannot make it vacuous. Inventory row deleted.
Merge branch 'lane-t900' (89195e5c): refusal inventory closed, 35 of 35 proven by enumeration, census or negative gate; dead palette guards deleted; sb128 intrabc gap pinned with a waiting witnessAhmet Kaan Gümüş · e5de66dBrowse files
test(av1): census the last three unproven refusals; pin the sb128-intrabc gapAhmet Kaan Gümüş · da8c1a6
test(av1): census the last three unproven refusals; pin the sb128-intrabc gap The three intrabc refusals are the inventory's residue, and all three are now measured against real aomenc streams rather than asserted: * sb128 + intrabc is REACHED -- all four `--sb-size=128` exact-repetition screen arms code `use_128x128_superblock && allow_intrabc` and every one of them refuses by name. A capability gap, pinned with its first-bad recipe and a waiting (ignored) pixel-exact witness; * a sub-8x8 leaf's `use_intrabc` symbol is read 38 times over two `--min-partition-size=4` arms and comes back 0 every time, frames exact; * the intrabc var-tx tree is read for 5 blocks over four quantisers, every one resolving to a uniform leaf size, frames exact. refusal inventory: 35 refusals / 32 proven -> 35 refusals / 35 proven.
Merge branch 'lane-thread2' (2eee637d): per-frame decode lifted into decode_frame; leaf frames decoded on scoped worker threads with a reorder queue (EC_AV1_THREADS, default 1); byte-exact at 1 and 4 threads on four inputs, 4K 1.51x at 2 threadsAhmet Kaan Gümüş · f5fdee3Browse files
test(av1): prove four refusals by enumeration and delete the dead palette (Y) guardAhmet Kaan Gümüş · 2937d25
test(av1): prove four refusals by enumeration and delete the dead palette (Y) guard The two `decode_rect_split` shape refusals (rect chroma tables, split intra strip transform unit) are enumerated over their five callers' footprint domain at every tx depth, against both `match` tables read out of decode.rs itself. The 128-root CfL/filter-intra/palette guard is enumerated over its four symbols' own size gates. The palette (Y) guard was dead -- all eight `read_intra_mode`/`read_intra_mode_rect` call sites hand the reader a real ctx/cache pair -- so both arms are deleted and an audit keeps the invariant. The superblock-strip palette refusal is registered as a witnessed capability gap: its gate already hard-asserts a real screen stream reaches it by name. refusal inventory: 36 refusals / 28 proven -> 35 refusals / 32 proven.
test(av1): a real stream decodes identically at 1 and at 4 threadsAhmet Kaan Gümüş · 5f3725c
test(av1): a real stream decodes identically at 1 and at 4 threads Two real fixtures through `decode_stream_with_threads`, every sink call compared (decode index, shown flag, all three planes). `reelb_arf_witness.obu` is the arm that proves the parallel path -- 18 of its 40 coded frames are leaves of the reference graph and really are decoded off the main thread, and it carries hidden alt-refs, where "output in coded order" and "output in worker completion order" differ; `palette_screen_witness.obu` is the complement, an 8-bit screen stream that dispatches nothing because every coded frame refreshes a slot. The dispatch counter is asserted in both directions (18 and 0), so neither arm can pass vacuously.
feat(av1): decode leaf frames on worker threads (EC_AV1_THREADS, default 1)Ahmet Kaan Gümüş · b3a78b4
feat(av1): decode leaf frames on worker threads (EC_AV1_THREADS, default 1) `decode_stream_with_threads(data, threads, sink)` decodes the frames no later frame can reference -- shown, non-key, `refresh_frame_flags == 0`, the leaves of the reference graph -- on scoped worker threads, while the main thread keeps parsing headers and decodes inline every frame that does feed the banks. Each worker gets a fresh `FrameCtx` and a `RefSnapshot` taken before dispatch (`Arc` clones of the DPB slots this frame names, re-shared until the slot is overwritten; the DPB itself stays owned `Picture`s, an `Arc` DPB measured slower single-threaded), so nothing is shared. A `Reorder` queue keyed on the output position hands `sink` every picture in coded order regardless of when a worker finishes; in-flight leaves are bounded to `threads + 1`; a worker error (panic included) aborts the stream with that error. `decode_stream_with` reads `EC_AV1_THREADS` (default 1), so the whole suite and every per-thread gate counter keep the serial semantics; the four perf-gate streams hash identically at 1 and at 4 threads. `stream::leaf_frames_dispatched()` (process-global, atomic) is the proof a threaded run actually used the parallel path -- decode_probe prints it.
Merge branch 'lane-t900' (0e80dea1): intrabc blocks follow the inter tx-size rule under TX_MODE_SELECT (skipped reads no symbol, unskipped reads the var-tx tree); intra path publishes txfm contexts under allow_intrabc; 128-root screen-strip refusal lifted with an edge-forced screen witnessAhmet Kaan Gümüş · 7407710Browse files
test(av1): witness the lifted 128-root screen-strip refusal with a real screen streamAhmet Kaan Gümüş · 0b83527
test(av1): witness the lifted 128-root screen-strip refusal with a real screen stream r18's edge-forced 704x320 recipe re-encoded with `--tune-content=screen --enable-palette=0 --enable-intrabc=0` DOES code 128-root HORZ/VERT halves inside its inter frames -- r23's census missed them because it never tried this source. Six encodes: cq 20/35/50 fire 15x 128x64 plus 8/10/6x 64x128 and decode all 15 frames byte-exact on every plane, and each one's `--enable-rect-partitions=0` twin codes zero 128-root halves, which is what says the shape is the coded HORZ/VERT arm. cq20 is pinned as `fixtures/intra128_in_inter_screen_witness.obu` (119048 bytes, sha256 c84a493f...). The gate reads `allow_screen_content_tools` out of the frame headers rather than trusting the encoder flag, so it cannot go vacuous against the condition the deleted refusal named.
test(av1): un-ignore the intrabc TX_MODE_SELECT witness; lift the 128-root screen-strip refusalAhmet Kaan Gümüş · bbe0850
test(av1): un-ignore the intrabc TX_MODE_SELECT witness; lift the 128-root screen-strip refusal Both arms of `an_intrabc_block_under_tx_mode_select_decodes_pixel_exact` decode pixel-exact against ffmpeg, and the census gate's `tiled-square-cq45` arm rejoins the ordinary table (it is no longer the hole the refusal was one `&&` narrower than). r31's note that cq=45's intrabc blocks are all `skip` was read off the desynced decode: corrected, cq=45 carries 3 unskipped of 10 and cq=30 carries 1 of 16, so both arms exercise both sides of the split and both assert the var-tx counter fired. Inventory: "an intrabc block under TxMode::Select" deleted (lifted); "a HORZ/VERT intra strip in a screen-content frame" deleted -- r31's enumeration (`av1_allow_palette`'s `bw > 64 || bh > 64` bound) is its proof that a 128-root half codes no palette syntax at all, so a screen frame's half is syntactically identical to the non-screen one the r18 witness already decodes byte-exact. One residue registered: a var-tx tree resolving to mixed leaf sizes, unreached by either arm.
refactor(av1): one coded frame decodes from a bank snapshot alone (decode_frame)Ahmet Kaan Gümüş · 1241afc
refactor(av1): one coded frame decodes from a bank snapshot alone (decode_frame) The body of `decode_stream_with`'s loop between "frame header parsed" and "reference banks updated" becomes `decode_frame(fctx, header, tile_bufs, seq, snap, ..) -> FrameOutput`, a function of the bitstream plus a `RefSnapshot` (the 8 DPB slots, the primary reference's saved CDFs and segment map, spec 7.9's projected motion field, the reference order hints) and `SeqFlags` (the sequence-header bits it needs). Nothing in it reaches for the parser or for a bank any more, which is what lets a frame be decoded off the parsing thread at all. Pure refactor: the four perf-gate streams hash exactly as before (seg1080 c2d4ef66, seg4k 3ac25ee5, seg4k_lr d197dbe0, palette 2bfb6839), and the refusal ORDER is preserved deliberately -- the "primary_ref_frame at a slot with no saved CDF state" error still fires inside `decode_frame`, after the segmentation and 12-bit refusals, even though the snapshot that carries the slot is taken before the call.
feat(av1): an intrabc block reads the INTER tx-size syntax under TX_MODE_SELECTAhmet Kaan Gümüş · 0674134
feat(av1): an intrabc block reads the INTER tx-size syntax under TX_MODE_SELECT libaom's `parse_decode_block` dispatches `read_block_tx_size` on `is_inter_block`, which counts an intrabc block (`blockd.h:373`). This decoder read the intra `tx_depth` symbol for both cases, so: * a SKIPPED intrabc block consumed a symbol libaom never wrote (`allowSelect = !skip || !is_inter` is false for it, spec 5.11.16), which desynced the tile from that block on -- the cq45 arm's first divergent pixel was the top-left of the superblock at (192,64), one whole block after the bad read (class `equal-range-means-unread`); * an UNSKIPPED one was refused by name. Both now follow the inter rule: skipped takes `maxRectTxSize` with no symbol, unskipped reads `read_var_tx_size`. The intrabc luma prediction moves onto the per-TU-windowed override slot (a split transform is the first shape that can reach the multi-TU loop with one set), the 4x4 units of an 8x8 intrabc leaf code off the inter ext-tx set, and every key-frame block publishes `set_txfm_ctxs` when `allow_intrabc` -- the var-tx read is the only intra-path reader of those bands and they were stuck at `TXFM_CTX_INIT`. A var-tx tree resolving to mixed leaf sizes is refused by name (the luma reconstruct loop is a uniform grid); neither test stream reaches it.
Merge branch 'lane-thread1' (24d7e690): the 38 per-frame decode-state thread_locals become one crate-private FrameCtx threaded through the decoder; public encoder signatures unchanged; byte-exact on four inputs, 2.6% fewer instructions (merge also makes decode_inter_frame_tile and InterStripChroma crate-private for a clean workspace check)Ahmet Kaan Gümüş · 63370ceBrowse files
refactor(av1): FrameCtx stays crate-private -- public signatures back to what they wereAhmet Kaan Gümüş · 1c71b70
refactor(av1): FrameCtx stays crate-private -- public signatures back to what they were The FrameCtx refactor threaded `&crate::decode::FrameCtx` through 21 `pub fn` signatures, which put a `pub(crate)` type in the crate's public API: external callers of `Av1Encoder::encode` stopped compiling (tools/ec-bench). `Av1Encoder` now owns its `FrameCtx` -- one per stream, not per frame, since the inter-frame inheritance guards carry state across frames -- so `encode` takes `(&mut self, picture)` again. `encode_key_frame`, `encode_key_frame_with_modes` and `encode_sequence` keep their old public signatures as wrappers over `pub(crate) *_with_ctx` inners that make the context. The other 14 helpers that gained the parameter (intra/mc/warp/motion predictors, `decode_key_frame_tile`) have no caller outside the crate and become `pub(crate)`. `Av1Encoder` is still `Send` (compile-time assert), but owning cells makes it `!Sync`; nothing in the workspace shares one by reference.
test(av1): pin that no per-frame decode state is thread_local againAhmet Kaan Gümüş · 4c4f667
test(av1): pin that no per-frame decode state is thread_local again The 38 names that moved into FrameCtx are asserted absent as `static` in decode.rs/encode.rs/film_grain.rs, and the scratch pools + gate hit counters are asserted still thread_local (they are per-thread by design; the gates read the counters on the test thread).
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.
Merge branch 'lane-t900' (40217d54): intrabc under TX_MODE_SELECT proven reachable by census (capability gap pinned), 128-root screen-strip palette absence enumerated; 29 of 37 provenAhmet Kaan Gümüş · e320ba7Browse files
test(av1): no block footprint with a 128-pixel side can carry palette syntaxAhmet Kaan Gümüş · 552edc4
test(av1): no block footprint with a 128-pixel side can carry palette syntax
Two inventory entries.
The intrabc/TX_MODE_SELECT refusal is registered as proven by the new census
gate: it is measured, reachable, and a capability gap rather than a claim.
The 128-root screen-strip refusal ("palette syntax is consumed for square
blocks only") gets an enumeration that DISPROVES its premise: av1_allow_palette's
bound, as decode.rs spells it in palette_bsize_ctx_wh, rejects every footprint
with a 128-pixel side, so a screen-content frame codes no palette syntax on a
128x64/64x128 half and that half decodes exactly like the non-screen twin
already witnessed. The bound is asserted against decode.rs's own source, not a
copy, so moving the predicate breaks the test.
It is deliberately NOT registered as proven: the guarded condition is still
reachable, so this proves the lift safe, not the case absent -- and the lift is
a decode.rs edit plus a --sb-size=128 --tune-content=screen witness that codes a
128-root half, which no encode has produced yet.test(av1): a real screen key frame codes an unskipped intrabc block under TX_MODE_SELECTAhmet Kaan Gümüş · c72e315
test(av1): a real screen key frame codes an unskipped intrabc block under TX_MODE_SELECT The refusal "an intrabc block under TxMode::Select" was an unmeasured claim about the encoder. Spec-wise its premise is open (tx_mode is forced to ONLY_4X4 only under CodedLossless; allow_intrabc is an independent screen-content condition) and libaom leaves it open too -- select_tx_mode never consults allow_intrabc, and the only downgrade to TX_MODE_LARGEST is txb_split_count == 0. The census over 13 real --tune-content=screen --enable-intrabc=1 key frames settles it: ordinary sources never present the premise (with tx-size-search on, RD never picks intrabc and libaom clears allow_intrabc again; with it off the frame is TX_MODE_LARGEST), but an exact-repetition source -- a 2x2 tiling of one bar pattern -- codes allow_intrabc under TX_MODE_SELECT, and with the rect/1:4 partitions off its intrabc block lands on a square block unskipped and reaches the refusal by name. Twelve arms decode pixel-exact against ffmpeg; exactly one refuses. So the refusal is real and load-bearing, and the lift it names gets a waiting witness gate (ignored until the intra path reads the inter var-tx tree). The same recipe at cq=45 exposes the hole the refusal does NOT cover: those intrabc blocks are all skip, pass the `&& !skip` guard and decode WRONG against ffmpeg. That arm sits in the ignored gate with a note; narrowing the guard is a decode.rs edit this round could not make.
Merge branch 'lane-t900' (4d424ef3): chroma deblock edges index the mode-info grid at the bottom/right mi of the 8x8 luma group with a 2-mi step and plane-pixel pu_edge (libaom set_lpf_parameters); superres all-tools 128-SB stream byte-exactAhmet Kaan Gümüş · d0c8191Browse files
fix(av1): a chroma deblock edge must read the group's BOTTOM/RIGHT miAhmet Kaan Gümüş · 58b009b
fix(av1): a chroma deblock edge must read the group's BOTTOM/RIGHT mi `set_lpf_parameters` (libaom av1_loopfilter.c:245) indexes the mi grid for a CHROMA edge at `scale | ((coord << scale) >> MI_SIZE_LOG2)` -- the bottom/right mi of the co-located 8x8 luma group, the same cell that donates the group's chroma prediction -- steps to the previous cell by `1 << ss` mi, and prices `pu_edge` by testing the edge coordinate against the block size in the FILTERED plane's own pixels (chroma bottoms out at 4 px). This decoder dropped the `| 1`, stepped by one mi, and compared mi origins. All three are invisible while every block is 8x8 or larger -- all four mi of a group carry the same tx size, ref frame, skip flag and delta_lf -- and wrong the moment cpu-used=4 splits a group into 4x4 luma blocks: the top-left mi's filter level 12 fired filter4 on a U edge where the bottom/right block's level 8 leaves it alone. Class `context-read-from-one-cell`. Measured on fixtures/superres_alltools_sb128_320x180.obu against the instrumented libaom: post-deblock (EC_AV1_POSTDEBLOCK_DUMP) 1 wrong U sample in frame 2 growing to 137 U + 131 V by frame 9 -> 0 in all 10 frames, and the final output goes from 280 U + 331 V (max 9) to byte-exact vs ffmpeg. The prediction path was never at fault: every prefilt frame was already exact, and the frame-4 prefilt drift was the deblocked reference chain. `a_superres_all_tools_sb128_stream_decodes_pixel_exact` is un-ignored.
Merge branch 'lane-perf9' (45593d8b): film-grain chroma AVX2, sgrproj box sums sliding vertically, deblock edge_params hoists segmentation_enabled; byte-exact on four inputs, 4.6% fewer instructions at 4KAhmet Kaan Gümüş · eb63f3eBrowse files
revert "perf(av1): the DPB shares one Arc per picture instead of copying it per slot"Ahmet Kaan Gümüş · 173712b
revert "perf(av1): the DPB shares one Arc per picture instead of copying it per slot" The wall-clock pairs that commit shipped (38.59 s -> 37.62 s) were noise: at +-2% run-to-run on this box three pairs cannot resolve a 1% effect. Measured again with `perf stat` (near-deterministic for this decoder) over six interleaved runs each, the Arc form retires 0.15 G fewer instructions -- the picture copies really do disappear, and page faults drop 401 k -> 142 k -- and still burns ~1% MORE cycles on seg4k: 188.4 G median (main) vs 190.7 G. The eight stable per-slot buffers the copies recycle are cheaper to walk than the one buffer per decoded frame the shared form allocates and frees. `perf stat -e cycles:u,instructions:u` on seg4k, alternating binaries, is the instrument the rest of this lane used; wall clock is not.
perf(av1): the deblock edge derivation reads segmentation once per plane passAhmet Kaan Gümüş · bf70705
perf(av1): the deblock edge derivation reads segmentation once per plane pass `edge_params` (2.9% self time at 4K, called for every 4x4 edge position) took four thread-local reads (`SEG_MI_DIMS` and `SEG_IDS`, twice each) plus two `SEG` borrows per call to look up two segment ids and their `SEG_LVL_ALT_LF_*` deltas. `segmentation_enabled` is a per-frame flag, so it is read once per plane pass now: with it clear every segment id is 0 and no LF feature can be active, so both lookups are skipped and the levels are identical. Small: seg4k pair deltas 0.20/0.16/0.04 s, medians 35.31 s -> 35.27 s. Byte-exact on all four inputs.
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): AVX2 film-grain chroma rowsAhmet Kaan Gümüş · 8d96c7f
perf(av1): AVX2 film-grain chroma rows The chroma arm of spec 7.18.3.5's `add_noise_to_block` was the last scalar half of grain synthesis (`add_noise_to_block` 4.6% self time at 4K next to the already-vectorised luma kernel's 2.4%): one loop doing both planes with the loop-invariant `apply_cb`/`apply_cr` tests inside it. Split per plane into `chroma_noise_row` (scalar reference) plus an AVX2 kernel that does 8 chroma samples at a time -- the 4:2:0 luma pair sum is one `vpmaddwd` against ones, the LUT read the same clamped gather as the luma kernel. `simd_matches_scalar_chroma_noise_row` pins the pair over every grain bit depth, both clip ranges, three multiplier triples (including `chroma_scaling_from_luma`'s 0/64/0) and lengths either side of the vector step. seg4k 36.70 s -> 35.88 s (medians of 3 interleaved pairs); byte-exact on seg1080/seg4k/seg4k_lr/palette.
perf(av1): the DPB shares one Arc per picture instead of copying it per slotAhmet Kaan Gümüş · 68c67bf
perf(av1): the DPB shares one Arc per picture instead of copying it per slot `refresh_frame_flags` names up to eight reference slots, and each one took a full `Picture` copy -- ~25 MB at 4K, so a key frame alone memcpy'd ~200 MB and every inter frame paid one copy per slot it refreshed. `perf --call-graph fp` attributes 2.2 of the 5.7% `memmove` self time to `decode_stream`'s own frame (the slot stores), the rest to the tile decode, `decode_inter_block`, loop restoration and the per-TU transform buffer. The slots now hold `Arc<Picture>`: one allocation per decoded frame, pointer copies per slot, and the shown-frame sink borrows either the grain-synthesised picture or the stored one instead of moving a copy through `output`. seg4k 38.59 s -> 37.62 s (medians of 3 interleaved pairs); byte-exact on seg1080/seg4k/seg4k_lr/palette.
Merge branch 'lane-perf8' (2e14ee56): AVX2 deblock over 16 edge lines with per-edge parameter sharing; Wiener restoration reuses the MC passes and resolves stripe substitution per row; byte-exact on four inputs, 4K 40.6 s to 35.7 sAhmet Kaan Gümüş · b83300dBrowse files
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 deblock kernel -- 4K decode 40.6 s -> 38.1 sAhmet Kaan Gümüş · 1332eb0
perf(av1): AVX2 deblock kernel -- 4K decode 40.6 s -> 38.1 s `filter_edge` was 8.0% of a 4K decode's self time and `edge_params` another 3.5%; `perf annotate` puts the cost on the per-tap strided addressing (`leaq`/`movzwl` pairs), not the arithmetic, which is why lane-perf7's three scalar restructures all measured neutral-to-worse. This filters 16 edge lines at once in 16-bit AVX2 lanes: the same masks, the same `filter4` centred-domain clamps and the same `filter6`/`8`/`14` weighted sums (their weights total 8 or 16, so a sum of 12-bit samples stays inside `u16` and the rounding shift is the unsigned one). A horizontal edge's taps are whole row segments, loaded directly; a vertical edge's are consecutive samples, so 16 rows are loaded as a 16x16 tile and transposed through the unpack ladder. Both passes now iterate the edge's own direction innermost so four consecutive 4-sample groups can share one kernel call. The swap is order-preserving: a group's writes reach only along its own edge, so the dependence stays on the outer loop's ascending order. Where the four groups' `edge_params` disagree, or the edge sits too close to a plane border for the kernel's window, the scalar `filter_edge` still runs -- it remains the reference, and a property test pins the kernel to it sample-exact over every bit depth, filter length, level, sharpness and both directions. Byte-exact on all four probe inputs (1080p, 4K, 4K+LR, palette).
Merge branch 'lane-perf7' (dd6a23f3): AVX2 CDEF tap filter with scalar reference and property test; loop-restoration stripe kernels hoist sample_max and reuse scratch; byte-exact on four inputs, 4K 47.1 s to 41.2 sAhmet Kaan Gümüş · d6ebc77Browse files
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): AVX2 CDEF filter -- 4K decode 47.1 s -> 41.2 sAhmet Kaan Gümüş · e2f820e
perf(av1): AVX2 CDEF filter -- 4K decode 47.1 s -> 41.2 s `cdef_filter_block` was 13.1% of a 4K decode's self time: a scalar loop doing ~17 bounds-checked window reads, four `constrain` calls and a min/max clamp per output sample. The kernel does the same arithmetic 16 samples (two rows) at a time in 16-bit AVX2 lanes -- the same primary/secondary taps, the same `sign(diff) * clamp(threshold - (|diff| >> shift), 0, |diff|)` (one `_mm256_sign_epi16` reproduces `signum`, zero included), the same exclusion of the `CDEF_VERY_LARGE` out-of-frame sentinel from the max clamp (masking it to 0 cannot win a max seeded with a non-negative sample), and the same `x + ((8 + sum - (sum < 0)) >> 4)` rounding. 16-bit lanes are exact for every value the filter sees: window samples are in [0, 0x4000], so a tap difference fits in `i16` and the tap-weighted sum is bounded by 24 * the threshold (at most 15 << 4). The scalar form stays the reference (`cdef_filter_block_scalar`, the only path on non-x86_64 and pre-AVX2 CPUs) and `cdef_simd_kernel_matches_the_scalar_filter` pins the pair over the whole domain: both block shapes, all 8 directions, every enable pair, the 8/10/12-bit strength/damping ranges and windows that mix real samples with sentinel borders. Byte-exact on all four gate inputs (seg1080, seg4k, seg4k_lr, palette). seg4k interleaved medians 3x: 47.08 s -> 41.23 s (-12.4%, 5.78 -> 6.60 fps); 1080p 11.00 -> 10.95 s.
Merge branch 'lane-perf6' (d14a4132): per-pixel env lookups removed from loop restoration, CDEF gathered window and resolved damping shift, pooled per-frame plane buffers, deblock bit-depth hoist, separable sgrproj box sums; byte-exact on four inputs, 4K 1.29xAhmet Kaan Gümüş · fb5fc2eBrowse files
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): resolve the deblock kernels' bit-depth reads once per callAhmet Kaan Gümüş · 801fe73
perf(av1): resolve the deblock kernels' bit-depth reads once per call `filter4` runs once per deblocked sample and read the thread-local bit depth nine times doing it -- once for its centring constant and once inside each of `sclamp`'s eight calls -- while `filter_edge` re-read it through `sample_max()` on all fifteen of its stores. Both are constant for the whole call; same bounds, read once. Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 60.53 s -> 48.33 s (1.252x, from 1.221x at the previous step), 1080p 10.74 s.
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): CDEF filters a gathered window with a resolved damping shiftAhmet Kaan Gümüş · 126001f
perf(av1): CDEF filters a gathered window with a resolved damping shift Every tap read went through a closure that re-derived the frame-bounds test (four compares plus the stride multiply) for each of a pixel's ~17 reads, and `constrain` recomputed its damping shift -- a `leading_zeros` and a branch -- twice per tap. `cdef_gather` now lifts a unit's whole footprint (its samples plus the two-pixel `CDEF_DIRECTIONS` ring) into a reused scratch window once, contiguously for the interior case, and both the direction search and `cdef_filter_block` index that; the shift is resolved once per block by `cdef_constrain_shift`. A unit whose four strengths are all zero now skips the gather and the direction search outright -- `dir`/`var` are only ever consumed through a strength. Byte-exact on seg1080/seg4k/seg4k_lr/palette; 4K 59.40 s -> 51.37 s against the same-session base (interleaved medians of 3, 1.156x vs the previous step's 1.140x), 1080p 10.72 s.
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.
Merge branch 'lane-perf5' (037ed4f1): AVX2/SSE4.1 kernels for the MC vertical/horizontal passes and film-grain luma with runtime dispatch and scalar reference; ec-av1 moves from forbid to deny(unsafe_code) with six allow sites; byte-exact, 1080p -5.5%Ahmet Kaan Gümüş · 4256150Browse files
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.
Merge branch 'lane-perf4' (486d8fd8): loop-restoration source planes cloned only when LR is active, intra DC sums the edge without materialising it, film-grain chroma and MC reconstruction on row slices; byte-exact, 4K 64.9 s to 58.4 s (conflict with r29's superres LR tail resolved: the optional deblocked planes are upscaled when present)Ahmet Kaan Gümüş · ea4deedBrowse files
perf(av1): inter reconstruction adds a row at a timeAhmet Kaan Gümüş · 180e079
perf(av1): inter reconstruction adds a row at a time `PlaneBuf::reconstruct_mc_rect` re-derived `row * side + col` twice and `(y + row) * self.width + x + col` once per sample, with a bounds check on each of the three buffers. `side` is the prediction/residual stride and `self.width` the plane's, so the three row bases are now taken once per row and the row slices zipped; the arithmetic on each sample (`clamp(0, sample_max())`) is untouched, as is the bottom/right overhang truncation above it. Byte-exact: EC_PROBE_OUT16 sha256 unchanged on a 1080p and a 4K segment and on `palette_screen_witness.obu`. Interleaved medians against the parent build alone (3 pairs, 1080p): 11.17 s -> 11.06 s.
perf(av1): film grain chroma noise walks contiguous rowsAhmet Kaan Gümüş · 8567ed5
perf(av1): film grain chroma noise walks contiguous rows `add_noise_to_block`'s chroma half recomputed `(ly * y_stride + lx)`, `(cy0 + i) * c_stride + (cx0 + j)` and the grain index per sample, and indexed four planes with a bounds check each time. Every one of those operands is contiguous along a row, so the loop now slices one row of luma, U, V and both grain planes per `i` and zips them: the 4:2:0 average (spec 7.18.3.5) is exactly `chunks_exact(2)` over the block's own luma row, `(l[0] + l[1] + 1) >> 1` as before. The whole loop is skipped when neither chroma plane takes noise. Byte-exact: EC_PROBE_OUT16 sha256 unchanged on a 1080p and a 4K segment and on `palette_screen_witness.obu`. Interleaved medians vs the tip before this lane (3 pairs 1080p, one pair 4K): 11.96 s -> 11.39 s at 1080p, 60.71 s -> 58.87 s at 4K.
perf(av1): intra DC edge extension without allocation; pre-CDEF planes cloned only when loop restoration runsAhmet Kaan Gümüş · bea828c
perf(av1): intra DC edge extension without allocation; pre-CDEF planes cloned only when loop restoration runs Two allocation sites the 1080p profile put at ~1.3% of self time between them, neither of which any pixel depends on: * `intra::dc` built one `Vec<u16>` per existing edge per intra block only to sum it. The replication libaom's `build_intra_predictors` performs is never indexed here, so the extended edge becomes a sum: `sum(samples[..n]) + last * (want - n)`, the same integers in the same order of magnitude, and the square/rect divisors come from `bw`/`bh` directly rather than from the (equal) vector lengths. * Both frame paths cloned all three planes before CDEF as the loop restoration source, and `apply_loop_restoration_plane` then copied each plane again to return it unchanged when its restoration type is `None`. The clone is now taken only when some plane's type is not `None` with a non-zero unit size, i.e. exactly when a restored sample can differ. Byte-exact: EC_PROBE_OUT16 sha256 unchanged on a 1080p and a 4K segment and on `palette_screen_witness.obu`. Interleaved medians (3 pairs 1080p, one pair 4K): 11.82 s -> 11.65 s at 1080p, 64.91 s -> 60.86 s at 4K.
Merge branch 'lane-t900' (b57adfd8): superres upscale moved between CDEF and loop restoration (spec 7.16); LR grid, unit corners and stripe boundaries in upscaled coordinates; superres key frame with CDEF+LR gated byte-exactAhmet Kaan Gümüş · cdcd10cBrowse files
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.