Commit Graph
79 Commits
Author SHA1 Message Date
Anees Iqbal c6ab041d68 🆕 Record a no-copy buffer's escape in the replay stream
metal2vulkan's replay player must stop, typed, where the GPU may reach a
no-copy buffer through an address in memory alone. The guest says so with
BUFFER_ESCAPED, but the note ended in the decoder: no stream carried it, and
only the stats file's counted totals showed it.

The decoder's first note for each buffer now also records it, where the
process records (REIMS_VGPU_RECORD): an m2v.bufferEscaped call on the
buffer's stream id, [kind], the note's RGFX_BUFFER_ESCAPED_* act (0
gpuAddress, 1 argument encoder, 2 resource id, 3 residency set), of the whole
buffer. It is queued on the decoder's thread at the note, so it lies after
the m2v.write records of each commit made before the note and before those of
each commit made after it. A later note, a note for a refused create and a
bad reference write none. Each record is counted by its selector in the stats
file, and the recorder_fix "buffer-escaped" names the change.

Nothing changes for the guest or the C API's host. With REIMS_VGPU_RECORD
unset the note costs one more relaxed load (recorder::on).
2026-11-18 22:08:45 -08:00
Anees Iqbal 5273e0eeb9 🆕 Give arm64 guests' device the Shared pool's room past RAM
QEMU gave the library a pool range only on a PC machine, and an arm64
guest's device on vmapple had none. vmapple now answers the room past its
RAM, from the end of RAM rounded up to 1 GiB to the end of the guest's
physical addresses (the CPU's PARange, at most 40 bits), as read-only
machine properties, and reims-graphics-pci gives the library that room
where no PC host bridge answers one, reserving nothing where the machine
has no fw_cfg. Ambrosia lists RAM alone, so the guest places nothing
there; it is told of no piece yet. x86-64 guests' pool is unchanged.
2026-11-18 19:15:08 -08:00
Anees Iqbal a39e43e99f 🐛 Cap the pool's room at the end of the host's physical addresses
QEMU offered the library the pool's room up to three quarters of the
guest's physical address space only. A guest may have more physical
address bits than its host (QEMU allows it with a warning; the Windows
mini's Coffee Lake has 39 against the guest's default 40), and a piece
placed past the host's width makes KVM refuse its slot (x86 KVM's
memslot check, read from code); WHPX gets the same cap. Under KVM and
WHPX the room now ends at the host's width too, read from CPUID
0x80000008: the device file builds for every target, where
target/i386's host_cpu_phys_bits is not linked.

What changed for the host: where the host's addresses end before three
quarters of the guest's, so does the room. Measured with the device
realized paused and the 64-bit window pushed so the room starts 4 GiB
below the host's end, the range the library took ends there: at
0x1000000000000 under KVM on a 48-bit Ryzen with phys-bits=52
(m3-max-49283), and at 0x8000000000 under WHPX on the mini
(m3-max-49316); under TCG it runs past both. On the mini's default q35
machine the room is now 487424 MiB, its 39 bits' end less the window's;
the range, the UHD 630's 31 GiB of heaps, is as it was.
2026-11-18 18:42:35 -08:00
Anees Iqbal f4692c7179 🐛 Take a pool piece out of the guest before its block goes back
The pool gave an empty piece's block back to its source and left the
guest's mapping to the source's unmap hook (BlockMappings::unmap), which
the source called before it freed the block, on the pool's thread or its
own. The metal2vulkan runtime deletes that hook, so the pool keeps the
promise itself: it gives a block back only once no thread of the device
holds it and the host has said its piece is out of the guest's address
space, and its close gives every block back only after every hold has
ended. The source may then free any block it gets back at once.
HostBlocks loses its mappings field, and Pool::new takes the source
itself.

What changed for the host: pool_remove comes on the device's pool thread
as the pool gives a block back (an empty piece past RELEASE_DELAY), never
on the source's thread; and a block the source hands out again is placed
and gets a new pool_add, where it used to keep its piece and mapping.
QEMU's x-pool-grow boot (8 asks of 256 MiB) now shows 8 adds and 7
removals (m3-max-49284), where it showed 5 removals before
(m3-max-49031). The release waits for the device's own holds before it
frees the blocks. The guest sees nothing new.

The tests that held "a block taken again keeps its piece" now hold that
it is mapped anew. New tests hold that a piece goes back only once the
host removed it and its hold ended, that one given back before the
host's add answered still waits for its remove, that ready blocks past
two are freed with no word to the host, and that the release gives a
held piece's block back only once the hold ends and asks the host
nothing. All ten fail on the code before this commit. QEMU's comment now
says pool_remove comes on the pool thread.
2026-11-18 18:42:29 -08:00
Anees Iqbal 16ad40298e 🆕 Size the guest's Shared pool's range from all the GPU's heaps
The guest's Shared pool's range of guest physical addresses, which QEMU
reserves and gives the firmware as etc/reserved-memory-end, is now the sum of
the host GPU's memory heaps, every heap, rounded up to 2 MiB and at most the
room the host gives, where it was the heap of the GPU's host-visible,
host-coherent and host-cached memory type alone. A heap's size is how the
driver accounts for memory, not the most it allocates: on a 780M, RADV puts
that type on a 5.52 GiB heap beside an 11.05 GiB device-local one over the same
system memory, so the guest's pool stopped at about 5.5 GiB, while the runtime
takes Shared blocks until the driver refuses one. A guest on a 780M now gets
about 16.6 GiB of pool addresses, on an RTX 3090 about 46 to 47 GiB, on an
RX 7900 XTX about 38.6 GiB; on an Iris Xe, with one heap, 23.24 GiB as before.

GpuDevice::shared_heap_size becomes memory_heaps_total, which sums the heaps
of VkPhysicalDeviceMemoryProperties and needs no buffer to ask which types a
buffer can use. A GPU that answers no heap still gives no pool. The library's
pool line now also logs the room the host gave, so a boot's log shows whether
the room clamps the range. QEMU's code is unchanged: vendor/qemu moves to a
commit that rewords its comments.
2026-11-18 17:54:51 -08:00
Anees Iqbal e74f40cc65 🆕 Name the display library's hash in each recording's stats file
A recording makes the device's own display library with
newLibraryWithSource:options:error: and no arguments, so a stream does not hold
its bytes. metal2vulkan's players now make it from a copy of the committed
shaders.metallib kept beside each stream (NAME.display.metallib), and asked that
each stream's stats file name that library by its hash, so a play can say which
display library it ran. The stats file now writes a display_library line after
recorder_commit: the SHA-256 of the bytes the device loads, in the hex the blobs
directory names libraries by, and their length.
2026-11-18 17:54:04 -08:00
Anees Iqbal 706353df2c 🆕 Size the guest's Shared pool's range from the GPU's Shared heap
The pool's range was a fixed 64 GiB of guest physical addresses, whatever the
host GPU: more than a GPU whose Shared heap is 24 GiB can ever fill, and less
than one whose heap is larger. The range now follows the heap the pool's
blocks come from: metal2vulkan-rt's Shared memory type, the first type with
HOST_VISIBLE, HOST_COHERENT and HOST_CACHED that a buffer of the device's
usage can use, on the GPU device the library opens. The bound is the heap's
size, not VK_EXT_memory_budget's budget: the range is address space held for
the VM's life, while a budget is momentary, moved by other processes, and on
Intel's Windows driver answered past its heap's size; RAM is bounded at each
block's take.

The config's pool range is now the room the host can give. The create opens
the GPU device, takes the heap rounded up to 2 MiB of that room (warning once
where the room is smaller, and giving no pool where no type is host-cached),
and rvg_graphics_device_pool_range answers what it took. The range is read
after the create rather than asked of the library before it, which would open
the GPU device twice or keep one alive without a device. QEMU offers the room
from pci-hole64-end to three quarters of the guest's physical addresses, then
reserves the range the library took, rounded up to 1 GiB, in
etc/reserved-memory-end, still at realize before the firmware runs. The
x-pool-size property goes; 0 and 0 still mean no pool in the C API.

What the guest sees changes: the firmware's reserved-memory-end, and so where
OVMF may put its 64-bit PCI window, follows the host GPU's Shared heap instead
of a fixed 64 GiB.
2026-11-18 16:52:12 -08:00
Anees Iqbal 5d38c7e825 📝 Say the library's hosts are Linux, Windows and macOS [ci skip]
The owner's word (Telegram 1924, relayed by metal2vulkan): the hosts are
Linux, Windows and macOS, and on macOS the library runs on Vulkan, not Metal.
README and the crates' and docs' notes said VMs run on Linux and that the Mac
build was for development and tests. They now say x86-64 guests run on Linux
and Windows hosts and arm64 guests on Apple silicon Macs, and that the Vulkan
platform runs natively on Linux and Windows and over MoltenVK on macOS.
rust-toolchain.toml names Windows' target as shipping too, and a reims-ctl
test's note says the test, not the installer, is Linux-only. AGENTS.md waits
for the owner's own word.
2026-11-18 14:28:11 -08:00
Anees Iqbal cb7f52c9a6 🆕 Name the recorder's build in each recording's stats file
metal2vulkan's stream table reads which recorder made a recording off its
files. The stats file now starts with recorder_commit, the commit the library
was built from, and a recorder_fix line for each change to what a stream holds
since format version 2, in landing order (recorder::FIXES, which each such
change extends in its own commit). cargo xtask dist stamps the commit for its
Cargo steps in RVG_BUILD_COMMIT (git rev-parse HEAD, -dirty where a tracked
file differs); other builds write unknown. Cargo and kache key the Vulkan
crate on the variable, so a dist at another commit compiles it again. The
stream itself and the device's behaviour are unchanged.
2026-11-18 13:56:40 -08:00
Anees Iqbal 285f0bdd69 🆕 Carry a no-copy Managed buffer's create-time bytes on two copies
On a device that keeps two copies of a Managed buffer (hasUnifiedMemory NO),
a no-copy Managed buffer's GPU copy takes the pages' bytes at its create, but
from zeroFrom on, and only didModifyRange: changes it afterwards. The stream
carried a no-copy buffer's bytes only as the writes before its first use, so a
player could not rebuild what the GPU copy held when the guest's CPU writes
since the create were never flushed to it.

Such a buffer's create record now carries the bytes the create copied, read
while the call holds them, a blob where long, as a copied buffer's contents
are: newBufferWithDescriptor:'s contents (the bytes before zeroFrom, nil where
that is 0) and newBufferWithBytesNoCopy:length:options:deallocator:'s first
argument (all of them). Shared and Private no-copy buffers, and any on a device
that keeps one copy, are recorded as before, and the writes before first use
are unchanged.
2026-11-18 00:45:55 -08:00
Anees Iqbal 0ba37884af 🆕 Record each device's identity at each segment's start
A player makes a stream's resources in the forms the recording device made
them, and the device's answers decide some of those forms: a Managed buffer is
one copy where the GPU shares the CPU's memory and two where it does not. The
stream named neither, so a player on another GPU could only guess them.

The recorder now writes an m2v.deviceIdentity call record on each device,
answering its name (the one the guest's device info gives) and
hasUnifiedMemory, right after the record that made the device, and again as the
first records of each later segment, one per device then live, so a segment
read on its own names them too. The format stays version 2: a reader that does
not use the record skips it, and its keys are answers.
2026-11-18 00:45:55 -08:00
Anees Iqbal b27a603cb4 🆕 Record the commands a CPU encodes into indirect command buffers
With REIMS_VGPU_RECORD set, the commands the guest's CPU encodes into an
indirect command buffer never reached the stream: an ICB_WRITE's went through
IndirectRenderCommand::encode and IndirectComputeCommand::encode, which had no
hook, and an ICB_SLOTS slot's call was recorded with its commands as nil (its
iterator prints nothing). The buffer's records live in the runtime, which no
memory write carries, so a replay executed commands it never saw.

Each send of commands to a buffer is now a call record on it,
indirectRenderCommandAtIndex: or indirectComputeCommandAtIndex:, with the
arguments [index, commands] that metal2vulkan's format names (section 8): the
commands in the order the platform carried them out, each a map of one pair,
the command's Metal selector and the list of its arguments read from its fields
(objects as stream ids, sizes and regions as maps). A command sent on its own
is a list of one; a slot's call lists the commands it took, read as it took
them, out of line over one iterator type. No m2v. selector is added.

With the variable unset nothing changes: one relaxed load and a branch, and the
platform's sends keep their shape.
2026-11-17 09:57:46 -08:00
Anees Iqbal 00d59542bc 🆕 Record Private buffers around dispatches of linked kernels
metal2vulkan replays the benchmark's lockstep kernels to check its forms against
Metal, and 28 of them link functions and bind Private buffers, whose bytes no CPU
can read, so no recording held them and those replays could not be checked.

With REIMS_VGPU_RECORD set, each recorded dispatch of a compute pipeline made
with linked functions (outside a block of command predication) now splits its
compute encoder around a blit before and after it, which copies each bound
Private buffer range (from its offset to the buffer's end, 256 MiB a dispatch at
most) into a Shared buffer of the recorder's own. At the command buffer's
completion the recorder writes both byte runs into the blobs directory and an
m2v.privateBytes record per range: receiver the buffer, arguments [the
dispatch's position among the stream's call records, {location, length}, the
before blob, the after blob]. A fresh compute encoder takes the guest's bindings
and residency again, as predication's refresh gives them; a recording process
keeps those bindings in a command buffer that holds no predication. Only these
dispatches: one per dispatch binding a Private buffer would split and copy far
more than the stream costs. stats.txt counts private_ranges, private_bytes and
private_skipped.

With the variable unset nothing changes: the hooks read the recorded call,
which is None there.
2026-11-17 09:24:15 -08:00
Anees Iqbal 426724ff52 🆕 Map the guest's Shared pool's blocks into a range the host reserves
metal2vulkan's new runtime allocates the GPU memory the guest's Shared
buffers live in, and the device maps those blocks into the guest (plan D2,
route 1). This is the host side of that pool: the guest's side, and the
wire it reads the range and its pieces from, come with the D2 guest work.

The library: a pool per device (crates/reims-vgpu/src/pool.rs) over the
range the host reserved. Its thread takes Shared blocks from a block source
and asks the host to map each at the lowest free 2 MiB-aligned address
(pool_add); the host says when the guest's address space has it
(rvg_graphics_device_pool_added). The source's unmap hook takes a piece out
of the lookups, waits for every hold on it, asks the host to unmap it
(pool_remove) and returns once the host says it is gone
(rvg_graphics_device_pool_removed); only then may the source free the block.
The pool keeps one empty piece as headroom, asks for a block more when the
guest uses the last empty one, and gives back a piece that stayed empty for
5 s above the lowest empty one. The source's calls and hook have
metal2vulkan-rt's shape (take_block, release_block, BlockMappings::unmap,
BlockInfo); until the device runs on that runtime the source is the
process's own memory (HostBlocks), so only the source changes then.

The C API: RvgGraphicsDeviceConfig and RvgGraphicsCallbacks go to their fifth
version (pool_physical_address and _length; pool_add and pool_remove), with
rvg_graphics_device_pool_added, _pool_removed and _pool_grow (the host's ask
for more pool now, which QEMU's x-pool-grow property drives).

QEMU (vendor/qemu): the device reserves 64 GiB past the RAM and the host
bridge's default 64-bit window, raises etc/reserved-memory-end past it so
OVMF's 64-bit window goes above it, turns KVM's zap-every-slot quirk off, maps
each piece as a RAM region of its own (a pure add) on its main loop, and under
WHPX runs the hypervisor's map outside the BQL. Its teardown takes every piece
out before the release, which frees the blocks before the process exits.

For the guest: the firmware's 64-bit PCI window starts past the reserved
range, 32 GiB or more higher than before; nothing else changes until the
guest's side maps the pool.
2026-11-17 06:35:09 -08:00
Anees Iqbal 14b69ece14 🆕 Record the platform's calls as a replay stream (format v2)
metal2vulkan's replay lane plays a guest's Metal work back on its own
runtime without a guest. It needs the calls our decoder makes on the
Vulkan platform, in order, with the guest memory the GPU reads, written in
its replay format v2.

The recorder is off until the host sets REIMS_VGPU_RECORD to a directory;
off, each hooked platform method costs one atomic load and a branch. On,
each process writes <dir>/<pid>.NNNN.m2vr segments (1 GiB each) from a
writer thread every 50 ms, libraries' bytes into the blobs directory beside
<dir>, and its counts into <dir>/<pid>.stats.txt.

- The hooks are in the Vulkan platform's trait impls (112 methods), and
  a thread-local depth records only the outermost call, the one core
  made. Arguments are written by their type: handles as object ids,
  bytes and strings as themselves, the rest from their Debug text.
- Before a commit, the recorder waits for the command buffers that ran
  before it and could still write what it reads, then writes the 4 KiB
  chunks of the memory it reaches that changed since the stream last held
  them. Only the ranges the GPU wrote are taken as the stream's once
  their command buffer completed, so CPU writes made meanwhile are kept.
- Blocks over guest memory and buffers in them are written as
  m2v.newBlockWithLength:storageMode: and m2v.newBufferInBlock:..., and
  each present the device's display shows, with a window or without one,
  as m2v.present of the surface's texture.
- format::summary reads a stream back; an ignored test prints it for a
  recording, on the host that made it.
- It never asks a buffer for its GPU address, which keeps a dma-buf
  import alive for good; addresses come from the calls that set them.

What the guest and the host observe is unchanged: the recorder only reads.
2026-11-17 05:56:10 -08:00
Anees Iqbal 64183b449e 🆕 Add several displays to the C API
RvgGraphicsDeviceConfig's fourth version adds display_count and
display_windows (the window configs of displays 1 and up, given exactly
where display 0 has a window). RvgGraphicsCallbacks' fourth version adds
cursor_glyph_at, cursor_show_at and cursor_move_at for displays 1 and up.
rvg_graphics_device_read_display_at and
rvg_graphics_device_cursor_position_at read any display, and
RVG_GRAPHICS_DISPLAYS_MAX names the limit. These are additions only: a host
built against the older structs, or one that gives a display_count of 0 or
1, gets one display and the same results and callbacks as before. The C
harness checks a device of two displays, and docs/api.md describes the
additions. QEMU's side follows in the next commit.
2026-11-15 15:16:04 -08:00
Anees Iqbal 9a4f391b23 📝 Say that Windows runs the window's callbacks on reims-vgpu.ui [ci skip]
With the window on Windows SDL3's on the library's own thread, as on Linux,
the C API's thread rules name Windows beside Linux: the header (from
window.rs, regenerated), docs/api.md and the feature's note in reims-vgpu's
manifest. docs/conventions.md says Windows takes Linux's host-call catch.
2026-11-15 07:44:23 -08:00
Anees Iqbal 7c672c67f8 🆕 Give the C API its Windows forms: a section's handle, an event
On Windows the host's guest RAM is a view of a pagefile-backed section and
QEMU's EventNotifier is a manual-reset event, so the two items that take the
host's OS handles get a form of Windows's own, under #if defined(_WIN32)
(cbindgen's [defines] maps cfg(windows) to it):
- RvgMemoryRangeFile is {void *handle; uint32_t flags; uint64_t offset;}, 24
  bytes; the create checks that a view the library may write maps the range's
  bytes from offset (MapViewOfFile, unmapped at once) and duplicates the
  handle (memory/windows.rs, with its tests);
- rvg_graphics_device_set_doorbell takes the event's handle.
A Windows device makes no bell, so it is handed neither route function.
Linux and macOS keep their forms and checks, under #if !defined(_WIN32); the
header's text changes there only by those guards and docs, and nothing the
guest or the host sees changes.
2026-11-15 06:43:52 -08:00
Anees Iqbal 5c1dd4f2e1 📝 Say where a rebound doorbell page drops its old routes
The device drops the routes on a doorbell page of its old context's queues
when a DOORBELL_PAGE_BIND write binds the page to another context, on the
host's thread that writes the register. The module doc still said such a
route stayed until its queue ended, and neither it, the host trait's
unroute_doorbell nor docs/api.md named the register write among the calls
that drop a route on the caller's thread, where the host must not wait for
a lock it holds around the call.
2026-11-14 18:01:16 -08:00
Anees Iqbal 18a87b6026 🆕 Give the device doorbell pages in BAR 4
A guest's single commit costs 5.4 us against 2.9-3.1 on a native Mac, and
about 1.5 us of it is the bundle's call into the kext to write DOORBELL.
The device now has a BAR 4 of 256 doorbell pages of 16 KiB, which a guest
binds to its contexts through DOORBELL_PAGE_BIND (0x040, `page | context <<
8`) where it took DOORBELL_PAGES (feature bit 46). A page is its context's
own DOORBELL: a write of a ring's id at its first byte wakes that ring
where it is one of the context's queues', and is answered at the doorbell
as there when it asks. Every other write is dropped and counted, logged
once per kind: at an unbound page or another offset (`unbound`), or of
ring 0 or another context's ring (`foreign`). Reads answer 0. A reset
unbinds every page.

A queue of a context with a page is routed on the page's doorbell
(`route_doorbell_page`), and on DOORBELL otherwise. A page bound to another
context drops the routes on it of its old context's queues, so the host
wakes no ring at a page but its context's.

What the host and guest see:
- the C API: `rvg_graphics_device_doorbell_write`, the config's
  `doorbell_pages` (third version) and the callbacks' `route_doorbell_page`
  (third version), whose thread docs/api.md section 5 names;
- FEATURES_HI bit 14 is offered only where the host sets `doorbell_pages`;
- QEMU's reims-graphics-pci (b4771167) maps BAR 4 and offers the pages;
- a guest that does not take the bit, or a host that does not offer it,
  has every doorbell on DOORBELL as before: the bind is ignored and every
  BAR 4 write dropped (`without_doorbell_pages_the_doorbells_are_the_register_s`).

The wire header's change rewrites the option ROM's record; its bytes are
the same.
2026-11-14 18:01:06 -08:00
Anees Iqbal 95843e7838 ✅ Prove a route waiting for the host's lock holds up nothing
QEMU applies a doorbell route under the BQL before route_doorbell returns,
so a ring-0 thread may wait for the BQL inside the device. That is safe
only if the device calls the route functions holding no lock of its own,
and no device function a host calls under the BQL waits for a thread
inside one. The device module's doc now names each call site and what it
holds: a QUEUE_CREATE, OBJECT_DESTROY or CONTEXT_CLOSE on the context's
lane (a ring-0 thread or the control thread) after the queues' table and
the ended rings are let go, and a reset on the resetting thread after it
let go of ring 0, the display, the completion ring, the table and the
ended rings. QEMU's registers are lockless, and its reset holds the BQL,
which its route function sees. What a host calls under its lock waits at
most for the control thread's display message, a ring's take or post, or
the table; the last device's release waits for the threads at most 5 s.

the_host_s_lock_held_around_its_calls_while_a_route_waits_for_it_holds_up_nothing
gives the test host a stand-in BQL its route functions take: while a
create's route waits for it, the thread holding it reads and writes the
registers, rings ring 0's and the queue's doorbells and resets the device,
and a watchdog ends the process if any call never returns. The route the
create took goes once the lock is let go. The C API and api.md name the
control thread among route_doorbell's threads, and design.md says which
hosts offer DOORBELL_ASKS.
2026-11-13 09:50:12 -08:00
Anees Iqbal 28250f0bed 🐎 Route plain queue doorbells to KVM where the guest asks apart
Every command queue doorbell write exited to QEMU and ran the library on
the guest's vCPU, though only a buffer that asks for its CB_SUBMITTED can
be answered there; the rest need only the queue's thread woken. Measured
on the Radeon 780M host, a doorbell QEMU takes as an ioeventfd costs the
guest 8.9 us and one run through the library 13.4 us, of a 17.1 us
commit.

The device offers DOORBELL_ASKS (feature bit 43, FEATURES_HI bit 11): a
guest that takes it writes an asking buffer's doorbell with the ring's
id and RGFX_DOORBELL_ASKS (bit 0), and every other doorbell with the id
alone. The device then answers at the doorbell only an asking write, and
gives each queue an eventfd its thread sleeps on, which it hands the host
with the ring's id (route_doorbell, a new C API callback at the end of
RvgGraphicsCallbacks, its second version). QEMU adds it as an ioeventfd
matching the id exactly, so KVM wakes the queue's thread in the kernel and
the vCPU goes back to the guest with no exit; the asking write matches no
route and reaches the library as before. A guest without the bit sees
nothing new: every doorbell is answered as before, and no queue is
routed.

The device routes at most 128 queues (KVM holds 1000 devices on its MMIO
bus, and QEMU ends the VM where KVM refuses one); a queue past them, or
one the host refuses, keeps its doorbell on the write, logged once per
kind and counted. A route goes as its queue ends, before the destroy,
close or reset is answered, and QEMU drops it under the BQL before the
callback returns, so a queue made again over the same ring gets every
write. The thread drains the eventfd and walks its ring on each wake, so
coalesced writes take every buffer in ring order.

QEMU's side is vendor/qemu d81bcaac. The guest's side, the ROM's record
and both guest sets follow.
2026-11-13 09:50:12 -08:00
Anees Iqbal 73b79f7e61 🐛 Quit a VM whose display read waits for a GPU that stopped answering
QEMU's quit hung for good after NVIDIA's Xid 109 (a context switch timeout)
in Apple's Modern Rendering sample, on an RTX 2080 and an RTX 3090: a
screendump's read of the display waited for its draw on the GPU, which never
finished, and the teardown at the quit waited for the read under the BQL
(thread_pool_free), so QMP's and HMP's quit both needed SIGKILL.

vendor/qemu 32a9f9a9 waits for the read at most 5 s, the bound the
library's release of its last device waits for its own threads, and past it
keeps the device to the exit, as a VM whose shutdown pauses it does. What the
host sees: such a quit now ends; a quit with no read under way, or one that
ends in time, is as before. docs/qemu.md says what was measured, including
that a pending screendump holds every QMP monitor while HMP, the vCPUs and the
guest go on, and docs/api.md the quit that keeps its device.
2026-11-12 16:38:38 -08:00
Anees Iqbal fab4be5201 🆕 Show black while the guest's display sleeps
A Mac's display goes dark when the OS puts it to sleep (Energy Saver's timer,
pmset displaysleepnow) and lights with the desktop at its wake. The device kept
showing the last frame instead, so a sleeping guest looked frozen.

What changes for the guest: the device offers DISPLAY_POWER (FEATURES bit 37)
on every host, and a guest that takes it sends SET_DISPLAY_POWER (command 8,
a 24-byte RgfxSetDisplayPower of display and on, answered COMPLETE), a display
command the control thread carries out. A reset turns the panel on. Nothing
else the guest sees changes: presents are taken and answered, VBLANKs go on,
and modes and the cursor's image stay.

What changes for the host: while the panel is off, the device's window and
rvg_graphics_device_read_display (QEMU's console and screendump) show black,
and cursor_show tells the host the cursor does not show; at the wake both show
what the guest shows again. The display callbacks' order now covers the
display power commands (docs/api.md). QEMU's reims-graphics-pci needs no
change: its console reads the display through read_display.

The tests that pinned the offered feature words and the backlog's display
command range take the new bit and command. The option ROM is built from the
wire header, so its record takes the header's new hash; the ROM's bytes are
unchanged (sha256 749434f8...).
2026-11-12 00:04:27 -08:00
Anees Iqbal 7f44053438 🐛 Answer a shared-memory GPU's working set from the guest's RAM
On a host GPU that shares the CPU's memory, the device answered
recommendedMaxWorkingSetSize with the platform's device-local memory, a share
of the host's RAM, which can be more than the guest's: guests of 8 GiB were
told 11864629248 bytes on a Radeon 780M and 24950464512 on an Iris Xe. No Mac
answers more than its RAM: a Mac's GPU that shares its memory answers a share
of it, from an Intel UHD 630's 0.023 (macOS 26.7.1) to an Apple M3 Max's 0.81
(macOS 27.0.1).

What the guest sees now:
- On a GPU that shares the CPU's memory (a Radeon 780M, an Iris Xe, an Apple
  GPU under MoltenVK), x86-64 and arm64 guests alike: the working set is three
  quarters of the RAM the host maps for the device, rounded down to 16 KiB, or
  the platform's answer where that is less; about 6 GiB for a guest of 8 GiB.
  maxBufferLength follows it by its rule (three quarters of the working set,
  about 4.5 GiB), and so does the kext's VRAM,totalMB (the working set in MiB).
- On a GPU of its own memory (an RTX 3090 or 5080, an RX 7900 XTX), and where
  the host passes no memory map: the platform's answer, as before, the card's
  own memory, as an AMD Radeon Pro 5300M answers its own 4 GiB less 16 MiB.

The RAM is the sum of the memory map's ranges, so no C API value is added:
q35's map leaves out the 384 KiB below 1 MiB, and vmapple's under HVF adds its
firmware's 1 MiB and config's 64 KiB, both well inside Apple's range.

On an Iris Xe, a macOS 14.8.9 guest told 24950464512, 5726617600, 4278190080
or 1610612736 bytes did the same work over a cold boot and a Safari scroll:
the runtime's blocks, the page's frames and the presents.
2026-11-11 13:16:00 -08:00
Anees Iqbal 56acf05064 🐛 Let go of the GPU device at the last graphics device's release
The C API's release ended a device's threads without waiting for them, and
the library kept its GPU device to the process's end; QEMU never released
its device at all, as it unrealizes nothing at its exit. A process that
exits with the runtime's device live can end with SIGSEGV inside NVIDIA's
driver (the commit before).

What the host now observes:
- rvg_graphics_device_release of the process's last graphics device waits,
  at most 5 s, for that device's threads, its objects and their GPU work to
  let go of the GPU device, then lets go of every GPU device the library
  keeps: the runtime's device is torn down on the releasing thread before
  the release returns (GraphicsDevice::let_go_of_gpu, LET_GO_BOUND).
- A device callback still running holds that wait up; one that waits for a
  lock the host holds around the release, for the whole 5 s. Past them the
  library keeps its GPU devices for the process, as before, and logs a
  warning naming what still held them.
- A device created after the let-go runs on a new GPU device, whose
  numbering starts again. A release while another device lives waits for
  nothing, as before.
- QEMU tears its device down as it quits, once vm_shutdown stopped the VM
  for good, with BAR 2 disabled first (vendor/qemu's reims-graphics-pci.c).
  None of its callbacks takes the BQL, which it holds there. A VM whose
  shutdown action pauses it, or that was stopped before the quit, keeps its
  device to the exit as before.

A new test (on_vulkan_the_let_go_waits_for_a_callback_blocked_on_the_...)
blocks raise_interrupt on a lock the releasing thread holds: the let-go
returns at its bound naming the ended decoder, and lets go once the lock goes.
The header, docs/api.md and QEMU's side change together.
2026-11-11 10:35:17 -08:00
Anees Iqbal df8f36bc9b 🐛 Answer a device the host's driver refuses as no device
A Vulkan device the host's driver refused at its make
(VK_ERROR_INITIALIZATION_FAILED and the other Vulkan failures, its memory run
out, or its device lost) ended the process at MTLCreateSystemDefaultDevice()
with a fatal line. It is the same class as a host with no Vulkan device, which
the library already answers: the platform makes none, and the graphics device's
create refuses.

Measured on an RTX 2080 behind a Thunderbolt 3 link (driver 620.70.06), whose
BAR1 is 256 MiB: each device maps 67 MiB of it, and 8 processes making a device
at once had 4 to 6 of them refused with -3 (NVRM: "dmaAllocMapping_GM107: can't
alloc VA space for mapping"). The refusals come from makes that race: with other
processes' live devices holding 245 of BAR1's 256 MiB, or seven devices of 16
queues each, a QEMU's device was still made, taking about 5 MiB. A QEMU whose
device the driver refused died at its realize.

What the host observes: rvg_graphics_device_create answers
RVG_ERR_HOST_RESOURCES where the driver refuses the device, as it does where the
host has no device, instead of the process dying; the library logs an error line
naming the refusal first. RVG_ERR_HOST_RESOURCES's message, which QEMU's realize
error prints, now reads "the host refused memory, a pipe, a thread or a GPU
device", and the header and docs/api.md name the GPU device among its causes.
The guest sees nothing: no device is realized either way. No degradation kind
changes.
2026-11-11 08:23:42 -08:00
Anees Iqbal cd6b7bb2bf 🐛 Answer framebuffer read to an arm64 guest as its host GPU can
arm64 guests drew WindowServer's menu bar, and some widgets, 100% black.
CoreAnimation compiles framebuffer fetch into its generic shader by
isFramebufferReadSupported, and that shader blends against the fetched
destination whatever the answer. The device answered no to every guest,
so the destination was the AIR's NaN. Metal on the M3 Max writes the same
NaN for that pipeline and its buffers, so the translation was right; the
answer was not one an Apple silicon Mac gives.

The x86 Macs split on it (AMD 5300M no, Intel UHD 630 yes, measured again
today), and x86 guests keep the AMD answer, which keeps their frameworks
off the platform's costly fetch. So the answer now follows the guest:

- The C API's RvgGraphicsDeviceConfig gains guest_arch (RvgGuestArch:
  RVG_GUEST_ARCH_X86_64 0, RVG_GUEST_ARCH_ARM64 1), its second version: a
  host built before it, whose struct_size ends before the field, serves an
  x86-64 guest; any other value is RVG_ERR_INVALID_ARGUMENT. The Rust API's
  GraphicsConfig gains GuestArch alike.
- The device-info blob answers isFramebufferReadSupported with the
  platform's answer for an arm64 guest (yes on MoltenVK, RADV, ANV and
  NVIDIA, which fetch through the pixel interlock), and no for an x86-64
  guest as before.

What the guest sees: an arm64 guest's MTLDevice answers
isFramebufferReadSupported yes where the host GPU fetches, once the host
names the guest arm64 (QEMU, next commit). An x86-64 guest's blob is byte
for byte what it was. On ANV and NVIDIA a pipeline that fetches an
attachment of a format the runtime does not fetch there (R8/RG8 sRGB, and
on NVIDIA the packed 16-bit formats and RGB9E5) is answered nil, relayed.
2026-11-09 18:15:57 -08:00
Anees Iqbal 031e0e8ca3 🐛 Hold the process's exit until the library's GPU steps end
A process exits on one thread, which runs the exit handlers and the loaded
libraries' destructors while every other thread goes on. A thread of the
library's inside a driver then ends the process: on the RTX 5080 test processes
ended with SIGSEGV inside libnvidia-glvkspirv after their tests passed, and the
awake thread's touches segfaulted 79 times in six minutes before it got a gate
of its own. The runtime's guard covers only the runtime's own threads, and the
platform keeps its devices for the process, so dropping them is no way out.

So the awake thread's gate becomes the library's: reims_vgpu_vulkan::exit_gate.
Each job of the library's threads that may call a driver is a step of it:
every reims-vgpu entry (the C API's calls, the device's callbacks, the jobs of
lanes, compile threads and surface workers), each compile (a making), a
window's frame, a video picture landed or frame encoded, and each call of the
video crate's threads, through a new Runtime::exit_step. An exit handler,
registered at each device's adoption, as a compile pool starts, after each
making and at each power of two of a thread's steps, closes the gate and
waits for the steps in progress on other threads, 2 s at most, or 60 s while
a compile is among them, as the runtime's guard waits for its makings. A step
begun after it ran parks its thread for good, except on the exiting thread.

What the host sees: an exit (QEMU's quit, a test process's end) now waits for
the library's GPU work in progress, bounded as above, where it could end the
process with a signal; a library thread or a call of the host's that would
begin work after the exit began parks. docs/api.md says so. Nothing the guest
sees changes. Tests: a child process that exits mid-compile with a second
compile queued (the first ends, the second never runs), the gate's own exit
children, and the awake thread's exit test on the shared gate.
2026-11-08 09:23:03 -08:00
Anees Iqbal 5a4418c894 📝 Say that core is the Vulkan crate's module [ci skip]
reims-vgpu-core is folded into reims-vgpu-vulkan, so the docs, the
manifests' comments and the crate descriptions that named the crate name
its module now: the crate lists and graph, seven crates, core's files under
crates/reims-vgpu-vulkan/src/core, the testkit feature, and what the x86-64
leg runs. The design note that put the decoder in core says where it is,
reims-vgpu's graphics::decode, and the path of a deleted file goes. The
kache measurement keeps the crate's name, as it was measured then.
2026-11-08 01:55:07 -08:00
Anees Iqbal 6fb33ecd27 🎨 Rename the reims-graphics crate to reims-vgpu-graphics
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.
2026-11-08 01:37:50 -08:00
Anees Iqbal acd9919a93 📝 Say the library runs on the Vulkan platform alone [ci skip]
The Metal platform is gone (the commit before): AGENTS.md, README.md and the
docs now say the library carries out the guest's calls on the Vulkan
platform, on Linux and on a Mac over MoltenVK for development and tests;
that the display's shaders live in the Vulkan crate; that `cargo xtask
dist` writes target/dist-vulkan on every OS; and that the tests of the
Vulkan platform compare with Metal's recorded answers. architecture.md's
section 4.6 describes the answer layer and the macOS message layer in
place of the metal crate's. conventions.md keeps "core changes as little as
the Vulkan and Linux work allows" without its reason, the Metal product.
2026-11-07 23:22:28 -08:00
Anees Iqbal a0dc2e80ff 🔥 Draw the scanout at each refresh, without the host's dirty log
The display showed the guest's scanout again at a refresh only where the
host's dirty log said the guest wrote it (scanout_written, QEMU's log over
BAR 2's allocations). The scanout shows only at boot and in recovery, and
the owner takes its full cost for the simplicity (2026-11-07): the
callback, RvgGraphicsScanoutWrittenFn and RvgGraphicsCallbacks'
scanout_written, are gone from the C API, with reims-vgpu's
ScanoutWrittenFn and reims-graphics' Host::scanout_written.

Each refresh while the guest has a scanout now asks the screen to show it
again (Screen::present). The window draws it only while it shows the
scanout: while a presented surface shows, a refresh draws nothing, and the
guest's presents alone draw, as before, so an accelerated desktop's
refreshes cost no frame (a 4K window at 120 Hz would otherwise copy about
4 GB/s for nothing).

For the host: RvgGraphicsCallbacks loses its scanout_written field, so the
cursor callbacks after it move up one pointer; QEMU's reims-graphics-pci
no longer sets it (the commit before). For the guest: the boot and
recovery screens show what the guest wrote by the next refresh, as before.

Window::frames_asked counts the frames a window is asked for, which the
new tests read: a refresh draws the scanout while no surface shows, and
nothing while one does.
2026-11-07 22:15:20 -08:00
Anees Iqbal d4a4431911 📝 Describe the architecture and the C API of our device [ci skip]
architecture.md and api.md described Apple's paravirtualized device: its
tasks, FIFOs, displays, frames, IOSurface and video devices, suspend and
resume, isolated tasks, the suite's runner and QEMU's apple-gfx. api.md now
specifies the C API there is, the graphics device's ten functions, with its
threads and locks in section 5, which the header cites. architecture.md
describes the crates and the device as they are, keeping the section and
decision numbers code cites; the numbers of what went are retired, not
reused.
2026-11-07 20:07:29 -08:00
Anees Iqbal 4f5d1d5069 ⬆️ Build on metal2vulkan fa07d59e81's runtime
Pin moves 17 and 18 in one: metal2vulkan development 6b4b4b0692..fa07d59e81
(220 commits), RUNTIME_VERSION 1807, SEMANTICS_VERSION 1990,
ARTIFACT_FORMAT_VERSION 492. What changes for the guest and the host:
- Guest RAM on a dma-buf device is a few long chunks, none made ahead, idle
  ones released; no making or copy waits for a chunk's import. On the 780M the
  first object over an unimported chunk took 665-692 ms and now 1-2 ms, and a
  gather's encode about 660 ms and now 23-38 ms.
- On Linux the process's exit waits within a bound for the runtime's work,
  then runs the earlier exit handlers (QEMU's exit notifiers among them).
- A colour attachment stored DontCare stores as the driver stores it by
  default, announced dont-care-store, and keeps its earlier texels, as Apple's
  GPU leaves them, under REIMS_VGPU_EXACT=dont_care_colors.
- Off macOS, the GPU's writes to no-copy memory made with Metal's private
  option bit 24 are dropped through a copy, as Metal drops them.
- Twenty formats Metal makes and the runtime refused, its one-plane YCbCr
  formats, the padded 10- and 12-bit display formats and transfer twins
  among them, are made for copies alone; every read, write and render of one
  stays refused.
- A 2D or 2D-array texture over a buffer whose texels run past its length is
  made, its tail the runtime's own.
- Mesh pipelines with maxVertexAmplificationCount above 1 are made, and their
  amplified draws refused.
- ARGB8Unorm destination alpha is blended in the shader where no Vulkan state
  gives Metal's blend; an executed command's unstrided buffer reads at stride
  2^32-1, as Metal reads it.
- Encoding costs less per draw: attachment memory worked out once a layout
  version, host-byte uses kept in the encoder, per-thread argument-table
  stamps, a bind memo.

No degradation kind is added or removed, so answer.rs places nothing new.
Cargo.lock is unchanged: the runtime's dependencies are the same, and the lock
keeps its metal2vulkan source lines stripped. RuntimeGap::
IndirectCommandUnstridedBuffer, which this tree never named, is gone.

Adapted here:
- The Linux remap test and the remap docs read Device::
  pointer_imports_follow_their_address, in place of the removed DriverFact::
  PointerImportsFollowTheirAddress.
- REIMS_VGPU_EXACT names dont_care_colors, selecting DontCareColorPolicy::
  Kept (platform.rs, docs/api.md, an accuracy-ledger row).
- The texture-gap tests take RGB10A8_2P (624), a format the runtime still
  refuses, since 501 is now made for copies alone.
- The MoltenVK tests take the copies-only formats: the formats-the-runtime-
  lacks test drops 501 and holds the two-plane RGB10A8 family (624-627); a new
  test makes and copies the nine one-plane formats at every creator as Metal
  does; the legacy-heap comparison leaves those nine out. Two ignored tests
  and two accuracy-ledger entries record the runtime's gaps there, asked of
  metal2vulkan: a kernel's read of one reads zeros, and in a heap its texels
  are tiled where Metal lays plain rows.

Checked on the Mac (MoltenVK), the 780M (RADV, the whole workspace) and the
RTX 5080, and the merged tree on um870's 780M with a video decode boot. The
Iris Xe leg is still to run: its host stopped answering before the run ended,
and the leg runs when the host is back, with any failure fixed forward.
2026-11-07 13:13:06 -08:00
Anees Iqbal 99bfd0583f 🐛 Build the library on Linux without the vulkan feature
On Linux the Vulkan platform is the library's only one, yet reims-vgpu and
reims-vgpu-c refused to build without their `vulkan` features (a
compile_error!), and the code behind it did not compile either: a
default-feature Linux build of the package failed. A crate that does not
build in a feature setting is a failure, so the platform is now unconditional
on Linux.

- reims-vgpu's new build script sets `cfg(vulkan_platform)` on Linux, and on
  macOS with the `vulkan` feature, declared for check-cfg. Every
  `feature = "vulkan"` gate in the crate is that cfg; the gates of "macOS or
  the feature", true on every target the library builds for, are gone.
- The Vulkan platform's dependencies are not optional on Linux; on macOS they
  stay the feature's, optional, so the Mac's default build is as before.
- reims-vgpu-c makes every handle on VulkanPlatform on Linux whatever its
  features; the compile_error!s go.

Behaviour is unchanged on both OSes: on macOS every cfg answers as the
feature did, and on Linux as the builds with the feature did. The docs and
comments that said Linux needs the feature say it no longer does.
2026-11-07 06:54:33 -08:00
Anees Iqbal 89c76816fc 🆕 Tell the graphics device's host the guest's cursor
The library kept the guest's SET_CURSOR and MOVE_CURSOR for its own window
and told the host nothing of them, so QEMU's console never had a cursor
for reims-graphics-pci: a VM on the reims-vgpu graphics option shown
through QEMU's own displays (SPICE, VNC, GTK, D-Bus) had none, though the
pointer moved the guest's, where apple-gfx's displays draw one.

RvgGraphicsCallbacks grows cursor_glyph, cursor_show and cursor_move, the
display's own callback types, and rvg_graphics_device_cursor_position reads
where the guest put its cursor's hot spot. The device queues them onto the
display thread in the order its control thread took the guest's commands
and its resets, so they run as a display's do and never inside a call of
the host's, a reset's included. The glyph is the straight-alpha RGBA the
window takes; the cursor shows once the guest has an image while it shows
its cursor. A host built against the first version passes 40 bytes and is
told nothing. The guest sees nothing of it, and the window is unchanged.
2026-11-07 04:20:17 -08:00
Anees Iqbal 8970ba8391 🐎 Answer a landed download on its ring-0 doorbell's thread
A CPU lock of a surface whose pages already hold its device cache (a decoder's
output whose early copy has landed, or a cache nothing wrote) still waited for
the control thread to wake and take its SURFACE_DOWNLOAD: p50 95.4 us from
the doorbell to the COMPLETE on the 5080 (decode-perf), most of it the idle
core's wake.

A DOORBELL write of ring 0 through mmio_write_taking now takes ring 0's next
message on the writing thread and answers it there, where it is a
SURFACE_DOWNLOAD the host has carried out already (Host::surface_downloaded,
new, default false), the control thread sleeps with every answer of what it
took posted (Submit::asleep, set and cleared under the ring's lock), the
block's lane has nothing left and the control completion ring has room.
Every lock is tried, the message is copied onto the stack, and nothing is
allocated or freed. The host's answer is the caches' own (downloaded_now):
true only where its download would answer at once with nothing to copy and
nothing to wait for, keeping the download's counts as it does. The interrupt
is raised with no lock held. In every other case the control thread takes
the download as before.

What changes for the host: a ring-0 DOORBELL write through
rvg_graphics_device_mmio_write_taking may now post a COMPLETE and call
raise_interrupt inside the call, as a queue's doorbell write already may (the
header, docs/api.md). The guest sees its answer sooner; its order among ring
0's answers is as the control thread gives it. QEMU 22ae1fd1 takes ring 0's
doorbell with an ioeventfd, so under QEMU nothing changes until
reims-graphics-pci sends that write through _mmio_write_taking too.

Tests: a_landed_download_is_answered_on_its_doorbell_s_thread and
a_doorbell_s_thread_leaves_a_download_the_control_thread_must_take
(reims-graphics), a_landed_download_s_answer_at_its_doorbell_allocates_nothing
(reims-vgpu). a_landed_download_s_doorbell_to_its_answer now measures both
writes, in turns over five rounds each.

Car 14's stack: device.rs keeps both new methods beside each other,
c14-submit-path's mark_idle and mark_awake (a queue's ring, efd360f45) and this
commit's download_on_doorbell (ring 0); ring_taking sends ring 0 to
download_on_doorbell and a queue's ring to answer_on_doorbell, as before.
2026-11-05 21:59:36 -08:00
Anees Iqbal 6bfd19641b 🐎 Serve ring 0's lanes on shared threads kept 10 s
Each of ring 0's lanes (a context's, the presents', a block's) had a thread of
its own, made as a message came to a lane with none and gone once the lane had
had none for 1 s. So every new surface's block made a thread for its first
SURFACE_PAGES, and so did every lane's message after a pause of a second. A
thread's start may map a 2 MiB stack and its end unmap one, writes of the
process's memory map that a vCPU's page fault waits behind: car 12's B1
counted 345 graphics threads made in 30 s of a WindowServer probe, and a vCPU
sat 30 ms or more in a fault while one of them was in munmap of 0x201000
bytes, inside an 81 ms frame (msi RTX 5080; measured).

Ring 0's threads, reims-vgpu.graphics-ring0-<i>, now serve the lanes. A lane
handed a message while it has no thread is given the thread that went idle
last, or one made for it where none waits, and keeps it until it has no
message left; the thread then waits for the next lane and goes once it has
waited 10 s (reims_graphics::keep, new: KEEP, and a clock the tests move). A
lane with nothing to do holds no thread, so the device holds as many threads
as it had lanes busy at once in the last 10 s, whichever contexts and blocks
they were. A lane with a message is never refused a thread, so the waits the
lanes' order relies on still end.

Measured on the M3 Max with
ring_0_s_threads_under_a_windowserver_probe_s_and_a_game_s_wakes, which
replays 30 s of B1's rates (presents at 60 Hz, ten contexts' messages at gaps
of 1.1 to 3 s, a new block's pages every 150 ms and again 1.5 s later) and of
a game's, wakes made up to their kinds, which make more threads without it
than the boots counted: ring 0's threads made in each 10 s went from 177, 183
and 181 to 3, 2 and 0 under the probe's wakes, and those ended from 158, 183
and 185 to 0, 0 and 1; under the game's, made from 14, 11 and 10 to 2, 0 and
0, and ended from 10, 11 and 11 to none. A synchronous create's round trip
(a_sync_create_s_round_trip, release, three runs each with this change and
without, alternating, on the M3 Max under other builds' load): after a pause
of 1.2 s, 64 to 171 us at the median against 116 to 353 us without, where the
pause ended the lane's thread; back to back, 13.6 to 16.4 us against 10.3 to
13.9; behind four creates it does not wait for, 10.6 to 12.8 us against 11.7
to 12.5. What this adds to a message for a lane that had emptied is a lane
record made again and the hand-over of a waiting thread through its own
condvar, where the lane's own thread was woken before.

For the host: the callbacks the lanes make (raise_interrupt among them) run on
reims-vgpu.graphics-ring0-<i> in place of reims-vgpu.graphics-context-<n>,
reims-vgpu.graphics-presents and reims-vgpu.graphics-block-<offset>. Thread
names are diagnostics (docs/api.md); the header's comment, api.md and
design.md name the new ones. The guest sees only timing.

Tests, on the test clock:
a_steady_load_s_lanes_are_served_by_one_thread_through_its_pauses (30 messages
of three contexts, each after 2 s, on one thread; it goes after 10 s with
none), a_burst_s_other_threads_go_once_they_have_waited_keep (three busy
lanes' threads, then one lane at a time: the two others go 10 s after the
burst, the one serving stays) and
the_device_s_end_ends_the_threads_that_wait_for_a_lane. The tests that named a
lane's thread now check it is one of ring 0's;
an_idle_lane_goes_while_another_context_s_is_busy, whose lane thread no longer
exists, is gone.
ring_0_s_threads_under_a_windowserver_probe_s_and_a_game_s_wakes is the
measurement, run by hand on macOS.
2026-11-05 21:59:35 -08:00
Anees Iqbal ed70015809 🐛 Answer nil where the runtime refuses an object for a gap
On the Vulkan platform, a runtime refusal at a creator for a gap of its own
or of the device's (Unsupported, but by a GPU family or a device Metal
itself refuses it on; NotImplemented; AppleOnly; a compile's Unsupported)
ended the process at the creator, where Metal makes the object. A Flutter
app's BGRA10_XR render pipeline on an RTX 5060 Ti took a macOS guest down
this way (Unsupported { feature: Format, needs: NotImplemented }).

Behaviour change, for the guest and the host: by default the creator now
answers nil, a pipeline state or a library creator with the runtime's
refusal as its NSError, so core's nil-without-error death never fires;
textures, views, buffers, heaps, functions, sampler and depth-stencil states,
argument encoders, indirect command buffers and rate maps answer nil. Apple's
guest framework then fails the work that names the object, as where Metal
answers nil: what was a VM going down is that exec faulting. In strict mode
(REIMS_VGPU_STRICT=1) each still dies at its selector with the same line.

This keeps the owner's rule on runtime gaps: the gap stays visible, relayed
as the new kind inexact-refused-create (the first of its kind writes a line
naming the refusal and the descriptor's formats, each one is counted) and a
death in strict mode, and it is handed to metal2vulkan. Nothing here makes
the missing feature. A lost device, a Vulkan failure, no memory, an answer
the runtime cannot prove and every other refusal still die at the creator.
The library's own pipelines and shader library are unchanged.

The kind is placed in every_inexact_kind_is_placed_once, the placement test
of this platform's own kinds, which also checks its code is no runtime
kind's. The accuracy ledger lists it.
2026-11-05 21:59:35 -08:00
Anees Iqbal a562b48c14 🆕 Read the graphics display back, and show it in QEMU's console
reims-graphics-pci's QEMU console carried input only, so QMP's screendump
was always an empty 640x480 image: the login-clock, desktop and lane-gate
checks had no way to see the guest's frame once WindowServer presents
IOSurfaces, which live in the host's device caches, not in the scanout.

For the host: rvg_graphics_device_read_display, the C API's 57th function
(additive), reads what the display shows now into the host's buffer: the
scanout or the presented IOSurface, through the display's colour, drawn as
the window draws it into a texture of the display's mode, BGRA8 rows of
width * 4 bytes, black where the guest shows nothing. It gives the mode's
size whatever it answers, so a NULL buffer asks it, and waits only for its
own draw on the GPU, on a queue of its own. QEMU (vendor/qemu 70a9a466)
calls it from the console's gfx_update on a thread of its pool, so the
console, QEMU's displays and screendump show the guest's frame.

For the guest: nothing. The read answers no present (the window's draw does,
through ScanoutDraw::encode, now over encode_shown), tells the guest no
mode, and holds a presented surface's block only while its draw reads it,
as the window's draw does. A device with no window keeps the guest's
scanout in a screen of its own for the reads, offering the same 1920 x 1080
at 60 Hz as before.
2026-11-05 21:59:34 -08:00
Anees Iqbal c9b243ff80 📝 Say what reims-graphics-pci calls and what its BAR 2 needs [ci skip]
QEMU's reims-graphics-pci writes every register through
rvg_graphics_device_mmio_write_taking, so a queue's doorbell may answer its
next command buffer on the vCPU; docs/api.md said it called everything but
that function. Its BAR 2 is the library's 1 GiB region, with the guest's
allocations from 0x400000, where the docs still said 256 MiB and 0x20000,
and a 1 GiB BAR needs the machine's max-ram-below-4g=1G, which docs/qemu.md
never named: reims-ctl does not add the device, so whoever adds it needs the
option too.
2026-11-05 21:59:32 -08:00
Anees Iqbal 859625a1f5 🐛 Keep the graphics display's scanout across a reset
A reset of the reims-graphics device (STATUS 0, or the host's reset) blanked
the display: the screen was told there was no scanout, and the window kept
its last frame. The kext's start resets the device to take it, and where the
start fails after that (the device lists no usable display, IOFramebuffer's
start fails) it resets it again on the way out. The OS then draws into the
firmware's framebuffer, but the firmware's scanout was gone. The host's
window stayed on the boot screen, and nothing the guest drew after that
reached it.

What the host sees now: a reset leaves the display's scanout as the last
SET_SCANOUT set it. A GPU's display engine does the same across a reset of
its driver. The screen is told nothing at the reset, and each refresh shows
the guest's writes there as before, until the guest sets another scanout or
blanks it. A reset while the display pipe shows a surface shows the kept
scanout in its place. The guest sees no change: nothing it reads names the
scanout.

The tests cover the failure after the take on the device and through the
window's sink on the testkit's platform. In the crate's tests the window
asks the host for no screen, so on Linux they start no UI thread.
2026-11-05 21:59:31 -08:00
Anees Iqbal 2204e4a7dc 📝 Name the closes' worker among raise_interrupt's threads [ci skip]
Since the close-cost change, a context's close lets go of its objects on the
closes' worker, reims-vgpu.graphics-closes-<i>, and drops the close's drain
there. Where its command buffers had already finished, the drain's answers run
on that thread: the close's answer, the waiting posts and raise_interrupt.
Releases chained behind the drain answer there too. The header promises
raise_interrupt only on the threads it names, and this one was missing from
the list. It is added to the C API's list, the Rust API's and docs/api.md's.
The names list in api.md also gains graphics-video-<i>, the video sessions'
worker, which raises nothing. cargo xtask header rewrote the header.
2026-11-05 21:59:30 -08:00
Anees Iqbal ff0a952a2b 🎨 Name the event-waits thread in the reims-vgpu scheme
Every other thread of the library's is named reims-vgpu.<role>, so a sample or
a crash log groups it with its device; the watcher of command buffers waiting
for shared events was still rgfx-event-waits. It is now
reims-vgpu.graphics-event-waits, and docs/api.md's list of thread names has it
with the graphics device's others. Thread names are diagnostics (docs/api.md),
so nothing a guest or host sees changes.
2026-11-05 21:59:29 -08:00
Anees Iqbal f892111aa6 🐎 Give each surface block and process a worker turn of its own
The surface worker and the ICB worker were one thread each, so one block's slow
view (9000 mappings of a 3840x2400 layer took up to 478 ms on the msi 5080
host) held every other block's SURFACE_PAGES behind it, and one process's ICB
creates every other process's. Each worker is now a pool of at most four
threads, made as a job finds none waiting and gone after 1 s idle, that runs one
key's jobs one at a time in the order handed over and different keys' at once.
The surface worker's key is the block (its SURFACE_PAGES, its BUFFER_OVER_PAGES
handed over, its release's drops, a buffer over its view at its destroy); the
ICB worker's is the buffer's context. A key's job wakes one waiting thread, a
ready key that finds every thread busy is counted, and a job runs where it is
handed over where no thread can be started.

No job waits for another key's job, so the cap cannot deadlock: a
BUFFER_OVER_PAGES waits only for its own block's SURFACE_PAGES, which ran
before it, and SURFACE_PAGES jobs wait for nothing. A debug build checks it in
Unsettled::wait. The one order the single thread gave that nothing needs: two
BUFFER_OVER_PAGES of one context on different blocks are made in either order,
which no answer orders; the context's later messages still wait for both.

The threads are named <name>-<i>, which docs/api.md, the header's comment and
reims-vgpu's callbacks doc now say. Beside K blocks that each run 25 ms jobs
back to back, another block's job starts after its hand-off in 0.015 ms at the
median for K of 1 or 2, 5 to 6 ms for 4 and 35 to 38 ms for 8, where one thread
took 24, 115 to 117 and 241 ms (another_blocks_job_beside_busy_blocks, release
build, M3 Max, two alternated runs each at load averages of 28 to 52).
2026-11-05 21:59:29 -08:00
Anees Iqbal 05d23288a2 🆕 Carry each block's pages and downloads on a lane of its own
A block's SURFACE_PAGES rode its context's ring-0 lane and its
SURFACE_DOWNLOAD ran on the control thread. The kext's hand-over of a
surface's put-off pages is a SURFACE_PAGES for the surface's maker, posted
from another process's CPU lock or from the release thread, and followed by
a download or a release without waiting for its answer. On the maker's lane
it sat behind the maker's unrelated messages, or behind a lane held by a
maker that had closed, and the download on the control thread could go
first.

Every SURFACE_PAGES and SURFACE_DOWNLOAD now goes to the lane of the block
it names, in ring order, whatever its flags or context. What reads what
that lane makes of the block waits for it through its position: a buffer
or heap over a pages block, a buffer over a surface's pages, and a release.
A context's later messages and command buffers still wait for its
SURFACE_PAGES, and a SURFACE_PAGES waits for its context's earlier makes
over the same block. So the only order dropped is a SURFACE_PAGES waiting
for its context's messages that do not name its block. A SURFACE_PAGES
also no longer clears a block's holders, so a release after a hand-over
still waits for the other holders' lanes. The lanes' module doc lists
every message that names a block by offset and what orders it.

What the guest sees: answers to a block's pages and downloads may come
before those of messages its maker posted earlier on other lanes. The kext
matches answers by seqno. The fuzz now generates every block-naming kind
against held block lanes.
2026-11-05 21:59:29 -08:00
Anees Iqbal 17f6d6cf47 📝 Name every thread that raises a graphics interrupt [ci skip]
raise_interrupt's thread list named the control, refresh, queue, compile and
ring-0 lane threads and the platform's handler thread, but not three threads
of reims-vgpu's that post on the control completion ring. Counted by thread
in two boots of 75 processes on the RTX 5080 host (car 8's image, before and
after ring 0's lanes), the control ring's interrupt was also raised on a
command queue's lane threads (reims-vgpu.graphics-lane-<id>, 84 and 62
times), the surface worker (reims-vgpu.graphics-surfaces, 4196 and 4284) and
the ICB worker (reims-vgpu.icb-create, once each). The header's comment,
docs/api.md and reims-vgpu's own doc now name them.
2026-11-05 21:59:28 -08:00
Anees Iqbal 4f666851e4 🐎 Carry each process's ring-0 messages out on a lane of its own
Ring 0's control thread carried out every guest process's control messages
in ring order, so one slow message, a pipeline compile of tens of ms or a
large buffer's make, held every other process's command buffers behind it:
their queues wait until the control thread has carried out what they name.

The control thread now takes each message and hands the lifecycle messages
of a context to that context's lane (`reims-vgpu.graphics-context-<n>`) and
PRESENT_SURFACE to the presents' lane (`reims-vgpu.graphics-presents`). Each
lane carries its messages out in ring order, made on demand and ended after
a second idle. A message waits on the lanes only where an order crosses
processes: a present for the creates and destroys of its surface's textures
and the closes of contexts that hold one, a block's release for its former
holders, a scanout grant for every other context, a resource-ID chunk for
its previous holder's close, and a context's first message for every close
not yet carried out. A queue's gate also waits for its own context's lane
to carry out the messages it names.

Each lane's thread waits on a wake of its own: it is woken for its own
messages and, where its next message waits for other lanes, as they carry
theirs out. With one wake for every lane, a boot of 75 processes on the RTX
5080 host woke every lane at each message any lane took or carried out, so
no lane ever went idle, and command buffers waited 1 ms or more for ring 0
1610 times (3266 ms in all) against 428 (1064 ms) on the control thread
alone; beside 75 idle lanes a context's burst of 200 messages took 16 to 59
ms at the median against under 1 ms beside none.

Display commands stay on the control thread, held, and a reset still drops
what no lane has begun, after the lanes' begun messages return. The host's
raise_interrupt may now run on a lane, which the header and docs/api.md say
(an additive change to the thread list).
2026-11-05 21:59:28 -08:00
Anees Iqbal 5bde808250 🐎 Answer a command buffer on its doorbell's vCPU
A guest write to a command queue's DOORBELL can now answer the buffer at
the head of that queue's ring, if it comes through
rvg_graphics_device_mmio_write_taking. The answer posts the buffer's
CB_SUBMITTED and raises the queue's vector on the writing vCPU, before the
queue's thread wakes. The buffer stays on the ring. The queue's thread
then takes it as it takes any other, without waiting for ring 0 again.

The vCPU only tries locks, and never waits, loops or allocates: the
message is copied onto its stack, at most 16 KiB. Any try that misses
leaves the buffer to the queue's thread, as before: a lock held
elsewhere, ring 0 not yet carried out as far as the buffer waits for, or
a buffer that uses a device cache, waits for an event or sits behind a
held buffer. The answer takes the buffer's lane turn and its ticket in
the commit order together. The begin uses them in place of its own, so
queue, commit and ring-0 order are those of an answer at the take.

What the guest sees: CB_SUBMITTED of such a buffer arrives inside the
doorbell write. A platform refusal of a buffer answered there fails the
buffer in its turn, after the answer, as one answered at its take does.

Tests:
- a counting allocator holds the vCPU path to no allocation;
- a reset between the answer and the begin lets the answer go;
- a refused make after an answer fails in turn;
- the decoder fuzz checks that queue and commit order match the
  worker-only path;
- the device checks that an answered buffer waits for no later ring-0
  message.
2026-11-05 21:59:26 -08:00