A command buffer's delivery releases what the buffer kept before it lets
its waiters go, as Metal does, and the destroys those releases hold armed
their 1 ms timer there: a dispatch_after, whose kevent wakes the dispatch
manager's thread. In a guest ktrace of Geekbench's Metal Super Resolution
on the 780M host that arm took the release 16.9 us p50 (30.2 p90) of each
delivery on the completion queue, between the app's handler and the wait's
return. The delivery now holds the arm (RgfxRingLaterArms) until its
waiters are let go: the destroys go as before, the timer from the end of
the delivery.
The host sees a command buffer only once a queue's thread takes it off its
ring, so the app's encode and the buffer's way to the host show as one span
with nothing pending on the host. This adds the guest's stamps that split it,
a diagnostic.
What changes for the guest:
- The device offers a new feature bit, RGFX_FEATURE_GUEST_TIMES (bit 44,
FEATURES_HI bit 12), and DRIVER_FEATURES takes it. The kext carries it.
- Where the device's word holds it, the bundle starts each command buffer's
stream with a new op, RGFX_OP_GUEST_TIMES (0x000e, 32 bytes): the guest's
clock as the buffer was made, as its commit was entered, and as its message
went on its ring. The last is written under the ring's lock, after the copy
and before producer is published; for a buffer in a block, into the block.
- After each VBLANK's reading of HOST_TIME the kext writes ring 0's new header
fields: guest_clock_offset_ns (0x18), then guest_clock_bound_ns (0x20) with
release, split out of reserved bytes. The host zeroes both as it initialises
a ring.
- The decoder walks the op as a no-op, so it changes nothing a buffer does,
and a host that did not offer the bit never sees it. Old guest sets carry
no bit, send no op and leave the fields 0.
The header is regenerated, both guest sets are rebuilt from the same sources,
and the option ROM's record takes the header's new hash; the ROM's bytes are
unchanged. The tests cover the op's and fields' layout (the header test, the
kext's vblank clock test), the bit's negotiation (the kext's features test,
the peer and memory-map tests), the stamps (the bundle's serializer and shell
tests) and the walk (a cmdbuf test, and the fuzz's streams). The host's
reading of the stamps is the next commit.
The host can take a queue's doorbell with no exit to its process only
where the write needs nothing of it but a wake, and a write of the ring's
id alone could be a buffer that asks for its CB_SUBMITTED, which the host
answers inside the write. Where the device offers DOORBELL_ASKS, the kext
takes it and the bundle writes an asking buffer's doorbell with the
ring's id and RGFX_DOORBELL_ASKS (bit 0), every other doorbell with the id
alone. On a host that does not offer it the bundle writes the id alone, as
before.
The kext writes what the bundle hands its doorbell call, so it needs
nothing more than the bit in its carried features. Tested by the kext's
features test and the bundle's
test_ring_doorbell_asks_where_the_device_takes_them.
Batch 42's guest test (job m3-max-25789) failed under the M3's load at
serializer_tests.cpp's CHECK(ending.calls.empty()): with setBatch's timer at
1 ms, a test thread held off a CPU for 1 ms after postLater let the timer
post before the writer's end. It is the class of the room-record test's
failure: a check that holds only while a thread runs within a time window.
The other guest test sites of it, found by reading every sleep, clock read
and timer delay in the bundle's and the kext's tests:
- serializer_tests, test_held_destroys, the writer's end: a run counts only
where the look at the calls comes within the timer's 1 ms from before the
post; runs repeat, up to 50, until one does. The calls are read under the
log's lock, as the timer's thread writes them.
- serializer_tests, test_ring_post_waits_for_room: the post's time, checked
to be at least 15 ms, was counted from after the host's thread started its
20 ms; it is now counted from before, so a late start of this thread no
longer shortens it.
- queue_tests, test_submitted_waits_for_the_buffers_before: the same for the
40 ms the wait must last, against the thread that commits after 50 ms.
- shell_tests, test_submitted_at_the_doorbell_wakes_no_thread: the
completion thread's late wake came 400 ms after the doorbell, and the test
checked the call took under 200 ms and the record was still untaken. The
wake now waits for the test to let it go (or 5 s), so the test checks the
call returned before the wake and the record untaken, with no window.
Each keeps what it checks. The rest hold under any delay: lower bounds
counted from before what they wait for, negative checks of work nothing
lets run, and bounded waits of seconds.
test_ring_post_waits_for_the_room_record checked that a post still waited
3 ms after the host took room with no record, and that the record ended
the wait within 15 ms. The wait's backstop ends it 20 ms after it began
(RgfxRingWriter.cpp's kRoomBackstopUs), and under the load of batch 41's
check (job m3-max-25671) the test's threads were held off a CPU long enough
for the backstop to come first: CHECK(!posted) failed, where the test
passed alone (25724). The post's own look after it stores the flag could
also find the host's take when its thread was held between the two, as the
test took room once it saw the flag.
The test now takes room only after the post rang the doorbell, which it
does once that look found no room, so from then on only the record or the
backstop ends the wait. A run counts only where it ends inside the backstop
from before its post began: the record alone can then have ended its post,
which was still waiting when looked at 3 ms after the take. Runs repeat, up
to 50, until one counts. A post the record does not wake never counts, and
one that does not wait fails the run that counts.
A texture's create (TEXTURE_CREATE), a view's (TEXTURE_VIEW), a Managed
texture's and buffer's (MANAGED_TEXTURE_CREATE, MANAGED_BUFFER_CREATE) and a
Managed buffer's modified range (BUFFER_DID_MODIFY_RANGE) are messages no one
waits for, each its own Submit call: on the RX 7900 XTX host 8 to 13 us each,
812 of them and 8.8 ms a Vision process. SubmitBatch now takes them too, each
of its one size, checked as Submit checks it, a create for a context closed
since its check destroyed behind it (rgfxSubmitBatchSize). None names a block,
which spans_test keeps. The bundle holds them with the destroys and the
heap-placed buffers (RgfxSerializer::postUnwaited), in their order, posted
before anything else the process posts or asks of the kext and before any
command buffer it commits. A texture over an IOSurface still goes at once, as
a present of the surface waits for it, and so do the creates that name a block.
This changes what the guest sees under transport exhaustion only (the control
ring full for 5 s, or the device stopped), as 628b03fb3 did for heap-placed
buffers: such an object made then is answered as made, held, where its refused
post answered nil. Its refusal reaches the app where Metal's caller sees a
lost GPU's: the next post retries what is held and is refused in that same
call where the held are refused again; a create that needs the held gone to
make room is refused at once; and a commit that finds anything but destroys
held fails its command buffer, unposted, with MTLCommandBufferErrorInternal.
postHeldCreates already answered so for every held type; serializer_tests'
test_held_creates checks each kind on its own, and protocol_tests'
test_commit_behind_an_untaken_buffer_fails a texture through a commit. A
create the host refuses was answered by no one before, and is not now.
A library's content key was one SHA-256 over its bytes past the bitcode
section: 2.9 to 6.2 MB for the MPS and Espresso libraries a Vision request
loads, hashed by CommonCrypto at 567 MB/s on a guest core (the RTX 3090 host's
guest, with or without the CPU's SHA extensions, which CommonCrypto does not
use), 30 ms of every process's newLibraryWithURL. The key is now
"rgfx-library-v2": SHA-256 of the prefix and of each 256 KiB piece's SHA-256,
in order, and the bundle hashes the pieces at once (dispatch_apply_f); the key
of a library's whole bytes, new on this branch, takes the same form
("rgfx-library-whole-v2"). The host computes both the same way, and both
sides' tests pin the same digests, a multi-piece library's among them.
wire.h is regenerated from wire.rs's new definition, so the ROM's record moves
(its bytes stay the same). An older guest set on this host keys its libraries
the old way: the host then vouches for none of them, so they are made in each
process, uncached, as before the cache. The host's persisted pipeline records,
keyed by their libraries' keys, go cold once.
Measured with the previous commit (rts2 against rts4, RTX 3090 host, load 3.4
and 3.0): newLibraryWithURL, 18 loads, 49.0 -> 18.3 ms in the first process,
44.5 -> 18.0 ms in the second; the three default.metallib loads that hash MPS's
and Espresso's libraries 7.3, 15.5 and 12.0 ms -> 2.8, 4.9 and 3.8 ms.
The host keeps a library under its content key only where it checked every
function's HASH tag against its bitcode. Core Image's libraries fail that check:
all 232 functions of ci_stdlib share one module whose HASH is no SHA-256 of
it. So ci_stdlib and ci_filters were made again in every process, twice each
in a Vision process (1.5 and 2.5 to 3.7 ms a load on the RTX 3090 host), and
their bytes crossed each time. The host now keeps such a library of at most
4 MiB under the key of its whole bytes, SHA-256 of "rgfx-library-whole-v1" and
them, which it computes from the bytes it stores, so no guest can bind other
bytes to it; the bundle asks for that key after a miss on the content key.
No wire change: LIBRARY_LOOKUP takes either key.
Measured with the next commit (rts2 against rts4, RTX 3090 host, load 3.4 and
3.0): the libraries' uploads (LIBRARY with a region) 5 calls and 8.0 ms ->
1 and 0.2 ms in the first process, 4 and 4.7 ms -> none in the second; the
first process's second loads of ci_stdlib and ci_filters 1.53 and 3.82 ms ->
0.24 and 0.20 ms.
A heap's buffer at an offset (BUFFER_AT_OFFSET, each small buffer of a slab) is
a create no one waits for, and cost its own kext call: 3079 a Vision process,
12 to 15 us each, 40 to 48 ms a process on the RTX 3090 host, between the
destroys, which broke each held run of destroys into one call of about 11.
SubmitBatch now takes BUFFER_AT_OFFSET too, of its one size, checked as Submit
checks it, and a buffer made for a context that closed since its check is
destroyed behind it, as Submit does (RgfxSubmitGate's rgfxSubmitBatchSize;
spans_test checks no message the batch takes names a block). The bundle holds
each buffer with the destroys, in their order, and a command buffer's commit
posts what is held before the buffer goes on its ring, as the host reads a
command buffer after the control ring's messages posted before it.
This changes what the guest sees under transport exhaustion only (the control
ring full for 5 s, or the device stopped):
- before, the buffer's create was refused there and the buffer was nil; now
it is answered as made, held, as Metal makes objects on a GPU that is gone;
- before, a command buffer committed on a stopped device was never answered,
and the run hung at its wait; now a commit that finds a buffer still held
fails the command buffer, unposted, with MTLCommandBufferErrorInternal
("Discarded (victim of GPU error/recovery)"), the host's own recovery error,
as the buffer may name it;
- the next post retries what is held and is refused where it is refused
again, and a buffer that needs the held gone to make room is refused at
once, holding nothing more.
Tested by serializer_tests' test_held_buffers and protocol_tests'
test_commit_behind_an_untaken_buffer_fails.
Measured, Vision cold request, RTX 3090 host (rts2, the destroys held,
against rts4, this commit and the next two; load 3.4 and 3.0): destroys and
heap-placed buffers together 62.0 -> 17.6 ms in the first process (3079
buffers and 294 destroy calls become 688 SubmitBatch calls), 51.6 -> 16.1 ms
in the second.
Each destroy cost the guest a trip into the kext, and a post that found the
host's control thread asleep a doorbell's exit too: 14 us a destroy in a Vision
request on the RTX 3090 host, 3415 destroys and 68 to 70 ms a process, in runs
an app lets go back to back. The kext now carries SubmitBatch (selector 5,
feature bit 1 << 1): the bundle holds each destroy (RgfxRingWriter::postLater)
and posts what it holds in one call of at most 4096 bytes, before anything
else the process posts or asks of the kext (every IOConnectCall goes through
rgfxKextConn, which posts the held first), once the held fill a call, or 1 ms
after the first held. The kext checks each as Submit checks one, all before it
posts any, puts the runs on the ring under one hold of its lock with one
doorbell at most, and ends a queue's as Submit does. A texture over an
IOSurface goes at once: a present of the surface waits for its destroy.
What an object lay over goes back as its destroy is held, as it went back once
the destroy was posted: whatever takes it again is posted after the destroy,
so the host drops the object first, and every answer the guest reads (a heap's
usedSize, a new object's GPU address and resource id) is the one it read
before (shell_tests' test_held_destroys_change_nothing_seen). Where the kext
stops taking them (control ring full 5 s, or the device stopped), the rest stay
held; the next post retries them under its own bound and is refused only where
they are refused again. The one difference, under that exhaustion only: what
the held destroys lay over has gone back, so a heap's usedSize read during a 5 s
stall of ring 0 reads lower than before (design.md, "Destroys go together").
Measured, Vision cold request, RTX 3090 host (rts1 against rts2, load 3.6 and
3.4): destroys 69.6 -> 18.6 ms in the first process, 67.7 -> 14.7 ms in the
second; all kext calls 216 -> 162 and 188 -> 135 ms.
While a queue's service thread walked a buffer on its own thread, it marked
the ring as it marks it before it sleeps, so the guest rang the queue's
doorbell for every buffer it published meanwhile: a VM exit that answered
nothing for a buffer that does not ask for its CB_SUBMITTED, in two of three
commits of a back-to-back run on a 26.7.2 guest (11.9 µs a doorbell on a
780M host). The thread now marks the ring walking (consumer_idle 2,
RGFX_CONSUMER_WALKING), for which the bundle rings only for a command buffer
whose last op is its ask, which the doorbell's write may answer; the thread
takes the rest after the walk, as before. A bundle that rings only for 1
rings for none during a walk, and its asking buffer is answered at that take.
What the guest sees: consumer_idle reads 2 during a walk, where it read 1.
Measured with commit_split, before and after in one job each, cold boots of
26.7.2 on um870 (m3-max-23492, m3-max-23493):
- RTX 3090: a back-to-back commit 15.8 -> 2.2 µs (median), doorbells 0.57 ->
0.30 a commit, 22.5 -> 20.2 µs a buffer over 100,000 buffers; a commit's
CPU time in encode_probe's cb.commit 19.6-21.2 -> 15.3-15.7 µs.
- Radeon 780M: 44.5-46.5 -> 44.7-45.3 µs a buffer, bound by the host's
submits; doorbells 0.66 -> 0.54 a commit, the rest of them posts that wait
for room; cb.commit's CPU time 19.6-20.2 -> 18.4-18.9 µs.
An idle queue's single commit rings as before (16.4-17.4 µs on both).
A message too large for half its queue's ring was built in a block of the
queue's pool once it outgrew the ring, and grew from block to block. The
block is write-combined where the kext maps it so, and on an AMD host, which
applies the guest's memory type, a write-combined store still pending
stalls the encoding thread's next locked instruction until it drains. Every
retain and release on that thread, the app's and ours, paid it: on a
26.7.2 guest of a Ryzen host (RTX 3090), encode_probe's
setRenderPipelineState took 108 ns a call in a 10000-call buffer against
21.6 ns in a 400-call one, which stays on the builder's heap, and a
setVertexBuffer between a CFRetain and a CFRelease 103 ns against 17.1 ns.
Growing from block to block also read the old block back, uncached.
The message is now built in the builder's own buffer whatever its size,
which grows to the queue's guess as it outgrows the ring, and the commit
copies it once, whole, into a block from the block's start. The host reads
the same COMMAND_BUFFER bytes; only where the message lies in its block
changes. The tests that held the old placement change with it.
The device answered minimumLinearTextureAlignmentForPixelFormat: with
linearTextureAlignmentBytes, the largest of every format's, for each format. On
a host GPU whose linear images ask more of larger texels that is too much for
the smaller ones: a Radeon RX 550 answers 256 bytes for texels of 1 to 4 bytes,
512 for 8 and 1024 for 16, and Geekbench's MPSImageGaussianBlur source, an
RGBA8Unorm texture over a buffer with rows of 7680 bytes, was nil against 1024.
What the guest observes changes:
- each format answer of the device info carries the runtime's alignment of
that format in its last two bytes (0x3e, `linear_alignment`, which were
zero): 0 where the runtime has none (compressed, depth and stencil formats)
or one past 65535;
- the bundle answers minimumLinearTextureAlignmentForPixelFormat: with the
format's own, and with linearTextureAlignmentBytes where the blob has none,
so the video output planes align to R8/RG8/R16/RG16's own answers too;
- linearTextureAlignmentBytes and deviceLinearTextureAlignmentBytes stay the
largest of every format's.
An x86-64 guest's device made no dynamic library: newDynamicLibrary:error:
and newDynamicLibraryWithURL:error: were RGFX_UNSUPPORTED, so a kernel linked
against a dynamic library could not be made. The platform makes them and
links them (the commit before), and nothing carried them from the guest.
What changes for the guest: the device offers feature bit 40,
DYNAMIC_LIBRARIES (FEATURES_HI bit 8), on every host, and the kext takes it.
Where taken, ring 0 carries DYNAMIC_LIBRARY_CREATE (0x239: the dynamic
library's ObjId and its library's), answered by COMPLETE with its status, and
a COMPUTE_PIPELINE_CREATE ends with a run of RgfxPipelineLibrary records
(library_count, where reserved_5c was): each a dynamic library, preloaded
where it has no install name, else the library that install name loads. The
bundle's RgfxDynamicLibrary answers its library's install name and writes its
bytes to a file URL; newDynamicLibraryWithURL: reads the file in the guest's
process with the AMD Radeon Pro 5300M's and the Intel UHD Graphics 630's
answers (measured, macOS 26.7.1, oracle_urls and oracle_fnptr: a nil URL,
bytes that are no metallib, a library that is not dynamic, a missing file).
Metal reads the file each install name of a library made from a file names
when it creates a pipeline, and none of a library made of bytes or of source
(measured, both Macs, oracle_fnptr: the linked kernel's file makes its
pipeline, and the same bytes through newLibraryWithData: are refused). The
bundle reads them then too: every name the kernel's library, its linked
functions' libraries and these dynamic libraries name, from the executable's
directory, the loading library's or an absolute path, each sent by name. A
name that loads nothing, or that a library of no file names, refuses the
pipeline with the 5300M's CompilerError 2, beside a preloaded library or not,
so the host is never left to read a file of its own. A dynamic library's
install name is read from its metallib's HDYN NAME tag. Render stages carry
none.
A compile of source whose options name dynamic libraries reads each through
the private member airData, the one message Metal sends it (measured, both
Macs): the bundle's dynamic library answers its library's bytes, as Metal's
answers its file's, where it ended the guest's process with an unrecognized
selector before. The caller owns the answer, as it owns Metal's, which is a
new object at each call: the compile releases it, and an unowned answer ended
the guest's process with SIGSEGV after the compile.
supportsDynamicLibraries stays no in this commit; a later one answers it once
the guest's sets carry this bundle. supportsRenderDynamicLibraries stays no,
as the 5300M answers it.
The host knows bit 40 (KNOWN_FEATURES); the tests that probed an unknown bit
at 40 probe 41. The decoder's tests make dynamic libraries on the fake
platform and pass a run's libraries to the creator; the serializer's, the
shell's (the linkage reader, the routing and airData, a pipeline's loads and
refusals), the kext's and the members register's tests cover the guest's
side, and design.md describes the messages.
test_region_pages_join_over_remapped_memory failed now and then at its check
that new memory mapped over the first (VM_FLAGS_OVERWRITE) has another
identity than the first (rgfxPagesIdentity). The identity is the memory's
vm_object's id, which a new object can take once the old one is freed, and
the test's fake block source holds nothing of the first memory, so the
overwrite freed it.
Production does not: the kext wires a pages block's memory (its
IOMemoryDescriptor's prepare), which keeps the first memory's object alive
while the block is held. Measured in a macOS 26.7.2 guest of our device on an
Iris Xe, 200 overwrites each: with a no-copy buffer over the first memory
alive, the new memory's identity was the old one's in 0; with no buffer, in
198. So the join cannot be fooled by a recycled id while the block it would
join is held, and the identity needs no change.
The test now holds a memory entry of the first memory to the end, as the
kext's wiring does, with a comment saying why. Measured on macOS 27.0.1 (the
M3 Max), 5000 overwrites each: the identity was the old one's in 0 with the
entry held, and in 717 without it.
An x86-64 guest's device made no function handle or visible function table:
the bundle's members were RGFX_UNSUPPORTED and the device info held
supportsFunctionPointers at no, so an app took its fallback. The platform
makes them for a compute pipeline (the commit before), and nothing carried
them from the guest to it.
What changes for the guest: the device offers feature bit 39,
FUNCTION_POINTERS (FEATURES_HI bit 7), on every host, and the kext takes it.
Where taken, ring 0 carries FUNCTION_HANDLE_CREATE (0x236: the handle's
ObjId, the pipeline state's, and its function as an RgfxLinkedFunction) and
FUNCTION_TABLE_CREATE (0x237: the table's ObjId, the state's and its entry
count), each answered by FUNCTION_POINTER_STATE (0x40c: the status, and a
table's gpuResourceID, allocatedSize and resourceOptions), and
FUNCTION_TABLE_SET (0x238: a range of a table's entries, 0 a nil entry),
which is not answered and is carried out before any command buffer the
process posts after it. A compute pass binds a table at a buffer index
(RGFX_OP_COMPUTE_SET_VISIBLE_FUNCTION_TABLE, 0x201e) or a range of them
(0x201f), and an argument buffer holds a table by its gpuResourceID. The
bundle's RgfxFunctionHandle and RgfxVisibleFunctionTable answer from the
host's state; a handle of a function the state does not link is nil, as
Metal's is (RGFX_STATUS_NOT_FOUND), and gpuResourceID of a handle and
functionHandleWithName: raise the unrecognized selector the AMD Radeon Pro
5300M and the Intel UHD Graphics 630 raise (measured, macOS 26.7.1). A
table's allocatedSize and resourceOptions are the host's table's, inside the
two Macs' answers. A render pipeline's handles and tables stay unsupported,
with Metal's error. supportsFunctionPointers stays no in this commit: the
next one answers it.
The host knows bit 39 (KNOWN_FEATURES), so a driver's write of it is taken.
The decoder's tests make handles and tables on the fake platform and call
through them on the Vulkan platform; the serializer's, the shell's, the
kext's and the members register's tests cover the guest's side, and
design.md describes the messages.
The x86-64 guest's device made no rate map:
newRasterizationRateMapWithDescriptor: was RGFX_UNSUPPORTED, and the device
info held the layer count at 0, so an app that asks for a rate map (Apple's
Modern Rendering sample among them) took its path without one. The platform
makes rate maps (metal2vulkan's runtime compiles Apple's map, rate_map.rs
there), and nothing carried one from the guest to it.
What changes for the guest: the device offers feature bit 38, RATE_MAPS
(FEATURES_HI bit 6), on every host, and the kext takes it. Where taken, ring 0
carries RATE_MAP_CREATE (0x233) and RATE_MAP_RESET (0x234), both
RgfxRateMapCreate (the map's obj_id, the screen size, the private mutability
where set, and the layers' RgfxRateMapLayer records with their samples),
answered by RATE_MAP_STATE (0x40a: the map's screen size, granularity, layer
count, mutability and parameter data's size and alignment), and
RATE_MAP_QUERY (0x235), answered by RATE_MAP_ANSWER (0x40b): a layer's
physical size, a coordinate mapped either way, or a copy of the parameter
data, which the platform writes where a buffer of the sender's lies before it
answers. A render pass names its map after its other records
(RGFX_PASS_FLAG_RATE_MAP, RgfxRenderPassRateMap). The kext admits the three
messages, waits for their answers, and destroys a create it timed out on. The
bundle's map (RgfxRasterizationRateMap) answers the host's state, asks the
host each answer that takes an argument, copies into a Shared buffer of ours
in place and into any other through a scratch buffer of its own, answers the
SPI's mutability, minFactor, resetUsingDescriptor: and formattedDescription:
(the words of Metal's base map, measured on the AMD Radeon Pro 5300M), and
ends the process where Metal's map does: at a copy into a Private buffer, and
at a coordinate map the host refuses (a map of no layers or of an empty
screen, a Mutable map not yet reset). The layer counts stay 0 in this commit:
supportsRasterizationRateMapWithLayerCount: answers no until the device info
answers the platform's.
The core platform's map gains screenSize, which the state answers.
New tests: the decoder's create, reset, queries and copy (decode/rate_map.rs,
on the fake and on Vulkan), a pass's map (cmdbuf.rs), the header's checks of
the new names, the kext's feature, gate and reply types, and the bundle's
messages (serializer_tests), map (shell_tests, its two deaths among them) and
pass record (protocol_tests).
00268441a lets a no-copy buffer join a live pages block when its address,
length and writability match. Matching values do not make it the same memory.
An object can outlive the app's hold of the memory under it, through a texture
over the buffer or a command buffer that holds it. In that time the app can
unmap the memory and map other memory at the same address. WindowServer does
this with CoreAnimation's shmem images. The new buffer then joined the old
block, so the GPU read the old pages, which the kext still had wired, while the
app wrote the new ones. In a macOS 26.7.2 guest, System Settings' "About" row
drew the Energy pane's title, clipped, in 3 of 8 pane switches on a Radeon 780M
and 3 of 8 on an RTX 3090. Setup Assistant's labels showed earlier panes'
strings in the same way at a379a5a45; that was not run again.
A block is now joined only where the memory at the bytes is the memory the
block was given for. rgfxPagesIdentity reads, for each VM region the bytes
span, the region's VM object (mach_vm_region_recurse's object_id_full) and the
offset in it. It is read once the kext has wired the block's pages, since
the wire gives a copy-on-write mapping an object of its own. A joinable block
whose bytes now hold other memory is joinable no longer, and the new buffer
takes a block of its own. So do bytes whose memory cannot be identified
(no object yet, a hole). The first refusal in a process logs one info line,
and each refusal logs a debug line.
With the check, no label drew stale in 16 switches on each GPU. In each run,
WindowServer refused joins over one-page images: 28 on the 780M and 15 on the
3090.
For the host, a buffer over remapped memory now names a pages block of its
own in BUFFER_OVER_PAGES, and its GPU reads and writes reach the app's current
memory. The guest's objects, GPU addresses and contents are unchanged.
Tests: the region joins over the same memory mapped again at the same
address and offset, and never over new memory at the same address with other
contents, over the same memory at another offset, or over memory with no pages
yet; a no-copy buffer over memory remapped while the first buffer lives takes
its own block, and a third buffer joins it.
A guest's samplers lost lodBias and reductionMode (macOS 26) on the way to
the host: SAMPLER_CREATE's extension, RgfxSamplerCreateExt, was on the wire,
but the bundle never sent it and new_sampler never read it, so every sampler
was made at bias 0 with weighted-average reduction. The guest's state cache
already keyed on both, so two descriptors that differed only there were two
guest samplers of one host shape.
The bundle now sends the extension with every create, on the posted and the
asked route. new_sampler sets the platform's reduction mode and its new LOD
bias from it, and leaves both unset for a create without one, which keeps
Metal's defaults. What the guest sees changes: a sampler of minimum or
maximum reduction samples that way, as Metal's does. The runtime's sampler
descriptor holds no bias yet, so a non-zero bias still samples at 0, and is
now relayed as inexact-sampler-lod-bias, with an accuracy-ledger row, until
the runtime takes one.
The header follows wire.rs's doc, the ROM's record that header (its bytes
are unchanged), and both guest sets are built again from these sources.
Since 18b642dab the guest's Metal device answered iosurfaceTextureAlignmentBytes
and iosurfaceReadOnlyTextureAlignmentBytes from the host's runtime, 128 on an
NVIDIA GPU and 256 on RADV, so that CoreAnimation would round its backing
stores' rows to what the host takes in place. CoreAnimation also refuses a
Metal texture of any surface whose rows or planes are not at a multiple of
that answer, and the surfaces other code makes keep their own rows. In macOS
26.7.2 guests on an RTX 3090 and an RTX 2080, WindowServer logged "Failed to
allocate MTLTexture from IOSurface ... Row bytes (5312) not 128 aligned" for
rows of 192 to 14272 bytes, and Safari drew pages blank and WebGL black on
every load (appwalk2 walks m3-max-16925, -17008). On a Radeon 780M, at 256, it
found Safari's 1080p and 2160p video frames without the proper alignment.
What the guest observes: the device answers 16 for both again, as Metal's
devices and the IOGPU base do, whatever the host's GPU answers. On RADV the
backing stores' rows go back to 64-byte multiples, so the runtime shadows
those 18b642dab moved in place (1399 textures over a cold boot and a Safari
scroll of macOS 11.7.11 on a 780M).
test_iosurface_alignments_divide_other_codes_surface_rows holds the answer to
the rows WindowServer refused; the member register lists both as Metal's. The
trap is in docs/lessons.md.
A no-copy Managed buffer over writable app pages was one copy on every host:
the bundle sent its BUFFER_OVER_PAGES with Shared storage, and its
didModifyRange: and a blit's synchronize of it, or of a texture over it, sent
nothing (e828db91b). Apple's OpenCL makes each default cl_mem such a buffer and
binds it to every kernel, so on a host GPU with memory of its own the kernels
read and wrote it across the bus in system memory. CL makes the calls Metal
requires of a Managed buffer: synchronizeResource: before a map, and
didModifyRange: after a map for writing (measured with cl_bw on a macOS 26.6.1
guest on the RTX 5080 host).
The buffer is now a Managed buffer over a Shared one, as the pages slabs'
large Managed buffers are: the BUFFER_OVER_PAGES buffer, still Shared, is its
CPU copy, and a MANAGED_BUFFER_CREATE over it, at an address of its own that
keeps the pointer's offset in its page, is the buffer the app gets. At its
release the Managed buffer goes first, then its CPU copy, then the pages
block. A device that makes no Managed buffer over a Shared one gives such
memory the shadow, as read-only memory has.
What the guest sees: the host's object for the buffer has storageMode Managed,
and the buffer's didModifyRange:, a replaceRegion: of a texture over it, and a
blit's synchronizeResource: or synchronizeTexture: of it or of such a texture
now reach the host. On a host GPU of its own memory the buffer is two copies,
as the AMD 5300M's is: the GPU sees a CPU write only after a didModifyRange:,
and the CPU a GPU write only after a synchronize. On a GPU that shares the
CPU's memory it stays one copy, as the Intel 630's is.
The shell tests that held one copy now hold the two messages, the ranges and
synchronizes sent, the release order, and the shadow where the device makes
no Managed buffer over a Shared one; the serializer tests hold the Managed
create's offset.
Each no-copy buffer over the app's own pages took a pages block of its own, so
two buffers over the same bytes had two host views of the same pages, and where
the views' gate refuses their import (a buffer of scattered guest pages at the
stock vm.max_map_count on NVIDIA), the runtime made a copy and a snapshot for
each. Apple's OpenCL makes such buffers: a Shared no-copy buffer over its
staging pages at each clEnqueueWriteBuffer, the same pages each time, while the
one before still lives. On the RTX 5080 host, each 256 MiB of them cost QEMU
512 MiB more Rss per write.
The region now gives a block asked for the same bytes, writability and join
again while it is joinable, so such buffers lie in one view and one copy, as on
a Mac they lie in the same pages. A block stays joinable until each buffer over
it has gone for the app, so a block is never joined over memory the app freed
and took again at the same address, and it goes back to the kext once the host
has dropped every buffer over it. A buffer of Metal's private bit 24, which the
host's runtime takes as read-only memory, joins only its own kind. Nothing
changes for the guest: each buffer keeps its object, GPU address and contents.
Tests: the region's joins and their release order, two no-copy buffers over
one block in the bundle, and the host's one view under two buffers.
The guest's Metal device left iosurfaceTextureAlignmentBytes and
iosurfaceReadOnlyTextureAlignmentBytes to the IOGPU base, which answers 16 from
its own state, so the host's answer in the device info never reached the guest.
CoreAnimation rounds the rows of its backing stores' IOSurfaces to
iosurfaceTextureAlignmentBytes (to no less than 64 bytes) and names them to
IOSurface, which keeps them. On RADV, which takes a linear image in place only
at rows a multiple of 256 bytes, those 64- and 128-byte rows are the runtime's
shadows. In a macOS 11.7.11 guest on a Radeon 780M, 1399 textures were shadows
for their pitch over a cold boot and a 15 s Safari scroll, and 11 with the
device answering 512.
The device now answers both from the device info, which carries the Vulkan
platform's answers. What the guest observes: since pin 37 the runtime answers
the device's linear row alignment there, so on RADV (GFX9 to 11) the guest
now sees 256 where it saw the base's 16, and CoreAnimation's backing stores
take rows the host's GPU takes in place; on other GPUs it sees that GPU's
linear row alignment. The device-info doc said an IOSurface's rows follow
none of the device's answers; it now says which answers they follow.
On macOS 12, Safari's web content process may call only the external
methods its sandbox lists on an IOAccelerator connection: 0-13, 15-18,
22-24, 28-31, 40, 42, 48, 256-265, 267, 268 and 512 in every Safari from
15.1 to 17.6. Its sandbox refused Features (0x10f) before the kext saw it,
and the bundle went on without the kext's features: it took 64-id chunks
where the kext granted 16, and the host refused the textures past each
chunk's first 16 ids (BadResourceId), so pages drew without their body and
text. Under Safari 15 and 16, SurfaceBlockRelease (0x10a) and
SurfaceRetire (0x10d) were refused too. macOS 11, and 13 and later, list
no numbers.
What the guest sees:
- New selector numbers, selector map 1: Features 3, PagesBlock 4,
TakeAnswers 7, SurfaceBlockRelease 8, SurfaceRetire 9, and a shared
event port's Export 10 and Import 11. 1, 5 and 6 stay reserved, 2 is
given to none, and the rest keep their numbers. No number of map 0
takes a new meaning, so a bundle or kext of map 0 is refused, not
misrouted.
- Features answers a third word, the selector map, and keeps its number
in every map. A bundle that meets another map has no Metal device.
- ResourceIds answers the chunk's size after its first id, and the bundle
takes its chunks at that size.
- Where the bundle's setup left a stubbed device (no features, the device
info unread or of another version, the context or the user client not
opened) or returned silently (the IOGPU base declined), the process has
no Metal device, with a log line that says why. A host's video caps of
another version still leave the device without video codecs, now
logged.
user_client_words_test holds the sandbox's set, checks every selector and
the kext's routing against it, and checks that every IOConnectCall*Method
in the bundle's sources names one of them. design.md's registry gives map
1 and what map 0 was. The kext set is built again.
What changes for the guest: the device's featureProfile is 10002 where it was
the host's, 10 on every host so far, wherever the guest's Metal has the
MTLArchitecture class (macOS 13 and later), on every host. Where it lacks the
class (macOS 11 and 12) the device still answers 10001. Both x86 Macs of the
oracle answer 10002 under macOS 26.7.1 (the Radeon Pro 5300M and the UHD 630),
and the guest's Metal keys its limits, families and feature queries on the
profile. 10 was the M3 Max's, kept only because macOS 26's WindowServer, under
10002, asks for tiled textures of 6 and 7 levels over a buffer, which the
device answered nil; the host makes those now (the two commits before), and
26.7.2 composes its desktop under 10002 with them.
The answer is made in one place, RgfxFeatureProfile.hpp, which no longer takes
the host's profile: the bundle stops reading it from the device info, whose
field the host still fills with its Metal device's or the M3 Max's.
The profile's unit test, which held the host's answer from macOS 13 on, holds
10002 there and 10001 below; the guest's kext set is built again with it.
macOS 12's Metal keys every limit of a device on its feature profile and has
none for the M3 Max's 10, which the device answered on every guest: it left
the limits 0 and ended WindowServer at device creation, so 12.x guests never
reached a desktop (launchd gave up after 14 runs).
The device now answers the host's profile only where the guest's Metal knows
it, told by what that Metal has: the MTLArchitecture class, which macOS 13
and later have (13.7.8, 14.8.9 and 26.7.2 boot with 10). Elsewhere (macOS 11
and 12) it answers 10001, as 12's drivers for the 5300M and the UHD 630 do.
26 keeps 10 rather than the x86 Macs' 10002: under 10002 its WindowServer
still asks for a mipmapped tiled texture over a buffer, which the device
refuses (dgpu-oracle.md, Q11, rechecked).
What changes for the guest: featureProfile on macOS 11 and 12 is 10001; on
13 to 26 it is unchanged.
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 device answered the IOGPU base's vendorName, "Apple", beside the Mac2
family alone, a pair no Mac has. The system's GL renderer
(AppleMetalOpenGLRenderer) picks its settings by finding "AMD" or "ATI",
"NVIDIA" or "Intel" in the vendor name, else by the Apple GPU families 7 and
5 (read from its code). On any other device it ends every process that makes
a GL context ("Unknown GPU!!", measured: macOS 26.6.1, RTX 5080 host).
The answer is now the vendor the device name's first word names, in the
words the Macs answer: "NVIDIA", "AMD" (the AMD 5300M's) or "Intel(R)" (the
Intel 630's, measured: macOS 26.7.1). A name of any other vendor answers
"AMD", the x86 Macs' discrete GPUs' vendor, since the renderer knows no
other. The Macs diverge here (class 2); the register says so.
RgfxEncoder zeroed the field the decode ops used to keep reserved, which
is output_rows now: the rows the output surface holds go to the host as
the video driver set them. The serializer test checks they arrive.
shell_tests' check count changed between runs of one tree (262756 to
296306) because of test_commit_order_names_no_cycle. Its two threads often
ran one after the other, so no post named the other queue, and its cycle
check checked nothing (40002 checks in a run, against 72352 in another,
m3-max-5134). The threads now start together, and a run where either queue
names nothing runs again, up to 50 times, before the test fails.
The check counter is atomic: CHECK runs on the test's threads, and the
plain int could lose counts there.
Reverts 0825b1ea2, restoring 0afc30f37, e8d04b187 and ea13ccbca. A write-combined
mapping of the region does take: the region's descriptor is physically
contiguous, and xnu's fault path maps such an object's pages in its own cache
mode (vm_fault's pmap_map_block_addr, read from the public xnu source), which
the earlier reading missed. The page-table probe that seemed to agree saw only
the processes on the CPUs at its instant, not the bench.
Measured on the Radeon 780M host, draws.10k's encode: 9.2-9.5 ms at the base,
7.7 ms with the slabs in the process's own pages alone (936e3968d's set), and
1.05-1.3 ms with the spans write-combined as well (0afc30f37's and ea13ccbca's
sets). The kext's comment and the design doc say why, and docs/lessons.md the
probe's trap.
For the guest, as 0afc30f37: a queue's submission ring starts 3840 bytes into
its block, the kext's Alloc takes a third input and its feature word holds
1 << 7.
Reverts 0afc30f37, e8d04b187 and ea13ccbca. On x86-64 xnu every mapping of
the region in a guest process is uncached, whatever cache mode the kext asks:
vm_fault enters each page with no cache flags, and the pmap gives a page it
does not manage PCD alone, the guest PAT's UC- (read from the public xnu
source: pmap_get_cache_attributes and vm_fault's pmap_enter wrappers). Measured
on the Radeon 780M host with both the region's own descriptor and one of the
write-combined spans' own: every page of a process's over BAR 2 was PCD alone,
none PAT and PCD, and draws.10k encoded as fast as with the spans write-back.
For the guest, a queue's submission ring starts its block again, the kext's
Alloc takes two inputs and its feature word drops 1 << 7; the slabs in the
process's own pages (72c09eddc) carry the measured gains. The design doc says
why the region is uncached, as measured.
The guest's kernel maps the device region uncached whatever the kext asks:
xnu's pmap sets PCD on every page it does not manage, and the region is no RAM
of the guest's. An AMD host applies the guest's memory type (Intel's EPT
ignores it), so on the Radeon 780M host the guest's stores there ran at
13 MB/s and draws.10k spent 9.1 ms encoding against 0.5 ms on the RTX 5080.
The kext's Alloc now takes a third input, the byte from which the process's
mapping of the block is write-combined (kIOMapWriteCombineCache, PAT index 6),
behind a kext feature bit. The bundle puts there what it only writes: a
submission ring's data, which now starts its block's second page with the
ring's header ending the first, write-back as before, since the host writes
it too and the writer reads it; command buffers' bodies; and a library's
staging chunks, past the page of acks it reads. The ring writer fences its
stores (sfence) before it publishes a message, so write-combined stores reach
the host before the producer index that names them, as a release store
orders write-back ones. ICB slots stay write-back: their setters read fields
back and OR bits in with locked operations, which write-combined memory does
not keep atomic.
For the guest, a queue's submission ring now starts 3840 bytes into its block
where the kext has the feature; the wire is unchanged.
The GL renderer makes its no-copy buffers with resource option bit 20
(0x100000), a hint for the device's driver. The bundle passed every bit
to the host, and the host's runtime refuses a buffer with a bit Metal
gives no meaning, so each such buffer was refused (measured: macOS 26.6.1
on the RTX 5080 host).
Heap and buffer creates now carry only the CPU cache, storage and hazard
tracking modes, and Metal's private bit 24, which the host takes as Metal
does.
A buffer outside a heap now answers resourceOptions with its three modes
alone. On macOS 26.7.1 the AMD 5300M and the Intel 630 drop each of bits
10 to 31 from the answer, for length and no-copy buffers alike: they give
0x200, 0x210 and 0x220 for Shared, Managed and Private.
A device-placed texture and a Managed texture's GPU copy take a GPU address
of the context's range, which runs out at address-space exhaustion. Their
creates took the address unchecked and posted 0, where a heap, a buffer and
every other create that picks an address answer no object.
What changes for the guest: at exhaustion such a texture is nil, as Metal
answers one it cannot place, and nothing is posted; its resource id goes back
for the next texture. A texture in a heap takes no address and is unchanged.
Test: test_creates_with_no_address_post_nothing fails at the base, where both
creates post with address 0.
For the guest: where the device takes MESH_PIPELINES, every
newRenderPipelineStateWithMeshDescriptor: form makes a mesh render pipeline. It
used to answer nil and an unsupported error. The render encoders send the object
and mesh stages' bindings and drawMeshThreadgroups:, drawMeshThreads: and the
indirect form, and the SPI's supportsMeshShaders answers YES. Without the
feature they answer as before. The state answers its object and mesh limits as
the host's platform answers them (maxTotalThreadgroupsPerMeshGrid NSUIntegerMax
past 32 bits) and the threadgroup sizes its descriptor required.
Measured with guest/bundle/tools/oracle/oracle_mesh, plain Metal, on the AMD
Radeon Pro 5300M and the Intel UHD Graphics 630 (macOS 26.7.1, 25G241) and the
M3 Max (macOS 27.0.1, 26A434), the creators now end the process where the x86
Macs' Metal does, with their words:
- supportIndirectCommandBuffers YES, on the 5300M and the 630 (the M3 Max makes
it): "validateWithDevice:1884: failed assertion `Mesh Render Pipeline
Descriptor Validation\nUse of mesh shader pipelines in indirect command
buffers is not supported by this device.\n'"
- no mesh function, on all three: "...\nmeshFunction must not be nil.\n'"
- no fragment function while rasterizing, on all three: "...\nfragmentFunction
must not be nil.\n'"
So no mesh pipeline supports indirect command buffers, and indirect commands
carry no mesh draw. This matches the families: supportsFamily: answers no for
Apple7 to Apple9 on the x86 Macs and on the device, and the SPI's
supportsMeshShadersInICB answers NO on the x86 Macs and the device (YES on the
M3 Max).
They refuse before the host is asked, in the x86 Macs' compiler's domain
(CompilerError):
- a payload past 16384 bytes, code 2, "payloadMemoryLength property of
MTLMeshRenderPipelineDescriptor (16385 bytes) exceeds maximum supported by
this device (16384 bytes)";
- a stage maximum past the device's 1024 threads, code 2, the 5300M's
"maxThreadsPerThreadgroup pipeline descriptor value (2048) exceeds maximum
supported (1024)\n" (the 630 makes it, the M3 Max refuses it);
- a vertex function as the mesh function, code 2, "RasterizationEnabled is
false but the vertex shader's return type is not void";
- any other function of another stage, code 1. The x86 Macs answer the
crashed compiler's XPC words; ours are the validation layer's;
- a mesh function as the object function, code 1, which the x86 Macs make
and the M3 Max refuses;
- an archive miss under MTLPipelineOptionFailOnBinaryArchiveMiss, code 2,
"Unable to find function \"f_col\" in binary archives. \n ". It names the
fragment function, else the mesh function. An x86 archive holds no mesh
pipeline, so every create naming an archive misses.
The creators with a reflection answer RgfxMeshPipelineReflectionOf's, the
reflection of the pipeline's functions, as the render pipeline creators answer
theirs.
Both x86 Macs read a binary archive's slice bytes only where the file holds the
device's own slice (its CPU type and subtype): then that slice and the AIR
slice are read, and either one junked is "an invalid format"; a file whose
slices are none of the device's is an archive of no keys, junk or not (AMD
5300M and Intel 630, macOS 26.7.1: oracle_bundle archive.slices, 21 files of
recombined and junked slices). No Metal slice is the device's, whose archives
are its own format, so the bundle, which never reads a Metal archive's slices,
already answers so; a junk AIR slice beside another GPU's slice now has a test.
The kext hands out chunks of 16 texture resource ids where it takes
SMALL_ID_CHUNKS (bit 23). The bundle now keeps its ids by small chunk, each
small chunk's free ids in a 16-bit mask, and takes each chunk from the kext
as the size its feature word says: 16 ids with bit 23, else 64, a chunk of 64
being four small chunks. A chunk not aligned to its size, past the pool, or
over a small chunk the process holds is no chunk.
Until the kext takes bit 23 its chunks are 64 ids, and the bundle takes and
hands out ids as before.
A guest app that makes a binary archive from a .metallib's URL now gets an
archive, holding none of the device's compiles, where the bundle answered nil
and "has an invalid format". Both x86 Macs' Metal makes one (AMD 5300M and
Intel 630, macOS 26.7.1; oracle_bundle archive.metallib). Bytes of the magic
MTLB whose header states another file size stay no archive, as the bundle reads
a fat file cut short.
The guest's IconRendering opens its binary.metallib, a fat file of magic
0xcafebabe and 18 slices of other GPUs, as a binary archive. The bundle read
only its own format and Metal's 0xcbfebabe, so it answered nil and "has an
invalid format". Metal reads the fat files of 0xcafebabe alike: on the AMD
5300M and Intel 630 under macOS 26.7.1 (oracle_bundle archive.*), that file
and an archive the device wrote with its magic changed each make an archive of
no keys with no error, and a file of no slices is an invalid format.
What the guest sees now: such a file makes an archive with no keys, which
misses every lookup, as another GPU's archive does.
A function made with a constant value of another type fails with Metal's
words, which name both types. The bundle named only the constant types (the
scalars and vectors) and printed any other value, a matrix, a texture or a
pipeline among them, as MTLDataType(N). Metal names every value of the enum
"MTLDataType" and its name in MTLDataType.h (measured with oracle_names on the
AMD Radeon Pro 5300M and the Intel UHD Graphics 630, macOS 26.7.1, each of the
95 values set for an int constant).
What the guest sees: the error's description names a value of a type no
function constant takes as Metal does ("... has type MTLDataTypeFloat4x4").
A value outside the enum still prints as MTLDataType(N).
The region gives an app about 440 MiB of slabs, past which its buffers'
creates fail. Where the host makes heaps over pages blocks (HEAP_OVER_PAGES)
and the kext wires them (PagesBlock), a heaped class's 2 MiB slab is now a
superpage of the process's own, one run of guest RAM, wired into a pages
block and made one HEAP_OVER_PAGES, its buffers placed in it as in a region
slab's heap: BUFFER_AT_OFFSET, and BUFFER_MANAGED_AT_OFFSET where the device
took MANAGED_AT_OFFSET. On the RTX 5080 such a heap takes 13.4 us and a
placed 4 KiB buffer 1.93 us, where a no-copy buffer over the block's view
took 65-75 us. A larger dedicated slab, which would be more than one run,
and a slab where the kernel has no superpage to give or the kext no pages
block, stay the region's. RgfxSlabs asks the first source before the
region's for each new slab, and a slab keeps the source it came from.
A process's first library over 8 KiB took a staging window of 64 MiB and kept
it for the process's life. On a busy desktop on the RTX 5080 host, nine
processes held 576 of the 731 MiB of the region outside WindowServer's
reserve that way (mediaanalysisd held nothing else), so the region ran out at
41 processes. From there, libraries, buffers and queue rings came back nil,
and Games, Photos, Photo Booth, Maps, the Dock's extras, NotificationCenter
and WebKit's GPU process crashed.
The window is now made for one stream and sized to its library: as few
chunks of at most 32 MiB as hold it, split evenly in whole pages, and a
second block only where there are two or more chunks. It goes back to the
region once the host has acked every chunk. Where the region refuses it,
smaller chunks are asked for, down to a page, so a library is made while any
room for three pages is left. A window whose chunk the host never acks is
kept, so nothing the host may still read is given out again.
The stream moves to RgfxLibraryStream.cpp, so the serialiser check covers it
against a host of its own: the shapes, the fallbacks and their bytes and
order, the window given back, and one kept when an ack never comes.
fillRenderPass carried no visibilityResultBuffer, so the host met each
setVisibilityResultMode:offset: of a mode in a pass with no buffer and failed
the command buffer. A render and a parallel render pass whose descriptor holds
one of our buffers now send it after their colour records and sample positions,
with the descriptor's visibilityResultType where its class answers it (macOS
26). The buffer is noted as the command buffer's write, as an attachment is,
so a copy of app memory or of an IOSurface under it takes the GPU's results
back and the buffer is kept to the completion.
The bundle's half of PagesBlock's plumbing, which no-copy buffers and
fix-shared-mem's guest-RAM slabs both build on, as its own commit.
RgfxRegion gains a pages block source: acquirePages asks it for the block of
the runs of the pages under an address range, which the kext wires for the
block's life. The block's pointer is null, since the process never maps a
pages block, and a block the region does not hold goes back through the
block source's release, as a surface block does. The device sets the source
to the kext's PagesBlock call (0x10e) only where the kext's own word holds
PagesBlock and the device's word holds PAGES_BUFFERS.
RgfxSerializer::createBufferOverPages posts BUFFER_OVER_PAGES. It picks the
GPU address and owns it as createBufferOverHostMemory does; the pick holds
the span from the page the buffer starts in, and the buffer's address keeps
its pointer's offset in that page, as Metal's no-copy buffer keeps its
pointer's. The answer's gpu_address is the pick, which releaseAddress gives
back; with an offset of 0 it is the buffer's address too.
The kext gave each process a context in one of 32 slots of 2 TiB, and refused
the 33rd: on the RTX 5080 host 17 processes held one on an idle desktop, and
opening the system's apps refused Freeform, the 13th, and every app after it
(57 processes, 25 refused). A refused process got a device whose every create
answered nil, and Maps and Journal aborted in VectorKit, Photos asserted and
Games faulted at their first objects. No Mac caps Metal processes like that.
The guest's [2^46, 2^47) is now 1024 units of 64 GiB, which the kext hands out
from a bitmap (RgfxContextSlots.hpp, with its native test) as aligned runs: one
unit a context, or the least power of two holding twice the device's
maxBufferLength where that is more than 32 GiB, so a buffer of maxBufferLength
always fits. Runs go round-robin, and the last 32 units free are WindowServer's
alone, as the blocks' and queues' reserves are.
OpenContext answers the span sixth under the kext feature bit ContextSpan
(1 << 5), and the bundle picks through it. A bundle that asks for five values
gets an aligned 2 TiB run, the span it picks through, so an old bundle keeps
working on a new kext, and a new bundle on an old kext takes its 2 TiB slot.
The host knows no slot: it pins each address as given, so it is unchanged, and
needs no device feature bit. Its test now pins at every unit's first address.
Past the last run the bundle answers no device in that process (init answers
nil), the answer every Metal client handles, in place of a device whose
creates answer nil.
A queue's ring writer logs its sleeps for room at the first sleep and then at
most once a second, so a process that slept for room for under a second after
that first line showed only the first sleep: in a ring-filling boot each
ringfill run's line read "1 sleeps" while the host posted about 2200 room
records in the same run, and how many more posts slept went unseen.
The writer now logs the counts once more as it goes (its queue's release) where
its posts slept since the last line.
A boot can now show how the commits that found a queue's submission ring
full waited: a line for each ring at its first sleep for room and then at
most every second, with the sleeps, how many a SUBMIT_ROOM record ended,
and their time in all and at most. Without SUBMIT_ROOM every sleep is the
backoff's; with it, the records end them. RgfxRingRoomSleeps counts and
paces the line, and the serializer tests pin both.
A commit that finds its queue's submission ring full rang the doorbell and slept
20 us, doubling to 1 ms, between looks, so its post went on up to the last
step after the host took room, and a stream of commits through a full ring ran
at the sleep's cadence.
Where the device's word holds SUBMIT_ROOM, a new queue's ring writer and its
completion reader share a room signal (RgfxRingRoomEvents). A post that finds
no room stores 1 in the ring's producer_waiting, fences and looks once more,
then waits on the signal, which the reader raises as it reads the host's
RGFX_EVT_SUBMIT_ROOM, with a 20 ms backstop; where no completion thread drives
the reader, the wait keeps the sleep's step, as the waiter's own pump takes the
record. Without the bit nothing changes. The signal is shared, so a record read
as its queue goes finds it alive.
serializer_tests' test_ring_post_waits_for_the_room_record pins it: the full
ring's post sets the flag, room taken with no record leaves it waiting, the
record ends the wait, and a reader hands its ring's record to the signal.