Commit Graph
301 Commits
Author SHA1 Message Date
Anees Iqbal 70088b78b1 🐛 Keep the bundle's log lines off the process's stderr
Every line of the Metal bundle's (rgfxLogLine) went to the unified log and also
to the process's stderr wherever NSLog writes there. So a command-line program
in a guest that joins its stderr to its output printed the bundle's lines among
its own: a user's script showed "RGFX: feature profile 10002: ..." in its
output. A Mac's Metal writes nothing there of its own.

rgfxLogLine now logs to the unified log alone. The words of a death, which the
process ends at next and which Metal writes on stderr at the same calls, go
through rgfxLogDeathLine, which still writes them there; the death checks read
them.

shell_tests runs itself again with --log-line, its stderr a pipe, and checks
that a logged line writes nothing there. It fails with the old rgfxLogLine.

What changes for the guest: a program's stderr carries none of the bundle's
lines except a death's words; the unified log keeps them all, as before.
2026-11-27 13:07:40 -08:00
Anees Iqbal 2591c9022e 🐎 Keep the Shared pool's empty slabs as the region's are
A class's slab of the Shared pool went back the moment its last buffer did
(RgfxPoolSlabSource::keepsFreed() answered false), and a large buffer's own slab
skipped the cache. A process that makes one buffer and frees it again and again
in an otherwise empty class then took a pool block for each buffer: a take the
thread waits for, a HEAP_OVER_POOL, the host zeroing the block, then the heap's
destroy and the block's give. Each new slab doubles its class's next one, so
after seven rounds every block was 16 MiB, for a buffer of one page. A user's
guest logged one process making and giving back about 17 such slabs a second,
none of them taken from again. The serialiser test of that pattern at
805c93a65 counted 100 small slabs (1539968 KiB) and 100 large slabs for 100
rounds of each, and 200 pool takes.

keepsFreed() is gone, so every source's slabs follow the one form. Each class
keeps two empty slabs, and large buffers' own slabs are cached, each for
kCacheIdleMs (2 s) at most. The pool source now takes a capacity, as the pages
source does, and the device passes the guest's RAM: the kext tells the bundle
nothing of the pool's length, so the pool's cache holds a sixteenth of the
guest's RAM at most. A refused take still lets the process's own kept and
cached slabs go first.

What changes for the guest: a buffer of the pool may lie in a slab an earlier
buffer emptied, at that heap's GPU address and offset, rather than in a new
block's heap, and the host sees fewer POOL_TAKE, HEAP_OVER_POOL,
OBJECT_DESTROY and POOL_GIVE messages. A kept block is its process's alone for
up to 2 s after its last buffer goes. A new buffer still reads zeros: the test
writes 0xa5 over each buffer before its free and reads zeros in the next.
test_pool_slab_churn_is_bounded holds the bound: one small slab, one large one
and two takes for those rounds. The pool tests that held the old let-go now
let kept slabs go through the idle clock or reclaim(). The guest sets are
rebuilt with the next commit, which changes the bundle too.
2026-11-26 21:03:21 -08:00
Anees Iqbal 805c93a65c 🎨 Count each in-place refusal of a surface by its reason
The kext answers an ask in place it does not carry out with one status for
three reasons: the device uses no surface in place (no SURFACE_PAGES), an ask
with no device cache meets a device that caches every surface (the kext's
`uncacheable`), and the device refused the surface's pages. The bundle counted
all three as "unsupported", and the first copy's line said "the device uses no
surface in place, or refused its pages", which named neither the uncacheable
refusal nor told the other two apart.

The bundle now tells them apart by the ask and by the device's SURFACE_PAGES
and SURFACE_CACHE_EVERY, and counts each under its own name. The guest's
surface copies line gains two counts, "asked uncached where every surface is
cached" and "refused by the device", and "unsupported" now counts only a
device that uses no surface in place. No Metal answer changes. The in-place
fallback test covers each reason.

Both guest sets are rebuilt with it: RgfxGate in guest/prebuilt and
guest/prebuilt-arm64e; Graft and ReimsGraphics keep their bytes.
2026-11-26 19:00:38 -08:00
Anees Iqbal e286ef37e3 🐛 Take no lock on an object the app can reach
An app may hold @synchronized on an object Metal hands it while it waits for
Metal's work on that object. A 2D game on a common engine holds its command
buffer's lock across the buffer's commit and waitUntilCompleted. The bundle
took @synchronized(self) in the command buffer, the queue and the function,
and @synchronized(device) for the CPU copies' queue, and the buffer's
completion took the buffer's lock (rgfxLetResidencySetsGo, on both devices).
So the completion waited for the app and the app for the completion: the
buffer never completed and the app never showed a window.

What changes for the guest: an app holding a command buffer's, a queue's, a
function's or the device's @synchronized no longer stalls the bundle's work
on that object on another thread, as on Metal. oracle_locks, measured on the
M3 Max under macOS 27.0.1, finishes each such step on Metal.

Each object keeps a std::mutex of its own: the command buffer's for its
residency sets and user dictionary, the queue's for its pools and residency
sets, the function's for its stand-in hash, and a static one for the device's
copy queue. None is recursive, as nothing done under one takes it again. No
block, handler, release or raise runs under one: the sets a removal lets go
are kept past the lock, and a nil set raises the counted set's exception from
a counted set of its own after the lock. The queue's barrier slots take no
lock: the fences never change, and the count is atomic. rgfxCopyQueue is
declared in RgfxTexture.h for the tests.

The tests (tests/queue_tests.mm, AN APP'S LOCKS) hold each lock and wait,
each case in a child that must end within 10 s; all five timed out on the
code before. The guest sets are rebuilt from these sources.
2026-11-26 17:36:11 -08:00
Anees Iqbal 92e7487237 🐛 Answer Foundation's full error for a refused dynamic library write
A dynamic library's serializeToURL: wrote through Foundation's atomic write
before 70d6be8d84, so a write the system refused answered Foundation's own
error. The bundle's own write answered only its domain, code, path and POSIX
cause; Foundation's has more, which this Mac's Foundation shows (measured on
macOS 27.0.1, x86_64 and arm64). Every refusal names the file's URL as well.
A refusal of the file made in the folder (a folder the process may not write
in, a read-only volume) also names the folder (NSUserStringVariant
"Folder") and carries a debug description. A directory at the path answers
NSFileNoSuchFileError over ENOENT, not a write error over EISDIR.

RgfxWriteFileWhole now says whether it got as far as making its file, and
the dynamic library's error takes each of these shapes, with a debug
description in our own words. What changes for the guest: those errors'
user info and, for a directory at the path, their code, as Foundation
answered them before. The test pins three refusals against Foundation: the
read-only folder, a name too long and a directory at the path. It compares
their domain, code, keys, path, URL, folder variant, description and cause.
2026-11-22 22:39:31 -08:00
Anees Iqbal 1034ed6de9 🐛 Write the bundle's files with calls every app sandbox takes
On macOS 11, every Safari page that used WebGL lost its WebContent
process. WebKit's WebContent profile there kills the process (SIGKILL) at
any system call its list leaves out, and the GL store wrote its entries
with Foundation's atomic write, which makes its file with
open_dprotected_np, a call that list leaves out. 12's list kills the same
way and leaves out setattrlist, which the store's touch could make
through Foundation.

The bundle now writes every file of its own through RgfxFiles: plain
POSIX calls (open, read, write, close, stat, rename, unlink, mkdir,
opendir) whose system calls every WebContent profile read takes, from
11.7.11, 12.7.6, 13.7.8, 14.8.9, 15.8.2 and 26.7.2 on x86-64 to 27.0.1 on
arm64. The GL store reads, writes, lists, touches and removes its entries
through it, and a binary archive's and a dynamic library's
serializeToURL: check their directory and write through it. A touch
writes the entry's first byte over itself, since no call that sets a
file's times is on every list.

What changes for the guest: a WebGL page in Safari on 11 is no longer
killed when the GL store writes. A dynamic library's write the system
refuses answers the error Foundation's atomic write answers for it, which
a new test pins against this Mac's Foundation; every other answer of the
two serializers is as before.

The bundle now imports open(2), so bundle_files_check.sh allows open
itself and bans instead the file calls a WebContent list leaves out, and
Foundation's file-writing selectors. tests/files_tests.mm checks the file
calls, and runs them and the store in a child under a sandbox that kills
at every file call some list leaves out; its controls (utimes,
setattrlist, open_dprotected_np) are killed.
2026-11-22 22:39:31 -08:00
Anees Iqbal 987f15e6c4 🐛 Answer nil for a placement that runs past its heap's size
A Placement heap's newBufferWithLength:options:offset: and
newTextureWithDescriptor:offset: placed a resource anywhere it was asked, a
Private heap's with no bound at all, and the host then refused the placement
past the heap, so the app held a resource its command buffers could not use.
Both x86 Macs answer nil under macOS 26.7.1, their processes going on
(oracle_errors bounds, in a 1 MiB Private heap: a buffer at its last 64 KiB
made, one of 128 KiB there and one of 1 MiB + 64 KiB at 0 nil; a texture at the
last offset of its alignment that holds it made, one alignment on nil).

For the guest: such a placement is nil, posting nothing, where it was an
object the host refused. A texture's bytes are the host's answer to its size,
which the serialiser keeps per descriptor; with no answer the host's refusal
stands as before. The nil is logged with the device's note of a nil, now in
RgfxLog so the heap logs it too. No test held the old answer; a new one holds
the bound.
2026-11-22 01:29:34 -08:00
Anees Iqbal c31ac47ad0 🐛 Answer nil for a no-copy buffer past maxBufferLength
newBufferWithBytesNoCopy: made a buffer of any length, and the host then
refused its BUFFER_OVER_PAGES past the device's maxBufferLength, so the app
held a buffer whose uses in its command buffers the host dropped. Metal's
answer, measured with oracle_errors bounds under macOS 26.7.1: the Intel 630
makes one at its maxBufferLength and answers nil one byte and one page past
it, its process going on; the AMD 5300M makes both. Nil is inside what the two
answer and is the one that keeps the app's view true, so the bundle now
answers nil past the device's maxBufferLength, posting nothing, with its
noteNil line, wherever the bytes lie. The tiled no-copy texture goes through
the same factory and follows.

For the guest: a no-copy buffer or tiled texture past maxBufferLength is nil
where it was an object the host refused. The factory takes the limit
(maxLength, 0 for none), so the tests that made no-copy buffers pass 0 and
hold what they held; a new test holds the bound. The host's comments that said
the bundle made such buffers at any length now say what it does.
2026-11-22 01:29:34 -08:00
Anees Iqbal 9c211e49a3 ✅ Run the held-create race tests on fair-share mutexes
The two race tests of 21e637db25 passed against the two-hold code they guard:
on libpthread's default mutex policy the committing thread took the held
messages' mutex again before the thread waiting on it, so the window between
the holds was never met. Each now runs in a child of its binary on the
fair-share policy (PTHREAD_MUTEX_DEFAULT_POLICY=1, rgfxRunFairShare), where an
unlocked mutex goes to its waiter, and checks that the child has it. The
protocol test's kext now refuses a held destroy, as a post that took every
held message leaves the old check a lock-free answer that waits for nothing.

Against the sources before the fix both fail, the serializer's at
postHeldCreates and the protocol's at the buffer missing from its ring; on
the fixed tree `make -C guest test` passes. The trap is in docs/lessons.md.
The bundle's tests are not among the sets' sources, so the sets stay as built.
2026-11-21 02:31:50 -08:00
Anees Iqbal a21fb9da70 🐛 Give no IOSurface view whose planes are not its surface's
A texture over an IOSurface plane is sent at the plane's place in its view,
shadow->planes[plane], and the plane was checked against the surface's plane
count, not against the view's own planes. A view that laid out fewer planes
than its surface has sent plane 1 out of bounds. On the UHD 630 under Windows
(winpics d1-c1, m3-max-59780/59893), the video decoder's chroma texture over a
4K '420v' output went at offset 0, rows 0 bytes apart, with facts of two
planes and plane 1 at offset 0, 0 bytes a row. The host refused the create,
the picture's decode that names it was dropped, and every picture after it up
to the next IDR was wrong (207 of 240 matched).

shadowFor now gives a view only where it lays out the surface's planes as
they are now (describes). One that does not gives way to a new view in the
registry, and lives on for the textures that hold it. The texture's make
checks its plane against the view, once more after a view made again, and
makes none where the view still does not lay out the surface. The first few
such views of a process are logged with the surface as the view was made of
it, its own surface now and the surface asked, since how such a view arises is
not yet known. Every other index of a view's planes is a texture's own plane,
which its make bounds, or rgfxIOSurfaceRowsHeld's, which checks it.
2026-11-20 17:13:30 -08:00
Anees Iqbal 3994dc6510 ✅ Name the refill block's last generation in the set's checks
The residency set's checks name the generation the refill test leaves in the
block's header, which is 18 now that the refill test plays a lock for each of
its cases.
2026-11-20 16:26:10 -08:00
Anees Iqbal de54e528c9 ✅ Test a GPU write under a held lock, not after a settle
The bundle's refill test expected a settled record to ask the kext again
after a GPU write, which the shared rule does not do and need not: a settled
cache holds the generation as the CPU left it, and the GPU's writes are the
cache's own. The write that asks is one under a lock still held, where the
record is owed; the test now plays that, and the rule's header says so.
2026-11-20 16:26:10 -08:00
Anees Iqbal 7a98159ca2 🐛 Owe a refill from each read-write lock, whatever filled the cache
A cached surface's device cache could hold the pages as they were mid-write
with no refill ever asked: the bundle recorded the surface's unlock seed only
as a commit first named a generation, so a fill the bundle never saw (a
present's, the first fill a block owes, a block named again) made while the
CPU held its read-write lock stood until the next lock. Such a present also
left the record to be made after the unlock, which then never asked.

The kext now writes each generation's refill record into the block's header
itself, as it caches the block and at each read-write lock, before the
generation, with the surface's unlock seed then (RgfxSurfaceRefill.hpp,
which the bundle shares). The first commit, in any process, once the unlock
seed has moved past the record's carries RGFX_SURFACE_USE_REFILL and settles
it; a commit while the lock is held or being taken asks nothing and leaves it
owed. For the host: a use after each read-write lock's unlock now carries the
flag, including the first use of that generation; the host ignores it where
the cache holds an older generation, as before, so a generation never filled
mid-write costs no extra fill. The record is one 64-bit word written by
compare-and-swap, so a holder never writes over a newer generation's record.
2026-11-20 16:26:09 -08:00
Anees Iqbal 318864dca5 🆕 Read once the file pages no guest process can ever write
Read-only memory under a no-copy buffer lies over a copy on rt wherever the
GPU cannot import it as it is, and every commit that uses the copy compared
all of its pages with their base. Much of that memory is a file's pages on
the guest's read-only system volume, which nothing can change while the
buffer lives, so the compare buys nothing there.

What the guest sees: the device offers feature bit 31, UNCHANGING_PAGES, with
READ_ONLY_PAGES, and the kext takes it (kext feature 1 << 19). At a no-copy
buffer's make over read-only memory, the bundle asks the guest's kernel once
whether the range is one file-backed region whose maximum protection has no
write (a shared mapping, or a private one whose maximum was lowered), whose
every page is the file's own, on a volume mounted read-only (proc_pidinfo's
fsid against getfsstat; no path is opened). Such a block is the app's own
memory, as before, marked RGFX_SURFACE_PAGES_UNCHANGING (and
_COPY_ON_WRITE); the kext's wire of a private mapping makes the process's
copy, as a Mac's does. Any other read-only block carries why not in its
flags' bits 8 to 11, which the host only counts.

What the host does: an unchanging block's copy is filled once, as its view is
made, never compared at a commit, and written again whole at the completions
of the command buffers that can write it, which drops the GPU's writes as
before. The views' summary counts the other read-only blocks by why, and
each texture over one (read-only-pages-textures-why-N, with one line per
format, size and why).

A private mapping whose maximum protection still has write is not provably
unchanging, since its process could raise its protection and write its copy:
it stays a plain read-only block, why "writable max protection".
2026-11-20 10:45:23 -08:00
Anees Iqbal 0f8bba3c2c 🆕 Make no-copy buffers at the host's address where blocks answer first
Where the device took IMPORT_ADDRESSES_LATER, a pages block is answered
before its view is imported, with no GPU address, so the bundle cannot place
the buffers over it at the view's address as it made them. It now lets the
host place them:
- a buffer over such a block goes in BUFFER_OVER_PAGES at gpu_address 0, which
  the host places at the view's address plus the buffer's offset; no address
  of the process's is picked for it;
- a Shared one asks its address of the host (PAGES_BUFFER_ADDRESS) at its
  first gpuAddress read, the argument encoder's and a texture over it
  included, and keeps the answer; a read with no answer is 0 and asks again;
- a Managed one, where the host makes Managed buffers at their copy's address
  (MANAGED_AT_COPY), asks its copy's address as it is made.

What the guest sees: on metal2vulkan-rt's platform, newBufferWithBytesNoCopy:
returns without waiting for the block's import, and the first read of the
buffer's gpuAddress waits for it instead. The addresses are the host's, as
they were where the block's answer carried one; on the default platform
nothing changes.
2026-11-20 07:15:38 -08:00
Anees Iqbal f13f992e49 🆕 Let the guest place a Managed buffer at its CPU copy's address
On a GPU that shares the CPU's memory a Managed buffer is its bytes, so its
GPU address is its CPU copy's. The guest's bundle picked it an address of its
own, in a Private block, which metal2vulkan-rt cannot keep for a buffer that
lies over the copy's bytes: rt made the buffer at the copy's address, while
the guest's pointers held the pick, and each pick held a Private take.

Feature bit 63, MANAGED_AT_COPY, names the other form: where the guest took
it, a MANAGED_BUFFER_CREATE's gpu_address is its CPU copy's, the guest takes
no address for the buffer, and the address goes back with the copy. Both
kexts carry the bit, the bundle's serializer, slabs and no-copy buffers post
the copy's address, and the device tells its host the features the driver
took as it becomes ready (Host::driver_ready), before any message, so the
host's decoder can read the creates in that form.

No host offers the bit in this commit, so nothing changes for a guest. The
wire header changes, so the ROM's record and the guest's prebuilt sets are
rebuilt in their own commit.
2026-11-19 15:43:47 -08:00
Anees Iqbal e1fa3d5ae3 🆕 Place planes in place at 16 bytes where every surface is cached
Where the device caches every surface in place (SURFACE_CACHE_EVERY), no
host texture lies over a surface's pages: each is a view of an image the host
fills from the plane's place and pitch in the cache and writes back there, by
copies that address them in texels of the view's format. The host's linear
texture alignment, 256 bytes, then turned surfaces into copies for nothing:
15 of the 259 copy views of an rt boot, an x420 3840x2160 video output with
plane 0 at 568256 bytes and rows of 8000 among them, and rt refuses every
texture over a copy.

Under the feature a plane's offset and rows need only be multiples of 16
bytes, the largest texel of a format of texels, so every view's fill and
write-back address the plane whatever format of texels it takes. Without
the feature nothing changes.

For the guest: such a surface's view is in place, cached, where it was a
copy counted for alignment.
2026-11-19 07:47:41 -08:00
Anees Iqbal 4d14de048b 🆕 Count a surface's copy view by why where every surface is cached
Where the device caches every surface the kext gives in place, a view that is
a copy is the fallback. It is still made, never nil, and counted by why:
alignment, unsupported, refused by the kext, or no room in the kext (now
apart from refused). The first of each reason goes out at the default level
with the surface's format and shape, and so does the minute's copies line
where a copy was made in it. A walk's guest log, which keeps the default
level, then shows what still takes copy blocks on rt.
2026-11-19 07:47:41 -08:00
Anees Iqbal 185374bcde ✅ Read the pool heap's address through the heap internals
RgfxHeap declares no gpuAddress property: the address is the private
RgfxMetalHeapInternals method, so the Shared-heap-of-the-pool test asks it there,
as the guest's frameworks do.
2026-11-19 04:06:03 -08:00
Anees Iqbal c8f85c1726 🔥 Make a Shared heap a block of the Shared pool where there is one
An Apple GPU's device (an arm64 guest's) makes a Shared heap, which until now
was a block of the device region, HEAP_OVER_HOST_MEMORY. Since the arm64
guest takes the Shared pool too, that heap was the last of the bundle's
buffers and heaps the region held where the pool is on.

What the guest sees: where the device has the pool (the slabs' one source),
newHeapWithDescriptor: of Shared storage takes a block of the pool of the
heap's size rounded up to 64 KiB and makes it one HEAP_OVER_POOL of the heap's
size, type and options, at the block's GPU address where the host gives one
(POOL_ADDRESSES), else at the process's pick. The heap's gpuAddress is that
address, its buffers lie at their offsets from it, and its bytes are the
block's, which the host zeroed. Its drop gives the block back, and no address
where the host gave it. A heap the pool has no block for, past the 4 GiB
longest block, or with no address left, is nil, as Metal's heap is where its
memory runs out; nothing falls back to the region. Where the pool is off, a
Shared heap is a region block as before. A new shell test makes one at the
host's address and its buffer, and the two nils.
2026-11-19 04:03:53 -08:00
Anees Iqbal 8b07780932 🔥 Make no upload chunk of the region where the slabs are the pool's
A queue's upload chunk, where set*Bytes: puts its bytes, is a buffer of the
device's slabs, and where the slabs had none for it, a block of the device
region of its own. Where the slabs are the Shared pool's alone (the commit
before), that block was the one region use left for an upload chunk.

What the guest sees: where the pool is on, a chunk the pool has no block for
is none, with no BUFFER_OVER_HOST_MEMORY over a region block, and the command
buffer whose bytes found no room completes with MTLCommandBufferErrorOutOfMemory,
as it did where the region was full, and as Metal's does where its memory runs
out. RgfxSlabs::inRegion says which the slabs are. A new shell test takes a
chunk of a pool that refuses and then gives a block. Where the pool is off,
chunks fall back to the region as before.
2026-11-19 03:59:31 -08:00
Anees Iqbal 66370e18be 🆕 Place no-copy buffers at the address the host gives their block
On metal2vulkan-rt a no-copy buffer's GPU address is the device address of the
host's import of its pages, which only the host knows, so a guest pick cannot
match it. Where the kext and the device both took IMPORT_ADDRESSES, the bundle
asks PagesBlock for its third output, the GPU address the host gave the block's
view, and makes each BUFFER_OVER_PAGES over the block there plus the pointer's
offset in its page, with no pick of its own and none given back at its destroy.

What the guest sees changes: a no-copy Shared buffer over writable memory the
kext wires answers a gpuAddress in [2^43, 2^44) on the Vulkan platform (at its
pages' import on rt) instead of a pick in the context's range, and two no-copy
buffers over the same bytes, which join one block, answer the same gpuAddress.
A Managed no-copy buffer's own address stays its GPU copy's pick; only its CPU
copy, the Shared buffer over the pages, moves. Read-only memory, copied memory
and blocks given no address keep their picks, and a guest without the bit sees
nothing change.

design.md gains the "Import addresses" paragraph, PagesBlock's third output and
the kext's bit 18.
2026-11-19 02:54:55 -08:00
Anees Iqbal add15cd8f9 🆕 Name the IOSurfaces a residency set holds at a buffer's commit
On the arm64 device, a command buffer named in SURFACE_USE only the cached
IOSurfaces it encoded a use of. A surface the GPU reached only through a
residency set the buffer used, or its queue held, was never named: its device
cache kept the generation of its last named use, and a copy-mode surface's
copy was not synced, so the GPU read what it held before the CPU's writes.

What the guest observes changes: at its commit, a buffer names each texture
over an IOSurface, or view of one, committed to a residency set it uses or its
queue holds, as a resource it reads. A cached surface's cache is filled first
where the CPU wrote it since, and a copy syncs. The set keeps its committed
IOSurface members as its own commit changes them, so a buffer's commit reads
them without walking the set. The x86 device makes no residency sets, and is
unchanged.
2026-11-19 01:11:57 -08:00
Anees Iqbal 4fd927b1f1 🆕 Fill a cached IOSurface's cache again after the CPU's unlock
A cached IOSurface's device cache was filled at the read-write lock that
moves the surface's generation, not at its unlock. A command buffer committed
while a CPU held the lock filled the cache with the pages mid-write, and the
CPU's writes after it reached the GPU only at the surface's next lock.

What the guest observes changes: the first command buffer committed after the
unlock that uses the surface now reads the CPU's writes made under the lock.
The bundle tracks a cached surface's unlock seed from a commit that found it
locked for writing, as copy mode does, and that buffer's SURFACE_USE carries
the new RGFX_SURFACE_USE_REFILL flag. The host fills the cache again at the
generation it holds, unless a command buffer that may write it was committed
since its last copy into the pages, whose write a fill would lose.

The flag is under the new feature bit RGFX_FEATURE_SURFACE_REFILL (bit 58),
which every host offers and both kexts take; the bundle sets it only where
its kext took the bit and answers the surface seeds. The bundle counts the
surfaces named mid-write and the refills, and the host its refills and the
refills it kept from, in their summaries.
2026-11-19 01:11:57 -08:00
Anees Iqbal 8447199fee 🆕 Note a no-copy buffer's identity the first time it escapes
The host reads a no-copy buffer's bytes in place. The guest's Metal can hand
that buffer's identity to the app, or write it where the GPU reads, with no
message naming the buffer, and from then on the GPU may reach the buffer
through memory alone. The host had no way to know which buffers that happened
to. This commit adds a note for it, so the host can tell them apart.

The note is RGFX_CMD_BUFFER_ESCAPED (0x23b), RgfxBufferEscaped of 32 bytes:
the buffer's object id and the act, one of GPU_ADDRESS, ARGUMENT_ENCODER,
RESOURCE_ID and RESIDENCY_SET. The device offers it as
RGFX_FEATURE_BUFFER_ESCAPED (bit 56), and both kexts carry it. The submit gate
takes it in a batch, like a Managed range's write: unwaited, a fixed size,
naming no block and making no object.

The bundle marks each covered buffer as it is made (_rgfxEscape, set by
rgfxOwesEscapeNote) where the host took the feature. The first of these acts
in the buffer's life posts the note, before the act returns:
- a read of the buffer's gpuAddress;
- an argument encoder's setBuffer(s) of it, or setTexture(s) of a texture or
  view over it;
- a read of such a texture's or view's gpuResourceID;
- the buffer, or such a texture, joining a residency set.
Every later act is one relaxed load.

Wire order holds the note ahead of any command buffer that could use the
identity. The note goes on ring 0, posted or held in the serialiser to go
before the next commit's messages, and the device carries out a command buffer
only after every ring-0 message its process posted before it. Across threads,
the act's slow path posts the note under the buffer's lock and then clears the
mark with a release store. Every commit takes an acquire fence before it posts,
so a commit after an act that found the mark clear posts after the note.

The covered buffers are the app's no-copy buffers over its own pages
(BUFFER_OVER_PAGES, writable or read-only, bit 24) and over bytes already in
a block of the process (BUFFER_OVER_HOST_MEMORY). Managed buffers, heaps over
pages, IOSurface shadows and buffers placed in a slab's heap
(BUFFER_AT_OFFSET) are not covered.

A slab buffer made with an address of its own is covered too: a Shared buffer
past 2 MiB over a slab of the process's own pages, a device buffer, or a
no-copy buffer's shadow (RgfxSlabSource::Made's ownsAddress). It reaches the
host as the same BUFFER_OVER_PAGES or BUFFER_OVER_HOST_MEMORY message as an
app's no-copy buffer, and the host takes every such message alike. Leaving
slab buffers out would leave the host unable to read the mark as "this
buffer's identity never left".

The host marks the buffer's entry escaped, once for its life, and a later
note changes nothing. A note for an object that is not such a buffer is a bad
reference. A note for an object whose create the host refused is dropped, as
any naming of one is. Escapes are counted in the degradation counts line and
in the recorder's stats (`counted <code> <n>` lines), with no new stream
records:
- buffer-escaped-gpu-address, -argument-encoder, -resource-id and
  -residency-set, by the act that noted the escape;
- buffer-escaped-read-only-pages, the escaped buffers over a copy of their
  pages;
- no-copy-buffers, every no-copy buffer made, of which the escapes are a
  share.
Each act's first escape is also logged at info.

This changes nothing the guest observes. No one waits for the note, it has no
reply, and the mark changes no answer, object, address or command. Both
prebuilt sets and the option ROM's record are rebuilt from these sources. The
ROM's bytes do not change: its record changes only by the wire header's hash.
2026-11-18 19:52:34 -08:00
Anees Iqbal 191daab32a 🐛 Send a render pipeline's tessellation state and call stack depths
A guest's render pipeline drew its patches with Metal's default tessellation
state, whatever its descriptor set: power-of-two partitions, a maximum factor
of 16, no factor scale, constant factors per patch and clockwise output. The
bundle never sent the seven tessellation fields, so the device never saw them.
For the same reason the device never saw maxVertexCallStackDepth or
maxFragmentCallStackDepth, and created every pipeline with a depth of 1.

The bundle now reads each of these properties and sends it. Each tessellation
field travels as Metal's raw value, and tessellationFactorScaleEnabled as a new
flag, RGFX_RENDER_PIPELINE_TESSELLATION_FACTOR_SCALE (bit 8). The depths are
read only where the descriptor answers their selectors (macOS 12 and later);
older guests send 1.

The decoder passes every value through FullRenderPipelineDesc to the runtime's
RenderPipelineDescriptor. A state equal to Metal's defaults becomes the
runtime's `None`, so a pipeline that sets nothing is created exactly as
before. A raw value the runtime has no enumerator for dies at the send, as
every other enumerated field does. The recorder's tag-13 map carries the
values as three keys after privateState: `tessellation`,
`maxVertexCallStackDepth` and `maxFragmentCallStackDepth`.

Guests now see patches tessellated with the partition mode, maximum factor,
factor scale, step function, winding and control point index type that their
pipeline sets. They also see pipelines created with the call stack depths
they asked for.

The tessellation fields and the call stack depths share this commit because
they share one wire record. RgfxRenderPipelineCreate grows from 464 to 496
bytes, with eight u32s appended at offset 464, and both prebuilt sets and the
option ROM's record are rebuilt from these sources. The ROM's bytes do not
change.
2026-11-18 18:12:19 -08:00
Anees Iqbal 38640a5e54 🐛 Answer gpuCoreCount on an x86-64 guest as the x86 Macs: not at all
Neither x86 Mac's Metal device responds to gpuCoreCount: the AMD Radeon
Pro 5300M's and the Intel UHD 630's answer respondsToSelector: NO under
macOS 26.7.1 (oracle_caps, m3-max-37201 and 37202). The bundle has
answered it on every guest since f692b4de0, from the M3 Max's answer,
the one device it was measured on then.

What the guest now sees: an x86-64 guest's device does not respond to
gpuCoreCount, and a call raises an unrecognized selector, as on the
x86 Macs, where it answered the host's count (a GPU's CUs or SMs, 0 on
Intel). An arm64 guest's device, an Apple GPU's, answers the host's
count as before.
2026-11-16 15:57:15 -08:00
Anees Iqbal 74869d936c 🐛 Answer the device's compile of a visible function as the x86 Macs
macOS 12 and 13 guests' iconservicesagent and com.apple.dock.extra send
the device's private compileVisibleFunction:withDescriptor:error: at
start-up, from Metal's own link of Core Image's kernels, and the bundle
answered it unsupported while supportsFunctionPointers answers YES (17
boots of 11-15/16). Both x86 Macs answer each of its three forms with no
error for any function and descriptor, keep the function in the archive
of the archive form, and call the handler form's one-argument handler
with nil on the caller's thread (oracle_binfn, macOS 26.7.1, Q47).

What the guest now sees, where the host makes function pointers:
- the three compile forms answer as the Macs do and compile nothing,
  as the host compiles a binary function where a pipeline links it;
  the archive form keeps the function as addFunctionWithDescriptor:
  keeps it, and the handler runs before the call returns;
- newComputePipelineStateWithAdditionalBinaryFunctions:error: answers
  the pipeline itself, as the AMD 5300M's does (the Intel 630 makes
  another; the Macs diverge), where it answered nil and an error;
- the device's functionHandleWithFunction: and its resource-index form
  raise an unrecognized selector, as both Macs' devices do, where they
  answered nil.
Where the host makes none, each answers the unsupported error as before.
2026-11-16 12:56:26 -08:00
Anees Iqbal 5afdd60765 🐛 Answer stage input attributes from Metal's own function
A function specialised by constant values answered as active an attribute that
Metal's compiler leaves inactive once it folds the values: the bundle read the
AIR itself, and its reading keeps reads that are dead only after folding.
RealityKit's vsRealityPbr, under its usdz preview's constants, answered color
active where the AMD 5300M answers it inactive; unspecialised, it answered the
15 attributes its metadata declares where Metal answers none.

Where a function's library has Metal's own library (the one Metal compiled,
linked or stitched, or one Metal makes over the bytes of a library of a file,
of data or of a bundle), its attributes are now those of Metal's own function
of the same name and constant values. The metadata and the AIR's
specialisation remain where there is no such library. oracle_fnreflect gains
v_deadfold, whose attributes' reads are dead only after folding, and the
shadow test checks that every function asks Metal's own.
2026-11-16 11:41:25 -08:00
Anees Iqbal d57948fc8d 🐛 Answer vertex amplification's built-ins as Metal does
RealityKit's usdz Quick Look preview asks the reflection of fullScreen2Vert, a
vertex function of amplification_id, and the bundle answered nil ("a built-in
air.amplification_id was not measured"); the preview stayed black. Measured on
the AMD 5300M under macOS 26.7.1: amplification_id and amplification_count are
built-ins 21 and 22 of uint, in a vertex function's pipeline reflection and its
own, and in a fragment function's own reflection, where its pipeline's lists
them nowhere; a kernel's dispatch_simdgroups_per_threadgroup and
dispatch_quadgroups_per_threadgroup are listed nowhere. The reflection now
answers them so, where it answered nil.
2026-11-16 09:41:07 -08:00
Anees Iqbal 67aa2527c5 🐛 Take stage attributes from Metal's compile where metadata has none
On x86-64 macOS 11.7.11 a function of a library compiled from source
answered nil for vertexAttributes and stageInputAttributes, where Metal
answers its attributes: that release's compiler writes no VATT or VATY tag
into the library's metadata, so the bundle read no declaration. 12.7.6,
13.7.8, 14.8.9, 15.8.2 and 26.7.2 write them (oracle_fnreflect's source
library on each, its attributes equal to the AMD 5300M's). A library Metal
compiled, linked or stitched keeps Metal's own library as its shadow; where
the metadata declares no attributes for a function, they are now those of
Metal's own function of the same name and constant values there (each
attribute's name, index, type, use and patch flags), made Metal's objects
as before. A specialised function's are Metal's own specialised function's,
not the unspecialised declaration specialised through the AIR: on 11.7.11
Metal's unspecialised function leaves out an attribute under a function
constant, which 26.7.2's answers. Where the metadata declares them, the
shadow is not asked, so the releases that write the tags answer as before.

The shell test has Metal compile two sources, strips their libraries'
VATT and VATY tags, and requires every function and specialisation to
answer Metal's own through the shadow, each specialisation asked of it;
with the tags kept, the shadow is never asked of a function that declares
attributes.
2026-11-16 09:10:30 -08:00
Anees Iqbal 60273f5170 🐛 Answer imageblockSampleLength 0 off an Apple GPU
A render pipeline answered the host platform's imageblockSampleLength, 4 for
one BGRA8 colour attachment, on the x86 guest's device too, where the AMD
5300M and the Intel 630 answer 0 for every pipeline: they have no tile memory.
The x86 guest's device now answers 0, and an Apple GPU's device, the arm64
guest's, keeps the host's answer, the M3 Max's 4.
2026-11-16 09:10:29 -08:00
Anees Iqbal 77129bbea0 🐛 Answer a function's stage input attributes as Metal does
vertexAttributes and stageInputAttributes answered nil, logged unsupported,
where the x86 Macs and the M3 Max answer an attribute object for each stage
input attribute. RealityKit's Quick Look of a usdz asks a vertex function's
attributes, and SceneKit, VFX and ShaderGraph read them to build their
vertex descriptors.

A function made by name now answers the attributes its library's public
metadata declares (the VATT and VATY tags, read beside the CNST table), which
is what Metal answers on all three Macs for every function of six libraries.
A function specialised by constant values answers them as the values
specialise its AIR: an attribute under a false predicate is left out, one only
removed code reads is inactive, a control point's stays active. The objects
are Metal's own (MTLVertexAttributeInternal for a vertex function, the same
for both getters; MTLAttributeInternal for a kernel's stage input), their
_flags bits measured on the 5300M and the M3 Max. Fragment functions answer
nil, as do kernels for vertexAttributes. Where Metal lacks the class or an
instance variable, or a specialisation's AIR is not read, the answer is nil,
logged once.

The AIR test checks every function's stage input nodes against its VATT tag,
and the shell test checks every function of four libraries, and thirteen
specialisations, against Metal's own answers on the Mac.
2026-11-16 09:10:29 -08:00
Anees Iqbal 61084eab14 🆕 Tell the host which bytes of a new Managed buffer read zero
On a GPU without unified memory the runtime makes a Managed buffer's GPU copy
by copying all of its CPU copy over the link as the buffer is made. Most of
those bytes are zeros the guest never wrote: on the RX 7900 XTX, Geekbench 7.1
Metal's making copies carried ~4.5 GB beyond what the guest marked written, up
to ~0.94 s of GPU time (one 131 ms job copied six new buffers' 631 MB, 12 MB
of it written). The guest knows which bytes read zero; the host cannot.

What changes for the guest and the host:
- MANAGED_BUFFER_CREATE takes a tail, RgfxManagedBufferZero at byte 56
  (RGFX_MANAGED_BUFFER_ZERO_OFFSET): its CPU copy reads zero from zero_from to
  the length as the create is posted. The bundle sends it with every create:
  0 for a buffer made with no bytes, whose slab range take() zeroed; the
  length, which says nothing, for one made with bytes or over the app's own
  memory. The kext's SubmitBatch takes the create at its new size, 64 bytes.
- The host passes a zero_from below the length to the platform
  (BufferDesc::zero_from), and the Vulkan platform to the runtime
  (HostMemory::with_zero_from): the GPU copy starts with zeros the GPU writes
  there, rather than with those bytes copied in. A guest write there reaches
  the GPU copy by a didModifyRange:, as on a Mac's discrete GPU, whose GPU
  copy is made at the buffer's making; before, a write made before the host
  took the create reached it too. A GPU that shares the CPU's memory keeps one
  copy, unchanged, and a create without the tail (an older guest's) is copied
  in whole, as before. An older host reads the create and ignores the tail.

Tests: the decoder passes the tail's offset and none without it or at the
length; the platform's zero bytes are the device's on a GPU of its own memory;
the serialiser, the slabs and the device buffers send each make path's value.
Both guest sets and the ROM's record are rebuilt in the next commit.
2026-11-15 18:44:04 -08:00
Anees Iqbal 70578a33ff 🐛 Make textures past a buffer's length to the runtime's new bound
metal2vulkan d0ef5e0145 bounds a texture over a buffer of 16 KiB or more
as the M3 Max does: a 2D texture and a texture buffer at their last texel,
whatever the bytes per row past it, and a heap's buffer at its heap's size
from the buffer's start, where it counted bytesPerRow * height against the
length rounded up to 16 KiB. The bundle answered nil wherever the old bound
refused, on both guests, so it held back textures the host now makes.

rgfxTexelsPastAllocation now counts that end against rgfxHostAllocation:
the heap's size for a heap's buffer, the length rounded up to 16 KiB for any
other. The runtime counts a buffer over pages (a no-copy buffer, or one over
the device's region) from the host pointer's offset in its 16 KiB page,
which the guest does not know and which only adds to the bound, so the
bundle keeps the length rounded up for those and posts nothing the host
refuses. 2D arrays keep their slices' end, and a texture whose texels end
inside the length stays made.

For the guest: on either guest, a texture buffer or 2D texture over a
buffer of 16 KiB or more whose last texel ends inside the allocation is now
made where its rows' padding runs past it, and a heap's buffer of 16 KiB or
more takes textures to its heap's size, both answered nil before.
2026-11-15 09:43:56 -08:00
Anees Iqbal d6aa451c0b 🐛 Answer nil past an Apple GPU's allocation of a buffer
Under an Apple GPU's rules the bundle made a texture over a buffer under
16 KiB however far its texels ran past the length, where the M3 Max
answers nil: a texture buffer over a 4096-byte buffer past 128 KiB, for
one. oracle_pastlen measured the M3's bound (macOS 27.0.1, arm64): the
texture is nil where it ends past the buffer's resourceSize, counted from
the buffer's start. That is the 128 KiB pool for a buffer under 16 KiB,
the heap's size for a heap's buffer, the 16 KiB pages a no-copy buffer's
bytes meet, and the length rounded up to 16 KiB for the rest. A 2D texture
or a texture buffer ends at its last texel, a linear 2D array at its
slices' end.

For the guest: an arm64 guest's device now answers nil for those
textures, sending nothing. The x86 guest's device, whose reference x86
Macs make them, is unchanged.
2026-11-15 08:01:12 -08:00
Anees Iqbal 884887c9c5 🐛 Copy a buffer texture's bytes past the length by the device's blit
getBytes: and replaceRegion: of a texture over a buffer copied every byte
in place in the guest's memory, past the buffer's length too, where the
host's platform keeps those texels in a tail of the texture's own, which
every GPU path reads and writes. Past the length the CPU so read and wrote
another allocation's bytes, which no GPU path saw.

oracle_pastlen shows every oracle keeps one memory there inside the
buffer's allocation (the AMD 5300M and the Intel 630 under macOS 26.7.1,
the M3 Max under macOS 27.0.1), while past it the x86 Macs keep two that
disagree. For a buffer the device makes, the bytes inside the length are
still copied in place, and those past it go through a blit on the device's
copy queue that the call waits for, so the guest sees one memory past the
length on every device. It costs one round trip per call whose region has
a byte past the length.

A no-copy buffer's bytes past its length are the app's own memory, which
Metal's CPU copies reach in place on all three oracles, each dying of
SIGBUS where the app's mapping ends, so those copies stay in place.

For the guest: over a buffer of the device's, getBytes: past the length
now reads what the GPU wrote there and a kernel reads what replaceRegion:
wrote, and the guest's memory past the buffer is no longer touched. Over a
no-copy buffer nothing changes.
2026-11-15 08:01:12 -08:00
Anees Iqbal 093f788582 🐛 Take texture buffers up to 2^28 elements wide, as Metal does
The bundle's copy of Metal's descriptor validation gave a texture buffer
(MTLTextureTypeTextureBuffer) the 2D width limit, 16384, and ended the process
past it. A guest's MoltenVK makes each texel buffer view as a texture buffer as
wide as the view's elements, and a user's Minecraft died there at a 46626-wide
R8Sint one.

Metal takes far wider ones: the AMD 5300M and the Intel 630 under macOS 26.7.1
and the M3 Max under 27.0.1 answer maxTextureBufferWidth 268435456 (2^28) and
make texture buffers up to that many elements of any format at the device's, a
Private heap's and a Shared buffer's creators, ending the process one element
past it with the width line every type gives (oracle_texdesc --texbuf, jobs
m3-max-31563, 31564 and 31565). The bundle now does the same under both rule
sets: what changes for the guest is that texture buffers from 16385 to 2^28
elements are made instead of ending the process, and the words past 2^28 name
268435456. The answers past the device's maxBufferLength and past an Apple
GPU's allocation of a buffer stay as they were.

The shell tests that held the old limit had none for a texture buffer; they now
check the measured cases at the validation and the 46626-wide view over a
buffer, made and carried to the host with its width.
2026-11-14 23:35:46 -08:00
Anees Iqbal 84c8e95747 🐛 Ask a presenting queue's buffers for their submission
The present hold makes a queue's next frame wait for the drawable's
present-scheduled report, which comes only after the presenting buffer is
scheduled. A buffer that does not ask for its CB_SUBMITTED is scheduled at the
platform's submission, and that can wait for the queue's earlier work on the
GPU. On the RTX 3090 host, the Modern Rendering sample's presenting buffer sat
behind its frame's 89 ms pass and was scheduled at the pass's end, 88.6 ms
after its commit. The GPU then stood idle 19 to 22 ms a frame, 12.3 -> 10.2
fps against the set without the hold. Metal schedules a buffer that waits for
nothing within a fraction of a millisecond of its commit, whatever its queue
runs before it.

What changes for the guest:
- Once a buffer of a queue presents a drawable, it and every buffer the queue
  commits after it ask for their submission (RGFX_OP_SUBMITTED), where the
  device answers it.
- The host then schedules each one at its take where it waits for nothing and
  no buffer before it on its queue owes its scheduling. Such a buffer becomes
  Scheduled, and its present is made, at its take instead of at the
  platform's submission.
- Queues that never present ask as before: only commitAndWaitUntilSubmitted's
  buffers ask.
2026-11-14 22:19:07 -08:00
Anees Iqbal 1651d3a96f 🐛 Hold a queue's later buffers until its present is scheduled
A GPU-bound app's window reached the screen at about half the app's rate:
our bundle's presentDrawable: posted every later buffer of the queue at
once, so the app ran as many frames ahead of WindowServer as its queue
held, and WindowServer's composite waited behind them on the host's GPU.

Metal's base command buffer asks each drawable it presents for a
present-scheduled report (addPresentScheduledHandler:, CoreAnimation's),
and its queue submits nothing after the presenting buffer until the
report comes. Measured on the MBP16's AMD 5300M and Intel 630 (macOS
26.7.1): with the report 200 ms after the present, a buffer committed
right behind it was scheduled at 200.7 to 210.5 ms, against 0.3 to 1.3 ms
with an immediate report, and both commits returned in 0.03 ms.

What changes for the guest: a buffer committed after a presenting one
stays committed, unsubmitted, until CoreAnimation reports the present
serviced, as on a Mac. Every drawable a buffer presents is now asked
for addPresentScheduledHandler:, as Metal asks it; a buffer that failed
before its present gives the signal from its scheduled handler.

The bundle's fake drawables gain addPresentScheduledHandler:, and a new
test holds the later buffers through the present until the report, for a
report on demand, at add, at present, and behind a host-failed buffer.
2026-11-14 22:19:06 -08:00
Anees Iqbal c749b28a16 🐛 Read a texture in a raster order group for pipelines' reflection
The AIR reader refused a texture argument that sits in a raster order
group (`[[texture(n), raster_order_group(g)]]`). Its function's pipelines
answered no reflection. QuartzCore's inplace_copy_lpf and inplace_copy_lph
fragments, the last two entry points the sweep of macOS 27's metallibs found
refused, take one.

The reader now takes the group after a texture's access. The reflection
answers the texture as it answers one in no group: the AMD 5300M and the
Intel 630 make r_rog_texture's pipeline and list the texture that way
(m3-max-31210, 31211), and MTLTextureBindingInternal has no field for a
group.

What changed for the guest: on either guest, pipelines of such fragments
now answer a reflection that lists the texture. Before, they answered none.
2026-11-14 20:50:59 -08:00
Anees Iqbal 662040dac0 🐛 Answer imageblocks in pipelines' reflection as Metal does
The AIR reader refused the nodes of an explicit imageblock, of a fragment
function's imageblock data and of a view of a master struct. Pipelines of
those functions answered no reflection, and the device logged "its nodes
were not read". A sweep of macOS 27's metallibs found about 270 such
entry points: QuartzCore's blur kernels, CoreComposite's and VectorKit's
tile views, among others.

The reader now takes the imageblock's layout, its data size and the
master struct. The reflection builder makes them from Metal's own classes,
as the oracles answer them (tools/pipeline_reflection_check's new cases):
- on an Apple GPU, a kernel's explicit imageblock is an
  MTLImageBlockArgument of binding type 17 and kind 1, at index 0, of its
  data's size and its struct; a false function constant leaves it out.
  Neither x86 Mac makes a pipeline of one, so an x86 guest's still answers
  none;
- a fragment function's imageblock data is an MTLImageBlockDataArgument of
  binding type 16, its master struct in imageBlockMasterStructMembers when
  it views one, on either guest: the M3 Max and the Intel 630 make those
  pipelines, and the AMD 5300M makes the master view's.

What changed for the guest: these pipelines now answer a reflection that
lists their imageblock. Before, they answered none. The x86 checks match
the AMD GPU in every value, and the Intel GPU in every value but its known
postVertexDumpStride (m3-max-31210, 31211). Of the entry points the sweep
found refused, 2 are left: QuartzCore's textures in a raster order group,
which the next commit reads.
2026-11-14 20:50:59 -08:00
Anees Iqbal 80d8e003b7 🐛 Answer an argument encoder's reflection as the function's pipelines do
newArgumentEncoderWithBufferIndex:reflection: answered the binding of the
library's reflection of the function, whose argument buffer arrays have
their element's size as their stride. Metal answers the binding a pipeline
of the function reflects, its arrays of stride 0: the AMD 5300M and the
Intel 630 under macOS 26.7.1 (c13's oracle_bundle argbuf.reflection,
argbuf.binding and argbuf.binding.lib) and the M3 Max under macOS 27.0.1
(m3-max-31079) alike.

What the guest sees: the reflection out-parameter is now the binding built
from the function's AIR as its pipelines' reflection is (on an arm64 guest
with the M3's alignment), an array of textures in it of stride 0; where that
is not made, the library's binding as before. The shell test holds the
stride over oracle_reflection's k_argument_buffer, and the protocol test the
binding over air_arguments' every_access.
2026-11-14 20:50:59 -08:00
Anees Iqbal 26c6fd2573 🐛 Read colour attachment inputs at computed indices or in raster groups
A fragment function's input of a colour attachment's value ([[color(n)]])
did not read where function constants compute n, or where the input is in a
raster order group, and pipelines of such a function answered no reflection:
41 of macOS 27's framework fragments (RenderBox's 35, PencilKit's, CoreRE's)
take an index function constants compute and 9 (CoreRE's) a raster order
group (the reflection sweep, m3-max-31057 and 31073). Metal's compiler writes
the index as the global its initialiser sets, as for a binding's index, and
the group as air.raster_order_group n after it (read: f_fetch_at and
f_fetch_group, macOS 27.0.1). The reader now takes both, the group only on a
colour attachment's input, where Metal lists the input nowhere (measured:
f_fetch); a binding in a raster order group still does not read.

What the guest sees: a render pipeline made with reflection options of such
a fragment function answers its reflection, the colour attachment's input
listed nowhere, where it answered nil; and its functions made with constants
are checked for overlapping arguments, as Metal checks them. oracle_reflection's
f_fetch_group and f_fetch_at hold it in the AIR test and the shell test, and
pipeline_reflection_check compares them with Metal's (r_fetch_group,
r_fetch_at).
2026-11-14 20:50:59 -08:00
Anees Iqbal e2870344f1 🐛 Follow argument buffers nested 32 deep for pipelines' reflection
The AIR reader stopped at 8 levels of layouts and argument buffers' members,
and a pipeline of an entry point nested deeper answered no reflection: 39 of
macOS 27's framework entry points (VFX 30, CoreUSDEdit 9; the reflection
sweep over every system .metallib on the M3 Max, m3-max-31057 and 31073),
which all read at 12. The limit only bounds the recursion, so it is now 32,
named kRgfxAirNesting, in the reader, in the count of a struct of members'
ids and in whether an argument buffer's members write a texture.

What the guest sees: a render, compute or mesh pipeline made with reflection
options of such an entry point answers its reflection, built as for the
shallower argument buffers, where it answered nil; textures in those
argument buffers that the function only reads are no longer taken as
written. oracle_reflection's k_deep_ab, a chain of seven argument buffers,
holds both in the AIR test and the shell test, and pipeline_reflection_check
compares it with Metal's (c_deep_ab).
2026-11-14 20:50:59 -08:00
Anees Iqbal d0c059bc14 🐛 Tell a Managed buffer's modified range up to its length
What changes for the guest and the host: replaceRegion: of a texture over a
Managed buffer whose rows run past the buffer's length now posts
BUFFER_DID_MODIFY_RANGE for the rows' span up to the length, and nothing for
rows wholly past it. Before, it told the whole span, past the buffer's end.
The host refuses a range past the buffer whole (decode/managed.rs,
did_modify_range), so even the bytes the write put inside the length never
reached the GPU's copy, and the next GPU read saw stale texels where Metal's
sees the write.

Such textures are made by both forms: a 2D texture past the length, and since
the commit before last a texture buffer. Their texels past the length lie in
the host's tail of the texture, which no range of the buffer names, so the
range stops at the length. The host's strict check stays as it is.

Test: test_buffer_texture_replace_region_past_the_length_tells_the_length
covers three textures over a 4096-byte Managed buffer:
- a texture buffer of 4 RGBA32Float texels from 32 bytes short of the length
  tells 32 bytes;
- one wholly past the length tells nothing;
- a 2D texture whose rows written cross the length tells its span up to the
  length.
2026-11-14 19:13:43 -08:00
Anees Iqbal c103f8fe03 🐛 Answer nil for a texture past an Apple GPU's buffer allocation
What changes for the guest: a texture over a buffer whose texels end past an
Apple GPU's allocation of a buffer of 16 KiB or more (its length rounded up to
16 KiB) answers nil and posts nothing. Before, the bundle answered a texture
and posted its create, which the host refused, so the guest held a refused
object whose uses were dropped. This covers a 2D texture by
newTextureWithDescriptor:offset:bytesPerRow:, and a 2D texture, 2D array or
texture buffer by the linear SPI; the public form's texture buffer already
answered this nil. All of them now take one rule, rgfxPastAllocation:.

Why nil: the M3 Max answers nil there (a texture buffer and a 2D texture over
16384 and 20000 bytes, scratch probe tbpa, job m3-max-30902;
metal2vulkan measured the arrays). The runtime at ce54ad8b25 answers nil there
on every device (BufferTextureProblem::PastAllocation), so the host's
platform cannot make one. The AMD 5300M and the Intel 630 make every one of
them (jobs m3-max-30900, 30901): a class 2 divergence, recorded in Q11, and
the runtime's to take. Short of the allocation, and past any buffer under
16 KiB, the textures are made as before.

No test held the old answer: none made such a texture. New tests:
- the bundle's test_textures_past_a_buffers_allocation_answer_nil checks both
  forms;
- reims-vgpu-vulkan's textures_past_their_buffers_allocation_are_nil_as_the_m3s
  holds the host's answer to the same rule, so a runtime that changes it
  fails here.
2026-11-14 19:13:43 -08:00
Anees Iqbal 5c49ec8aaa 🐛 Make a texture buffer whose texels run past its buffer's end
What changes for the guest: newTextureWithDescriptor:offset:bytesPerRow: of
a texture buffer whose texels run past the buffer's length answers a texture
and posts TEXTURE_FROM_BUFFER, where the bundle answered nil and posted
nothing. Both x86 Macs make it (4 RGBA32Float texels at offset 4064 of a
4096-byte buffer, dgpu-oracle.md Q11), and so does the M3 Max
(metal2vulkan's probes/texture_buffer_past_length.m). The host's platform has
made it since metal2vulkan RUNTIME 1808 (pin 37), keeping the texels past the
length in a tail of the texture's own, so the refusal the nil stood in for is
gone. The 11-07 opengl lane hit that refusal.

It stays nil, posting nothing, where the texels end past an Apple GPU's
allocation of a buffer of 16 KiB or more (its length rounded up to 16 KiB).
The M3 answers nil there, and the runtime at ce54ad8b25 answers nil there on
every device, so the device cannot make it. The x86 Macs do make it there
(scratch probe tbpa, jobs m3-max-30900 to 30902): a class 2 divergence,
recorded in Q11.

The tests that held the old answer change with it.
test_buffer_texture_buffers now expects the texture made, with its create,
over 4096 bytes from 4064 and 12288 and over 20000 bytes from 19968, and nil
past the allocation. The new reims-vgpu-vulkan test
a_texture_buffer_past_its_buffers_length_is_made_as_metals makes the measured
shape over host memory and checks four things:
- a kernel's read and a blit read the buffer's bytes inside the length, and
  zero past it;
- a CPU write of the buffer reaches the next read;
- a blit's write lands in the buffer inside the length and in the tail past
  it, and changes no byte outside the buffer;
- one past a 16 KiB buffer's allocation is nil.
2026-11-14 19:13:43 -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 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