WindowServer drives the display pipe in the transactional model while
kIOWindowServerActiveAttribute carries kIOWSAA_Transactional ('wsrv'
0x80000013 at its start, then 0x11). When its session restarts it hands the
display back to the CPU ('wsrv' 0x2) and submits the shutdown's frames, each
with cookie 0 at +0x100, waiting on each with selector 9 before it exits. The
kext notified every completion. On a macOS 26 guest, WindowServer aborted in
IOAccelerator's _ioAccelDisplayPipeTransactionNotifyCallback about 5 ms after
the kext sent the notification of the first cookie-less transaction, and the
session's next WindowServer started over it.
The cookie is the transaction's own sign that a notification is wanted. The
pipe now notifies a completion only where its transaction carries a cookie;
every transaction still completes for its waiters and for the display. The
bookkeeping moves into RgfxPipeTransactions.hpp, with a native test that
replays the hand-over's order.
Measured on a cold boot of the x86 guest with the same rule keyed to 'wsrv'
instead of the cookie, which notifies the same transactions on every one
measured: 4469 transactions over three hand-overs (a reboot, a logout and a
loginwindow death). All 4461 submitted in the model carried a cookie and were
notified; each hand-over's 4 shutdown frames carried none and were not. Each
WindowServer then exits with exit(0) and no crash report, every wait returns
(26 ms at most), and the next WindowServer enters the model and composites
with Metal.
A texture create over a buffer (TEXTURE_FROM_BUFFER,
LINEAR_TEXTURE_FROM_BUFFER, TEXTURE_FROM_IOSURFACE) that the platform makes
no texture of was logged only as "was not carried out: Refused". The
platform's nil names no reason, as Metal's does, so nothing recorded what
the guest asked for. On the x86-64 guest with the tiled-texture fix,
WindowServer's IOSurface textures were refused that way at login, and every
later command buffer naming them faulted, with no record of their
descriptors.
The decoder now warns with every argument of the create: the descriptor's
format, type, size, levels, array length, samples, usage, resource options
and swizzle, the offset and bytes a row, the buffer and its length, a
linear texture's bytes an image and an IOSurface texture's surface and
plane. With these, the runtime's rules decide which refusal it was. Nothing
changes for the guest or the host: the line is a diagnostic.
With the display on the accelerated model, the first WindowServer's first
Metal composite builds a MetalTiledBacking for the display's backing and
calls newTiledTextureWithDescriptor:offset:bytesPerRow: on its buffer. The
bundle answered no such selector, and WindowServer died raising it (pm14 with
"ReimsGraphicsAMD", pm16 with "ReimsGraphicsIntel": the vendor does not
decide the call). Its arguments (pm15): a 2D BGRA8Unorm descriptor of
1024 x 1024, usage ShaderRead | RenderTarget, storage Managed, at offset 0
with a pitch of 15360 bytes, on a Shared buffer of 36864000 bytes, the
3840 x 2400 display's backing: one tile of it at the backing's pitch.
The buffer now makes a texture over its bytes from the offset, rows
bytesPerRow apart, as newTextureWithDescriptor:offset:bytesPerRow: does,
with the buffer's storage. Measured on the M3 Max under macOS 27.0.1: Metal's
validation layer's buffer (MTLDebugBuffer, type `@40@0:8@16Q24Q32`) answers
the selector and asserts that the descriptor is Managed, the buffer Shared
and offset + bytesPerRow x (height - 1) + a row's bytes within the buffer,
with no alignment of offset or pitch; the M3's own buffers answer no such
selector. Those three rules answer nil here, logged. What a Managed-storage
GPU's driver answers is not measured, as no such GPU is on hand.
Measured on a cold boot of the x86 guest on the effort tip's host (pm17): the
first WindowServer builds its tiled backing, renders through it twice, tears
it down, and stays up through the login to the desktop, compositing with
CompositorMetal at 23-49 frames a second; nothing on the tiled path is
refused or unrecognized.
metal2vulkan 4ba981e668, now pinned, links a function Metal's stitcher made
like any other. Nothing checked that a guest's stitched library gets Metal's
answers on the Vulkan platform. The Metal-host test can't run on Linux: only
Metal's stitcher makes a stitched library, and Linux has no Metal.
So the Vulkan crate's build makes the bytes on a Mac, as it compiles the
other metallibs a build off a Mac copies:
- stitchable.metallib: the shell tests' stitchable.metal.
- stitched.metallib: the library Metal's stitcher makes of its graph `fused`
over those functions, as the bytes Metal answers for it. src/gpu/stitch.m
stitches on the CPU, on the Mac's default device. These are the bytes the
guest's route sends.
Both are recorded in metallibs.toml by the hash of their sources and
commands, so a stale one fails the build off a Mac and the Mac's freshness
test, as the others do. The other metallibs are unchanged. This Mac's Xcode
writes different bytes for them, so they were left as committed; their
record is unchanged too.
The new test drives the committed bytes through the decoder on the Vulkan
platform, and asserts Metal's answers. `fused` linked in the linked
functions, or in the private functions, makes a pipeline that writes 20 of
(2, 3, 4); with nothing linked, the create is refused. The Metal-host test
now also runs the committed bytes on Metal, tying them to Metal's own
answers there. The one signature the runtime still refuses, a
linked-constants signature on a module that still declares function
constants, is not this library's.
Nothing changes for the guest or the host; this is a test.
CoreDisplay finds the display's GPU vendor from the framebuffer's class name,
as IOObjectCopyClass answers it (GetGPUVendorForFramebufferService): it
searches the name, ignoring case, for the vendor names it knows, among them
"Intel", "AMD" and "NVDA". CoreDisplay::EnableWSAA asks that vendor for
every IOFramebuffer service, and for ours, with "ReimsGraphics" matching
none, it answers false: CoreDisplay never sets kIOWindowServerActiveAttribute,
its display stays on the CPU route, and WindowServer composites with
CompositorSW. On the stock device the name matches, and CoreDisplay moves
the display to the accelerated, transactional model.
IOObjectCopyClass answers the service's IOClassNameOverride property, a
string, in place of its class. The framebuffer now carries
"ReimsGraphicsAMD", which contains "AMD". Only the framebuffer's name is
read: the vendor scan matches IOFramebuffer services.
Measured on a cold boot of the x86 guest with this name: CoreDisplay's vendor
lookup answers 0x4 and EnableWSAA 0x1, the kIOWindowServerActiveAttribute
sequence matches the stock device's, and WindowServer composites with
CompositorMetal at 26-29 frames a second, CompositorSW never. The display pipe
carries IOSurface transactions, which the host presents at about 29 a second
with no long completion waits.
The runtime now links a function Metal's stitcher made as any other visible
function: a linked module's signature is read as the entry module's. A
pipeline that links a stitched library's function, in its functions or its
private functions, is made, where the runtime refused it (Linking), so the
stitched libraries the guest's Metal makes over our functions' shadows
(SkyLight's, Core Image's fused kernels) reach their pipelines on the Vulkan
platform as on Metal.
The guest stitches in its own Metal and sends the stitched library's bytes as
an ordinary library create. The host never sees a stitch. Nothing checked
that those bytes make a library on the host whose function a pipeline links
and runs as Metal's own does.
The test makes on this Mac what the guest's route sends. Metal compiles the
shell tests' stitchable.metal, and Metal's stitcher makes `fused`, (a + b) *
c, from that library's own functions. Both libraries' bytes go to the decoder
as library creates, then three pipeline creates of `stitch_caller`: one with
`fused` in the linked functions, one with it in the private functions, and
one with nothing linked. Their statuses must equal Metal's own creates of the
same pipelines: made, made, refused. What each made pipeline writes of (2, 3,
4) on the platform must equal what Metal's own pipeline writes, 20.
Nothing changes for the guest or the host; this is a test.
The decoder half is generic over the platform. The Vulkan platform's twin is
one call, once the metal2vulkan pin carries its stitched linking. At the
current pin, 37280bc223, a scratch twin on MoltenVK showed the Vulkan
platform refusing all three creates. The process did not end, and every
create was answered RGFX_PIPELINE_REFUSED.
Our archive answered addLibraryWithDescriptor: unsupported, and a stitched
create that fails on a binary-archive miss always missed. Metal's archive
keeps stitched libraries, and a create finds one there. Its answers, measured
on the M3 Max (macOS 27):
- addLibraryWithDescriptor: stitches on the archive's device, through
newLibraryWithStitchedDescriptor:destinationBinaryArchive:error:, and the
library is kept in the archive. It answers YES. A graph Metal cannot
stitch answers NO and the stitcher's error ("missing function 'nope'
required by DAG 'bad'"). A descriptor that fails on a miss, and that no
archive holds, answers NO and the miss.
- A create with MTLStitchedLibraryOptionFailOnBinaryArchiveMiss finds the
library where one of its archives holds the same graphs over the same
functions. The functions may come in any order, and from any library over
the same bytes. The options are not part of the key. Another graph name,
swapped arguments or another attribute miss. A miss, with no archive named
or a nil list too, answers nil and MTLLibraryErrorDomain 3 "Failed to find
library in binary archive.", with nothing stitched.
- The archive holds stitched libraries in memory only: none in its keys,
and none written to a file (an archive holding only them answers "Nothing
to serialize").
What changes for the guest:
- addLibraryWithDescriptor: on one of our archives now answers as Metal's.
The stitched library is made, sent to the host as an ordinary library
create, and kept in the archive.
- A stitched create that fails on a miss is now found, where an archive
holds the library.
- The destination form keeps its library in the archive it names, where
that archive is ours.
Metal is still handed no archive and no fail-on-miss option: it would read
our archives as its own. The lookup is ours, before the stitch.
The test runs Metal's own stitch over our functions' shadows, through a
device that stitches as ours does.
Three of Metal's stitched-library entry points still ran the base device's
own code over our functions:
- newLibraryWithStitchedDescriptorSPI:error:, which SkyLight calls,
- newLibraryWithStitchedDescriptor:destinationBinaryArchive:error:, which
the SPI form and Metal's archive call, and
- newLibraryWithDAG:functions:error:, which SkyLight and MPSCore call.
What the guest saw from them: Metal's own _MTLLibrary, or the end of the
process.
- On macOS 27, measured on the M3 Max with our functions, Metal's base path
answers its own _MTLLibrary, whose `fused` is Metal's _MTLFunctionInternal.
Every pipeline create naming it is refused ("is not from a library of this
device").
- Where Metal's path reads a function's library data, as the guest's
macOS 26 path does, a function with no shadow yet ends the process at
-[RgfxFunction libraryData]. That is iconservicesagent's crash loop in the
ledger.
Now all three answer as the public form and its completion-handler form
already did. Metal stitches over the functions' shadows, and the guest gets
our library, made from the bytes Metal answers, as an ordinary library create
on the wire. Its functions are ours, so pipelines can name them and the host
links them. Where Metal refuses, the guest gets Metal's error: its stitcher's
for a descriptor, or its parser's for a DAG ("error while parsing script:
...", MTLLibraryErrorDomain 3).
Unchanged: the public form and its completion-handler form. The processes
that see the change are those calling the three entry points: WindowServer
and the apps that stitch through SkyLight, and MPS users through MPSCore's
DAG. The destination form keeps the library in no archive yet: ours answer
addLibraryWithDescriptor: unsupported until the next commit.
The test drives a DAG through the shadow route on Metal's own device. The
three device methods are thin calls into the helpers the shell tests cover;
the device class itself does not instantiate on the Mac.
CoreDisplay gets kIOWindowServerActiveAttribute ('wsrv') on the framebuffer
as WindowServer brings the display up. Ours answered kIOReturnUnsupported,
IOFramebuffer's default. The stock device answers every get with success
and accepts every set: its CoreDisplay sets 0, then kIOWSAA_To_Accelerated
and kIOWSAA_Accelerated, each with kIOWSAA_Transactional, which
IOGraphicsTypes.h describes as the move to the transactional operation
model.
The framebuffer now keeps the value WindowServer last set, answers it
(kIOWSAA_Unaccelerated before any set), and accepts every set. What the
display shows does not change with it: the scanout, or the surface the
display pipe last presented.
Measured in a macOS 26 guest: each WindowServer's gets now succeed (0), and
CoreDisplay still makes no set. Its framebuffer setup goes on to the display
pipe where the stock one sets the attribute first, and WindowServer still
composites on the CPU: the answer alone does not decide the compositor.
WindowServer's CoreDisplay opens type-0 (IOAccel surface) clients on the
accelerator at display start. We accepted them, and CoreDisplay took its
display surface from them (acquire, access, release and finish, 20 times
each). The stock device refuses every type-0 open with
kIOReturnUnsupported, in its IOGPU base, and its WindowServer makes none of
those calls. The accelerator now refuses type 0 the same way, logged once,
as any other type it does not serve.
Measured in a macOS 26 guest, on a boot with this and the framebuffer's
IOAccelRevision gone: the 13 type-0 opens are refused and no display-surface
call reaches the accelerator; CoreDisplay maps the framebuffer's memory for
its surface instead. WindowServer still composites on the CPU, as before:
the IOAccel surfaces did not decide the compositor.
ReimsGraphics no longer publishes IOAccelRevision; it keeps IOAccelIndex 0
and IOAccelTypes. CoreDisplay reads the key on the framebuffer once as
WindowServer brings the display up (InitializeMPPrivAccelerator). The stock
device's framebuffer does not carry it, and its WindowServer finds nothing
there; ours found 2. The key was published with IOAccelIndex for the display
pipe, which reads only the index.
Measured in a macOS 26 guest, on a boot with this and type-0 clients
refused: the read finds nothing, as on the stock device. The reads after it
(the framebuffer's IOCFPlugInTypes, the accelerator's AccelCaps) and the
type-0 opens at display start come with or without the key, on both stacks,
and WindowServer still composites on the CPU: the key did not decide the
compositor.
The runtime now makes Core Image's kernel libraries (a metallib whose
header's file type is 1, as ci_kernel.metallib is), so the Vulkan platform
makes the libraries Core Image hands it as Metal does, and the test that
expected a refusal now checks that one is made.
It also links functions with specialized names and constant values as Metal
does, and refuses a pipeline of a function made by name whose function
declares constants (Invalid, UnspecializedFunction), where Metal aborts. The
answer layer decides that refusal as a death at every pipeline creator, as
Metal aborts there, where an Invalid refusal at a getter would otherwise be a
raise.
RgfxAccelerator now publishes IOAccelIndex = 0 in the registry before it
registers, the index ReimsGraphics' IOAccelIndex already names it by. As
WindowServer brings its display up, IOPresentment reads IOAccelIndex on
the accelerator while it matches the display to its GPU
(ioPresentmentFindIOServiceMatch, measured in a macOS 26 guest). It found
nothing there before; it now finds 0, the framebuffer's own index, so the
display and the accelerator carry the same index on both sides. The
framebuffer's keys are unchanged.
The compile pool took creates in the order they were handed over, from one
queue every process shares, so a process's burst of pipeline creates added
its whole length to every other process's synchronous create, WindowServer's
among them. With Metal each process compiles its own pipelines, and one
app's burst delays no other's creates.
The pool now keeps each context's compiles in a queue of its own and serves
the contexts in turns: the context that owns the scanout (the one whose
texture the last PRESENT_SURFACE showed) first where it has a compile
waiting, then the context with the fewest compiles running, the one longest
without a turn among equals. A context's own compiles keep their order.
Library makes go before pipeline compiles, so a pipeline waiting on its
thread for another context's library never waits for one no thread holds.
The thread count is unchanged.
Each compile now logs its context, its wait and its compile time at debug
(reims_vgpu::graphics::compile).
Three pool tests pin the order, and each fails on the order compiles were
handed over, as the check of the change: a context's single create behind
another's twenty finishes one compile after the first running one ends
(six compiles under the old order); the scanout owner's compile goes before
the other contexts'; a library make goes before pipeline compiles. The
present test checks that a present favours the texture's context and its
close ends that.
The device answered every selector it does not implement with a zero
scalar, through forwardInvocation:, a forwarder that fakes answers. Every
MTLDeviceSPI member Metal's bring-up sends is now implemented, so the device
logs a selector it does not answer, once, and raises, as every other class
of the bundle does and as Metal's own device does.
WindowServer's first composites still go through SkyLight's software
compositor after the device answers featureProfile. To compare our device
with Metal's on what WindowServer asks as it starts, answers_probe prints
the default device's answer to each of those queries, in WindowServer's
order, and supportsFamily: of every family. On the reims-graphics device it
also prints what an instance answers before it has read the host's
capabilities, which is what the base class's init sees when it asks
during [super initWithAcceleratorPort:].
Fast resource loading (MTLIOCommandQueue and its file handles) was the last
of Apple2's pieces the lane lacked: the device refused every IO creator.
Metal's own IO queue and raw and compressed file handles work over any
device they are given, through its public command queue, shared event and
buffer members. On the M3 Max, Metal's queue over Metal's device loads
buffers, process memory and textures exactly as the device's own queue
does. So the device now makes them over itself, and no wire is needed.
Before opening a file, the device checks its URL as Metal's does:
- a URL that is not a file's is MTLIOErrorDomain 1;
- a missing file is the reachability error, NSCocoaErrorDomain 260.
Every other answer is the handle's own. Where the guest's Metal lacks a
class, its creator is refused as before.
With IO queues in WIRED, the lane now answers Apple1 and Apple2 where the
platform does, with iOS_GPUFamily1 and 2's feature sets. Apple3 still
waits on indirect command buffers. Guests see these family answers
change.
io_probe checks the IO answers against Metal's; it prints IO OK on the
M3 Max.
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.
A command buffer the host could not carry out, one whose draw sets a pipeline
the host refused or that names anything else it does not hold, was answered
failed at its decode: ahead of the buffers committed before it on its queue,
and without the shared event values it signals. A later buffer waiting on the
GPU for one of those values, or a guest thread waiting for one, then waited
for good.
Such a buffer is now stood in for on its queue: a command buffer holding the
buffer's event waits and signals alone, in stream order. Its completion posts
the values signalled, then the buffer's internal-error CB_COMPLETE, so the
failure comes in the queue's order, as a buffer Metal could not run finishes,
and nothing waits on its events for good. Where there is no stand-in (a
message too short to name its queue, a queue the process does not hold, a
context whose work is refused), the failure is posted at once, as before.
Core Image asks a shared event IOSurfaceSharedEvent, and the bundle's shared
event raised on it. Metal's answers the event itself (measured on the M3 Max
under macOS 27: the same object, of its own class), and so does the bundle's
now; a plain event answers no such member, as Metal's does not.
Core Image, QuartzCore, SkyLight and MPS ask a sampler its pixelFormat, MPS its
gpuAddress and Core Image its uniqueIdentifier, and the bundle's sampler raised
on each. They are answered as Metal's sampler answers them, measured on the M3
Max under macOS 27: no GPU address and no pixel format, 0 for both, whatever
the descriptor; and the identifier is the value of its gpuResourceID, so the
samplers of equal descriptors, which the host answers with one id, answer one,
as Metal's one object for them does.
SkyLight, QuartzCore, Core Image and MPS ask a texture the resource SPI's
members, its GPU and CPU addresses, the size of the allocation it lies in, its
identifier, whether it is a drawable's and its rotation, and the bundle's
texture raised on each. They are answered as Metal's texture answers them,
measured on the M3 Max under macOS 27:
- the resource SPI as a buffer answers it (RGFX_RESOURCE_SPI);
- the options as asked, and resolved: a Default hazard tracking mode answers
Tracked, and resourceOptions now says so too;
- a heap's texture lies at the heap's GPU and CPU addresses plus its offset,
in the heap's allocation, of the heap's size and options;
- a texture over a buffer lies in the buffer's memory: its addresses plus the
offset, its allocation, size, options, heap and offset there, and it stays
NonVolatile whatever it is told;
- the textures over one IOSurface plane, and their views, share one allocation
and one GPU address, and have no CPU address;
- a view answers its texture's, at any level and slice;
- the identifier counts the process's textures, views among them, from 1;
- no drawable, rotation 0, and didModifyData does nothing.
Two answers differ from Metal's: a Shared or Managed texture in no heap has
no CPU address, since the device keeps no memory of it the CPU reaches, and a
device-placed texture's GPU address is the one its create reserved, where the
host does not place its memory.
A Shared newBufferWithLength: or newBufferWithBytes: the region had no room for
fell back to a device buffer: memory of the guest's own that the host never sees,
so what the app wrote there never reached the GPU. It now answers nil, as Metal
answers a buffer it cannot place (measured on the M3 Max, macOS 27: nil for a
length past maxBufferLength, in every storage mode).
The same measure answers nil for a length of 0 in every mode, which made a
buffer here, and newBufferWithBytes: answers nil for a NULL pointer, which
Metal's validation refuses and its copy faults at. A Private buffer past
maxBufferLength is nil too, where the host would have refused its create.
The device's buffer makers forward to one factory in RgfxBuffer, which the shell
tests reach.
QuartzCore makes the textures it copies images into with a buffer's
newLinearTextureWithDescriptor:offset:bytesPerRow:bytesPerImage:, which the
bundle sent as the three-argument form and answered nil for a 2D array. The
new LINEAR_TEXTURE_FROM_BUFFER carries the call as the guest made it, bytes
per image included, and the host makes the texture by the platform's own
linear form, which both platforms have.
Metal's linear form, measured on the M3 Max under macOS 27: a 2D texture,
a texture buffer or a 2D array over the buffer's bytes from the offset, rows
bytesPerRow apart, a 2D array's slices bytesPerRow times the height apart
whatever bytesPerImage, sharing the buffer's bytes both ways; nil past the
buffer's end; and its validation ends the process at another type, at more
than one level and at an offset or rows off the format's alignment. The
bundle answers nil, logged, for the types and levels, as it answers a view
Metal ends the process at; the host refuses the rest as its platform does.
MPS's Lanczos scale asks a texture isCompressed, of every format and storage
mode, and the bundle's texture raised on it: WindowServer ends there. It is
answered by the rule Metal's texture follows, measured case by case on the M3
Max under macOS 27: NO for a texture over a buffer or an IOSurface, a
Memoryless one, one that does not allow GPU-optimized contents, one of no
usage or of any of ShaderWrite, PixelFormatView and ShaderAtomic, one under
16 texels wide or high, and one of a block-compressed or 4:2:2 format; YES
for any other, of any storage mode, type, sample or level count. A view
answers its texture's.
SkyLight, MPS, Core Image and QuartzCore send buffers the resource SPI and
members no SDK protocol declares, and the bundle's buffer raised on each.
Each is answered as Metal's buffer answers it on the M3 Max under macOS 27:
- allocationID: the allocation it lies in, its heap's for a heap's buffer;
- doesAliasResource: and its two list forms: YES only where both lie in one
heap over bytes that meet, so a buffer in no heap aliases nothing;
- isComplete, isWriteComplete YES and waitUntilComplete at once;
- isPurgeable: YES once made Volatile or Empty;
- resourceSize: its own size, or its heap's;
- unfilteredResourceOptions: its options as asked, or its heap's;
- virtualAddress: its contents, or its heap's address plus its offset (the
offset itself in a Private heap);
- iosurface: none, as the device makes no buffer over one;
- newLinearTextureWithDescriptor:offset:bytesPerRow:bytesPerImage: as the
three-argument form; a 2D array, whose slices the wire's texture over a
buffer does not space, is nil, logged.
The members go on buffers only, not the base every wrapper shares, as Metal's
samplers and queues do not answer them; textures take the same macro next.
resourceOptions and hazardTrackingMode now resolve a Default hazard tracking
mode to Tracked, as Metal's do, and a heap's buffer answers its heap's
options and stays NonVolatile whatever it is told, as Metal's does.
SkyLight, MPS and Core Image send heaps members no SDK protocol declares, and
the bundle's heap raised on each: WindowServer ends at the first one. Each is
answered as Metal's heap answers it on the M3 Max under macOS 27:
- gpuAddress: the heap's base, where a resource at offset 0 lies;
- newBufferWithDescriptor: an Automatic heap places a buffer of the
descriptor's length as it places one of a length, at the descriptor's
alignment where it is larger, with the heap's options whatever the
descriptor asks; a Placement heap, a length of 0 and no descriptor answer
nil, and so, logged, does a descriptor over memory of its own;
- newAccelerationStructureWithSize:resourceIndex: nil, logged, as the other
acceleration structure members;
- unfilteredResourceOptions: the heap's options as resourceOptions answers
them.
resourceOptions and hazardTrackingMode now resolve a Default hazard tracking
mode to Untracked, as Metal's heap does (0x120 for a Private heap), and the
heap keeps the purgeable state it is told and answers the previous one, as
Metal's does, where it answered NonVolatile to every call.
The feature profile and FP config getters ran inside a helper's closure,
which the message-layer check does not count as caught: each now runs in
msg::get itself, after respondsToSelector:, as the rest of device.rs sends.
WindowServer asks our device featureProfile at start (boot 3 logged it ten
times). SkyLight also names halfFPConfig, singleFPConfig, doubleFPConfig
and gpuCoreCount. The device's catch-all answered 0 for each; Metal's
device answers the GPU's own values (the M3 Max: 10, 0xe, 0x54, 0 and 40).
The device info now carries the four MTLDeviceSPI values as identity
sizes, taken by calling the API:
- Metal platform: the host device's own answers, asked after
respondsToSelector:.
- Vulkan platform: on macOS, Metal's answers for the GPU Metal's registry
ID names. Everywhere else, the M3 Max's measured values, the one device
they are measured on, since no Vulkan query reports them.
The bundle's device answers the four from the blob, and gpuCoreCount, as
unsigned int, from the count the blob already held.
The blob grows by 32 bytes, so its version goes to 3. The kext copies
sizeof(RgfxDeviceInfo), so the host, kext and bundle ship together.
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.
waitUntilSignaledValue: took the reader its event is registered with as one no
thread drives, and so pumped it every millisecond: the device's reader, which
reads no ring. Its signals come from the queues' readers, which the completion
thread drives, so the wait now sleeps until the value moves; it still takes a
ring that no thread drives (a unit test's).
encodeSignalEvent:value: and encodeWaitForEvent:value: were stubs that only
logged: no command buffer ever signalled an event, a wait ordered nothing, and a
shared event's CPU set never reached the host.
The wire gains the framing ops SIGNAL_EVENT and WAIT_EVENT (an event or a
shared event, and a value), between encoders, and SHARED_EVENT_SET_VALUE on the
control ring. The host carries the ops with encode_signal / encode_wait, faults
one with an encoder open or naming no event, sets a shared event on the CPU's
set, and sets one made at another value to it after its create. Once a buffer
finishes, each shared event it signalled goes to the guest as EVENT_SIGNALLED on
its queue's completion ring, ahead of its CB_COMPLETE; the guest sees the signal
at the buffer's end rather than where its GPU reaches it (design.md says what
that means for a CPU wait on a mid-buffer signal). GPU waits wait on the host's
event and are not affected.
The bundle writes the ops, keeps the event while the buffer runs, posts the
CPU's sets, and hands a queue reader's EVENT_SIGNALLED to the device's reader,
where shared events listen. As Metal's (measured on the M3 Max), the value only
rises, and notifyListener blocks run on their listener's queue with the value
they were registered at, where they ran synchronously on the completion thread
with the current one.
A command buffer that waits is watched: one not finished 5 s after its commit is
named in the log, and again when it finishes. Diagnostics only.
The window server runs Metal Performance Shaders on the device for its
effects, and MPS sends the device's objects members beyond the public
protocols; one that raises kills the window server. mps_probe runs what
those effects use: a Gaussian blur (source to destination and in place), a
Lanczos scale, an MPSImage read back and a blur through a temporary image,
on BGRA8Unorm and RGBA16Float textures in each storage mode. It checks every
pixel against the one color the source holds, and prints the exception an
unrecognized selector raises, which names the selector and the receiver's
class. --discover stubs each miss in the probe alone, to name the next one.
On the M3 Max (macOS 27) every step matches.
WindowServer's custom-effect pipelines (RenderBox's) link a visible function
under the specialized name custom_fn that their fragment calls, and some of
those functions declare constants. Nothing checked that a linked function's
constant values reach the create, beside its library and specialized name,
which the host needs to make it. The test links one of another library, made
from a descriptor with values and a specialized name, into a fragment made
with a uint4 constant, and reads each back from the create.
MPS sends a library bitcodeData and Core Image serializeToURL:error:, which
the device's libraries did not answer. Metal answers nil for the bitcode of
a library made from bytes, from data or from a URL; it writes a library made
from data as the bytes it was made from, with Foundation's error for a URL
it cannot write, and refuses one made from a URL with MTLLibraryErrorDomain
1, "MTLLibrary is not formatted as a MetalLib file." (measured: macOS 27,
M3 Max).
A library now answers the bitcode of its shadow where one is made, which
for one Metal's link or stitching made is Metal's own, and nil otherwise;
its shadow writes it, and one made from a URL, or a file or a bundle's
default library, is refused with Metal's error.
Core Image, MPS and SkyLight send a function arguments, importedLibraries,
returnType, functionConstants, bitcodeData, pluginData, setOptions: and
setPluginData:, which only a function with a shadow answered, and only by
forwarding. Metal's answers depend on the function (measured: macOS 27,
M3 Max): nils for a plain kernel, a stitchable function's bindings and
return type, an unspecialised function's declared constants, and its AIR.
A function made with no constant values now makes its shadow from its
library's on first use, as the link already did, and answers these from it,
logged once per class; one made with values answers nil for its constants,
as Metal's, and nil, logged, for the rest. pluginData is nil, as Metal's
answers even for a function of a descriptor with plugin data; setPluginData:
ends the process, as Metal's does for any argument; setOptions: keeps the
options, as Metal's.
SkyLight, MPS and QuartzCore send a binary archive keys and options, which
the device's archive did not answer. Metal's archive answers a key for each
compile it holds, equal and of one hash with the key of the same entry and
with its copy, and its descriptor's options with 8 added where it has any (0
answers 0, the default 2 answers 10; measured: macOS 27, M3 Max). Ours
answers a key for each entry its own architecture holds, as read or added,
and its descriptor's options as Metal's archive answers them.
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 host's mode can change at any moment (its window draws its first frame, or
is resized), also while WindowServer reads the framebuffer's modes, which it
does during the framebuffer's own start. The framebuffer then answered as
current a mode its list no longer held, kept a startup mode the device no
longer showed, dropped a change that came before IOFramebuffer registered its
connect interrupt, and left the next WindowServer the mode configuration a
previous one made from the old list.
The mode rules move to RgfxDisplayModes.hpp, with a native test of each
ordering (a change before the connect interrupt is registered, between the
current mode and the list, after the startup mode is set): the mode set stays
listed until another is set, the startup mode follows the device's preferred
one where the device no longer shows it, a change that waits for the connect
interrupt fires once it is registered and on, and the first server connection
after a change drops the IOFBConfig left on the framebuffer.
reims-graphics-pci's console has empty display callbacks: QEMU's displays and a
QMP screendump of it show an empty 640x480 whatever the guest shows, which a
boot check read as a black screen. The design now says so, says a check reads
the scanout from the region instead, and lists a console that shows the
scanout as open.
Only the task that holds the framebuffer's server connection reaches the
scanout, but a task that lost the connection kept what it held of it until
its surface went or it locked again: a 0x108 grant (the span mapped in its
context's window) and a backing-less lock's mapping of the scanout in the
task. A live former owner could go on reading and writing the display after
the next WindowServer took it.
When a new server connection makes its task the owner, ReimsGraphics now has
the accelerator take every other task's hold back (scanoutOwnerMoved): each
grant goes, its span mapped back out of the client's window, and each surface
client's lock mapping is unmapped from its task. The new owner's own holds
stay (rgfxKeepsScanout), so a WindowServer that opens its connection again
keeps its own. The kext logs what it took back.
What IOFramebuffer itself mapped for the former owner (the VRAM range on its
connections) is IOFramebuffer's and goes only with its connection, and the
device keeps the old context's BLOCK_GRANT of the span until the new owner's
grant or the old context's close.
window_probe gains former-owner: run as root with WindowServer stopped, it
owns the scanout through the server connection, locks a surface over it and is
granted it, closes the connection, and has another process open one. On msi
the lock mapping read before the move and faulted after it, the window's span
read zeros and a write there faulted, and the kext logged one grant and one
mapping taken back. WindowServer still drew the login screen and its caret,
before and after a killall.
When a command buffer ends, the Vulkan platform's Progress runs the changes
its commands made at completion or failure, then lets go of what they used,
on the runtime's thread. That ran outside the refusal scope the command
carried, so a death in one change or one release (the platform's release of a
buffer, a texture or an indirect command buffer it executed) ended the process
even for the graphics lane, which refuses the same death on the op's thread.
Progress::end now takes the scope Ending carried and runs each change, and
lets go of each object, in it, one at a time: a death in one is refused and
logged, the rest still run and go, and the stage is set. Outside every scope,
the paravirt device's, each runs and goes as before, in the same order, and a
death still ends the process.
A context whose command buffer the platform failed off its op's thread has its
later work refused, but three of its messages still went through. Its
QUEUE_CREATE was answered OK, since the device makes a queue's rings before the
decoder sees it, so its process got a queue whose every command buffer then
failed. Its HEAP_TEXTURE_SIZE_AND_ALIGN and ARGUMENT_LAYOUT queries were
answered from the platform: the size query did not even set the decoder's
context, so it read another context's.
The device now asks its host whether a context is refused
(Host::context_refused, false by default) before it makes a queue's rings, and
answers a refused one's QUEUE_CREATE with RGFX_STATUS_REFUSED. The graphics
lane answers it from the decoder's failed contexts, shared with the control
so no decoder lock is taken. The size query sets the sender's context, and
both queries of a failed context are answered RGFX_STATUS_REFUSED with the
platform not asked and nothing written.
The host took any scanout in the guest's allocations, so a SET_SCANOUT could
name a range past RGFX_SCANOUT_SPAN, in the accelerator kext's blocks, and the
display would show the processes' memory there: their buffers, surfaces and
rings. The framebuffer kext never asks for more than its room
(rgfxScanoutRoom), but the host does not trust the guest.
A scanout now lies whole in the RGFX_SCANOUT_SPAN bytes at
RGFX_ALLOCATIONS_OFFSET, else it is refused with RGFX_STATUS_INVALID_ARGUMENT
and nothing changes. The wire header's comment says so (cargo xtask header).
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.
Core Image asks its kernel library for each kernel's reflection, and the
library answered nil as unsupported (measured: macOS 26.6.1, ci_probe). A
library that keeps its source now answers its shadow's, Metal's own reflection
of the same function, which is what Metal answers for those bytes; one with no
source still answers nil as unsupported.
Core Image reflects each kernel it makes through Metal's private function
getters, and ci_probe aborted in the guest at -[RgfxFunction returnType]
(measured: macOS 26.6.1, CIKernelReflection::reflect). A function holding a
shadow, Metal's own function of the same entry point, now hands each message it
does not implement to the shadow, which answers it for the same function, and
says it does so; nothing else answers in its place. Each selector so handed is
logged once per class, so a run shows what Core Image asks.