The device's newTextureWithDescriptor: sent every texture its validation
passed to the host, posted, and answered a texture, however many bytes it took.
Metal answers nil for one too large to make: the Intel 630 past its
maxBufferLength, the AMD 5300M past 16 GiB (the previous commit's
measurement). A texture whose create the host's platform refused for its size
was then one the app held, and the draws of every command buffer naming it
were dropped (refused.rs), where Metal's app would have seen nil and taken
another path.
What the guest sees: the device's creator answers nil, sending nothing, for a
texture whose bytes, every level of every slice and sample in its format's
blocks (its allocatedSize), are more than the device's maxBufferLength, as the
Intel does and as the bundle answers a buffer and a heap past it. It is inside
both x86 GPUs' answers, and keeps a texture within three quarters of the host
GPU's working set, which our maxBufferLength is. A heap's, a buffer's and an
IOSurface's creators place a texture in memory of their own size, and are
unchanged. test_textures_past_max_buffer_length_are_nil expects it.
guest/prebuilt is rebuilt from the tree (make -C guest prebuilt, the macOS
26.7.1 KDK): RgfxGate, which carries the bundle, and the record.
Both x86 Macs make a texture buffer by the public form even when its texels
lie past the buffer's bytes (measured: macOS 26.7.1, 4 RGBA32Float texels at
offset 4064 of a 4096-byte buffer). metal2vulkan refuses such a texture
(TexelsPastLength), and the Vulkan host ends its process at a refusal by this
creator. So the bundle answers nil, logged once, and sends nothing, as it does
for the other textures over a buffer the host does not carry.
The GL renderer builds each OpenCL program's kernels in gldBuildComputeProgram
and sends each one reflectionWithOptions:3, unguarded (read from its code).
Our functions did not answer it, so every OpenCL build on our GPU ended the
process with an unrecognized selector (cl_probe on the RTX 5080 host,
m3-max-3947).
What the AMD 5300M and the Intel 630 answer, alike (measured: macOS 26.7.1,
OpenCL C and Metal kernels):
- an MTLFunctionReflectionInternal, for options 0, 1 and 3;
- its arguments and bindings are the same objects a pipeline's reflection
lists;
- a kernel's by-value argument is a buffer binding of type 22, of the value's
type, size and alignment, with a pointer type that is no constant buffer.
Our functions now answer that class over the arguments their pipelines'
reflection lists. A by-value argument (air.constant) of a scalar type is now
reflected, where it was refused. A struct passed by value was not measured
and is still refused.
newLibraryWithData: keeps the bytes it was given, for the library's shadow.
For the bytes Metal's compiler answers for OpenCL C source, that is the
container, not the .metallib of its kernels that the library was made from.
The library then read its entry points' arguments from the container, found
no bitcode, and answered none. So the GL renderer's OpenCL kernels on the
RTX 5080 host had no arguments ("__entry_add: no arguments read (the library
holds no bitcode for it)", m3-max-3947).
The reader now takes the container as the .metallib of its kernels, as the
library was made from it.
A buffer's newTextureWithDescriptor:offset:bytesPerRow: answered nil for a
texture buffer, logged as a type the host does not carry. The GL renderer
makes each GL texture buffer this way: gl_cases' texbuffer case got nil, and
the renderer drew it in software (RTX 5080 host, m3-max-3947).
Both x86 Macs make one by this form (measured: macOS 26.7.1, RGBA32Float and
RGBA8Unorm):
- over a Shared or a Managed buffer, at any offset (0, 4, 16, 64, 100, 256);
- with rows of at least its texels' bytes (64 and 4096);
- and their kernels read the buffer's bytes from the offset.
The host's platform makes one by the same form, at any offset, so the create
now goes to the host as TEXTURE_FROM_BUFFER with its type. For rows of 0 bytes
both Macs end the process with the same words, and the bundle does too. For
fewer bytes than the texels need, the AMD answers nil where the Intel ends
the process; the bundle answers nil, as the AMD does.
The lowering added air.arg_type_size and air.arg_type_align_size to a GL
buffer argument from its air.arg_type_name. The generator names a uniform
block's pointer, typed <4 x float> addrspace(2)*, "uchar" (measured: macOS
26.7.1, gl_cases' block case). So the lowering wrote a size of 1, and
metal2vulkan refused each such pipeline: it requires the pointee's
allocation size (TypeSizeMismatch at air.arg_type_size). The GL renderer then
drew the block case in software (RTX 5080 host, m3-max-3947).
The size and alignment now come from the parameter's pointee type in the
entry point's function type, as `metal` writes them:
- an integer, half, float or double;
- a vector or an array of them.
No size is added for any other pointee, a struct among them.
Reverts 0825b1ea2, restoring 0afc30f37, e8d04b187 and ea13ccbca. A write-combined
mapping of the region does take: the region's descriptor is physically
contiguous, and xnu's fault path maps such an object's pages in its own cache
mode (vm_fault's pmap_map_block_addr, read from the public xnu source), which
the earlier reading missed. The page-table probe that seemed to agree saw only
the processes on the CPUs at its instant, not the bench.
Measured on the Radeon 780M host, draws.10k's encode: 9.2-9.5 ms at the base,
7.7 ms with the slabs in the process's own pages alone (936e3968d's set), and
1.05-1.3 ms with the spans write-combined as well (0afc30f37's and ea13ccbca's
sets). The kext's comment and the design doc say why, and docs/lessons.md the
probe's trap.
For the guest, as 0afc30f37: a queue's submission ring starts 3840 bytes into
its block, the kext's Alloc takes a third input and its feature word holds
1 << 7.
Reverts 0afc30f37, e8d04b187 and ea13ccbca. On x86-64 xnu every mapping of
the region in a guest process is uncached, whatever cache mode the kext asks:
vm_fault enters each page with no cache flags, and the pmap gives a page it
does not manage PCD alone, the guest PAT's UC- (read from the public xnu
source: pmap_get_cache_attributes and vm_fault's pmap_enter wrappers). Measured
on the Radeon 780M host with both the region's own descriptor and one of the
write-combined spans' own: every page of a process's over BAR 2 was PCD alone,
none PAT and PCD, and draws.10k encoded as fast as with the spans write-back.
For the guest, a queue's submission ring starts its block again, the kext's
Alloc takes two inputs and its feature word drops 1 << 7; the slabs in the
process's own pages (72c09eddc) carry the measured gains. The design doc says
why the region is uncached, as measured.
On a host of 4 KiB pages, a heap of 3 pages rounds up to Metal's 16 KiB page, past a
view of 3 pages; and a region slab's heap is its class's slab size, not 2 MiB.
The guest's kernel maps the device region uncached whatever the kext asks:
xnu's pmap sets PCD on every page it does not manage, and the region is no RAM
of the guest's. An AMD host applies the guest's memory type (Intel's EPT
ignores it), so on the Radeon 780M host the guest's stores there ran at
13 MB/s and draws.10k spent 9.1 ms encoding against 0.5 ms on the RTX 5080.
The kext's Alloc now takes a third input, the byte from which the process's
mapping of the block is write-combined (kIOMapWriteCombineCache, PAT index 6),
behind a kext feature bit. The bundle puts there what it only writes: a
submission ring's data, which now starts its block's second page with the
ring's header ending the first, write-back as before, since the host writes
it too and the writer reads it; command buffers' bodies; and a library's
staging chunks, past the page of acks it reads. The ring writer fences its
stores (sfence) before it publishes a message, so write-combined stores reach
the host before the producer index that names them, as a release store
orders write-back ones. ICB slots stay write-back: their setters read fields
back and OR bits in with locked operations, which write-combined memory does
not keep atomic.
For the guest, a queue's submission ring now starts 3840 bytes into its block
where the kext has the feature; the wire is unchanged.
The pages slab source took only 2 MiB superpages, and the guest's kernel runs
out of them minutes after a boot: measured on an x86-64 macOS 26.7.2 guest of
8 GiB on the Radeon 780M host, a process got 19 at boot with 2.5 GiB free,
then KERN_NO_SPACE, and none three minutes later. Every Shared buffer, 4 KiB
up, then lay in the device region, which the guest maps uncached and an AMD
host applies: its stores ran at 13 MB/s, against 56-123 GB/s in a superpage.
Where the kernel refuses superpages, the source now takes plain pages,
zero-filled and wired into a pages block by the kext: a 2 MiB slab is one
HEAP_OVER_PAGES the host lays over the block's view, a larger dedicated
Shared one a BUFFER_OVER_PAGES over it, as before. Only where neither comes
is a slab the region's.
A queue's upload chunks, the bytes set*Bytes: hands in, are now Shared
buffers of the slabs, so they lie in the process's own pages too, and fall
back to region blocks only without slabs.
The M3 Max's Metal on macOS 27 writes the container's function table with a
first u16 of 9 where macOS 26.7.1 writes 8; the rest of the layout is the
same (measured, m3-max-3913). The reader no longer checks that u16, so the
bundle test over this Mac's own container passes.
Metal's compiler answers a library of OpenCL C source (the GL renderer's
compute programs) as a container that is no .metallib: a function table and
one bitcode module per kernel. The host reads only .metallibs, so it refused
every such library (status 5, cl_probe on the 5080 and the RX 550). The device
now takes those bytes as the .metallib of their kernels, written by the
metallib writer, which now writes several functions placed as `metal` places
them. The container's layout is measured on macOS 26.7.1's Intel and AMD
devices; the bundle tests check the writer against this Mac's Metal and the
reader over a container written in that layout.
The GL code generator writes a uniform buffer's argument node without
air.address_space. For a buffer with air.buffer_size it also leaves out
air.arg_type_size and air.arg_type_align_size (measured: macOS 26.7.1,
gl_cases' shaders). `metal` writes all three, and the device's reflection
reads them. On the RTX 5080 host each such pipeline came back with no
reflection, and gl_cases' uniforms and block cases read black.
The lowering now adds:
- the address space of the parameter's pointer, after the access
qualifier;
- the pointee size and alignment of the node's air.arg_type_name, where
the node has none.
This is the order `metal` writes them in.
On macOS 26.7.1 the AMD 5300M and the Intel 630 answer nil to
newBufferWithLength:options:, newBufferWithBytes:length:options: and
newTextureWithDescriptor: when the options hold bit 18 (0x40000). That
holds in every storage mode; bits 17 and 19 make the resource as
usual. The bundle made every one of them.
Both Macs agree, so it is the contract, and those creates now answer nil.
The Macs make a no-copy buffer and a heap's buffer with bit 18, and so
does the bundle. On a Private heap they diverge (the AMD's is nil, the
Intel's is made), and the bundle keeps making it. What the bit means
nothing states.
The GL renderer makes its no-copy buffers with resource option bit 20
(0x100000), a hint for the device's driver. The bundle passed every bit
to the host, and the host's runtime refuses a buffer with a bit Metal
gives no meaning, so each such buffer was refused (measured: macOS 26.6.1
on the RTX 5080 host).
Heap and buffer creates now carry only the CPU cache, storage and hazard
tracking modes, and Metal's private bit 24, which the host takes as Metal
does.
A buffer outside a heap now answers resourceOptions with its three modes
alone. On macOS 26.7.1 the AMD 5300M and the Intel 630 drop each of bits
10 to 31 from the answer, for length and no-copy buffers alike: they give
0x200, 0x210 and 0x220 for Shared, Managed and Private.
The Vulkan host's runtime reads AIR's metadata as a closed grammar. On the
RTX 5080 host it refused every GL pipeline (UnknownKey at gld.plugin_info).
Compiling the pipelines of gl_cases' 29 cases, dumped on the Intel 630,
with the runtime's compile API found what else the GL code generator
writes that `metal` does not.
The generator links its builtins, compiled as AIR 2.8 and Metal 4.0, into
any shader that uses them. Their lists' entries then follow the module's
own: more versions and languages, conflicting compile options, and
duplicate air.max_* flags. Each module, a kernel's included, now keeps:
- no gld.* lists;
- only its own air.version and air.language_version entry, the language
Metal's at the AIR version;
- its own compile options, one of each kind, without
native_double_disable;
- the first module flag of each name.
On the entry points, a vertex input loses the bare attribute name after
its location, and a flat fragment input loses its sampling key, as
`metal` writes [[flat]].
With these rules all 29 cases compile on the RTX 5080 and 780M profiles,
and draw right through the lowering on the Intel 630 (macOS 26.7.1).
The system's GL renderer sends readsDepth, writesDepth, readsStencil and
writesStencil to every depth/stencil state it binds, without asking first
whether the state responds. Our state had none of them, so the first GL
draw with depth or stencil ended the process on an unrecognized selector
(measured: macOS 26.6.1 on the RTX 5080 host).
On macOS 26.7.1 the AMD 5300M's and the Intel 630's states answer YES to
all four for every descriptor asked, including one that tests and writes
nothing. The bundle's state now answers the same.
test_gl_renderer_spi compares the ops of one pass encoded with and without
the renderer's cleared marks, and committed with commit and commitAndHold.
Each pass's encoder takes the queue's next barrier fence, so its
ENCODER_BEGIN_RENDER and its fence ops differ from the others' by that
fence's id alone, and the comparison failed on them. Those ops' bytes are
blanked before the comparison; their tags and sizes, and every other op,
are still compared whole, and the first op that differs is printed.
The pass's target is a stand-in handle, as other encoder tests' are.
On the reims-graphics device, the system's GL renderer ended the process at
its first glClear: -[RgfxTexture swizzleKey] was an unrecognized selector
(measured on macOS 26.6.1 with an RTX 5080 host). Comparing the renderer's
selectors with what Intel's x86 classes answer, on the oracle Mac, turned up
four that our classes lacked and that the renderer sends unguarded. Their
behaviour was measured on macOS 26.7.1 on an AMD 5300M and an Intel 630:
- swizzleKey: the texture's swizzle channels, one byte each, red lowest.
The default swizzle gives 0x05040302 whatever the pixel format.
- commitAndHold: Metal commits the buffer and holds its submission until the
queue's next commit. Ours commits it as commit does, so it runs in the
same order, and never later than Metal's would.
- setDepthCleared and setStencilCleared on a render encoder: hints for the
driver's own clear state. They leave the pass unchanged on both Macs, and
post nothing here.
A shell test covers the keys of a texture and its views, and checks that the
marks and commitAndHold post the same ops as a plain pass and commit.
The GL code generator's modules made two pipelines fail on Metal (measured
on macOS 26.7.1, Intel UHD 630, through tools/gl_cases.m):
- a flat int varying is typed "uint" in the vertex output and "int" in
the fragment input, and Metal fails the link on the difference, so the
renderer drew the shader in software;
- gl_FragDepth's air.depth output carries no air.arg_type_name, and Metal's
reflection reader dereferences the missing string and ends the process.
The lowering now rewrites a vertex or fragment variant's stage metadata
before writing its bitcode. Integer user() varyings take the unsigned name
on both sides; AIR holds no signedness and the bits pass as they are. A node
with no type name gets the Metal name of its LLVM type, and an arg_name
where it has none. All other nodes are left alone. The edit goes through the
module's text, which the system's LLVM parses again. With it, all 29 of
gl_cases' cases pass through the bundle's lowering on the Intel 630, and the
flat case stays on the GPU.
macOS's OpenGL renderer over Metal hands a device each shader as GL IR
and each variant as plugin data. Metal's own devices lower the two to
AIR in their compiler service; ours has none, so a variant is now
lowered in the renderer's process, through the GL code generator the
system ships beside the renderer, called in place. The AIR goes into a
.metallib of one function, which the device makes a library of, so it
reaches the host as any library does.
- RgfxGLFunction answers the six newFunctionWith{GL,GLCore,GLES}IR:
members, with what Metal's own function of GL IR answers.
- RgfxMetallibWriter writes the .metallib, and unwraps the bitcode the
system's LLVM writes, which Metal refuses wrapped twice.
- The generator's return data rides with the variant, and the render
and compute reflections answer it as Metal's do.
- The register lists the device's GL members as implemented and the GL
function's members.
test_stitched_libraries_in_archives and test_library_members_as_metal each
make two libraries of the stitchable bytes before they drain the control
ring, which the 16 KiB metallib no longer lets a 32 KiB ring hold: the
second library was nil (an uncaught exception in the first, a wrong error
domain in the second). A 64 KiB ring holds them, as for the stitched-shadows
test.
stitchable.metal's second caller grew its metallib to 16 KiB, so the test's
two libraries of those bytes no longer fit the fixture's 32 KiB control
ring: the second create was never posted, its library was nil, and the
test's check that a library with no shadow logs its reflection as
unsupported failed. A 64 KiB ring holds them.
MPSGraph's softmax (Geekbench 7's Background Blur and Face Tracking) links
MPSNDArray's reduce_stitched, which calls reductionStitched::write_fn with
three arguments, to the write_fn MPS stitches of two inputs. Metal links it
and drops the extra argument, and the Vulkan runtime refuses the link
(LinkProblem::Signature), which metal2vulkan is fixing.
The shell tests' stitchable.metal gains `pair`, a call of three arguments to
a graph of two, which stitch.m stitches into the committed fixture beside
`fused`. A macOS decoder test runs it on Metal's own pipeline, through the
decoder over the bytes Metal's stitcher makes, and over the committed
fixture: each writes 2 + 3 from either list. The Vulkan-side test comes with
the metal2vulkan pin that carries the fix.
MPS stitches its uber shaders' visible functions after making them with
constant values and a specialized name (MPSLibrary::CreateUberShaderKey). Our
stitch runs over each function's shadow, Metal's own function over the same
bytes, and a function made with constant values had none, so the stitch was
refused ("link: function constant_0000000000000000_f has no function of Metal's
own library"), MPS inserted the nil it got into an array and threw: Geekbench
7's GPU benchmark aborted at its first MPSGraph convolution.
A function now keeps the constant values it was made with, and its shadow is
Metal's own function of a descriptor of the entry point, those values and its
specialized name. Metal's own library on this device makes such functions and
stitches them (measured in a macOS 26.6.1 guest on the RTX 5080 host,
tools/stitch_probe --metal). The same covers a function given a specialized
name alone, whose shadow answered the entry point's name, which a graph's node
naming the specialized one does not find.
The shell tests stitch functions specialised each way over Metal's own shadows
(tests/stitch_constants.metal); tools/stitch_probe runs the stitched function
on a guest's device.
Since c13-contract (ae37ce1c2) the bundle answered nil for a BC1 to BC7
texture over an IOSurface or one of its planes, before it took a view of the
surface. Metal on the x86 Macs makes these wherever the rows fit, over a
surface with planes or without, in Managed or Private storage
(oracle_surftex, Q20). The nil was the host's limit: pin 14's runtime made
no texture of one over a surface's rows (NotLinear). metal2vulkan's stack
34, at this branch's pin, makes them in the x86 Macs' form, row j of blocks
at the plane's row j (on MoltenVK as a shadow image), and the bundle's own
CPU access takes the same rows since 187d1ee33. Runtime gaps are
metal2vulkan's, and ours go at the pin that fixes them.
What changes for the guest: newTextureWithDescriptor:iosurface:plane: of a
BC format answers a texture and posts its create, where it answered nil and
logged "no texture (descriptor)". The shapes stack 34 still refuses (a BC
texture over a plane at an offset or rows off 16 bytes, or wider than the
plane's rows) are posted and refused as the host's other refused shapes are
(decode/refused.rs). On the Metal platform, whose buffer creator answers nil
for BC as Metal's IOSurface creator does (87b24e27e), the texture is a
refused create too.
Test: test_iosurface_block_compressed_textures_are_made fails at the base,
where the bundle answers nil.
A texture over an IOSurface read and wrote its rows on the CPU (getBytes,
replaceRegion) in the surface's elements, not the texture's texels. A
texture of a narrower format than the surface's element wrote past the
caller's rows: an R8Unorm texture over a 'BGRA' surface copied four bytes a
texel into a buffer of one a texel. A wider format copied too few bytes, and
a surface whose elements are not single pixels (a 4:2:2 one) gave none.
Metal reads and writes the texture's own texels, row j of them at the
plane's row j.
What changes for the guest: getBytes and replaceRegion of a texture over a
surface read and write the blocks of the texture's own format
(rgfxPixelFormatBlock) at the plane's rows, over a 4:2:2 surface too. A
texture of a format with no block there (depth or stencil, Private over a
surface) reads and writes nothing.
It is also the ground for block-compressed textures over a surface, whose
rows of blocks lie at the plane's rows.
Test: test_iosurface_cpu_access_in_the_texture_s_format fails at the base,
where the R8Unorm read writes past the caller's 256 bytes.
c14-shared-events and c14-texture-nil each added a Q23 to dgpu-oracle.md. The
car keeps shared events' Q23 and numbers texture-nil's two sections after it:
the texture descriptors each creator refuses are Q24, and what a command buffer
does with nil objects is Q25. The references in dgpu-oracle.md, design.md, the
decoder's refused.rs and the shell tests follow, and the report's probe list
names oracle_events, which shared events added to the oracle's README and
build.sh.
The bundle posted a BC1 to BC7 texture over a buffer's bytes, which the host's
platform makes none of (Metal's over a buffer, and metal2vulkan's linear
images), so the host refused it and every draw that named the texture was
dropped. The AMD 5300M answers nil for one over a Shared buffer, 64 x 64 and
62 x 64 (oracle_texdesc buffer bc1.*), where the Intel 630 makes it: the
envelope holds nil, and the bundle answers it, sending nothing.
For the guest: newTextureWithDescriptor:offset:bytesPerRow: of a
block-compressed format is nil. Both x86 Macs make a single block's (2 x 2),
which is now nil too.
A texture create is posted, not waited for, so a descriptor the host refused
left the app holding a texture whose every draw was dropped, where Metal on the
x86 Macs ends the process at its descriptor validation. The bundle copied a few
of its rules (three-channel formats, multisample compressed formats, depth in
CPU storage), and the IOSurface creator a subset of its own.
Every texture creator now runs one copy of
-[MTLTextureDescriptorInternal validateWithDevice:]: the device's, both of a
heap's, a buffer's public form and its linear and tiled SPI, and the creator
over an IOSurface. It follows the AMD 5300M and the Intel 630 under macOS
26.7.1 at the device, a Private heap and a Shared buffer (oracle_texdesc, 107
descriptors): every rule broken a line, in their order, in one assertion; the
sample counts the device makes; Depth24Unorm_Stencil8 and X24_Stencil8 lacked,
as on the Intel. A heap's creators then end the process at a descriptor of
another storage mode than the heap's, and a texture type past TextureBuffer
ends it with no words, as there.
For the guest: a process that sent the host a texture create Metal does not
make now ends at the create with Metal's words, and the host is sent nothing.
A device-placed texture and a Managed texture's GPU copy take a GPU address
of the context's range, which runs out at address-space exhaustion. Their
creates took the address unchecked and posted 0, where a heap, a buffer and
every other create that picks an address answer no object.
What changes for the guest: at exhaustion such a texture is nil, as Metal
answers one it cannot place, and nothing is posted; its resource id goes back
for the next texture. A texture in a heap takes no address and is unchanged.
Test: test_creates_with_no_address_post_nothing fails at the base, where both
creates post with address 0.
eventPort, newSharedEventHandle, newSharedEventWithHandle: and
newSharedEventWithMachPort: answered nil or raised unrecognized selectors. They
now answer as the AMD 5300M and the Intel 630 do under macOS 26.7.1
(oracle_events, identical on both), where the kext and the host carry ports:
- eventPort is the kext's port for the event, asked once and the same name at
each ask, which the event holds one send reference of;
- the handle is Metal's own MTLSharedEventHandle over it, which takes its own
reference, keeps the label, and crosses NSXPC as Metal's does;
- an event made of a port or a handle is the same host event at its value,
holds one more reference, and is labelled as the handle (nil from a port);
made of this process's own port it is the event's alias, which reads the
other's sets at once, as Metal's two events do;
- MACH_PORT_NULL, a dead name, a port the process receives, a port that names
no shared event, and a nil handle answer nil, the references as they were;
the bundle asks its own connection whether a port is the kext's
(IOConnectAddClient) before it calls on it, so another process's own port is
answered nil, where an IOKit call on it would kill the process;
- the event adopts NSSecureCoding and codes only through an NSXPCCoder, raising
NSInvalidArgumentException with Metal's words otherwise.
The values other processes give the event come on a queue of the device's own,
its listen queue. A value set in another process reaches this one as the host
posts it, where Metal's shared page is read at once: a read right after the
other's set may see the value before it.
After the AIR read cache (104f648f8), a library's lookup of a function's
module was mostly a walk of its .metallib's function list to the name:
1.39M instructions (73 us) a lookup on the M3, on average over macOS 27's
framework libraries, all of them cache hits (m3-max-2221). Libraries of many
functions (MPSImage's 1,837) pay O(n) per lookup, and finding a function's
table entry walked the table by name too.
The shared function table now indexes both when it is read, once per content
key: each function's entry by name, and its bitcode as rgfxMetallibBitcode
finds it (RgfxMetallibBitcodeIndex: the first function of a name answers, and
none past a group that does not read, as the walk). Bytes of another length
or header than those the index walked are walked as before.
Lookups find what they found before: the AIR test checks that the index
answers what rgfxMetallibBitcode answers for every name of its libraries, of
the committed metallibs and of 2,000 libraries with spoilt function lists.
Only when the list is walked changes, never what a lookup finds.
Since 81618ace7 a cached module also holds its decoded code
(RgfxAirEntries::code) where it declares function constants. The cache
counted only the module's bytes against its 16 MiB, so its memory was no
longer bounded as the header said: decoded code grows with the function
bodies, not the metadata. Each kept module now costs its bytes plus what
its code's containers hold (rgfxAirModuleCost), and the budget bounds that
sum. Only which modules the cache keeps changes, never a read's answers.
The AIR test's whole-value comparison of one read with each reader did not
cover the fields 81618ace7 and 19ef218a6 added: a node's globals and render
target, an entry's function, and the code. It now compares them, the code by
what rgfxAirSpecialise answers for each entry point. The cache test budgets
by cost, and checks that every_access, which declares a constant, costs more
than its bytes.
A buffer with a completed handler paid two hops to its queue's completion
queue, one for its CB_SCHEDULED and one for its CB_COMPLETE, though its
scheduling runs nothing of the app's when it has no scheduled handler. Such a
buffer's scheduling now runs on the completion thread as it takes the record,
where none of the queue's records still waits on the completion queue, as the
records of a buffer with no handler at all already do.
What the guest sees: for a buffer with no scheduled handler, the status turns
Scheduled and waitUntilScheduled returns from the completion thread, one
thread wake sooner. Behind a record of its queue still to run, it waits its
turn as before, so the status still flips in the ring's order among the
handlers. The completed handler still runs on the completion queue.
The car 12 probe put a lone buffer's commit-to-scheduled-handler at about
390 us p50 on the RTX 5080 host, against 198 on an AMD Mac. Part of that is the
guest's own hops: the completion thread's wake, then the queue's completion
queue for each record. shell_tests --queue-timing [rounds] times them on the
bundle's real queue, reader and completion thread, with the kext's wait stood
in for: how long after the host's post of a CB_SCHEDULED, then a CB_COMPLETE,
the handlers run and waitUntilScheduled and waitUntilCompleted return, for a
buffer with both handlers, one with a completed handler alone and one with
none. It is a measurement, run by hand, never in make test.
c14-air-cache's test of every committed metallib (1cb31349f) lists the entry
points whose nodes do not read, among them rounding.metallib's and
rounding_safe.metallib's three framebuffer-fetch fragments, whose `[[color(0)]]`
input (`air.render_target`) the node reader did not follow. c14-reflection
(19ef218a6) taught the reader that input, so on car 14 those six read, and the
test failed at the first (m3-max-2483: "rounding.metallib: fetch_half_fragment:
its nodes do not read"). The three explicit-imageblock kernels still do not
read, as c14-reflection's message says.
Car 14's stack: a test fix where c14-air-cache meets c14-reflection.
The shell tests now make k_specialised and v_specialised under two sets
of constant values and expect what the 5300M and the 630 answer: an
index kIndex + 1 computes, an argument under kOn || kOff kept or left
out, and which arguments a switch, a select and an optional constant
leave used. air_arguments_test checks rgfxAirSpecialise directly (the
arguments used, the globals the initialisers leave, no values given),
and specialises 4000 spoilt copies of k_specialised's module without a
crash or a hang.
A pipeline's reflection answered nil where a function had an argument
buffer of a struct of members, a C array of members, an array of
samplers or a pointer to an argument buffer of its own, a function table
or an acceleration structure, a texture of 64-bit atomics, or a fragment
function that reads its colour attachments: the AIR reader refused the
fragment node, and the reflection had no answer measured for the others.
Each now answers what Metal answers on the x86 Macs (measured on the
5300M and the 630 with tools/pipeline_reflection_check, every getter and
instance variable alike):
- a struct of members is a struct of its own argument buffer members,
at ids from its first, a C array of them an argument buffer array of
the ids an element takes as its index stride;
- a C array of a member is an argument buffer array whose details are
the element's binding, of a constant's size's stride;
- a metal::array of samplers is an array of index stride 1, as textures';
- a pointer to an argument buffer is a pointer member of its binding;
- function tables and acceleration structures are bindings of their
own types, read only, as kernel and fragment arguments and as an
argument buffer's members;
- a texture of ulong is of MTLDataTypeULong (the 630's answer; the 5300M
makes no pipeline of one, nor of a fragment table);
- a fragment function's colour attachment reads are listed nowhere.
For the guest: those pipelines now answer a reflection where they
answered nil. An imageblock still answers nil: neither x86 Mac makes a
pipeline of one.
A pipeline's reflection is built in the guest from its functions' AIR,
and answered nil where a binding index, a count or a predicate was an
expression of function constants, and isUsed came from the AIR alone,
which marks used an argument read only in code a constant removes.
Metal reflects the specialised function (measured on the 5300M, the 630
and the M3: an argument read only under a false constant is unused, and
[[buffer(kIndex)]] is at the index kIndex gives).
The AIR reader now decodes the function bodies of a module that declares
function constants. Under the function's constant values it runs the
module's initialisers (the stores that set the globals a computed index,
count or predicate is read from), propagates the values through the
entry point's branches, switches, selects and phis, and marks used the
arguments a live instruction of a reachable block reads.
For the guest: such a pipeline now answers a reflection, its arguments
at the indices and counts its constants compute, and an argument read
only in code its constants remove answers isUsed and isActive 0. Where
the reader does not follow the module's code, the answers are as before.
Car 14's stack: resolved over c14-air-cache's one read of a module (104f648f8).
The specialisation code sits before visibleOf in the anonymous namespace,
rgfxAirSpecialise after rgfxReadAirEntries outside it, and finishCode takes a
const Module. rgfxReadAirEntries and rgfxReadAirModule read with wantCode;
where the cache's read with code fails, the module is read again without it for
its functions and visible functions, so only its entry points go unread, as on
this lane. rgfxAirEntryNamed copies the module's code pointer beside its
constants. The header keeps both includes and both sections.
A library read a function's AIR module once for each kind it asked for (the
arguments, a visible function's signature, the nodes a pipeline's reflection
reads), and every library object over the same bytes read it again. The
c13-answers probe measured 20.6 us a read on average over macOS 27's
frameworks (m3-max-1379).
Now one read of a module gives all three answers (rgfxReadAirModule), and
the process keeps its reads by the module's bytes (RgfxAirModuleCache), so a
second library over equal bytes, or another kind of lookup, reads nothing
again. The cache's key is a copy of the bytes, compared whole, so equal
reads always come from equal bytes. It keeps the most recently looked-up
modules while their bytes total 16 MiB, and reads one it let go again.
A function's answers are a function of its module's bytes alone, so the
cache changes when a library's answers are produced, never the answers
themselves: the AIR test checks that one read answers what each reader
answers, for every module of its libraries. Libraries over equal bytes now
share one object per function's arguments and signature (the shell test).
The ledger listed 8 committed metallibs whose functions the AIR argument
reader did not read. At b4aff9c7f it reads them all: Core Image's kernels
(TYPE 5) get no read at all, the linked, stitchable and stitched libraries'
visible functions are read by the signature reader, and kernel_trunc.metallib
is cut to 1000 bytes on purpose, so its function has no bitcode. The AIR test
now runs the readers over every committed metallib (the suite's fixtures and
the Vulkan platform's), and checks that each function is found by the read
the device makes for its kind.
Nine entry points' nodes do not read. Each has a framebuffer-fetch input or
an explicit imageblock, and their pipelines answer no reflection. The test
lists them, so a new miss, or a fix for these, shows up.
The copies a command buffer wrote that no surface retire waits for went
back only at its delivery, behind the queue's earlier completed handlers:
app memory under a no-copy buffer (RgfxMemoryShadow), and the copy of a
surface whose writes were not named to the kext. A handler that ran long,
or a CPU that read the memory once the GPU was done (a shared event the
buffer signalled), saw the bytes as of an earlier buffer.
Those copies now go back on the queue's write-back queue as the buffer's
CB_COMPLETE is taken, in the ring's order, as the named surfaces' copies
already did; the delivery waits for them, so the status and the waiters
still come after the write-back.
What the guest sees: a buffer's GPU writes to such memory show as soon as
its completion is taken, not after the handlers of the buffers before it.
A texture over an IOSurface whose GPU view is a copy took the surface's
CPU lock under the view's own lock: replaceRegion: wrote the copy back to
the pages under IOSurfaceLock, and the copy's upload read the pages under
a read lock, both with the view's lock held. A command buffer's write-back
of the copy at its completion takes the view's lock before the buffer's
writes retire, and in the guest a CPU lock of the surface waits for those
writes in the kext. So a CPU copy racing a write-back waited out the
kext's 2 s and went on without the buffer's results.
Every surface lock is now taken before the view's lock: the upload checks
the seed under the view's lock, then takes the surface's read lock and the
view's lock in that order, and replaceRegion: takes the copy's write lock
before the view's lock and lets it go once the rows are in the pages. The
bundle counts surface locks taken under a view's lock, for the test,
which expects none.
What the guest sees: such a CPU copy waits only for the GPU's write.
For the guest: where the device takes MESH_PIPELINES, every
newRenderPipelineStateWithMeshDescriptor: form makes a mesh render pipeline. It
used to answer nil and an unsupported error. The render encoders send the object
and mesh stages' bindings and drawMeshThreadgroups:, drawMeshThreads: and the
indirect form, and the SPI's supportsMeshShaders answers YES. Without the
feature they answer as before. The state answers its object and mesh limits as
the host's platform answers them (maxTotalThreadgroupsPerMeshGrid NSUIntegerMax
past 32 bits) and the threadgroup sizes its descriptor required.
Measured with guest/bundle/tools/oracle/oracle_mesh, plain Metal, on the AMD
Radeon Pro 5300M and the Intel UHD Graphics 630 (macOS 26.7.1, 25G241) and the
M3 Max (macOS 27.0.1, 26A434), the creators now end the process where the x86
Macs' Metal does, with their words:
- supportIndirectCommandBuffers YES, on the 5300M and the 630 (the M3 Max makes
it): "validateWithDevice:1884: failed assertion `Mesh Render Pipeline
Descriptor Validation\nUse of mesh shader pipelines in indirect command
buffers is not supported by this device.\n'"
- no mesh function, on all three: "...\nmeshFunction must not be nil.\n'"
- no fragment function while rasterizing, on all three: "...\nfragmentFunction
must not be nil.\n'"
So no mesh pipeline supports indirect command buffers, and indirect commands
carry no mesh draw. This matches the families: supportsFamily: answers no for
Apple7 to Apple9 on the x86 Macs and on the device, and the SPI's
supportsMeshShadersInICB answers NO on the x86 Macs and the device (YES on the
M3 Max).
They refuse before the host is asked, in the x86 Macs' compiler's domain
(CompilerError):
- a payload past 16384 bytes, code 2, "payloadMemoryLength property of
MTLMeshRenderPipelineDescriptor (16385 bytes) exceeds maximum supported by
this device (16384 bytes)";
- a stage maximum past the device's 1024 threads, code 2, the 5300M's
"maxThreadsPerThreadgroup pipeline descriptor value (2048) exceeds maximum
supported (1024)\n" (the 630 makes it, the M3 Max refuses it);
- a vertex function as the mesh function, code 2, "RasterizationEnabled is
false but the vertex shader's return type is not void";
- any other function of another stage, code 1. The x86 Macs answer the
crashed compiler's XPC words; ours are the validation layer's;
- a mesh function as the object function, code 1, which the x86 Macs make
and the M3 Max refuses;
- an archive miss under MTLPipelineOptionFailOnBinaryArchiveMiss, code 2,
"Unable to find function \"f_col\" in binary archives. \n ". It names the
fragment function, else the mesh function. An x86 archive holds no mesh
pipeline, so every create naming an archive misses.
The creators with a reflection answer RgfxMeshPipelineReflectionOf's, the
reflection of the pipeline's functions, as the render pipeline creators answer
theirs.
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.
Every pipeline creator answered a nil reflection, whatever its options. An
app that asks for MTLPipelineOptionBindingInfo or BufferTypeInfo to find its
buffers' indices, sizes or struct layouts found none.
What changes for the guest: a render, mesh or compute pipeline made with
either option now answers Metal's own reflection (its private reflection
classes), in the synchronous creators and in the completion handlers alike.
It is built in the guest from the AIR of the pipeline's functions and its
vertex or stage input descriptor: each stage's bindings, built-in arguments,
types and struct members, and the private postVertexDumpStride. Options of
neither still answer nil. A pipeline the bundle cannot answer exactly (an
index function constants compute, a kind no x86 Mac was measured for, a
function of no library of ours) still answers nil, logged once per reason.
An argument read only in code its function constants remove is answered
used, where Metal answers it unused; Intel's postVertexDumpStride is 4 less
than ours, which is AMD's. Nothing changes on the wire.
The values are an x86 Mac's (macOS 26.7.1, AMD Radeon Pro 5300M and Intel
UHD Graphics 630), measured with the oracle_reflection probe and recorded in
docs/graphics-kext/dgpu-oracle.md, Q20. tools/pipeline_reflection_check.mm
makes the same pipelines on a device and compares its reflection with ours,
getter by getter and instance variable by instance variable: over 80 cases it
finds no difference on the AMD GPU, and on the Intel GPU only that stride.
The shell test checks ours over the probe's library. RgfxMeshPipelineReflectionOf is the
mesh creators' to answer once they make mesh pipelines.
Car 13's stack: resolved docs/graphics-kext/dgpu-oracle.md, where c13-contract
added Q20 (textures over an IOSurface) first: this commit's section is Q21, and
the probe list names oracle_surftex and oracle_reflection;
guest/bundle/Makefile's shell tests take both RGFX_AIR_REFLECTED
(c13-wire-gaps) and RGFX_ORACLE_REFLECTION.
The pipelines' reflection needs more of each entry point than its argument
list: every node's kind, index, access, type, size and alignment, a struct's
members with their offsets, arrays and argument buffer details, the function
constant a node is gated on, a vertex or mesh function's outputs and a mesh's
vertex and primitive data. rgfxReadAirEntries reads them, and refuses a
module it does not follow. air_arguments_test checks it over the oracle
probe's library (build/oracle_reflection.metallib, which `make test` now
builds), and spoils its bytes 4000 times to check it fails cleanly.
Car 13's stack: resolved against c13-answers' function-constant reader
(69d1cd068, f59eeb440): RgfxAirArguments.cpp keeps both readers, the constants
(constantType, readConstants) and this commit's whole nodes, which take a
function_constant predicate's name from the constant's node at operand 2 as
readConstants does; the Makefile builds both test libraries (AIR_OLD_LIB,
ORACLE_REFLECTION_LIB) and links the AIR test with RgfxFunctionConstants.o;
air_arguments_test's header names both.