Commit Graph
477 Commits
Author SHA1 Message Date
Anees Iqbal 4e1f847978 🐛 Answer nil for a device texture of more bytes than maxBufferLength
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.
2026-11-07 11:07:32 -08:00
Anees Iqbal 8b59610c48 ✅ Measure where Metal answers nil for a large texture
The bundle sends a texture create to the host posted and answers a texture
whatever the host's platform then does with it, so a texture Metal answers nil
for by its descriptor alone has to be answered nil in the bundle. The
descriptor's rules were copied on 11-05 (Q24); what Metal answers for a texture
too large to make had not been measured.

oracle_texdesc's 13 new cases are RGBA32Float textures within every rule, of
2 GiB to 8 TiB, at the device's creator; each prints the size
heapTextureSizeAndAlignWithDescriptor: answers, and a made one its
allocatedSize and the process's footprint. On macOS 26.7.1 the Intel 630 makes
2 GiB, its maxBufferLength, and answers nil a row taller; the AMD 5300M makes
16 GiB and answers nil from 20 GiB, its maxBufferLength 3.2 GB. A texture that
is made commits no memory. The M3 Max answers nil for the 128 GiB and 8 TiB
ones. dgpu-oracle.md, Q24, records the table.
2026-11-07 11:07:32 -08:00
Anees Iqbal 1c77a6d25a ✅ Measure a long command buffer's GPU times on x86 Macs
A command buffer the host commits in parts answers GPU times from its first
part's start to its last part's end, which hold the host's walk between parts:
game_6000's gpu_p50 went from under 1 ms to 5.4-8.5 ms with car 12's split.
What a Mac answers for one long buffer had not been measured.

oracle_cmdbuf's new gputimes case commits K encoders of about 0.5 ms each (K
= 1, 8, 32; compute and render passes) in one buffer, and the same encoders
one buffer each, back to back. On both x86 Macs (macOS 26.7.1, the AMD Radeon
Pro 5300M and the Intel UHD Graphics 630) one buffer spans its encoders' GPU
time summed, as the back-to-back buffers do, within the GPUs' clock ramp; the
CPU's encoding time never counts; GPUStartTime comes 0.08 to 0.40 ms after
the commit. dgpu-oracle.md, Q7, records the table.
2026-11-07 11:01:27 -08:00
Anees Iqbal 450661e889 🐛 Answer nil for a texture buffer past its buffer's bytes
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.
2026-11-07 09:11:16 -08:00
Anees Iqbal 1a7b309917 🆕 Answer a function's reflectionWithOptions:
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.
2026-11-07 09:11:16 -08:00
Anees Iqbal 04b1282f7f 🐛 Read an OpenCL library's arguments from its kernels' metallib
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.
2026-11-07 09:11:16 -08:00
Anees Iqbal 55bbbd0f82 🆕 Make texture buffers over a buffer by the public form
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.
2026-11-07 09:11:16 -08:00
Anees Iqbal fbd4b951fe 🐛 Size a GL buffer's pointee from its LLVM type, not its name
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.
2026-11-07 09:11:16 -08:00
Anees Iqbal 8f748fa587 🆕 Trace a GL context's textures and samplers in gl_inject
On the RTX 5080 guest, ten of gl_cases' texture cases sample zeros on our
device (m3-max-3831) while the same lowered shaders pass over the Intel 630's
textures on the oracle. GL_INJECT_TEXTURES=1 writes the first calls of each kind
that make, fill, view, copy into and bind the device's textures and samplers,
with their arguments and each object's number, so a guest run shows which step
loses the texels.
2026-11-07 09:11:16 -08:00
Anees Iqbal 402b7463a9 🐎 Restore the write-combined spans: they take, and the encode was theirs
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.
2026-11-07 08:27:28 -08:00
Anees Iqbal c08c19f377 🔥 Drop the write-combined spans: no user mapping of the region can be
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.
2026-11-07 08:27:28 -08:00
Anees Iqbal bcd75ba81e ✅ Give the heap tests views a heap of Metal's page fits
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.
2026-11-07 08:27:28 -08:00
Anees Iqbal b396a9b33a ✅ Refill the write-combined test's memory before its second region
The test's first region zeroed its rings in the same memory, so the second region's
check that its ring block's head is untouched read those zeros.
2026-11-07 08:27:28 -08:00
Anees Iqbal fac9e06ca7 🐎 Map the bytes the guest only writes write-combined
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.
2026-11-07 08:27:28 -08:00
Anees Iqbal ae0edc382e 🐎 Lay slabs in plain pages where no superpage is left
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.
2026-11-07 08:27:28 -08:00
Anees Iqbal 3e5d0d255f 🐛 Take macOS 27's OpenCL containers too
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.
2026-11-07 07:57:22 -08:00
Anees Iqbal d4b0e099c5 🆕 Send OpenCL programs' kernels to the host as a metallib
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.
2026-11-07 07:57:22 -08:00
Anees Iqbal 7e043d48a2 🐛 Give GL buffer arguments the address space and size Metal writes
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.
2026-11-07 07:57:21 -08:00
Anees Iqbal 3c3b2a5397 🐛 Declare the bit-18 rule outside RgfxBuffer's interface
3564633f2 declared kRgfxOptionBit18 and RgfxMakesNoResourceOf inside the
@interface block. clang refuses a variable or a function definition
there, so the bundle did not build. Both now come before the interface.
2026-11-07 07:04:00 -08:00
Anees Iqbal 3564633f28 🐛 Make no buffer or texture with resource option bit 18
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.
2026-11-07 07:00:29 -08:00
Anees Iqbal 11672a2a5f 🐛 Carry only the options the host takes on heap and buffer creates
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.
2026-11-07 06:57:51 -08:00
Anees Iqbal a756b25f60 🆕 Add cl_probe, the OpenCL devices a guest sees and a run on each
cl_probe lists every OpenCL device of every platform. On each one it
builds and runs c = a + b over 1024 floats and checks what it reads back.
It exits 0 when every run passes.

The GL renderer that an accelerator's IOGLBundleName names has compute
entry points of its own, so naming it on our accelerator may change what
OpenCL finds. The guest checks run cl_probe before and after that change.
On the x86 oracle it finds the CPU, the Intel 630 and the AMD 5300M, and
all three runs pass (macOS 26.7.1).
2026-11-07 06:57:51 -08:00
Anees Iqbal 78b20b87a9 🆕 Dump each GL render pipeline's state from gl_inject
With GL_INJECT_DUMP=DIR, gl_inject already writes every library the class
makes from bytes. It now also writes each render pipeline to
DIR/pipeline-N.txt: whether it was made, the numbers of the libraries its
two functions came from, and its descriptor's state. That state is the
vertex attributes and layouts, color attachments, depth and stencil
formats, sample count, alpha to coverage, rasterization and topology.

These dumps let the GL renderer's own pipelines be compiled off the guest,
against the Vulkan host's runtime, without a boot. That is how the
lowering's module rules were found.
2026-11-07 06:57:51 -08:00
Anees Iqbal fb8a9078c3 🐛 Make the GL generator's modules what one Metal compile writes
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).
2026-11-07 06:57:51 -08:00
Anees Iqbal 9027ae34bf 🐛 Answer the GL renderer's depth/stencil state queries
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.
2026-11-07 06:57:51 -08:00
Anees Iqbal ab4ee7c149 ✅ Compare the GL SPI test's passes without their fences
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.
2026-11-07 06:57:50 -08:00
Anees Iqbal f2c1b62ccc 🐛 Answer the texture, buffer and encoder SPI the GL renderer sends
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.
2026-11-07 06:57:50 -08:00
Anees Iqbal 35eb641eed 🆕 Let gl_inject answer a device's vendorName
The system's GL renderer picks its per-vendor settings by the Metal device's
vendorName, and ends the process on a name it does not know. With
GL_INJECT_VENDOR=NAME, gl_inject makes the device class answer NAME, so each
vendor's settings can be tried on the reims-graphics device in a guest.
2026-11-07 06:57:50 -08:00
Anees Iqbal 9f12048105 🆕 Add gl_cases, and logging and dumps to the GL tools
gl_cases draws 29 GL features apps use into a framebuffer object and checks
each centre pixel against the GL spec. It runs in a 4.1 core context, and the
legacy cases in a legacy one. The same cases on Metal's own GL path and
through the bundle's lowering (gl_inject) must give the same pixels. That is
how the lowering's two link and reflection failures were found.

gl_inject now logs each render pipeline the device makes, with its functions
and its error, when GL_INJECT_LOG=1 is set. It writes each library made from
bytes to a directory when GL_INJECT_DUMP is set. gld_lower's new dis mode
prints a .metallib's bitcode as the system's LLVM reads it.
2026-11-07 06:57:50 -08:00
Anees Iqbal c53f0986e1 🐛 Name GL stage outputs and integer varyings as Metal links them
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.
2026-11-07 06:57:50 -08:00
Anees Iqbal efd1f714ea 🆕 Print what the GL renderer asks of each Metal device in gl_probe
The renderer sets its features from the device's vendor and support
queries as it makes its own device, so the probe prints each device's
answers to compare a guest's device with an x86 Mac's.
2026-11-07 06:57:50 -08:00
Anees Iqbal ad63abb2fc 🆕 Add gl_window, an on-screen GL context as a windowed app makes it
It draws gl_probe's triangle into an NSOpenGLView for N frames, through
the window's surface or a layer-backed view, and checks the back
buffer's pixels: what the renderer needs of the device for on-screen
contexts shows on a guest.
2026-11-07 06:57:50 -08:00
Anees Iqbal 0183b141ee 🆕 Add gl_inject, the tree's GL members over an installed device
A library inserted into one process gives the device installed in a
guest the GL members of this tree's sources, so the GL renderer can be
tried on it before the kext carries them, and on another Mac's Metal
device (GL_INJECT_CLASS) to check the lowering against Metal's own.
2026-11-07 06:57:50 -08:00
Anees Iqbal 03d0d1bb65 🆕 Make the device's GL shaders libraries of AIR it lowers
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.
2026-11-07 06:57:50 -08:00
Anees Iqbal 603f1f18a9 🆕 Make gld_lower's lowered AIR compile and draw on Metal
The system's LLVM writes bitcode for an Apple triple inside the same
wrapper a .metallib's bitcode section carries, so the section was
wrapped twice and Metal's compiler service aborted reading the module
(an interrupted connection to the caller). gld_lower now unwraps the
writer's output first. With that, both GL shaders of gl_probe's triangle
make a render pipeline, and a draw with it gives the expected pixels.

It also reads the bitcode back and runs the verifier, assembles IR text
(the writer's check apart from the GL code generator), edits the module
text through GLD_REPLACE, sets a vertex descriptor (GLD_VERTEX) and the
descriptor's openGLModeEnabled (GLD_GL_MODE), and draws (GLD_DRAW).
2026-11-07 06:57:50 -08:00
Anees Iqbal 05ef25f2cd 🆕 Add gld_lower and gl_redirect, the GL lane's proof tools
gld_lower lowers the GL IR AppleMetalOpenGLRenderer hands a Metal device to
AIR through the GL code generator the system ships beside the renderer, and
wraps it in a .metallib of one function, as the layout metal writes for a
macOS 11 target. gl_redirect, inserted into one process, makes that process's
OpenGL see an IOGLBundleName on an accelerator, so the renderer can be tried on
a device before a kext names it. gl_probe -x now also traces the plugin data,
the pipelines and their reflection the renderer asks for.
2026-11-07 06:57:50 -08:00
Anees Iqbal 90efb369cf 🆕 Add gl_probe, what OpenGL gives a guest
The OpenGL lane needs to see what a guest's GL apps get from our device:
which renderers CGL lists, which one an accelerated context lands on, and
whether a clear, a shaded triangle and an IOSurface-backed framebuffer draw.
-x and -X dump the GL IR AppleMetalOpenGLRenderer hands the device, which
the lane's design reads to decide where GL shaders are lowered.
2026-11-07 06:57:50 -08:00
Anees Iqbal 53964346f8 ✅ Give the other stitchable tests' rings room for two libraries
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.
2026-11-07 04:54:29 -08:00
Anees Iqbal 1932512d2f ✅ Give the stitched-shadows test's ring room for its libraries
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.
2026-11-07 04:54:29 -08:00
Anees Iqbal 5662c5af54 ✅ Test that Metal links a stitched call of an extra argument
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.
2026-11-07 04:54:29 -08:00
Anees Iqbal 20f40016a1 🐛 Link the stitch probe's fused function as MPS links its own
The probe ran its stitched function through a visible function table, which
the bundle does not support (function pointers), so its run step failed
whatever the stitch did. MPS links its stitched functions by declaration
(MTLLinkedFunctions), as its reduce_stitched kernel does, so the probe's
kernel now declares `fused` and links it the same way.
2026-11-07 04:54:29 -08:00
Anees Iqbal 8228bedd37 🐛 Give functions made with constant values a shadow to stitch
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.
2026-11-07 04:10:56 -08:00
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