Commit Graph
435 Commits
Author SHA1 Message Date
Anees Iqbal 892a0eefb0 🐛 Make BC textures over a surface where they answered nil
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.
2026-11-05 21:59:37 -08:00
Anees Iqbal 6813776e3c 🐛 Size a surface texture's CPU access in its own format's texels
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.
2026-11-05 21:59:37 -08:00
Anees Iqbal 9beab79d22 📝 Number texture-nil's oracle sections Q24 and Q25 after shared events
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.
2026-11-05 21:59:37 -08:00
Anees Iqbal 31115cc8df 🐛 Answer nil for a block-compressed texture over a buffer
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal 476bafaad7 🐛 End every texture creator at the x86 Macs' descriptor validation
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal 6bffecada8 🆕 Add oracle_nilbind, what a command buffer does with nil objects
A command buffer naming an object whose posted create the host refused stands
the object in as nil. What Metal does with nil there (a draw or dispatch
reading or writing a texture, sampler or buffer bound nil, a pass with a nil
attachment, a nil pipeline state, a blit from or to nil) is measured here on
the x86 Macs and the M3. [ci skip]
2026-11-05 21:59:36 -08:00
Anees Iqbal 77f12120d4 🐛 Answer nil for a texture with no GPU address left
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal 07bae0cdc9 🆕 Add oracle_texdesc, the descriptors each texture creator refuses
What the device's, a Private heap's and a Shared buffer's texture creators
make, answer nil for, or end the process at, by the descriptor alone. The
bundle's creators copy the x86 Macs' answers, and oracle_surftex measured
them only over an IOSurface. [ci skip]
2026-11-05 21:59:36 -08:00
Anees Iqbal d4398c6465 🆕 Hand shared events to other processes, as Metal does
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal fa37211c2f 🐛 Keep oracle_events' answers through a call that never returns
The connect case's calls each run on a thread of their own, and a call that
never returns keeps its detail text: it is on the heap, not in a block's
captures, which clang refuses for an array. The probe links IOKit for them, and
IOConnectAddClient, which takes the port as its argument, never its
destination, now runs first, so a port the next calls kill the process on is
still answered.
2026-11-05 21:59:36 -08:00
Anees Iqbal 13e04ee270 🆕 Ask oracle_events about a killed exporter and foreign ports
The third round of the probe: an event made from a port whose exporter was
killed, before and after the kill, and what IOKit's object and connection calls
answer for a connection, a task port and a port the caller receives, which the
bundle's own port checks have to match.
2026-11-05 21:59:36 -08:00
Anees Iqbal ff95cf3345 🆕 Ask oracle_events what a handle's make sends its event
The second round of the probe: a handle made by initWithSharedEvent: over an
object of the probe's own, which logs what the handle asks of it, sent across
XPC as a real handle is, and the refs a port held by handles and events made
from them takes, freed as the probe's events are, by the ownership the
selectors' names give.
2026-11-05 21:59:36 -08:00
Anees Iqbal 9dfaa621e5 🆕 Add oracle_events, a probe of shared events across processes
What a Mac's Metal answers for a shared event used by two processes: its
eventPort and handle, the events made back from either, their coding, and
the value, listeners and GPU waits two holders share. It runs unchanged on
the guest's device, so it is the guest's check of the same.
2026-11-05 21:59:36 -08:00
Anees Iqbal 57e2bcce59 🐎 Find a library's function and its bitcode by name in O(1)
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal e4d8932355 🐛 Count a module's decoded code against the AIR cache's budget
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal 80d9f171bc ✅ Time the busy buffer in the behind submit probe
submitted.tiny.behind's rounds took twice as long on car 13's tip as on car
12's (n 8059-8955 against 14742-20172 per 5 s), while its ret, the tiny
buffer's commitAndWaitUntilSubmitted, is at most about 70 us of a round.
The case now also prints the busy buffer's commit to its GPUStartTime, its
GPUStartTime to its GPUEndTime and the whole round. Those split the extra
time between the host's submission, the GPU's fills and the completions.
2026-11-05 21:59:36 -08:00
Anees Iqbal 4ed0e6923a 🐎 Schedule a buffer with no scheduled handler where it is seen
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal 09eb85c73c ✅ Time the guest's buffer scheduling and completion
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal fadd0bbb10 ✅ List only the imageblock entry points as unread in the AIR 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.
2026-11-05 21:59:36 -08:00
Anees Iqbal bf214206db ✅ Check specialised reflections against Metal's answers
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal 0932f1cd0c 🐛 Reflect nested argument buffers, tables and colour reads
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal 3f9781016d ✅ Measure argument buffers' further members
pipeline_reflection_check now also makes c_nested_more, an argument buffer
of C arrays of samplers and of pointers to argument buffers, a struct of
members that holds one and a C array, and a C array of those structs, and
c_ab_tables, function tables and acceleration structures as an argument
buffer's members, so that Metal's answers for them are measured on the
x86 Macs alongside the kinds c_nested and c_tables measure.
2026-11-05 21:59:36 -08:00
Anees Iqbal 3b05f264e2 🐛 Reflect pipelines as their function constants specialise them
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.
2026-11-05 21:59:36 -08:00
Anees Iqbal 6eaf530e66 ✅ Measure reflection's unmeasured kinds in the pipeline check
pipeline_reflection_check gains the cases the bundle's pipeline reflection
answers nil for: nested argument buffers and their arrays, function and
intersection tables, acceleration structures, further texture types, an
imageblock, a 64-bit atomic texture, framebuffer fetch and tables in a
fragment function, and functions whose binding index, predicates and
reads function constants decide. With -v a case ours does not make
prints Metal's instance variables too, and a case Metal makes no
pipeline of prints its error without counting as a difference.
2026-11-05 21:59:36 -08:00
Anees Iqbal 50429f473a 📝 Say how much memory the AIR module cache holds when full [ci skip]
Measured over 2,000 modules of macOS 27's frameworks: a kept module holds
about 1.5 times its bytes in use. Comment only.
2026-11-05 21:59:36 -08:00
Anees Iqbal dff5d2d43a 🐎 Read each AIR module once a process, for every library
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).
2026-11-05 21:59:36 -08:00
Anees Iqbal b840c3f7f3 ✅ Read every function of the committed metallibs in the AIR 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.
2026-11-05 21:59:36 -08:00
Anees Iqbal 0f98581125 🐛 Write a buffer's copies back as its completion is taken
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.
2026-11-05 21:59:35 -08:00
Anees Iqbal 1cbd3e280c 🐛 Lock an IOSurface before its copy's view lock, never under 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.
2026-11-05 21:59:35 -08:00
Anees Iqbal 3a127e823d 📝 Record Macs' mesh pipeline answers and the mesh wire [ci skip]
dgpu-oracle.md Q22 holds oracle_mesh's and base_answers_probe's measurements
on the 5300M, the Intel 630 and the M3 Max, each classified, and what the lane
answers. design.md names FEATURES_LO bit 25 and the mesh create in the wire's
table, and the oracle README lists oracle_mesh.
2026-11-05 21:59:35 -08:00
Anees Iqbal 7defb7f533 🆕 Make mesh render pipelines and draw them, as an x86 Mac's Metal
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.
2026-11-05 21:59:35 -08:00
Anees Iqbal 9e2129f57c 🆕 Probe what a device answers for mesh pipelines and draws them
oracle_mesh makes mesh render pipelines of each descriptor shape an app sets
(object functions, the maxima, the payload, required sizes, no fragment or no
mesh function, functions of another stage, archive misses, indirect command
buffer support), and prints the state's answers. It draws each mesh draw form
into a target and prints which threadgroups of what grid ran, and makes
indirect command buffers of the mesh command types and executes a mesh draw
from one. The mesh lane matches the x86 Macs' answers it measures
(docs/graphics-kext/dgpu-oracle.md, Q22).
2026-11-05 21:59:35 -08:00
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 320b9e5314 🐛 Answer pipelines' reflection as an x86 Mac's Metal
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.
2026-11-05 21:59:34 -08:00
Anees Iqbal b978f7b6f7 🆕 Read an entry point's AIR nodes whole
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.
2026-11-05 21:59:34 -08:00
Anees Iqbal 69d473a437 🆕 Add an oracle probe of pipelines' reflection
oracle_reflection makes render, mesh and compute pipelines of
oracle_reflection.metal's functions on a device, with each pipeline option,
and prints the reflection each creator answers: every getter of every
object, recursively, and with ORACLE_IVARS set every instance variable. Its
walker is oracle_walk.h, which the bundle's pipeline_reflection_check shares.

The functions cover buffers of each value type, structs and arrays of them,
argument buffers, threadgroup memory, textures of each type and access,
samplers, arguments the function never reads or a function constant gates,
stage inputs, built-ins, outputs and payloads. It measured the x86 Macs'
answers the bundle's pipelines' reflection is to equal.

Car 13's stack: resolved guest/bundle/tools/oracle's README.md and build.sh
against c13-contract's oracle_surftex and the oracle_bundle cases of
c13-answers and c13-wire-gaps: kept every probe's row and build.
2026-11-05 21:59:34 -08:00
Anees Iqbal 9a9077389c 🐛 End the process at every two-plane texture over a surface
The bundle made two-plane Y'CbCr textures over a surface as the M3 Max does
(dgpu-oracle.md Q13, read as class 2). The lane imitates the x86 dGPU Macs,
and both end the process there: oracle_surftex's third round measured
"MTLTextureDescriptor has invalid pixelFormat (N)." on the AMD 5300M and the
Intel 630 under macOS 26.7.1 at every two-plane Y'CbCr format (500, 502, 503,
505 to 510, 520, 522, 523, 525 to 530, 540 to 545) and at the extended-range
RGB10A8_2P_XR10 and its sRGB twin (550, 551), over either plane of a 420v
surface, a one-plane surface and a surface without planes. Where both agree,
their answer is the lane's contract; the M3, which makes them all, is outside
its envelope. Q13 records the reversal.

What changes for the guest: newTextureWithDescriptor:iosurface:plane: ends
the process at a texture of any of these formats, at any size, with the x86
Macs' words, sending the host nothing. The odd-extent render target rule
folds into it. No code of the bundle makes such a texture: the video decoder
lands pictures through R8, RG8, R16 and RG16 textures over the planes. The
one-plane 4:2:2 formats (GBGR422, BGRG422) are made as before.

Test: test_invalid_surface_textures_end_the_process holds a death per format
over the luma plane, 500 over the chroma plane and over a surface without
planes, and passes for the planes' own formats and the 4:2:2 ones; it fails
at surface-ycbcr-flat with the rule stubbed out.
2026-11-05 21:59:34 -08:00
Anees Iqbal d9f8a77dcc 🆕 Probe every two-plane format over a surface's plane
oracle_surftex's third round asks for a texture of each two-plane format,
the Y'CbCr ones of 4:2:0, 4:2:2 and 4:4:4 chroma and the extended-range one,
over a 420v surface's luma plane, and of format 500 over its chroma plane and
over a one-plane surface: what the x86 Macs answer for the formats the bundle
had measured only at 500.
2026-11-05 21:59:34 -08:00
Anees Iqbal 2cfd44fb18 🐎 Lay a one-level Managed 2D array over its CPU copy
On a GPU that shares the CPU's memory the host laid a Managed texture over
its CPU copy only where it was a one-level 2D texture: every 2D array kept two
copies there, the guest's CPU copy and the platform's own texture, so it took
its size twice in memory, each replaceRegion: was copied again on the host,
and the guest's getBytes: of it waited for a device copy. The platform makes a
one-level 2D array over a buffer too, by the linear SPI, which lays each slice
at its rows' bytes rounded up to 128 (measured on the M3 Max; the Vulkan
platform's runtime alike, array_over_host_memory_is_metals), and a CPU copy's
rows are multiples of 256 bytes, so its slices lie where the copy's layout
puts them.

For the host: on unified memory MANAGED_TEXTURE_CREATE of a one-level 2D
array of a linear format is newLinearTextureWithDescriptor: over the CPU
copy's buffer, its rows and slices the layout's, in place of a
newTextureWithDescriptor: beside it; TEXTURE_REPLACE_REGION and
synchronizeTexture: of it copy nothing. A texture of the one-copy shape whose
texture over its buffer the platform refuses is logged once. On a GPU of its
own memory nothing changes but where it has no memory for the GPU's copy,
where such an array now takes the one-copy form too.

For the guest: where the device answers hasUnifiedMemory yes, getBytes: of such
an array reads its CPU copy, as a one-level 2D texture's does, with no device
copy (rgfxManagedLiesOverCopy). A mipmapped texture, a cube, a 3D texture and a
block-compressed one stay two copies: no texture over a buffer has their shape,
and without the CPU copy an upload would be a staging blit the call waits for,
340 to 420 us a call where a Managed one's is 2 to 4 (dgpu-oracle.md Q17).

An older bundle on this host reads such an array through a device copy, which
reads the one copy: correct. This bundle on an older host would read a CPU
copy the host keeps apart: the two ship together.

Car 13's stack: resolved a comment in shell_tests.mm over
test_managed_texture_reads_on_unified_memory against c13-answers (16c2a86ad):
kept this commit's 2D-array wording and c13-answers' virtualAddress sentence.
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 938f3e7e74 🐛 Hold the functions given in a function array's library
newLibraryWithFunctionArray:error: went through Metal's own library of the
functions' shadows (46b5a4d66), but Metal's function-array library holds no
bytes to make ours over, so the guest got nil. Both x86 Macs (AMD 5300M and
Intel 630, macOS 26.7.1, oracle_bundle libforms2 and libforms3) make a library
that holds the given functions themselves, which a guest now gets:

- each function by its name, the very object given, whatever constants or
  descriptor ask for it; nil, or MTLLibraryErrorDomain 5 "Function NAME was
  not found in the library", for a name it lacks;
- its functionNames in the reverse of the order given;
- type Executable, no install name, label, reflection or extern functions,
  and serializeToURL:error: refused with "MTLLibrary is not formatted as a
  MetalLib file.";
- two functions of one name: nil and code 1 "function names must be unique";
- an empty array ends the process with Metal's assertion words.

Nothing goes to the host. The test of the old route is replaced by one of
these answers, with the empty array's death.
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 b08d7badba ✅ Pin x86 Metal's rule for which archive slices it reads
Both x86 Macs read a binary archive's slice bytes only where the file holds the
device's own slice (its CPU type and subtype): then that slice and the AIR
slice are read, and either one junked is "an invalid format"; a file whose
slices are none of the device's is an archive of no keys, junk or not (AMD
5300M and Intel 630, macOS 26.7.1: oracle_bundle archive.slices, 21 files of
recombined and junked slices). No Metal slice is the device's, whose archives
are its own format, so the bundle, which never reads a Metal archive's slices,
already answers so; a junk AIR slice beside another GPU's slice now has a test.
2026-11-05 21:59:34 -08:00
Anees Iqbal 52a2fe4227 🎨 Answer newBufferWithIOSurface: nil as x86 Metal does, unlogged
Both x86 Macs answer nil for a buffer over an IOSurface (the AMD 5300M and the
Intel 630 under macOS 26.7.1, for BGRA and two-plane 420v surfaces:
oracle_bundle iosurf.buffer), so the device's nil is Metal's answer and no
longer an unsupported member: it logs nothing. The guest sees the same nil.
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 69baa95133 🆕 Probe IOSurface texture properties, encoder indices and array libraries
oracle_bundle's second round for the bundle's remaining divergences: what
copyIOSurfaceSharedTextureProperties: answers across formats, sizes, levels and
slices, an encoder at a function's plain buffer and at an index it has no
buffer at, setting a depth/stencil state or nil into an argument buffer, and
what a function array's library answers.
2026-11-05 21:59:34 -08:00
Anees Iqbal 0ae3bc5cbd 🐛 Make libraries of function arrays and packages as x86 Metal does
Guest-visible: an app's newLibraryWithFunctionArray:error: now answers a
library of the visible and stitchable functions given, where the bundle
answered nil and MTLLibraryErrorUnsupported. Both x86 Macs make one (AMD 5300M
and Intel 630, macOS 26.7.1: oracle_bundle libforms). It is Metal's own library
over the functions' shadows, made ours over its bytes, as the bundle's links
and stitches are.

newLibraryWithMetalPackageURL:error: and newLibraryWithMPSGraphPackageURL:
name:error: now run Metal's own reading of the package, the base class's, and
make a library it answers ours over its bytes, as a source compile is. So a
refusal is Metal's own: both x86 Macs answer MTLLibraryErrorDomain 1 "Invalid
metal package" for a missing path and a .metallib, where the bundle answered
code 1 in its own words, and MTLLibraryErrorDomain 6 "failed to open MPSGraph
package", logging "Error: did not find file at url", where the bundle
answered code 1.
2026-11-05 21:59:34 -08:00