Commit Graph
79 Commits
Author SHA1 Message Date
Anees Iqbal 32dd62ef28 🐛 Make a GL tessellated draw's kernel one Metal compiles
The renderer makes a tessellated draw's vertex and control shaders one kernel
that takes the draw's vertices as a patch control point input, and makes its
compute pipeline under a stage input descriptor. Metal compiles that input in
no kernel (m3-max-30197): its own devices define the input's control point
function from the descriptor. The device's pipeline of the kernel was refused,
and the renderer drew the draw's vertex and control stages in software.

A kernel variant with the input now keeps its module's text, and its compute
pipeline is made of the kernel made one without the input under the
pipeline's descriptor, once per descriptor: a wrapper kernel of the same name
takes the buffers the fields read and the stage input region's origin, and
the control point function, defined in place of its declaration, fetches each
field as Metal's [[stage_in]] fetch does. The pipeline answers the variant's
reflection. GL tessellated draws run on the GPU where the renderer drew them
in software.

The fetch matches the M3 Max's own [[stage_in]] kernels bit for bit, for every
attribute format and step function (gl_tests' stage input oracle,
m3-max-30314), which measured two of its conversions: Int1010102Normalized's
10-bit components are c times the float nearest 1/511, and RG11B10Float's
NaNs are 0x7fc00000.
2026-11-14 15:16:50 -08:00
Anees Iqbal 1fc43b257c 🐛 Refuse a function whose constants overlap its arguments
Metal refuses function constant values that put two present arguments of one
argument table at overlapping locations. It refuses them where it makes the
function, by values, by a descriptor or with a completion handler, with
MTLLibraryErrorDomain 3 and one line per such argument (measured:
oracle_overlap, the 5300M, the 630 and the M3 Max, the same). The bundle made
the function and posted its pipeline, and the host's compile then refused that
create (OverlappingArgument). The guest got a pipeline whose work the host
drops.

The bundle now gives Metal's refusal in newFunctionWithName:constantValues:,
which every other way reaches, with no call to the host. It reads each
argument's predicate, index and count from the function's AIR, with the
module's initialisers run on the values. It looks only where the arguments'
declared locations can overlap at all. Where the AIR does not tell, the host
still refuses the pipeline, as before.

For the guest: such a newFunction now answers nil and Metal's error, and no
pipeline create of it reaches the host. The shell test compares each way's
answer with this Mac's Metal over oracle_overlap.metal.
2026-11-13 08:43:21 -08:00
Anees Iqbal f187cc950f 🆕 Add encode_probe, the hot encoder calls' cost in ns a call
Nobody knows what the guest's Metal bundle costs the guest's CPU per Metal
call against a real Mac's Metal: the host's per-draw cost is measured, the
guest's share is not. encode_probe times runs of one encoder call each
(buffer, bytes, texture, sampler and pipeline sets, draws, compute sets and
dispatches, encoder make and end, command buffer make and commit) and prints
ns a call from wall and thread CPU time, so a guest and a real Mac run the
same binary and compare call by call.
2026-11-12 16:14:00 -08:00
Anees Iqbal 987618f7ca 🆕 Add icb_probe, the cost of CPU encodes into ICBs and IOSurfaces
The guest's CPU encodes into an indirect command buffer write its slots in a
block of the device region, which the guest's kernel maps uncached, as is a
surface's copy where the host takes it not in place. The probe times them a
command at a time against a real Mac: an ICB of draws, of inherited draws and
of dispatches, encoded again each repetition as a renderer does each frame
and then executed and checked, a range reset, and a CPU write of an IOSurface
read by the GPU, at rows every host takes in place and at rows a host whose
linear textures align to 128 bytes or more copies.
2026-11-12 15:33:37 -08:00
Anees Iqbal 864a468059 🆕 Make residency sets on the arm64 device
What changes for the guest: on an arm64 guest, newResidencySetWithDescriptor:
error: now makes a set and sets the error out to nil, where it answered nil and
an error, and allocResidencySet makes its object. Apple silicon's Metal makes
one on macOS 15 and later, and apps built for it (game ports, engines, and
QuartzCore's CAMetalLayer.residencySet on macOS 26) use it; some abort at nil.
The x86 guest answers exactly as before: nil, its error out set to nil, as the
x86 Macs answer.

The device keeps every allocation resident, so a set is guest-side
bookkeeping and sends nothing to the host. It answers what the M3 Max's set
answers (tools/oracle/oracle_residency): adds and removes pending until a
commit, a pending remove still counted, the set holding its allocations,
allocatedSize the memory the last commit left, each piece once (a heap's
resources their heap, a view its texture, a texture over a buffer its buffer),
a nil allocation ending the process. Two answers differ on purpose: the label
is the descriptor's, as Metal's documentation gives it (the M3 answers nil),
and a small buffer counts its own pages, not a shared 128 KiB block.

The arm64 queue holds its sets in a counted set and the command buffer holds
the sets it uses, and those its render and compute encoders are given, until
it completes, as Metal's do; a nil set raises the counted set's exception
there, as on the M3, so useInternalResidencySet: of nil now raises on arm64.
The register lists the set's members, and the old residency entries say they
describe the x86 bundle.
2026-11-12 10:14:40 -08:00
Anees Iqbal 5fc2e3c20c 🐛 Read a library URL of no scheme as the file at its path
newLibraryWithURL:error: read its URL through Foundation's URL loading, which
refuses a URL of no scheme (NSURLErrorDomain -1002), and answered nil and
NSCocoaErrorDomain 256. Espresso names each of its kernels' libraries by such
a URL (-[EspressoMetalKernelsCache lazySetup]), so on the device it had no
kernel library and every GPU Vision and Core ML request threw: Geekbench 7's
workload 302, Photos, FaceTime's and Continuity Camera's effects, on every
host GPU.

The device now opens the file at the URL's path, whatever its scheme, as Metal
does, and answers Metal's errors for a file it cannot read
(src/RgfxLibraryFile.*). Measured with a .metallib of our own at each URL form,
alike on macOS 26.7.1's AMD Radeon Pro 5300M and Intel UHD 630 and macOS
27.0.1's M3 Max (jobs m3-max-20286, 20287, 20288):
  - a URL of no scheme, absolute, relative to the current directory or with
    percent escapes, a file URL, one relative to a file URL, and an http or
    other scheme's URL of a file's path: the file's library;
  - no file there: MTLLibraryErrorDomain 6, "library not found", for a file
    URL too, which answered Foundation's read error before;
  - a URL of no path (data:): MTLLibraryErrorDomain 6, "Invalid file url";
  - a file it may not open: MTLLibraryErrorDomain 1, "metal library file PATH
    failed to open with error: Permission denied";
  - a directory or an empty file: MTLLibraryErrorDomain 1, "Invalid library
    file (unexpected end of file)".
A URL of another scheme is no longer fetched through URL loading.

The other URL readers do not read this way: a binary archive's descriptor URL
must be a file URL, the IO handles take Metal's own check of a file URL, and
dynamic libraries are not supported. The shell tests read each URL form, and
compare each answer with this Mac's Metal's.
2026-11-12 03:43:38 -08:00
Anees Iqbal 72503e9c5d 🐛 Read OpenCL kernels' by-value arguments, each function on its own
The bundle's AIR argument reader did not know `air.constant`, the node Metal's
compiler writes for an OpenCL C kernel's argument passed by value (a scalar, a
vector, a struct or a union), bound at an `air.location_index` among the
buffers. It took the unknown binding as one that may be a texture, so the
kernel's arguments did not read, and functionsOf() then dropped every entry
point of the module. Nearly every OpenCL kernel takes a value, so the guest
logged "no arguments read (its module did not read)" for each of them, and
every texture with ShaderWrite usage it bound was taken as written: a cost in
surface writes, never a wrong result.

Now a by-value argument is read as a buffer at its index, of the access its
node names (none): every kernel of the audit's clprobe reads, k_buffers and
k_struct among them. And an entry point whose arguments do not read is listed
with `argumentsRead` false beside the module's other entry points, which keep
their own answers; the library logs "an argument of it is not one the reader
follows" for it alone.

Read from this Mac's compile of OpenCL C programs of our own (macOS 27.0.1,
the M3 Max), as LLVM's text form prints the modules. The tests read every
kernel of the CL mode tests' programs and of a new one of every value kind,
and a module of every entry point of tests/air_arguments.metal (the
compiler's .air) with one entry point spoilt.
2026-11-12 03:43:38 -08:00
Anees Iqbal da4748c0f1 🐛 Log the bundle's os_log lines on a subsystem of their own
Every os_log line of the Metal bundle went to OS_LOG_DEFAULT, which has no
subsystem, so no `log config` mode could keep its debug lines: on macOS
26.7.2 the system mode persists none, `log config --process PID` refused
the pid, and a debug stream dropped every line under load (26.7.2, 12.7.6).
The resource-wait counter ("RGFX: resource waits so far", RgfxResource.mm)
could not be read there.

The bundle's os_log lines now go to one os_log object, made once a process
with os_log_create on the subsystem ai.aneesiqbal.reims-graphics, the
bundle's CFBundleIdentifier, and the category "bundle" (RgfxLog.hpp),
defined outside ARC so nothing releases it. In the guest each line keeps
its text and level and now carries that subsystem, so `log config
--subsystem ai.aneesiqbal.reims-graphics` sets the level its lines are kept
and persisted at, on every release. Reads that match a line's message see
the same lines. Its NSLog lines, at the default level the log store keeps,
are as they were.

tests/bundle_log_check.sh, in `make test`, keeps the bundle off
OS_LOG_DEFAULT (no _os_log_default import), its log object linked rather
than left to -undefined dynamic_lookup, and the subsystem equal to
Info.plist's identifier.
2026-11-12 02:35:28 -08:00
Anees Iqbal 8c61d99be4 🐛 Read a buffer's address space from its parameter before macOS 13
The Metal compiler of macOS 11 and 12 writes no air.address_space on a
buffer argument, and neither does this Mac's compiler for a macOS 11 or 12
target (measured: 11.7.11's and 12.7.6's compiler in a guest, and Xcode
27.2's for macos-metal2.3 and 2.4). The reader then left every buffer of
such a module without an address space, and a pipeline's reflection of any
function with a buffer answered nil ("a buffer of no address space or
pointee"), so Metal apps that ask for reflection got none on 11 and 12.

An entry point's buffer node that names no address space now takes its
parameter's: the address space of the pointer at the node's position in
the function's type. Modules that name it are read as before.

The AIR test reads a library built at test time for macOS 11
(tests/air_arguments_11.metal): its device, constant and threadgroup
buffers each take their parameter's space, and its textures, samplers and
built-ins take none.
2026-11-11 06:32:24 -08:00
Anees Iqbal b415f5b61b 🔥 Lay every slab in plain pages, asking for no superpage
A 2 MiB slab of a process's own pages was a superpage the slabs' thread
asked for ahead of its take. Asking still stalled the process: the kernel's
search for a contiguous 2 MiB runs in vm_map_enter with the task's map
interlock held and the new entry locked exclusive (public xnu-12377.101.15
vm_map.c), so any walk of the map past it waits. Tailspin on an 8 GiB
macOS 26.7.2 guest on the Radeon 780M host: WindowServer's slabs thread was
in cpm_allocate while its main thread, making a texture over a layer's image
in a live resize, waited in mach_vm_region behind it, and Safari's page drew
no frame for 179 ms. No thread placement avoids that, superpages run out
minutes after a boot anyway, and the held one cost up to 38 MiB across the
19 processes that map the bundle.

So every slab of the process's own pages is plain pages, taken by the take
that needs it, as it already was once superpages ran out. The superpage
call, its record in the kext and the VM-guard tool go.

What changes for the guest: the kext no longer answers selector 12
(Superpages) nor sets kext feature bit 8; both lived only between the kext
and the bundle, which ship together, and reims_graphics_wire.h never had
them. The host sees the same pages blocks as a guest out of superpages
does: HEAP_OVER_PAGES and BUFFER_OVER_PAGES over plain pages' runs.
2026-11-09 04:56:53 -08:00
Anees Iqbal 1927ea3c4f 🔥 Drop the several-superpage call the slabs no longer make
Since the slabs' thread asks for one superpage ahead and a slab larger than
2 MiB is plain pages, nothing asked the kernel for several superpages in a
call: the reservation it was made in piece by piece, its test VM and its
test, and spguard's cases of it ran only that path.

RgfxSuperpages now makes one superpage, anywhere, in one call, and says why
one: a call for several that runs out partway raises a deallocation-gap
guard exception, fatal in processes whose VM guard is on. spguard keeps the
cases that show that exception (several.anywhere, several.fixed,
several.fatal, the old.* cases renamed) and no longer builds our module.
2026-11-09 04:56:53 -08:00
Anees Iqbal 4377c7ebcb 🐛 Link the arm64e bundle with small objc stubs so its set reproduces
Two builds of one tree gave two arm64e RgfxGate binaries, alternating
(three clean builds on the M3 Max: A, B, A). They differed only in the
Metal bundle's arm64e image inside RgfxGate: its UUID, its signature and
__objc_stubs. ld (ld-27106.1) makes two slots for objc_msgSend in the
authenticated GOT, one for the message-send stubs and one for
objc_msgSend's own call stub, and gives each stub its slot in either order
from one link to the next. The arm64 image, whose GOT is not
authenticated, was the same every time.

The arm64e bundle now links its message-send stubs in their small form,
which branch to objc_msgSend's call stub and take no GOT slot of their
own, so the one slot leaves nothing to order. docs/lessons.md records the
trap.
2026-11-08 23:07:49 -08:00
Anees Iqbal ab53a4b949 🆕 Build the guest's kext set for arm64 guests too
The arm64 macOS 13 and later guests Ambrosia boots get a set of their own,
guest/prebuilt-arm64e: ReimsGraphics and RgfxGate for arm64e, the Metal bundle
inside RgfxGate for arm64e (system processes such as WindowServer) and arm64
(apps). `make -C guest set-arm64e` builds it and `prebuilt-arm64e` writes it with
its own sources.toml; prebuilt-check, which cargo xtask check runs, now checks
both sets.

The build picks per-architecture files with ARCH_NAME. An arm64 kernel collection
has neither AppleGraphicsDeviceControl nor IOAcceleratorFamily2, so the arm64e
kext has its own Graft declaration (src/graft-arm64e.json: IOFramebuffer and
IOAccelerator, both from IOGraphicsFamily) and its own Info.plist
(src/Info-arm64e.plist: no device control, no library of either). It leaves
RgfxDeviceControl out and references no IOAccelMemoryMap function. Graft's
consumer rules read src/Info.plist only, so the kext Makefile replaces that one
recipe for arm64e until Graft's rules take the path; make says so with a warning.
RgfxGate packs the guest's slice's cdhash, arm64e for this set.

The x86-64 set's kexts build byte for byte as before; only its record of the
sources changes. The arm64e set does not list Graft yet: it takes Graft's arm64e
build once guest/graft carries one. Its ReimsGraphics' imports all resolve in the
kernel collections of macOS 13.6, 14.6.1, 15.6.1, 26.6.2 and 27.0.1; RgfxGate's
install still calls VNOP functions an arm64 collection does not export.
2026-11-08 20:34:15 -08:00
Anees Iqbal f98bd174be ✅ Walk the SPI protocols and older releases' members
The register's check walked only the public protocols the bundle's classes
adopt, so it could not see the class of member macOS 13's Maps died on: a
member of Metal's SPI counterpart (MTLLibrarySPI for MTLLibrary), which
Metal's own objects adopt and the guest's frameworks send without asking. It
now walks each protocol's SPI counterpart too, and adds the members only
older guest releases' protocols carry, which the Mac it runs on lacks
(tests/protocol_members_releases.txt: macOS 11.7.11, 12.7.6, 13.7.8 and
26.7.2 against 27.0.1).

The register lists every SPI member: the forwarders as implemented, the
constant answers as Metal's with why, and the rest by what the AMD 5300M's
and the Intel 630's objects answer (measured with respondsToSelector:, macOS
26.7.1), counted by class family: pending where both answer (305, to be
answered as Metal's), absent where neither does (54) or they differ (6),
pending where the oracle's macOS lacks the member (14). A new kind, pending,
is checked as absent. The 31 members only older releases carry are absent:
no app pass on those releases showed a framework sending one, and the 4 of
MTLDeviceSPI are answered there by the device's own IOGPU base.

tools/protocol_dump.m dumps a Metal's protocols for the releases list, and
tools/oracle/oracle_spi_members.m asks a Mac's own objects for the verdicts
and what their getters answer. docs/lessons.md says what the trap was.
2026-11-08 12:13:20 -08:00
Anees Iqbal 6fb33ecd27 🎨 Rename the reims-graphics crate to reims-vgpu-graphics
The crate that holds the reims-graphics device's wire and transport now
carries the library's prefix, as reims-vgpu-video does: its directory is
crates/reims-vgpu-graphics, its package reims-vgpu-graphics, and its Rust
path and log target reims_vgpu_graphics. The guest's, the option ROM's and
Ambrosia's Makefiles include the wire header from the new directory, and the
prebuilt records name it there.

Nothing changes for the guest or the host. The device keeps its name
(reims-graphics, QEMU's reims-graphics-pci, PCI 1234:5247), and the wire
header keeps its file name and RGFX_ symbols. The C API header is unchanged,
and the prebuilt kexts and option ROM are byte-identical; only the records'
paths and source hashes move. A log filter names the crate's lines by its
new target (REIMS_VGPU_LOG=info,reims_vgpu_graphics=trace), a diagnostic.
2026-11-08 01:37:50 -08:00
Anees Iqbal 47ce2a20ed 🎨 Point the bundle's peer test at the Vulkan dist tree
`cargo xtask dist` writes target/dist-vulkan on every host since the Metal
platform went, so the bundle's DIST default named a tree nothing writes. Two
comments still cited the deleted Metal crate: the texture's note on a GPU
address no resource holds, and the oracle's list of MTLDeviceSPI answers.

The prebuilt set was rebuilt with `make -C guest prebuilt` (KDK 25G241): the
kexts are byte-identical, and only the record's hashes of the two changed
sources move.
2026-11-07 23:29:49 -08:00
Anees Iqbal 17a724aa74 🆕 Make an OpenCL kernel's function of OpenCL mode for the host to link
The GL renderer runs an OpenCL program's kernels on the device. It makes each
kernel's function with newFunctionWithPluginData:bitcodeType:2, then a compute
pipeline of it with openCLModeEnabled, and binds three buffers of its own ahead
of the kernel's arguments. Metal links the kernel for OpenCL mode as it makes
the pipeline. On our device the host's platform does, and the AIR goes to it
unchanged.

The bundle's variant is a new function of the same entry point. It holds the
plugin data and answers the plugin return data the x86 Macs answer
(LinkerScript_buffer_bindings, LinkerScript_byVal_bindings,
LinkerScript_function_name and air.work_group_size), from the kernel's nodes
as the AIR reader reads them; the reader now takes a kernel's
air.work_group_size. Its pipeline's reflection lists the kernel's arguments
at Metal's indices, values as buffers that are no constant buffer, then the
three buffers. Its create carries RGFX_COMPUTE_PIPELINE_OPENCL_MODE, and a
variant is made only where the host offers RGFX_FEATURE_OPENCL_MODE (bit 27),
which the kext now carries; an older host never sees the flag.
2026-11-07 21:11:05 -08:00
Anees Iqbal 9381ef053a 🐛 Link ReimsGraphics and the bundle on macOS 11 to 15
ReimsGraphics called IOPCIDevice::setBusLeadEnable, a non-virtual member the
kernel links by name. IOPCIFamily exports it only from macOS 12 on, so on 11.x
the kernel could not link the kext. It now calls setBusMasterEnable, which is
virtual: the call goes through IOPCIDevice's vtable, whose slot holds the same
member on every release from 11.7.10 to 26.7.2, and the kext imports nothing
for it. The SDK deprecates it, so the two calls silence that warning alone.

The bundle had no deployment target, so its minos was the SDK's 27.0 and every
import was strong, and dyld refuses an image with a strong import its libraries
lack: _MTLTensorDomain on 15.x, up to eleven symbols on 11.x. Built for 11.0,
the eight Metal symbols newer than that are weak imports and libc++'s
bad_function_call imports are gone; every strong import then resolves on the
ten releases checked, 11.7.10 to 26.7.2, against each one's dyld cache. Where
a weak symbol is absent, the code either does not reach it or treats it as a
class that is not there.

guest/prebuilt is rebuilt from the macOS 26.7.1 KDK.
2026-11-07 20:48:38 -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 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 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 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 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 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 c5f268c638 🐎 Read macOS 10.12's AIR modules, of LLVM 3.5's metadata nodes
A .metallib built for macOS 10.12 (-std=macos-metal1.2, the language its
function constants came with) holds AIR modules in LLVM 3.5's metadata form:
each node a METADATA_NODE of code 8 whose operands are pairs of a type and a
value, a metadata's number where the type is metadata and a value in place of
a METADATA_VALUE otherwise, and each string a record of its own. The reader
took code 8 for a record of no node, so not one entry point of such a module
read (measured: Apple metal 32023.922, every entry point of a library built
from our sources for 10.12, and none of one built for 10.13), and each took
every texture whose usage has ShaderWrite as written.

The reader now reads the module's type table for its metadata and void types
and takes those nodes so, the values held beside the numbered metadata. Its
test reads a library built for 10.12 from tests/air_arguments_old.metal: each
entry point's arguments, and its constants as its CNST tag lists them.

The guest sees no other answer: textures such modules' functions only read or
sample are no longer taken as written.
2026-11-05 21:59:34 -08:00
Anees Iqbal 29dd60bfb9 🆕 Read each module's function constants from its AIR
A .metallib names a function's constants in its public metadata (the CNST
tag), and the bundle had nothing else to read them from: a function whose
metadata names none took every value set for it as set for nothing.

Each module lists its constants in the named metadata air.function_constants:
the global the value is read from, the type's name, the constant's name and
its index. The AIR reader now reads them beside the arguments and signatures,
into RgfxAirFunction and RgfxAirVisible. A constant is required where its
global is unnamed_addr; one the function tests with
is_function_constant_defined has its address taken and is not. Measured over
the 46,563 functions of macOS 27's frameworks' .metallibs on the M3 Max: each
of the 6,615 with constants lists the same names, indices and types in its
module as in its CNST tag, the 25,275 unnamed_addr ones required and none of
the 7,108 others, and no function without a CNST tag declares any.

The reader's test compares every function of its library with its CNST tag,
over a new kernel of five constants (vectors, and one tested for) and a
visible function of one.
2026-11-05 21:59:34 -08:00
Anees Iqbal 8d53659fbd 🐛 Name every MTLDataType in a constant's type error as Metal does
A function made with a constant value of another type fails with Metal's
words, which name both types. The bundle named only the constant types (the
scalars and vectors) and printed any other value, a matrix, a texture or a
pipeline among them, as MTLDataType(N). Metal names every value of the enum
"MTLDataType" and its name in MTLDataType.h (measured with oracle_names on the
AMD Radeon Pro 5300M and the Intel UHD Graphics 630, macOS 26.7.1, each of the
95 values set for an int constant).

What the guest sees: the error's description names a value of a type no
function constant takes as Metal does ("... has type MTLDataTypeFloat4x4").
A value outside the enum still prints as MTLDataType(N).
2026-11-05 21:59:31 -08:00
Anees Iqbal f63a98d9d0 🆕 Time the CPU's uploads into textures at WindowServer's shapes
WindowServer now uploads its refused linear textures through Managed textures
and replaceRegion: (8d8ccc3ef), so what those calls cost here, against a Mac
with a discrete GPU, decides which share of the path to cut.

upload_probe times, at the shapes of the linear textures WindowServer made
(BGRA8 128x32, 336x64 and 480x36, A8 64x64, RG8 64x64) and at 1024x1024:
- replaceRegion: of a Managed and of a Shared texture: the call alone, back
  to back and 2 ms apart, and end to end with a blit that reads it;
- a burst of 64 such calls, then one command buffer of their blits;
- didModifyRange: of 256 B, 4 KiB and 64 KiB of a Managed buffer, alone and
  in bursts;
- replaceRegion: and didModifyData of a linear texture over a Managed buffer.
Each end-to-end case checks the bytes the GPU read.

make upload-probe builds it for x86_64 (a guest, an Intel Mac) or arm64.
2026-11-05 21:59:30 -08:00
Anees Iqbal 4eb3ee02b9 ✅ Add spguard, the VM guard against superpage calls
What the kernel's VM guard makes of the device's superpages can only be
seen in an x86-64 guest: its own calls in a scratch process that turns its
VM guard on and takes its EXC_GUARD exceptions on a port of its own. It runs
car 8's one call for more superpages than RAM is free, at an address of its
own (the gap's place) and anywhere, rgfxTakeSuperpages short of RAM and with
room, and both in a child with the guard fatal, as WebKit's GPU process has
it. make -C guest/bundle spguard; never in make test.
2026-11-05 21:59:28 -08:00
Anees Iqbal 87efcd206c 🐛 Make each superpage its own kernel call
WebKit's GPU process died of EXC_GUARD (VIRT_MEMORY, DEALLOC_GAP) inside
mach_vm_allocate when a WebGPU page asked for a large Shared buffer under the
app load. A call for several superpages that runs out of contiguous RAM
partway takes down the whole range it was asked for on macOS 26.4 and later:
vm_map_enter shrinks the size to what it made, then deletes up to the
request's end, over memory it never mapped. That gap is fatal in every
process whose VM guard is on: Apple's platform binaries and the hardened
browser processes. A third-party app just gets the refusal.

A dedicated slab of several superpages now reserves its range first and
makes each superpage over its own 2 MiB of it, fixed and overwriting. A
refused superpage leaves its piece of the reservation in place, and one
deallocation gives back the whole range, so the slab fails cleanly and is
the region's, as any refusal was. A one-superpage slab stays one call
anywhere. The tests' kernel acts as xnu does there; car 8's one call fails
them on the gap.
2026-11-05 21:59:28 -08:00
Anees Iqbal 2b1b29a759 🐛 Stream each library through a window made for it
A process's first library over 8 KiB took a staging window of 64 MiB and kept
it for the process's life. On a busy desktop on the RTX 5080 host, nine
processes held 576 of the 731 MiB of the region outside WindowServer's
reserve that way (mediaanalysisd held nothing else), so the region ran out at
41 processes. From there, libraries, buffers and queue rings came back nil,
and Games, Photos, Photo Booth, Maps, the Dock's extras, NotificationCenter
and WebKit's GPU process crashed.

The window is now made for one stream and sized to its library: as few
chunks of at most 32 MiB as hold it, split evenly in whole pages, and a
second block only where there are two or more chunks. It goes back to the
region once the host has acked every chunk. Where the region refuses it,
smaller chunks are asked for, down to a page, so a library is made while any
room for three pages is left. A window whose chunk the host never acks is
kept, so nothing the host may still read is given out again.

The stream moves to RgfxLibraryStream.cpp, so the serialiser check covers it
against a host of its own: the shapes, the fallbacks and their bytes and
order, the window given back, and one kept when an ack never comes.
2026-11-05 21:59:27 -08:00
Anees Iqbal 53632d1ae3 🐎 Encode an ICB's CPU commands into slots in the region
Where the device offers ICB_SLOTS, an indirect command buffer of one
command type, with at most 32 bindings of each kind, takes a block of the
process's region holding a slot per command, allocated at its first command
lookup or range reset and zeroed. A setter writes its field into its
command's slot and sets the field's bit with an atomic OR, and marks the
command's chunk of 64 dirty; resetWithRange marks each command's slot for a
range reset alone. The serializer's flush, at each commit and before any
ICB_WRITE record, posts one ICB_SLOTS naming the dirty chunks' runs, up to
the ring's message cap, so a CPU encode posts nothing per command.

An encode of 16384 draws with a pipeline and two buffers took 137 to 148 ns
a command on the M3 natively, posting 112 messages inline; through slots it
takes 90 ns and posts none. The floor is the command object Metal hands out
per lookup, 48 ns.

A buffer past the slot's bindings turns its ICB to records for good, after
posting its dirty slots, as do a buffer over 8 MiB of slots and a process
past 32 MiB of them; the slots' block is released after the ICB's last use.
2026-11-05 21:59:26 -08:00
Anees Iqbal 509abb3090 🆕 Make indirect command buffers in the bundle
newIndirectCommandBufferWithDescriptor: answered nil, so WebKit's render
bundles and every Metal app using ICBs failed on the device. Where the feature
word holds INDIRECT_COMMAND_BUFFERS the bundle now makes one on the host
(ICB_CREATE, answered with its gpuResourceID), and each CPU encode on its
commands is a record the serialiser keeps and posts as ICB_WRITE before the
process's next command buffer, before a destroy that a record may name, and
when a message would pass the control ring's largest.

The answers follow the Macs measured with oracle_icb (AMD 5300M, Intel 630,
M3 Max), taking the cheapest where they differ: a nil command past the size
or of the other kind, a new command object per lookup, the macOS 26 render
states raising unrecognized selector, mesh setters logged no-ops, render
barriers sent on, ranges clamped to the size, 64 bytes a command in whole
pages, and a Memoryless buffer ending the process as on all three. An
argument buffer holds the buffer's gpuResourceID, and the device's GFX and CMP
ICB queries answer YES with the feature.
2026-11-05 21:59:25 -08:00
Anees Iqbal 351724d07a 🐎 Lay Shared and Managed buffers in slabs of the region
Each Shared or Managed buffer took a kext block of its own: a blocking ALLOC
with a first-fit scan and an overwrite mapping, a BLOCK_GRANT, a memset of the
whole block, a host import per buffer, and a BLOCK_RELEASE round trip at its
free. In a 16 GiB guest on the 5080 that made 4 KiB creates 29 us (76 us late
in a hold, the scan), stopped them at the block table's 16,384 entries, and
made frees a round trip each, RES-01's trigger.

Buffers now take whole 4 KiB pages of slabs the bundle holds (RgfxSlabs):
- a Shared slab is one Placement HEAP_OVER_HOST_MEMORY of the class's
  options and each buffer a BUFFER_AT_OFFSET there; a Managed slab a plain
  block and each buffer a BUFFER_OVER_HOST_MEMORY over its own range;
- buffers up to 1 MiB share their class's slabs, which grow from 128 KiB to
  2 MiB; a larger one takes a slab of its own, cached once freed for reuse;
- a create zeroes only what of its range is dirty, and a background thread
  zeroes freed ranges and lets slabs go, so no free waits for the host;
- where the region has no block for a slab, the process's own empty and
  cached slabs go first, then smaller slabs down to the buffer's size: nil
  only where the region is full.

A create is a free-list take and one ring-0 post, with no kext call, and the
block table holds one entry per slab. Where slabs come from is their source's,
so guest-RAM slabs can take the region's place behind a feature bit.
2026-11-05 21:59:24 -08:00
Anees Iqbal 031733f6f4 🐛 Close the sessions of the contexts a failed create deletes
Where CreateContexts could not open a later context's host session, it
deleted the contexts it had made before it without closing their sessions or
taking them out of the live ones. The sessions leaked on the host, and the
next FreePixelBufferPool walked the deleted contexts. Both paths now delete
a context the same way: its session closed and out of the live ones, and no
token naming it.

video_driver_tests drives the driver's entry points as AppleGVA calls them,
over a stand-in for the host's sessions: a create whose second session is
refused, DeleteContexts, and a decode the driver cannot send, which fails its
schedule. The first check fails on the old cleanup.
2026-11-05 21:59:24 -08:00
Anees Iqbal ae30f6891a 🆕 Decode HEVC in the guest's video driver
The video driver now offers AppleGVA HEVC decode where the host's video
caps list it: Main into NV12 ('420v', '420f') and Main 10 into P010
('x420', 'xf20'), in the profiles the host lists. Each picture goes to the
host as H.264's do, its slice segments copied out of AppleGVA's bitstream
buffer and the SPS and PPS written from AppleGVA's parsed form where they
changed (RgfxVideoH265.cpp, sharing the bit writer with H.264).

An HEVC decode command carries no output surface and no transfer command,
unlike H.264's: AppleGVA names the output frame in its decoded-picture
record, whose frame holds the surface's global IOSurface id, and the driver
looks it up there. AppleGVA holds each short-term set of the SPS by its
pictures, a predicted set's already derived, and the writer writes every set
by them. Both measured on the guest with the RTX 5080; the sets' layout
against hevc-main-720p-sets-sps, whose 25 sets AppleGVA held as 7-61 and
7-62 derive them, and whose SPS written from AppleGVA's struct decodes as
the stream's own.
2026-11-05 21:59:24 -08:00
Anees Iqbal 4d6776e9d1 🐎 Post a pipeline create equal to an accepted one without waiting
Every pipeline create waited a kext round trip for its reflection: 0.09-0.54 ms
for a descriptor the process had made before, where Metal answers from its
caches in 4-27 us. The client that makes the RenderBox states makes 8.5k-10.5k
creates per login.

The device now keeps the reflection of each create it accepted for the
process, keyed by SHA-256 of the whole create message except its header and
object id (RgfxKnownPipelines). A create with a known key is posted through the
kext's deferred submit (kRgfxSubmitDeferred) and returns at once. Its state
takes the known reflection, with its own object id and seqno. Its gpuResourceID,
the one value the host gives each create alone, waits at its first read for
the create's own answer, which the process takes with TakeAnswers.

- Each create is still a new object, posted as any, with its own resource ID,
  as Metal's equal creates are.
- The first create of each key waits as before, so a refusal is still known at
  the create. A refusal is never kept.
- Where the kext has no slot left, the create is answered at once as any.
- The process also takes the answers no one asked for every 32 deferred posts,
  so they don't hold the kext's slots.
- One residual is accepted: the platform running out of memory at the new
  state's own VkPipeline link shows at gpuResourceID (as 0) and in the command
  buffers naming it, not at the create (design.md, "Known pipeline creates").

The device posts this way only where the kext's feature word has
kRgfxKextFeatureDeferredAnswers, which the bundle reads through wire-v3's
Features once phase 1 lands. Until then no kext is taken to defer, and every
create waits as before. tests/known_pipeline_tests.mm checks the states over a
kext stand-in.
2026-11-05 21:59:24 -08:00
Anees Iqbal aea974e518 🐛 Write no file from the bundle, logging to os_log instead
Every process that loads the bundle wrote /tmp/rgfx-diag.log (a trace left
from bring-up, at device init and on transport failures) and
/tmp/rgfx-surface-copies.log (the surface copy counts, every 10 s while
copies run). In sandboxed processes each write is refused and reported, and
the reports fill the kernel's message buffer: wire-v3-p1 saw them from
iconservicesagent, VTDecoderXPCService, WallpaperAerialsExtension and
avconferenced. The trace's NSLog lines also went to every app's stderr.

The transport's failures (the user client, the caps blob, the context, the
completion thread and its wait) are os_log errors now, and the copy counts
an os_log info line; the trace's other lines, +load and the -init override
that only logged, go. make test runs tests/bundle_files_check.sh, which fails
where the bundle's executable names a temporary directory or imports open(2)'s
family; it failed on the bundle before this change.
2026-11-05 21:59:24 -08:00
Anees Iqbal 0e1650ca71 🆕 Add a probe of shader and pipeline costs to the bundle's tools
tools/pipelines measures what libraries and pipeline states cost on a Metal
device, cold (a nonce no cache has seen) and warm (the same object again, in
the process or, with the same -s seed, in a later process, a reboot or another
VM): newLibraryWithSource in both forms, newLibraryWithData of metallibs the
build writes, newLibraryWithURL of system metallibs, specialization, render and
compute pipeline creates of a new library, specialization or state, the same
descriptor again, eight asked at once, the first draw and dispatch of a new
pipeline, a topology change, and binary archive hits in the process and from
a file. Its numbers on the guest lane beside the M3 Max and the MacBook Pro
2019's GPUs show where shader and pipeline time goes, and which caches outlive
what.
2026-11-05 21:59:23 -08:00
Anees Iqbal e394be2ea9 ✅ Test the user clients' words, from one protocol source
No test reached what the kext's user clients answer: the display pipe's VBL
and completion notifications and the replies to the IOGPU base's device calls
were packed inside .cpp files only the kernel builds, so the VBL layout bug
(a75584e08) passed every test. The selectors and user-client type were written
twice, in the kext and the bundle (and a third time in window_probe), kept in
step by hand.

The protocol constants now live in RgfxUserClientABI.hpp, which the kext, the
bundle and window_probe include. The notification words and the IOGPU replies
are built by RgfxPipeNotifications.hpp and RgfxIOGPUReplies.hpp, which the kext
calls, and user_client_words_test pins each word and byte, which calls the
kext answers, and the context selectors' range without a gap. Values and
layouts are unchanged: the kext check passes (502 imports, the layout, the
OpenCore link) and window_probe's code is byte-identical (aud-tests-07).
2026-11-05 21:59:23 -08:00
Anees Iqbal 3a603a21aa 🐛 Answer a function's patch type and control points as Metal does
patchType answered MTLPatchTypeNone and patchControlPointCount 0 for every
function, where Metal answers a post-tessellation vertex function's [[patch]]
type and count, and -1 for the count of every function that states none. The
device draws patches, so an app that fills its tessellation state from the
function built a wrong pipeline.

The library now reads each function's TESS tag from the .metallib's function
list: the type in its low two bits, the count above them, 63 for none, as
Apple's compiler writes it and as Metal's own functions answer for those bytes
on the M3 Max, the AMD 5300M and the Intel 630. A shell test checks both
answers against Metal's for a library of every patch kind (aud-tests-02).
2026-11-05 21:59:23 -08:00
Anees Iqbal 24addecc72 🐛 Answer nil for every object whose create the device never got
Only pipelines, libraries, video sessions and now queues looked at whether
their create reached the device. Buffers, heaps and their buffers,
textures (device, over a buffer, linear, views, Managed and over an
IOSurface), events, fences, shared events, samplers and depth-stencil
states came back as objects the host never made where the kext's submit
refused the message, so a command buffer naming one would fail on the
host.

What the app sees: each of these creates now answers nil there, as Metal
answers for an object it cannot make. RgfxSerializer::refused() gives
back the GPU address and resource id the create picked, as no destroy
follows; the callers already give back their region blocks and heap
ranges on nil.

create_tests.mm makes each kind against a device that takes a set number
of messages: made while the device takes its create, nil once it refuses
it, with the address, resource id, region block and heap range back.
2026-11-05 21:59:23 -08:00
Anees Iqbal 6254f3fc0a 🐛 Hold an encoder's command buffer until its endEncoding
An encoder held its command buffer weakly but wrote through the buffer's
RgfxEncoder, which the buffer's dealloc deletes. A buffer that went while its
encoder was open, such as a Swift makeCommandBuffer() temporary or one made in
a pool that drained, left the encoder writing freed memory (aud-bundle-10).

What changes for the guest: each encoder (render, compute, blit, parallel and
a parallel pass's sub-encoder) now holds its buffer strongly from its making
until its endEncoding, then lets it go. That is what Metal's encoders do
(measured on the M3 Max, an AMD 5300M and an Intel 630): a buffer whose only
holder is an open encoder lives on, an ended encoder no longer keeps it, and
the ended encoder's commandBuffer is nil once the buffer is gone.

The check is tests/queue_tests.mm, a new part of the shell tests, with the
audit's encoder check folded in.
2026-11-05 21:59:23 -08:00
Anees Iqbal 42ee595c52 🆕 Add a probe of a command buffer's fixed cost and latency
The lane had no measure of what one command buffer costs end to end: bench
times GPU-heavy work, and cb_probe only checks that completions come. The
probe times commit-only and commit-and-wait rates, a completed handler's round
trip, commit to the scheduled and completed handlers with and without an idle
gap, the same from several threads on their own queues or one they share, and
a shared event's signal from the CPU and the GPU to a waiter on each. It builds
for the guest and for Macs (make submit-probe), so one binary compares the lane
with native Metal; -v prints each case's largest samples with when they were
taken, to match a host trace.
2026-11-05 21:59:23 -08:00
Anees Iqbal 8bb3f9b5aa ✅ Record the bundle's wire traffic against the host library
Phase 1 must show that the bundle of today, under a host that negotiates
features, still speaks wire 2. The Rust FakeGuest covers the device's side of
that against fake host code; nothing ran the bundle's own C++ ring code
against the real library.

peer_tests drives the bundle's serialiser, a queue made as the device makes
one (RgfxRegion's ring pair, RgfxRingWriter, RgfxReplyReader), the
completion thread and command-buffer commits against libreims_vgpu.a through
the C API, as QEMU links it, on this Mac's GPU with no window. A stand-in
does the kext's part: the start, lifecycle posts and their answers, block
grants and releases, queue opens with the one vector, doorbells and the
completion thread's wake. It records register traffic, every record each
side publishes and the settled ring headers against tests/peer_wire2.trace.
Interrupts are counted, not traced: a buffer's CB_SCHEDULED and CB_COMPLETE
raise once or twice depending on when the GPU finishes (7 or 8 in three
runs). `make peer-test-build`, then `make peer-test` under the GPU lock;
never in `make test`.
2026-11-05 21:59:23 -08:00
Anees Iqbal b2e252af65 🆕 Add a probe of what Metal resources cost
res times making and freeing buffers, textures, IOSurfaces, heaps and
state objects, the CPU's access to resource memory, and the process's
footprint over many make-and-free rounds, so the graphics lane can be
compared with real Macs case by case.
2026-11-05 21:59:23 -08:00
Anees Iqbal 99a6d3c474 ✅ Check every Metal protocol member against a register
presentDrawable: and its variants were empty, and vertexAttributes,
stageInputAttributes and currentAllocatedSize answered a constant with
nothing logged, and every test passed: no test asked whether a member does
what it says. The bundle's protocol completeness diagnostics see only a
member that is missing, and protocol_audit runs only on a guest and fails on
nothing.

protocol_members_tests loads the x86-64 bundle under Rosetta, as
inherited_tests does, and walks every member, required and optional, of every
MTL* protocol a class of ours adopts, through the Objective-C runtime: 1129
members of 28 classes on this Mac's Metal. tests/protocol_members.txt lists
each with how it is answered: implemented, partial, unsupported (marked
RGFX_UNSUPPORTED), metal (answers what Metal's own does, with why), gap (a
known divergence), base (the IOGPU base answers it) or absent. The test fails
on a member the register does not list, on a stale line, and where the code
contradicts the kind: a member listed implemented whose body is empty or
only answers a constant, read from its source and from its x86-64 machine
code, or an unsupported one whose body has no RGFX_UNSUPPORTED. A new member,
from a new macOS or a new class, fails until it is classified; --propose
prints a line for each.

With the four stubs of 710cc917d and d54024a3b put back, the test fails on all
six members, from the source and from the machine code alone. On the tip it
passes and prints three gaps it found: a function's patchType and
patchControlPointCount answer None and 0 for every function, where Metal
answers the [[patch]] attribute's and -1 when none is stated (measured on the
M3 Max, the AMD 5300M and the Intel 630), and a CAMetalLayer drawable's
texture answers isFramebufferOnly NO, where Metal's answers the layer's
setting, YES by default. The metal, absent and gap lines' answers were
measured on the M3 Max and on the AMD and Intel devices of a 2019 MacBook
Pro.
2026-11-05 21:59:22 -08:00
Anees Iqbal bf67af7cbf 🆕 Add a GPU benchmark of the Metal device to the bundle's tools
To compare the x86-64 guest's GPU lanes on one host, and against real Macs,
under GPU-heavy work rather than desktop compositing: fragment ALU at 1080p
and 2160p and fill, compute FMA, a 256 MiB blit, texture sampling, 10,000
draws a command buffer, Shared upload and readback, MPS SGEMM at 2048 and
4096, and an on-screen CAMetalLayer at display rate. Each case warms up,
repeats (at least REPS times, or -m seconds), prints its medians on one
line, and marks its start, so a case that hangs or dies is known.
2026-11-05 21:59:22 -08:00
Anees Iqbal 153d41ae42 🆕 Write H.264 parameter sets back out from AppleGVA's records
AppleGVA parses a stream's SPS and PPS itself and hands the video driver
only its parsed records, one 32-bit field per syntax element, with each
picture's slices. The host decodes access units as a stream gives them, so
the driver writes the parameter sets back out as Annex-B NAL units: the SPS
without its VUI, which holds nothing a decoder needs, and the PPS whole. A
scaling list's trailing run is cut short only where that is no longer, as
encoders write it, so the PPS comes out byte for byte.

The records' layout is placed by H.264's syntax order between the fields
the calls' use states. On the guest, the sets written from AppleGVA's
records of six x264 streams equal the streams' own (the SPS up to its VUI
flag): Constrained Baseline with POC type 2, Main with B-frames and weighted
prediction, High with cropping, default and custom scaling matrices (stored
in coded order) and chroma QP offsets. That check also showed each record
starts with a word that is no syntax element. The tests check the writer
against those streams' parameter sets on the Mac (`make test`).
2026-11-05 21:59:21 -08:00