metal2vulkan's replay player plays the host video recordings, whose surface
caches the hardware writes outside the runtime: VA-API's decode or video
processing into a dma-buf cache, NVDEC's copy through CUDA's import of an
exportable one. It must refill what lies over such a cache where those writes
become visible to the device: the platform's external_write_done, the
runtime's acquire. The platform made that call unrecorded, so no stream held
the point, and a player had to infer it.
external_write_done now records m2v.externalWriteDone on the buffer, with no
arguments, as the call returns, as rebindNoCopy and every other hooked call
are recorded. The host's video makes the call on the session's landing thread
once the picture is in the cache, right before the session's
setSignaledValue: that releases the decode's command buffer past its wait, so
the record lies after the hardware's writes and before every command that
reads them. A refused acquire is recorded as any refusal is. The record is
counted by its selector in the stats file, and the recorder_fix
"external-write-done" names the change.
Nothing changes for the guest or the C API's host. With REIMS_VGPU_RECORD
unset the call costs one relaxed load more.
On metal2vulkan-rt a no-copy buffer's GPU address is the device address of the
host's import of its pages, which only the host knows, so a guest pick cannot
match it. Where the kext and the device both took IMPORT_ADDRESSES, the bundle
asks PagesBlock for its third output, the GPU address the host gave the block's
view, and makes each BUFFER_OVER_PAGES over the block there plus the pointer's
offset in its page, with no pick of its own and none given back at its destroy.
What the guest sees changes: a no-copy Shared buffer over writable memory the
kext wires answers a gpuAddress in [2^43, 2^44) on the Vulkan platform (at its
pages' import on rt) instead of a pick in the context's range, and two no-copy
buffers over the same bytes, which join one block, answer the same gpuAddress.
A Managed no-copy buffer's own address stays its GPU copy's pick; only its CPU
copy, the Shared buffer over the pages, moves. Read-only memory, copied memory
and blocks given no address keep their picks, and a guest without the bit sees
nothing change.
design.md gains the "Import addresses" paragraph, PagesBlock's third output and
the kext's bit 18.
This change is visible to the guest. Where the kext and the device both took
PRIVATE_BLOCKS, these objects now get their gpuAddress inside blocks the
host gives the context, rather than in the context's own range in
[2^46, 2^47):
- Private buffers;
- heaps that are not Shared, and the buffers in them;
- Managed buffers, whose GPU copies are what the address names.
On the Vulkan platform those addresses lie in [2^44, 2^45). On
metal2vulkan-rt's device they are the Vulkan device addresses of the host's
memory, which is the reason for the move. Shared buffers, the pool's heaps
and no-copy buffers keep their addresses.
How the bundle picks inside its blocks:
- Picks are next fit through the blocks, on the same span and granule
rules as the context's range.
- A block is taken from the kext when none has room: 256 MiB, or the pick's
span and alignment rounded up to 64 KiB where that is more. 256 MiB is
rt's pooled block, and it keeps a freed span from being picked again soon
after its destroy.
- Free ranges never join across blocks, so no pick spans two of them.
- One empty block is kept for the next picks. Any further empty block is
given back after the last object's destroy has been posted.
- Where the host refuses a take, the bundle picks in the context's range as
before and logs the first refusal.
The serializer tests cover picks in blocks, a block of its own for a large
pick, giving back and keeping, blocks side by side, refusal and threads.
docs/graphics-kext/design.md gains "Private blocks" and the two selectors.
Where the device and the kext both took POOL_ADDRESSES, the bundle asks
PoolTake for its fourth output and makes the block's HEAP_OVER_POOL at that
address, picking none of the context's: on metal2vulkan-rt's device the
address is the block's Vulkan device address, which the guest cannot pick.
The heap's destroy gives no address of the process's back (ownsAddress), so
a host address that meets one of the process's picks never frees the pick.
The pool takes' log line counts the heaps placed at the host's addresses.
What moves for the guest: every Shared pool slab's heap, and so each
buffer placed in it (gpuAddress, contents' GPU address), moves from the
context's range [2^46, 2^47) to the host's address: [2^45, 2^46) on the
Vulkan platform, the block's device address on rt. A buffer's address is
still its heap's plus its offset; Managed buffers' own addresses, Private
buffers and the region's slabs are the process's picks as before.
test_pool_slab_source_at_host_addresses holds the new placement; the
existing pool slab test holds the old one for a kext without the bit.
On the arm64 device, a command buffer named in SURFACE_USE only the cached
IOSurfaces it encoded a use of. A surface the GPU reached only through a
residency set the buffer used, or its queue held, was never named: its device
cache kept the generation of its last named use, and a copy-mode surface's
copy was not synced, so the GPU read what it held before the CPU's writes.
What the guest observes changes: at its commit, a buffer names each texture
over an IOSurface, or view of one, committed to a residency set it uses or its
queue holds, as a resource it reads. A cached surface's cache is filled first
where the CPU wrote it since, and a copy syncs. The set keeps its committed
IOSurface members as its own commit changes them, so a buffer's commit reads
them without walking the set. The x86 device makes no residency sets, and is
unchanged.
A cached IOSurface's device cache was filled at the read-write lock that
moves the surface's generation, not at its unlock. A command buffer committed
while a CPU held the lock filled the cache with the pages mid-write, and the
CPU's writes after it reached the GPU only at the surface's next lock.
What the guest observes changes: the first command buffer committed after the
unlock that uses the surface now reads the CPU's writes made under the lock.
The bundle tracks a cached surface's unlock seed from a commit that found it
locked for writing, as copy mode does, and that buffer's SURFACE_USE carries
the new RGFX_SURFACE_USE_REFILL flag. The host fills the cache again at the
generation it holds, unless a command buffer that may write it was committed
since its last copy into the pages, whose write a fill would lose.
The flag is under the new feature bit RGFX_FEATURE_SURFACE_REFILL (bit 58),
which every host offers and both kexts take; the bundle sets it only where
its kext took the bit and answers the surface seeds. The bundle counts the
surfaces named mid-write and the refills, and the host its refills and the
refills it kept from, in their summaries.
A boot found it: the kext's event handler routed answers from a list of its
own, POOL_BLOCK was not in it, and POOL_TAKE's waiter, asleep uninterruptibly
with no deadline, hung WindowServer for good with no fatal line on the host.
Say how to spot the next one.
design.md gains "The Shared pool", which the wire, the host and the kext
cite: the range and who gets it, a take and its wait with no deadline, the
heap over a block, a give and a close, what moves to the pool and what stays
in the region, and why no empty slab of the pool is kept. The slab section
says the pool comes first where the device has one.
The x86-64 kext takes the device's POOL where offered, and sets its own Pool
bit (1 << 15) where it did. A process takes a block through selector 16
(PoolTake): the kext posts its context's POOL_TAKE, maps the block the host
answers with into the process write-back, and lists it. It gives the block
back through selector 17 (PoolGive): the kext unmaps it, then posts the
POOL_GIVE. At the client's close the kext unmaps every block it lists before
the CONTEXT_CLOSE, which gives them all back. HEAP_OVER_POOL joins the
context ring's commands a process submits itself.
The take waits for the host's answer with no deadline, THREAD_UNINT like
the kext's other asks of the host: the host answers each take of an open
context, and the close waits for its takes in flight, so the kext never
gives up on a take whose answer then comes late. Where the host stops
answering, each taking thread waits, holding one of the 32 lifecycle
waiters, until it does.
The arm64e kext takes no POOL and sets no Pool bit: selectors 16 and 17
answer kIOReturnUnsupported there, and its processes keep the region's
blocks and the kext's chunked pages. Selectors 16 and 17 are numbers the
sandbox lets a web content process call.
The times recorded came from a job at potluck's memory priority 4, which
Windows trims and a user's QEMU does not run at (docs/lessons.md). A run at
5 populated 256, 548 and 1024 MiB in 40, 71 and 119 ms, where the run at 4
took 37, 86 and 151 ms.
The walks on the 3090 and the 780M measured what the populate costs and
saves: a removal's BQL hold back under 0.8 ms with its slot delete on the
library's thread, adds as before at the median with a 3-of-72 tail of single
slot creates, and no workload slower beyond the walks' spread.
The populate maps a whole pool piece, so KVM's delete of a removed piece's
slot zaps all of it: 3.0-8.3 ms for a 256 MiB piece on the 780M and 3090
hosts, under the BQL, where a removal held it 0.8-1.4 ms p50 before the
populate. QEMU's 7ad9c809 deletes the slots on the library's thread before
the removal is queued (kvm_unmap_before_del), as WHPX unmaps a removed
piece there, so the removal's transaction finds no slot.
QEMU's reims-graphics-pci now fills the second-level tables of each pool
piece once its add is answered, on a thread of its own in 2 MiB slices, so
the guest's first touch of a piece takes no fault where it took one a 4 KiB
page: 140,289 for 548 MiB, 184 ms on um870's 3090 and 262 ms on um790's
780M under KVM, and 1.3 s on the Windows mini under WHPX. Under KVM the
call is KVM_PRE_FAULT_MEMORY on a vCPU of the thread's that never runs,
which keeps KVM's master clock on across guest reboots and is never waited
for under the BQL; under WHPX it is WHvAdviseGpaRange's populate.
vendor/qemu moves to b561d79c (dd0e0d4a..b561d79c on 0590cfde), and
docs/qemu.md says what the populate does.
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).
The pass that zeroes the scanout's room for a new owner runs only when a new
WindowServer process opens the server connection, never at boot or on the
same WindowServer's reopen. It zeroes the display's whole share, so the host
backs all of it from the first replacement on. The paragraph now says so, with
the measured stores on KVM (103 ms) and WHP (802 ms).
Measured on the UHD 630 Windows host, a guest page under WHPX costs about
20 us the first time the guest touches it, guest RAM and the device's
region alike, and a page the host already backs about 1.5 us. qemu.md now
holds those costs, the region's use at the desktop, and the largest
first-touch burst between two presents, so later sizing reads them there.
The same runs found that potluck's Windows jobs start at memory priority 4,
and that Windows trims a priority-4 QEMU's working set with tens of GB free:
703,604 RAM and 9,637 region pages in one walk, each costing 19 to 32 us to
fault back, and none at priority 5, which a user's shell gives. lessons.md
records the trap and how to spot it, since a timing taken in such a job pays
faults a user's VM does not.
The kext zeroed each span of a new block through a kernel mapping it made for
that span and took down after it. Over a boot to the desktop and a probe's 905
new bodies (rzboot2, a macOS 26.7.2 guest on a 780M host), making and taking
down those mappings took 402.5 ms of the zeroing's 433.3 ms, and they were its
longest waits at boot: 114 ms for one staging chunk, 19 ms for one surface
header.
The kext now maps the blocks' range into the kernel once for each cache mode at
its start, write-back from the region and write-combined from the region's
write-combined descriptor. It keeps both mappings for the kernel's life, as it
keeps the doorbells' mapping, and writes a new block's zeros through them, so a
block's zeros cost only their stores. The kept mappings hold the kernel's
address space and page tables only, and none of the host's memory: no page of
the region is touched until it is zeroed or used. On a Windows host (WHP) the
kext's zeros are the first touch of a region page that was never touched
before. Where the kernel will not make a kept mapping, each span is mapped
alone, as before. The kext logs each kept mapping's size and how long it took
to make, once at its start.
The scanout's room holds the display's pixels, and the region keeps them past
the process that wrote them. A task that opened the framebuffer's server
connection after another (the next WindowServer, after a crash or a logout)
was handed the room through the VRAM range, a surface lock or the scanout
grant with the last owner's last frame still in it.
The framebuffer now zeroes the display's room when a task that is not its
last owner opens the server connection, through a write-back mapping, the mode
the windows and the locks map the scanout in. The task owns nothing until the
zeros are in, and every other task's hold of the scanout is taken back first.
A room the kernel will not map for the zeros fails the open. The last owner
opening again keeps its bytes, and the first owner finds the boot screen,
which no process wrote and which the first present clears, as before.
What the guest sees: the screen shows black, not the old owner's last frame,
from the new owner's open until its first present. The pass is one zeroing of
the display's room, up to 128 MiB, per new owner, logged with its mapping and
store time.
scanout_owner_test checks that a new owner's first read of the room is zero
and that it owns nothing before, and that the last owner's open again keeps
its bytes.
A region block's offset goes to any process once the device answers its
release or its holder's close, and the region keeps its bytes across the
device's reset and the guest's reboot. A new block held whatever its last
holder left: another app's command buffers' bodies, its shader library's
staging chunks, its buffers, or a surface copy of its window's pixels.
The kext now writes zeros over every span a window maps of a new block
before the window maps it, each through a kernel mapping of the cache mode
the window maps it with (write-combined from the region's write-combined
descriptor, write-back from its own), and allocBlock maps from the same
spans, so what is zeroed is what is mapped (RgfxBlockZero.hpp). A surface's
new block is zeroed over the part its holders map: the whole copy for a copy
block, the header for one in place. A span the kernel will not map fails the
grant. A block held again (a shared or revived surface block) and a pages
block, never in a window, are left.
The kext logs what the zeroing took by kind (bodies, split, write-back,
surface copies, surface headers), and offers it as feature bit 1 << 14
ZeroedBlocks, after which the bundle takes the region's slabs as clean
rather than zero them again. block_zero_test checks the spans and the
cross-process cases natively; guest/bundle/tools/block_zero_probe.c checks
them in a guest, a block filled by one process and read by the next.
On Linux and Windows, a no-copy buffer over pages the process maps read-only
lies over a copy of those pages. Once such a buffer's identity has escaped,
the GPU may read the copy through memory after the guest's CPU has changed
the pages, with no binding naming the buffer. This commit records how often
that situation arises, and pins the runtime behaviour that keeps it correct.
The behaviour is unchanged: the decoder adds nothing to any command buffer.
Metal requires an encoder to make resident (useResource:usage:) any buffer a
function reaches through memory, and that names the buffer as a use. At the
commit, the runtime copies in every copy that a command buffer's uses name,
and every copy where its work may reach memory that no use names
(metal2vulkan's command_buffer/mod.rs:4747-4772 at the pinned commit, which
picks the copies at 4754-4766). A reach of a buffer that no encoder made
resident is undefined in Metal, and on the runtime it reads zero
(residency.rs).
What the decoder adds is bookkeeping:
- each process's count of its live escaped copies (Context::escaped_copies),
which a copy joins at its first note and leaves when it is dropped;
- escaped-copy-commits, which counts each command buffer begun by a process
that holds one, in the degradation counts line and the recorder's stats.
The first such command buffer is logged at info.
on_vulkan_an_escaped_copy_reached_by_its_address_reads_the_cpus_writes pins
today's runtime. A kernel reaches the escaped copy only through an address it
loads, with the encoder having made the copy resident. It reads the pages' old
bytes, then their new ones after the CPU's write.
The host reads a no-copy buffer's bytes in place. The guest's Metal can hand
that buffer's identity to the app, or write it where the GPU reads, with no
message naming the buffer, and from then on the GPU may reach the buffer
through memory alone. The host had no way to know which buffers that happened
to. This commit adds a note for it, so the host can tell them apart.
The note is RGFX_CMD_BUFFER_ESCAPED (0x23b), RgfxBufferEscaped of 32 bytes:
the buffer's object id and the act, one of GPU_ADDRESS, ARGUMENT_ENCODER,
RESOURCE_ID and RESIDENCY_SET. The device offers it as
RGFX_FEATURE_BUFFER_ESCAPED (bit 56), and both kexts carry it. The submit gate
takes it in a batch, like a Managed range's write: unwaited, a fixed size,
naming no block and making no object.
The bundle marks each covered buffer as it is made (_rgfxEscape, set by
rgfxOwesEscapeNote) where the host took the feature. The first of these acts
in the buffer's life posts the note, before the act returns:
- a read of the buffer's gpuAddress;
- an argument encoder's setBuffer(s) of it, or setTexture(s) of a texture or
view over it;
- a read of such a texture's or view's gpuResourceID;
- the buffer, or such a texture, joining a residency set.
Every later act is one relaxed load.
Wire order holds the note ahead of any command buffer that could use the
identity. The note goes on ring 0, posted or held in the serialiser to go
before the next commit's messages, and the device carries out a command buffer
only after every ring-0 message its process posted before it. Across threads,
the act's slow path posts the note under the buffer's lock and then clears the
mark with a release store. Every commit takes an acquire fence before it posts,
so a commit after an act that found the mark clear posts after the note.
The covered buffers are the app's no-copy buffers over its own pages
(BUFFER_OVER_PAGES, writable or read-only, bit 24) and over bytes already in
a block of the process (BUFFER_OVER_HOST_MEMORY). Managed buffers, heaps over
pages, IOSurface shadows and buffers placed in a slab's heap
(BUFFER_AT_OFFSET) are not covered.
A slab buffer made with an address of its own is covered too: a Shared buffer
past 2 MiB over a slab of the process's own pages, a device buffer, or a
no-copy buffer's shadow (RgfxSlabSource::Made's ownsAddress). It reaches the
host as the same BUFFER_OVER_PAGES or BUFFER_OVER_HOST_MEMORY message as an
app's no-copy buffer, and the host takes every such message alike. Leaving
slab buffers out would leave the host unable to read the mark as "this
buffer's identity never left".
The host marks the buffer's entry escaped, once for its life, and a later
note changes nothing. A note for an object that is not such a buffer is a bad
reference. A note for an object whose create the host refused is dropped, as
any naming of one is. Escapes are counted in the degradation counts line and
in the recorder's stats (`counted <code> <n>` lines), with no new stream
records:
- buffer-escaped-gpu-address, -argument-encoder, -resource-id and
-residency-set, by the act that noted the escape;
- buffer-escaped-read-only-pages, the escaped buffers over a copy of their
pages;
- no-copy-buffers, every no-copy buffer made, of which the escapes are a
share.
Each act's first escape is also logged at info.
This changes nothing the guest observes. No one waits for the note, it has no
reply, and the mark changes no answer, object, address or command. Both
prebuilt sets and the option ROM's record are rebuilt from these sources. The
ROM's bytes do not change: its record changes only by the wire header's hash.
A cold boot of macOS 26.6.2 under TCG on a Linux host's Radeon 780M passed
check-boot with no fatal line, with the device's pool grown over QMP at the
desktop: under TCG vmapple answers the same 1012 GiB room to 2^40, the max
CPU's 52-bit PARange stopping at 40. The measured block also names the
rebased commits its measurements ran as, since 66e66267 and 818dd28e6 are
no longer on the branch.
Measured on the M3 Max on 11-18: HVF's default and largest IPA sizes, the
room vmapple answered paused and the range the library took of it, a macOS
27.0.1 boot that passed check-boot with the pool grown mid-boot, and the
stage-2 cost of a 40-bit IPA against 36 bits, none measurable. The M2's
largest size is read from a public thread; the M1's and M4's are not known.
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.
vendor/qemu's vmapple had no get_physical_address_range, so HVF made the
VM with its default IPA size, 36 bits, and the guest's
ID_AA64MMFR0_EL1.PARange read 36 (HVF clamps it to the VM's size). The
machine now asks for 40 bits, the most macOS's kernel maps (its TCR_EL1.IPS
is 40 bits, read from xnu's source), or for the host's most where that is
fewer, so an arm64 guest on the M3 Max reads PARange 40 and the device has
room past RAM for the Shared pool, which the next commit gives it. KVM and
TCG are unchanged.
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.
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.
A guest's render pipeline drew its patches with Metal's default tessellation
state, whatever its descriptor set: power-of-two partitions, a maximum factor
of 16, no factor scale, constant factors per patch and clockwise output. The
bundle never sent the seven tessellation fields, so the device never saw them.
For the same reason the device never saw maxVertexCallStackDepth or
maxFragmentCallStackDepth, and created every pipeline with a depth of 1.
The bundle now reads each of these properties and sends it. Each tessellation
field travels as Metal's raw value, and tessellationFactorScaleEnabled as a new
flag, RGFX_RENDER_PIPELINE_TESSELLATION_FACTOR_SCALE (bit 8). The depths are
read only where the descriptor answers their selectors (macOS 12 and later);
older guests send 1.
The decoder passes every value through FullRenderPipelineDesc to the runtime's
RenderPipelineDescriptor. A state equal to Metal's defaults becomes the
runtime's `None`, so a pipeline that sets nothing is created exactly as
before. A raw value the runtime has no enumerator for dies at the send, as
every other enumerated field does. The recorder's tag-13 map carries the
values as three keys after privateState: `tessellation`,
`maxVertexCallStackDepth` and `maxFragmentCallStackDepth`.
Guests now see patches tessellated with the partition mode, maximum factor,
factor scale, step function, winding and control point index type that their
pipeline sets. They also see pipelines created with the call stack depths
they asked for.
The tessellation fields and the call stack depths share this commit because
they share one wire record. RgfxRenderPipelineCreate grows from 464 to 496
bytes, with eight u32s appended at offset 464, and both prebuilt sets and the
option ROM's record are rebuilt from these sources. The ROM's bytes do not
change.
The boot that checked the sum of the heaps as the pool's range logged the
range, the room QEMU gave and the heaps' total; the room, 725 GiB on
reims-ctl's machine, is far above any lab GPU's sum, so none is clamped.
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.
With N of the guest's 16 MiB pool pieces in, one add cost QEMU 21 ms of BQL
under KVM at N = 2,000 (13.5 ms under HVF, 43 ms under WHPX), most of it
work that walked every RAM block or flat range: a probe device doing the
add's calls, paused, measured each part. vendor/qemu moves to six cuts, each
its own commit with its measurement:
- set a piece unmergeable inside its add's transaction, so an add commits
once, not twice;
- place a RAM block in one pass over the blocks sorted by offset, not by
comparing each block with every other;
- carry out a run of queued asks of one kind in one transaction, answering
each add once its run has committed;
- render a flat view with a gap at the last insert and a binary search,
not by moving every later range, with the same views (20,162 compared);
- put a RAM block in the list by its run of one size, with the list's order
unchanged (4,398 compared);
- find a pool piece by binary search over the pieces sorted by address.
After them one ask at N = 2,000 costs 745 / 779 us (add / removal) under
KVM, 584 / 565 us under HVF and 376 / 370 us under WHPX, and a run of 8
119 / 121, 81 / 70 and 63 / 47 us an ask. What the guest observes does not
change: its pieces, their addresses and the order of the device's answers
are as before. Between free gaps of one size a new RAM block now takes the
lowest offset, an offset of this process's own that no guest sees.
docs/qemu.md gives the before and after per host, with the job ids; what
one ask costs at the 131 pieces a recorded session reached, set beside what
the runtime's own 16 MiB block costs on each host; the rule that a piece
the runtime holds for reuse keeps its region, with what a removal and
re-add would cost; and HVF's costs with many blocks resident and the counts
it maps without a refusal.
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.
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.
README.md, docs/qemu.md's "arm64 guests" and reims-restore's design say that
reims-ctl restores an arm64 VM from an IPSW and starts it on vmapple with
Ambrosia: under HVF on an arm64 Mac, KVM on arm64 Linux and TCG on x86-64
Linux, and that install-ctl.sh builds the qemu-system-aarch64 it runs there.
metal2vulkan's runtime cutover maps the host-visible blocks it gives the
device into the guest one block at a time, as WHPX does today. The M3's
measurement of that form under HVF (11-18, Hypervisor.framework alone) found
the map cheap at any size, the unmap about 70 ns a touched page, no vCPU
stall and no refault of other mappings, and a first touch of about 1.2 us a
16 KiB page. docs/qemu.md holds the VM measurements.
At the runtime's cutover every host makes a no-copy buffer over pages the
guest maps read-only over a copy of them, the Mac included, where today it
imports them in place. To know what that copy costs a guest, the decoder now
counts each such buffer it makes, once a boot, in the degradation counts'
line: `read-only-pages-buffers` (how many were made) and `read-only-pages-kib`
(their bytes' sum in KiB, rounded up).
A BUFFER_OVER_PAGES over a block the kext marks RGFX_SURFACE_PAGES_READ_ONLY
is the only such object: the bundle sends read-only Shared memory there with
bit 24, and a heap, an indirect command buffer's slots or a Managed object's
CPU copy over the block is refused. The count is taken there, in the decoder
every host shares, so it means the same on Linux, Windows and macOS.
The counts' line is where they go: docs/conventions.md lists every kind
counted since the process began there, not degradations alone (the rings'
`vblank-dropped` and `*-post-waited` among them), and says no count goes
elsewhere. On macOS the buffers are no degradation; on Linux and Windows the
runtime also counts their copies, with failed imports, under its own code.
answer.rs gains count_kind_by, which adds an amount to a kind's count.
Diagnostics only: no ring message, value or answer the guest sees changes.
The swapchain, the window's presenter, the display's sink and the window
system's extensions present on Windows too, through SDL's Win32 surface
(os/windows.rs's WINDOW_SURFACE_EXTENSIONS), but their docs said "either OS"
or named Linux and macOS alone. rust-toolchain.toml still named the Metal
platform, deleted on 11-07. caps.rs's table gave a host's naming of its
device by Metal's registry ID (open_device, a handshake) as the reason for
the stand-in; no host names its device so now, and the reason that holds is
that Metal's core count and driver sizes for that GPU are found by that ID.
Comments and docs only.
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.
metal2vulkan's new runtime counts its GPU times on CLOCK_MONOTONIC on Linux
(its ruling of 2026-11-18: lavapipe calibrates no CLOCK_MONOTONIC_RAW domain),
while the device's clock, which the guest's kext maps the device's times by, is
CLOCK_MONOTONIC_RAW. At the cutover every GPU time the platform answers has to
be moved onto the device's clock before the guest sees it.
reims-vgpu-graphics's clock::runtime does that by a paired read (the
platform's clock, the device's, the platform's again; the least bracket of
three), fresh at each conversion, and names the platform's clock in one
constant, PLATFORM. Its one call is the CB_COMPLETE record's GPU start and end
in the decoder: the only platform GPU time that reaches the guest. One pair
moves both, so the run's length, which is what the guest reads, stays exact.
The runtime the library runs today counts the device's clock on Linux and
Windows, so PLATFORM is Domain::Device and the times pass unchanged: no value
the guest sees changes. The cutover sets it to Domain::Monotonic on Linux;
should the new runtime count CLOCK_MONOTONIC_RAW there, the module goes.
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.
oracle_storage mtexcap on the AMD Radeon Pro 5300M: a replaceRegion: made after
the commit is seen, whole or partial, until the command buffer is submitted (a
wait on an unsignalled shared event holds it unscheduled until the signal), and
not once the GPU has started it: the bytes are taken at the submission, as a
Managed buffer's. The Intel UHD Graphics 630, one copy, sees every replace.
metal2vulkan's planner is ruling on when the new runtime takes a Managed
buffer's CPU bytes on a discrete GPU. capture's new steps, run at 4 KiB
and 64 MiB on the 5300M and the Intel 630, answer it: the 5300M takes the
bytes at the submission, after the commit returns (a write at once after
the commit is seen whole, one 20 ms after scheduling is not), and a second
didModifyRange: does not reach a command buffer already running. The
Intel 630, one copy, sees every write.
Q2 gets the three steps' rows, the 64 MiB answers of all eight, the job
ids, the 64 MiB run's memory, and the window's timings. The sentence that
said no step writes between the commit and the submission now says step 5
does, and that the 5300M's spin once saw the CPU's flag write.
The oracle table's row for our device now reads 2147483648 (c795bf3d5), and
its relaxation names the cap and why. A lessons entry records the trap: a
size the device answered (12821200896 on the RTX 5080) passed what the
platform's shaders address, and only an access past 4 GiB in a buffer shows
it.
reims-graphics-pci.c is built once into every QEMU target, so the pool's
KVM quirk call broke qemu-system-aarch64's link on x86-64 Linux hosts,
and only an aarch64 build saw it. Say how to spot the next one.
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.
A loop of command predication that ran past the iterations laid down for
it set a flag in its command buffer's state buffer, and a completed handler
of the platform's own read the flag and ended the process. That handler ran
on the runtime's thread outside every refusal scope, so a guest whose loop
ran on, or anything that wrote the flag, ended QEMU. The state buffer is host
data the GPU writes, and after the runtime's cutover every byte on the device
is guest-writable.
The flags are now read where the runtime's own failures are read, once the
command buffer completed with none: by each completed and completion-seen
handler's read, and by status, error and waitUntilCompleted. An overrun is a
failure that is none of Metal's, dying where it is read, as the others do.
What the guest sees: inside the graphics lane's refusal scope, which every
guest command buffer's handlers carry, the read is refused and the command
buffer completes with status Error and an internal error (RGFX_CB_INTERNAL),
after its event signals and in its queue's order, and QEMU goes on. Each
such command buffer is counted once as the degradation
predication-loop-overrun. Outside every scope (the library's own tests) it
still ends the process, now at the first read of the completion.
The death test now dies at the wait, and two tests pin the refused
completion and a loop that ends within its copies.