forge
Explore
Log in

Don't you dare go Hollow

Commits

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

2026-09-06

feat(av1): the motion search starts from a step scaled by the reference's order-hint distanceAhmet Kaan Gümüş · d53c852
feat(av1): the motion search starts from a step scaled by the reference's order-hint distance

A reference twice as far back holds content that has moved about twice as
far, so motion::search now takes that reference's own order-hint distance and
opens its log stage at step * (1 + 0.5 * (dist - 1)), capped at 4x the flat
step. LAST stays at the flat step; GOLDEN (the key frame, 2..12 frames back
in this GOP) and ALTREF (2) widen.

The hints had to be armed before the search: tile::arm_order_hints ran beside
the tile WRITE, so ref_distance read (0, 0, [0; 7]) and returned 1 for every
reference -- the first sweep came out byte-identical at every scale (the knob
never reached the tool). Armed in encode_inter_frame's header setup, the
traced distances are ALTREF 2 and GOLDEN 2..12.

Sweep vs libaom (1080p/2160p, screen byte-identical at every point): 0
+100.7/+115.8, 0.25 +98.5/+112.2, 0.375 +98.2/+115.6, 0.5 +94.4/+104.3, 0.625
+95.9/+106.5, 0.75 +92.8/+112.7, 1.0 +98.8/+113.0. Ships at 0.5 (-6.3/-11.5
/flat, vs rav1e +47.5/+63.6/+13.8); wall 5.7s/5.1s/5.8s, unchanged.

Byte pins move with the streams.
perf(av1): integer SAD in the motion search, a priced-once symbol tableAhmet Kaan Gümüş · 06a3123
perf(av1): integer SAD in the motion search, a priced-once symbol table

Two more bit-exact costs off the RD search's inner loops:

- the motion search accumulated its SAD as one f64 conversion and dependent
  add per sample; a 32x32 block of 8-bit samples sums exactly in u32, and
  that sum converts exactly to f64, so the value is unchanged;
- `symbol_bits` called libm's log2 for every symbol of every candidate the
  search prices, but a CDF interval is a 15-bit width, so there are only
  32769 prices; they are now computed once into a table (each entry exactly
  the expression the call site used to evaluate).

instructions:u on the 24-frame 1280x720 sequence bench: 231.8G -> 209.0G
(-9.8%); output bytes unchanged (64931), BD-rate unchanged on all three gate
clips, gate wall 7.0/6.7/6.7 -> 6.3/6.0/6.2 s.
perf(av1): the motion search reads the reference picture's own planeAhmet Kaan Gümüş · 06abb60
perf(av1): the motion search reads the reference picture's own plane

Every call to `motion::search` allocated and converted the WHOLE reference
luma plane from the encoder's `u8` shadow copy to `u16`, once per searched
block. The DPB picture already holds that plane as `u16`, so the search now
takes it directly and the shadow copy is gone.

Output is byte-identical (the BD gate's four points per clip and the
sequence bench's 64931 bytes are unchanged); instructions:u on the 24-frame
1280x720 sequence bench fall 384.4G -> 283.6G (-26.2%).

2026-09-04

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

2026-08-30

2026-08-27

fix(av1): clamp inter MC reads to the reference's true extent, not its coding strideAhmet Kaan Gümüş · 8d520ef
fix(av1): clamp inter MC reads to the reference's true extent, not its coding stride

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

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

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

2026-08-26

feat(av1): diamond/log integer + half/quarter-pel motion searchAhmet Kaan Gümüş · 5986059
feat(av1): diamond/log integer + half/quarter-pel motion search

Adds crates/ec-av1/src/motion.rs: a log/diamond integer-pel search over one
reference plane through mc::predict, refined by one half-pel then one
quarter-pel round. Cost is SAD + lambda * mv_bits, where mv_bits prices the
MV residual (joint/class/bit/fraction/hp) by interval-narrowing through
encode::symbol_bits against the cdf::MV_* tables, matching the tile writer's
own convention rather than a per-entry probability lookup.

SEARCH_INITIAL_STEP_PEL=8 landed from a three-way sweep (4/8/16) recorded in
motion.rs's own inline test. SAD chosen over SSE per a doc-comment measurement.