Commit Graph
1084 Commits
Author SHA1 Message Date
Anees Iqbal 7d65e1f36f 📦 Rebuild both guest sets for GL tessellated draws' kernels
The x86-64 set and the arm64e set from 9eacce0a9, replacing e50e5dd95's: the
Metal bundle inside RgfxGate makes a GL tessellated draw's kernel, which takes
a patch control point input, a kernel without it under its compute
pipeline's stage input descriptor, which Metal compiles. ReimsGraphics and
Graft are unchanged.

Built on the M3 (m3-max-30316, make -C guest prebuilt and prebuilt-arm64e,
237 s with the bundle's test binaries and Ambrosia's config bundle), and
make -C guest prebuilt-check passes on both. make -C guest test passed on
the M3 (m3-max-30320, 29 s).
2026-11-14 15:16:50 -08:00
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 e50e5dd951 📦 Rebuild both guest sets for GL control point fields
The x86-64 set and the arm64e set from 405988082, replacing 927cafcf6's:
the Metal bundle inside RgfxGate makes a GL patch control point input's
fields what `metal` writes. ReimsGraphics and Graft are unchanged.

With these sets the kernel of a GL tessellated draw is still refused, now at
the control point input itself ("UnknownKey", key
air.patch_control_point_input, m3-max-30171). metal2vulkan takes no patch
control point input in a kernel, as Metal takes none (m3-max-30197,
m3-max-30201 and m3-max-30203), so the renderer still draws the draw's
vertices in software until the device makes the kernel one Metal compiles.

Built on the M3 (m3-max-30169, make -C guest prebuilt and prebuilt-arm64e,
224 s with the bundle's test binaries and Ambrosia's config bundle), and
make -C guest prebuilt-check passes on both. make -C guest test passed on
the M3 (m3-max-30170).
2026-11-14 13:39:38 -08:00
Anees Iqbal 4059880823 🐛 Normalize a GL patch control point input's fields
94b38e703 took a GL kernel's inputs through the lowering's input rules, and
said the tessellated draw's kernel had the generator's bare attribute name
in its argument 0. It does, but one level down. The kernel the renderer
makes of a tessellated draw's vertex and control shaders takes the draw's
vertices as a patch control point input, and the bare name is in that
input's field node. The field also has the key air.arg_type_name where the
type name goes. The library dumped as the device made it shows both
(measured: macOS 27.0.1 arm64, m3-max-30158). metal2vulkan reads a field
through the same attributes as any input, so it still refused the kernel's
compute pipeline ("UnknownKey" at argument 0, "attrib_0"), and the renderer
still drew the draw's vertices in software.

A patch control point input's field node k now loses the bare name. Where
its type name is the key, it gets the Metal name of member k of the control
point function's result, which is what `metal` writes: one field per
member, in order. The rule applies in vertex functions and kernels alike.
gl_tests holds the generator's shape in a kernel and in a
post-tessellation vertex function, and checks that the input as `metal`
writes it comes through byte for byte. The header and the gl_tests
comment no longer put the name in the kernel's input node itself.

For the guest: the fields of a GL tessellated draw's kernel are now what
`metal` writes. The device still refuses the kernel, now at its patch
control point role (m3-max-30171). metal2vulkan refuses that role in a
kernel as Metal does: Metal compiles no kernel with a patch control point
input (measured on the M3 by metal2vulkan, m3-max-30197, m3-max-30201 and
m3-max-30203). The renderer draws the draw's vertices in software until the
device makes the kernel one Metal compiles.
2026-11-14 13:39:38 -08:00
Anees Iqbal 927cafcf6f 📦 Rebuild both guest sets for GL kernels' normalized inputs
The x86-64 set and the arm64e set from 94b38e703: the Metal bundle inside
RgfxGate makes a GL kernel's inputs what `metal` writes. ReimsGraphics and
Graft are unchanged.

Built on the M3 (m3-max-30148, make -C guest prebuilt and prebuilt-arm64e,
220 s with the bundle's test binaries and Ambrosia's config bundle), and
make -C guest prebuilt-check passes on both.
2026-11-14 13:39:38 -08:00
Anees Iqbal 94b38e7034 🐛 Normalize a GL kernel's inputs as a vertex function's
The GL lowering makes each variant's metadata what `metal` writes, but it
read only a vertex or fragment entry point's inputs. A kernel's inputs kept
the generator's bare attribute name after air.location_index and had no
buffer address space. The kernel GL's renderer makes for a tessellated draw
has such an input ("attrib_0" at its argument 0). metal2vulkan refuses that
key, so the device refused the kernel's compute pipeline. The renderer's
buildPipelineState failed, and it drew the draw's vertices in software
(measured: macOS 27.0.1 arm64, a quad patch through a tessellation control
and evaluation shader, m3-max-30129).

For the guest: a GL kernel's inputs now follow the rules a vertex
function's do. The tessellated draw's kernel was still refused with these
rules alone (m3-max-30150): the name sits in its control point input's
field, which the next commit normalizes. gl_tests holds a kernel's inputs
through the rules.
2026-11-14 13:39:38 -08:00
Anees Iqbal 42f95955e7 📦 Rebuild both guest sets for the device's compiler target
The x86-64 set and the arm64e set from e33c569c9: the Metal bundle inside
RgfxGate answers targetDeviceArchitecture with the device's own target where
it answered nil. ReimsGraphics and Graft are unchanged.

Built on the M3 (m3-max-30088, make -C guest prebuilt and prebuilt-arm64e,
222 s with the bundle's test binaries), and make -C guest prebuilt-check
passes on both.
2026-11-14 13:39:38 -08:00
Anees Iqbal e33c569c9c 🐛 Answer the device's own compiler target, never nil
What the guest sees changes: the device answers targetDeviceArchitecture
(MTLDeviceSPI) with an MTLTargetDeviceArchitecture, Metal's own class, of
cpuType 0x01005247, subType 0, version 1.0.0 and driverVersion 0x10000. It
answered nil, the IOGPU base's answer.

Metal's loader ends the process at nil (+[MTLLoader sliceIDForDevice:
legacyDriverVersion:airntDriverVersion:]), and MTLAssetUpgraderD, which asks
Metal's archive reader about every .metallib of an app it is told of for
every device, ended with SIGABRT at each app installed in the guest: 1-2
reports in every walk since pin 70, on Iris and the 3090.

Every Mac answers an object (oracle_archtype: AMD 5300M, Intel UHD 630, M3
Max, dgpu-oracle.md Q42), so nil is outside the envelope. The values name
each GPU's own compiler target, so the device names its own: CPU_ARCH_ABI64
with its PCI device id, which no Metal slice carries, so no archive holds a
slice Metal reads as this device's; one target whatever the host GPU; and
one version for both version fields, as the M3 Max and the Intel 630 answer.
Where the guest's Metal lacks the class or its setters, nil as before.

inherited_tests now checks the answer, and the register's line says why it
changed.
2026-11-14 13:39:38 -08:00
Anees Iqbal fffc41b341 🆕 Add oracle_archtype, the probe of a device's compiler target
MTLAssetUpgraderD ends with SIGABRT in every guest that installs an app: for
each .metallib of the app it asks Metal's archive reader about the file for
every device, and Metal's loader asserts on the device's
targetDeviceArchitecture, which the reims-graphics device answers nil.

The probe prints what a device answers there (the class, its members and
their values) and what the archive and dynamic library readers answer for
named files and for an archive and a dynamic library the device serializes
itself, each read in a child process, so a Mac's answers and the guest's can
be compared and the guest's abort is reproduced without an app install.
2026-11-14 13:39:38 -08:00
Anees Iqbal 8366731632 🆕 Let oracle_surfresolve resolve into plane 1 of a 420v surface
Its first round measured plane 0 of a surface with planes; a texture over a
later plane is the platform's other planar shape, so the probe asks it too:
plane 1 of a 128 x 32 420v surface, whose 16 rows of 128 bytes hold a 16 x 16
RGBA16Float texture.
2026-11-14 10:04:24 -08:00
Anees Iqbal 740f167a5b 🆕 Add the oracle probe of resolves into surface textures
The Vulkan platform drops a 4x BGRA8 attachment's resolve into a texture of
another format (RGBA16Float, BGR10_XR, BGR10_XR_sRGB) where the M3 Max was
measured to leave the texture untouched, but its measurements covered only a
texture over an IOSurface without planes in Shared or Managed storage. The
guest's surfaces now reach the platform as buffers, whose storage the device
picks (Private over a device cache), and the guest's own textures may lie over
a plane of a surface with planes or be Private.

oracle_surfresolve measures the rest: one case a process, the resolve
texture of its own, over a surface without planes, or over plane 0 of a 420v
surface, Shared, Managed and Private, by MultisampleResolve and
StoreAndMultisampleResolve, against a resolve of the same format.
2026-11-14 10:04:24 -08:00
Anees Iqbal c97df17e33 📦 Rebuild both guest sets with the lane's kext and bundle changes
The x86-64 set (make -C guest prebuilt) and the arm64e set (make -C guest
prebuilt-arm64e), rebuilt on the M3 from this tree: the kept framebuffer, ring
0's completion arm-once, the kept framebuffer's liveness check, and a commit's
publish made in the kext call that posts the held messages. make -C guest
prebuilt-check passes for both.
2026-11-14 10:01:56 -08:00
Anees Iqbal a66f2b91f6 🐎 Publish a commit's buffer in the kext call that posts the held
A command buffer committed while the control ring held messages made two kext
calls: SubmitBatch posted the held, then the bundle published the buffer on
its queue's ring and rang the queue's doorbell through the kext. The second
call costs its kernel entry and return around the doorbell's write: measured
with the commit probe and the kext's stamps at 4.6 us p50 a commit on the Iris
Xe host (1.3 in, 2.0 the write, 1.2 out), and on the 780M host 4.5 us warm and
11.3 us after 2 ms idle (3.2 in, 2.7 out). Every commit the probe made behind
held messages rang it.

Where the kext answers kRgfxKextFeatureQueuePublish, SubmitBatch takes three
scalars more: the queue, its ring's new producer and the doorbell's flags. The
bundle writes the buffer on its ring and fences its stores, leaves the
producer, and hands the publish to the held (RgfxRingWriter::tryPost's `via`,
RgfxSerializer::publishVia). Once the kext has posted every held message it
stores the producer, fences, reads consumer_idle and rings the doorbell as the
bundle's own publish does (RgfxQueuePublish.hpp), so the host sees the held on
ring 0, then the buffer, as before. A commit with nothing held, or behind an
indirect command buffer's encodes or a refused destroy, goes as before; so
does every commit with a kext that lacks the bit. Where the kext leaves a held
message other than a destroy unposted it publishes nothing, and the bundle
takes the buffer off its ring unseen, its seqno the next buffer's and its
expected records dropped (RgfxReplyReader::forget), and fails it as before.
The buffer's posted time is stamped before the call.

The kext maps each queue's submission ring header at QUEUE_CREATE, while the
ring's block is pinned, only where the block is the client's own (ownsBlock),
in RgfxAcceleratorUserClient::keepQueueHeader. It lets the mapping go before
the pages can: at the queue's destroy (destroyQueueIfTracked), at Free of the
block the ring lies in, before the free, and at the context's close
(releaseContext, before the window and the blocks go). Each publish runs under
the client's list lock, which every drop takes. A device reset frees no block:
the mapping stays the process's ring until one of those. A queue past the
client's first 64 is published by the bundle.

Tests: queue_publish_test (the kext's publish against the bundle's own, every
consumer state and flag, and the headers' table through create, free, destroy
and close), shell_tests' test_commit_hands_its_publish_to_the_held (one call,
nothing held, a kext without the bit, a refused create, refused destroys
alone) and user_client_words_test (the bit).
2026-11-14 10:01:56 -08:00
Anees Iqbal 9333313af9 🐛 Let the kext import check take com.apple.kpi.unsupported
`make -C guest/kext check` failed on every tree since f91bd13f3, which named
com.apple.kpi.unsupported in the kext's OSBundleLibraries for mach_vm_region
and kernel_map: check-imports.sh refused that KPI as open to com.apple.* kexts
alone. The kernel's rule is narrower. OSKext::resolveDependencies fails a kext
outside com.apple.* only where it names com.apple.kpi.private (read from xnu's
OSKext.cpp: PRIVATE_KPI is the one KPI it checks so), and every kernel the kext
boots on exports the unsupported KPI's names to any kext. So the check now
refuses the private KPI alone and resolves the unsupported KPI's names against
the KDK's symbol set as it does every other library's. Nothing the kext or its
Info.plist holds changes.
2026-11-14 10:01:56 -08:00
Anees Iqbal f11b7acdab 🐛 Look the framebuffer up again once the kept one stops or goes
The accelerator keeps the framebuffer its lookup found started, and handed the
kept one out again while it had started. A framebuffer whose termination has
begun before its stop could still be handed out. The keep now hands it out
only while it has started and is not terminated (IOService::isInactive); one
that is not is let go of the keep, and the lookup is made again, which finds
the framebuffer that replaced it or none, so a restart never hands back a
stale pointer.

The rule is header-only (RgfxKeptService.hpp) and kept_service_test walks it:
a framebuffer not yet started is handed out and never kept, a started one is
kept and handed out with no lookup, a stopped or terminated one is let go and
its successor found and kept, and every reference taken is let go.
2026-11-14 10:01:56 -08:00
Anees Iqbal c25957d43e 🐎 Arm ring 0's completion ring only where something changed
The kext takes ring 0's completion ring at every interrupt of the control
vector, which every command queue's completion shares, and at a waiter's look
for its answer. Each take stored the consumer, stored armed, fenced and read
the producer again, whatever it found: four accesses to a header that is
uncached memory to the guest on an AMD host, where an uncached load costs
79-138 ns and a store runs at 13 MB/s.

A take that finds nothing now leaves the consumer as it was, and a ring whose
last arm found it empty, nothing taken since, is not armed again while its
producer reads as it did then: the host clears armed only in a post, after its
publish. That is one load where nothing changed, as the bundle's completion
thread arms its queues' rings. completion_arm_test runs every interleaving of
the host's post (its publish, then its look at armed with the re-arm) with a
take's accesses: none leaves a record untaken with no vector to come, or the
ring unarmed.
2026-11-14 10:01:56 -08:00
Anees Iqbal 061ef5b947 🐎 Keep the framebuffer the accelerator found started
Every message the kext posts (each SubmitBatch, Submit, deferred create and
release) looked the framebuffer up: a walk of the PCI device's clients and a
build of the accelerator's service-plane path under the registry's lock, then
the IOAccelTypes check. Measured on the Iris Xe host with the commit probe and
the kext's kdebug stamps: 4.0 us of a warm SubmitBatch's 9.9 us, and 9.9 us of
25.3 us after 2 ms idle.

The first lookup that finds the framebuffer started now keeps it, and the ones
after take the kept one while it runs. The naming it carries is unchanged: the
rename it fixes is the accelerator's own, at its start, before its first
lookup, and the framebuffer names the accelerator at its own start, before it
counts as started, so the path a started framebuffer holds stays right. The
kept pointer lives beside the contexts' state, out of the class, whose layout
stays as the loader's sites were taken from.
2026-11-14 10:01:56 -08:00
Anees Iqbal e2ef6ac2bf 🆕 Let oracle_twinwrites write through an argument buffer and into 500
metal2vulkan refuses a write of every two-plane YCbCr texture reached through
an argument buffer, and asked what Metal stores there before taking the slot
answers for it. oracle_twinwrites gains `argbuf`, a kernel's write() through an
argument buffer that holds the texture, made resident for writing, and 500
(YCBCR8_420_2P over a '420v' surface), whose slot writes Metal drops, so one
run compares the two routes. Written from scratch.
2026-11-14 09:23:15 -08:00
Anees Iqbal 265065139c 🆕 Add the oracle probes of two-way failures and twin writes
oracle_failways measures a command buffer the GPU fails two ways at once: a
render pass storing into bit-24 memory beside encoders made under protection
options, each encoder followed by an event signal. The Vulkan platform died at
such a commit because nothing measured which failure wins. oracle_twinwrites
records what Metal stores into a 4:4:4 surface's planes through the _sRGB twins
523 and 527, whose writes the runtime refuses for want of those bytes. Both are
written from scratch, and build.sh builds them with the other probes.
2026-11-14 09:15:10 -08:00
Anees Iqbal f11fd8f5c0 📦 Rebuild both guest sets with the completion and ring 0 changes
The x86-64 and arm64e sets from this tree: the bundle's completion thread
arming an idle ring once, its deliveries arming the held destroys' timer
after their waiters go, and the kext writing ring 0's submit data through
a write-combined map on x86-64. Built by m3-max-29200 on the M3 Max, where
make -C guest test and make -C guest prebuilt-check passed.
2026-11-14 07:50:59 -08:00
Anees Iqbal 1de7739292 🐎 Write ring 0's submit data through a write-combined map
The region is uncached to the guest's kernel on an AMD host, where a store
to it runs at 13 MB/s, and the kext wrote each message of ring 0's submit
ring there word by word: in a guest ktrace of Geekbench's Metal Super
Resolution a SubmitBatch call, which a commit makes to post the creates and
destroys held before it (749 of 910 commits), took 33.6 us p50 on the 780M
host against 15.2 us on the Iris Xe host, whose EPT ignores the guest's
memory type. Where the region's write-combined mappings are ordinary memory
(x86-64), the kext now writes the data's pages past the header's through a
write-combined map of a descriptor of its own, and fences its stores before
it publishes the producer (RgfxControlRing.hpp); the header and the first
page stay uncached. arm64 writes as before. The host reads the same bytes in
the same order. control_ring_test holds the order under both rules.
2026-11-14 07:50:59 -08:00
Anees Iqbal 15df01ce67 🐎 Arm the held destroys' timer after a delivery's waiters go
A command buffer's delivery releases what the buffer kept before it lets
its waiters go, as Metal does, and the destroys those releases hold armed
their 1 ms timer there: a dispatch_after, whose kevent wakes the dispatch
manager's thread. In a guest ktrace of Geekbench's Metal Super Resolution
on the 780M host that arm took the release 16.9 us p50 (30.2 p90) of each
delivery on the completion queue, between the app's handler and the wait's
return. The delivery now holds the arm (RgfxRingLaterArms) until its
waiters are let go: the destroys go as before, the timer from the end of
the delivery.
2026-11-14 07:50:59 -08:00
Anees Iqbal 839f920d8e 🐎 Arm an idle completion ring once, and store its count on a take
The completion thread pumps and arms every live queue's completion ring on
each pass, and the ring headers are uncached memory to the guest: a store
there costs about 0.3 us on an AMD host, a load 0.1 us (design.md). A ring
the last pass armed and found empty is armed still while the host publishes
nothing, as the host clears `armed` only in a post, so the pass now reads
its `producer` alone, and a pump that took nothing leaves `consumer` as it
was. The host sees the same counts and the same arm.
2026-11-14 07:50:59 -08:00
Anees Iqbal 788561ff8f 📝 Record Metal's order of waits against handlers that block [ci skip]
oracle_waits on the 5300M, the 630 and the M3 Max: a queue's statuses,
handlers and waits run in one order on its completion queue. A status changes
before its stage's handlers, waits return only after them, and a handler that
blocks holds everything of its queue after it. Our delivery keeps that order.
The probe now counts a status its polling thread never read apart.
2026-11-14 07:50:59 -08:00
Anees Iqbal d89f0bdb7f 🆕 Add an oracle probe of waits against handlers that block
The guest's completion delivery runs a command buffer's completed handlers
before its waiters wake, and its fast path for a buffer with no handler waits
behind every earlier record of its queue. Whether Metal orders them so is what
decides how far that path can be cut. oracle_waits measures it on a Mac:
waitUntilCompleted and waitUntilScheduled against completed and scheduled
handlers that block, and a later buffer's waits against an earlier buffer's
handler that blocks.
2026-11-14 07:50:59 -08:00
Anees Iqbal a1da511c2a 🆕 Add oracle_readonly, the probe of writes into read-only memory
What Metal does with a GPU or CPU write into read-only memory (a no-copy
buffer or heap made with MTLResourceOptions bit 24, or over pages the
process maps read-only) decided where the Vulkan platform faulted, dropped
or ended the process, and only the M3 Max had been measured. oracle_readonly
asks every such write on any Mac, one shape a process against a writable
control: a render pass's stores and resolves of every action, colour, depth
and stencil, by the descriptor and late; a draw's, a kernel's and a blit's
texture writes; the CPU's replaceRegion:; and whether the queue runs on and
its second fault revokes it. oracle_readonly.sh DEVICE runs every shape.
dgpu-oracle.md Q38 holds what it found on the M3 Max, the Radeon Pro 5300M and
the UHD Graphics 630 (m3-max-29292 to m3-max-29294, m3-max-29309 to
m3-max-29311). It is written from scratch, in plain Metal.
2026-11-14 07:25:13 -08:00
Anees Iqbal 7c6149b53f 🆕 Add gameload's --private, its GPU-read Shared buffers made Private
A discrete GPU reads gameload's Shared buffers in system memory: the frame's
constants and the materials' argument buffers, which every vertex and fragment
reads, and the ICBs' argument buffers, which each encode thread reads. On the
RTX 3090 behind a Thunderbolt link, gameload's frame takes 46 ms of GPU time
against the RX 7900 XTX's 9.9 ms, and the link carries many small reads a
frame. --private frame,materials,args puts each in a Private buffer instead,
copied from its Shared one by a blit at the start of the frame (once where the
CPU writes it once), so a run with it measures what those reads cost.
2026-11-14 05:03:33 -08:00
Anees Iqbal 18310e5539 📦 Rebuild both guest sets with read-only pages blocks
The kext takes RGFX_FEATURE_READ_ONLY_PAGES and makes read-only pages
blocks, and the bundle lays read-only no-copy memory over them (the two
commits before this one). The x86 set (with the KDK) and the arm64e set are
rebuilt from the tree on the M3, with their sources records; make -C guest
prebuilt-check and make -C firmware prebuilt-check pass on it.
2026-11-14 04:03:18 -08:00
Anees Iqbal 320ad08811 🐎 Lay read-only no-copy memory over its pages, not a copy
newBufferWithBytesNoCopy: over Shared memory the process maps read-only took
a slab copy that the bundle merged from the memory at every commit using it.
On macOS 12.7.6's WindowServer, which wraps clients' Core Animation backing
stores (VM_MEMORY_LAYERKIT, mapped read-only, 8-30 MB each) so and draws from
them every frame, that merge was 14.10 s of the commit path's 14.25 s over a 451 s walk, 130,850 MiB
compared, and its commit-to-post wait 2-6 ms a frame where 14.8.9's is
20-60 us (appwalk14, ms01's Iris Xe).

Where the kext makes a read-only pages block (RGFX_FEATURE_READ_ONLY_PAGES),
such memory now lies over its own pages: the bundle asks the block for
reading alone and makes its BUFFER_OVER_PAGES with Metal's private bit 24,
sent to the host alone. The buffer answers the app's options, without the
bit, as Metal's does; its contents, length, allocatedSize and GPU address
(the pointer's offset in its page) answer as before. Read-only blocks join
only read-only ones. Read-only Managed memory keeps its copy: the host's two
copies would write the CPU copy back to the pages. Where the kext gives no
block (a host without the bit), the copy stays.

What changes for the guest, beside the time: the GPU's writes to such memory
follow accuracy-ledger.md's read-only-pages-written row, as Metal's do, where
the copy kept them in the slab for later command buffers to read:
- a shader's store, a blit's fill or copy and a pass's visibility results
  into it complete with their writes dropped, and later command buffers see
  the memory as it is;
- a pass that stores an attachment there (Store,
  StoreAndMultisampleResolve) fails its command buffer with
  MTLCommandBufferErrorPageFault, where the copy let it complete;
- the CPU sees its pages unchanged, as before.

On Linux the runtime makes a bit-24 buffer over a copy of the pages today,
compared with them at each commit that uses it, so the per-commit compare
moves from the guest's process to the host's commit until metal2vulkan
imports such memory in place.

The shell tests that held "read-only memory never asks for a block" now hold
the new route: the ask for reading alone, the bit on the wire and not in the
buffer's options, and the copy where no block is given. Both guest sets are
rebuilt in the 📦 commit that follows.
2026-11-14 03:39:14 -08:00
Anees Iqbal ccbcdabd6d 🆕 Make pages blocks of memory a process maps read-only
A no-copy buffer over memory its process maps read-only cannot lie over its
own pages today: the kext refuses the pages block, and the host would lay a
buffer over it that takes the GPU's writes. So the bundle syncs a slab copy
of it at every commit that uses it. macOS 12's WindowServer wraps clients'
Core Animation backing stores, mapped read-only into it (8-30 MB each), that
way, and spent 14.1 s of a 451 s walk syncing them (appwalk14, 12.7.6 on the
Iris Xe). This makes the device and the kext ready to keep them in place; the
bundle takes the route in the next commit.

What changes on the wire:
- A new feature bit, RGFX_FEATURE_READ_ONLY_PAGES (bit 45, FEATURES_HI bit
  13), offered wherever PAGES_BUFFERS is, and taken by the kext.
- A new SURFACE_PAGES flag, RGFX_SURFACE_PAGES_READ_ONLY (1 << 5), meaningful
  with RGFX_SURFACE_PAGES_PRIVATE alone (else INVALID_ARGUMENT): the pages
  block holds pages its process maps read-only.
- BUFFER_OVER_PAGES needs no new field: its options already carry
  MTLResourceOptions bit 24 to the host, which hands it to the runtime as
  memory whose GPU writes it drops (accuracy-ledger.md,
  read-only-pages-written).

The host keeps every object over a read-only block from writing its pages: a
BUFFER_OVER_PAGES without bit 24, a HEAP_OVER_PAGES, an ICB_SLOTS_IN_PAGES
and a MANAGED_BUFFER_CREATE or MANAGED_TEXTURE_CREATE whose CPU copy lies over
one are refused, each logged as the guest error it is. The block's view stays
the writable mapping of guest RAM.

Where the kext took the bit, PagesBlock makes a block of read-only memory too:
it wires the pages with kIODirectionOut, which asks the VM system only for
read access, completes them for that direction at the unwire, and marks the
block read-only (rgfxPagesWiring). Without the bit it refuses read-only
memory as before.

Why a feature bit, though reims-ctl ships the host and the x86 set together:
the mark is where the host holds the line, not a hint. A process can post any
message on its rings, so a forged BUFFER_OVER_PAGES without bit 24 over a
read-only block would let the GPU write pages the process maps read-only, a
file's page cache among them. A host older than the mark ignores it, so the
kext makes such a block only where the host took the bit. The arm64e set also
reaches VMs through Ambrosia's config bundle, apart from the host. Old guest
sets never ask, and change nothing; a new set on an older host gets no block
and keeps its copy.

The header is regenerated, and the option ROM's record takes the header's
new hash (the ROM's bytes are unchanged); both guest sets are rebuilt with
the bundle's change, in the 📦 commit after it. Tests: the
header test, the peer and offer tests, a decoder test of what a read-only
block admits and refuses
(a_read_only_pages_block_holds_only_buffers_that_drop_their_writes), and the
kext's features and pages-block tests.
2026-11-14 03:39:14 -08:00
Anees Iqbal 6beda4878b 📦 Rebuild both guest sets for the slabs' wait and the overlaps
Both sets built afresh from this tree on the M3 Max (Xcode 27.2, job
m3-max-28669: make -C guest test, make -C guest prebuilt, make -C guest
prebuilt-arm64e and make -C guest prebuilt-check, each exit 0), for the
Metal bundle's sources the two commits before this changed:
RgfxSlabs.cpp, RgfxSlabs.hpp and RgfxRegion.hpp (a take and a reclaim wait
for the slabs on their way back), RgfxAirArguments.cpp and
RgfxPipelineReflection.mm (the overlap refusals at newFunction). Only
RgfxGate, which carries the bundle, and the records change.
2026-11-14 01:59:55 -08:00
Anees Iqbal 9e942f2447 🐛 Refuse overlaps of half constants and function tables at newFunction
What changes for the guest: newFunction now answers nil with
MTLLibraryErrorDomain 3 (CompileFailure) and Metal's own lines ("error:
buffer argument b has invalid location (<0,1>) in k\n"), by any way of
making the function, where function constant values put two present
arguments of one argument table at overlapping locations through
(a) a predicate or an index computed from a half constant,
(b) an index computed through a conversion between a float and an integer,
(c) a function table (visible or intersection) or an acceleration
    structure (primitive or instance) at a buffer's location.
Before, newFunction made the function in those three cases and the
pipeline's create refused it later on the host (OverlappingArgument). Metal
refuses at newFunction (oracle Q33), and the bundle already did so for
every other case its AIR reader decides.

Why the bundle missed them: the initialisers' evaluator folded no half
constant's value; the compiler writes a float-integer conversion as a call
(air.convert.u.i32.f.f16 and the like), which it took as any value; and the
reader did not count a function table's or an acceleration structure's
location, whose table and word were not measured.

Q33's probe, oracle_overlap, gains eight functions (k_halfpred, k_halfidx,
k_fidx, k_sidx, k_vft, k_ift, k_pas, k_ias), measured on the 5300M, the 630
and the M3 Max (m3-max-28663, 28662, 28659). The three oracles agree on
every newFunction answer: function tables and acceleration structures take
locations of the buffers' table, with the word `buffer`; a half constant's
predicate and index, and an index through conversions truncated toward
zero (-1.5 gives -1), count as any other. One pipeline differs: the 630
refuses k_vft's compute pipeline where the table is called, its compiler
service dying (CompilerError 1, XPC_ERROR_CONNECTION_INTERRUPTED), while
the 5300M and the M3 make it. Making it stays inside what the x86 Macs
answer, so nothing here follows the 630 there; Q33 records it.

For the overlap check alone (rgfxAirConstantGlobals) the evaluator now
folds a half constant's value, rounds each half result to the nearest half
as LLVM folds a half, and folds air.convert of scalars between floats and
integers (a float to an integer only where the truncated value is in the
integer's range); the bodies' specialisation (reflection's used arguments)
still takes those as any value. The reader counts a function table's or an
acceleration structure's location in the buffers' table, and the check
names it `buffer`. test_overlapping_arguments_refused_as_metal compares
the eight new functions with this Mac's Metal for every value and way, and
checks the x86 Macs' words.

Still left to the host, written in Q33: an initialiser operation the
evaluator does not fold (vector or array elements, conversions of two
integers or of vectors, other calls), an air.buffer with no address space
(no form built writes one), and a function of a library Metal's link made,
which keeps no bytes.
2026-11-14 01:59:32 -08:00
Anees Iqbal 4b06fb8eb8 🐛 Wait for the slabs on their way back before refusing a buffer
A slab being let go leaves the slabs' books before its memory is back in its
source: its heap's destroy and its block's release, which the kext answers
once the host has let go of it, run outside the lock. A buffer create that
found no room, and whose own let-go of the empty and cached slabs found
nothing left to drop, asked its source again at once and answered nil while
another thread (or the background thread) was still giving those slabs back.
The region's reclaim answered the same way for any block it was asked for.

For the guest: newBuffer of a Shared or Managed buffer, and a block of the
region (a Shared heap, a texture's CPU copy, a staging window, a command
buffer's out-of-line message), could be nil near the region's or the pages'
end while another thread freed buffers. It found the memory a moment later.
test_slab_thread caught it once on the M3 (m3-max-25197): on that
4-thread test under Rosetta, development's slabs refused a 3 MiB take in 8,
9 and 3 of 1,000 runs (m3-max-28562, 28595, 28619). Each refusal came with
15 to 52 slabs, 42 to 154 MiB, out of the books and not yet back in the
source: a starved background thread had let doomed slabs pile up, and one
thread's evict was dropping them all. This branch: 0 of 1,000 and 0 of 2,000.

A take that finds no room now waits for the drops in flight and the doomed
slabs as it asks, then asks again; so does RgfxSlabs::reclaim, which then
answers true. Those are the drops its own dropDoomed(true) would have made
had it come first, on the same locks and the same host answers, so the wait
holds the thread on nothing that call does not. None of the region's
callers that reach the reclaim holds a lock the drop path takes (the
serializer's library-key, ICB, destroy and ring locks, the region's pages
lock): the argument encoders' answer blocks, an ICB's slots (its own slot
lock), a Shared heap, an IOSurface's shadow (its making lock), the upload
and body pools (an arena's lock, a queue's post lock), a library's staging
window (the stream lock), a texture's CPU copy. stats().dooming counts the
drops in flight too.

Tests: test_slab_take_waits_for_slabs_given_back and
test_region_reclaim_waits_for_slabs_given_back hold a slab's release at a
gate while another thread asks for its room: without the waits each answers
nil at once (both fail without their halves of the fix). test_slab_thread
also checks that every byte its source gave is a slab's.
2026-11-14 01:57:11 -08:00
Anees Iqbal 14c2c18e8c 🆕 Stamp each command buffer with the guest's clock (GUEST_TIMES)
The host sees a command buffer only once a queue's thread takes it off its
ring, so the app's encode and the buffer's way to the host show as one span
with nothing pending on the host. This adds the guest's stamps that split it,
a diagnostic.

What changes for the guest:
- The device offers a new feature bit, RGFX_FEATURE_GUEST_TIMES (bit 44,
  FEATURES_HI bit 12), and DRIVER_FEATURES takes it. The kext carries it.
- Where the device's word holds it, the bundle starts each command buffer's
  stream with a new op, RGFX_OP_GUEST_TIMES (0x000e, 32 bytes): the guest's
  clock as the buffer was made, as its commit was entered, and as its message
  went on its ring. The last is written under the ring's lock, after the copy
  and before producer is published; for a buffer in a block, into the block.
- After each VBLANK's reading of HOST_TIME the kext writes ring 0's new header
  fields: guest_clock_offset_ns (0x18), then guest_clock_bound_ns (0x20) with
  release, split out of reserved bytes. The host zeroes both as it initialises
  a ring.
- The decoder walks the op as a no-op, so it changes nothing a buffer does,
  and a host that did not offer the bit never sees it. Old guest sets carry
  no bit, send no op and leave the fields 0.

The header is regenerated, both guest sets are rebuilt from the same sources,
and the option ROM's record takes the header's new hash; the ROM's bytes are
unchanged. The tests cover the op's and fields' layout (the header test, the
kext's vblank clock test), the bit's negotiation (the kext's features test,
the peer and memory-map tests), the stamps (the bundle's serializer and shell
tests) and the walk (a cmdbuf test, and the fuzz's streams). The host's
reading of the stamps is the next commit.
2026-11-13 21:25:12 -08:00
Anees Iqbal a28ecb8955 🆕 Add gameload's cicb, a compute ICB of concurrent dispatches
G1, the host's replay of GPU-encoded indirect command buffers, has a compute
half that gameload's icb shape (draws only) never reaches. cicb is that shape:
a kernel encodes CICB_COMMANDS concurrent dispatches into a compute indirect
command buffer, every fifth reset, and a later compute encoder sets the
pipeline and its buffers at non-zero offsets and executes it. The commands
inherit the pipeline, and the encoder's buffers unless -b, where the kernel
sets each command's three buffers itself.

The dispatches sum their input into one word for each frame in flight, which
the CPU checks against its own sum as the frame slot comes back. A replay that
drops a command, a grid or an offset then fails the run (exit 1, cicb_bad)
instead of only running slower. -c sets the command count (512 by default),
which the frame constants carry in what was their pad word. The tools' README
names the new shape.
2026-11-13 18:30:24 -08:00
Anees Iqbal 7809cef902 📝 Record what aliased surface textures see in one command buffer [ci skip]
dgpu-oracle Q37 records oracle_surftex's aliasing cases on the three Macs: a
write through one texture over a plane reaches the next encoder's read through
another, tracked or behind a fence, on all three; the bytes past the plane's
texels are the surface's own on the M3 and the GPU's own on the x86 Macs. It
says which answer each wide home gives. Decided 14 in the device's design and
the oracle tools' list name the wide home and its copies.
2026-11-13 17:49:41 -08:00
Anees Iqbal 33cc8eff6e ✅ Ask what a wide reader reads past the plane's texels
The x86 Macs keep the CPU's bytes past the texels in the surface after a wide
texture writes them; the aliasing cases now count, where the wide texture
reads, the runs whose read of the bytes past the texels gave the CPU's.
2026-11-13 17:49:41 -08:00
Anees Iqbal 4679e24068 ✅ Count the texels and the bytes past them apart after an alias
The x86 Macs left the surface without the wide texture's writes after the
command buffer of an aliasing case, where the M3 held them: the count of the
surface after each run now takes the plane's texels and the bytes past them
apart, and counts the runs whose bytes past the texels still hold the CPU's.
2026-11-13 17:49:41 -08:00
Anees Iqbal 45cd68878c ✅ Ask oracle_surftex what aliased surface textures see in one CB
A texture over an IOSurface plane wider than the plane's texels gets a home of
its own on a host whose device cache lays the plane out at the GPU's pitch, so
the host has to know whether Metal shows one encoder's writes through one
texture to the next encoder's reads through another texture over the same
plane, in one command buffer. The aliasing cases write an L008 surface of
128-byte rows through an RG8 texture of the whole rows or an R8 texture of the
plane's texels, by a blit or a clear, and read them back through the other in
the next encoder, tracked and Untracked with a fence, 16 runs each.
2026-11-13 17:49:41 -08:00
Anees Iqbal f2d3443a05 🆕 Add gameload, a game-shaped Metal load beside the oracles
The perf ledger's AAA rows (heap shadows, format views, chunk imports, heap
compression, per-draw cost) each wait on a run that makes the load an AAA
Metal port makes, and none of our walks makes it. gameload is that load, our
own code: offscreen, a fixed number of frames, each frame's CPU, wait,
frame-to-frame and GPU times printed with their p50, p90 and mean, and the
measured window's start and end on the wall clock so a host's logs of the same
span can be cut to it.

A frame holds placement-heap streaming (slots made again at their offsets and
uploaded, BC7 where the device has it, a placed vertex buffer, transient
textures from an automatic heap made aliasable), render targets placed in a
heap, a 4x MSAA scene with depth resolved, composited through an sRGB view and
with a UI pass into a BGRA view, a GPU-encoded indirect command buffer, 4000
CPU draws and 1000 shadow draws over argument buffers, compute
post-processing and a blit stream with a read-back. Each of the eight shapes
turns off by name, so a run with one off measures its share; -b makes the
indirect command buffer inherit no buffers.

make -C guest/bundle/tools/gameload builds one universal binary (arm64 and
x86_64) for an Apple-silicon Mac, the Intel oracle and both guests. It has a
Makefile of its own because guest/bundle/Makefile is a source the prebuilt
guest sets record, and a target there would mean rebuilding both sets. The
tools' README gives the command lines the measured runs used.
2026-11-13 17:47:40 -08:00
Anees Iqbal 8d05592c7f 📦 Rebuild both guest sets for the texture usage rules
The bundle in RgfxGate leaves ShaderAtomic and 0x8 out of a texture's
answered usage, and ends the process at the usage bits and atomic formats
Metal's validation ends it at. Built by make -C guest prebuilt and
prebuilt-arm64e on the M3 (m3-max-27197) after make -C guest test passed.
2026-11-13 16:44:56 -08:00
Anees Iqbal 1b34bc2126 🐛 End the process at unknown usage bits and non-atomic formats
Metal's descriptor validation, which runs without the debug layer, ends the
process at every usage bit it names none for. The exceptions are 0x8, which
it takes and leaves out of the answer, and 0x4000, 0x8000 and 0x10000, which
it takes and answers. It names the bits in one line ("MTLTextureUsage has
unknown bits 0x1c0."). It also ends the process at ShaderAtomic on any
format but R32Uint and R32Sint, and on an Apple GPU RG32Uint; the x86 Macs
name RG32Uint in words of their own. This was measured alike on the M3 Max
(macOS 27.0.1), the AMD 5300M and the Intel UHD 630 (26.7.1), over an
IOSurface and over none, in oracle_surftex's sixth and seventh rounds:
0x40, 0x80, 0x100, 0x200 to 0x2000, 0x20000 to 0x100000, 0x1000000,
0x80000000, and BGRA8Unorm, R32Float, RGBA8Uint, R8Uint, R16Uint, RG32Sint,
RGBA32Uint and format 500 with the atomic bit.

The bundle ended the process at 0x80 alone and made the rest, so a guest
held textures no Mac makes. Now every creator ends where the Macs end, in
their words and order, on x86 and arm64 guests. An arm64 guest still makes
an atomic RG32Uint texture, as the M3 does.
2026-11-13 16:44:56 -08:00
Anees Iqbal bb60762eb0 🐛 Leave ShaderAtomic and 0x8 out of a texture's answered usage
An R32Uint texture over a BGRA surface made with ShaderRead, ShaderWrite and
ShaderAtomic answered usage 0x23 in the arm64 guest, where the M3 answers
0x3. The class is wider than surfaces: the M3 Max (macOS 27.0.1), the AMD
5300M and the Intel UHD 630 (26.7.1) all leave ShaderAtomic (0x20) and 0x8
out of every texture's usage answer, over an IOSurface of each kind and over
none, in Managed, Shared and Private storage, and so do the texture's views
(oracle_surftex's sixth and seventh rounds: 0x23 answers 0x3, 0x20 answers
0, 0x29 answers 0x1). Bits 0x4000, 0x8000 and 0x10000 are answered as given.

x86 and arm64 guests both answered the bits as given. The answer now masks
them, while the wire keeps the usage the descriptor gave, so the host's
texture still takes the atomic bit. isCompressed reads the usage the texture
was made with, as it did through the answer before.
2026-11-13 16:44:56 -08:00
Anees Iqbal 5b381d1e86 ✅ Ask oracle_surftex every usage bit Metal names none for
The sixth round showed all three Macs end the process at usage bits 0x40
and 0x100, drop 0x8 from the answer and keep 0x4000 and 0x10000, and end
it at the atomic bit for every format but R32Uint, R32Sint and, on an
Apple GPU, RG32Uint. The seventh round asks each other bit alone, three
at once, and more formats with the atomic bit, so the bundle's rule
covers the class and not the bits seen so far.
2026-11-13 16:44:56 -08:00
Anees Iqbal 585a37a370 ✅ Ask oracle_surftex which usage bits a surface texture keeps
The arm64 guest answered usage 0x23 for an R32Uint texture over a BGRA
surface asked for ShaderRead, ShaderWrite and ShaderAtomic, where the M3
answers 0x3. One case can't say which bits Metal drops, for which formats,
or whether the surface or the format decides. The sixth round asks the
atomic bit across formats, storage modes and surfaces, with and without
PixelFormatView, bits Metal has no name for, the same descriptors over no
surface, and a view of the texture over the surface.
2026-11-13 16:44:56 -08:00
Anees Iqbal e617b1a999 🐛 Keep no-copy buffers and function tables NonVolatile
Metal's no-copy buffers answer NonVolatile to every purgeable state they are
told, on the M3 Max, the AMD Radeon Pro 5300M and the Intel UHD 630 alike
(oracle_bundle purgeable.kinds), as views, textures over buffers and heaps'
resources already do here: the host backs none of them with a purgeable
allocation of its own. The bundle's no-copy buffers kept the state told.

A visible function table answers NonVolatile on the M3 Max and the Intel 630,
where the AMD 5300M keeps the state told; the bundle answered the AMD's (2,
then 3 when asked). It now answers the M3's and the Intel's on every guest.

What the guest sees: setPurgeableState: on a no-copy buffer or a visible
function table answers NonVolatile, whatever was set before, and isPurgeable
answers NO. Every other resource keeps the state told, as before. The oracle
doc records the measurement (Q35), and both guest sets are rebuilt.
2026-11-13 14:24:45 -08:00
Anees Iqbal d672b9d661 ✅ Probe each resource kind's purgeable states in oracle_bundle
The arm64 walk found a visible function table keeping the Volatile state it
is told on the guest, where the M3 Max's stays NonVolatile. Before the
bundle's answers change, purgeable.kinds measures the states every kind of
resource the device makes answers, buffers, views, textures over buffers and
IOSurfaces, heaps and what they hold, and indirect command buffers, so the
rule comes from measurements on each reference GPU.
2026-11-13 14:24:45 -08:00
Anees Iqbal b615cec64c 📦 Rebuild both guest sets for the arm64 guest's Apple answers
The bundle inside RgfxGate now answers an Apple GPU's depth/stencil
queries, constant buffer alignment in reflection, function handle ids and
byte libraries' executable-path names; both sets are rebuilt from the tree
with them.
2026-11-13 13:05:57 -08:00
Anees Iqbal 11d137d7b8 ✅ Probe what Metal's base device answers under a feature profile
The arm64 guest's device answers the x86 Macs' feature profile, 10002,
where the M3 Max answers 10. Metal reads the profile at device creation and
keys limits, families and feature queries on it; this probe prints what the
base device answers under each profile asked, so the change to 10 can be
weighed against what the device itself answers.
2026-11-13 13:05:57 -08:00
Anees Iqbal 674370fdc2 📝 Record the M3 Max's answers to the rest of the x86 rules [ci skip]
Q34 gains the answers arm64rules2 measured on the M3 Max under macOS 27.0.1:
the depth/stencil queries, ids and words the arm64 guest now takes, and
those the M3 gives as the x86 Macs do (a state's resourceIndex and
uniqueIdentifier, dynamic library refusals, a dylib's exported function,
texture addresses, the indirect command read-back), so they stay as they
are.
2026-11-13 13:02:55 -08:00