Commit Graph
16 Commits
Author SHA1 Message Date
Anees Iqbal 7d153fc6f2 🆕 Write a picture into its dma-buf cache by the driver's VPP
Where the host's video decodes into device caches, a picture the driver's
check refused to decode into its cache (its codec and format), or whose planes
do not lie as a target's must, landed by the runtime device's GPU copy, which
imports the decode surface as images by their DRM format modifiers, and else
by the CPU through the session's staging. On an RX 550 both apply to HEVC Main
10: its radeonsi fails the check's second step for P010 (the first wrong byte,
0x40, is the low byte of the check's 0x5a5a scribble as a 10-bit sample, read
from the reference's overwritten target), and its RADV lists no
VK_EXT_image_drm_format_modifier, so every 10-bit picture was read back and
copied by the CPU. A 26.7.2 guest's walk there (m3-max-21989) played a
2160p30 HEVC Main 10 clip at 22.2 fps with 109 frames dropped.

The cache's memory is a dma-buf the arm already exports for its decodes
(CacheTargets). The arm's first landing, the driver's video processing into a
linear VA surface over a dma-buf of the planes' pages (Frame::write_to_guest),
now also takes such a cache: CacheBytes hands the cache's memory as the
device memory of the write, each range at its own byte of the one dma-buf, and
the write is acquired as a decode into the cache is
(Buffer::external_write_done). Its import goes as the cache does, by the
cache's identity. Where the driver's import check refuses the format or the
planes' alignment, the picture lands as before.

What the guest sees: the same pictures in its outputs, landed in the cache by
the driver's GPU work rather than by the CPU. The session counts such pictures
"in a device cache, by the hardware".

Tests: the ignored hardware test
a_picture_written_into_a_dma_buf_cache_by_video_processing_is_the_cpus_copy,
on a VA-API host with the conformance suite's streams.
2026-11-12 11:53:16 -08:00
Anees Iqbal 2208a41716 🐛 Wait for a video op's cache and GPU copy as long as they take
A video op faulted its command buffer where its surface's device cache was not
filled, or its last picture not copied into its pages, within 2 s; and a VA-API
picture failed where the runtime device's GPU copy of it took over 2 s. The
fault was seen once, behind a 2 s GPU stall on a loaded host. A Mac's video work
waits for the GPU's earlier work on its surface however long it takes.

The op now waits until the fill and the copy are done. Each ends as the
platform sees its command buffer complete, which it does on every path, failed
where the device was lost; a reset of the device ends the wait, as it ends every
wait of the decoder's, so none holds a reset up. A wait past 2 s is named in the
log. The device caches' waits take what ends them in place of a timeout, and a
deferred fill's make is waited for in the same slices, so a reset ends that wait
too where it waited without end before. The plane copier waits on its fence with
the maximum timeout, which Vulkan returns from in finite time once the device is
lost.

For the guest: a decode or encode whose output's or source's device cache is
slow to fill, or slow to be copied out, no longer faults its command buffer
after 2 s, and a VA-API picture whose GPU copy is slow no longer fails its
decode; both wait, and only a reset of the device or a lost device fails them.
2026-11-12 11:53:03 -08:00
Anees Iqbal 9289b2f37f 🐛 Keep a zero-copy import for each buffer's planes in a mapping
VA-API's zero copy kept a guest buffer's import by the mapping's identity
and the frame's size and format alone. One mapping can hold several buffers
of one size: macOS 26.7.2's HEIC decodes (Preview opening a desktop picture,
Freeform's welcome) write each tile of a grid image into one surface at the
tile's own offset. Every tile after the first found the first tile's import,
so its frame was written over the first tile's planes, the check that
declines a luma plane off a page's start on iHD was skipped, and the guest
showed the other tiles as zero YUV (green) on the Iris Xe.

The import is now kept by the place and pitch of the buffer's planes as well:
core's DeviceImports takes a variant of the backend's own type, compared
whole. What changes for the guest: each tile's frame lands in its own planes,
or is copied by the CPU where the driver takes no import of them. The new
VA-API test writes two buffers of one memory, stacked and side by side, and
failed with the old key on the Iris Xe.
2026-11-11 02:27:46 -08:00
Anees Iqbal 7e264b6dbd 🔥 Hold GPUs through potluck alone and remove gpu-locks.sh
Every build, test, boot and copy on the shared machines has run as a
potluck job since 11-05, and the job's lease is the lock: --gpu holds a
GPU, --exclusive gives a timing run the whole machine. gpu-locks.sh and
metal2vulkan's maclock took lock files potluck never sees, so a run under
them could still share a GPU with a potluck job.

AGENTS.md, the boot section of docs/qemu.md, the video checks, the cost
benches' docs and the oracle README now name potluck's lease. The
conformance scripts take no lock of their own, and lane-gate runs its
tests under its job's lease. A build holds no GPU: it builds in a job
without --gpu, and the tests run in the same workspace holding one.
2026-11-10 23:17:59 -08:00
Anees Iqbal f77c620de6 ✅ Run the VA target probe by hand, outside the VA check
The documented VA-API check, `cargo nextest run -p reims-vgpu-video
--run-ignored only -E 'test(/^vaapi::/)'`, failed from a clean checkout:
the target probe's ignored test, in that set, needs RVG_VA_STREAMS, the
streams the conformance scripts write with x264, x265 and ffmpeg.

The probe becomes a tool rather than a test, since the target check's own
tests are the check. The probe prints how many pictures of each way came
out as the driver's own surfaces', and asserts only that it decoded
something; the target check's tests check every byte of their targets'
memory after each picture, and run in the set with no streams. Taking the
streams where the scripts leave them would still fail from a clean
checkout, and running the probe inside the scripts would add its decodes,
about 150 s on a 780M, with no verdict, to every conformance run.

The tool is an ignored test at the crate's root (`probes::`), outside the
`vaapi::` and `nvidia::` sets the hardware hosts' checks run, as the
fuzzers' long runs and reims-vgpu's RVG_VA_STREAMS tests sit outside them.
It is not an example: an example reaches only the public API, and the
probe's import hook (`surface::MAKE_SURFACE`), which has every surface a
decoder's pool makes imported over the probe's memory, exists only in a
test build. Its code and unsafe blocks stay in the `va` module. Without
RVG_VA_STREAMS it still fails, naming it. Nothing it compares changed.
2026-11-08 18:20:43 -08:00
Anees Iqbal 822ff54fc7 🐛 Answer H.264's largest size at most 4096 wide under the macroblock bound
The cut of the VA arm's H.264 answer to 65,535 macroblocks kept the driver's
largest width and lowered the height. radeonsi answers 4096x4096, which came
out as 4096x4080, but iHD answers 8192x8192 in VAConfigAttribMaxPictureWidth
and Height, which came out as 8192x2032: the guest's video driver would then
refuse 3840x2160 and every H.264 stream taller than 2032 at its create, and
VideoToolbox would decode 4K H.264 in software on Intel hosts.

iHD decodes nothing wider than 4096: its surfaces' bound is 4096x4096, and
ffmpeg's VA-API decode refuses every size from 4112x2160 to 8192x1024 on an
Iris Xe (iHD 26.3.5). So where the driver's largest size holds more than the
bound, the answer is at most 4096 wide and as tall as the bound leaves there:
4096x4080 on both drivers, holding 3840x2160 and 4096x2160. The test now
feeds iHD's answer too, and the sizes users play.

For the guest: on an iHD host H.264's largest size is 4096x4080, where it was
8192x2032 since the bound came in.
2026-11-08 16:51:38 -08:00
Anees Iqbal 2d5d6a4003 🐛 Keep H.264 pictures under the macroblocks VA's drivers decode
iHD and radeonsi answer 4096x4096 as their largest H.264 decode, yet give
every frame of a 4096x4096 stream back with its luma all zeros, every call
succeeding: ffmpeg's VA-API decode as ours, on an Iris Xe, an RX 7900 XTX
and a Radeon 780M. 4096x4080, 4080x4096 and 15 other sizes decode right.
4096x4096 is the one size within the drivers' bound of 65,536 macroblocks.

So the VA decoder refuses a picture of more than 65,535 macroblocks at its
SPS, and the graphics device answers H.264's largest size under the bound,
4096x4096 as 4096x4080: the guest's video driver then refuses such a stream
at its create, and VideoToolbox decodes it in software, where before every
frame reached the guest black. Recorded as bugs.md U28.
2026-11-08 16:37:43 -08:00
Anees Iqbal 020efddfc1 🐛 Decode H.264's Extended profile where its slices use only Main's tools
The codec module refused every SPS of profile_idc 88, at the first picture,
which through the graphics device reaches the guest as undecoded frames:
AppleGVA's H.264 decoder hears of no failure. Apple's AVC decoder on an x86-64
Mac decodes such a stream in hardware (measured on a Radeon Pro 5300M's
AppleGVA flow and an Intel UHD 630's, macOS 26.7.1: JM 19's Extended stream of
CAVLC B slices decoded as JM's reconstruction). Its pictures are Main's where
they use none of Extended's own tools, so the SPS is taken, the VA-API arm
asks for VA's Main profile, else High, and data partitioning and SP and SI
slices stay refused at the slices that use them.

For the guest: an Extended stream now decodes on the host where it reached the
client as undecoded frames.
2026-11-08 16:37:43 -08:00
Anees Iqbal 5dfba088f8 🐛 Decode HEVC tile columns from 128 samples and rows of any height
The HEVC decoder refused a PPS with a tile column under 256 luma samples or a
row under 64, the Main profiles' bounds (A.3.2 to A.3.4), after the guest had
scheduled the picture. kvazaar writes such streams without a warning. The
hardware decodes them: columns of 128 and 192 samples and rows of 16 and 64
matched kvazaar's MD5 SEI and reconstruction on every frame on radeonsi (a
Radeon 780M), on iHD (an Iris Xe), on NVDEC (an RTX 5080 Laptop GPU), and on an
x86-64 Mac's Apple decoders (Intel UHD 630, and AMD's driver on a Radeon Pro
5300M). A column of 64 samples, one CTB of 64, came out wrong on every frame,
with no error, on radeonsi and on the Mac's AMD driver, and right on NVDEC and
the Intel ones.

The decoder now refuses only tile columns under MIN_TILE_COLUMN_WIDTH, 128.
No driver reports the bound, so it is the same on every host. For the guest,
kvz-720p-tiles-narrow (a 192-sample column) and a stream with a row of 16
decode on every frame. A stream with columns of 64 is still refused.
hevc-check.sh decodes kvz-720p-tiles-narrow and kvz-720p-tiles-short, and
expects kvz-720p-tiles-col64 to be refused at its PPS.
2026-11-08 12:47:31 -08:00
Anees Iqbal 4d76e9b642 🐎 Land VA-API pictures in device caches where memory is shared
What changes for the guest: on a host whose GPU shares the CPU's memory
(RGFX_FEATURE_SURFACE_CACHE_REFUSED), with VA-API's hardware video (the
Radeon 780M's radeonsi, the Iris Xe's iHD), the video caps now say
RGFX_VIDEO_CAPS_OUTPUT_CACHED, with no output layouts, as a host of a GPU
of its own memory says them where its video lands pictures in caches. The
guest's video driver then asks its output surfaces cached, with their
layout, as any other surface (RgfxAskUncachedScope no longer covers them),
and the device keeps a cache of those it answers RGFX_STATUS_CACHE: an
output whose textures would not lie in place in its pages, or whose view
has no room for its mappings. A picture lands in such a cache by the
runtime device's copy of the decode surface (or the CPU's, through the
session's staging, where that copy is refused), and a CPU read of a decoded
frame has the cache copied out into its pages first. An output that lies
in place stays in its pages, as before.

For the host: VaapiVideo::lands_in_device_caches is true, and the device
offers cached outputs wherever the kext makes caches (video_caps, out of
GraphicsDevice::with_platform). The caches lay the first plane on 256
bytes of their memory (the commit before), so textures over the decoded
planes lie in them rather than in the runtime's shadows.

Measured on guest boots of macOS 26.7.2, Safari playing 4K60 HEVC clips
(8-bit, then 10-bit; then two and three at once), against development
81f187735 on the same host, vm.max_map_count 1048576, before this change
was rebased onto development's df50639ea (a laid-out cache's bytes between
rows declared unobserved), which the boots did not include:

- Radeon 780M (radeonsi and RADV, Mesa 26.2.6): the runtime's shadow
  texels copied in per presented frame fell from 10.2-15.6 M to 0.00-0.03 M.
  18 of 85 sessions landed in caches (4K outputs whose planes exceed
  udmabuf's 1024 pieces), the rest in place; 148 caches were made aligned.
  Presented fps 55.8/55.5 single, 53.9/57.0 two, 52.1/51.9/54.0 three
  (development 57.0/57.2, 56.0/57.5, 53.9/53.3/52.6), drops 14/14/6 at
  three (13/15/5). Mappings 5.7-6.6 k both.
- Iris Xe (iHD, ANV Mesa 26.2.6), where ANV answers a cache for every
  surface: all 85 sessions landed in caches, and the process's mappings
  peaked at 13.3 k (311 k on development). Shadow texels 0.07-0.32 M per
  frame both. Presented fps 53.3/54.0 single, 54.4/53.6 two,
  54.5/55.2/55.0 three (development 57.1/56.6, 55.4/53.9, 54.0/51.8/54.0),
  at most 2 drops a clip; a second pair of boots, development's first,
  gave 56.5/55.4 single (development 54.1/55.7): the single clips' spread
  is the boots', not the change's.
- Both: 0 pictures copied by the CPU, 0 fatal lines. A guest process
  reading every decoded frame on the CPU (decode_md5 against ffmpeg's
  framemd5) matched on 63 of 75 streams both ways, the same 12 failing on
  development, the three 4K streams (in caches) among those matching. The
  byte-exact test lands every third of 4951 pictures of the conformance
  streams in a cache made as the device makes one, equal to the CPU's copy.
- RTX 5080 Laptop GPU (NVDEC): its caps and caches are as before (no cache
  made aligned); the boot's playback swung as development's does there.
2026-11-08 10:33:54 -08:00
Anees Iqbal 24fa54079b 🐎 Copy VA-API pictures into the guest's planes on the GPU
On VA-API every picture the reims-graphics device decoded was read back and
copied into the guest's output planes by the CPU (B93): CoreVideo lays each
plane 32 bytes into its page, and neither radeonsi's nor iHD's video
processing writes that layout, so the in-place write declined every picture.

Where the in-place write declines, the arm now exports the decode surface as
dma-bufs (vaExportSurfaceHandle, each plane a layer of its own, kept with the
surface's pool), imports each plane once into the runtime device as an image
of its DRM format modifier, and copies it with vkCmdCopyImageToBuffer into the
buffer the output plane lies in, the surface's pages or its device cache, at
the plane's offset and rows: the Vulkan platform's PlaneCopier, one a session
on a runtime queue of its own, which waits for the copy on a fence. The copy
writes the crop the CPU's copy writes and nothing past it, after the decode is
done, and the session signals the decode once the copy is done on the GPU.

Which way each host's pictures take, in order, each where those before it
refuse:
- radeonsi (Radeon 780M, Mesa 26.2.6): the in-place write declines
  CoreVideo's planes (it imports planes 256 bytes apart alone); every picture
  lands by the GPU's copy: radeonsi exports one object of modifier
  0x200000010401b04, and RADV imports each plane.
- iHD (Iris Xe, intel-media-driver 26.3.5): the in-place write declines them
  (iHD writes a plane only at its dma-buf's first byte, U26); every picture
  lands by the GPU's copy: iHD exports one Y-tiled object (0x100000000000002),
  and ANV imports each plane.
- A host whose driver exports a surface other than as a layer a plane, whose
  runtime device lists none of the dma-buf image extensions or refuses the
  modifier for the plane's format, or whose plane lies in a buffer the GPU's
  writes do not reach (pages the runtime copies, a detached buffer): the CPU's
  copy, as before. The session logs each reason once at that point, as `a
  picture copied by the CPU: <the in-place write's refusal>; and the GPU's
  copy: <its refusal>`, or `; and no GPU copy: <why>` where the device made
  the session no copier.
The in-place write stays first wherever the import check passes for the
planes' layout.

For the guest nothing changes: the planes hold the same bytes, padding
included, and the decode's event and completion come as before. For the
host, the pictures land by the hardware instead of the CPU, the session's
counts say so, and each session logs its GPU copies and their GPU time at its
end.

Checked on the Radeon 780M and the Iris Xe: the conformance suites
(h264-check.sh 62 and hevc-check.sh 156 checks pass on each), the video
crate's ignored VA tests (15 on each), and a new ignored test,
a_picture_copied_by_the_gpu_is_the_cpus_copy_byte_for_byte, which lands every
picture of the suites' Annex B streams by the GPU's copy and by the CPU's into
the same CoreVideo-like layout at two pitches and compares every byte: 4849
pictures of 79 streams equal on the 780M, 4951 on the Iris (the latter going
on past the leading pictures random access skips). The workspace's Linux
tests pass on the radeonsi host (1862).

In cold boots of a macOS 26.7.2 guest playing 4K 60 fps HEVC in Safari,
against the arm before it on the same GPU: on the 780M no picture was copied
by the CPU (9979 before), 10000 by the GPU at 1.01 ms of GPU time each, and
three clips at once played at 53.2, 53.7 and 52.5 fps with 3, 2 and 0 frames
dropped (50.0, 50.3, 52.0 and 10, 11, 5 before); on the Iris none (9899
before), 10040 at 0.52 ms each, 53.8, 54.2 and 56.4 fps with 4, 3 and 0
dropped (52.3, 51.7, 53.5 and 71, 74, 1 before).
2026-11-08 06:52:46 -08:00
Anees Iqbal f3b120ad16 🎨 Collapse the video crates into reims-vgpu-video
The host's video was five crates: core, codec, conformance, and the VA-API
and NVIDIA backends, with the examples and tools split between two of them.
One device uses them, from one library. They become one crate,
crates/reims-vgpu-video, with the modules core, codec, vaapi and nvidia, the
last two built on Linux alone. The conformance readers and writers, which only
the examples use, stay a crate of their own beside it, at
crates/reims-vgpu-video/conformance (reims-vgpu-video-conformance). The files
move with git mv, their paths rewritten, with no re-exports left behind. The
NVIDIA examples build on every host, as a stub off Linux.

Dead code goes with them: NVDEC's VP9 path and the codecs nothing asks it for
(NvdecCodec is H.264 and HEVC), and the Vulkan platform's listing of the
host's GPUs (host_gpus::hardware_gpus and gpu_device_gpu), which nothing
called, with its serde_json dependency.

AGENTS.md, development.md, docs/video and the nextest filter name the one
crate.
2026-11-07 21:32:05 -08:00
Anees Iqbal 3b3a5a7fa4 📝 Keep docs/video to the graphics device's video [ci skip]
The paravirt video devices, their JPEG engine and scaler, and Vulkan Video
are gone, so docs/video says only what is left: the reims-graphics device's
video on NVDEC or VA-API, and the crates under it.

- devices.md: what the device answers the guest (the caps, the layouts,
  OUTPUT_CACHED where NVDEC lands pictures in device caches) and what a
  decode does, on each arm.
- backends.md: the two arms, their crates and traits, and the conformance
  suite, which is VA-API's h264-check.sh and hevc-check.sh.
- core.md, vaapi.md and nvidia.md: the crates as they stand; vaapi.md adds
  the 2026-11-07 runs of both scripts on the Iris Xe and a Radeon 780M.
- bugs.md keeps the entries the code and the other docs cite that still
  hold, rewritten without the deleted devices; B26 is condensed.
- scaler.md, videotoolbox.md, hardening.md and vulkan.md go.
- AGENTS.md's video rows name the arms, the docs and the two scripts.
2026-11-07 19:55:37 -08:00
Anees Iqbal e7b22b2318 📝 Document the VA-API import check and graphics arm [ci skip]
The VA-API doc still named a list of drivers trusted with imports, which
the import check replaced, and imports of a dma-buf a plane, now one of
both planes. It said nothing of the reims-graphics device's arm. bugs.md
said Intel's drivers were not measured.

vaapi.md gains "The import check" (what it tries, the drivers' answers,
its cost, the sweep) and "The reims-graphics device" (the chooser, the
two landings, the boots' results). The staged copy back's whole-rows
layout and zero copy's one dma-buf are described as they now are.
bugs.md gains U26, iHD's writes into an import, and B93: on VA-API the
device's pictures are all copied by the CPU, since CoreVideo's layout
of the guest's frames is one neither driver's video processing writes.
2026-11-07 19:03:06 -08:00
Anees Iqbal e0208b1571 ✅ Pass a JPEG refusal outside what the backend answers
Core's JpegDecoder now answers what its backend decodes at all
(JpegDecodes: the samplings and the largest picture): VA-API's the
samplings its driver lists and its largest size, NVIDIA's the four it
measures at any size. The guest hears of it only through the refusals it
already got, so nothing it sees changes.

The conformance suite's jpeg-check reads it. A stream outside the answer
that a case asked to decode now passes when refused as UnsupportedStream
("refused as answered"), and fails when it decodes; inside the answer every
refusal fails, as before. jpeg-check.sh's last line counts the passes, the
refused as answered among them, and the failures.

On an RX 550 (radeonsi, Polaris 12) the driver lists 4:2:0, 4:2:2 and grey
up to 4096x4096, so 19 cases failed on development (job 4315): every 4:4:4
one, and the 16384-wide 4:2:2 case. Each was the engine refusing a stream
by the driver's own answer.
2026-11-07 10:57:33 -08:00
Anees Iqbal 833e496af1 🆕 Add the VA-API video backend
reims-vgpu-video-vaapi is the host's codecs on Linux through libva, with no
codec layer between: H.264, HEVC, VP9 and AV1 decoders through one generic
session, H.264 and HEVC encoders, and a JPEG engine whose outputs are read
into host memory of its own, in strips past 64 MiB. Its waits on the GPU
are bounded at 5 s, inside the driver too, processing runs wait outside
the driver's lock, and every picture begun is ended. hevc-craft and
vp9-craft make streams no encoder here writes, and docs/video/vaapi.md
records what radeonsi and NVIDIA's VA-API driver answer.

Source: c5b409362 eb70a2030 db99192cc e3d5616a4 7cef9973a 1148ce260 60d08c4f4
        efbcf2dbb c4c476643 31bad2301 a07ffd70b b7455918b 3ff9083c6 3bf366e81
        6d3b97a59 a10ff547d 1ccde0ef6 d763ddffd 30c2cef88 41235220c 319bc132e
        1a0d1c3da d9b09f352 dc672b5cc 33b40ae4a 77609a028 8ac416039 118f49023
        76951e3ea 939f635ee 505569531 9400f48cb 9e050f933 62e19c8ef 0c2d725b3
        c8c7b3400 95ce68182 b5f40ad74 d01bbdc9e 601c23067 a0243edfc 96f459104
        8c58f98c4 eef22173d ab8fc3c4d 745cef197 7d74266f5 22625b578 73e48ad5a
        986872956 b63299e88 096878653
2026-10-26 12:24:31 +02:00