forge
Explore
Log in

Don't you dare go Hollow

Commits

Commits on b8aec297d78df52fc2faa266cc7303687f64e205Filtered to crates/engine/tests/hw_encode.rsClear filter

2026-09-12

♻️ 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).

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

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

2026-08-13

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

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.