forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on 8a4a771a4745f6ba758ee92b871a3dd35d4ef04e

2026-09-06

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.
Merge branch 'lane-av1tsearch' (52ab4845): the RD/motion search runs one job per tileAhmet Kaan Gümüş · fe25c8d
Merge branch 'lane-av1tsearch' (52ab4845): the RD/motion search runs one job per tile

1080p 4x2 at 8 threads 11.49 -> 6.98 s (1.04 -> 1.72 fps); 3840x1608 4x2
17.12 -> 8.64 s. Inter frames byte-identical at every layout; key frames
at multi-tile layouts now price modes against tile-local bands (what the
writer reads back). 1x1 unchanged. ~43% of an inter frame is outside the
tile search (frame-level filter search): that is the next serial wall.
Merge branch 'lane-av1pal' (0966e6d6): screen-content detection and luma palette coding on key and inter framesAhmet Kaan Gümüş · 93f25fe
Merge branch 'lane-av1pal' (0966e6d6): screen-content detection and luma palette coding on key and inter frames

Screen BD vs libaom +73.0 -> +66.4, vs rav1e +13.7 -> +10.3; both film
clips byte-identical (detector off there; libaom's 4-colour bound separates
nothing on real material, 32 colours over a third of the frame does).
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.
fix(av1): the GOP round-trip tests decode the key frame under its own screen flagAhmet Kaan Gümüş · 625e01e
fix(av1): the GOP round-trip tests decode the key frame under its own screen flag

Three decode::tests GOP tests handed `decode_key_frame_tile_lr` a hard-coded
`allow_screen_content_tools = false` while decoding an encoder-written tile
whose detector had fired (stale-header class, same shape as the
`reference_select` instance): frame 0's luma came back wrong.
perf(av1): the RD/motion search runs per tile, on the tile thread poolAhmet Kaan Gümüş · 8421ce2
perf(av1): the RD/motion search runs per tile, on the tile thread pool

The frame's superblock loop was one whole-frame pass in raster order even
when the frame carried a tile grid; only the entropy write was split
(lane-av1tiles), which is why tile threads bought nothing measurable.

Both search loops now run one job per tile through `search_tiles`, the
search-side counterpart of `write_tiles`: each job owns its own
reconstruction planes, its own `MiGrid`, its own neighbour-mode bands and
its own `FrameCtx`, and copies its rectangle back into the frame's planes
at the end. Availability was already tile-relative, so a tile reads
nothing another tile wrote.

Inter frames are byte-identical to the whole-frame loop at every layout.
Key frames change at MULTI-TILE layouts only: the mode-cost bands are now
tile-local, which is what the tile writer actually reads back (a tile
resets its neighbour contexts, spec 5.11.1) -- the old frame-scoped bands
let a block at a tile's left edge cost its mode against the tile to its
west. One tile is unchanged, and the byte pins hold.
feat(av1): palette on the intra blocks of inter frames tooAhmet Kaan Gümüş · 17922e6
feat(av1): palette on the intra blocks of inter frames too

The three intra arms of the inter-frame writers (32/16/8) now code the same
spec 5.11.46 syntax the key frame's does, through one shared
`write_palette_syntax`; the neighbour bands are published from
`record_mi_planes` -- the single point EVERY block of either frame type
passes through -- so an inter block clears what an earlier palette block left
in its column instead of desyncing the next context (the hazard lane-t900 r23
hit on the decoder side).

The inter frame sets `allow_screen_content_tools` from its own detection,
gated on the sequence having offered the bit at all (the key frame's
decision); `decode_inter_frame_tile_lr` takes the flag rather than assuming
false, and `Encoded::screen` carries it to every raw-tile decode.

The leaf (16/8) intra candidates get the palette RD for free -- they route
through `code_square`. The 32x32 inter search's own intra loop does NOT yet
offer one (corner-cut: its candidates are hand-rolled beside the inter ones).

Check: a_screen_content_picture_codes_palette_blocks_ffmpeg_decodes_exactly
now codes a 4-frame GOP as well -- 3 inter frames set the bit, 56 palette
blocks, ffmpeg reconstructs all four frames exactly in all three planes.
Merge branch 'lane-av1tiles' (d53ac525): multi-tile frames (uniform spacing, per-tile CDF/LR/neighbour reset) with deterministic parallel tile writesAhmet Kaan Gümüş · b58ff3f
Merge branch 'lane-av1tiles' (d53ac525): multi-tile frames (uniform spacing, per-tile CDF/LR/neighbour reset) with deterministic parallel tile writes

Sample-exact through our decoder and ffmpeg at 1x1/2x1/1x2/2x2/4x2; default
1x1 byte-identical. Root cause on the way: the writer's intra_inter/tx-size
contexts asked frame-relative availability (class: new map ignores tile
edge). Tile threads buy no wall yet: the search is still whole-frame.
merge: lane-av1tiles with main ac6e60b4 (compound prediction)Ahmet Kaan Gümüş · e6c05e0
merge: lane-av1tiles with main ac6e60b4 (compound prediction)

The per-tile jobs arm the compound lane's new thread-locals
(arm_reference_select / arm_order_hints) on their own workers.
test(av1): the intra-mode ablations force the palette offAhmet Kaan Gümüş · cf280e5
test(av1): the intra-mode ablations force the palette off

A two-colour synthetic picture is coded losslessly by the palette under every
arm of a mode ablation, so both ladders reach infinite PSNR and the ablation
measures nothing (three tests failed exactly that way). `force_screen` is a
per-thread override -- the suite runs in one process, so an environment
variable could not do it.
feat(av1): tune screen detection to the measured colour-count split, gate printsAhmet Kaan Gümüş · 55cb55e
feat(av1): tune screen detection to the measured colour-count split, gate prints

libaom's own bound (blocks with 2..=4 distinct colours over a tenth of the
frame) separates NOTHING on real material: `probe_screen_detect` measures the
share of 16x16 luma blocks under each bound on the gate's three clips and the
two populations only part at 32 colours -- film 20.3..21.9%, the OBS capture
51.1..51.5%. Defaults move to 32 colours over a third of the frame, both
still swept by EC_AV1_SCREEN_COLORS/EC_AV1_SCREEN_PCT.

The gate now prints, per clip, how many frames set
`allow_screen_content_tools`, how many blocks took a palette and of what size
(gate-blind-to-feature).

BD gate, 12 frames at 640x384 (vs libaom / vs rav1e), base -> now:
  1080p film   +121.2 / +71.8  -> unchanged, detector off, pins unmoved
  2160p film   +146.4 / +97.8  -> unchanged, detector off
  screen       +79.1  / +17.0  -> +74.9 / +14.2   (487 palette blocks)
wall ours 5.6 / 4.7 / 5.5 s against 5.1 / 4.7 / 5.4 s.
feat(av1): palette-coded luma intra blocks on a screen-content key frameAhmet Kaan Gümüş · f2eac79
feat(av1): palette-coded luma intra blocks on a screen-content key frame

The whole spec 5.11.46 chain, mirrored symbol for symbol from this crate's
own decoder: `palette_y_mode` off the real `av1_get_palette_mode_ctx`
neighbour bands, `palette_y_size`, the colours coded against the above/left
colour cache `av1_get_palette_cache` builds (`palette_ctx_and_cache`, the
decoder's own merge and dedup), and the colour-index map on
`decode_color_map_tokens`' wavefront diagonal with
`av1_get_palette_color_index_context`'s ordering.

The candidate palettes are libaom `av1_k_means`-shaped: a block with at most
8 distinct colours takes them all (exact prediction), a busier one is
quantised to 8 and to 4 by a histogram Lloyd iteration, and each is priced
through the very writers the tile uses (`palette_bits` on a
`SymbolEncoder::pricer`) against the mode the intra search already settled.

Check: encode::tests::a_screen_content_picture_codes_palette_blocks_ffmpeg_decodes_exactly
-- 48 palette blocks (sizes 2/3/4, 16 each) on a 192x96 screen card, ffmpeg
and our own decoder both reconstruct the encoder's picture exactly, and the
film-shaped test card leaves the detector off.
Merge branch 'lane-av1comp' (1300db86): compound reference prediction (NEAREST_NEAREST / GLOBAL_GLOBAL / NEW_NEW, LAST+GOLDEN and LAST+ALTREF) on by defaultAhmet Kaan Gümüş · 583d98d
Merge branch 'lane-av1comp' (1300db86): compound reference prediction (NEAREST_NEAREST / GLOBAL_GLOBAL / NEW_NEW, LAST+GOLDEN and LAST+ALTREF) on by default

BD vs libaom +120.1/+128.5/+73.0, vs rav1e +67.8/+86.0/+13.7 (all down
from 1dbd8f15); compound takes 8-14% of inter blocks. Two defects found on
the way: write_single_ref dropped a compound neighbour's second reference
from its context votes, and comp_group_idx/compound_idx must not be written
under a sequence that clears masked/jnt compound.
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.
test(av1): tile BD-cost knob for the gate and a 1080p tile/thread wall tableAhmet Kaan Gümüş · ebca9e8
test(av1): tile BD-cost knob for the gate and a 1080p tile/thread wall table

EC_AV1_TILES in a test build lets the BD gate code the same ladder under a
tile grid; the 1080p wall table shows tile threads buy nothing yet -- the
per-tile ENTROPY write is a few percent of the frame, the search is still
whole-frame and single-threaded.
feat(av1): compound reference on by default -- BD down on all three gate clipsAhmet Kaan Gümüş · e062d5b
feat(av1): compound reference on by default -- BD down on all three gate clips

Flat BD gate, same machine: vs libaom +121.2/+146.4/+79.1 -> +120.1/+128.5/+73.0
(1080p/2160p/screen), vs rav1e +71.8/+97.8/+17.0 -> +67.8/+86.0/+13.7, wall
6.5/5.6/6.2 s -> 7.5/6.4/6.4 s. Compound takes 8.1%/8.6%/13.8% of coded inter
blocks; modes NEAREST_NEAREST 1218/1439/1848, GLOBAL_GLOBAL 268/377/0, NEW_NEW
203/34/0; pairs LAST+GOLDEN 450/397/311, LAST+ALTREF 1239/1453/1537.

The three GOP round trips in decode.rs called decode_inter_frame_tile_lr with a
hard-coded reference_select = false while decoding a tile the ENCODER wrote
(stale-header class); they now pass the encoder's own bit. Byte pins updated.
Merge branch 'lane-av1fsearch' (0a6ed84e): filter search scores per unit in one chunked pass and replays CDEF candidates off cached deblocked planesAhmet Kaan Gümüş · 39035c8
Merge branch 'lane-av1fsearch' (0a6ed84e): filter search scores per unit in one chunked pass and replays CDEF candidates off cached deblocked planes

Byte-identical to 7f2ab3ea (FNV sets on the three gate clips, BD
unchanged); instructions -11.2%, ladder wall 5.34/4.91/7.06 -> 4.51/4.08/4.80 s.
The filter stage is 12.9% of the encode now (26.3% before).
feat(av1): compound-reference blocks -- comp_ref/compound_mode syntax and averaged two-reference predictionAhmet Kaan Gümüş · 3cac217
feat(av1): compound-reference blocks -- comp_ref/compound_mode syntax and averaged two-reference prediction

The tile writer now codes a COMPOUND_REFERENCE block: comp_mode = 1, the
comp_ref_type/uni_comp_ref/comp_ref/comp_bwdref pair tree, the
inter_compound_mode symbol at the compound MV stack's own context, and (for
NEW_NEWMV) the compound DRL walk plus both motion vectors -- mirrored symbol
for symbol from decode.rs read_compound_ref_frames /
read_inter_compound_mode / assign_compound_mv. comp_group_idx/compound_idx
are NOT coded: this crate's sequence header clears enable_masked_compound and
enable_jnt_comp, under which decode.rs reads neither and infers the simple
average, which is the only blend the encoder forms.

The 32x32 block search offers NEAREST_NEARESTMV, GLOBAL_GLOBALMV and
NEW_NEWMV (seeded from the two single-reference searches, no joint search)
for the pairs LAST+GOLDEN and LAST+ALTREF, predicted through
mc::predict_compound_intermediate + mc::combine_compound at the 8/8 split.

Root cause found on the way: write_single_ref dropped the neighbour's SECOND
reference from every single_ref_p*_ctx vote (libaom
av1_collect_neighbors_ref_counts counts both), so every single-reference
block sitting under a compound neighbour decoded a different reference name.
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.
feat(av1): the encoder writes multi-tile frames, sample-exact at every layoutAhmet Kaan Gümüş · a01d142
feat(av1): the encoder writes multi-tile frames, sample-exact at every layout

Uniform tile spacing (spec 5.9.15), one tile group OBU with per-tile sizes,
context_update_tile_id on the largest tile, and per-tile CDF / LR-reference /
neighbour-band / MV-grid resets mirroring the decoder's own tile loop. The
writer's availability answers are tile-relative now (the intra_inter and
tx-size contexts asked mi_row > 0 and coded a tile's first row against a
neighbour the decoder does not have).

EncoderConfig gains tile_cols_log2/tile_rows_log2 (default 0/0, byte-identical
to the one-tile stream); ec-bench takes EC_AV1_TILES=<cols>:<rows>.
feat(av1): reference_select frames -- the comp_mode symbol and its skip-mode header gateAhmet Kaan Gümüş · 14a71ba
feat(av1): reference_select frames -- the comp_mode symbol and its skip-mode header gate

The frame-header writer refused reference_select outright; it now writes the
bit, and with it spec 5.9.22's skip_mode_present gate (skipModeAllowed
mirrored from ec-av1-syntax's own read_skip_mode_params, off the per-reference
order hints the encoder now hands the header from its DPB). Every inter block
of a reference_select frame codes a comp_mode symbol at
mvstack::reference_mode_ctx's context -- the writer side of decode.rs
read_comp_mode -- and every block still names SINGLE, so the only stream
change is that one symbol per block.

Armed by EC_AV1_COMPOUND=1 in a test build; off by default until compound
candidates exist to pay for the bit.
perf(av1): the filter replay deblocks once per level pairAhmet Kaan Gümüş · 95de47f
perf(av1): the filter replay deblocks once per level pair

The search fixes the deblocking levels in its first three stages and
then walks 18 CDEF strength candidates that all replay the same
deblock. The replay now keeps the deblocked planes with the levels that
produced them and copies those instead when the levels match -- the
same copy the replay was already making, with the deblock skipped.
Byte-identical on the three gate clips; ladder wall 4.64/4.21/4.91 ->
4.51/4.08/4.80 s.
perf(av1): score the filter search's two sides once each, per unitAhmet Kaan Gümüş · 2b23fd6
perf(av1): score the filter search's two sides once each, per unit

The filter search's per-64x64 error pass (`unit_sse`) was the encoder's
second-largest self-time symbol (10.6%), and the frame-level `plane_sse`
that ran beside it (1.7%) summed the very same terms a second time.

Two exact changes, no decision moved (byte-identical streams on the
three gate clips):

* `unit_sse` returns the frame total as well, so `plane_sse` is gone,
  and its inner loop walks unit-sized chunks with a `u32` accumulator
  instead of dividing `col / unit` per sample and accumulating straight
  into `out` -- a shape LLVM turns into a reduction.
* Each candidate's luma and chroma error is memoized under the
  parameters that side actually reads: `apply_deblock` filters luma on
  `level[0..2]` and chroma on `level[2..4]`, and CDEF's strengths are
  per plane type, so the ~11 luma-deblock candidates all share one
  chroma score and the 9 chroma-CDEF candidates all share one luma
  score. The luma deblock level is in the CHROMA key because CDEF's
  direction search runs on the post-deblock luma window and chroma
  reuses that direction -- except when chroma CDEF is off, which is the
  case that makes the deblock stages share.

1080p / 2160p / screen ladder wall 5.34/4.91/7.06 -> 4.64/4.21/4.91 s.
Merge branch 'lane-av1trial' (782b5748): trial-set census, exact SAD pre-pass skip, split RD breakout (0.125 lambda)Ahmet Kaan Gümüş · 826851c
Merge branch 'lane-av1trial' (782b5748): trial-set census, exact SAD pre-pass skip, split RD breakout (0.125 lambda)

Wall -11.0/-11.1/-6.9% (instructions -10.0% 1080p) for BD +0.1/+0.3/-0.2
vs libaom (+121.2/+146.4/+79.1). Chroma top-K ships off (measured: SAD
ranks the chroma winner first only 67-77% of the time). Census via
EC_AV1_CENSUS=1 on examples/enc_probe.
Merge branch 'lane-av1pyr' (a5447b64): two-level frame pyramid (opt-in), target-bitrate rate mode, encode_frames/flush APIAhmet Kaan Gümüş · 7c2597d
Merge branch 'lane-av1pyr' (a5447b64): two-level frame pyramid (opt-in), target-bitrate rate mode, encode_frames/flush API

Pyramid ships OFF: 4:-16:8 measures +131.9/+178.7/+78.4 vs libaom against
flat +121.1/+146.1/+79.3 (hidden frame predicted mini_gop pictures ahead
under the same search range; leaves reach it only via extra-ref modes).
Defect fixed on the way: decode_inter_frame_tile_lr hard-coded
NO_SIGN_BIAS, desyncing the encoder's own filter-search re-decode for any
backward reference (surfaced as a missing-picture refusal).
perf(av1): RD breakout on the inter split trial, chroma top-K lever, leaf censusAhmet Kaan Gümüş · 4e368e4
perf(av1): RD breakout on the inter split trial, chroma top-K lever, leaf census

The census says the split trial runs on nearly every non-skip 32x32 block and
wins 7.6% of the time on film, 3.0% on screen. A 32x32 whose whole-block RD
cost per pixel comes out under 0.125*lambda (and a 16x16 leaf likewise) is no
longer offered the split: -10.0%/-5.7% instructions (1080p/screen) for
+0.1/+0.3/-0.2 BD points vs libaom. Chroma top-K by prediction SAD ships off:
no K bought >=5% wall inside +0.3 BD.
fix(av1): the encoder's filter-search re-decode ignored ref_frame_sign_biasAhmet Kaan Gümüş · 28f2d42
fix(av1): the encoder's filter-search re-decode ignored ref_frame_sign_bias

decode_inter_frame_tile_lr hard-coded NO_SIGN_BIAS, so the trial decode of a
pyramid leaf reading its group's backward hidden ALTREF built different MV
stacks than the writer and desynced into 'a reference frame selected with no
picture at this frame's own ref_frame_idx slot'.
perf(av1): trial-set census, and the intra SAD pre-pass only when something ranks by itAhmet Kaan Gümüş · bf299cd
perf(av1): trial-set census, and the intra SAD pre-pass only when something ranks by it

The key-frame luma search summed a per-mode SAD the unpruned default never
reads (top_k is None there); byte-exact on all three probe clips, ~2% wall.
EC_AV1_CENSUS=1 counts the search's full RD trials by kind and histograms
where the RD winner sat in the SAD ranking.
Merge branch 'lane-av1price' (128ba78b): byte-exact pricer speed -- telescoped symbol cost, pricing coder without the carry state, interior context fast path, all-zero eob testAhmet Kaan Gümüş · e6e02af
Merge branch 'lane-av1price' (128ba78b): byte-exact pricer speed -- telescoped symbol cost, pricing coder without the carry state, interior context fast path, all-zero eob test

-5.3% instructions on the 1080p ladder, streams byte-identical (12/12 FNV
points on the three gate clips against its base; the byte pins from
lane-av1mv hold on the merged tree).
Merge branch 'lane-av1mv' (8f1e2498): NEWMV against GOLDEN/ALTREF with stack-seeded starts and a swept early-outAhmet Kaan Gümüş · 3e400dc
Merge branch 'lane-av1mv' (8f1e2498): NEWMV against GOLDEN/ALTREF with stack-seeded starts and a swept early-out

BD vs libaom +121.1/+146.1/+79.3, vs rav1e +71.8/+97.5/+17.2 (all down or
flat from 52819482); wall +2-3% on the film clips, inside this box's
run-to-run noise. Census: motion::search is not the wall (halving its evals
moved a 6 s ladder by 0.2 s).
feat(av1): a two-level frame pyramid in the encoder facadeAhmet Kaan Gümüş · d496905
feat(av1): a two-level frame pyramid in the encoder facade

Hidden ALTREF coded ahead of its display position and re-output by a
show_existing_frame header, per-level quantizer offsets, a per-level rate
loop and packet dts/level. The flat one-in-one-out path is untouched.