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.
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.
Where the host's video imports device caches (NVDEC), every device cache was
made exportable, whatever its surface. The video writes only two-plane surfaces
(NV12, P010), so a window's or a layer's cache gained nothing from it and paid
for it: metal2vulkan makes each exportable buffer a dedicated allocation, to
which it binds no image, so every texture over every cached surface was a
shadow, copied in before and back after each command buffer that used it.
On a GPU of its own memory the cache maker knew only the first plane's byte of
the layout a cached block's SURFACE_PAGES carries. CacheLayout now carries the
surface's plane count too, and only a cache whose layout gives two planes is
made exportable and gives the video its identity. A cache of one plane, or of
a surface whose pages carry no layout, is made as any other cache.
Measured with a macOS 26.7.2 guest at 3648x2038 on GPUs behind a Thunderbolt 3
link (PCIe x4 Gen3), each step Launchpad or Mission Control held open, ABBA on
one host, development 9e2f9e90f (A) against this change on it (B):
GPU run Launchpad held take-to-show Mission Control held
RTX 2080 A1 24.5/s 66.2 ms 52.1/s
B1 56.8/s 14.9 ms 59.9/s
B2 56.9/s 6.9 ms 60.0/s
A2 24.4/s 66.6 ms 52.1/s
RTX 3090 A1 23.1/s 70.7 ms 51.9/s
B1 55.7/s 20.1 ms 59.8/s
The 3090's B2 and A2 did not run: its Thunderbolt link failed during B2 (a
fatal PCIe error at the dock's bridge, Xid 79). A walk of this change with
video on that 3090 held Launchpad at 56.8/s, 6.9 ms. On the 3090 the shadow
copies went from 151M texels in and 165M back a present to 23M to 36M in and
next to none back. NVDEC still lands every picture in its output's exportable
cache, by the hardware.
What the host observes: timing alone; the guest sees nothing else change. The
exportable allocations and their exports are made for the video's caches
alone, and the caches' count line's "made exportable" counts those. No
degradation kind changes; the warning for a carried layout that does not lie
in its surface now says its cache is made, not placed, as with none.
The aligned byte puts a cache's first plane where an image over its memory
may start, but on the RTX 5080 metal2vulkan makes each exportable buffer its
own dedicated allocation, to which it binds no image, so the NV12 and P010
planes' textures over NVDEC's caches stay shadows wherever the byte lies.
Measured in a 4K60 bar boot: their shadows' cause moved from the texels
sharing a line to the exported memory's, and their count stayed (1424 at
development, 1586 with the byte). The docs said they lie in place; they now
say where that holds.
aligned_byte named a surface's first plane's byte only where it lay off a
multiple of 256 bytes, a figure of the runtime's that our code repeated
(ALIGNED_BYTE_MULTIPLE). It now names the byte wherever the plane starts
past the surface's first, and the platform places it on its own boundary:
on the Vulkan platform the runtime's multiple of 256 bytes
(BufferDescriptor::with_aligned_byte), the largest linear image alignment
measured (RADV's 256 on an RX 550, 128 on an RTX 5080 Laptop GPU). A plane
256 bytes in is now placed by the runtime rather than left to the buffer's
own start; where the buffer starts on that boundary the memory is the same.
For the guest nothing changes: the same answers and the same bytes in its
pages. The asked cache's test now has the platform place a plane 256 bytes
in (an_asked_cache_places_its_first_planes_byte).
NVDEC lands each 4K picture in an exportable device cache, and the guest's
decode names R8 and RG8 textures over its planes 32 bytes into the surface,
as CoreVideo lays them. NVIDIA's linear images need 128 bytes there and
RADV's 256, so every such texture was a metal2vulkan shadow, its plane
copied in before each command buffer's use (1114 of them in one boot of the
5080's 4K60 bar at development). The host now places the cache by the layout
a cached or deferred block's SURFACE_PAGES carries on a device that asks
nothing (CacheLayout::FirstPlaneAt): the surface's first plane's byte goes on
a multiple of 256 bytes of the cache's memory (BufferDescriptor::
with_aligned_byte), as an asked cache's already did, on the exportable route
(new_exportable_buffer_of_length takes the byte, made as BufferDescriptor::
exported_as OpaqueFd) and on a plain cache's (new_buffer_of_length_aligned,
declaring nothing else). A layout that does not lie in the surface's bytes
is logged and places nothing. The copies between a cache and its pages are
unchanged: only the ask's layout makes them take texels alone.
For the guest nothing changes: the same answers and the same bytes in its
pages. On the wire, CACHED and DEFERRED SURFACE_PAGES may carry the layout,
64 to 200 bytes, compatible both ways (the kext's commit before this).
The tests: on Linux, an exportable cache of a 4K NV12 frame made with the
byte takes both planes' textures in its memory (Buffer::
texture_placement_with_iosurface_plane answers NotHostPages; made without
it, both were shadows, printed); the NVDEC landing test lands its pictures
32 bytes into such a cache through CUDA's mapping at the export's offset; a
cached block's layout places its cache alone, a deferred block's alike, a
first plane at the first byte, a layout past the bytes and none place
nothing, and the copies stay whole; the graphics crate hands a cached
message's layout to the host.
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.
A boot of the guest on a Radeon 780M decoded the item's 30 H.264 streams, on
the hardware decoder alone and as a player takes them, beside the MacBook Pro
16 2019's answers: interlaced streams, 4:2:2, 4:4:4, monochrome, lossless and
8192x4320 fail their session's create in the guest as on the Mac's 5300M, and
a 4096x4096 stream now fails it too, at the driver's size check, and decodes
right in software. High 10, FMO, data partitions and SP slices reach the host
only with a picture, and give the 5300M's frames.
T3 says what interlaced streams do now, D25 what is left of it, and devices.md
and design.md where an H.264 decode is checked.
AppleGVA's decode flow takes every query of a decode for its completion
and reads no status or error from it (read from its code on macOS
26.7.1); the one failure it reports to VideoToolbox is a failed
schedule. The driver answered a query of a decode the host was still
running as running and never looked at its token again, so a host
failure that came after the query was lost: the guest got the untouched
surface as a decoded frame and no error. Only a failure the host had
already reported at the query failed the session's next schedule, two
pictures late.
Now the schedule of an HEVC picture waits for the host's verdict on it,
out of the lock that orders the sessions' pictures, and fails where the
host failed it. What changes for the guest: an HEVC decode's
ScheduleCommands returns once the host has decoded the picture, and a
picture the host fails gets kVTVideoDecoderMalfunctionErr itself, from
that frame on, instead of two frames later or never. H.264 is unchanged:
AppleGVA's H.264 pipelines keep no decode's result, so its schedule waits
for no verdict (docs/video/bugs.md D25, now H.264's alone).
The tests that held the deferred failure (failsLaterSchedule,
queryReport) change with it, and checkHostVerdict drives the schedule
through a host that fails one picture.
An HEVC picture that the host refuses was sent anyway, and the refusal came
back only at the host. AppleGVA takes such a picture, and the one after it,
for decoded (D25), so VideoToolbox delivered two wrong frames before
-12911. The refused pictures were: one whose coded size was outside the
caps; one whose PPS had a tile column narrower than the host decodes; and one
whose current reference sets held more pictures than the caps'
max_references, as kvz-720p-ref15's tenth picture does.
The driver now checks each picture against its HEVC decode entry and the
entry's decode caps before it sends it (hevcTaken). It reads NumPicTotalCurr
from the first slice segment's header (h265::currentReferences): its own
short-term set or the SPS's, with prediction, and its long-term pictures.
It works out the PPS's narrowest tile column with 6.5.1's layout
(h265::narrowestTileColumn). A picture that fails the check fails its
schedule. VideoToolbox reports kVTVideoDecoderMalfunctionErr for that frame
and every one after it, where it used to deliver two wrong frames. A bound
of 0 refuses nothing, and a header the driver cannot read leaves the verdict
to the host. kvz-720p-ref15 now decodes 9 frames and then fails, as it does
on an M3's VideoToolbox. H.264 gets no such check: AppleGVA's H.264 decoder
delivers a picture whose schedule failed.
The kext set is built again with the bundle.
The host refuses an HEVC picture whose PPS has a tile column under 128 luma
samples (MIN_TILE_COLUMN_WIDTH), and nothing on the wire said so. The guest
could learn it only after it had scheduled the picture, which AppleGVA takes,
with the picture after it, for decoded.
RgfxVideoCaps gains decode (at 0x510), an RgfxVideoDecodeCaps for each entry.
Its min_tile_width is 128 for HEVC decode on both arms, and 0, no bound, for
every other entry. The kext copies the device info and the caps by their
sizes, so the kext set is built again with the header. The option ROM's
record names the header, so the record is written again too.
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.
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).
The crate that holds the reims-graphics device's wire and transport now
carries the library's prefix, as reims-vgpu-video does: its directory is
crates/reims-vgpu-graphics, its package reims-vgpu-graphics, and its Rust
path and log target reims_vgpu_graphics. The guest's, the option ROM's and
Ambrosia's Makefiles include the wire header from the new directory, and the
prebuilt records name it there.
Nothing changes for the guest or the host. The device keeps its name
(reims-graphics, QEMU's reims-graphics-pci, PCI 1234:5247), and the wire
header keeps its file name and RGFX_ symbols. The C API header is unchanged,
and the prebuilt kexts and option ROM are byte-identical; only the records'
paths and source hashes move. A log filter names the crate's lines by its
new target (REIMS_VGPU_LOG=info,reims_vgpu_graphics=trace), a diagnostic.
devices.md and backends.md described decode alone. They now say what an
encode entry answers (its rate controls and B pictures, and a zero layout,
since both arms read every source by a copy), what an encode op does from its
check to its result and event, how each arm encodes, and the host encode
session's traits and thread. The guest's video driver sends no encode op yet.
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.
A macOS guest hands its VideoToolbox sessions, and its
IOSurfaceAccelerator's scaling and conversion, to the host through two
virtio-PCI devices, 106b:1a03 and 106b:1a0b, as Virtualization.framework
gives them. The library gains their host side, VideoDevice and
ScalerDevice over core's host session and scaler, and QEMU their
transports, apple-videotoolbox-pci and apple-m2scaler-pci, with no
properties of their own.
The library picks each device's backend itself and logs why, on the GPU
apple-gfx-pci's device runs on, taken from the runtime's identity of it:
NVDEC and NVENC on an NVIDIA GPU, else VA-API on its render node, and
VideoToolbox on macOS. The scaler device exists on every host and refuses
its features where it cannot transform; a guest message over 16 MiB is
answered -12904 unread.
For the host: the C API gains rvg_video_device_* and rvg_scaler_device_*,
additively. For the guest: a VM given the devices has the host's video
decode, encode and scaling.
Source: c5b409362 375acb462 8be7593eb fbbeebfb2 e3d5616a4 60d08c4f4 c4c476643
fe105edcb 36a6a82c6 ee2b1ca71 d7d5cfede b15f40717 a07ffd70b bfe6b8338
7433026a9 0030b24a7 64497f931 76acbacc7 3bf366e81 6d3b97a59 fa5b4aafc
401e0b727 1af53ce1a 0fa52d070 ce6eab571 33b40ae4a 82beaf64a ef26f02e1
08bb763c4 5ff2dd73f 62e19c8ef ce406ddb2 fd92f66c4 52fba93c9 e179dc0bd
b5f40ad74 d01bbdc9e 950a7e024 601c23067 9857b1fc8 b427bebfb 55a1d96e7
a0243edfc ef54c395f c23c83073 bc6fcdaa7 1b783baca