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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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...).
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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.
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.
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).
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.
metal2vulkan e71efbe0e9 is c8a0481cf8 plus three stacks (RUNTIME 1747):
- Command queues share VkQueues where the device's own check finds the GPU
idles at each switch between queues (the 5080), with an unshared form for
a queue that must never wait behind another's long command buffer:
new_command_queue_unshared. The graphics lane's WindowServer queues
(RGFX_QUEUE_UNSHARED) now take it through unshared_queue, which made the
plain queue until the runtime had one; on a device that shares no VkQueue
it is the queue every create makes. The runtime's exact answers keep every
queue on its own VkQueue, so REIMS_VGPU_EXACT gains queue_sharing
(QueueSharingPolicy::PerQueue), with its accuracy-ledger row; docs/api.md
now also lists extended_range_blits there.
- Noted textures' pattern reads and writes are logged once each, with no
allocation per draw.
- A command buffer joins its ended encoders' resources into its residency
where its work reads them, not as each encoder ends (end_call with 4096
resident: 205 to 7.2 us on the RTX 5080); a sampler state's creation prunes
the live states' map only once it has doubled (1.97 to 0.56 us at 1000
live, 16.75 to 0.48 us at 10000, on the M3 Max); a commit counts its
buffers' host imports in place, and the translator's spec_key makes its
lists once.
A reset (the framebuffer's STATUS 0, and QEMU's reset of the device at a
reboot inside one QEMU run) put the rings and the display back, but told the
host nothing: the decoder kept every texture, heap, buffer, pipeline, library,
surface view (with its lease on guest RAM and its imports), device cache and
managed copy, and the region kept every block grant. A rebooted guest then met
its own leaked objects: the next boot's WindowServer had its buffer pins
refused by Metal's space ("refused the pin: Held { requested:
400000008000.., held: 400000008000 }"), and its command buffers faulted by
the thousand.
After a reset the device now looks new, as a real device does after a function
reset. Every queue ends and is fenced, no block is any process's, and the host
is told on the control thread (Host::device_reset), before the thread takes
anything published after the reset. The decoder drops every context's objects
as a close does, each in a refusal scope, lowest context first, and with them
the surface views, the device caches (uncopied: the pages are the rebooted
guest's), the library cache, the presents waiting, the pipelines compiling and
the shown surface. Nothing begun before the reset reaches the guest after it:
a poster carries the reset count its work began at, a queue made before the
reset hands the host nothing more (not even its destroy, which the reset
stands for), and a compile begun before it stores nothing.
What the guest observes after a reset: the ids it picks, the texture resource
ids and pinned GPU addresses it uses, and the samplers' ids it is handed are
free as on a new device; a library lookup misses; no answer or event of work
from before the reset arrives.
QEMU 67cc08ad takes reims-graphics-pci's command queue doorbells through
rvg_graphics_device_mmio_write again, so the queue's thread takes its
command buffers and the vCPU only wakes it. The library keeps
_mmio_write_taking, additive and now unused by QEMU.
The take on the vCPU did not pay on msi's x86-64 guest. 86% of the
compositor queue's doorbells found ring 0 behind and fell back to the
queue's thread, so the frame's command buffer was rarely taken inline.
WindowServer's composite (CLTD, its CompositeLayersToDestination call's
wall time) was a wash at the tip, mean 555 us with the take against 621
without and p50 442 against 435, and the take cost the vCPU about 15 us a
doorbell at the p50. Its tail was jemalloc's decay purge, madvise calls of
up to 340 us run on the vCPU inside the take's allocations.
A cold boot of the x86-64 guest on msi with this QEMU reached the desktop
and dragged a window with no fatal or ERROR line; CLTD measured mean 407 us,
p50 396, p99 613.
docs/qemu.md and docs/api.md say what QEMU calls again.
The header, api.md section 5, the Rust API's GraphicsCallbacks and the
device's Host doc said raise_interrupt runs with no lock of the library's
held. It does not: on a queue's service thread it runs under the queue's
claim on its next message, and some events are posted, and their vector
raised, under locks of the library's:
- the decoder's lock, at a command buffer's CB_SUBMITTED posted as the
buffer is taken, on its queue's thread or inside
rvg_graphics_device_mmio_write_taking, and, with the download's answer
slot, at a SURFACE_DOWNLOAD answered at once;
- a command buffer's CB_SUBMITTED latch, wherever that is posted, which
keeps it once and ahead of the buffer's other records;
- the presents' queue, at a present answered at once with no window.
Moving those raises out from under the locks would delay the CB_SUBMITTED
the guest's commitAndWaitUntilSubmitted waits for, or break its order.
What a host relies on still holds: no function of the graphics device
takes any of them, and rvg_graphics_device_mmio_write_taking only tries the
claim and the decoder's lock. So the docs now say that: the library calls
raise_interrupt with no lock held that a function it may call waits for,
directly or through a thread of the library's, so it may call them at once,
and it may still wait for a lock the host holds while it calls the device.
api.md section 5 and GraphicsCallbacks name the locks.
Two doc errors of the inline take's commits go with it: the Host doc still
said no callback runs inside a call of the host's, though
Device::mmio_write_taking calls take_command_buffer and may raise there,
and GraphicsCallbacks did not name the host's own thread inside
mmio_write_taking. A raise_interrupt doc line ran past 100 columns.
QEMU f2c7e2a5 sends the vCPU's BAR 0 writes of reims-graphics-pci to
rvg_graphics_device_mmio_write_taking. A DOORBELL write of a command queue's
ring can then take the queue's next command buffer on the vCPU, post its
CB_SUBMITTED and raise the interrupt there, through the irqfd under KVM or
the BH elsewhere. The control ring's doorbell still goes to the ioeventfd,
and reads are unchanged.
Measured on msi under KVM in one boot, the same guest under window-drag
load, with the take switched on and off every 20 s (the first 5 s of each
window left out; 60 s on, 51 s off):
- WindowServer's commit to its wake in commitAndWaitUntilSubmitted fell to
173 us on average, from 218 (p50 168, from 185; p99 440, against 402);
- its CA::Layer::commit_transaction-to-display (CLTD) fell to 384 us on
average, from 434 (p50 376, from 400; p99 667, against 654). Every 20 s
window with the take on beat both windows next to it;
- the vCPU took 32% of all doorbell writes, and 62% of the buffers that ask
for their CB_SUBMITTED. The rest went to the queue's thread: 2731 because
a ring-0 message published before them was not carried out yet, 23
because a lock was held. The 6608 buffers that ask for no CB_SUBMITTED
were left too;
- a take cost the vCPU 14 us at the p50 and 31 us at the p99, 274 us at
most, and a plain doorbell write 2 us. A vCPU-posted CB_SUBMITTED reached
the ring 10.7 us after the doorbell, against 199 us for one the queue's
thread posted;
- the control thread waited for the decoder at 20.6% of its locks, from
15.3%, for 38.2 ms a second in all, from 36.8. 2204 of those waits were
behind a take's carried lock. The queue's thread never waited for it.
A boot of the plain build (no measurement) reached the desktop and dragged
at 59.6 composites a second, with CLTD averaging 369 us and no fatal,
ERROR or WARN line in the host log.
docs/qemu.md and docs/api.md now say which BAR 0 call QEMU makes, and how
the interrupt is sent since 36deb281.
rvg_graphics_device_mmio_write_taking is rvg_graphics_device_mmio_write,
except that a DOORBELL write of a command queue's ring first offers the
queue's next COMMAND_BUFFER to the host on the writing thread. Under QEMU
that thread is the guest's vCPU. Where the buffer asks for its CB_SUBMITTED
and nothing need be waited for, the vCPU takes it: it makes the buffer's
command buffer, posts its CB_SUBMITTED onto the queue's completion ring and
raises the queue's vector. It then hands the rest to the queue's service
thread, which walks and commits the buffer before it takes anything more of
the queue's. The guest's commitAndWaitUntilSubmitted no longer waits for
that thread to wake, which costs about 85 us on msi's host, the exit of an
idle CPU from its deep C-state.
Nothing on the vCPU waits. Every lock the take needs is tried: the queue's
claim, which its service thread holds from its take of a message to the
hand-over; the queue's submission ring; the control submission ring; the
compile table; and the decoder. Where any is held, the buffer stays on the
ring and the write wakes the queue's thread, as rvg_graphics_device_mmio_write
does. It also stays there where:
- a ring-0 message published before it is not carried out yet;
- it waits for an event, or a buffer before it holds its queue;
- a pipeline it names is compiling;
- a device cache it uses wants a fill, or a wait for one;
- its queue holds 48 command buffers made and not completed (the
platform's commandBuffer waits at 64);
- it does not ask for its CB_SUBMITTED.
The CB_SUBMITTED's post on the vCPU waits for nothing either. Where the
completion ring is busy or full, the service thread posts it before the
walk, where the post is today.
The decoder's lock is taken on the vCPU and let go on the service thread
after the commit. So every message the guest sends after it sees the
CB_SUBMITTED is carried out after the buffer's commit, as it is today.
Class: FREE. Only the thread that posts a buffer's CB_SUBMITTED and its
timing change. Each queue's events keep its order: the vCPU takes only
while the service thread holds none of the queue's messages, and the
service thread carries out what the vCPU took before it takes the next.
The interrupt still follows its ring write on the same thread.
The C API gains the function, additively: the header and api.md list it,
and section 5 names the calling thread for raise_interrupt inside it, which
must not wait for a lock the host holds while it calls the function.
rvg_graphics_device_mmio_write and its "Calls back: never" are unchanged,
and so are the pins (re-recorded, no difference). The decoder's lock
crosses threads through parking_lot's arc_lock and send_guard.