Commit Graph
8 Commits
Author SHA1 Message Date
Anees Iqbal 77f12120d4 🐛 Answer nil for a texture with no GPU address left
A device-placed texture and a Managed texture's GPU copy take a GPU address
of the context's range, which runs out at address-space exhaustion. Their
creates took the address unchecked and posted 0, where a heap, a buffer and
every other create that picks an address answer no object.

What changes for the guest: at exhaustion such a texture is nil, as Metal
answers one it cannot place, and nothing is posted; its resource id goes back
for the next texture. A texture in a heap takes no address and is unchanged.

Test: test_creates_with_no_address_post_nothing fails at the base, where both
creates post with address 0.
2026-11-05 21:59:36 -08:00
Anees Iqbal 0f9108bdfa 🐛 End the process at Shared heaps and CPU depth textures, as x86 Macs
Guest-visible: an app's newHeapWithDescriptor: with Shared storage now ends
the process with Metal's words ("Heap Descriptor Validation\nShared storage
mode disallowed"), where the bundle made a heap over host memory; and a depth,
stencil or depth-stencil texture in Shared or Managed storage, from the
device's, a heap's or a buffer's texture creators, ends it with Metal's
"Depth, Stencil, DepthStencil textures cannot be allocated with
MTLStorageModeShared or MTLStorageModeManaged on this device.", where the
bundle made one. Neither sends the host anything.

The x86 lane imitates an x86 Mac's GPU, and both oracles, the AMD 5300M and
the Intel 630 under macOS 26.7.1, end the process there: at a Shared heap
(oracle_bundle heapbuffers), at a Depth32Float texture in Shared storage over
a buffer (buftex.depth), and at the device's Depth32Float in Shared or Managed
storage and Stencil8 in Managed (devtex.*), making the Private one. The M3 Max
makes the heap and the texture over a buffer, but is no oracle of this lane.
The heap's region argument is now unused.
2026-11-05 21:59:33 -08:00
Anees Iqbal 68e47d8eaf 🐛 Keep what an object lay over until its destroy is posted
Where the kext refused an object's OBJECT_DESTROY (its control ring stayed
full), the host kept the object, yet the guest gave back its GPU address,
its resource id and its heap's bytes at once, so a later object could take
them while the host still held the old one there.

What changes for the guest and the host: a destroy the ring does not take
waits, with what its object lay over, behind any destroy already waiting.
The waiting destroys go out in the order they were made, ahead of the next
destroy and at each commit, and each one's give-backs run once it is posted,
so the host drops the object and nothing reuses its address, id or bytes
before. A slab's heap gives its address back the same way. With none
waiting, a destroy is posted as before.

create_tests' test_refused_destroy_waits lets a buffer and a texture go while
destroys are refused: no buffer finds an address and the texture's id stays
taken until an event's destroy posts all three in order.
2026-11-05 21:59:32 -08:00
Anees Iqbal b5a1aec913 ✅ Test that a refused create gives its GPU address back
RgfxSerializer::refused gives back the GPU address a create picked where the
device never got the create, which only reading the code showed. In a context
whose addresses hold one pick, a device buffer, a device heap, a heap and a
buffer over region blocks, a device texture and a Managed texture, each
refused, leave the address to a device buffer made next.
2026-11-05 21:59:32 -08:00
Anees Iqbal 998d692afc 🐛 Lay Managed textures' CPU copies in the slabs, not region blocks
Each Managed texture's CPU copy was a region block of its own, in the 1 GiB
region every process shares, so a desktop of apps with Managed textures ran
the region, and WindowServer's reserve in it, short.

Where the device took MANAGED_TEXTURE_SLABS, the copy is now a Shared buffer
of the process's slabs, as a device buffer of its size is: the process's own
superpages where the device takes them, else a range of a region slab shared
with other buffers. It reads zero as before, and MANAGED_TEXTURE_CREATE names
it. A device without the feature keeps the region block. Nil, as before, where
neither has room.

For the guest: a Managed texture's CPU copy comes as HEAP_OVER_* and
BUFFER_AT_OFFSET (or BUFFER_OVER_PAGES) in place of BUFFER_OVER_HOST_MEMORY
over a block of its own.

Car 12: kept fx-managed's test_managed_texture_reads_on_unified_memory
beside this test in shell_tests.mm, where both were added.
2026-11-05 21:59:31 -08:00
Anees Iqbal 351724d07a 🐎 Lay Shared and Managed buffers in slabs of the region
Each Shared or Managed buffer took a kext block of its own: a blocking ALLOC
with a first-fit scan and an overwrite mapping, a BLOCK_GRANT, a memset of the
whole block, a host import per buffer, and a BLOCK_RELEASE round trip at its
free. In a 16 GiB guest on the 5080 that made 4 KiB creates 29 us (76 us late
in a hold, the scan), stopped them at the block table's 16,384 entries, and
made frees a round trip each, RES-01's trigger.

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

A create is a free-list take and one ring-0 post, with no kext call, and the
block table holds one entry per slab. Where slabs come from is their source's,
so guest-RAM slabs can take the region's place behind a feature bit.
2026-11-05 21:59:24 -08:00
Anees Iqbal ab42daa0b3 🐎 Make one sampler or depth-stencil state per descriptor
Every sampler create waited for the host's SAMPLER_STATE through a kext call
and a ring-0 round trip, and every depth-stencil create was a kext call, with
no reuse: WindowServer makes a sampler each frame, and the ledger measured that
create waiting ~573 us behind the compositor's ring-0 work (aud-bundle-04).

The M3 Max's Metal answers an equal descriptor with the object it made before
(measured, macOS 27): it compares every property, the label among them, an
empty label as none and -0.0 as 0.0. The AMD 5300M and the Intel 630 make a new
one each call. Metal's docs promise neither, so the cheaper answer is taken.
RgfxStateCache holds each object weakly while the app holds it, and the last 64
made of each kind strongly, so an app that makes one sampler again and again,
letting each go, pays one host create in all. The M3 itself keeps depth-stencil
states after release; it frees samplers. A create that made nothing is not kept.

The factories also label what they make with the descriptor's label, which they
dropped before, as Metal answers it.
2026-11-05 21:59:23 -08:00
Anees Iqbal 24addecc72 🐛 Answer nil for every object whose create the device never got
Only pipelines, libraries, video sessions and now queues looked at whether
their create reached the device. Buffers, heaps and their buffers,
textures (device, over a buffer, linear, views, Managed and over an
IOSurface), events, fences, shared events, samplers and depth-stencil
states came back as objects the host never made where the kext's submit
refused the message, so a command buffer naming one would fail on the
host.

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

create_tests.mm makes each kind against a device that takes a set number
of messages: made while the device takes its create, nil once it refuses
it, with the address, resource id, region block and heap range back.
2026-11-05 21:59:23 -08:00