Anees Iqbal c86adb77ff vgpu: a mip chain the guest declares in full reaches the device as its base alone
Component: crates/reims-vgpu — compute staging and the Vulkan compute engine.
Pathway: x86 macOS / Linux Vulkan. Rail: macos-13.

Metal's `read(coord, lod)` and `sample(_, _, level(lod))` both name a level of
the chain a texture declares. A type-2/3 texture descriptor declares that chain:
`mipmapLevelCount` plus one `TextureLevelLayout` per level, each with its own
offset, row stride and extent, all already decoded and already checked against
`contract::extent::mip_extent` by the mipmap resolver. Measured on this rail, a
seven-level 64x64 RGBA8 texture arrives with all seven records, extents matching
`mip_extent` exactly, tight strides, ascending offsets, and every level resolving
through `level_gva` down to the 1x1 tail.

The compute rail staged one of them. `stage_texture_raw` called
`level_gva(view_level)` once and returned a `StagedTexture` whose
`width`/`height`/`bytes` is a one-level shape; `ComputeSampledImageResource` and
`StorageImageKey` were one-level too, and `acquire_storage_image` hardcoded
`.mip_levels(1)`. So a fetch at any level above the base returned nothing and an
explicit-LOD sample clamped to level 0 — which is indistinguishable from a
texture whose upper levels were never written, and is why both upload routes
(`replace(region:mipmapLevel:)` and a blit from a buffer) failed identically.

The invariant now belongs to the staging owner: a sampled type-2/3 binding stages
the declared pyramid, level by level, each read at its own gva, stride and
extent, packed tightly base-first by `contract::extent::tight_pyramid_spans`.
Producer and consumer both call that one function, so no site computes a level
offset of its own. A storage binding and a level-naming view stay at the base —
a compute write names one level and a levelled view exposes one. A resident
source can only answer for one window at one level, so it is not paired with a
pyramid: the runtime declines the optimisation and the engine refuses the pair by
name. A level the descriptor will not place truncates the chain to the prefix
above it and says so on the fail channel, because that is dropped guest work. The
Metal rail refuses `mip_levels > 1` rather than binding a pyramid flattened to
its base; its ABI carries one level and this pathway is not validated here.

Tests. `a_declared_mip_chain_stages_every_level_and_not_only_its_base` builds a
four-level chain through a real descriptor with padded rows and per-level
markers; red witnesses probed by hand: staging only the base reads 1 level
against 4, and reading every level at the base's stride puts a neighbour's
marker in a level. `compute_sampled_image_serves_every_declared_mip_level` runs
`OpImageFetch ... Lod n` per level on the real device against a pyramid the test
lays out by hand rather than through the shared helper; putting `.mip_levels(1)`
back reproduces the guest's `got=0x00000000` at level 1 exactly.
`compute_sampled_resident_bind_refuses_a_pyramid` pins the refusal.

Verification. 2274 lib tests plus every integration binary, serially, exit 0.
`cargo fmt --all` then `--check` clean. All three clippy arms clean at
`-D warnings`. Conformance on macos-13: three control boots at 6026f037, all
byte-identical at 221 PASS / 55 FAIL / 17 SKIP, against two candidate boots,
byte-identical to each other at 239 / 37 / 17 — 18 FAIL to PASS, zero
regressions, 293 names present exactly once, and every surviving failure keeping
its exact detail string. The 18 are `mip_fetch_level_{1..6}`,
`mip_sample_level_{1..6}` and `mip_blit_level_{1..6}`. No new refusal channel
fired. A 60 s host-driven Maps pan-and-zoom over 116 phases rendered correctly,
frames inspected as images: correct tiles, labels at many sizes, full Dock and
menu bar, no corruption. Silent-loss counters all zero; `web-content` 20/20 and
`wallpaper` 10/10 clean.

Catastrophic result, and why it does not implicate this change. One candidate
visual-gate boot took a guest kernel panic (`tro ... @bsd_kern.c:139`) during
session log-out. The identified control at 6026f037, built in an isolated
worktree with its own QEMU and run through the identical gate, panicked on two
of three boots — and one of its signatures, `Taking non-sleepable RW lock with
preemption enabled @lock_rw.c:1377`, is the same string a candidate boot
produced. Five distinct signatures across seven gate boots, in five guest
processes, four with no GPU frame in the backtrace, one reached while the guest
sat idle before any probe ran. The class is the rail's, demonstrated by the
control. All five conformance boots, which drive far more GPU work, were clean.

Not verified. arm64 Metal-direct and MoltenVK pathways, and every rail but
macos-13. The storage half of a buffer-backed texture, still refused. The
truncation path, which no case reaches. `REIMS_VGPU_GUEST_IMPORT=off`. Every
boot in this session ran on the host's Intel integrated GPU under Mesa — the
unified, host-pointer-import memory cell — because the host's NVIDIA driver is
not answering; the discrete cell is unverified for this change. The visual gate
cannot reach a verdict on this rail on either arm: its modal-button probe logs
the session out for real when its cancelling keystroke loses the race, so every
gate boot ended without a verdict.
2026-08-30 06:31:32 +03:00
2026-07-26 15:24:53 +03:00
2026-07-26 15:24:53 +03:00
2026-07-26 15:24:53 +03:00
2026-07-26 15:24:53 +03:00
2026-07-26 15:24:53 +03:00
2026-07-26 15:24:53 +03:00

reims-vgpu

License: LGPL-3.0-or-later Discord

Alpha. This project is early and under active development. The QEMU device ABI, boot scripts, crate layout, backend behavior, and supported host/guest pathways may change without a stable compatibility guarantee. Treat it as research-quality: useful for experimentation and bring-up, not a frozen virtualization product.

reims-vgpu is an experimental virtual GPU for macOS guests. It aims to let macOS running inside a VM use accelerated graphics instead of a basic framebuffer, while keeping the guest operating system unchanged.

macOS already includes a paravirtual GPU driver named AppleParavirtGPU.kext. reims-vgpu provides the QEMU device that driver attaches to, then decodes the guest's GPU command stream on the host and executes it through Metal (TODO) or Vulkan, with Vulkan translation handled by metal2vulkan. There is no custom macOS kext and no guest driver to install.

Contributions are welcome. I am especially interested in collaborating with developers who want to work on correctness, visual glitches, synchronization bugs, command-stream decoding, Metal/Vulkan translation, and making more host/guest combinations reliable.

reims-vgpu running an arm64 macOS 13 Ventura guest desktop on an Apple Silicon host

arm64 macOS 13 Ventura guest on an Apple Silicon host.

reims-vgpu running an x86_64 macOS 13 Ventura guest desktop on a Linux host

x86_64 macOS 13 Ventura guest on a Linux host.

Three pathways

crates/reims-vgpu targets the following host/guest/backend combinations. Agents pick the pathway their unit of work is on.

Pathway Host Guest Device attach Backend Boot
x86 macOS / Linux Vulkan Linux x86_64 (KVM) x86_64 macOS Metal guest PCI reims-vgpu-pci host Vulkan via metal2vulkan vm/boot-x86.sh
arm64 macOS / macOS Metal Apple Silicon macOS (HVF) arm64 macOS Metal guest (vmapple) sysbus MMIO reims-vgpu-mmio host Metal vm/boot-arm64.sh
arm64 macOS / macOS Vulkan Apple Silicon macOS (HVF) arm64 macOS Metal guest (vmapple) sysbus MMIO reims-vgpu-mmio host Vulkan via metal2vulkan through MoltenVK vm/boot-arm64.sh
  • QEMU device shims: vendor/qemu tracks steelbrain/qemu-reims-vgpu@host-reims-vgpu-vmapple (thin C — QOM/MMIO/IRQ/console/HostOps only)
  • Product logic: crates/reims-vgpu (decode + device model + Metal/Vulkan backends)
  • Wire layouts: crates/reims-vgpu-wire (derived serializer views/parsers; decode uses these as the layout authority for covered records)
  • Vulkan translator dependency: public steelbrain/metal2vulkan Git crate. On macOS, the Vulkan host backend runs through MoltenVK.
  • VM lifecycle: vm/ (snapshot-revert; arm and x86 guest boot scripts)

Getting started

This tree ships boot scripts and the device, not a ready-made macOS disk image. Guest disks, firmware vars, and OpenCore blobs are private/gitignored under vm/. Pick a pathway, provision a guest once, freeze a golden snapshot, then use the snapshot-revert boots for day-to-day work. macOS 13 Ventura is the recommended guest release for bring-up.

x86_64 guest on Linux (KVM)

  1. Host prep. You need KVM (/dev/kvm), a working NVIDIA (or other) Vulkan stack for the product backend, and build deps for the in-tree QEMU (scripts/qemu-build/qemu-build.sh --target x86_64 --backend vulkan).

  2. Generate OpenCore, OVMF, and a guest disk with OSX-KVM. macOS 13 is recommended.Follow that project’s docs to fetch recovery media, build OpenCore, and install macOS under QEMU+KVM. The point of this step is only to produce a working, post-Setup-Assistant guest plus the usual OpenCore/OVMF pieces — not to stay on OSX-KVM’s long-term launcher.

  3. Drop the artifacts where this repo expects them (paths are the defaults in vm/boot-x86.sh; override with env if you prefer):

    Artifact Default location
    Guest system disk vm/disks/macos.img
    OpenCore boot disk vm/disks/OpenCore.qcow2
    OVMF code vm/ovmf/OVMF_CODE_4M.fd
    OVMF vars template vm/ovmf/OVMF_VARS-1920x1080.fd

    Finish install in the guest: enable Remote Login, install your SSH key, turn off sleep/screensaver as you like. Host SSH is typically localhost:2222 → guest :22 (see vm/boot-x86.sh).

  4. Capture the first immutable snapshot. Guests are organised into rails — one rail per guest OS line (macos-11 … macos-26), each with a snapshot history of its own under vm/disks/rails/<rail>/snapshots/. Create the rail's directory, then from a clean guest state (logged in, network/SSH known-good) shut down cleanly while booting in capture mode:

    mkdir -p vm/disks/rails/macos-15
    vm/boot-x86.sh --rail macos-15 --capture --device vmware-svga
    # clean shutdown from inside the guest → new label under
    # vm/disks/rails/macos-15/snapshots/, and that rail's snapshots/current points at it
    

    Every later boot clones the selected rail's snapshots/current (COW when possible) and throws the clone away on exit, so wedges and hard kills never poison the golden image.

    Importing a guest built elsewhere is the same shape without the boot — drop {macos.img,OpenCore.qcow2,OVMF_VARS.fd} (plus OVMF_CODE.fd if that guest was installed under a different OVMF build) into vm/disks/rails/<rail>/snapshots/base/, chmod 444 them, and ln -sfn base vm/disks/rails/<rail>/snapshots/current. Use cp --reflink=auto on btrfs and the import costs no disk.

  5. Day-to-day boots.

    vm/boot-x86.sh --list-rails                  # what guest lines exist (* = default)
    vm/boot-x86.sh --rail macos-15 --list-snapshots
    
    # Console only (mainstream OSX-KVM-style VGA) while you debug the host stack
    vm/boot-x86.sh --testing --device vmware-svga
    
    # Product Reims VGPU device (needs in-tree QEMU + reims-vgpu Vulkan)
    REIMS_VGPU_BACKEND=vulkan scripts/qemu-build/qemu-build.sh --target x86_64
    vm/boot-x86.sh --testing --device reims-vgpu-pci --rail macos-15
    
    # Host-window screenshot on the Linux/Plasma host
    scripts/screenshot-when-kde-plasma-host/screenshot-when-kde-plasma-host.sh -o /tmp/screen.png
    

    Without --rail a boot follows vm/disks/rails/current; change it with ln -sfn <rail> vm/disks/rails/current. Neither --rail nor --snapshot repoints anything.

arm64 guest on Apple Silicon (HVF / vmapple)

Arm bring-up is in-tree: Virtualization.framework via Homebrew macosvm, then QEMU’s vmapple machine under HVF. There is no OSX-KVM step.

  1. Install macosvm, and build the vendored QEMU:

    scripts/qemu-build/qemu-build.sh --target aarch64 --backend metal
    
  2. Provision a guest from a UniversalMac IPSW with the project helpers in scripts/vmapple-provision/. The live bundle lives under vm/guest/ (disk, aux, vm.json / ECID).

  3. Configure the guest once: enable Remote Login, run scripts/vmapple-guest-config/ for no-sleep settings, and optionally enable auto-login by hand in System Settings. Capture a golden under vm/guest/rails/<rail>/snapshots/ with the snapshot helpers (scripts/vmapple-snapshot/, or vm/boot-arm64.sh --rail <rail> --capture once the disk is ready).

  4. Boot:

    vm/boot-arm64.sh --testing --device reims-vgpu-mmio    # product
    vm/boot-arm64.sh --testing --device apple-gfx-mmio   # Apple ParavirtualizedGraphics A/B
    scripts/screenshot-when-macos-host/screenshot-when-macos-host.sh /tmp/screen.png
    

    Optional performance ceiling reference: the same guest under native VZ via macosvm --gui.

After the first snapshot

  • Prefer --testing for agent/measurement boots (time-bounded, always reverts).
  • Use --interactive when you need an open-ended GUI session (still reverts unless you are in --capture mode).
  • Say which rail a result came from. A number from macos-11 and a number from macos-26 are two measurements, not one — that separation is the whole reason snapshots are per-rail.
  • Never commit disks, IPSWs, or OpenCore/OVMF runtime under vm/.
  • Device/backend work lives in crates/reims-vgpu + the thin shims in vendor/qemu; rebuild QEMU after product changes before claiming a live boot result.

The host window takes your keyboard shortcuts

On the reims-vgpu-pci / reims-vgpu-mmio device the guest is displayed in a window this project owns, and while that window has keyboard focus it asks the host desktop to stop acting on its own shortcuts so they reach the guest instead. Without that the desktop consumes them first: a stock Plasma session claims 63 Meta/Alt/Ctrl combinations, and because a macOS guest reads host Meta as Cmd, that covers most of what the guest expects — Cmd+A, Cmd+V, Cmd+Q, Cmd+W, Cmd+1…Cmd+9, and Alt+Tab.

Press Ctrl+Alt+Esc to release the grab. While it is held your own Alt+Tab goes to the guest, so this is how you get back to the host desktop. The chord is consumed rather than forwarded, and the grab re-arms by itself the next time you focus the window — it is an escape hatch, not a mode you have to remember you are in. The guest's own Cmd+Option+Esc (Force Quit) carries no Ctrl and is forwarded to the guest untouched.

The window says so on stderr the first time it captures, and records it in the always-on log:

window_capture_engaged mechanism=wayland_shortcuts_inhibit release=Ctrl+Alt+Esc

How much can be captured depends on the host, and the log names which mechanism a boot got:

Host Mechanism Coverage
Wayland zwp_keyboard_shortcuts_inhibit_v1 full, when the compositor implements it
X11 XGrabKeyboard full, unless another client holds the keyboard
macOS NSApplicationPresentationDisableProcessSwitching partial — Cmd+Tab and Cmd+H only; the window server keeps its reserved chords

A host that cannot capture at all still runs; it emits a window_capture_* reason on /tmp/reims-vgpu-fail.log rather than silently dropping the keys.

Environment overrides

Set on the boot command; every one is optional and every default is "let the device decide". The full list, with the parse, is crates/reims-vgpu/src/env.rs. Each accepts 1/on/true/yes and 0/off/false/no, case-insensitively.

Variable Effect
REIMS_VGPU_DMABUF=off Stop reaching guest pages through a dma-buf, even where the host can. Every guest-memory rail takes the copying path instead — which is what runs on any host without VK_EXT_external_memory_dma_buf, so this is how that half is exercised on a machine that has it.
REIMS_VGPU_DRAW_LOG=on Verbose per-draw detail on top of the always-on failure log.

An override can only narrow what the device does. There is no way to switch a rail on that the host reported it cannot run: capability is measured from the device at startup, and asking a driver for an extension it does not advertise fails device creation rather than degrading. REIMS_VGPU_DMABUF has no on direction for that reason — on a host without the extension it is already off, and the vk_caps line in /tmp/reims-vgpu-fail.log names which check said so.

Repo layout

AGENTS.md           - repo operating guide for agents
crates/             - Rust crates (`reims-vgpu`, `reims-vgpu-wire`, `reims-vgpu-efi`)
scripts/            - host setup, VM lifecycle, screenshot, and diagnostic helpers
vendor/             - vendored QEMU submodule and patch record
vm/                 - VM launch/configuration glue; images are private/untracked

crates/reims-vgpu-wire holds zero-copy views and parsers for the Apple paravirtualized GPU serializer format, derived from Apple's own encoder rather than inferred from captures. crates/reims-vgpu's runtime::decode uses those exports for opcodes, record framing, and field layouts on wire-covered families (encoder blit/compute/render binds and state, and the create records above); decode remains the mapping layer into the device's Command / Kind model and decline naming. Gaps without a wire export (FIFO, event opcodes, unobserved compute residency, pipeline TLV) stay local to decode.

License

Licensed under the GNU Lesser General Public License v3.0 or later (LGPL-3.0-or-later).

Metal, macOS are trademarks of Apple Inc. reims-vgpu is an independent project and is not affiliated with, sponsored by, or endorsed by Apple Inc.

Languages
Rust 61%
C++ 17%
Objective-C 7.9%
Objective-C++ 7.4%
C 2.6%
Other 4%