forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on cbbd6e2ef6acafb00aeb55e460423f024126f90fFiltered to crates/ec-av1/src/stream.rsClear filter

2026-09-06

merge main 1c844b01 (tile layout) into the palette laneAhmet Kaan Gümüş · eeee023
merge main 1c844b01 (tile layout) into the palette lane

Hand-resolved: the palette write sits inside the per-tile closures main's
TileLayout introduced, so `arm_screen` is armed per tile job beside
`arm_sign_bias`/`arm_reference_select`; the new plural
`decode_inter_frame_tiles_lr` takes this lane's `allow_screen_content_tools`
and the single-tile wrapper forwards it.
feat(av1): screen-content detection sets allow_screen_content_tools on a key frameAhmet Kaan Gümüş · 3136cbe
feat(av1): screen-content detection sets allow_screen_content_tools on a key frame

libaom's `av1_set_screen_content_options` shape (distinct colours per 16x16
luma block, blocks with 2..=4 of them covering more than a tenth of the
frame), run on the source luma before any header is built. When it fires the
sequence header carries the SELECT form of
`seq_force_screen_content_tools` and the key frame sets its own
`allow_screen_content_tools`; every intra block of that tile then codes the
two `read_palette_mode_info` flags (spec 5.11.46), both at ctx 0 and both
"no palette" -- the syntax a palette block will fire inside next.

A sequence with no screen content leaves the sequence bit at 0 and writes
exactly the stream it wrote before: the byte pins do not move.

Verified with the detector forced on (EC_AV1_SCREEN=1):
ffmpeg_decodes_exactly_what_the_encoder_reconstructed and
every_frame_of_a_sequence_decodes_through_our_own_decoder both pass, so the
new symbols are the ones libaom reads.
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.
Merge branch 'main' (d5fc99e0) into lane-av1lrAhmet Kaan Gümüş · 8e2799a
Merge branch 'main' (d5fc99e0) into lane-av1lr

Nine hunks across three files, all taken both ways.

tile.rs: that lane split each writer into a `_tx` wrapper and a
`_cdfs` worker, so this lane's arm/clear guard moves down into the
worker, where the symbols are actually written.

decode.rs: `decode_inter_frame_tile_lr` now takes `initial_cdfs`
alongside `lr` and both wrappers thread it; the two chained-decode
tests pass this frame's own `loop_restoration` AND its `start_cdfs`.

encode.rs: the tile is written through the CDF-carrying writer, and
this lane's re-codes (for the `cdef_idx` literals and the per-unit
restoration syntax) each restart from the frame's OWN `start_cdfs`
rather than from where the first write left them -- the second tile is
the first tile's symbol sequence plus new ones, so it has to adapt from
the same point the decoder will. The winning re-code publishes its
end-of-tile tables into `next_cdfs`, which is what the next frame's
writer starts from; the first write's would have been stale.

Byte pins re-measured on the merged tree: q=150 7416 -> 7458 bytes,
q=60 27927 -> 27807.
test(av1): the hand-built GOLDEN fixture keeps its frames' CDF carry offAhmet Kaan Gümüş · 4db0da1
test(av1): the hand-built GOLDEN fixture keeps its frames' CDF carry off

Its two inter tiles are hand-coded from a fresh Cdfs, so their headers
must say so now that inter_frame_headers leaves
disable_frame_end_update_cdf off -- otherwise frame 2's decode loads what
frame 1 stored and desyncs at the first symbol. Swept the crate: the only
other hand-built inter headers (frame.rs' header round trip) code no tile.
feat(av1): encoder enables CDEF and searches its strengths (cdef_bits = 0)Ahmet Kaan Gümüş · df76271
feat(av1): encoder enables CDEF and searches its strengths (cdef_bits = 0)

The sequence header now sets enable_cdef and every frame header carries one
strength pair per plane type, chosen by the same re-decode search as the
deblocking levels -- cdef_bits = 0 means no cdef_idx literal is read in the
tile, so this costs no tile-writer change. Encoded carries the chosen
CdefParams and the tests that decode Encoded::tile take them from there.

BD-rate vs libaom 198.2/218.1/136.9 -> 143.6/179.5/88.0 (1080p/2160p/screen),
vs rav1e 143.1/162.4/52.7 -> 94.0/128.8/21.5.
feat(av1): encoder picks per-frame deblocking levels by re-decoding its own tileAhmet Kaan Gümüş · 873a1fb
feat(av1): encoder picks per-frame deblocking levels by re-decoding its own tile

The encoder runs no loop filter of its own: filter_search hands the coded
tile back to this crate's decoder under each candidate loop_filter_level and
keeps the winning picture as the reconstruction, so the reference frame stays
identical to what a decoder produces. Encoded now carries the chosen
LoopFilterParams and every test that decodes Encoded::tile takes them from
there (class: test asserts against a stale header).
fix(av1): a key frame test decoded its own tile as TxMode::LargestAhmet Kaan Gümüş · 787a14a
fix(av1): a key frame test decoded its own tile as TxMode::Largest

The nine failing gates fed decode_key_frame_tile a hardcoded tx_select =
false while the encoder had moved its key frame header to
TxMode::Select, so the decoder missed the first block tx_depth symbol
and desynced at pixel (0,0). Encoded now carries the header bit and the
encoder-driven decode sites pass it along.
test(av1): the bounded-pool test allows a small load-dependent growth between decodes (pool grows to busy+queued; 9 -> 10 seen at load 62), keeps the structural boundAhmet Kaan Gümüş · d552955
test(av1): the bounded-pool test allows a small load-dependent growth between decodes (pool grows to busy+queued; 9 -> 10 seen at load 62), keeps the structural bound

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): two-stage publication on by defaultAhmet Kaan Gümüş · 30b0391
perf(av1): two-stage publication on by default

With the sub-8x8 group predictions deferred, no parse thread reads a
reference pixel at all (instrumented: zero `ref_planes` calls on the
decode threads over both gate segments at 16 threads / 4 filter / 2
recon), so a consumer frame parses its WHOLE tile over its producer's
filter tail instead of the 4.2% that made this flag a wash before.

4K critical chain, interleaved pairs at (16,4,2): off 14450 / 10594 /
14407 ms vs on 12790 / 9207 / 12463 ms -- 11-14% shorter, three pairs
out of three, with wall agreeing (15.74/11.35/15.69 s vs
13.93/10.76/13.92 s). The same interleaving on the pre-lane-sub8group
binary moves 3-7%, so most of the margin is the deferral.

`EC_AV1_TWO_STAGE=0` restores the old publication point. Byte-exact:
the four gate streams at 1, 4, 16(4,2) and 16(3,1) threads with the new
default and at 16(4,2) with the flag forced off, plus six film cuts
base vs new at 16(4,2).
perf(av1): two-stage reference promises default OFF -- byte-exact, but the overlap is too short to payAhmet Kaan Gümüş · 4231093
perf(av1): two-stage reference promises default OFF -- byte-exact, but the overlap is too short to pay

Measured, not assumed. An inter tile parses 4.2% of its own length before its
first `ref_planes` call (seg4k, 272 frames, 16/4/2, instrumented first-touch
timer) because the 8x8-leaf, OBMC and sub-8x8-piece predictions build INLINE
on the parse thread -- only the 16x16-and-bigger blocks go to a recon worker.
So a consumer overlaps ~3 ms of its parse plus its 1.2 ms setup with a
producer tail of ~7 ms per chain frame. The chain report shows exactly that:
the segments now sum to 108% of the chain instead of 101% (the tail IS
overlapped), while the chain itself is unchanged (5621.7 ms vs 5547.2 ms) and
the wall does not move (seg4k at (16,4,2): base 5143/5337/5350 ms vs
5244/5738 ms; at (6,1,1): base 10498/10635/11232 vs 10128/10309/11747).

The machinery stays -- it is byte-exact on all four gate configs and the six
film cuts, and it is the half of the lever that is hard to build. It pays
once the 8x8-leaf/OBMC/sub-8x8 predictions are deferred to the recon workers
too; until then `EC_AV1_TWO_STAGE=1` enables it and the default publishes a
frame's meta after its filters, as before.
perf(av1): two-stage reference promises -- meta at the tile boundary, pixels after the filtersAhmet Kaan Gümüş · b8ec726
perf(av1): two-stage reference promises -- meta at the tile boundary, pixels after the filters

A consumer frame used to wait for its references' FILTERED pixels before it
could start: the tile decoder built the reference `PlaneBuf`s at frame entry,
so the borrow existed from the first block even though the first pixel READ
comes later. Measured on a 4K stream (272 frames, 16/4/2): an inter tile
parses 4.2% of its own length before its first `ref_planes` call, and the
producer tail a consumer waits through (recon tail + filters + publish) is
8.2% of the decode chain.

So a reference slot is published in two stages. Stage 1 -- end-of-tile CDFs
(spec 7.20's `save_cdfs`, shared with the frame's own slot store), segment
map, motion field and picture size -- is fulfilled the moment the last tile
symbol is read, before the filters run; the motion field moves up with it
(it is built from the mode-info grid, no pixel). Stage 2 is the filtered
picture, fulfilled where the single promise was fulfilled before. A consumer
waits stage 1 for setup and carries a `RefPix` handle into the tile decoder,
which serves reference SIZES (`mc::scale_factor`) from stage-1 metadata and
waits stage 2 at the first `ref_planes` call.

DEADLOCK: unchanged in shape. Both stages of a producer are fulfilled by the
producer itself and wait on nothing but its own decode; every wait still
points from a later coded frame to an earlier one, so the wait graph is the
reference DAG. A failing frame now fails BOTH promises.

`EC_AV1_TWO_STAGE=0` restores the old publish point (meta after the filters).
feat(av1): EC_AV1_TIMELINE -- per-frame decode timeline + critical-path reportAhmet Kaan Gümüş · 9cdd364
feat(av1): EC_AV1_TIMELINE -- per-frame decode timeline + critical-path report

Two lanes pipelined the loop filters per superblock row and recovered 2.3%
wall although the filters were 19% of frame-thread time; nobody had measured
the actual critical path. `EC_AV1_TIMELINE=1` records ~10 timestamps per
coded frame on one monotonic clock -- submit, worker start, each reference
slot wait (with the producing frame, so the DAG has real edges), header
setup, tile parse, wavefront drain, filters, slot publish, grain, output --
plus every block of the dispatcher at the in-flight bound, and dumps them as
TSV at stream end. `scripts/av1-timeline-report.py` reports phase medians,
the reference waits, the work-weighted critical path through the DAG,
concurrency at 10 ms ticks (in-flight vs actually RUNNING) and the cap waits.

Measured at (16,4,2) on the 4K segment, 3 runs: wall 5.44 s, of which the
measured dependency chain is 4.96 s = 91%, and 90.8% of that chain is parse.
Only 2.9 frames are runnable at any instant while 18 are in flight, so the
dispatcher cap is never the bound (48 threads on the 1080p cut: 4.0 running,
no wall gain). The filters are 5.0% of the chain -- which is exactly the
2.3% the pipelining lanes could recover.

Off, this is one `LazyLock<bool>` load per event at frame granularity: eight
gate hashes byte-identical at 1 and 16 threads, instructions:u +0.056%
(gate 0.05%, wall -0.5%).
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): the reference bank and the output queue share the pictureAhmet Kaan Gümüş · 900cf2d
perf(av1): the reference bank and the output queue share the picture

A decoded frame's picture was copied once per reference slot it
refreshes and once more to leave the worker (`Arc::try_unwrap` never
succeeded -- the slot promise holds the other handle), 24 MB per copy at
4K 10-bit. `ref_slots`, `Reorder` and the worker reply now carry
`Arc<Picture>`: the sink still takes `&Picture`, so no public signature
moves, and grain (which must not be stored in the bank) still allocates
its own output.

seg4k, all 12 sha6t hashes unchanged at (1,1,1), (6,2,4), (1,1,4).
Single thread: 30.39 s -> 29.71 s, page faults 397 k -> 111 k,
instructions:u 599.40 -> 600.57 G (+0.20%). Composed (6,2,4) best-of-2
interleaved: 12.58 s base -> 12.08 s, page faults 3.77 M -> 0.85 M.
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): reconstruction on a superblock-row wavefront (EC_AV1_RECON_THREADS)Ahmet Kaan Gümüş · f7306dd
perf(av1): reconstruction on a superblock-row wavefront (EC_AV1_RECON_THREADS)

lane-wave1 step (ii). Above one reconstruction thread the parser keeps
parsing and never writes the planes: each superblock's drained
`Vec<ReconOp>` becomes one job (one per 128x128 superblock when `sb128`,
since a 128 block writes across its four 64x64 visits), and N scoped-per-
tile workers reconstruct them in wavefront order -- job `(r, c)` starts
once `(r - 1, min(c + 1, last_col))` and `(r, c - 1)` are complete, which
covers every pixel an intra predictor can reach and every CfL AC read.
Jobs are handed out in raster order, so the oldest outstanding one always
has its dependencies met; a `WaveGuard` joins every worker on each exit
from the tile decoder, including the `?` ones.

The two parse-time pixel READS (the intrabc source fetch, the interintra
intra predictor) keep their `flush_recon`, which now waits the wavefront
out first and replays the current superblock inline -- so an intrabc block
serialises the tile at that point instead of trusting the spec's 256-px
delay against our lag, and stays byte-exact.

MEASURED and it does not pay: seg4k 31.8 s at (frame, filter, recon) =
(1,1,1) vs 31.9 s at (1,1,4) with CPU 99% -> 117%, seg1080 9.4 -> 9.9 s;
with frame threading it is a loss (seg4k 13.5 s at (6,2,1) vs 14.5 s at
(6,2,4)). Recording the ops copies the residual and the MC prediction on
the PARSE thread, which cancels what the workers take off it. Default
stays 1 (inline), where nothing is recorded at all.

Byte-exact: sha6 on seg1080/seg4k/seg4k_lr/palette at recon 1, at recon 4,
and at EC_AV1_THREADS=6 EC_AV1_FILTER_THREADS=2 EC_AV1_RECON_THREADS=4;
new gate `a_real_stream_reconstructs_identically_with_one_and_four_recon_threads`
on reelb_arf_witness (hidden ARF, 10-bit) and both palette/intrabc screen
witnesses.

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`.
test(av1): two gate counters incremented and never read now report and assertAhmet Kaan Gümüş · 9c001a3
test(av1): two gate counters incremented and never read now report and assert

class [[gate-blind-to-feature]], two instances in stream.rs `mod tests`:

- the 16x16 1:4-partition gate's `rect_residual_refusals` counted attempts
  stopping on "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs
  rectangular residual coding" and never printed or asserted it. The refusal
  string still exists in decode.rs but is narrowed past this shape: the sweep
  now reaches it ZERO times at either depth (attempt 1, the recipe r5
  recorded stopping there, decodes). Reported in the summary and pinned at 0.

- the superres census's `other` was incremented and then panicked on in the
  same arm, so the CENSUS line -- the gate's whole output -- never printed
  when an unknown refusal fired. Unknown strings are collected instead,
  counted in the summary, and asserted empty after it.
perf(av1): a show_existing_frame output no longer stalls the parsing threadAhmet Kaan Gümüş · fada71e
perf(av1): a show_existing_frame output no longer stalls the parsing thread

The parser waited for the named slot's promise before emitting the picture,
and that wait was where the whole decode went: 7.9 s of an 8.8 s 1080p decode
and 18.9 s of a 23.3 s 4K one, measured with a counter around the wait. A
stalled parser dispatches nothing, so every worker drained behind it.

The output job now runs on a worker too (wait for the slot, synthesise grain,
send): the parser only copies the promise into the slots the header refreshes,
which needs no value at all. The wait still points at an earlier coded frame,
so the deadlock argument at `SlotPromise` is unchanged.

Frame decodes and output jobs are bounded separately (`threads + 2` each): an
output job is a wait plus a memcpy, so letting it hold a decode's budget just
idles a core (4K 18.7 s at 244% CPU sharing one bound, 17.7 s at 287% not).

seg4k 272 frames: 35.7 s at 1 thread -> 18.7 s at 4 (was 24.2 s before this
commit); seg1080 299 frames: 10.5 s -> 8.0 s (was 9.4 s). All twelve gate
hashes unchanged at 1, 2 and 4 threads.
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.
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.
feat(av1): dependency-aware frame scheduling -- every non-key frame decodes on a workerAhmet Kaan Gümüş · fcddd9c
feat(av1): dependency-aware frame scheduling -- every non-key frame decodes on a worker

lane-thread2 could only dispatch LEAVES of the reference graph (shown,
non-key, refresh_frame_flags == 0), which on an aomenc pyramid stream is
almost nothing: seg1080 has 1 dispatchable frame in 299.

Each of the 8 reference slots now holds a `SlotPromise` instead of a value
when `threads > 1`: the parsing thread installs a frame's promise into every
slot its `refresh_frame_flags` names at DISPATCH time, in decode order, so
the next frame's dependencies are known without waiting for the previous one
to finish. A worker waits on exactly the promises of the slots its frame
reads (its `ref_frame_idx` entries -- references, primary CDFs, previous
segment map, reference order hints and spec 7.9's motion-field projection all
come from those), then decodes, publishes its clean picture/CDFs/motion
field/segment map, and only then synthesises film grain.

`setup_motion_field` therefore runs on the DECODING thread, inside
`RefSnapshot::take`, after those waits (it takes borrowed slots now, so no
motion field is copied to hand it over).

Deadlock argument, spelled out at `SlotPromise`: every wait points from a
later coded frame to an earlier one, so the wait graph is the reference DAG;
the parsing thread waits only for a `show_existing_frame` output and at the
in-flight bound (threads + 2), where the earliest in-flight frame always has
its producers already finished. A frame that errors or panics marks its
promise Failed, so no consumer waits for a value that never arrives.

Key frames and `show_existing_frame` headers stay inline. `threads == 1` is
untouched: no promise is ever created and the owned bank is the same one.

`leaf_frames_dispatched` -> `frames_dispatched`. The 1-vs-4-thread gate now
dispatches 39 of reelb_arf_witness's 40 coded frames (was 18) and 14 of
palette_screen_witness's 15 (was 0), and asserts more than half the shown
frames really ran on a worker.
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.
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.
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.
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.
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.
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.
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.
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.
test(av1): four more refusals proven -- empty ref slot, segmentation overrides, OBMC filter band, superres 8x8 leafAhmet Kaan Gümüş · baa89bd
test(av1): four more refusals proven -- empty ref slot, segmentation overrides, OBMC filter band, superres 8x8 leaf

Round 27 of the refusal-proving lane. 25 -> 29 proven of 40.

* "a reference frame selected with no picture at this frame's own
  ref_frame_idx slot for it": negative gate on `ref_planes` over all six
  non-LAST references. No stream-level witness exists with this crate's
  writers -- a shown key frame refreshes all eight slots and nothing
  clears one, and a stream opening on an inter frame is stopped one
  guard earlier ("an inter frame with no key frame before it"). The
  reachable premise is a HIDDEN key frame with a partial
  refresh_frame_flags, which write_frame_header cannot write; that is
  the open half, recorded in the inventory.
* "a frame whose segmentation enables SEG_LVL_REF_FRAME/SKIP/GLOBALMV":
  negative gate (written key frame, three features x three segment ids,
  refused by name with 0 pictures) plus a census of what aomenc emits.
  Measured: --aq-mode=1/2 and --deltaq-mode=1 reproduce the baseline
  stream byte for byte at this recipe (the flags change nothing);
  --aq-mode=3 does code segment_id symbols (133 at cq40, 444 at cq10)
  and never enables any of the three. No capability gap here.
* "an OBMC neighbour whose switchable interp filter was never recorded":
  structural audit -- record_inter_rect_mi is the band's single writer
  and no call site stamps the [3, 3] sentinel on an INTER cell (each
  site's arguments tokenised, never substring-matched) -- plus a witness
  gate on two real --enable-obmc --enable-dual-filter streams: 237 band
  reads over ~115 OBMC blocks each, refusal 0x. --cpu-used=0 is
  load-bearing: at speed 4 aomenc settles on a frame-level fixed filter
  and the band is never read (0 reads, measured).
* superres trio census, six real streams: the four fixed-denominator
  --superres-mode=1 encodes (denoms 10/12/16, warp + OBMC on) ALL stop
  at "an 8x8 partition leaf under a scaled reference", and the two
  --superres-mode=3 auto encodes pick denominator 8 and carry no scaling
  at all (0 scaled MC blocks). The warp and sub-8x8 scaled refusals
  never fire: the 8x8-leaf guard sits in front of them, so they stay
  unproven until that gap is lifted. All three are real capability gaps.
test(av1): four more refusals proven -- mi grid, ref height, primary_ref CDFs, intra modeAhmet Kaan Gümüş · 367c38e
test(av1): four more refusals proven -- mi grid, ref height, primary_ref CDFs, intra mode

Two enumerations and two negative gates, taking the inventory's numerator
from 21 to 25 of 40:

* "a frame with no mode-info grid": `compute_image_size` (spec 5.9.9) is
  zero only for a zero frame width/height, and no path that sets one can
  produce that -- `frame_size()` is `+1`-coded, `superres_params()`
  divides by 9..=16 with rounding (enumerated over the whole 16-bit
  upscaled domain, minimum 1), and `show_existing_frame` /
  `frame_size_with_refs` copy a slot. Swept per axis through the REAL
  header reader over every size this crate's writers can express.
* "a reference picture whose height does not match this frame's own true
  size": negative gate, a written 64x64 key frame followed by a 64x32
  inter frame (`frame_size_override_flag` with error resilience on, the
  one combination the writer expresses) -- refused by name, one picture
  out.
* "a frame naming primary_ref_frame at a reference slot with no saved CDF
  state": the picture and CDF slots are written by exactly two loops over
  the same refresh mask (enumerated from the source, so no slot holds a
  picture without CDFs), and the reachable case is a slot nothing has
  refreshed -- a stream opening on a non-error-resilient inter frame,
  gated at all eight slots. This refusal, not the missing-key-frame one,
  is what such a stream reaches: the CDF load happens in the header path.
* "an intra mode this decoder does not code (round 2)": all three guards
  refuse `mode >= 13` on a symbol read from the 13-symbol `y_mode` CDF;
  the test finds each site by the refusal in its own body, resolves the
  CDF the symbol came from, and fails if a wider alphabet (`uv_mode_cfl`
  is 14) ever feeds one.