🆕 Give reims-ctl's VMs the VideoToolbox and M2 scaler devices

QEMU has had apple-videotoolbox-pci and apple-m2scaler-pci since the video
devices landed, but reims-ctl never put them on a VM's command line, so no VM
it starts had them, and the drivers reims-util 381f913 puts in x86-64 images
had nothing to drive.

Every VM on reims-vgpu now gets both. An x86-64 VM has them at slots 8 and 9,
after the IOSurface mapper their ported drivers link; one on vmware-svga, which
has no mapper, gets neither. A vmapple VM gets them too: arm64 macOS ships the
drivers, which link the mapper vmapple builds in. A guest without the drivers
leaves the devices without one. docs/video/bugs.md's D6, the images without
the kexts, goes.

Both devices realize on the installed QEMU (paused, on an arm64 machine's
PCIe bus). No guest has booted with them from reims-ctl's command yet, and no
arm64 guest has run against them at all (bugs.md T9).
This commit is contained in:
Anees Iqbal committed 2026-10-26 14:18:08 +02:00
1 parent 599fbe46be
commit 054ac2080e
3 files changed
+43 -5

No files matched your search

+38 -1
View File
@@ -48,7 +48,15 @@
//! no Wayland compositor or X server, GTK's window would end QEMU as it starts, so it is
//! `-display none` there, and the guest runs headless, as on the library's window.
//!
//! `vmapple-arm64` follows scripts/internal/run_vmapple.sh.
//! Every VM on reims-vgpu also has the VideoToolbox device (`apple-videotoolbox-pci`, 106b:1a03)
//! and the M2 scaler device (`apple-m2scaler-pci`, 106b:1a0b). arm64 macOS ships their guest
//! drivers, which link the IOSurface mapper vmapple builds in. x86-64 macOS ships none:
//! reims-util's images carry ports of them for macOS 26.7 (reims_util.rs), which link the port's
//! mapper driver, so an x86-64 VM has the devices at slots 8 and 9, after its mapper, and one on
//! `vmware-svga`, which has no mapper, has neither. A guest without the drivers leaves both
//! devices without one (docs/qemu.md, "The VideoToolbox device" and "The M2 scaler device").
//!
//! `vmapple-arm64` follows scripts/internal/run_vmapple.sh, with the video devices besides.
use crate::host::{Host, Os, Profile};
use crate::vm::{Graphics, Vm};
@@ -275,6 +283,13 @@ fn q35(vm: &Vm, ctx: &Ctx, a: &mut Vec<String>) -> Result<()> {
"-device",
"apple-gfx-iosurface-pci,id=iosfc,gpu=gfx,bus=pcie.0,addr=0x6",
]);
// The video devices, whose guest drivers link the mapper's (the module doc).
push(&[
"-device",
"apple-videotoolbox-pci,id=video,bus=pcie.0,addr=0x8",
"-device",
"apple-m2scaler-pci,id=scaler,bus=pcie.0,addr=0x9",
]);
}
push(&[
"-device",
@@ -347,6 +362,13 @@ fn vmapple(vm: &Vm, ctx: &Ctx, a: &mut Vec<String>) -> Result<()> {
"-global",
&format!("apple-gfx-mmio.resolution={}", c.display.qemu_resolution()?),
]);
// The video devices, whose guest drivers arm64 macOS ships (the module doc).
push(&[
"-device",
"apple-videotoolbox-pci,id=video",
"-device",
"apple-m2scaler-pci,id=scaler",
]);
if c.audio.enabled {
push(&["-audiodev", &audiodev(vm, ctx)]);
push(&["-device", "virtio-sound-pci,id=audio,audiodev=snd0"]);
@@ -565,6 +587,14 @@ mod tests {
"-device",
"apple-gfx-iosurface-pci,id=iosfc,gpu=gfx,bus=pcie.0,addr=0x6",
],
&[
"-device",
"apple-videotoolbox-pci,id=video,bus=pcie.0,addr=0x8",
],
&[
"-device",
"apple-m2scaler-pci,id=scaler,bus=pcie.0,addr=0x9",
],
&[
"-device",
"qemu-xhci,id=xhci,addr=0x5,conditional-intr-mapping=on",
@@ -754,6 +784,11 @@ mod tests {
));
assert!(has(a, &["-display", "gtk"]));
assert!(!a.iter().any(|x| x.contains("apple-gfx")), "{a:?}");
assert!(
!a.iter()
.any(|x| x.starts_with("apple-videotoolbox") || x.starts_with("apple-m2scaler")),
"no video devices without the mapper their drivers link: {a:?}"
);
assert!(inv.env.is_empty(), "{:?}", inv.env);
// Without a screen for the window, headless.
let headless = Ctx {
@@ -791,6 +826,8 @@ mod tests {
&["-device", "vmapple-virtio-blk-pci,variant=root,drive=root"],
&["-global", "apple-gfx-mmio.displays=2"],
&["-global", "apple-gfx-mmio.resolution=1920x1080"],
&["-device", "apple-videotoolbox-pci,id=video"],
&["-device", "apple-m2scaler-pci,id=scaler"],
&["-audiodev", "coreaudio,id=snd0"],
&["-device", "virtio-sound-pci,id=audio,audiodev=snd0"],
] {
+4 -2
View File
@@ -201,7 +201,8 @@ on its render node, and the host's first hardware GPU that offers video,
discrete ones first, where that GPU is a software rasterizer or offers
none. The library logs its choice and why; where no backend opens, the
guest is offered no codec and decodes in software. A VM takes it as
`-device apple-videotoolbox-pci`.
`-device apple-videotoolbox-pci`; reims-ctl gives every VM on reims-vgpu
one, an x86-64 VM's at slot 8.
Queue 0's elements go to `rvg_video_device_deliver`, gathered across
descriptors, and its status is scattered into the writable part; one whose
readable part is over 16 MiB (`RVG_VIDEO_MAX_MESSAGE_SIZE`) is answered
@@ -290,7 +291,8 @@ and the device's `validate_features` refuses the guest's features
stays unset. The guest kext reads its status back, fails its start before
DRIVER_OK, writes FAILED and registers no service, and the guest's
IOSurfaceAccelerator does without it ([video/scaler.md](video/scaler.md),
"A host without a GPU"). A VM takes it as `-device apple-m2scaler-pci`.
"A host without a GPU"). A VM takes it as `-device apple-m2scaler-pci`;
reims-ctl gives every VM on reims-vgpu one, an x86-64 VM's at slot 9.
Each queue element's readable part, at most 64 KiB, is copied into one
buffer for `rvg_scaler_device_process`, which answers in place. A longer
one is a needs-reset before anything is allocated or copied, as the
+1 -2
View File
@@ -469,11 +469,10 @@ Bugs in drivers, libraries and tools that our code or our checks work around.
- **D3. VideoToolbox in an x86_64 guest does not use the scaler.** `VTPixelTransferSession` and `VTPixelRotationSession` ran in an x86_64 guest, with nothing reaching the host. That is the guest's choice, not ours.
- **D4. AV1 profiles 1 and 2** (4:4:4, 4:2:2, 12-bit) are not listed: core has no such pixel formats, and the Radeon 780M has no Profile 2.
- **D5. An arm64 Linux host:** a host running `vmapple` on KVM on Apple silicon (Asahi), with libva-v4l2_request, is not built, as there is no such machine to run it on.
- **D6. Users' OpenCore images carry no guest kexts for the devices.** An x86_64 guest lacks the video and scaler kexts and the mapper they link ([devices.md](devices.md), "What an x86_64 guest has"); their x86_64 ports, and VtWaitPatch (D11), are in our test VMs alone. Putting them in the images reims-util makes (`crates/reims-ctl/src/reims_util.rs` pins it) is reims-util's change, and waits for the owner's word, as every release does.
- **D7. JPEG 4:1:1, and JPEG encode.** radeonsi lists no `YUV411` render target for JPEG and no JPEG encoder on an RX 7900 XTX or a Radeon 780M, and nvJPEG's hardware decoder refuses 4:1:1 (`NVJPEG_STATUS_JPEG_NOT_SUPPORTED`) on an RTX 5080 Laptop GPU (**measured**, libnvjpeg 13.2.3, 2026-10-25), so the engine refuses 4:1:1 streams on both with kIOReturnBadMedia and answers every `jenc` with -16994 ([vaapi.md](vaapi.md), "The JPEG decoder"; [nvidia.md](nvidia.md), "The JPEG engine"). On NVIDIA both could be had: nvJPEG's hybrid decoder decodes 4:1:1 within 1 of libjpeg, at scale 1 alone, and its GPU encoder (`nvjpegEncodeYUV`) encodes 4:4:4, 4:2:2, 4:2:0, 4:4:0, 4:1:1 and grey, 4000x3000 4:2:0 in 0.97 ms and 16384x16000 in 10 ms on the GPU, each stream decoding in libjpeg-turbo 3.2.0 with no warning (**measured**, same GPU and day; its hardware encoder answers `NVJPEG_STATUS_ARCH_MISMATCH`). Put off: core has no encode path for `jenc`, whose options are not read ([devices.md](devices.md), "The JPEG engine"), and Apple's answer to a 4:1:1 decode is not measured. To add encode: read CMPhoto's `jenc` options and its destination in a guest, then an encoder part in core's backend, then nvJPEG's encode behind it.
- **D8. ProRes, a JPEG engine and 4:2:2 or 4:4:4 decode on VideoToolbox.** Apple's host offers ProRes and JPEG decoders to its guest ([devices.md](devices.md)), and the M3 Max's VideoToolbox decodes both in hardware, and lists 4:2:2 and 4:4:4 profiles of H.264, HEVC and AV1 besides ([devices.md](devices.md), "How the guest finds the host's codecs", "The levels Apple lists", and "AV1", `dcap` for `av01`). Core has no ProRes codec and no pixel formats past 4:2:0, and the VideoToolbox backend has no JPEG engine ([videotoolbox.md](videotoolbox.md), "ProRes", "JPEG").
- **D10. No tool copies a test VM between hosts.** The first VM on the NVIDIA host was made from a Radeon host's VM by hand: a snapshot, its free space zeroed in a scratch VM, `qemu-img convert`, and a copy over the network. A tool that crosses hosts waits until a second cross-host VM is wanted, since the next VM on that host is better copied from the one there.
- **D11. VtWaitPatch knows only 25G241's convert pages.** The guest plugin that makes an x86_64 guest's 10 s reply waits hold ([devices.md](devices.md), "What an x86_64 guest has") patches the guest's timeout conversion where a validated page's SHA-256 is that of 25G241's `x86_64` or `x86_64h` convert page, and arms nothing on any other. Another guest build needs its digests, its two sites' offsets and a proof read from its own caches, and a boot; until then that guest's 10 s waits expire at once, as Apple's x86_64 build has them. It waits for a second guest build. The plugin is in our test VMs alone (D6).
- **D11. VtWaitPatch knows only 25G241's convert pages.** The guest plugin that makes an x86_64 guest's 10 s reply waits hold ([devices.md](devices.md), "What an x86_64 guest has") patches the guest's timeout conversion where a validated page's SHA-256 is that of 25G241's `x86_64` or `x86_64h` convert page, and arms nothing on any other. Another guest build needs its digests, its two sites' offsets and a proof read from its own caches, and a boot; until then that guest's 10 s waits expire at once, as Apple's x86_64 build has them. It waits for a second guest build. reims-util's OpenCore images carry the plugin, with the two drivers.
- **D12. NVENC runs without lookahead.** The NVIDIA backend turns it off in every preset's configuration (`crates/reims-vgpu-video-nvidia/src/nvenc/encoder.rs`), since with it on frames are lost (U6). P6 and P7 lose the quality lookahead brings, unmeasured.
- **D14. NVIDIA's smallest frames are larger than Apple's.** NVDEC decodes VP9 and AV1 from 128x128 and HEVC from 144x144, so a session with a side of 64 to 127 (143 for HEVC), which Apple's host decodes, is refused at `dsta` with -12911, as Apple's decoder refuses a size it does not decode, so that the guest decodes it itself. NVDEC's H.264 starts at 48x64, below AVD's 64, and so decodes there ([devices.md](devices.md), "Where we differ from Apple"). NVENC encodes H.264 from 145x49 and HEVC from 129x33, so smaller `esta`s are refused. Each is the driver's answer (**measured** with `nvidia-probe`, RTX 5080 Laptop GPU, 2026-10-24).
- **D15. NVENC's AV1 encoder is not offered.** NVENC lists AV1 Main on an RTX 5080 Laptop GPU, but core's encoders are H.264 and HEVC.