forge
Explore
Log in

Don't you dare go Hollow

Commits

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

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-06

perf(av1): the filter stage's capture decode replaced by one more filter replayAhmet Kaan Gümüş · 2d19659
perf(av1): the filter stage's capture decode replaced by one more filter replay

The stage decoded the coded tile a SECOND time after the search -- 10% of a
4K frame's encode -- only to reach the post-CDEF plane the loop restoration
search reads and the picture the stage splices back. Both come out of one
more replay of the winning deblock/CDEF parameters on the pre-filter planes
the search already captured: the same two kernels, on the same input, in the
same order. The re-coded tile still carries the cdef_idx literals, which the
replay is handed directly.

Also gates the per-trial stage timers on par::stage_times: two Instant::now()
ran per transform trial and per mc::predict call in every cfg(test) build
whether or not anyone read the breakdown.
perf(av1): band the encoder's frame-level filter stage across the tile workersAhmet Kaan Gümüş · 996b587
perf(av1): band the encoder's frame-level filter stage across the tile workers

The per-tile search leaves every core idle for the rest of the frame. The
filter stage now bands itself across the same workers:
`par::override_filter_threads` (thread-local, so nothing outside this span
changes) puts the deblock and CDEF replays, the capture decode's own filter
chain and the loop-restoration passes on the decoder's existing band split,
the per-64 SSE gets a unit-row band of its own (`unit_sse_rows`, partial
u64 sums), and a candidate's ~6 MB plane copies come off a recycled buffer
pool -- a fresh Vec per copy was 12.6% of a 1080p frame's wall in page
faults alone -- banded when the buffer is already the right length.

Gated by `filter_stage_bytes_do_not_depend_on_the_thread_count` (one tile,
a cropping size, 1 vs 2/4/8 threads) and by `unit_sse_matches_the_naive_sum`
at 2/4/8 bands.
perf(av1): the filter search's replay now covers cropped framesAhmet Kaan Gümüş · 8a4a771
perf(av1): the filter search's replay now covers cropped frames

The encoder scores ~30 deblock/CDEF candidates per frame by replaying the
loop filters on one captured reconstruction (`decode::FilterReplay`), but
the capture demanded `frame == plane` dimensions -- and no export size meets
that: 1080 and 1608 both pad to a superblock row. Every candidate at those
sizes fell through to a full re-decode of the frame, which the new per-stage
breakdown measures at 57% of a 1080p frame's wall.

The capture now also fires on a cropped frame and the replay finishes with
the decoder's own cropped return path (crop + wide-margin stash), so it is
still exactly the decode it stands in for.

1920x1080, 8 frames, 4x2 tiles, 8 tile threads: 6.75s -> 2.63s (1.19 ->
3.05 fps); filter search 57.2% -> 27.6% of wall.

Adds `par::timer`/`EC_AV1_STAGE_TIMES` (off by default: one relaxed atomic
load per stage per frame) and `encoder::tests::filter_stage_wall_*`, plus
`filter_replay_codes_the_same_stream_as_a_full_decode` at a cropping size.
feat(av1): a frame's tiles are written in parallel on the crate's own poolAhmet Kaan Gümüş · 1878642
feat(av1): a frame's tiles are written in parallel on the crate's own pool

EC_AV1_TILE_THREADS workers (default 1) take bands of the frame's tiles;
each tile is written from the frame's own starting tables into its own slot,
so the bytes never depend on the thread count -- pinned by
tile_bytes_do_not_depend_on_the_thread_count at 2x1/1x2/2x2/4x2.

2026-09-05

test(av1): pin the worker pool's thread count across repeated decodesAhmet Kaan Gümüş · 44460db
test(av1): pin the worker pool's thread count across repeated decodes

Two threaded decodes of one stream at 4 frame / 4 filter / 2 recon
threads: the pool stays inside the composed setting and the second
decode adds no thread. The nested-pool shape this replaces had no bound
at all.
perf(av1): one pool per job tree and a shared capped plane-scratch poolAhmet Kaan Gümüş · 2636658
perf(av1): one pool per job tree and a shared capped plane-scratch pool

A filter band job opened a sub-pool on the worker running it, one level
per pipeline stage, and no pool ever shrank: 1038 threads at
(16,4,2). A job now submits back into the pool it is running on
(`ON_POOL`), so the thread count is the peak of `busy + queued` over the
whole job tree. `Pool`'s handles moved behind the queue lock because the
thread that grows the pool is now whichever one submits.

The whole-plane scratch pool was per thread while its buffers are not:
the frame thread allocates the snapshots and a filter worker returns
them, so ~19 MB a set leaked into every worker the decode touched. One
process-wide pool, best-fit by capacity, hard-capped at 32 buffers.

4K peak RSS 9.33 GB -> 4.07 GB, peak threads 1053 -> 59, instructions:u
+0.10% and page faults -30% on seg4k at (16,4,2).
perf(av1): run the loop filters per superblock row, pipelined behind reconstructionAhmet Kaan Gümüş · 7fd0e67
perf(av1): run the loop filters per superblock row, pipelined behind reconstruction

The frame's filters used to run only once the whole tile was parsed and
reconstructed: the tile loop ended, the wavefront drained, and then
apply_deblock / plane_snapshot / apply_cdef walked the whole picture on the
frame thread. With ~2.5 frames in flight the wall tracks that frame thread's
own latency, and the whole-frame filter stage is ~19% of it. dav1d and libaom
instead run the filters a few superblock rows behind reconstruction, so the
filter work overlaps the parse.

DEPENDENCY SHAPE (a band = 64 luma rows = one superblock row; derived from
this decoder's own whole-frame order: all vertical deblock edges, then all
horizontal ones, then CDEF, then superres, then loop restoration):

  * intra prediction of band r+1 reads the UNFILTERED bottom rows of band r,
    so no filter may touch band r until band r+1 is fully reconstructed:
    V(r) waits for ready >= r+2.
  * the horizontal edge at y = r*64 reads and writes 6-7 rows either side of
    the band boundary, so H(r-1)'s last edge reaches into band r, which the
    whole-frame order has already vertical-filtered. Running V(r) before
    H(r-1) reproduces that exactly.
  * band j's own bottom rows are still rewritten by H(j+1)'s first edge, so
    j's post-deblock snapshot may only be taken after H(j+1).
  * CDEF(j) reads the post-deblock picture 2-3 rows across its 64x64
    boundaries, i.e. bands j-1..j+1, so it runs after snap(j+1).

Iteration k therefore runs V(k), H(k-1), snap(k-2), CDEF(k-3), on the filter
pool, released by the frame thread at every superblock row start from the
wavefront's own per-row completion (WaveQueue now tracks the last column
parsed and the last job pushed per row, so a row that recorded no write still
counts as complete). Rows still pending at the end of the tile loop are
drained there; loop restoration, the superres upscale, motion field and grain
stay in the frame thread's tail, and LR reads the snapshot the pipeline built
band by band (whole rows when CDEF is on, else only the four rows per stripe
boundary plane_snapshot copied).

Kept whole-frame, and counted (EC_AV1_WAVE_STATS prints pipe=<pipelined>/<frames>):
superres frames (a whole-plane resample between CDEF and LR), segmentation
(the deblocker reads seg_ids while the parse thread is still filling it),
delta_lf, more than one tile COLUMN, every pixel-dump/stage-skip debug flag,
and the (1,1) thread setting -- where the filters would move to a worker
thread for nothing and the crate's thread_local gate counters would miss them.
EC_AV1_PIPE_FILTERS=0 forces the whole-frame path. Key frames keep it too:
only the inter tile decoder is wired.

Byte-exact: the 12-hash gate at 4 and at 16/(4,2) reproduces every reference
hash; seg4k reports pipe=272/272.
refactor(av1): name the pool worker threads by submitting class; drop two dead recordersAhmet Kaan Gümüş · 9a4d798
refactor(av1): name the pool worker threads by submitting class; drop two dead recorders

The persistent pool is thread-local and shared by every class a thread
submits, so a worker's name is the class that grew the pool for it:
`ec-av1-frame` (stream.rs), `ec-av1-recon` (the tile wavefront) and
`ec-av1-filter` (par::run_bands), plus its index. The test-only ffmpeg
and aomenc stdin writers in decode.rs/stream.rs get names too.

Also deletes `push_intra_owned`/`push_mc_rect_owned`, dead since the
wavefront lanes, and replaces a `drop` of a `Copy` `Shared` in
film_grain.rs with `let _ =`, which was the last ec-av1 warning.

Byte-exact: the four perf6 inputs hash unchanged at default and at
(6,2,4) threads.
perf(av1): persistent worker pools instead of per-frame and per-tile threadsAhmet Kaan Gümüş · a02c7bd
perf(av1): persistent worker pools instead of per-frame and per-tile threads

Every threaded stage spawned its threads per unit of work: one
`thread::scope` per filter stage per frame, `EC_AV1_RECON_THREADS`
workers per tile, one frame worker per coded frame -- 2363 distinct
threads in a 13 s 4K decode. What died with each of them was the
`thread_local!` decode scratch (planes, rows, dq, mc, wiener, sgr),
re-allocated and re-faulted on every new thread.

`par::Batch` submits jobs to a pool owned by the submitting thread
(thread-local, joined at thread exit), growing to `busy + queued` so a
job never queues behind a blocking one -- the recon wavefront's workers
block on their own dependencies. `Batch`'s drop waits every job out and
re-raises the first panic, which is `thread::scope`'s contract minus the
spawns, so the three call sites keep their borrows.

Byte-exact: all 12 sha6t hashes at (frame, filter, recon) = (1,1,1),
(6,2,4) and (1,1,4). seg4k (6,2,4) best-of-2 interleaved: 13.02 s -> 12.24 s.
perf(av1): recorded writes run inline at one reconstruction threadAhmet Kaan Gümüş · 9258b06
perf(av1): recorded writes run inline at one reconstruction thread

lane-wave1 step (ii), first half. Step (i) deferred every recorded
`ReconOp` to the end of its superblock, which cost +1.2% instructions and
+4.5% wall on 4K: the residual is written at parse and read back
cache-cold at replay.

`EC_AV1_RECON_THREADS` (default 1) now decides. At 1 the tile decoder
registers its three planes (`ReconInline`, dropped on every exit from the
tile including `?`) and every `push_*` performs its write on the spot,
with the residual still borrowed -- no record built, no queue, no
`to_vec`. Above 1 the queue behaves exactly as step (i) left it, for the
wavefront workers to come.

Measured against 69e1e50e, interleaved, same box: seg4k 607.12 -> 603.33 G
instructions:u (-0.62%), seg1080 189.81 -> 188.83 G (-0.52%); wall inside
the run-to-run noise on both (seg4k 30.5 vs 30.0-30.9 s, seg1080 9.2 vs
9.1-9.7 s). sha6 byte-exact on seg1080/seg4k/seg4k_lr/palette.

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`.