A command buffer committed while the control ring held messages made two kext
calls: SubmitBatch posted the held, then the bundle published the buffer on
its queue's ring and rang the queue's doorbell through the kext. The second
call costs its kernel entry and return around the doorbell's write: measured
with the commit probe and the kext's stamps at 4.6 us p50 a commit on the Iris
Xe host (1.3 in, 2.0 the write, 1.2 out), and on the 780M host 4.5 us warm and
11.3 us after 2 ms idle (3.2 in, 2.7 out). Every commit the probe made behind
held messages rang it.
Where the kext answers kRgfxKextFeatureQueuePublish, SubmitBatch takes three
scalars more: the queue, its ring's new producer and the doorbell's flags. The
bundle writes the buffer on its ring and fences its stores, leaves the
producer, and hands the publish to the held (RgfxRingWriter::tryPost's `via`,
RgfxSerializer::publishVia). Once the kext has posted every held message it
stores the producer, fences, reads consumer_idle and rings the doorbell as the
bundle's own publish does (RgfxQueuePublish.hpp), so the host sees the held on
ring 0, then the buffer, as before. A commit with nothing held, or behind an
indirect command buffer's encodes or a refused destroy, goes as before; so
does every commit with a kext that lacks the bit. Where the kext leaves a held
message other than a destroy unposted it publishes nothing, and the bundle
takes the buffer off its ring unseen, its seqno the next buffer's and its
expected records dropped (RgfxReplyReader::forget), and fails it as before.
The buffer's posted time is stamped before the call.
The kext maps each queue's submission ring header at QUEUE_CREATE, while the
ring's block is pinned, only where the block is the client's own (ownsBlock),
in RgfxAcceleratorUserClient::keepQueueHeader. It lets the mapping go before
the pages can: at the queue's destroy (destroyQueueIfTracked), at Free of the
block the ring lies in, before the free, and at the context's close
(releaseContext, before the window and the blocks go). Each publish runs under
the client's list lock, which every drop takes. A device reset frees no block:
the mapping stays the process's ring until one of those. A queue past the
client's first 64 is published by the bundle.
Tests: queue_publish_test (the kext's publish against the bundle's own, every
consumer state and flag, and the headers' table through create, free, destroy
and close), shell_tests' test_commit_hands_its_publish_to_the_held (one call,
nothing held, a kext without the bit, a refused create, refused destroys
alone) and user_client_words_test (the bit).
Guest-visible on an arm64 guest (and wherever the device answers an Apple
family): a depth/stencil state's gpuResourceID now answers 0, and an argument
encoder's setDepthStencilState:atIndex: (and its range form) writes nothing,
where both raised an unrecognized selector, which ends the process where
nothing catches it.
The M3 Max under macOS 27.0.1, with no validation layer, answers 0 for every
state's gpuResourceID, and its encoders write nothing and raise nothing for a
state or nil: at a depth/stencil descriptor's index, beside a texture and a
pointer, on an encoder of one texture, and on one of a function's argument
buffer holding a state (oracle_bundle Apple argbuf.ds.id, .set, .mixed, .tex,
.texnil, .nil and .function, 11-13). x86 guests keep the x86 Macs' raises,
which the protocol test keeps beside the new answers. A state's resourceIndex
and uniqueIdentifier still raise on both: the M3's answers to them were not
measured.
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 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.
An encoder's setVertexBytes, setFragmentBytes and setBytes took the command
buffer's upload arena's lock for every put. In a macOS 26.7.2 guest a 16-byte
setVertexBytes cost 105 ns on a Radeon 780M host and 103 ns on an RTX 3090
host, against 12 ns for Metal's on an AMD 5300M and an Intel 630, and sample
put 89% of the call in os_unfair_lock_unlock (encode_probe).
Each encoder now fills a run of a chunk of its own, where a put that fits
takes no lock, and hands what is left back as it ends, so the command
buffer's next encoder fills on from there: the bytes land where the one
shared cursor put them, a parallel pass's sub-encoders each fill a run of
their own, and nothing the host reads changes for an encoder of its own
pass. The new test puts bytes from four sub-encoders' threads at once and
checks every binding's bytes and place.
The bundle kept requiredThreadsPerThreadgroup guest-side and sent the host
none of it, so a compute pipeline whose required size is past its kernel's
[[max_total_threads_per_threadgroup(n)]] was made, where Metal's compile
refuses it. maxTotalThreadsPerThreadgroup against the kernel's attribute and
the device's limit went unchecked guest-side too, and macOS 27's
forwardProgressUsage and contentionRelief were taken whatever their value.
oracle_threads measured each case on the AMD 5300M, the Intel 630 and the
M3 Max (m3-max-22216, 22217, 22214; dgpu-oracle.md Q32). The AIR reader now
reads a kernel's attribute (air.max_work_group_size), and the bundle checks
the fields before it posts the create, in the x86 guest the AMD GPU's way
and in the arm64 guest the M3's, as its validation and compiler do.
What the guest observes: a required size with an axis of 0, past the
device's limit or past the descriptor's maximum ends the process at Metal's
failed assertion; a required size past the kernel's attribute, a descriptor
maximum other than the kernel's or past the device's limit, and a forward
progress usage or contention relief Metal does not name are refused with
the device's error, and nothing is posted; a pipeline of a required size
answers its threads as maxTotalThreadsPerThreadgroup; and forwardProgressUsage
Automatic answers Weak. The tests that held the old answers change with it.
What changes for the guest: on an arm64 guest, newResidencySetWithDescriptor:
error: now makes a set and sets the error out to nil, where it answered nil and
an error, and allocResidencySet makes its object. Apple silicon's Metal makes
one on macOS 15 and later, and apps built for it (game ports, engines, and
QuartzCore's CAMetalLayer.residencySet on macOS 26) use it; some abort at nil.
The x86 guest answers exactly as before: nil, its error out set to nil, as the
x86 Macs answer.
The device keeps every allocation resident, so a set is guest-side
bookkeeping and sends nothing to the host. It answers what the M3 Max's set
answers (tools/oracle/oracle_residency): adds and removes pending until a
commit, a pending remove still counted, the set holding its allocations,
allocatedSize the memory the last commit left, each piece once (a heap's
resources their heap, a view its texture, a texture over a buffer its buffer),
a nil allocation ending the process. Two answers differ on purpose: the label
is the descriptor's, as Metal's documentation gives it (the M3 answers nil),
and a small buffer counts its own pages, not a shared 128 KiB block.
The arm64 queue holds its sets in a counted set and the command buffer holds
the sets it uses, and those its render and compute encoders are given, until
it completes, as Metal's do; a nil set raises the counted set's exception
there, as on the M3, so useInternalResidencySet: of nil now raises on arm64.
The register lists the set's members, and the old residency entries say they
describe the x86 bundle.
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).
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.
The render encoder now answers setPrimitiveRestartEnabled:index: and
setProvokingVertexMode:, as the Intel UHD 630's encoder does. The AMD Radeon
Pro 5300M's answers neither (respondsToSelector:, macOS 26.7.1). What the 630
draws under them, measured with Metal calls of our own:
- setPrimitiveRestartEnabled:YES index:k makes indexed line and triangle
strips after it restart at k alone, 16- and 32-bit, and draw the all-ones
index as a vertex. NO makes them restart at their index type's all-ones index
again, as without a call, whatever k is.
- setProvokingVertexMode: 1 takes flat inputs from a primitive's last vertex
(strip triangle i's vertex i + 2), and 0 from its first.
The wire and the host carry both already. The host draws the index a restart
op carries whether it is enabled or not, so a call that is not enabled posts
the all-ones index (0xffffffff, which a 16-bit strip takes as 0xffff), and only
after an enabled call in the same encoder. An enabled call posts its index once
while it stays. A parallel pass sets both back to their defaults between its
sub-encoders. The register lists both members as implemented.
What the guest sees: the GL renderer no longer writes
"setPrimitiveRestartEnabled:index: unsupported!". It sends the setter before
its draws, never enabled whatever GL's restart state (traced on the 630), and
restarts GL's strips itself, so on our device the setter posts nothing and
every GL draw stays as it was. The renderer still writes
"setProvokingVertexMode: unsupported!" and never sends that setter, on our
device as on the 630, whose encoder answers it. So a flat-shaded line under
GL's default convention keeps its first vertex's colour, as through the same
renderer on the 630.
The guest's frameworks send Metal's SPI members to the objects they are given
without asking respondsToSelector: first, so each member the AMD 5300M's and
the Intel 630's objects both answer is now answered by the bundle's classes of
that kind, as Metal's own base classes answer it (read from code, macOS 27.0.1
on the M3 Max) and as a fresh object of both x86 Macs answers those that take
no argument (measured on macOS 26.7.1, tools/oracle/oracle_spi_members.m):
- textures, samplers and depth-stencil states: the handle and resource index
Metal's base derives from gpuResourceID; a depth-stencil state's index and
identifier raise, as Metal's base does;
- heaps, events, shared events, buffers and argument encoders: the memory
pool, the base heap's description and its raising backing members, the
event's barrier flag and rollback answer, the buffer's Neural Engine surface,
and no layout object (logged);
- libraries and functions: identifiers, triples, validation, file and line
answers from Metal's own shadow function, relocations, and functionHandle,
at which every x86 Mac's function ends the process;
- functions of GL IR: what Metal's function of GL IR answers on the Intel 630
(tools/gl_probe.m -s), its IR as its bitcode and a hash of it;
- compute and render pipelines: resource index, handle, telemetry IDs, no
debug instrumentation or global constants, function tables through the
device, and no mesh shader emulation;
- binary archives: Metal's archive's description, and none of its function
IDs, pipeline collections or recompiles (logged).
The members the oracle's protocols lacked were asked by name
(oracle_spi_members ask), and those neither Mac answers stay absent. The
register lists each member with how it is answered.
c13-wire-gaps' test_argument_encoders_of_bindings posts tests/air_arguments.metal
built for macOS 26 on a control ring of 512 KiB, of which a message takes at
most half (RgfxRingWriter::fits). c13-answers' function constants (d6c38832d,
cbcf338bb) grew that source, and the library built from it to 280056 bytes,
past 256 KiB: it was not posted, and the test's library was nil
(protocol_tests.mm:2155). The test's ring is 1 MiB now. The bundle is
unchanged.
The test of newArgumentEncoderWithBufferBinding: (50fc793f5) took its
bindings from the library's reflection, Metal's own, which answers none for
tests/air_arguments.metal built for macOS 14, so it failed at its first check.
It now takes them from Metal's own pipeline reflection: a binding the device
did not answer is laid out from descriptors, the same binding noted as the
function's is the function's encoder, and a plain buffer's has none. The
library's reflection is checked over the same source built for macOS 26
(RGFX_AIR_REFLECTED), against Metal's own answer, and the test says how many
bindings Metal reflects there.
Car 13's stack: resolved guest/bundle/Makefile's test prerequisites against
c13-answers' AIR_OLD_LIB: the test target needs both AIR_OLD_LIB and this
commit's AIR_REFLECTED.
copyIOSurfaceSharedTextureProperties:, which SkyLight calls, answered nil and
logged. Both x86 Macs (AMD 5300M and Intel 630, macOS 26.7.1, oracle_bundle
iosurf.props and props2) answer a mutable dictionary of IOSurfaceAllocSize and
keys of their own drivers', for every shape tried: AMD's size its GPU's
layout's, Intel's the texture's linear rows.
The guest's device now answers a mutable dictionary of IOSurfaceAllocSize
alone: the texture's linear rows of blocks, each at the host's linear texture
alignment, through every level, slice, sample and depth image, which a
surface's rows meet for the device to use its pages in place. A 64 x 64 BGRA8
texture and an array of two take what both x86 Macs answer (16384 and 32768).
nil for no descriptor, or one no texture has.
newArgumentEncoderWithBufferIndex: asked the host's layout at every index. Both
x86 Macs (AMD 5300M and Intel 630, macOS 26.7.1, oracle_bundle argbuf.index.1
and .5) make an encoder of no arguments, 0 bytes long, at a plain buffer's
index, and end the process at an index of no buffer, with "bufferIndex N does
not identify an argument buffer".
The guest's function now reads its AIR arguments for the index: a plain
buffer answers an encoder of no arguments (length 0, alignment 1, the AMD
5300M's) with nothing sent to the host; no buffer ends the process with
Metal's words; an argument buffer, or a function whose AIR was not read or
whose buffer index is a function constant's, asks the host as before.
An argument encoder's setDepthStencilState:atIndex: wrote nothing for nil and
raised at a state's gpuResourceID. The encoders of both x86 Macs (AMD 5300M
and Intel 630, macOS 26.7.1, oracle_bundle argbuf.ds.tex, .texnil and .nil)
raise an unrecognized selector of their own for every state, nil among them,
though they answer that they respond, and so does the guest's now, writing
nothing. setDepthStencilStates:withRange: raises at its first state.
The pipeline-state test still read the state's gpuResourceID as a logged 0,
which 836a89937 made raise; it now checks the raise, unlogged.
Guest-visible: newArgumentEncoderWithBufferBinding: now answers the encoder of
the argument buffer the binding describes, where the bundle answered nil and
logged, and newArgumentEncoderWithBufferIndex:reflection: answers the buffer's
reflection, where it answered nil and logged. Both x86 Macs make both (the AMD
5300M and the Intel 630 under macOS 26.7.1: oracle_bundle argbuf.binding.lib,
argbuf.reflection).
A binding the device answered, of its library's reflection of a function
(Metal's own over the same bytes), makes the function's own encoder of that
buffer, as both x86 Macs answer the same encoder for the two. Another binding
is laid out from descriptors of its struct's members, as Metal lays one out from
the binding's type; a plain buffer's binding has none, as the AMD answers. The
reflection is that binding of the library's reflection, an
MTLBufferBindingInternal as Metal's; its arrays' strides are an element's size
there, where the x86 Macs' encoder reflection answers 0.
Guest-visible: a depth/stencil state's gpuResourceID now raises an unrecognized
selector (NSInvalidArgumentException), which ends the process where nothing
catches it, and so does setDepthStencilState:atIndex: of a state on an argument
encoder, before it writes anything. The bundle answered 0 and logged, and the
encoder kept the argument's bytes and logged.
No x86 Mac holds a depth/stencil state in an argument buffer. Both the AMD
5300M's and the Intel 630's states answer respondsToSelector: YES for
gpuResourceID and raise so (macOS 26.7.1: oracle_bundle argbuf.ds.id); the
Intel's encoder raises there at a set (argbuf.ds.set, .mixed), and the AMD's
ends the process earlier, asserting at an encoder that holds one
(argbuf.ds.encoder). Setting nil still writes nothing.
fillRenderPass drops a pass's supportColorAttachmentMapping (macOS 26). With
it and no map, the M3 Max under macOS 27 draws each output into the
attachment of its index, and the AMD 5300M and Intel 630 under macOS 26.7.1
draw no colour at all (measured); Metal's docs say neither. The lane takes
the M3's, which costs nothing: the device answers no Apple family, and a map
the encoder is given is logged and dropped. The function's comment now says
so, and a test checks such a pass travels as the same pass without it.
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.
newIndirectCommandBufferWithDescriptor: answered nil, so WebKit's render
bundles and every Metal app using ICBs failed on the device. Where the feature
word holds INDIRECT_COMMAND_BUFFERS the bundle now makes one on the host
(ICB_CREATE, answered with its gpuResourceID), and each CPU encode on its
commands is a record the serialiser keeps and posts as ICB_WRITE before the
process's next command buffer, before a destroy that a record may name, and
when a message would pass the control ring's largest.
The answers follow the Macs measured with oracle_icb (AMD 5300M, Intel 630,
M3 Max), taking the cheapest where they differ: a nil command past the size
or of the other kind, a new command object per lookup, the macOS 26 render
states raising unrecognized selector, mesh setters logged no-ops, render
barriers sent on, ranges clamped to the size, 64 bytes a command in whole
pages, and a Memoryless buffer ending the process as on all three. An
argument buffer holds the buffer's gpuResourceID, and the device's GFX and CMP
ICB queries answer YES with the feature.
The bundle's asynchronous creators (pipelines, libraries, functions, and the
unsupported ones that only refuse) compiled and called their completion
handler on the caller's thread before returning. Every Mac measured returns
first and calls the handler on another thread. The M3 Max (macOS 27.0.1)
returns in about a millisecond and calls the handler about 0.2 ms later on
the global default-QoS queue. The Radeon Pro 5300M and the UHD 630 (macOS
26.7.1) call theirs about 60 ms later on a serial queue of the device's.
A guest handler that ran a block synchronously on the caller's own serial
queue deadlocked under ours, or tripped libdispatch's check and ended the
process.
For the guest, each creator now copies its descriptor and handler and
returns at once. The create and the handler then run on the global
concurrent queue of default QoS, as on the M3 Max, in an autorelease pool
of their own. Handlers of separate creates no longer run in the order of
the calls.
A command buffer the host failed came back as an NSError with its code and no
userInfo, so the guest read "The operation couldn't be completed.
(MTLCommandBufferErrorDomain error 9.)" where Metal says "Invalid Resource
(00000009:kIOGPUCommandBufferCallbackErrorInvalidResource)". RenderBox and
the other frameworks log the description, so the guest's logs named no cause.
What the guest sees now: a command buffer failed with Internal, Timeout,
PageFault, AccessRevoked, OutOfMemory or InvalidResource carries Metal's own
description of it, as the M3 Max gives it (macOS 27.0.1), and an
InvalidResource one also carries the IOGPUCommandQueueErrorDomain error 9
Metal puts under it. A code with no measured description keeps its code
alone. A buffer whose inline bytes found no room fails with Metal's
OutOfMemory description, the cause now in an RGFX log line.
QuartzCore and SkyLight send setLineWidth:. The bundle logged every width but 1
and sent nothing, so the host drew each line 1 pixel wide where Metal draws it
wider. The bundle now posts the width in the SET_LINE_WIDTH op, which the wire
and the decoder already carried, and the Metal platform sends it to the host
encoder's own setLineWidth:.
Measured black-box on the M3 Max at macOS 27.0.1, Metal truncates the width to
1/16 of a pixel and clamps it to [0, 16]. At 1 it draws its ordinary
diamond-exit lines. At any other width each segment is a band that wide along
the line's minor axis, and Metal draws the pixels whose centres the band holds:
nothing at 0.5 along a pixel edge, 4 rows at 3.5, and only the centres on the
line at 0. A Metal-platform test draws a line list and a strip at 0, 0.5, 1, 2,
3.5 and 8 through the platform's encoder, and matches Metal's own pixels
exactly.
The Vulkan platform still draws such lines 1 pixel wide and relays
inexact-line-width, since metal2vulkan's encoder refuses any width but 1.
The full shell suite ended under ASan and TSan at main's last autorelease
pool: the protocol tests keep their serialiser and rings on the stack, and
the objects they let go (the queue's factory reference, command buffers that
hold the queue, samplers) were autoreleased into main's pool, so each dealloc
posted its destroy through a serialiser whose frame was gone. Without a
sanitizer the dead stack happened to still hold a working mutex.
Each test that keeps its transport on the stack now drains its own pool
while the transport lives, and QueueFixture drains the queue factory's
reference in its constructor, so the fixture's own reference is the queue's
last and goes before the serialiser. The device never frees its serialiser,
so the bundle itself has no such lifetime. The whole shell suite now
completes under ASan and TSan, with no reports.
Core Image and MPS set function tables in argument buffers through
setVisibleFunctionTable:atBufferIndex:, setVisibleFunctionTables:
withBufferRange: and their intersection-table twins, which Metal's argument
encoder answers beside the public atIndex: and withRange: names, writing the
same bytes (measured: macOS 27, M3 Max). The device's encoder now answers
them through its atIndex: and withRange: setters.
Core Image, MPS and SkyLight send a pipeline state uniqueIdentifier,
gpuAddress, and a render pipeline requiredThreadsPerThreadgroup and
staticThreadgroupMemoryLength, which the device's pipelines did not answer.
Metal's pipelines answer 0 for the address, those that support indirect
command buffers too, an identifier unique and stable per object (an address
inside it), and {0, 0, 0} and 0 for the two members on a vertex and fragment
pipeline (measured: macOS 27, M3 Max). Ours answer the same, with the
object's address for its identifier.
SkyLight, QuartzCore, Core Image and MPS send our device, command queues,
command buffers and encoders members beyond the public protocols. Encoders
raise on those (the WindowServer abort was one of them); the device answers
zero. Each now answers what Metal's does, measured on the M3 Max (macOS 27).
- Device:
- supportsSampleCount: as supportsTextureSampleCount:;
- metalAssertionsEnabled, settable;
- Metal's resource patching kinds and sparse tile sizes; reserving
resource indices writes nothing, as Metal's does;
- newBufferWithDescriptor: from the descriptor's length, options and
contents;
- the shorter indirect-command-buffer and tile-pipeline creates, as the
public ones;
- nil, logged, where Metal answers nil or an object of its driver's own:
indirect encoders, visible function tables, resource groups, texture
layouts, shader sample buffers. Also IOSurface buffers and IOSurface
texture properties, which need a layout this device does not have.
- Queue: no perf samples, requestCounters:withIndex: -1, statistics
settings taken.
- Command buffer: userDictionary; encodeSignalEvent:value:agentMask: as
encodeSignalEvent:value:, for every mask; validate; statistics.
- Render encoder: setFragmentTexture:...samplerState: as the two sets.
setLineWidth: takes 1 and logs any other width: Metal widens lines, and
no width is on the wire yet. Region tile dispatches are refused.
- Render and compute encoders: residency sets.
- Compute encoder: GPU-side while loops are refused; encodeEndWhile NO, as
Metal's with no loop open.
Enabling statistics is logged, as nothing gathers them.
The first WindowServer of a boot with the kext loaded aborts at 2 s:
MPSImage, under SkyLight, sends globalTraceObjectID to our compute encoder,
which does not answer it. MPS, CoreImage and the rest of SkyLight send
the same member to the other kinds, and commandBuffer to every encoder.
Metal answers globalTraceObjectID (measured on the M3 Max, macOS 27) on:
- the device, command queues and command buffers;
- every encoder, a parallel pass's sub-encoders too;
- heaps and shared events.
Each id is a 64-bit value, unique and stable, taken in creation order from
one counter those kinds share. Ours now answer the same way: each object
takes its id from one counter as it is made. The device keeps its base
class's answer. Every encoder also answers the command buffer that made
it. A parallel pass's sub-encoder answers the pass's buffer, where Metal's
answers an internal buffer of its own on the same queue.
Every class of the bundle now logs a selector it does not answer, once
per class and selector, and then raises as before, so the next boot shows
every remaining miss, not only the first. The device answers zero as
before, and logs its misses the same way. The rest of the selector sweep
(~/.cache notes, selector-sweep.md) follows in later commits.
Apple2's rows need programmable sample positions, and the bundle dropped them:
a pass's setSamplePositions:count: never left the guest, and
setDepthStoreActionOptions: was a logged no-op. The device answers
areProgrammableSamplePositionsSupported from the host, so apps that asked got
the default positions with no sign of it.
A pass's positions now travel after its colour records
(RGFX_PASS_FLAG_SAMPLE_POSITIONS, RgfxRenderPassSamplePositions), and the host
sets them on its pass; RENDER_SET_DEPTH_STORE_ACTION_OPTIONS (0x104f) carries
the encoder's options to Metal, and to the Vulkan platform as late options over
a store action left Unknown, as the stencil and colour ones go.
Metal ends the process at positions it does not take (measured on the M3 Max,
macOS 27): its descriptor's setter at a count other than 2, 4 or 8 or a
coordinate outside [0, 1), its pass validation at a count the device makes no
texture of (8 there), whatever the attachments' sample count. The guest's
descriptor stops the first; the bundle answers no encoder for the second; and
the host faults a pass that holds either, so no guest bytes reach the abort.
SamplePositions joins WIRED with its cap test: Apple2 now waits only on Metal
IO queues.
An argument buffer holds a sampler as its gpuResourceID, and the guest's
samplers answered 0, so a sampler written by an argument encoder named
none. ArgumentEncoders could not join the wired pieces without it.
The guest does not pick the id, as it does for textures. On the M3 Max,
macOS 27, Metal's plain sampler ids do not skip one placed with
setResourceIndex: (placed at 6, the next plain ones were 5, 6, 7), equal
descriptors are one sampler whatever index each asks for (100 and 101
both answered 100), and an index past Metal's pool writes out of bounds
(16383 and 65536 died, 65535 did not). Guest-picked ids would then meet
the ids the host numbers its own samplers and its pipelines' constexpr
samplers by.
So SAMPLER_CREATE is now answered: the host makes the sampler, numbered
by its device, and answers SAMPLER_STATE (0x404) with its status and
gpuResourceID on the control completion ring, which the kext's submit
waits for as for a pipeline's reflection. The bundle asks it through the
serializer's asker, its sampler answers the id and the encoder writes it,
and a create refused or not answered is nil, as Metal answers a sampler
it cannot make. Equal descriptors keep Metal's one sampler and one id,
as the Vulkan platform's do too.
With samplers carried, argument encoders are wired: ArgumentEncoders
joins WIRED, and the cap test checks Apple2 stands once Apple2's last two
pieces are carried as well.
The bundle's argument encoders were stubs: newArgumentEncoderWithArguments:
and a function's newArgumentEncoderWithBufferIndex: answered nil, so no
app or framework could fill an argument buffer.
Each now asks the host for the layout (ARGUMENT_LAYOUT) through the
serializer's asker, the kext's submit that waits for the answer, into a
page of the region it gives back once the answer is read, and asks once
more into a block of the size the host needs where the layout outgrows the
first. The encoder parses the layout into a tree, checked whole, and writes
each argument's word where Metal's encoder writes it: in the last member
holding the index, at its element, through struct elements, and at the
arguments' offset 0 for an index no argument has. A buffer writes its GPU
address plus the offset, a texture or pipeline its resource id, nil 0. A
nested argument buffer's encoder takes its layout from the same answer.
What the wire does not carry logs its first use: a sampler's resource id
(its word is 0), a depth/stencil state's (the bytes stay), and the
argument's reflection. Indirect command buffers, acceleration structures
and function tables take only nil, which writes 0, since the device makes
none. A setter with no argument buffer set, where Metal's process ends,
writes nothing and logs it.
An Automatic heap's newBufferWithLength:options: and
newTextureWithDescriptor: answered nil, and usedSize and
maxAvailableSizeWithAlignment: answered 0 and the heap's size. The heap now
places each resource itself, as Metal's Automatic heap does on an M3 Max
under macOS 27 (RgfxHeapRanges.hpp): at the lowest free offset at its
alignment, a buffer taking its length at the device's heap buffer
alignment and a texture the size heapTextureSizeAndAlignWithDescriptor:
answers, now the host device's (HEAP_TEXTURE_SIZE_AND_ALIGN) and the bound
only where none came back. Each goes to the host as a placement at that
offset in the Placement heap the host made; its heapOffset answers 0, as
Metal's does. Its bytes go back when it is made aliasable, at once, or else
once its destroy has gone, and usedSize and maxAvailableSizeWithAlignment:
answer from the placements, 0 for a Placement heap as Metal answers. A
heap's size is the descriptor's rounded up to the 16 KiB page, as Metal's
and the host's are, and a heap texture answers its placed size as its
allocatedSize.
The lane now carries Automatic heaps, so the piece joins WIRED.
barrierAfterQueueStages:beforeStages: did nothing. Metal's waits for the
work of every encoder before it on the queue, so a dropped one let an
encoder race the earlier work it depends on. That holds for any resource
Metal does not track: heaps' by default, and untracked ones.
The wire has no barrier op, but it has fences, and a fence orders encoders
of one queue across command buffers. So each queue now makes eight barrier
fences with itself.
- Every encoder takes the next fence in turn and updates it at its end
(render passes after every stage).
- An encoder that takes a fence an earlier encoder took first waits for
that encoder, eight back. That ordering is mild, and it makes each fence's
last update cover every earlier encoder that used the fence.
- A barrier then waits for the other seven, once per encoder, which covers
every encoder made before it, whatever stages it names. That
over-synchronises, as Metal allows.
- A parallel pass takes one fence for all its sub-encoders.
The host sees one fence update per encoder, one wait on a long-done fence
per encoder from the ninth on, and eight fences per queue. The order is
the order the encoders were made in. That is the queue's order wherever
its command buffers are committed in the order they were encoded.
MTLBuffer's texture factory had no answer, so a call to it ended the
process. It now makes a texture over the buffer's bytes from the offset,
with rows bytesPerRow apart. It uses the texture-over-buffer create the
IOAccel surface path already sends, so the host makes the same linear
texture Metal makes. The texture keeps the buffer, and answers its
buffer, bufferOffset and bufferBytesPerRow.
heapBufferSizeAndAlignWithLength:options: and
heapTextureSizeAndAlignWithDescriptor: had no answer of ours. The IOGPU base
has none either, so they reached the device's catch-all, which answers
MTLSizeAndAlign as one zeroed register, and a heap sized by that held
nothing.
- A heap buffer answers its length at the host's alignment for a page
(the device info's heap_buffer_page_private). Metal answers the length
at 256 for every length and options, and so does metal2vulkan. This is
measured on the M3 Max for lengths up to 3 MiB in every storage and
cache mode.
- A heap texture's size depends on the host GPU's layout, and no query on
the wire carries it yet. So the device answers a bound: blocks rounded
to 16 KiB tiles, plus an eighth, at 16 KiB. It holds Metal's answer for
all 806 descriptors measured on the M3 Max (1.06 to 640 times, about 1.1
times for a texture of a few MiB) and logs that it is a bound.
- sampleTimestamps:gpuTimestamp: answers mach_absolute_time() for both.
No counter sample buffer or counter heap stamps the GPU's domain, and
queryTimestampFrequency answers that domain's rate.
- The sizes of acceleration structures, tensors and counter heap entries
are 0, logged: the device makes none of them.
- newCommandQueueWithDescriptor: makes a queue of the descriptor's
command buffer count.
set*Bytes: with no upload chunk to hold the bytes (the region has no room)
made no binding, and the command buffer then completed as if it had run
right: the GPU read whatever was bound there before, with no error.
The command buffer now completes with MTLCommandBufferErrorOutOfMemory, as
Metal's does when memory runs out, so the app sees that its work did not
run as encoded. The host still runs it, so its events, fences and order
are those of the rest of the queue.
The argument encoder had no-op setters and placeholder lengths, a silent
answer to work that needs an argument-buffer layout the wire does not
carry. Each of its members now logs its first use as unsupported (a nil or
empty argument still does nothing, as on Metal), and encodedLength is 0,
so a caller sees that nothing is laid out.
A library's intersection functions answer nil with Metal's own
MTLLibraryErrorUnsupported, through both forms, and its function
reflection is nil, logged. A function's argument encoder logs the same way.
A shared event's waitUntilSignaledValue:timeoutMS: waits on the mirror:
it returns as soon as the host's EVENT_SIGNALLED or the CPU's set reaches
the value, NO once the timeout passes, and takes the reply off a reader no
thread drives meanwhile.
The rest of MTLComputePipelineState, MTLRenderPipelineState and
MTLDepthStencilState was unanswered.
- What the create asked, the state answers: supportIndirectCommandBuffers
(the host's reflection flag once it arrives), and a compute pipeline's
requiredThreadsPerThreadgroup and forwardProgressUsage where the guest's
descriptor has them.
- shaderValidation is Disabled, since the device validates no shader.
reflection is nil, Metal's answer for any pipeline a device rather than
a Metal 4 compiler makes.
- A vertex/fragment pipeline answers 0 for the mesh, object and tile
stages' sizes and widths, as Metal's does. The device makes no mesh or
tile pipeline.
- allocatedSize, imageblockMemoryLengthForDimensions: and
recommendedPersistentThreadgroupsPerGrid... need host answers that
RgfxPipelineReflection does not carry. They answer 0, logged.
- Function handles, binary-function pipelines, function tables and
newRenderPipelineDescriptorForSpecialization answer nil, with an
unsupported NSError where the member has an error out, logged.
- A depth/stencil state's gpuResourceID is 0, logged. Its create carries
no resource id, and the device supports neither argument buffers nor
ICBs that would read one.
- A buffer answers sparseBufferTier None and remoteStorageBuffer nil, as
Metal's buffer that is not placement-sparse or a remote view does. The
device makes neither kind.
- addDebugMarker:range: and removeAllDebugMarkers change nothing, as
Metal's do when no capture is under way. No capture tool sees this
device's work.
- newRemoteBufferViewForDevice: answers nil, since there is no other
device. newTensorWithDescriptor:offset:error: answers nil with an
unsupported NSError. Both log.
- A heap's allocatedSize is its size, all of it reserved at its create.
- The heap's four newAccelerationStructure... members answer nil (no ray
tracing). The automatic placements newBufferWithLength:options: and
newTextureWithDescriptor:, which already answered nil, now log too.
They need the host's size and alignment, which the wire does not
carry.
The buffer's newTextureWithDescriptor:offset:bytesPerRow: waits for the
texture-over-buffer factory it shares with the IOAccel surface path.
The MTLTexture members other than CPU access, buffer offsets and size, and
the texture-view class (taken elsewhere) were unanswered.
- allowGPUOptimizedContents and compressionType have no field in the
wire's texture descriptor. The texture keeps them from the descriptor it
was made from, and answers Metal's defaults where none was taken.
- A texture that is not sparse, shared or remote answers what Metal's such
texture answers. iosurfacePlane is 0, isShareable is NO, and the sparse
tier is None with no mip tail. rootResource is its parent or its buffer,
and remoteStorageTexture is nil. The device makes none of the other
kinds, so these answers are exact.
- newRemoteTextureViewForDevice: (there is no other device) and
newSharedTextureHandle answer nil, as Metal answers what it cannot make,
and each logs the ask once.
The rest of MTLCommandBuffer and MTLCommandQueue, apart from the command
buffer's timing, error options and logs (taken elsewhere), was unanswered.
A call to any of them ended the process.
- The acceleration-structure and resource-state encoders answer nil, as
on a device without ray tracing or sparse textures, and log the ask.
- The device makes no residency sets. useResidencySet(s) on a command
buffer, and add/removeResidencySet(s) on a queue, do nothing. Any
non-nil set is logged.
- insertDebugCaptureBoundary marks nothing, as Metal's does when no
capture is under way. No capture tool sees this device's work.
WindowServer's clients call encoder members the bundle did not implement,
and die on the unrecognized selector. The worst is the set*Bytes family,
which CoreAnimation and RenderBox use for most of their constants.
- set{Vertex,Fragment,Tile}Bytes: and compute setBytes:, with their
attributeStride forms, write into a per-queue pool of upload chunks in
the device region. Each chunk is a Shared buffer the host reads in
place. A command buffer packs each call's bytes at a 256-byte boundary
and binds the chunk at that offset. It gives its chunks back once the
host has completed it. A chunk is created once (one
BUFFER_OVER_HOST_MEMORY) and reused after that, so a call copies its
bytes once and posts nothing on ring 0.
- The render encoder's memoryBarrierWithScope:afterStages:beforeStages:
maps to the existing scope op. memoryBarrierWithResources:... becomes
the scope of the resources' kinds, which covers at least what Metal
covers. textureBarrier becomes the render targets' fragment barrier.
- computeCommandEncoderWithDispatchType: carries the type on the pass,
and the encoder answers dispatchType. The descriptor form goes the same
way.
- copyFromTexture:toTexture: copies as many whole surfaces as Metal
computes over the existing slice copy.
- tileWidth/tileHeight answer the pass descriptor's tile size.
- The members whose features the device does not support do nothing on
the wire: function tables, acceleration structures, mesh and object
stages, counters, tensors, queue-stage barriers, depth bounds, colour
attachment maps, and depth store-action options. A nil or default
argument is exact. Any other use is logged once through RgfxUnsupported,
which marks each such member RGFX_UNSUPPORTED in the source. A device
tile size not named by the pass descriptor is not on the wire either:
it answers 0, logged.
The new tests/protocol_tests.mm, built into shell_tests, reads back the
ops and the region bytes of each member.