Commit Graph
253 Commits
Author SHA1 Message Date
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 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 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 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 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 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 1f840cd203 🐛 Load a byte library's executable-path names on an Apple GPU
Both x86 Macs load the install names of a library read from a file alone:
a kernel whose library was made of bytes or of source refuses its pipeline
though the named file is there. An arm64 guest's device answers as an
Apple GPU, and the M3 Max makes both pipelines, bare and with the library
preloaded, and they run as the file's (oracle_fnptr Apple, macOS 27.0.1).

The arm64 guest's pipelines now load such a library's @executable_path
names; its @loader_path names, of which a library of no file has no
directory, still refuse it, as nothing measured them. An x86 guest's
pipelines refuse as before, which the test keeps beside the Apple answer.
2026-11-13 13:02:55 -08:00
Anees Iqbal f71b060b0c 🐛 Answer 0 for a function handle's gpuResourceID on an Apple GPU
Both x86 Macs' function handles raise an unrecognized selector at
gpuResourceID, and so did ours on every guest. An arm64 guest's device
answers as an Apple GPU, and the M3 Max's handles answer 0, for a compute
pipeline's linked functions and a render pipeline's fragment functions
alike (oracle_fnptr Apple, macOS 27.0.1).

The arm64 guest's handles now answer 0; an x86 guest's still raise, which
the test keeps beside the Apple answer.
2026-11-13 13:02:55 -08:00
Anees Iqbal 2db7041e50 🐛 Answer an Apple GPU's depth/stencil reads and writes
Apple's GL renderer asks a depth/stencil state it binds whether it reads
and writes depth and stencil. Both x86 Macs' states answer YES to all four
for every descriptor, and so did ours on every guest. An arm64 guest's
device answers as an Apple GPU, and the M3 Max's states answer what the
descriptor does (oracle_bundle Apple ds.queries and ds.grid, 717
descriptors under macOS 27.0.1): writesDepth is the depth write;
readsDepth is that, or a depth compare other than Always and Never; a face
writes the stencil where its write mask is not 0 and an operation is not
Keep, and reads it where it writes it, or its read mask is not 0 and its
compare is neither Always nor Never.

The arm64 guest's states now answer that; an x86 guest's still answer YES,
which the test checks for each descriptor beside the Apple answer.
2026-11-13 13:02:55 -08:00
Anees Iqbal ea05c9f1c8 🐛 Reflect a constant buffer's own alignment on an Apple GPU
An arm64 guest's device answers as an Apple GPU, whose Metal reference is
the M3 Max. Its pipeline reflection answers a constant buffer's alignment,
and its pointer type's, as the pointee's (16 for a struct of float4x4
members, 8 and 4 for others), where both x86 Macs answer 32: measured by
tools/pipeline_reflection_check Apple under macOS 27.0.1, whose only other
differences are compiler flags in instance variables no getter reaches.

The arm64 guest's pipelines now reflect the M3's alignment; an x86 guest's
answer stays 32, which the test checks beside the Apple one.
2026-11-13 13:02:55 -08:00
Anees Iqbal e55e1f64c1 🐛 End the process at depth textures over a buffer on an Apple GPU
Guest-visible on an arm64 guest (and wherever the device answers an Apple
family): a texture of a depth or stencil format over a buffer's bytes, by the
public newTextureWithDescriptor:offset:bytesPerRow: and the linear SPI, now ends
the process with the M3 Max's words ("Linear texture: cannot create
compressed, depth, or stencil textures, pixelFormat (...) disallowed",
_mtlValidateStrideTextureParameters), sending nothing, where the bundle made
it: an Apple GPU's descriptor validation takes depth and stencil textures in
Shared storage, so the x86 Macs' end at the storage never came.

Measured: the M3 Max under macOS 27.0.1 with no validation layer ends the
process there at Depth16Unorm, Depth32Float, Stencil8, Depth32Float_Stencil8
and X32_Stencil8 in Shared storage over a Shared buffer, and at Depth32Float by
the linear SPI (oracle_bundle Apple buftex.depth*, linear.depth, 11-13). x86
guests keep the x86 Macs' end at the descriptor's validation
(buffer-texture-depth).
2026-11-13 12:10:35 -08:00
Anees Iqbal 120c54ef7f 🐛 Answer linear texture alignments by an Apple GPU's rules on one
Guest-visible on an arm64 guest (and wherever the device answers an Apple
family): minimumLinearTextureAlignmentForPixelFormat: now answers the device's
alignment for the formats the M3 Max answers and ends the process at the rest
as it does, where the bundle took the x86 Macs' set. It answers 111 more raw
values: those the x86 Macs lack but Invalid, D24S8 and X24S8 (B5G6R5, A1BGR5,
ABGR4, sRGB R8 and RG8, Unspecialized, the two-plane and XR10 formats) and
values of no name in the SDK (26, 44, 66, 116, 501, 504, 521, 524, 546 to 548,
560, 562 to 613, 615 to 629). It ends at PVRTC, EAC, ETC2 and ASTC with the
compressed formats' words, and at 651 and 652 with the depth/stencil words,
where it said Invalid.

Measured: the M3 Max under macOS 27.0.1 with no validation layer, at each raw
value from 0 to 799 and 1000, 1023, 4096 and 65535, one child process each
(oracle_bundle Apple linalign, 11-13): 175 answered (16 each), 82 compressed,
7 depth/stencil, the rest Invalid. rgfxLinearAlignmentAnswer classifies a
value for a device; test_linear_alignment_as_an_apple_gpu checks every value
against the M3's table and that the x86 Macs' 64 stay where the device
answers no Apple family.
2026-11-13 12:10:35 -08:00
Anees Iqbal 41266883c2 🐛 Make Shared heaps on an Apple GPU, as the M3 Max does
Guest-visible on an arm64 guest (and wherever the device answers an Apple
family): newHeapWithDescriptor: with Shared storage now makes a heap over a
block of the device region (RGFX_CMD_HEAP_OVER_HOST_MEMORY), whose buffers'
contents lie there, where the bundle ended the process with the x86 Macs'
"Heap Descriptor Validation\nShared storage mode disallowed".

The M3 Max under macOS 27.0.1 makes a 4 MiB Shared heap, Shared buffers in it
whose contents the CPU reaches, and a Shared texture in it (oracle_bundle Apple
heap.shared, 11-13). The heap over host memory is the path the bundle took for
every Shared heap before 0f9108bdf moved the x86 guests to the x86 Macs' end;
it is restored for Apple GPUs alone. x86 guests keep the end
(heap-shared); test_shared_heaps_on_an_apple_gpu checks the new heap.
2026-11-13 12:10:35 -08:00
Anees Iqbal d0ddab6e38 🐛 Answer a view in no format nil on an Apple GPU, as the M3 Max does
Guest-visible on an arm64 guest (and wherever the device answers an Apple
family): newTextureViewWithPixelFormat: and its forms in
MTLPixelFormatInvalid now answer nil, sending nothing, where the bundle ended
the process with the x86 Macs' words ("texture view pixelFormat
(MTLPixelFormatInvalid) not castable").

The M3 Max under macOS 27.0.1, with no validation layer, answers nil for that
view (oracle_bundle Apple view.noformat, 11-13), and ends the process at the
view's other rules in the x86 Macs' words: a format of another class, levels
or slices past the texture's, a type of another family and a cube of slices
not a multiple of six (view.class, view.levels, view.slices, view.type and
view.slicecount). rgfxEndAtViewMetalEnds takes the texture's device for it.
x86 guests keep the x86 Macs' end; test_views_as_an_apple_gpu checks the new
answer beside the old test, and two of the shared rules on an Apple GPU.
2026-11-13 12:10:35 -08:00
Anees Iqbal 8cf2932fa5 🐛 Answer textures over a surface by an Apple GPU's rules on one
Guest-visible on an arm64 guest (and wherever the device answers an Apple
family): newTextureWithDescriptor:iosurface:plane: now ends the process at a
Cube or CubeArray texture over a plane of a surface with planes, and answers
nil, sending nothing, for a compressed format (BC, ASTC, ETC2, EAC, PVRTC)
over any surface once its rows and height fit, and for a two-plane format of
4:2:0 or 4:2:2 chroma of an odd width or height that is a render target or
that a shader writes. It made each of these.

These are the M3 Max's answers under macOS 27.0.1 with no validation layer
(oracle_surftex Apple, 11-13, Q20): IOGPUMetalTexture asserts
"carriesComplexTexture || numFaces == 1" at every cube over a plane, of a
one-plane BGRA surface and a 420v one's luma plane, and answers nil for the
others over a surface without planes, a one-plane surface and either plane of
a 420v one; 4:4:4 and XR10 two-plane textures and read-only ones of odd sizes
it makes. An arm64 Mac's GPU is always Apple's, so an arm64 guest's frameworks
expect these answers. x86 guests keep the x86 Macs' answers, which make BC
textures wherever their rows fit and cubes over a plane, and end the process
at every two-plane format: the new test checks every case against both.
2026-11-13 12:10:35 -08:00
Anees Iqbal c178927136 🐎 Check argument overlaps without following the entry's body
Batch 41's overlap check (1fc43b257) runs at every newFunction with constant
values whose arguments may overlap. It ran rgfxAirSpecialise, which runs the
module's initialisers and then follows the entry point's body twice, with the
values and blind. The check reads only the initialisers' globals: each
argument's predicate, index and count. The body passes were 99.5% of its cost.
For VideoToolbox's VTMTSComputeFunction, which its pixel transfers make for
every tile of a HEIC decode, a specialisation took 35.6 ms against 0.19 ms for
the initialisers alone (measured on the M3 Max, macOS 27). The guests' heic
step slowed from 6-7 ms a tile to 52-104 ms on every GPU.

rgfxAirConstantGlobals runs the initialisers alone, through the same
Specialiser and the same reading of its memory that rgfxAirSpecialise uses for
its globals. RgfxOverlappingArgumentError takes its globals from it. The
answers are unchanged, and test_overlapping_arguments_refused_as_metal still
compares each against Metal's. A new shell test counts the bodies followed over
sixteen makes each of a function that is made and one that is refused, with the
same values: none.
2026-11-13 11:19:22 -08:00
Anees Iqbal 36470e8d18 ✅ Count the copy header's two new words in the tests
The surface header grew by the unlock seed a copy was synced at and its
write-held flag (the copy's unlock sync, the commit before), which moves every writers offset 8 bytes on.
The tests' header size still said 24, so each writers offset they expected
was 8 short.
2026-11-13 11:10:25 -08:00
Anees Iqbal 808431e933 ✅ Test a surface copy synced while another holder writes
Two holders of one IOSurface's copy, this process and another the test
plays: the other's CPU writes the surface under a read-write lock and its GPU
writes the shared block. A commit made while the other's CPU holds its lock
copies the pages half written, and IOSurface's seed moved at the lock, not
at the unlock, so nothing copies the finished write until the next lock: the
copy keeps the torn pages. The test checks that the commit after the unlock
copies the whole write, that a settled copy neither copies nor asks again,
and that the other holder's named GPU write is not copied over before its
write-back, for a shared block and for one of the process's own.

The region gets a source for a surface's lock and unlock seeds, which the
test plays as IOSurface keeps them. The test fails here: the fix follows.
2026-11-13 11:10:25 -08:00
Anees Iqbal 7c9c37a4f6 ✅ Hold the guest tests' timing checks under load
Batch 42's guest test (job m3-max-25789) failed under the M3's load at
serializer_tests.cpp's CHECK(ending.calls.empty()): with setBatch's timer at
1 ms, a test thread held off a CPU for 1 ms after postLater let the timer
post before the writer's end. It is the class of the room-record test's
failure: a check that holds only while a thread runs within a time window.
The other guest test sites of it, found by reading every sleep, clock read
and timer delay in the bundle's and the kext's tests:

- serializer_tests, test_held_destroys, the writer's end: a run counts only
  where the look at the calls comes within the timer's 1 ms from before the
  post; runs repeat, up to 50, until one does. The calls are read under the
  log's lock, as the timer's thread writes them.
- serializer_tests, test_ring_post_waits_for_room: the post's time, checked
  to be at least 15 ms, was counted from after the host's thread started its
  20 ms; it is now counted from before, so a late start of this thread no
  longer shortens it.
- queue_tests, test_submitted_waits_for_the_buffers_before: the same for the
  40 ms the wait must last, against the thread that commits after 50 ms.
- shell_tests, test_submitted_at_the_doorbell_wakes_no_thread: the
  completion thread's late wake came 400 ms after the doorbell, and the test
  checked the call took under 200 ms and the record was still untaken. The
  wake now waits for the test to let it go (or 5 s), so the test checks the
  call returned before the wake and the record untaken, with no window.

Each keeps what it checks. The rest hold under any delay: lower bounds
counted from before what they wait for, negative checks of work nothing
lets run, and bounded waits of seconds.
2026-11-13 09:49:33 -08:00
Anees Iqbal e8f925660b ✅ Give the overlap test's library the bytes it is made of
The device keeps a library's bytes, which its functions' AIR is read from; the
test's library, made apart from the device, kept none, so the overlap check had
no AIR to read and accepted every function. The test now gives it its bytes, as
the device does.
2026-11-13 08:43:22 -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 84a38bf2d9 ✅ Hold a pages block's memory in the remap test's fake
test_no_copy_buffer_over_remapped_memory_takes_its_own_block failed twice on
the M3 Max (m3-max-22849, m3-max-22981) at its check that the kext is asked
again for new memory mapped over a live no-copy buffer's: the fake pages
block source held nothing of the old memory, the overwrite freed its VM
object, and a new object can take a freed one's id (object_id_full), so the
region told the new memory for the old. 41feda1f7 held a memory entry of the
old memory in the test's body.

In the guest the kext holds it for the block's life: the block's prepared
IOMemoryDescriptor wires the pages through vm_object_iopl_request, which
begins an activity on the object, and the object's termination, handed to
the reaper, waits for that to end before the object is freed (XNU,
osfmk/vm/vm_pageout.c and vm_object.c, read from code). 149fc57c8 measured
the same in a macOS 26.7.2 guest: the id came back in 0 of 200 overwrites
under a live buffer. The bundle needs no change.

The fake now holds as the kext does: each pages block takes a memory entry
of its bytes when it is made and lets it go at its release. The test checks
the cause, deterministically, where it checked a symptom the kernel's
allocator shows in some runs: before the overwrite the old memory's object
has a reference past the app's mapping (vm_region_recurse_64's ref_count is
2 or more), which a fake holding nothing never gives it; after it the new
memory's identity differs from the old; and once both blocks are back the
fake holds nothing.
2026-11-12 21:46:32 -08:00
Anees Iqbal ecf693f1bf 🐎 Build a large command buffer's message off its block
A message too large for half its queue's ring was built in a block of the
queue's pool once it outgrew the ring, and grew from block to block. The
block is write-combined where the kext maps it so, and on an AMD host, which
applies the guest's memory type, a write-combined store still pending
stalls the encoding thread's next locked instruction until it drains. Every
retain and release on that thread, the app's and ours, paid it: on a
26.7.2 guest of a Ryzen host (RTX 3090), encode_probe's
setRenderPipelineState took 108 ns a call in a 10000-call buffer against
21.6 ns in a 400-call one, which stays on the builder's heap, and a
setVertexBuffer between a CFRetain and a CFRelease 103 ns against 17.1 ns.
Growing from block to block also read the old block back, uncached.

The message is now built in the builder's own buffer whatever its size,
which grows to the queue's guess as it outgrows the ring, and the commit
copies it once, whole, into a block from the block's start. The host reads
the same COMMAND_BUFFER bytes; only where the message lies in its block
changes. The tests that held the old placement change with it.
2026-11-12 16:14:00 -08:00
Anees Iqbal 41feda1f79 ✅ Keep the old memory alive in the remapped-memory test
test_no_copy_buffer_over_remapped_memory_takes_its_own_block maps other
memory over the address a live no-copy buffer lies over and checks that the
next buffer there takes a pages block of its own. Nothing in the test held
the old memory's VM object, so the overwrite freed it, and its id can come
back as the new object's: the region then told the new memory for the old,
and the check that the kext is asked again failed in one of two runs of the
same tree on the M3 Max (m3-max-22981; development's passed, m3-max-22986).
In the guest the kext's wiring of the live buffer's pages holds the object;
a memory entry of the old range now holds it in the test.
2026-11-12 16:14:00 -08:00
Anees Iqbal d13d23593b 🐎 Read a function's AIR without its bodies until asked
A new function's first read of its AIR module decoded the bodies of every
function of a module that declares function constants, which only a
pipeline's reflection, an OpenCL-mode function and constants set by name with
no function list to resolve them use. That decode is most of the read:
MPSNeuralNetwork's cnnConvArray took 391 us with it and 40 us without,
Espresso's dequantizeGeneric 54 and 17 (M3 Max, macOS 27), and Vision's first
newFunctionWithName: of an MPS kernel took 0.16 ms in the 26.7.2 guest where
the AMD 5300M takes 0.01 ms.

The module cache now keeps two reads of a module: its arguments and visible
functions alone, made at the first ask without the entry points and costing
its bytes, and the read with them, made at the first ask with them and costing
its code. A library's entry point that a pipeline's reflection asks for is so
read twice, once for each kind. Nothing the guest observes changes: the
arguments and visible functions are the readers' own answers either way, and
every library over equal bytes still shares one read of each kind.
2026-11-12 13:28:15 -08:00
Anees Iqbal d96a612b55 🐛 Check compute pipelines' threadgroup fields as Metal does
The bundle kept requiredThreadsPerThreadgroup guest-side and sent the host
none of it, so a compute pipeline whose required size is past its kernel's
[[max_total_threads_per_threadgroup(n)]] was made, where Metal's compile
refuses it. maxTotalThreadsPerThreadgroup against the kernel's attribute and
the device's limit went unchecked guest-side too, and macOS 27's
forwardProgressUsage and contentionRelief were taken whatever their value.

oracle_threads measured each case on the AMD 5300M, the Intel 630 and the
M3 Max (m3-max-22216, 22217, 22214; dgpu-oracle.md Q32). The AIR reader now
reads a kernel's attribute (air.max_work_group_size), and the bundle checks
the fields before it posts the create, in the x86 guest the AMD GPU's way
and in the arm64 guest the M3's, as its validation and compiler do.

What the guest observes: a required size with an axis of 0, past the
device's limit or past the descriptor's maximum ends the process at Metal's
failed assertion; a required size past the kernel's attribute, a descriptor
maximum other than the kernel's or past the device's limit, and a forward
progress usage or contention relief Metal does not name are refused with
the device's error, and nothing is posted; a pipeline of a required size
answers its threads as maxTotalThreadsPerThreadgroup; and forwardProgressUsage
Automatic answers Weak. The tests that held the old answers change with it.
2026-11-12 12:45:37 -08:00
Anees Iqbal 7ff8cfb02e 🐛 Reflect post-tessellation vertex functions' control points
A post-tessellation vertex function's control point input
(air.patch_control_point_input) takes two nodes the AIR reader did not
follow, its control point function's and its attributes', so the reader
gave up on the whole entry point and its pipelines got no reflection: a
creator asked for reflection answered nil where Metal answers one.

The reader now follows them, keeping each attribute of the control point,
and reads the entry's patch type (air.patch). The reflection answers what
the AMD 5300M, the Intel 630 and the M3 Max agree on, measured with
pipeline_reflection_check's patch cases (m3-max-22312, 22313, 22314): the
control points and the patch's attributes are no bindings, the vertex
descriptor's buffers are unused though the function reads them,
position_in_patch and patch_id are built-ins 14 and 13, and the dump stride
adds the patch's position, 12 bytes for a triangle and 8 for a quad, taken
or not. Two new probe functions (a triangle patch that takes no position,
and a quad that takes one it never reads) pin the last rule.

What the guest observes: those pipelines' reflection, where it got nil.
2026-11-12 12:45: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 50be7d4a9a 🆕 Carry compute dynamic libraries to the host
An x86-64 guest's device made no dynamic library: newDynamicLibrary:error:
and newDynamicLibraryWithURL:error: were RGFX_UNSUPPORTED, so a kernel linked
against a dynamic library could not be made. The platform makes them and
links them (the commit before), and nothing carried them from the guest.

What changes for the guest: the device offers feature bit 40,
DYNAMIC_LIBRARIES (FEATURES_HI bit 8), on every host, and the kext takes it.
Where taken, ring 0 carries DYNAMIC_LIBRARY_CREATE (0x239: the dynamic
library's ObjId and its library's), answered by COMPLETE with its status, and
a COMPUTE_PIPELINE_CREATE ends with a run of RgfxPipelineLibrary records
(library_count, where reserved_5c was): each a dynamic library, preloaded
where it has no install name, else the library that install name loads. The
bundle's RgfxDynamicLibrary answers its library's install name and writes its
bytes to a file URL; newDynamicLibraryWithURL: reads the file in the guest's
process with the AMD Radeon Pro 5300M's and the Intel UHD Graphics 630's
answers (measured, macOS 26.7.1, oracle_urls and oracle_fnptr: a nil URL,
bytes that are no metallib, a library that is not dynamic, a missing file).

Metal reads the file each install name of a library made from a file names
when it creates a pipeline, and none of a library made of bytes or of source
(measured, both Macs, oracle_fnptr: the linked kernel's file makes its
pipeline, and the same bytes through newLibraryWithData: are refused). The
bundle reads them then too: every name the kernel's library, its linked
functions' libraries and these dynamic libraries name, from the executable's
directory, the loading library's or an absolute path, each sent by name. A
name that loads nothing, or that a library of no file names, refuses the
pipeline with the 5300M's CompilerError 2, beside a preloaded library or not,
so the host is never left to read a file of its own. A dynamic library's
install name is read from its metallib's HDYN NAME tag. Render stages carry
none.

A compile of source whose options name dynamic libraries reads each through
the private member airData, the one message Metal sends it (measured, both
Macs): the bundle's dynamic library answers its library's bytes, as Metal's
answers its file's, where it ended the guest's process with an unrecognized
selector before. The caller owns the answer, as it owns Metal's, which is a
new object at each call: the compile releases it, and an unowned answer ended
the guest's process with SIGSEGV after the compile.

supportsDynamicLibraries stays no in this commit; a later one answers it once
the guest's sets carry this bundle. supportsRenderDynamicLibraries stays no,
as the 5300M answers it.

The host knows bit 40 (KNOWN_FEATURES); the tests that probed an unknown bit
at 40 probe 41. The decoder's tests make dynamic libraries on the fake
platform and pass a run's libraries to the creator; the serializer's, the
shell's (the linkage reader, the routing and airData, a pipeline's loads and
refusals), the kext's and the members register's tests cover the guest's
side, and design.md describes the messages.
2026-11-12 08:14:05 -08:00
Anees Iqbal 019d941b54 🆕 Carry compute function pointers to the host
An x86-64 guest's device made no function handle or visible function table:
the bundle's members were RGFX_UNSUPPORTED and the device info held
supportsFunctionPointers at no, so an app took its fallback. The platform
makes them for a compute pipeline (the commit before), and nothing carried
them from the guest to it.

What changes for the guest: the device offers feature bit 39,
FUNCTION_POINTERS (FEATURES_HI bit 7), on every host, and the kext takes it.
Where taken, ring 0 carries FUNCTION_HANDLE_CREATE (0x236: the handle's
ObjId, the pipeline state's, and its function as an RgfxLinkedFunction) and
FUNCTION_TABLE_CREATE (0x237: the table's ObjId, the state's and its entry
count), each answered by FUNCTION_POINTER_STATE (0x40c: the status, and a
table's gpuResourceID, allocatedSize and resourceOptions), and
FUNCTION_TABLE_SET (0x238: a range of a table's entries, 0 a nil entry),
which is not answered and is carried out before any command buffer the
process posts after it. A compute pass binds a table at a buffer index
(RGFX_OP_COMPUTE_SET_VISIBLE_FUNCTION_TABLE, 0x201e) or a range of them
(0x201f), and an argument buffer holds a table by its gpuResourceID. The
bundle's RgfxFunctionHandle and RgfxVisibleFunctionTable answer from the
host's state; a handle of a function the state does not link is nil, as
Metal's is (RGFX_STATUS_NOT_FOUND), and gpuResourceID of a handle and
functionHandleWithName: raise the unrecognized selector the AMD Radeon Pro
5300M and the Intel UHD Graphics 630 raise (measured, macOS 26.7.1). A
table's allocatedSize and resourceOptions are the host's table's, inside the
two Macs' answers. A render pipeline's handles and tables stay unsupported,
with Metal's error. supportsFunctionPointers stays no in this commit: the
next one answers it.

The host knows bit 39 (KNOWN_FEATURES), so a driver's write of it is taken.
The decoder's tests make handles and tables on the fake platform and call
through them on the Vulkan platform; the serializer's, the shell's, the
kext's and the members register's tests cover the guest's side, and
design.md describes the messages.
2026-11-12 08:14:05 -08:00
Anees Iqbal 19c587e68b 🐛 Carry a rate map descriptor's mutability to the host
The bundle carried a descriptor's private mutability only where the public
MTLRasterizationRateMapDescriptor class answered it, and no Metal answers it
there: Metal's descriptors are of its private subclass, which alone declares
mutability (macOS 26.7.1 and 26.7.2, oracle_ratemap). So every map was made
Immutable, and a map the app made Mutable answered mutability 2 (measured in a
macOS 26.7.2 guest) where the 5300M answers 1.

What changes for the guest: a rate map whose descriptor answers mutability is
made of it on the host, and answers it; a Mutable map is the platform's
Mutable map. The shell test checks a fresh descriptor's 2 and a Mutable one's
1 in the create.
2026-11-12 08:14:05 -08:00
Anees Iqbal f5030a5f78 🆕 Carry rasterization rate maps to the host
The x86-64 guest's device made no rate map:
newRasterizationRateMapWithDescriptor: was RGFX_UNSUPPORTED, and the device
info held the layer count at 0, so an app that asks for a rate map (Apple's
Modern Rendering sample among them) took its path without one. The platform
makes rate maps (metal2vulkan's runtime compiles Apple's map, rate_map.rs
there), and nothing carried one from the guest to it.

What changes for the guest: the device offers feature bit 38, RATE_MAPS
(FEATURES_HI bit 6), on every host, and the kext takes it. Where taken, ring 0
carries RATE_MAP_CREATE (0x233) and RATE_MAP_RESET (0x234), both
RgfxRateMapCreate (the map's obj_id, the screen size, the private mutability
where set, and the layers' RgfxRateMapLayer records with their samples),
answered by RATE_MAP_STATE (0x40a: the map's screen size, granularity, layer
count, mutability and parameter data's size and alignment), and
RATE_MAP_QUERY (0x235), answered by RATE_MAP_ANSWER (0x40b): a layer's
physical size, a coordinate mapped either way, or a copy of the parameter
data, which the platform writes where a buffer of the sender's lies before it
answers. A render pass names its map after its other records
(RGFX_PASS_FLAG_RATE_MAP, RgfxRenderPassRateMap). The kext admits the three
messages, waits for their answers, and destroys a create it timed out on. The
bundle's map (RgfxRasterizationRateMap) answers the host's state, asks the
host each answer that takes an argument, copies into a Shared buffer of ours
in place and into any other through a scratch buffer of its own, answers the
SPI's mutability, minFactor, resetUsingDescriptor: and formattedDescription:
(the words of Metal's base map, measured on the AMD Radeon Pro 5300M), and
ends the process where Metal's map does: at a copy into a Private buffer, and
at a coordinate map the host refuses (a map of no layers or of an empty
screen, a Mutable map not yet reset). The layer counts stay 0 in this commit:
supportsRasterizationRateMapWithLayerCount: answers no until the device info
answers the platform's.

The core platform's map gains screenSize, which the state answers.

New tests: the decoder's create, reset, queries and copy (decode/rate_map.rs,
on the fake and on Vulkan), a pass's map (cmdbuf.rs), the header's checks of
the new names, the kext's feature, gate and reply types, and the bundle's
messages (serializer_tests), map (shell_tests, its two deaths among them) and
pass record (protocol_tests).
2026-11-12 08:13:36 -08:00
Anees Iqbal 3f278c9a99 🐛 Carry constant values where a function's declarations do not read
A function whose library entry names no constants takes its module's AIR
declarations. That covers a .metallib with no CNST tag: the GL renderer's, our
writer's, a library a framework makes from data. Where those declarations did
not read (a constant's node of a type or a form the reader does not follow),
newFunctionWithName:constantValues: resolved the values against an empty list
and dropped every one without an error. The pipeline then reached the host
unspecialised. The declarations were also asked through the function's
arguments, so a function whose arguments did not read lost its constants as
well.

Now the declarations are read from the function's module whatever else of it
reads. Where they do not read, every value the caller set is carried by index,
as set, as the values of a library whose table did not read already were. A
value set by name is carried at the index the module's air.function_constants
names it at (each node that reads), so none is dropped where its name is
known. A function whose module reads and declares none still takes no values.

What the guest sees: such a function's pipelines carry the constant values
the caller set, for the host to specialise by, where they carried none.

Not F13's cause: there the kernel's entry lists its three constants in a CNST
tag, and the host's refusal names the three values. The test spoils
every_constant's CNST tag and one constant's type in tests/air_arguments.metal's
library, and checks that each value reaches the function and its compute
pipeline, which links two private functions of the library.
2026-11-12 05:35:38 -08:00
Anees Iqbal 276e4ea3d3 🐛 Join a pages block only over the memory it was given for
00268441a lets a no-copy buffer join a live pages block when its address,
length and writability match. Matching values do not make it the same memory.
An object can outlive the app's hold of the memory under it, through a texture
over the buffer or a command buffer that holds it. In that time the app can
unmap the memory and map other memory at the same address. WindowServer does
this with CoreAnimation's shmem images. The new buffer then joined the old
block, so the GPU read the old pages, which the kext still had wired, while the
app wrote the new ones. In a macOS 26.7.2 guest, System Settings' "About" row
drew the Energy pane's title, clipped, in 3 of 8 pane switches on a Radeon 780M
and 3 of 8 on an RTX 3090. Setup Assistant's labels showed earlier panes'
strings in the same way at a379a5a45; that was not run again.

A block is now joined only where the memory at the bytes is the memory the
block was given for. rgfxPagesIdentity reads, for each VM region the bytes
span, the region's VM object (mach_vm_region_recurse's object_id_full) and the
offset in it. It is read once the kext has wired the block's pages, since
the wire gives a copy-on-write mapping an object of its own. A joinable block
whose bytes now hold other memory is joinable no longer, and the new buffer
takes a block of its own. So do bytes whose memory cannot be identified
(no object yet, a hole). The first refusal in a process logs one info line,
and each refusal logs a debug line.

With the check, no label drew stale in 16 switches on each GPU. In each run,
WindowServer refused joins over one-page images: 28 on the 780M and 15 on the
3090.

For the host, a buffer over remapped memory now names a pages block of its
own in BUFFER_OVER_PAGES, and its GPU reads and writes reach the app's current
memory. The guest's objects, GPU addresses and contents are unchanged.

Tests: the region joins over the same memory mapped again at the same
address and offset, and never over new memory at the same address with other
contents, over the same memory at another offset, or over memory with no pages
yet; a no-copy buffer over memory remapped while the first buffer lives takes
its own block, and a third buffer joins it.
2026-11-12 04:21:35 -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 fe9a056b7b 🐛 Carry each sampler's LOD bias and reduction mode to the host
A guest's samplers lost lodBias and reductionMode (macOS 26) on the way to
the host: SAMPLER_CREATE's extension, RgfxSamplerCreateExt, was on the wire,
but the bundle never sent it and new_sampler never read it, so every sampler
was made at bias 0 with weighted-average reduction. The guest's state cache
already keyed on both, so two descriptors that differed only there were two
guest samplers of one host shape.

The bundle now sends the extension with every create, on the posted and the
asked route. new_sampler sets the platform's reduction mode and its new LOD
bias from it, and leaves both unset for a create without one, which keeps
Metal's defaults. What the guest sees changes: a sampler of minimum or
maximum reduction samples that way, as Metal's does. The runtime's sampler
descriptor holds no bias yet, so a non-zero bias still samples at 0, and is
now relayed as inexact-sampler-lod-bias, with an accuracy-ledger row, until
the runtime takes one.

The header follows wire.rs's doc, the ROM's record that header (its bytes
are unchanged), and both guest sets are built again from these sources.
2026-11-12 00:04:50 -08:00
Anees Iqbal fedd9e8410 🐛 Make no-copy Managed buffers over app pages Managed on the host
A no-copy Managed buffer over writable app pages was one copy on every host:
the bundle sent its BUFFER_OVER_PAGES with Shared storage, and its
didModifyRange: and a blit's synchronize of it, or of a texture over it, sent
nothing (e828db91b). Apple's OpenCL makes each default cl_mem such a buffer and
binds it to every kernel, so on a host GPU with memory of its own the kernels
read and wrote it across the bus in system memory. CL makes the calls Metal
requires of a Managed buffer: synchronizeResource: before a map, and
didModifyRange: after a map for writing (measured with cl_bw on a macOS 26.6.1
guest on the RTX 5080 host).

The buffer is now a Managed buffer over a Shared one, as the pages slabs'
large Managed buffers are: the BUFFER_OVER_PAGES buffer, still Shared, is its
CPU copy, and a MANAGED_BUFFER_CREATE over it, at an address of its own that
keeps the pointer's offset in its page, is the buffer the app gets. At its
release the Managed buffer goes first, then its CPU copy, then the pages
block. A device that makes no Managed buffer over a Shared one gives such
memory the shadow, as read-only memory has.

What the guest sees: the host's object for the buffer has storageMode Managed,
and the buffer's didModifyRange:, a replaceRegion: of a texture over it, and a
blit's synchronizeResource: or synchronizeTexture: of it or of such a texture
now reach the host. On a host GPU of its own memory the buffer is two copies,
as the AMD 5300M's is: the GPU sees a CPU write only after a didModifyRange:,
and the CPU a GPU write only after a synchronize. On a GPU that shares the
CPU's memory it stays one copy, as the Intel 630's is.

The shell tests that held one copy now hold the two messages, the ranges and
synchronizes sent, the release order, and the shadow where the device makes
no Managed buffer over a Shared one; the serializer tests hold the Managed
create's offset.
2026-11-11 12:20:36 -08:00
Anees Iqbal c1da5cf831 🐛 Take a tiled texture's copy again after a replaceRegion of level 0
On the x86 Macs a replaceRegion: of a mipmapped tiled texture's level 0
writes the buffer's bytes, and the texture's copy of them is taken again at
its next GPU use, every level made from the new bytes, with no didModifyData
(measured on the AMD 5300M and the Intel 630 under macOS 26.7.1, added to
docs/graphics-kext/dgpu-oracle.md Q11 with what getBytes: and replaceRegion:
of each level reach there). The bundle wrote the buffer's bytes and told only
the buffer, so the host's copy kept the old texels.

What changes for the host: a replaceRegion: of level 0 of a texture over a
buffer of more than one level now also sends TEXTURE_DID_MODIFY_DATA, where
the host carries it. getBytes: and replaceRegion: of level 0 still address the
buffer's bytes, as both x86 GPUs' do. The levels above it stay the device
copy's; both x86 GPUs keep a replaceRegion: of those from the GPU, which no
app is known to make.

The shell test of the tiled form checks the message after a replaceRegion: of
level 0, and none for a texture of one level or where the host does not
carry it.
2026-11-11 11:46:13 -08:00
Anees Iqbal d4bc329148 🆕 Carry a mipmapped tiled texture's didModifyData to the host
A 2D texture of more than one level over a buffer (Metal's
newTiledTextureWithDescriptor:offset:bytesPerRow:) holds a copy of the
buffer's bytes on the x86 Macs, every level made from them, taken at its first
GPU use, and taken again at its first use after didModifyData (measured on
the AMD 5300M and the Intel 630, docs/graphics-kext/dgpu-oracle.md Q11). The
host's platform makes that copy since metal2vulkan's Texture::did_modify_data,
but the bundle sent nothing at didModifyData, so a texture whose bytes the CPU
changed after its first use kept the old ones for good.

What changes for the guest: the device offers feature bit 36,
TEXTURE_DID_MODIFY_DATA (FEATURES_HI bit 4), on every host, and the kext takes
it. Where taken, ring 0 carries a new command, TEXTURE_DID_MODIFY_DATA (0x232,
RgfxTextureDidModifyData, 24 bytes: the header and the texture's obj_id),
which the submit gate admits. The bundle sends it for didModifyData on a
texture over a buffer of more than one level; a one-level one tells its
buffer's didModifyRange as before. The host calls Texture::did_modify_data
in the context's order, before the next command buffer it carries out, and
refuses a texture it does not hold. Not answered.

TEXTURE_FROM_BUFFER's doc now says what the tiled form holds: a copy taken at
its first use and again after the new message, not its first level in the
buffer.

New tests: the message's order against a later command buffer
(a_texture_s_modified_data_is_carried_out_before_a_later_command_buffer), the
rows and second level a tiled texture holds after it, on Vulkan
(on_vulkan_a_tiled_texture_takes_the_rows_again_after_did_modify_data), the
header's checks of the new names, and the kext's and the bundle's tests of the
feature, the gate and the message.
2026-11-11 11:46:13 -08:00
Anees Iqbal 00268441aa 🐛 Lay no-copy buffers over the same bytes in one pages block
Each no-copy buffer over the app's own pages took a pages block of its own, so
two buffers over the same bytes had two host views of the same pages, and where
the views' gate refuses their import (a buffer of scattered guest pages at the
stock vm.max_map_count on NVIDIA), the runtime made a copy and a snapshot for
each. Apple's OpenCL makes such buffers: a Shared no-copy buffer over its
staging pages at each clEnqueueWriteBuffer, the same pages each time, while the
one before still lives. On the RTX 5080 host, each 256 MiB of them cost QEMU
512 MiB more Rss per write.

The region now gives a block asked for the same bytes, writability and join
again while it is joinable, so such buffers lie in one view and one copy, as on
a Mac they lie in the same pages. A block stays joinable until each buffer over
it has gone for the app, so a block is never joined over memory the app freed
and took again at the same address, and it goes back to the kext once the host
has dropped every buffer over it. A buffer of Metal's private bit 24, which the
host's runtime takes as read-only memory, joins only its own kind. Nothing
changes for the guest: each buffer keeps its object, GPU address and contents.

Tests: the region's joins and their release order, two no-copy buffers over
one block in the bundle, and the host's one view under two buffers.
2026-11-11 11:38:41 -08:00
Anees Iqbal 962e758b48 🆕 Answer the GL renderer's restart and provoking-vertex setters
The render encoder now answers setPrimitiveRestartEnabled:index: and
setProvokingVertexMode:, as the Intel UHD 630's encoder does. The AMD Radeon
Pro 5300M's answers neither (respondsToSelector:, macOS 26.7.1). What the 630
draws under them, measured with Metal calls of our own:
- setPrimitiveRestartEnabled:YES index:k makes indexed line and triangle
  strips after it restart at k alone, 16- and 32-bit, and draw the all-ones
  index as a vertex. NO makes them restart at their index type's all-ones index
  again, as without a call, whatever k is.
- setProvokingVertexMode: 1 takes flat inputs from a primitive's last vertex
  (strip triangle i's vertex i + 2), and 0 from its first.

The wire and the host carry both already. The host draws the index a restart
op carries whether it is enabled or not, so a call that is not enabled posts
the all-ones index (0xffffffff, which a 16-bit strip takes as 0xffff), and only
after an enabled call in the same encoder. An enabled call posts its index once
while it stays. A parallel pass sets both back to their defaults between its
sub-encoders. The register lists both members as implemented.

What the guest sees: the GL renderer no longer writes
"setPrimitiveRestartEnabled:index: unsupported!". It sends the setter before
its draws, never enabled whatever GL's restart state (traced on the 630), and
restarts GL's strips itself, so on our device the setter posts nothing and
every GL draw stays as it was. The renderer still writes
"setProvokingVertexMode: unsupported!" and never sends that setter, on our
device as on the 630, whose encoder answers it. So a flat-shaded line under
GL's default convention keeps its first vertex's colour, as through the same
renderer on the 630.
2026-11-11 08:23:42 -08:00
Anees Iqbal 72340455c7 🐛 Make pre-13 arguments of the classes of their kinds
Before macOS 13 a pipeline's reflection made every binding an
MTLArgumentInternal. On macOS 11 and 12 only an argument of its kind's
class answers that kind's getters: a buffer's bufferDataType, a texture's
textureType and threadgroup memory's data size fail their assertion on any
other object and end the process (measured: 11.7.11 and 12.7.6, each
getter of each class in a guest). The GL renderer asks a stage's vertex
descriptor buffer for its bufferDataType, so on 11.7.11 a GL program's
first draw with a vertex descriptor ended its process there (measured:
gl_cases, the assertion in its crash report).

Those releases have MTLBufferArgument, MTLTextureArgument and
MTLThreadgroupMemoryArgument, which take the initialisers macOS 13's
buffer, texture and threadgroup binding classes take. Each binding is now
made of its kind's class there, and samplers and the other kinds of
MTLArgumentInternal's own initialiser, through the same code as on 13 and
later, which is unchanged.

The pre-13 test's stand-ins now model 11's classes: the base class counts
each kind getter it is asked, and the test checks that none is asked, that
each argument is of its kind's class and answers its kind's getters (a
vertex descriptor's buffer its bufferDataType among them), and that a
kernel built for macOS 11 has the right class for each buffer.
2026-11-11 06:32:24 -08:00
Anees Iqbal 777271e2be 🐛 Make pipelines' reflection of the classes macOS 11 and 12 have
A pipeline's reflection was made only of macOS 13's binding classes
(MTLBindingInternal and its kind), which macOS 11 and 12 do not have, so
every pipeline made with reflection options answered nil there. The GL
renderer reads a stage's uniforms and textures from its pipeline's
arguments, so on macOS 11.7.11 every WebGL and GL draw that used a uniform
or a texture drew with none bound: 14 of the 36 GL cases failed, and so did
Safari's WebGL uniforms, textures and blending. A reflection that carried
only the variants' plugin return data did not fix them (measured in an
11.7.11 guest).

Where Metal has no binding classes, each binding is now an argument of that
release's MTLArgumentInternal, of the binding's name, type, access, index,
use and array length, and of the same type object a binding gets, which its
getters answer from. Built-ins and an argument buffer's constants are of
that release's MTLBuiltInArgument and MTLIndirectConstantArgument. The
reflections keep no binding lists and no print style, which the classes
before macOS 13 do not have. macOS 11's struct type is made with no type
name, as its class takes none. Mesh pipelines and payloads, macOS 13's,
answer none. The classes, initialisers and instance variables are macOS
11.7.11's and 12.7.6's as a guest's class dump lists them. On macOS 13 and
later every class is looked up in the same order and every object is made
with the same calls as before.

For the guest: on macOS 11 and 12, pipelines made with
MTLPipelineOptionArgumentInfo or MTLPipelineOptionBufferTypeInfo now answer
a reflection, where they answered nil.

test_pipeline_reflection_before_macos13 makes the reflection of the oracle
library's pipelines from stand-ins of the classes macOS 11.7.11 and 12.7.6
have. It checks the arguments, their type objects, the built-ins, an
argument buffer's constant, a descriptor's buffers and the plugin return
data. It also checks that a mesh pipeline answers none.
2026-11-11 06:32:24 -08:00
Anees Iqbal bfeb1dbcba 🐛 Wait for an IOSurface view being made before naming its buffer
shadowFor entered a new IOSurface view in the process's registry before it made
the view's buffer. A second thread that asked for a texture over the same
surface in that window found the view, took its buffer while it was still nil,
and sent TEXTURE_FROM_IOSURFACE naming buffer 0. The host answered BadReference,
and that texture was never made. ImageIO's tile threads decoding a HEIC in
Preview hit it in 3 of 6 boots on the 780M, macOS 13.7.8 to 15.8.2.

The thread that makes a view now holds the view's `making` lock from its entry
in the registry until its buffer, and a copy's first upload, are made. A thread
that finds the view waits on that lock, then takes the view only if its buffer
was made; otherwise it answers nil, as the maker does.

What the host sees: the second texture names the view's buffer, the same one
the first texture names, where it named buffer 0 before.
test_iosurface_texture_waits_for_a_view_being_made holds it; it fails on the
old code. Both kext sets are built again from the new source.

Checked: make -C guest test, both sets and prebuilt-check on the M3 Max; walks
on the 780M with this set, 14.8.9 and 15.8.2, three HEIC steps each: no
BadReference, no fatal, error or warning lines.
2026-11-11 03:53:01 -08:00
Anees Iqbal 46b930fbfe 🐛 Make arm64 guests' textures of the two-plane XR10 formats
14.6.1's WindowServer ended in SkyLight's MetalBacking::AbortWithTextureInfo:
on a display that answers extended range it flattens a window's layers into
a Private texture of RGB10A8_2P_XR10 (550), usage ShaderRead and
RenderTarget, and the device's creators answered nil for every two-plane
format under an Apple GPU's rules. The M3 Max was measured to answer nil
for a two-plane Y'CbCr format (500); Metal there makes a texture of either
XR10 format (550, 551) of its own memory, as the Vulkan platform's tests
that compare theirs with Metal's make them, and the runtime makes them, in
heaps too.

The device's and a heap's creators now make them on an arm64 guest's
device; a buffer's creator still answers nil, as the runtime makes no
texture of one over a buffer. An x86-64 build is unchanged: its rules end
the process at both formats in the validation.
2026-11-09 12:23:11 -08:00
Anees Iqbal 2a7078b2bd 🐛 Take an Apple GPU's texture rules on an arm64 guest's device
14.6.1's WindowServer ended at the bundle's descriptor validation: it makes a
texture of a two-plane format (550), which the x86 Macs' rules call lacking,
and the bundle chose those rules because the device answers no Apple family,
as the host lets it answer none. An arm64 Mac's GPU is always Apple's, so in
an arm64 guest the device now takes an Apple GPU's rules (the M3 Max's),
whose creators answer nil for a two-plane format. The choice is the device's
own (RgfxAppleRulesDevice), built for arm64 alone; an x86-64 build is the
same code as before. rgfxAppleGPU is the bundle's one place that chooses a
behaviour by Apple-family answers; RgfxCaps's Mac2 asks are feature answers.
2026-11-09 11:02:31 -08:00
Anees Iqbal 142349f225 ✅ Declare the Apple-family test device at global scope
b672007c3 declared RgfxAppleFamilyDevice inside the tests' anonymous
namespace, where Objective-C declarations may not appear, so shell_tests
did not build (job m3-max-11841).
2026-11-09 09:41:26 -08:00
Anees Iqbal a544e8dad5 🐛 Validate textures by an Apple GPU's rules on an Apple GPU
On 27.0.1 WindowServer died 17.7 s in, in our descriptor validation, at
CoreAnimation's create_surface_with_properties. The bundle checked every
texture descriptor by the x86 Macs' rules, while in an arm64 guest the
device answers an Apple family, and CoreAnimation asks such a device for
what an Apple GPU makes: an XR10 format where it answers
supportsExtendedXR10Formats (read from 27.0.1's QuartzCore), and
Memoryless textures. The x86 Macs lack both.

oracle_texdesc on the M3 Max under 27.0.1, at the device's, a heap's and a
buffer's creators, measured the Apple GPU's rules: the same words and
order, but it has every format the x86 Macs lack except Invalid, D24S8
and X24S8; answers nil for two-plane formats and Unspecialized; makes
multisample BGR5A1 and RGB9E5, depth and multisample textures in Shared
and Managed storage, and Memoryless ones, in a Private heap too; makes 2
and 4 samples but not 8; and over a buffer answers nil for every
compressed format. Where the device answers Apple7 (rgfxAppleGPU) the
bundle now takes those rules; elsewhere they stay the x86 Macs'. The
test runs every descriptor case under an Apple GPU against the M3's
answers, and the doc records them (Q24).

A validation death also writes Metal's words and the descriptor to the
unified log: WindowServer's stderr is kept nowhere, so the boot showed
only that the validation ended it.
2026-11-09 09:41:26 -08:00