Files
Anees Iqbal 4c07913bc7 📝 Say a Windows host encodes the guest's video in software on every GPU [ci skip]
README.md and docs/video/devices.md said the guest encodes in software on an
Intel UHD 630, as if another GPU could encode on Windows. The Windows arm opens
with encodes off on every GPU (open_on_rt in graphics/vaapi.rs), since rt imports
no shared Direct3D 12 texture, so no Windows host lists an encoder today.
2026-11-26 13:18:48 -08:00

328 lines
21 KiB
Markdown

# reims-vgpu
[![License: GPL-2.0-or-later OR LGPL-3.0-or-later](https://img.shields.io/badge/License-GPL--2.0--or--later%20OR%20LGPL--3.0--or--later-blue.svg)](LICENSE) [![Discord](https://img.shields.io/badge/Discord-Join%20the%20community-5865F2?logo=discord&logoColor=white)](https://discord.gg/D2AM9mrDgs)
> **Beta.** reims-vgpu has largely stabilized. We're now working through differences between
> platforms and GPU drivers, so how well it runs can still depend on your host and its GPU.
> [docs/known-issues.md](docs/known-issues.md) lists what we know is wrong right now.
reims-vgpu is a virtual GPU for macOS VMs. It gives x86-64 macOS running in QEMU on Linux or
Windows accelerated graphics, on your GPU's Vulkan driver. The guest drives it with macOS drivers
of our own, which `reims-ctl` puts in the VM's OpenCore image, so there's nothing to install in the
guest yourself.
Alongside the GPU, we ship a QEMU build that uses it, and `reims-ctl`, a small tool that creates
and runs macOS VMs for you.
![reims-vgpu running an x86_64 macOS 26 Tahoe guest desktop on a Linux host](assets/readme/reims-vgpu-macos-x86-desktop.png)
*x86_64 macOS 26 Tahoe guest on a Linux host.*
![reims-vgpu running an arm64 macOS 26 Tahoe guest desktop on an Apple Silicon host](assets/readme/reims-vgpu-macos-arm64-desktop.png)
*arm64 macOS 26 Tahoe guest on an Apple Silicon host.*
## Getting started
We don't ship disk images: macOS comes straight from Apple. `reims-ctl` downloads the installer
from Apple and sets the VM up for you, or uses a disk that already has macOS on it.
x86-64 macOS needs an x86-64 Linux host or an x86-64 Windows PC. Our drivers load on macOS 26.4
and later for now; we've tested macOS 26 on an RTX 5080 laptop GPU and a Radeon 780M on Linux, and
on an Intel UHD 630 on Windows 11.
On Linux, a VM on our virtual GPU needs Linux 7.2 or later. Before 7.2, the kernel hands an AMD
GPU the wrong pages of the guest's memory, which can overwrite it. `reims-ctl` won't start one on
an older kernel, and `reims-ctl doctor` shows the kernel it found.
arm64 macOS 14 to 27 runs on QEMU too, with Ambrosia, our own arm64 firmware, and the same virtual
GPU. On an Apple silicon Mac it runs under HVF, macOS's hypervisor, and on arm64 Linux under KVM.
An x86-64 Linux host runs arm64 VMs as well, with QEMU emulating the CPU (TCG), which is much
slower; we've checked macOS 14, 15 and 26 that way. `reims-ctl` makes an arm64 VM by restoring
macOS from an IPSW, Apple's restore image, onto a new disk, and boots it with Ambrosia, which adds
our drivers to the guest as it starts. [docs/qemu.md](docs/qemu.md), "arm64 guests", has the
details.
### Install reims-ctl
On Linux or an Apple silicon Mac, clone the repository (without `--recursive`: QEMU's own
submodules are not needed) and run:
```sh
scripts/install-ctl.sh
```
It installs what the build needs (apt on Ubuntu and Debian, dnf on Fedora, pacman on Arch and
CachyOS, Homebrew on a Mac; Rust through rustup.rs), and on Linux `vulkan-tools` too, whose `vulkaninfo` goes into
`reims-ctl report`'s zip. It fetches `vendor/qemu`, builds the library on Vulkan (on a Mac,
on Mesa's KosmicKrisp, from Homebrew's `mesa`) and QEMU on it, installs QEMU into `~/.local/share/reims-ctl/qemu`, and
`reims-ctl` into `~/.cargo/bin`. Where x86-64 VMs run, it installs
[reims-util](https://github.com/steelbrain/reims-util) beside it; where arm64 VMs run, it installs
`reims-restore` beside it and downloads [Ambrosia](https://github.com/steelbrain/ambrosia)'s
release, which `reims-ctl` checks against the hash it pins. `vendor/qemu` is
fetched from its public repository (`steelbrain/qemu-reims-vgpu`), at the commit this checkout
pins, and Cargo fetches metal2vulkan from its public repository, at the commit the workspace's
`Cargo.toml` names. `reims-ctl doctor` checks the host and the install.
On Windows, open PowerShell and run:
```powershell
irm https://raw.githubusercontent.com/steelbrain/reims-vgpu/master/scripts/install.ps1 | iex
```
It installs MSYS2 and Git for Windows with winget if you don't have them, turns on the Windows
Hypervisor Platform that VMs run on (Windows asks for an administrator for that step alone, and you
restart once before your first VM), clones the repository into your user folder (or into
`C:\reims-vgpu` if your user folder's path has a space, since QEMU's build can't take one), and runs
`scripts/install-ctl.sh` in MSYS2's CLANG64 shell. That builds the library and QEMU with MSYS2's
clang, with the Rust toolchain that goes with it: it installs Rust if you don't have it, and adds
that toolchain beside yours if your Rust is set up for Visual Studio, so you don't need Visual
Studio. It installs `reims-ctl` into `%USERPROFILE%\.cargo\bin`. On an Intel Core i7-8700B a
first install took about 20 minutes, and running it again about a minute. From a clone,
`powershell -ExecutionPolicy Bypass -File scripts\install.ps1` does the same. Windows support is
newer than Linux's. The guest's H.264 and HEVC video decodes on your GPU there through Mesa's VA-API
driver for Direct3D 12, which the install adds from MSYS2. Encoding doesn't use your GPU on Windows
yet, whichever GPU you have, so the guest encodes video in software there.
### Set up a VM
1. **Host prep.** You need KVM (`/dev/kvm`) and a Vulkan driver; `reims-ctl gpus` lists the GPUs a
VM can be given. The guest's memory reaches the GPU through `/dev/udmabuf`, whatever your GPU,
so you need to be able to open it: without it the guest can crash at higher resolutions, at 4K
even at its desktop. That means being in the group that owns it (usually `kvm`, the same group
as `/dev/kvm`); a desktop session may let you open it anyway, but a VM started over ssh needs
the group. `scripts/install-ctl.sh` offers to add you, and `reims-ctl` warns when you can't.
On an NVIDIA GPU, raising `vm.max_map_count` makes things faster: past a point the GPU gets
copies of the guest's memory instead of the memory itself. `reims-ctl doctor` and the
installer tell you the value that avoids the copies, if yours is lower. It's optional: the
guest works at your distribution's default.
On Windows there's nothing to prepare once the installer has turned on the Windows Hypervisor
Platform and you've restarted, and on a Mac there's nothing to prepare at all.
2. **Create a VM.** Run `reims-ctl`, press `n`, pick a macOS version and press Ctrl-S. It downloads
the installer from Apple and makes the VM's OpenCore image and disk; then press `s` to start it.
Or from a shell:
```sh
reims-ctl create mac --macos tahoe --start # about 1 GB; installs the newest Tahoe
reims-ctl create mac --macos 26.6.2 --offline --start # one exact release, 13 to 20 GB
```
The VM boots into macOS Recovery. Open Disk Utility, erase the VM's disk (the largest QEMU
HARDDISK Media, about 137 GB on a new VM; the others are the installer and OpenCore's) as APFS,
and pick Reinstall macOS; with the offline installer, run
`sh /Volumes/Installer/install-macos.sh` in Terminal instead. Once macOS is installed,
`reims-ctl eject mac` takes the installer out at the VM's next start, so there's no need to stop
the VM first. Downloads are kept for your next VM, in `~/.local/share/reims-ctl/installers`
(delete them there to get the space back, once your VMs' installers are ejected), and an
interrupted one picks up where it stopped.
Already have macOS on a disk? `--disk` uses it, copied or in place. The copy is instant where the
disk and the VM's folder are on one file system that makes reflinks, such as btrfs or XFS;
otherwise reims-ctl copies it in full, and says so, with its size, before it starts. Where the
OpenCore image it booted with sits beside it as `opencore.qcow2`, as in a VM's folder, the VM's
new image presents that same Mac; `--opencore` copies an image of yours instead, with OVMF beside
it, which keeps its Mac too. With neither, or when you copy the disk of one of your reims-ctl
VMs, which can then run beside it, the VM is a new Mac to that macOS, so it opens Setup Assistant
once at its first boot; finish it in the window, since it won't shut down until you do.
`--installer` takes an installer of your own.
An arm64 VM comes from an IPSW instead. On a Mac or arm64 Linux that's what `create` makes; on
x86-64 Linux, `--ipsw` asks for one:
```sh
reims-ctl create mac --ipsw latest --start # downloads the current macOS's IPSW, about 25 GB
reims-ctl create mac --ipsw ~/Downloads/UniversalMac_14.6.1_23G93_Restore.ipsw
```
Apple offers only the current macOS to download, so an older one needs an IPSW you have. The
download is kept for your next VM. The VM's first boot makes macOS's Data volume and then
resets the VM, which won't start again until you finish it: stop it, run
`reims-restore finish-eacs` with the VM's folder, and the next start goes to Setup Assistant.
### Day to day
`reims-ctl` with no command opens its interactive interface: create a VM, start it (each of its
displays opens in a window), stop it (the guest shuts down, or is powered off after a timeout),
edit its CPUs, memory, displays (up to four), resolution, borderless windows, input capture,
GPU, audio and logs, change its installer, print the exact QEMU command it runs, and zip its
logs with the host's details into Downloads for a bug report.
```sh
reims-ctl list # the VMs and whether they run
reims-ctl set mac --memory 12G --resolution 1920x1080 # applies at the next start
reims-ctl command mac # the QEMU command it runs, as a shell script
reims-ctl report mac # logs, settings, the host's details and its vulkaninfo, zipped, for a bug report
reims-ctl update # pull the checkout and install again
reims-ctl update --channel development # switch to the development branch first (stable is master)
```
`reims-ctl help` lists every command; every option takes `--name value` or `--name=value`. A running
VM keeps the QEMU it started with across an update.
### The window takes your keyboard shortcuts and your mouse
Each of the guest's displays opens in a window the library owns (`crates/reims-vgpu-window`). **Click into the
guest's picture to capture the keyboard and the mouse:** shortcuts and system keys then go to the
guest instead of the host, and the pointer stays inside the picture until you release it, so you
can throw it at the guest's corners and edges without landing on another window. Keys reach the
guest by position, so the guest's own layout applies, and the Super key (the Windows key on Windows)
is the guest's ⌘. While captured, the window grabs the whole keyboard (SDL3's window, on Wayland or
X11), so the compositor's shortcuts, Super and Alt+Tab among them, reach the guest; on Windows, the
Windows key and Alt+Tab do too. **Ctrl+Alt+Super** together (**Ctrl+Alt+Win** on Windows) releases
it.
The title says when input is captured and how to release it. Losing focus releases capture too,
and gives the host back its system keys and its pointer. Losing focus, releasing capture or closing the window sends a key-up for every key
still down, so nothing sticks. Closing a window first asks "Turn off the VM?": Turn Off powers the
VM off at once, as if its power were cut, and Cancel keeps it running.
If you'd rather the window never capture anything, turn off **Capture input** in the VM's
settings (`e` in `reims-ctl`, or `reims-ctl set <vm> --capture false`; it applies at the VM's
next start). The title then ends "— input capture off". Clicks and keys still reach the guest
while its window is in front, but nothing is grabbed or held: the pointer moves out of the window
freely, and the host keeps its own shortcuts, such as Alt+Tab or ⌘Tab. On a Mac, other ⌘
shortcuts go to the guest, ⌘Q among them, so quit the VM from the menu or by closing its window.
A game that steers by the mouse's motion gets the plain pointer, which stops at the edge of the
guest's picture.
Fn/Globe does not reach the guest (QEMU's USB keyboard cannot carry it), and there is no HDR output.
[`crates/reims-vgpu-window/features.md`](crates/reims-vgpu-window/features.md) lists everything the
window does: its sizing, HiDPI, pointer, scrolling and cursor, each entry with its guard.
### Environment overrides
Set in QEMU's environment (`reims-ctl set <vm> --env KEY=VALUE`). Every one is optional; the library
reads them once per process, and an unset or unparsable value is the default.
| Variable | Effect |
|---|---|
| `REIMS_VGPU_LOG=info` | the library's log lines to stderr, filtered by a level and `target=level` pairs (`warn,reims_vgpu_graphics=debug`); unset, nowhere. `reims-ctl set <vm> --log-level` sets it |
| `REIMS_VGPU_WINDOW=0` | QEMU stays headless under `-display none` (QEMU reads it, not the library) |
| `REIMS_VGPU_WINDOW_BORDERLESS=1` | a borderless window that fills its screen |
| `REIMS_VGPU_STRICT=1` | end the process when the host runs out of memory, instead of answering the guest the way Metal does then |
The window opens at the size of QEMU's `reims-graphics-pci` property `resolution=` (1920x1080 by
default), which `reims-ctl`'s resolution setting sets, and the guest follows the window as you
resize it. [docs/api.md](docs/api.md) section 2 lists every setting and variable.
## What's here
- The library: `crates/`. Core holds the behavior, generic over its platform; beside it are the
Vulkan platform, which runs on metal2vulkan, the reims-graphics device's host side (`crates/reims-vgpu-graphics`), a display's window, host video on VA-API and NVDEC/NVENC,
the Rust API and the C API ([docs/development.md](docs/development.md#crates)).
- The guest's side: `guest/`, the kexts that drive the device and the Metal bundle that turns the
guest's Metal calls into its command stream. `guest/prebuilt` holds the built set, which
reims-ctl puts in each VM's OpenCore image.
- QEMU: `vendor/qemu` tracks
[`steelbrain/qemu-reims-vgpu@steelbrain/reims-vgpu-rebase-2`](https://github.com/steelbrain/qemu-reims-vgpu/tree/steelbrain/reims-vgpu-rebase-2):
`reims-graphics-pci` in C on the C API, which finds the library through pkg-config and links it
statically.
- The option ROM: `firmware/`, the device's UEFI driver, in C, which the guest's firmware runs.
`firmware/prebuilt` holds the built ROM, which reims-ctl gives the device. `firmware/ambrosia`
is the device's driver module for Ambrosia, which gives an arm64 guest's firmware an early
console on the device, with our configuration of Ambrosia and the check of a guest's boot on it.
- The Vulkan platform's runtime: metal2vulkan's public repository, at the commit the workspace's
`Cargo.toml` names.
- VMs: `reims-ctl` (`crates/reims-ctl`) creates, boots and manages them.
## Developing
The reims-graphics device (PCI `1234:5247`) and everything on both sides of it are ours. In the
guest, our kexts drive the device, and our Metal bundle turns macOS's Metal calls into the
device's command stream. On the host, QEMU's `reims-graphics-pci` hands that stream to the
library, which runs it on Vulkan through [`metal2vulkan`](https://github.com/steelbrain/metal2vulkan)
and draws the guest's display into a window of its own. On a Mac the library runs on Vulkan too,
on Mesa's KosmicKrisp driver rather than on Metal, and the guest's side is built there. x86-64 VMs
run on Linux and Windows hosts, and arm64 VMs under HVF on Apple silicon Macs, under KVM on arm64
Linux and under TCG on x86-64 Linux ([docs/qemu.md](docs/qemu.md), "arm64 guests").
The library's C API (`crates/reims-vgpu-c/include/reims_vgpu.h`, specified in
[docs/api.md](docs/api.md)) is its interface to QEMU: `cargo xtask dist` writes the library, the
header and a pkg-config package into `target/dist-vulkan`, which QEMU links.
[AGENTS.md](AGENTS.md) has the rules for changing the code. `scripts/install-ctl.sh` installs what
it needs itself; working on the code needs the following.
### Requirements
- A Linux host for the library and for VMs (on x86-64, x86-64 VMs under KVM and arm64 VMs under
TCG; on arm64, arm64 VMs under KVM; VMs on our GPU need Linux 7.2 or later), and an Apple silicon Mac for the metallibs and the guest's
kexts, where arm64 VMs run under HVF. Every Rust binary built on the Mac is arm64
(`aarch64-apple-darwin`): rustc's arm64e target has no pointer authentication, and its binaries
crash before `main` (`rust-toolchain.toml`).
- The toolchain `rust-toolchain.toml` pins: nightly-2026-11-03 with rustfmt and clippy, for rustc's
parallel front end (`-Zthreads`, in `.cargo/config.toml`). rustup installs it on first use.
- `cargo-nextest`, which runs the tests in `cargo xtask check`
(`cargo install --locked cargo-nextest`).
- cbindgen 0.29.4, for `cargo xtask header` (`cargo install --locked cbindgen --version 0.29.4`).
- On the Mac, Xcode's clang, for objc2's exception helper (which the `cc` crate builds), Xcode's
Metal toolchain, with which the Vulkan platform's crate compiles its metallibs as it builds
(`xcodebuild -downloadComponent MetalToolchain`), and Homebrew's `vulkan-loader` and `mesa`,
whose KosmicKrisp, on macOS 26 and later, is the Vulkan driver the library runs on there. The
guest's kexts build with Xcode alone (`guest/Makefile`).
- clang and lld for the option ROM and the Ambrosia module (`firmware/`; on a Mac, Homebrew's
`lld`). reims-ctl's build makes the module itself with clang and the Rust toolchain's own lld.
- For `make qemu`: the `vendor/qemu` submodule (`git submodule update --init vendor/qemu`) and
QEMU's build dependencies (`meson`, `ninja`, `pkg-config`, `glib`, `pixman` and so on).
On x86-64 Linux the library builds on the Vulkan platform alone, with no Mac and no Xcode. It needs
the toolchain above (cargo fetches metal2vulkan at the commit the workspace's `Cargo.toml` names),
CMake and a C compiler for SDL3, which the build compiles from its pinned source, and `make` for
jemalloc, the allocator the library uses, which the build also compiles.
### Building
```sh
make # the library (cargo xtask dist), in target/dist-vulkan
make qemu # qemu-system-x86_64 with reims-graphics-pci on the library, in build/qemu
make clean # remove build/
make -C guest test # the guest side's tests, on a Mac
make -C firmware # the option ROM, in firmware/build
make -C firmware/ambrosia bundle # the Ambrosia module and a bundle that starts it, in firmware/ambrosia/build
make -C firmware/ambrosia config-bundle GRAFT=... REIMS_GRAPHICS=... RGFXGATE=...
# our configuration: the module, Graft and our kexts (arm64e builds)
```
The Makefile's header describes every target and its variables. `make` runs `cargo`, which you can
drive directly. [docs/development.md](docs/development.md) has the repository's layout, its tests,
the crates, `cargo xtask` and the build profiles and features.
If you have [kache](https://github.com/kunobi-ninja/kache) installed, run
`. scripts/internal/dev-env.sh` before cargo and your builds go through it, so a new worktree reuses
what other worktrees on your machine already compiled. It's optional: without kache, builds are
cargo's own. See "Building through kache" in docs/development.md for the setup.
The Vulkan platform's shaders are metallibs, which only Apple's compiler makes. A Mac compiles its
own as it builds; any other host copies those a Mac compiled, committed in
`crates/reims-vgpu-vulkan/metallibs`, once their `metallibs.toml` names each with the sha256 of the
commands and sources this tree compiles it from (`crates/reims-vgpu-vulkan/build.rs`).
`RVG_METALLIB_DIR=<dir>` takes them from `<dir>` instead.
```sh
cargo xtask metallibs # on a Mac: compile them into crates/reims-vgpu-vulkan/metallibs
cargo xtask metallibs <dir> # the same into <dir>, for RVG_METALLIB_DIR
```
A change to a `.metal` source of the Vulkan crate, `shaders.metal` among them, commits
the metallibs `cargo xtask metallibs` writes with it: until then a test of `cargo xtask check` fails
on the Mac (`the_committed_metallibs_are_this_trees`), and the build fails on Linux.
## License
The repository is free software under the GNU General Public License, version 2 or later, or the
GNU Lesser General Public License, version 3 or later, at the recipient's choice:
`GPL-2.0-or-later OR LGPL-3.0-or-later`, the workspace's `license` in `Cargo.toml`.
[LICENSE](LICENSE) says so, and `LICENSES/` holds the texts, the GPL's version 3 among them, since
the LGPL's version 3 adds its permissions to it.
QEMU (`vendor/qemu`) keeps QEMU's licenses. The crates the build takes keep their own:
metal2vulkan's, which the Vulkan platform links, and SDL3's sources, which the window crate builds
and links statically, among them.
## Legal
Metal and macOS are trademarks of Apple Inc. reims-vgpu is an independent project and is not
affiliated with, sponsored by, or endorsed by Apple Inc.