forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on mainFiltered to crates/engine-hw/src/lib.rsClear filter

2026-11-25

2026-11-16

⚡ 10-bit HEVC hardware export 4x faster, output bit-identical: pipelined encode/decode-ahead, zero-copy P010 dmabuf for caption-free spansAhmet Kaan Gümüş · 902be04
⚡ 10-bit HEVC hardware export 4x faster, output bit-identical: pipelined encode/decode-ahead, zero-copy P010 dmabuf for caption-free spans

- hw encoder on its own thread; direct u16 shm copies (bytemuck)
- hw-child decode-ahead for wide frames; T_NEXT_DMA16 exports P010 to the encoder child
- spans split at caption/title boundaries; quiet spans stay on the GPU
- DMA header count read at the right offset (every hw decode had fallen to software)
- hw_fallback and hw_midgop_seek take the hardware seat: the failure hook no longer leaks across parallel tests

2026-11-15

2026-10-23

🚚 edith moves to git.tahinli.comAhmet Kaan Gümüş · b02f499
🚚 edith moves to git.tahinli.com

The working tree as of 2026-10-23, as one commit on top of the last one
here. It carries the work up to that date plus the test-slimming work:
integration tests merged into one binary per crate, nextest config,
doctest = false, debug line tables only, perf tests behind --ignored,
and faster generators, reverse, undo, subtitle-export, hevc, stabilise
and hear tests.

2026-09-24

apply(decode): stretch the anamorphic picture once, at the single post-decode stepAhmet Kaan Gümüş · b3a5acb
apply(decode): stretch the anamorphic picture once, at the single post-decode step

ffmpeg applies the sample aspect exactly once, at the conversion to the
square-pixel raster; so does this engine now. Render::frame takes the
file's pixel_aspect beside its rotation and, only where the samples are
not square, resamples the coded picture to the displayed width with the
existing scale_i420 -- the same bilinear the canvas places through. A
square-pixel file takes the branch by a bool and not one byte is
touched: the passthrough fast path, the tonemap FNV constants and the
graded path are all exactly what they were (matrix_render and
tonemap_render green unchanged).

The export takes the same two facts through place_picture -- stretch
after turn, the order ffmpeg composes -- and an anamorphic span is
barred from the DMA fast path, whose whole premise is that no seat
touches a sample before the encoder. Dissolve's B half carries its own
file's aspect beside its own rotation.

VhMeta grows the coded pair and the aspect ratio, so the plugin ABI
answers both questions a display size may now raise: what to draw and
what the samples are stored at.

2026-09-18

🐛 fix(media): audio routing, session audio re-arm, hw trailing-zero NALs, display-matrix rotationAhmet Kaan Gümüş · bc8b82e
🐛 fix(media): audio routing, session audio re-arm, hw trailing-zero NALs, display-matrix rotation

- is_audio admits .mpeg/.mpg so mp3-with-cover files import (was fed to Mp4Demuxer)
- session audio walks past trackless leading sources and re-arms when a
  sounding file joins a silent timeline (fixes add/remove/add silence)
- engine-hw pump clears trailing cabac_zero_word bytes instead of dying
  with code -2; export falls back to software decode before first frame
- tkhd display matrix read for mp4; 90/180/270 turns baked into preview
  and export pixels; other angles refused by name (UnsupportedRotation)

2026-09-12

♻️ refactor(engine-hw): the VP8 decode seat is ec-vp8 native -- libvpx and its hand-written FFI are deleted, the plugin links the decoder as ordinary Rust (56 ec_vp8 symbols, no DT_NEEDED, no dlopen); VpxSession keeps its five-verb boundary (init/decode/flush/get_frame, destroy now the drop of an owned decoder) and everything above it is untouched; CAP_VP8 lights unconditionally and still never reads as a GPU seat; A/B byte-exact against the libvpx seat on the 1280x720 fixture (60/60 frames), the 2560x1321 odd-size webm (270/270) and a two-pass auto-altref stream (90/90 shown, 6 hidden produce none, seek landings identical); vp8 twins 4/4, capability_matrix+backends+caps green, --all-targets 0 warningsAhmet Kaan Gümüş · 36bd0e7
♻️ refactor(engine-hw): the VP8 decode seat is ec-vp8 native -- libvpx and its hand-written FFI are deleted, the plugin links the decoder as ordinary Rust (56 ec_vp8 symbols, no DT_NEEDED, no dlopen); VpxSession keeps its five-verb boundary (init/decode/flush/get_frame, destroy now the drop of an owned decoder) and everything above it is untouched; CAP_VP8 lights unconditionally and still never reads as a GPU seat; A/B byte-exact against the libvpx seat on the 1280x720 fixture (60/60 frames), the 2560x1321 odd-size webm (270/270) and a two-pass auto-altref stream (90/90 shown, 6 hidden produce none, seek landings identical); vp8 twins 4/4, capability_matrix+backends+caps green, --all-targets 0 warnings
♻️ refactor(engine): the software H.264 export seat encodes with ec-h264Ahmet Kaan Gümüş · 0bc3a6b
♻️ refactor(engine): the software H.264 export seat encodes with ec-h264

The last rusty_h264 seat in the tree moves to the project's own encoder:
Enc::Sw drives ec_h264::Encoder (CABAC Main/High, 8x8 transform, threaded
slices) where it drove rusty's Constrained-Baseline CAVLC encoder, and the
export's second decode site (SwDecoder) follows the playback seat onto
ec_h264::H264Decoder in true display order, flushed at end of stream.

Feature mapping: same fps/bitrate/GOP knobs (the level the seat used to
compute by hand the encoder now derives from the same Table A-1); Fast
stays the preset; intra-only exports stay all-IDR through gop_size 1.
Named gaps: odd dimensions are now refused by name like the HEVC seat
(4:2:0 cannot crop back to an odd picture; the old encoder silently coded
them); the seat no longer forces level_idc. One honest flag rise: the
Matroska-facing key mark is now what the bitstream says, not a constant
false. One contract tightening, held rather than papered over: ec-h264
buffers nothing, so drain is structurally empty and the old lookahead
corner-cut note is closed.

tests/sw_backends' independent witness becomes ffmpeg byte-for-byte (the
rusty oracle retired with the crate); hw_encode and the mp4 repack test
decode through ec-h264; caps and the card label say ec-h264.

Quality, same 300-frame 720p window at the seat's own ~2.76 Mbps CBR,
both seats driven directly on identical frames and the outputs decoded by
ffmpeg (reviewer-reproduced numbers; an earlier in-lane harness measured
rusty at 25 dB through a stale-plane A/B bug -- frame-0 luma riding under
fresh chroma, which rate control hides in the byte count -- so its rusty
row was noise, while the ec row reproduced to the digit): rusty PSNR-Y
40.51 / SSIM 0.9842 at 3.46 MB against ec-h264 PSNR-Y 41.58 / SSIM
0.9903 at 3.39 MB -- about +1.1 dB-Y and +0.006 SSIM for ~2% fewer bits,
with tighter rate fidelity (rusty overshot to 3.0 Mbps on hard content).
✨ feat(engine): software VP8 decode via dlopen'd libvpx seat in the pluginAhmet Kaan Gümüş · ba33df0
✨ feat(engine): software VP8 decode via dlopen'd libvpx seat in the plugin

VP8 was refused by a stale UNSUPPORTED claim ('no VP8 decoder'); the
vendored cros-codecs VP8 decoder is VA-API-only and the test GPU
exposes no VP8 VA-API profile, so the real seat is software: libvpx.so.9
dlopen'd inside libengine_hw.so (vpx.rs), routed before any GPU device
opens, seek = destroy+re-init on the demuxer's keyframe contract,
CAP_VP8 reported as the plugin's seat. Codec::Vp8 plumbed through
demux (V_VP8 + mp4 vp08), colorspace, refusals; export UI gains a
truthful read-only VP8 row; test_vp8.{webm,mp4} fixtures + capability
row + tests/vp8.rs decode/export twins. Verified by the authoring
session: headless playloop 270 frames 0 dropped, 50/50 seeks, live
harness-driven UI playback, cross-provider review PASS (FFI layouts
against shipped libvpx DWARF, valgrind-clean).

2026-08-22

🐛 fix(engine-hw): rewrite H.264 frame_num/POC the driver zeroesAhmet Kaan Gümüş · 2436826
🐛 fix(engine-hw): rewrite H.264 frame_num/POC the driver zeroes

mesa radeonsi (26.1.7) writes its own slice headers and ignores the
frame_num and pic_order_cnt_lsb cros-codecs passes in, so every slice of
every export carried 0 for both. Desktop decoders tolerate it; stateful
phone decoders judder at every GOP (measured on three real exports).

slice_fix rewrites both fields per access unit on the plugin side
(frame_num on reference pictures, POC per picture, IDR resets), and the
level_idc now follows Table A-1 / Table A.8 instead of a hard-coded L4.
Header-only: macroblock data is byte-identical, bitrate unchanged.

Verified: ffmpeg trace_headers on a plugin dump (frame_num 0..31 wrap,
POC 2n, IDR restart, level 40 at 1080p30); 2560x1440 re-export plays
clean on the phone that juddered before.

2026-08-15

🐛 fix(engine-hw): a forward reposition replaces the skip, never adds to itAhmet Kaan Gümüş · 1077f5f
🐛 fix(engine-hw): a forward reposition replaces the skip, never adds to it

pump's one law is 'the picture delivered is position + skip': position
advances for every handle popped, dropped ones included, so a forward
reseek to a target ahead of the decoder must leave skip = ahead --
exactly the distance still to walk. The landed code added to whatever
skip was still standing, so a second forward reseek before the first
drained (rapid small seeks on the kept worker, or a flush whose RAP
skip was undrained when a forward span was asked) delivered ahead
frames past its target -- silently, because the pictures kept coming.

forward_skip() is the seam the law lives in, with a pinning test for
the stacked-forward and flush-then-forward shapes (red on the add,
green on the replace).
🐛 fix(playback): a silence cut's boundary decodes forward, not flushAhmet Kaan Gümüş · e045b5e
🐛 fix(playback): a silence cut's boundary decodes forward, not flush

Cutting silences leaves a timeline of same-file micro-clips, and every
boundary reseeked the worker the expensive way: decoder FLUSH, demuxer
seek to the RAP, skip-decode RAP->clip-start (up to a GOP of VCN work,
the GPU spikes), then a re-prime whose ~178ms ttff at 4K outlasts the
0.15-0.65s clips -- so the picture starved while the continuous audio
feeder played on (the freeze), and LATE_RESYNC answered the starved
picture with another flush storm every RESYNC_GAP.

- engine-hw: seek_to reaches a target ahead of the decoder, within
  FORWARD_SECS (0.5s) of it, by decoding forward and dropping through
  the existing skip path -- no flush, no RAP seek, no re-prime; behind,
  past the reach, and past EOF keep the flush. Decision extracted as
  the pure reposition() + tests; position tracked per popped handle.
- playback: the session reports picture_priming() -- owed from span
  start until its first frame -- and the player's resync waits out a
  prime instead of restarting into it (resync_due, constants kept).
- bench cutloop: the freeze metric -- an N-region cut timeline played
  end to end, displayed/dropped per second, restarts and resyncs.

2026-08-14

🐛 fix(engine): the seat a test cycles is one no other test is sitting inAhmet Kaan Gümüş · 88ce23e
🐛 fix(engine): the seat a test cycles is one no other test is sitting in

The stand-in encoder seat was armed by a process-wide variable and read by
`hw_seat`, so a software test that had already opened its own export picked
it up mid-flight, met the hang injection, and stalled: `cargo test -p engine
--test export` was green or five-failed depending on the interleaving. The
progress reset the fallback does made it worse -- one cancel test hot-spins
on progress reaching 1.0 and a regression there never ends.

The seat is process state, so it is borrowed rather than assumed: the whole
software suite shares a read guard, exactly as parallel as it always was, and
the encoder-death family takes it exclusively, lifting the software encode
pin only for its own exports and putting it back before it lets go. Which
lets `hw_seat` go back to being production policy with no test flag in it.

Also: a child that does not answer `vh_enc_dma_geometry` is now reaped there
instead of costing the next picture a second whole timeout; the plugin's own
note no longer claims the editor never loads the encode half, when what it
never does is *call* it -- the availability check is a dlopen and opens no
VA-API display; and the guard that refuses to write an export again in
software when a person picked the GPU by name now has the test it was
shipped without.
✨ feat(engine): the driver that aborts kills a process nobody was editing inAhmet Kaan Gümüş · c0a1847
✨ feat(engine): the driver that aborts kills a process nobody was editing in

Mesa's radeonsi calls libc abort() from its own C worker thread when the
video ring resets under it -- amdgpu_ctx_set_sw_reset_status, mesa 26.1.6,
vcn_unified_0 hung during an AV1 encode submission on 2026-08-13. A foreign
thread's abort is not an unwind, so every catch_unwind in the plugin was
structurally unable to see it: the editor died with the driver and took the
session's work with it.

So the encoder is not in the editor's address space any more. HwEncoder is a
handle on a `hw-encode-child` process that dlopens the plugin, and its death
-- by abort, by any signal, or by going quiet past VE_HW_TIMEOUT_MS -- comes
back as an error the export answers by writing the file again in software.
A person who picked the GPU by name still gets the refusal in words rather
than an encoder nobody chose.

Isolation that cost the speed would not be worth having, so pictures do not
travel down a pipe: in-memory ones go through a memfd mapped in both
processes, and pictures still on the GPU never move at all -- their
DRM-PRIME descriptors cross as file descriptors over SCM_RIGHTS, so the
zero-copy export path stays zero-copy across the boundary. Measured on this
box at 1080p: 430 fps in-process, 384 isolated, 89% of it, worst case
(every export of an untouched clip takes the descriptor path instead).

The proof does not need a wedged ring, which is the one thing a wedged
machine cannot supply: VE_HW_TEST_FAKE opens a stand-in seat in the child and
VE_HW_TEST_ABORT / VE_HW_TEST_HANG say where it dies or stops, so the
containment paths are exercised on any machine, GPU or no GPU.

Decode is still in the editor's process, where the same abort would still be
fatal; the seam to move it is now the one this built.
🐛 fix(engine-hw): the hardware HEVC seat says what its samples meanAhmet Kaan Gümüş · 9fdee6f
🐛 fix(engine-hw): the hardware HEVC seat says what its samples mean

The plugin's HEVC encoder wrote no VUI at all, so libavcodec read the
stream's colour as "unspecified" and rendered a 709 export through the
601 matrix -- the HEVC decoder takes the bitstream's answer and
overwrites the container's with it, which is why the mp4's `colr` box
and the Matroska's Colour element could not cover for it
(`export_color::every_format_signals_its_space_in_the_bitstream`, both
HEVC containers, whenever the plugin is on the path).

The three H.273 code points and the range flag now go in at the open,
from the same `ColorDescription::output` rule the software intra seat's
VUI and both muxers' tags come from, through the vendored `SpsBuilder`'s
own `video_signal_type`/`colour_description`. A symbol of its own,
`vh_enc_hevc_open_colour`, rather than four more arguments under the old
name: a plugin that predates it is then simply missing the seat and the
export falls back to the software encoder, which has always written the
VUI, instead of being called with a signature it does not have.
🐛 fix(engine-hw): a group of one picture writes a header a decoder can readAhmet Kaan Gümüş · 9a188c5
🐛 fix(engine-hw): a group of one picture writes a header a decoder can read

Every intra-only hardware file was undecodable. The intra seat asks for a group of one picture, the predictor hands that limit to `SpsBuilder::max_frame_num`, and `1.ilog2()` is 0 -- so `0u8 - 4u8` wrapped to 252 in release and every SPS shipped `log2_max_frame_num_minus4 = 252`, outside the spec's 0..=12. Decoders answered "out of range (0-12): got 252".

Saturate instead, in both builders that do the arithmetic (the `max_pic_order_cnt_lsb` twin asks for 2 and wrapped to 253) and in the H.265 parser's copy of the same line. Zero is not merely legal for an all-IDR stream, it is right: `frame_num` never leaves 0 there. The limit itself stays 1 -- that is the IDR-per-access-unit mechanism, and only the header field was garbage.

2026-08-13

🔀 merge(engine): the stand-in decides one path, and the intra file keeps its marksAhmet Kaan Gümüş · eff035e
🔀 merge(engine): the stand-in decides one path, and the intra file keeps its marks

Lane P's proxy workflow meets a main that had taken S's persistent decode
workers, E's pipelined export and E4's zero-copy encode.

* `start_span` keeps S's reuse door and P's single substitution point at
  once: `picture_path(source)` is resolved *before* the door and handed to
  both halves of it. A worker holding the film is then asked for a span of
  the stand-in, declines on the path it already has (`Worker::reseek`),
  and `set_proxies`' seek becomes a respawn on the other file -- while a
  span that did not change files still costs no thread and no VA-API init.
  Asking the project for the path at the door, as main did, would have
  left every proxied span opening a worker from scratch.
* `Enc::encode_dma` takes P's `intra` flag, which is not symmetry: a proxy
  of a file already small enough is coded at that file's own size
  (`proxy::size_for` -- `wanted` is true for HEVC and AV1 at any size), so
  an intraframe export's decoder and encoder can agree on a surface and
  the buffer goes straight across. Marked `false` there, an all-intra
  stand-in would have carried no sync point at all, which is the exact
  bug `gop_limit` was written against, reached by the other door.
* The five other conflicts were both sides adding a field: `drop_late`
  and `proxies` next to each other, in the struct and in all three opens.
* `enc_depth` is keyed by codec, so the intra seat takes H.264's two. Said
  in its doc rather than left to be re-derived: that seat is the same
  entrypoint with every inter dependency removed, so a picture there is
  finished no later than one on the seat the two was measured on.

`nm -D libengine_hw.so` lists sixteen: P's `vh_enc_open_intra` beside
E4's `vh_next_frame_dma`, `vh_enc_dma_geometry`, `vh_enc_frame_dma` and
main's `vh_seek`. `picture_path` still has exactly one call site outside
the tests, and it is in `playback` -- an export reads the film.

The intra seat and the zero-copy path are read, not run: every test that
would reach either is hardware-gated and the GPU is wedged.
🔀 merge(engine-hw): the encoder that skips the CPU keeps the two it holdsAhmet Kaan Gümüş · 9717151
🔀 merge(engine-hw): the encoder that skips the CPU keeps the two it holds

Lane E4's zero-copy encode path meets lane E's two-picture encoder. Both
touched the same file at the same place and neither knew of the other.

* `vh_seek` and `vh_next_frame_dma` were the textual conflict and nothing
  more: two different symbols added at one spot. Both kept.
* `EncSession::encode_dma` submits a picture like `encode` does, so it
  counts one in `in_flight` -- one session takes both kinds of picture
  (an untouched clip hands buffers over while a graded one or a gap goes
  through the pixel path), and a submission missing from that count is an
  input buffer the pixel path would believe free one picture too early.
* No deferred poll on the dma path, said in a comment where it would go:
  the depth exists to overlap the *next* picture's CPU interleave with
  this one's encode, and a picture arriving on the GPU has no interleave
  to overlap. Draining every call is also what keeps the decoder's own
  hold on the buffer short.
* Per-codec `enc_depth` therefore governs both kinds: the pixel gate is
  the only one there is, and the dma path leaves `in_flight` at its floor.

`nm -D libengine_hw.so` lists both lanes' optional symbols: vh_seek,
vh_next_frame_dma, vh_enc_dma_geometry, vh_enc_frame_dma. The refusal
fallback is untouched -- a buffer the plugin cannot hand over comes back
as pixels, never as a failure.

The dma path itself is read, not run: every test that would exercise it
is hardware-gated and the GPU is wedged.
Merge branch 'worktree-agent-a1dbd9ef7cdaec697'Ahmet Kaan Gümüş · 1cb74a4
Merge branch 'worktree-agent-a1dbd9ef7cdaec697'

# Conflicts:
#	scripts/bench.sh
🐛 fix(engine-hw): two pictures in flight only on the seat it was measured onAhmet Kaan Gümüş · fa1ce8e
🐛 fix(engine-hw): two pictures in flight only on the seat it was measured on

Depth 2 makes a promise about the driver: a picture submitted must hand its
access unit back on the very next poll, and `encode` treats a seat that does
not as an error, because it cannot write into a buffer the GPU may still be
reading. That was measured on the H.264 seat and nowhere else, and it was
applied to all three. HEVC and AV1 on this plugin are intra-only through the
same driver and very probably behave the same way -- "very probably" is not
what a hard error should rest on, and the GPU has been unavailable since the
measurement was possible. They take depth 1, which is the one-buffer
behaviour every seat had before this lane: the picture coded before the next
is written. `enc_depth` says so in one place, and the number is per session
rather than a constant, so raising it is a measurement away.

Also in the vendored flush: a plane of zero length at a non-zero offset would
have flushed the byte one past the mapping, where upstream's byte loop
flushed nothing at all for `0..0`. Guarded. No such plane exists on this
path -- both NV12 planes are non-empty -- so this is the edge kept closed
rather than a bug seen.
🐛 fix(engine): the GPU's stand-in was one starting point long, not every frameAhmet Kaan Gümüş · 60ae56c
🐛 fix(engine): the GPU's stand-in was one starting point long, not every frame

A proxy asked the ordinary hardware seat for a key frame on every
picture, which is not the same thing as an intra-only file and does not
make one: cros-codecs' low-delay predictor takes the keyframe branch
with `idr` false for a forced key frame, writes no SPS or PPS with it,
and `fix_slice_nal_headers` -- which reads the parameter sets to know
what a slice is -- then marks it a plain I slice. A 60-picture hardware
proxy came back with **one** frame a decoder could start on, so its
seeks were the film's own seeks and the whole point of it was gone.
Software was right all along (150 of 150), which is what hid it.

The thing that decides this is the predictor's group limit, and a group
of one picture is what an intra seat is: the counter is then pinned at
zero, every picture takes the keyframe branch as an IDR, and every
access unit carries its own parameter sets. That is the HEVC seat's own
mechanism, now the H.264 one's as well.

Its own plugin symbol (`vh_enc_open_intra`) rather than a flag on the
existing one, matching the AV1 and HEVC seats: a plugin built before it
exists has no intra seat, and the caller then takes the software encoder
-- which codes one frame a GOP and writes what was asked for -- instead
of being handed a long-GOP file under a name that promises otherwise.
`intra_only` on anything but the mp4 pair is now refused by name.

Checked without a GPU: the group limit and the IDR-marking rule are both
unit tests in the plugin. The hardware end-to-end twin (`sync_points`
== frame count) is written and `#[ignore]`d, for a machine whose GPU is
not wedged.
⚡ perf(export): the picture the GPU decoded is the picture it encodesAhmet Kaan Gümüş · 366171b
⚡ perf(export): the picture the GPU decoded is the picture it encodes

An untouched clip's frames never leave the card: the decode session hands
its DRM-PRIME buffer over and the encoder imports it, so an export of a
clip with no grade, no tone map, no matrix remap and no canvas to place
on costs neither the `vaGetImage` read-back nor the NV12 interleave back
up -- both of which used to run once per frame, per side.

Three optional plugin symbols carry it (`vh_next_frame_dma`,
`vh_enc_dma_geometry`, `vh_enc_frame_dma`), so an older `libengine_hw.so`
reads back exactly as it did, and any refusal at all -- another coded
size, another fourcc, a driver whose export the plugin will not take, a
software decoder on the other end -- hands the pixels over instead of
failing. The decode session keeps six pictures out of its pool while
they are outstanding, and reserves six extra buffers the moment a caller
asks, so a decoder is never robbed of its own.

Measured on the film, 60s span, hardware H.264 both ways: 94.58 -> 276.46
fps median, 46.9s -> 15.6s wall, and 37.6s -> 0.5s of user CPU. SSIM
against the source frames is 0.964490 where the read-back path scores
0.964506 -- the same picture, coded by the same encoder.
⚡ perf(decode): the worker that decoded a span stays for the next oneAhmet Kaan Gümüş · bbdd4d6
⚡ perf(decode): the worker that decoded a span stays for the next one

A seek used to cost a thread, a container parse and a VA-API
initialisation (98 ms measured worst case) before it could decode a
single picture, because every span opened a decoder of its own and threw
it away again. The worker now outlives its span: it parks on a command
channel, and a seek onto the file it already has open reaches it through
Worker::reseek -- a demuxer seek and a decoder flush, 1-4 ms measured
against a 28-37 ms open of the same file warm.

The plugin learns the same trick from the other side: vh_seek
repositions an open session exactly as vh_open_at positions a new one,
and it is an optional symbol, so a plugin built before it still decodes
and its caller simply opens a session per seek as it always did.

Cancelling and abandoning become two different things: a seek abandons
the span (the thread, the file and the decoder stay), a replacement
cancels the worker (the thread ends, and the command channel goes with
it, so nothing parks in recv past the session that owns it and no VA-API
session meets Mesa's atexit).
⚡ perf(engine-hw): the picture is written where the last one is already codedAhmet Kaan Gümüş · 01fb8ce
⚡ perf(engine-hw): the picture is written where the last one is already coded

A hardware export spent four fifths of its per-frame time putting the picture
*into* the encoder, not encoding it. Two things were paying for that, and both
are gone:

The NV12 rows were interleaved a byte at a time straight into the mapped buffer
object, which is write-combining memory -- every pair of stores flushed a
partial buffer. The row is built in ordinary memory now and copied across in
one piece: 8.2 ms a picture became 6.7 ms at 1080p (measured on radeonsi by
alternating the two paths frame by frame inside one export, so the machine's
load weighed on both).

And there was one input buffer, so the GPU had to finish coding a picture
before the next could be written into it -- the CPU's interleave and the GPU's
encode ran end to end. There are two now, and the access unit collected after a
submit is the *previous* picture's: the GPU codes while the caller interleaves.

Per-frame encode cost, minimum over 719 frames of the same film span, three
interleaved runs each: 9.4/9.4/10.2 ms before, 6.9/7.3/7.4 ms after -- 27% off
the only stage that was costing anything.

The file is the same file: a ten-second span of the same source exported
through both plugins is byte-identical (6,379,699 bytes, cmp clean), ffmpeg
-v error empty, and tests/hw_encode.rs round trips all three ways.
🐛 fix(hevc): the parameter sets say what the GPU actually codesAhmet Kaan Gümüş · a082e61
🐛 fix(hevc): the parameter sets say what the GPU actually codes

The hardware seat's pictures were a band of noise over flat green while the
frame count decoded clean, on every real 1080p and 4K source and on none of
the synthetic ones. Three promises the synthesized parameter sets made that
the driver never kept, each of which desyncs CABAC and turns the rest of the
picture into coefficient garbage:

`max_transform_hierarchy_depth_intra`/`_inter` were the builder's default 0,
which says `split_transform_flag` is never coded and a decoder must infer no
split. The encoder splits transform trees wherever the residual asks for it,
so from the first coding tree unit on its split flags were read as residual.
Measured alone: SSIM 0.17 against the source, 371 decoder complaints.

`cu_qp_delta_enabled_flag` was off, so `cu_qp_delta_abs` had nowhere to be
written -- but the driver's rate controller moves the quantizer between
coding tree blocks and codes the delta regardless. Measured alone: SSIM 0.17.

And the picture was declared at `MinCbSizeY`, so 1080 lines claimed a 56 line
bottom coding tree row where the encoder had coded a full 64. The sets now
declare the coding-tree-aligned size and crop back with the conformance
window, which is what the working reference encoders on this driver do, and
the surface is allocated to match.

Flat gradients and a screen capture pass either way -- they split no
transforms and give the rate controller nothing to do -- which is exactly how
this reached a default-on seat.
✨ feat(engine-hw): a third encode seat, and it writes HEVCAhmet Kaan Gümüş · 76787eb
✨ feat(engine-hw): a third encode seat, and it writes HEVC

`vh_enc_hevc_open` beside `vh_enc_open` and `vh_enc_av1_open`: the same
signature, the same session fed through the same `vh_enc_frame` /
`vh_enc_drain` / `vh_enc_close`, so the codec is decided once at the open
and nothing after it is a third path. `EncSession`'s `av1: bool` becomes
an `EncCodec` of three, which is what a two-codec boolean could no longer
say.

Two things the H.264 seat's numbers do not carry over:

  * **Intra-only, every picture an IDR.** With a GOP, the P slices this
    driver writes are undecodable: the slice segment headers are the
    driver's to write and radeonsi writes a constant picture order count
    into all of them, so a decoder sees frame after frame claiming to be
    the same output picture (measured 2026-08-13 -- only each group's
    leading IDR decoded). Intra is therefore not a preference here, and
    it happens to be the file the software HEVC seat already writes.
  * **384x384 floor.** The same driver that takes a 128x128 H.264
    context answers VaError(19) to an HEVC one below that, so the open
    says no and the caller falls back rather than reading a driver
    refusal mid-export.

`CAP_TABLE`'s HEVC row gains the encode profile it now really opens
(Main, 8-bit -- the Main 10 entry beside it stays a decode claim), and
the caps test that pinned encode to H.264|AV1 pins it to the three.
chore: rename ponytail: comment marker to corner-cut:Ahmet Kaan Gümüş · 9ba8e0a
chore: rename ponytail: comment marker to corner-cut:

Marker convention renamed after uninstalling the ponytail plugin;
semantics unchanged (deliberate corner-cut, known ceiling + upgrade path).
Token-only rename, 81 comment lines, no code change.
🐛 fix(decode): a seek into an open GOP is hardware's to finishAhmet Kaan Gümüş · 7652ada
🐛 fix(decode): a seek into an open GOP is hardware's to finish

A Blu-ray remux codes its GOPs open: the I picture that opens one is stored
ahead of the leading pictures that are *shown* before it, and those reference
the GOP before. Restart decoding at that random access point -- which is what
every seek, scrub and clip boundary does -- and the leading pictures have
references nobody decoded, so the plugin failed its first frame, playback fell
back to `rusty_h264`, and that decoder died on the file's I_PCM macroblocks.
Seventeen of twenty scrub steps on a 5.27 GB AVC remux ended with no picture
at all, and the three that survived cost 482 ms each in software.

The pictures are not ours to show, so they are dropped and the decode walks on
(bounded by `LEADING_LIMIT`, and only for a session that was positioned
somewhere other than the file's own start). The refusal that the tolerance
would otherwise swallow is kept at both ends: a stream read from frame 0 is
still refused the moment its first picture will not decode, and the plugin
probe now counts an immediate end of stream as a refusal rather than a pass --
a session that hands back no picture is the black-frame-and-instant-eof the
probe exists to catch.

The vendored H.264 decoder's own refusal goes with it: it failed a `frame_num`
gap outright unless the stream declared gaps allowed, which is exactly the
wrong reading here -- the gap is the editor's, made by starting in the middle
of a film, and §8.2.5.2's non-existing frames are what stands in for it. The
loop that builds them was already there, behind that flag.

Twenty of twenty scrub steps on the remux now decode in hardware, 77 ms
median against 482 ms; `seek_matches_linear_every_container` holds for every
container, and `dump_frame <file> <n> <out> seek` is what a picture reached by
a seek can be compared with the same picture reached by decoding from the
start.

2026-08-12

🐛 fix(decode): a film's grain is synthesized into a surface of its ownAhmet Kaan Gümüş · c52b667
🐛 fix(decode): a film's grain is synthesized into a surface of its own

An AV1 frame with `apply_grain` set is *displayed* from a second surface:
the driver writes the reconstructed picture into the render target, which
later frames reference, and the grain-synthesized one into a target the
decoder has to hand it. The vendored backend handed it none -- it passed
`VA_INVALID_SURFACE` as `current_display_picture` while still asking, in
the very same buffer, for the grain -- and radeonsi refuses that picture
outright: `vaEndPicture` answers VA_STATUS_ERROR_INVALID_SURFACE.

That is what killed the only AV1 film in the library at frame 49, its
first picture with grain; 1337 of the first 1504 have it, so AV1 playback
on real media had never worked. Every fixture that said otherwise was
grainless, which is why `test_av1_grain.mkv` is now beside them and why
its test decodes all ninety frames and then asks whether the grain
actually reached the picture -- turning `apply_grain` off would make the
decode succeed too, and would silently strip the film of its texture.

A grainy picture costs two pool frames rather than one, so a sequence
whose header admits grain gets a pool of twice the size; one that does
not is left exactly as it was, as are H.264, HEVC and VP9, which have no
such surface and read back the reconstructed one as always.
🐛 fix(demux): a codec's support is probed per container, not inferred from a neighbourAhmet Kaan Gümüş · 4f4dcb4
🐛 fix(demux): a codec's support is probed per container, not inferred from a neighbour

VP9 was decodable out of an mp4 and refused out of a .webm — `V_VP9` fell
through the Matroska track dispatch into `OtherVideo` and came back as
"V_VP9 video in a Matroska file is not supported", with the VA-API VP9
decoder wired in `engine-hw` the whole time. A browser-downloaded .mkv was one of those
files.

Both dispatches now read one table (`CODEC_IDS`), and the Matroska arm
matches on `Codec` with no wildcard, so a codec added to the enum fails
to compile until it has been routed rather than falling through to a
refusal. A cell that is deliberately absent is a row in `UNSUPPORTED`
with a reason, and the refusal quotes that reason instead of listing
what is supported and leaving the user to guess.

The mp4 video track comes out of `moov.traks` in file order, not a
`HashMap` walk of `Mp4Reader::tracks()`: a file with two video tracks
opened on a different picture from one run to the next, and a saved
.edith reopened on the other one. `audio::audio_track_ids` fixed the same
trap for sound; the naming half of `AudioSession::unsupported` had it too.

VP9 states its bit depth in no container record — an mkv `TrackEntry`
carries none and an mp4's `vpcC` is optional — so it is read off the
first keyframe's uncompressed header. Assumed 8-bit, a profile 2 stream
would decode into an NV12 pool and come back as garbage; 12-bit is
refused by name like 12-bit AV1 and HEVC.

The audio refusals said "AAC and AC-3 only" long after FLAC, MP3, Vorbis,
ALAC and PCM decoded out of a Matroska file. They name the real set now,
per container, because an mp4 video's sound never reaches symphonia and
reads fewer codecs than an mkv does.

tests/capability_matrix.rs holds all of it against real files.

2026-08-11

✨ feat(av1): 10-bit AV1 opens instead of being refusedAhmet Kaan Gümüş · 25aef8c
✨ feat(av1): 10-bit AV1 opens instead of being refused

The `av1C` record's `high_bitdepth` was an outright refusal ("10-bit AV1 is
not supported yet"), on a comment that had gone stale: the vendored decoder
takes its RT format from the stream and maps Depth10 to YUV420_10, and the
plugin's read-back pool is P010 whenever the demuxer says >8 -- which is how
HEVC Main 10 has been playing all along.

So `parse_av1c` reads the depth instead of refusing it, in both containers
(the mp4 `av1C` box and the Matroska `CodecPrivate`), and 12-bit stays
refused by name in the words HEVC's own depth check uses. Nothing else needs
the plugin any differently: AV1 has no software decoder at any depth, so a
machine without `libengine_hw.so` still refuses it as `needs_plugin` always
has.

Fixture: assets/test_av1_10.mkv (libaom, yuv420p10le), the AV1 seat of the
pair test_hevc.mkv/test_hevc10.mkv already make for HEVC.
✨ feat(caps): the card says what this machine and this build can really doAhmet Kaan Gümüş · 0f37a18
✨ feat(caps): the card says what this machine and this build can really do

The hardware half was never asked for: the plugin decoded what it was
handed and the front-end had nothing to show before a file arrived. Now
an optional `vh_caps` symbol asks the driver -- profiles, entrypoints and
whether a P010 image exists for a 10-bit read-back -- and intersects that
with the codecs the plugin actually implements, so a GPU with an HEVC
encode entrypoint is not reported as an HEVC encoder edith can reach.

Optional exactly as `vh_enc_av1_open` is: a plugin built before this
still loads and still decodes, and the listing degrades to "none" for it,
for a missing plugin and for a machine with no driver alike.

The software half is a table -- what this build was compiled with is a
question the manifest already answered -- and both halves land at the
foot of the export card, where a user asks them.

2026-08-10

✨ feat(import): a Matroska film opens, its 10-bit picture and its 5.1 sound alikeAhmet Kaan Gümüş · b083a3b
✨ feat(import): a Matroska film opens, its 10-bit picture and its 5.1 sound alike

mkv HEVC demux (Main/Main10), a P010 pool in the hardware path read back to
I420, mkv audio through symphonia's Matroska reader with rusty_aac decoding
what symphonia's own AAC refuses (anything wider than stereo), and a BS.775
fold of 5.1 down to the stereo the output device takes.

vendor/rusty_aac is 0.5.0 with one local patch: its decoder's IMDCT caches the
cosine matrix instead of calling cos() per term, 11x faster and the difference
between playable and not.
✨ feat(export): AV1 comes back out, in a Matroska file this editor reopensAhmet Kaan Gümüş · dd3a2a8
✨ feat(export): AV1 comes back out, in a Matroska file this editor reopens

The export card's second picture format. AV1 already *arrives* here as
Matroska (`mp4 0.14` has no `av01` sample entry at all, so `demux` walks
the EBML by hand); it now leaves the same way, through an `MkvMuxer`
written beside the mp4 one -- EBML header, `Info`, one `V_AV1` track whose
`CodecPrivate` is a real `av1C` record built from the first keyframe's
sequence header OBU, then clusters that open on every keyframe. The
segment size and the duration are the only two fields patched at `finish`.
Matroska rather than AV1-in-mp4 because the reader for it already exists:
the round trip closes against this project's own `Demuxer`.

Picture only, and said so on the row before a destination is picked ("AV1
picture in .mkv — no sound: export WAV or FLAC for that"). Matroska
carries no sound this project can *write* -- no AAC or Opus encoder here
-- and an AAC track copied in would be one this engine's own reader leaves
silent (`AudioSession::open` refuses Matroska audio). A silent track
written anyway is the one failure a user would not notice.

The encoder pair mirrors H.264's: `rav1e` in software, the plugin's new
`vh_enc_av1_open` on the GPU. The hardware seat is wired, tested and
**opt-in** (`VE_HW_AV1=1`): the vendored cros-codecs AV1 encoder took the
radeonsi box this was written on into an amdgpu hard recovery, and a
driver reset is not an export. `rav1e` is not a new dependency at all --
`ravif` already locks the same 0.8.1 -- and is built with `asm` off (no
`nasm` in this build) and `threading` on: 39 s for the 5 s 720p fixture,
progress reported the whole way.

HEVC and VP9 are rows too, refused by name: no encoder in this stack and
patent-encumbered, and superseded by the AV1 row above.
✨ feat(engine): AV1 import via the VA-API pluginAhmet Kaan Gümüş · 6d3e3ba
✨ feat(engine): AV1 import via the VA-API plugin

AV1 arrives in Matroska, never in an mp4 -- `mp4 0.14` knows no `av01`
sample entry at all -- so the demuxer grows a second container:
`MkvDemuxer` walks the EBML itself, indexes every block of the AV1 track
in one header-only pass (payloads are seeked over) and hands each block
to the decoder as the temporal unit it is, with the `av1C` sequence
header re-injected ahead of every keyframe the way the H.264 parameter
sets are.

Matroska indexes neither the frame count nor the frame rate, which is why
that walk exists: the count is the blocks of the track and the rate is
`DefaultDuration` in nanoseconds (33333333 = 30 fps to seven digits,
where the millisecond block timestamps beside it would say 30.30).
Keyframe flags come out of the same pass, so a seek lands on a sync point
without a Cues element and without guessing at the bitstream.

Audio is picture-only for now: a Matroska file is a silent source and
says so by name ("A_AAC audio in a Matroska file is not wired to the
decoder yet") rather than failing in the mp4 reader's words. 10- and
12-bit AV1 are refused at open like HEVC Main 10, for the same 8-bit
read-back reason.

No new dependency: symphonia's mkv reader drops the keyframe flag and
`DefaultDuration` and offers no frame count, so it could not have done
the job. edith keeps its 7 DT_NEEDED entries.
✨ feat(engine): HEVC import via the VA-API pluginAhmet Kaan Gümüş · 85c152d
✨ feat(engine): HEVC import via the VA-API plugin

The demuxer takes a hev1 track alongside avc1 and vp09. Its parameter sets are
read out of the file by hand: mp4 0.14 reads one byte of hvcC and skips the
rest, so the VPS, SPS and PPS an HEVC decoder cannot start without are
unreachable through the crate. A small ISO-BMFF walk finds the track's hvcC and
the record gives both the parameter sets and the NAL length prefix width -- the
avcC one is now read the same way instead of assumed to be four bytes, which is
one hardcoded guess less on the H.264 path too.

Samples are repacked to Annex-B exactly as H.264's are, parameter sets ahead of
every sync sample, because a hardware decoder that joins the stream at a seek
has nothing else to configure itself from.

Main 10 is refused at open by name: the plugin's NV12 pool and its vaGetImage
read-back are 8-bit, and a 10-bit stream decoded into them would be garbage
shown as a picture rather than an honest no. Same reasoning as the software
refusal, which is now one message shared by every codec that has no software
decoder at all.

The C ABI is unchanged again: the plugin demuxes the file it is given, so an
older libengine_hw.so still loads, still decodes H.264, and simply returns null
for an HEVC path.
✨ feat(engine): VP9 import via the VA-API pluginAhmet Kaan Gümüş · 03a34d3
✨ feat(engine): VP9 import via the VA-API plugin

The demuxer takes a vp09 track alongside avc1 and hands its samples through
untouched -- an mp4 VP9 sample is a self-contained superframe, so there is no
avcC repack and no parameter sets to re-inject. VideoMeta carries the codec,
and the plugin picks its cros-codecs decoder from it.

The C ABI is unchanged on purpose: the plugin demuxes the file it is given,
so the codec is a property of the container rather than of the call, and a
libengine_hw.so built before this still loads and still decodes H.264 -- it
simply returns null for a VP9 path, the same no it gives for an unsupported
profile.

There is no software VP9 decoder to fall back to, so a VP9 file the plugin
will not take is refused at open, by name, where the front-end can show it --
never a black screen, and never VP9 bytes fed to rusty_h264. One timeline
stays one codec, and export re-encodes to H.264 as before; only audio is
ever copied packet for packet.
🐛 fix(engine): NTSC frame rates survive the sample tableAhmet Kaan Gümüş · 3f81ef8
🐛 fix(engine): NTSC frame rates survive the sample table

`mp4 0.14`'s `Mp4Track::frame_rate` divides the sample count by whole
milliseconds before the float cast, so 24000/1001 read back as a flat
23.0: the picture the audio-sample master clock asked for was 4 % out and
the drift grew with the film — five minutes of it by the end of a
two-hour one. The frame rate now comes off the stts totals in f64, which
is exactly `timescale / delta` for a constant table and an average for a
spread one.

The same truncation lived at the writing end (a 90 kHz clock cannot count
23.976 fps in whole ticks), so the muxer picks a timescale that can:
90 kHz wherever it divides exactly — every integer rate, so those exports
are byte for byte what they were — and `round(fps * 1001)` over 1001
ticks otherwise, which is exact for the whole NTSC family. The hardware
encoder gets that same rational instead of a rounded `fps * 1000`.

The video edit list is honoured now too, the way the audio one always
was — but only what it really trims: a `media_time` equal to the first
`ctts` offset is the B-frame composition delay, not a cut, and reading it
as one throws two real frames away.

A file whose audio we cannot decode at all (an AC-3 remux) played silent
with the reason on stderr; the session carries it now and the window says
NO AUDIO in its notice bar.

2026-08-09

✨ feat(engine-hw): vh_enc_* — VA-API H.264 encode with Mesa slice-header fixupAhmet Kaan Gümüş · b75c83e
✨ feat(engine-hw): vh_enc_* — VA-API H.264 encode with Mesa slice-header fixup

The plugin grows an encode half beside the decode one:
vh_enc_open/vh_enc_frame/vh_enc_drain/vh_enc_close, and engine::hw
gains HwEncoder behind a SEPARATE symbol table. That separation is the
point -- a libengine_hw.so predating this commit must keep decoding, so
the four new symbols must not join the decode Plugin struct where a
missing one would take decode down with them. Absent symbols just mean
HwEncoder::open returns None and the caller falls back to the
rusty_h264 software encoder.

Measured on radeonsi (Mesa 26.1.5): 3.98 ms/frame at
1280x720 CBR 4 Mbps including the I420->NV12 upload, against 25.6
ms/frame for rusty_h264 Fast at the same size -- 6.4x. Profile Main,
level 4, LowDelay so there are no B-frames and coded order is display
order; radeonsi exposes no VAEntrypointEncSliceLP for H.264 so
low_power stays off. One reusable DMA-BUF frame carries every picture
because BlockingMode::Blocking plus a poll() in each entry point syncs
the coded and recon promises before returning. Non-16-aligned sizes
allocate aligned surfaces, carry the true size in the SPS crop, and
replicate the edge pixel into the padding rather than shipping gbm
garbage there.

The one ugly part is fix_slice_nal_headers. cros-codecs supplies no
VAEncPackedHeaderH264_Slice, and Mesa fills forbidden_zero_bit /
nal_ref_idc / nal_unit_type only from a packed slice header, so every
slice NAL leaves the encoder with a 0x00 header byte and both ffmpeg
and rusty_h264 refuse the stream. Patching that single byte per slice
makes both decode it fully. An all-zero header byte is never valid
H.264, so the rewrite is a no-op on drivers that write it properly
(Intel iHD, which cros-codecs was built against). Marked ponytail; the
real fix is a packed slice header in vendor/cros-codecs.
✨ feat(engine): seek primitives — video open_at, ao_flush, audio open_atAhmet Kaan Gümüş · 96ae365
✨ feat(engine): seek primitives — video open_at, ao_flush, audio open_at

Lane 1 of the seek slice; PlaybackSession orchestration comes next.

- demux/decode: stss sync lookup, DecodeSession::open_at decodes from
  the keyframe and discards to the target; Frame.index stays absolute.
  HW plugin ABI: vh_open renamed vh_open_at(path, target) — discards
  skip the vaGetImage readback; measured seek cost 65ms HW / 222ms SW
- engine-audio: ao_flush drains the ring consumer-side in the RT
  callback (one-shot atomic), stale PCM unplayable even when paused;
  played-position atomics untouched so clock math survives
- audio: open_at walks stts, 2-packet AAC pre-roll (MDCT overlap
  reconstructed exactly — verified 0-diff before the first PNS band),
  sample-exact trim; priming skip and seek discard unified. AAC seek
  is deliberately not bit-exact: symphonia's PNS noise LCG state
  depends on packet history; bounded <1e-3 by test instead
🎉 feat: MVP decode pipeline — mp4 → H.264 → gpui previewAhmet Kaan Gümüş · 0acbf8d
🎉 feat: MVP decode pipeline — mp4 → H.264 → gpui preview

- engine: mp4 demux → Annex-B, rusty_h264 software decode, BT.601
  I420→BGRA; decode on worker thread behind a bounded channel
- engine-hw: optional VA-API decode plugin (cros-codecs) behind a
  C ABI, dlopen'd at runtime with silent software fallback; the app
  binary keeps zero libva/gbm/drm linkage so it runs on any distro
- app: gpui window, per-frame RenderImage swap + drop_image
- vendor/: cros-libva + cros-codecs with 3 LOCAL PATCH fixes (libva
  1.23 struct init, radeonsi 64x64 min context, pub surface()) —
  upstream is dormant, so vendor/ is adopted code, not a temp fork
- fixtures are gitignored; scripts/gen_fixtures.sh regenerates them