forge
Explore
Log in

Don't you dare go Hollow

Commits

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

2026-09-08

feat(av1): code allow_high_precision_mv frames -- header bit, mv_hp symbols, pricer, eighth-pel search stageAhmet Kaan Gümüş · c5d3832
feat(av1): code allow_high_precision_mv frames -- header bit, mv_hp symbols, pricer, eighth-pel search stage

The writer refused any odd eighth-pel mv residual, so the finest vector
this encoder could commit to was a quarter pel. It can now code a frame
with allow_high_precision_mv: the header bit follows libaom's own rule
(qindex below a threshold), tile::write_mv_component codes the
mv_hp/mv_class0_hp symbol, encode::mv_component_bits prices it,
round_to_valid_mv stops rounding, and motion::search runs a fourth
refinement stage at 1/8 pel in such a frame. Default stays off
(HP_MV_QTHRESH = 0) until the BD sweep decides the policy.

Witness: a_high_precision_frame_codes_eighth_pel_motion_vectors_both_decoders_read
-- 0 hp symbols off, 6 on (5 of them eighth-pel vectors the off arm
cannot name), both arms sample-exact through ffmpeg and decode_stream.
perf(av1): the motion search charges its rate term at half the block lambda and iterates each subpel stageAhmet Kaan Gümüş · 215871e
perf(av1): the motion search charges its rate term at half the block lambda and iterates each subpel stage

The search compares SAD while the lambda it is handed is an SSE-domain RD
weight, so a coded vector was over-priced inside the search itself; and one
round per subpel stage cannot reach a winner two half-pels from the integer
centre. MV_SEARCH_LAMBDA 0.5 and MV_SUBPEL_ITERS 4, both swept.

Native BD gate, ours vs libaom / vs rav1e:
12-frame  film A +21.0/-4.8 -> +20.6/-5.1, film B +24.9/-1.9 -> +24.8/-2.1,
          screen +14.5/-33.2 -> +14.6/-33.2
long-GOP  film A +25.2/-7.2 -> +24.7/-7.5, film B +86.7/+7.3 -> +86.8/+7.4

Encoder wall +5-7%. Pins re-taken (inter vectors move).
instrument(av1): a NEWMV census plus mv-rate weights for the block decision and the searchAhmet Kaan Gümüş · f00abe4
instrument(av1): a NEWMV census plus mv-rate weights for the block decision and the search

EC_AV1_NEWMV_CENSUS=1 prints, per block side, how often a LAST NEWMV is
searched, offered to RD, and wins, the RD margin either way, the searched
vector's distance from NEARESTMV, and the mv syntax bits it spends, plus the
two pre-RD margins' skip shares and the search's own bound witness (how often
the winner was walked to at the log stage's widest step).

EC_AV1_MV_LAMBDA weights the mv rate term of the block decision only and
EC_AV1_MV_SEARCH_LAMBDA the search's own; both default 1.0, byte-identical.

2026-09-07

census(av1): per-coded-frame syntax census with order hints, and the ARF-vs-ARF table it printsAhmet Kaan Gümüş · 671d201
census(av1): per-coded-frame syntax census with order hints, and the ARF-vs-ARF table it prints

The census now carries each coded frame's order_hint and its references'
order hints, so EC_CENSUS_PERFRAME=1 prints one full report per coded frame
with the display-order PSNR joined to it and every reference named by display
distance -- which is what an ARF-vs-ARF comparison against another encoder's
stream needs. EC_AV1_MV_DIST_SCALE is readable outside a test build (like the
encoder's other search margins) and its ceiling is a named constant with its
own knob, because the ceiling was written when the deepest reference in the
GOP sat at distance 4.

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.