Commit Graph
32 Commits
Author SHA1 Message Date
Anees Iqbal 6691ea5f93 🎨 Fix car 13's stack: give the binding encoders' test a ring for its library
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.
2026-11-05 21:59:34 -08:00
Anees Iqbal 9dfa32fcde ✅ Test binding encoders over Metal's pipeline bindings
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.
2026-11-05 21:59:34 -08:00
Anees Iqbal 7f9ad4db4e 🐛 Answer an IOSurface texture's properties with its linear size
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.
2026-11-05 21:59:34 -08:00
Anees Iqbal efbf359c2b 🐛 Answer a function's encoder at a plain buffer, and end at none
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.
2026-11-05 21:59:34 -08:00
Anees Iqbal 3df1e1a03c 🐛 Raise at every depth/stencil state an argument encoder is set
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.
2026-11-05 21:59:34 -08:00
Anees Iqbal 0ca3f8563a 🐛 Make encoders of buffer bindings and answer an encoder's reflection
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.
2026-11-05 21:59:34 -08:00
Anees Iqbal 323c0b1eec 🐛 Raise at a depth/stencil state's resource id, as x86 Metal does
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.
2026-11-05 21:59:34 -08:00
Anees Iqbal a0defae31e ✅ Pin that a pass's colour attachment mapping is not carried
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.
2026-11-05 21:59:30 -08:00
Anees Iqbal c5f49a295f 🆕 Send a render pass's visibility result buffer from the bundle
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.
2026-11-05 21:59:26 -08:00
Anees Iqbal 509abb3090 🆕 Make indirect command buffers in the bundle
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.
2026-11-05 21:59:25 -08:00
Anees Iqbal d2dd87dd2b 🐛 Run the async creators' handlers after the creator returns
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.
2026-11-05 21:59:20 -08:00
Anees Iqbal 934685aeac 🐛 Give a failed command buffer the error Metal gives
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.
2026-11-05 21:59:19 -08:00
Anees Iqbal ccd2c8c787 🆕 Draw lines as wide as setLineWidth: sets, as Metal does
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.
2026-11-05 21:58:33 -08:00
Anees Iqbal b271b18f50 ✅ Drain protocol tests' objects while their transport lives
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.
2026-11-05 21:58:33 -08:00
Anees Iqbal 88d3842f5c 🐛 Answer the encoder's buffer-index table setters as Metal's
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.
2026-11-05 21:58:33 -08:00
Anees Iqbal de3b3ad0e1 🐛 Answer pipelines' GPU address and identifier as Metal does
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.
2026-11-05 21:58:33 -08:00
Anees Iqbal f6b2dbd7fb 🐛 Answer what frameworks send the device, queues and encoders
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.
2026-11-05 21:58:33 -08:00
Anees Iqbal 52c1d16f8b 🐛 Answer trace ids and encoders' command buffers as Metal does
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.
2026-11-05 21:58:32 -08:00
Anees Iqbal 75daf32d69 🆕 Carry a pass's programmable sample positions
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.
2026-11-05 21:58:32 -08:00
Anees Iqbal be3c3c04c5 🆕 Answer a sampler's resource id from the host, and wire encoders
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.
2026-11-05 21:58:32 -08:00
Anees Iqbal 516a241e09 🆕 Write argument buffers by the host's layout in the guest's encoders
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.
2026-11-05 21:58:32 -08:00
Anees Iqbal 5b45fdb5e8 🆕 Place an Automatic heap's resources as Metal does
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.
2026-11-05 21:58:32 -08:00
Anees Iqbal 6c34ff89b7 🐛 Order a queue barrier after every earlier encoder of the queue
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.
2026-11-05 21:58:31 -08:00
Anees Iqbal 6e687fdc1e 🆕 Answer a buffer's newTextureWithDescriptor:offset:bytesPerRow:
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.
2026-11-05 21:58:31 -08:00
Anees Iqbal e9e015974b 🆕 Answer the device's heap sizes, timestamps and queue descriptor
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.
2026-11-05 21:58:31 -08:00
Anees Iqbal 5f222ca416 🐛 Fail a command buffer whose inline bytes found no room
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.
2026-11-05 21:58:31 -08:00
Anees Iqbal d85832db83 🆕 Answer the library, argument encoder and shared event members
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.
2026-11-05 21:58:31 -08:00
Anees Iqbal aac5a0af88 🆕 Answer the pipeline and depth/stencil state members of Metal
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.
2026-11-05 21:58:31 -08:00
Anees Iqbal 6686a596cb 🆕 Answer the buffer and heap members of Metal's protocols
- 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.
2026-11-05 21:58:31 -08:00
Anees Iqbal da30dd759b 🆕 Answer the texture members of Metal's protocols
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.
2026-11-05 21:58:31 -08:00
Anees Iqbal 112a0a27fc 🆕 Answer the command buffer and queue members of Metal's protocols
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.
2026-11-05 21:58:31 -08:00
Anees Iqbal b368f98f81 🆕 Answer every command encoder member of Metal's public protocols
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.
2026-11-05 21:58:31 -08:00