Files
reims-vgpu/docs/graphics-kext/dgpu-oracle.md
T
Anees Iqbal 17d65be9c2 🐎 Post surface-ordered buffers' records at their commit
The guest sees a command buffer that waits on the GPU for another queue's
buffer (SURFACE_ORDER) as submitted and scheduled when the host commits it,
instead of when that other buffer finishes. The order itself is unchanged: the
buffer still waits on the GPU and completes after the buffer it names.

The host counted such a buffer as one that waits for an event: its CB_SUBMITTED
and CB_SCHEDULED went at the platform's scheduling, and every later buffer of
its queue waited behind it. On the Vulkan platform a shared-event wait is held
on the host until its value is reached, so the records came only after the other
queue's buffer completed. WindowServer waits for submission three times a
frame, so the glass drag composited at about 59 a second on msi since the
surface order landed, against 117 before it.

A Mac holds back no record for such an order (dgpu-oracle.md, Q16): the blit
behind another queue's or process's 210 ms pass returns from
commitAndWaitUntilSubmitted and is scheduled within a millisecond on the 5300M
and the M3, and within 5 ms on the 630, and completes after the pass. So a
queue's records now go at commit, in its commit order, while one of its ordered
buffers is not yet taken by the platform (cmdbuf.rs, Line). Buffers that wait
for an event or a device cache's fill keep their records at their scheduling,
as before.

With such a buffer no longer holding its queue, a buffer behind it that ends
in its ask may be answered at the doorbell (answer_at_doorbell): its
CB_SUBMITTED is the answer's, and its CB_SCHEDULED goes at its commit through
the queue's Line, after the ordered buffer's. Submitted and Scheduled each post
once, whoever posts them first.

The fake platform can now hold submissions (World::hold_submissions), so the
tests pin both: an ordered buffer's records at commit, with completions in
order, and an explicit event wait that still holds its queue. A third pins a
doorbell answer between an ordered buffer's take and its commit: each record
once, in the queue's order. A test on each real platform pins the records at
commit and B's copy of what A wrote.
2026-11-05 21:59:28 -08:00

49 KiB

The dGPU oracle: what an x86 Mac's Metal leaves loose

Every Metal rule the reims-graphics lane imitated was first measured on an Apple M3 Max, a unified-memory tile-based GPU. The lane's guests are x86-64 macOS, whose apps and frameworks were written against Intel Macs: an AMD discrete GPU, an Intel iGPU, or both. This report measures those GPUs as a black box, with probes of our own, and compares each answer with what our stack enforces. Where the x86 contract is looser, the host may do less work; where it is stricter than the M3's, guests may rely on it.

The probes are in guest/bundle/tools/oracle (README): oracle_iosurface, oracle_storage, oracle_passes, oracle_cmdbuf, oracle_caps, oracle_errors, oracle_source, oracle_ycbcr, oracle_ca_ycbcr, oracle_sampler, oracle_icb and oracle_order.

Machines. Every claim below is measured, on:

  • AMD: AMD Radeon Pro 5300M (Navi 14, amdgpu_gfx1012, 4 GB; AMDRadeonX6000 on IOAcceleratorFamily2), in a MacBookPro16,1 (i7-9750H), macOS 26.7.1 (25G241), x86_64.
  • Intel: Intel UHD Graphics 630 in the same Mac. It drives the Mac's display.
  • M3: Apple M3 Max, Mac15,9, macOS 27.0.1 (26A434), arm64. It ran only the probes where it shows the gap.

The two x86 GPUs agree on every coherence question except the ones named, so "x86" below means both.

Reading the oracles

Each answer below is read in one of four classes, and its class decides what the lane does with it:

  1. Documented. Metal's documentation promises the behaviour. The lane keeps it exactly, whatever a Mac measured here does.
  2. Divergent. The documentation leaves it open, and the three Macs disagree. Any of their answers is inside the envelope a guest can meet, so the lane takes the one that costs the host least.
  3. Agreed. The documentation leaves it open, and all three Macs do the same. Guests may rely on it, so the lane treats it as contract.
  4. Outside the envelope. No Mac does what the lane does, or the documentation forbids it. The lane fixes it.

A boot overrides all four: what a guest's frameworks do on the lane decides, whatever the class. The tags below, (class N), say which class each answer is read in.

Ranked relaxations

# relaxation evidence what it removes expected win
1 (class 2) An IOSurface's GPU copy is a device cache. Copy the surface's pages in only at the first GPU use after a CPU read-write unlock, and write the GPU copy back only when a CPU lock follows a GPU write. Q1: on x86 an unlocked CPU write is never seen by the GPU, and a GPU write is never seen in the pages without a lock, the committing process included. m2v's whole-surface shadow copy-in before each command buffer, and its merge-back after each writing encoder, of every render-target surface. The copy path's per-command-buffer write-back on the guest CPU. In WindowServer's steady state nothing CPU-locks the 3840x2400 display surface, so both copies of 36.9 MB per composite go to zero. That is most of the pl1 gap: CLTD 28.2 ms against stock's 0.53. The copies x86 does make cost 5.6 to 7.6 ms each at 4K, paid only at those locks.
2 (class 3; landed, c95fca750) commitAndWaitUntilSubmitted and waitUntilScheduled return at submission. Q7: x86 returns 0.29 to 0.41 ms after commit, behind a 200 ms command buffer, as the M3 does. The wait for completion the bundle restored (bbb153d9e), once rgk-lock's lock wait lands. rgk-perf's fix 1 measured CLTD 19.6 to 6.1 ms. This is the M3's rule too; the oracle confirms x86 has no stricter one.
3 (class 3; the handler's queue class 2) Asynchronous pipeline creators return before the compile. Q7: the handler runs about 60 ms later, on Metal's Device serial queue. Our bundle compiles on the caller's thread, inside the call. Compile time moves off apps' calling threads (launch, first frames). Nothing in WindowServer's steady state.
4 (withdrawn) Shared textures' CPU access on a discrete host may use a CPU copy. Q3: on AMD, getBytes: of a Shared texture never sees GPU writes, and replaceRegion: uploads the CPU copy whole. The waited staging blit of each getBytes:/replaceRegion: of a Shared texture. Small: the calls are rare, and Intel and the M3 keep such textures coherent.

Relaxation 4 is withdrawn: the calls are rare, and Intel and the M3 keep such textures coherent, as ours does.

No relaxation was found for Managed storage (Q2: our discrete path already keeps two copies synced by didModifyRange: and synchronizeResource:, as AMD does), Shared buffers (Q3: coherent at command-buffer boundaries on x86, and ours are in place), load and store actions (Q4), memoryless, tile and fetch features (Q5), hazard tracking (Q6), errors (Q8) or limits (Q9). In Q4 and Q6 the x86 GPUs are stricter than the M3 (below).

Where x86 is stricter than the M3 rules we copy

Every x86 Mac behaved this way. Where the M3 does otherwise, the answer is divergent, not agreed:

  • (class 2: the lane keeps the M3's, which copies less) DontCare stores keep color. A pass with store action DontCare writes its draws and clears to memory on both x86 GPUs. On the M3 it drops them, and m2v copies nothing back for a DontCare store (render/shadows.rs), as the M3 does (Q4).
  • (class 2: the lane keeps the M3's) Untracked resources are ordered across command buffers. An untracked buffer written by one command buffer and read by the next on the same queue, with no event, is ordered on both x86 GPUs and races on the M3 (Q6).
  • (class 2) A timeout's error is IOAccelerator's. x86 answers code 2 with "Caused GPU Timeout Error (00000002:kIOAccelCommandBufferCallbackErrorTimeout)" and no underlying error. Our bundle answers code 2 with the M3's "Caused GPU Hang Error (00000003:kIOGPUCommandBufferCallbackErrorHang)" (Q8).
  • (class 3: the M3's are real too) GPU times are real. GPUStartTime/GPUEndTime are on the host clock on x86. The host sends the platform's GPU times in each completion, where it sent 0 for both (Q7).

Q1: IOSurface-backed textures

Probe: oracle_iosurface DEVICE single|cross|timing [W H [rt|ro [managed|shared|private]]]. A BGRA8 surface; each step writes a letter to every pixel on the CPU (with or without a lock) or the GPU (a blit from a buffer, or a render-pass clear), and reads the GPU's view (a blit into a Shared buffer) or the CPU's (the surface's base address, with or without a lock). The steps run in one process, and across two with a texture each.

What x86 does (AMD and Intel alike)

step AMD and Intel 630 M3
CPU write without a lock, then a GPU read: at the next command buffer, after another one, 200 ms later old pixels, every time new pixels
the same through a texture made after the write, in either process old pixels new pixels
a read-only lock and unlock seed unchanged, GPU still old (in place)
a read-write lock and unlock, even with no write seed +1; the next GPU use uploads the whole surface from the pages (in place)
an unlocked write of the top half, then a read-write lock and unlock the GPU sees new top, old bottom: whatever the pages hold (in place)
a write under lock and unlock seen at the next command buffer seen
GPU write, then the committing process reads without a lock: at completion, 200 ms later old pixels new pixels
GPU write, then a lock (read-only or read-write, any process) the lock downloads the whole surface; the GPU's pixels the GPU's pixels
GPU write, an unlocked CPU write of half, then a lock the GPU's pixels everywhere: the download overwrites the unlocked CPU write the CPU's half
GPU write, then a locked CPU write of half CPU's half, GPU's other half the same
another process's texture over the same surface, after a GPU write sees it at once sees it

So each surface has one GPU copy per GPU, shared by every texture and every process on that GPU. On AMD it is in VRAM: rgk-lock's traces of the driver's lock path show a written surface marked current at submit and paged off at a lock (traced on this Mac, not by these probes). The GPU copy is refreshed from the pages at the first GPU use after the seed moved past the GPU copy's, and the pages from the GPU copy at the next lock after a GPU write. The same held for texture storage Managed, Shared and Private, and for usage ShaderRead alone.

A GPU write moves the seed by one, but the GPU's own move does not make the next GPU use upload. Measured at 3840 x 2400 (36.9 MB), in ms of a GPU read of the whole surface:

GPU read AMD Intel 630
nothing changed 7.8 to 7.9 13.9 to 14.0
after a read-write unlock (upload) 13.5 21.5
after a read-only unlock, or an unlocked CPU write 7.8 to 7.9 13.9 to 14.0
after a GPU write (seed +1) 5.4 to 5.8 13.7 to 13.8
lock AMD Intel 630
after a GPU write (download) 5.5 to 5.6 (8.1 read-only once) 7.5 to 7.7
again, with no GPU write between 0.00 0.00

A read-write lock after a GPU write therefore costs a download, then an upload at the next GPU use (AMD 5.6 + 5.6 ms at 4K), even when the CPU wrote nothing.

What our stack does

  • In place (RGFX_FEATURE_SURFACE_PAGES): the host maps the surface's guest pages and makes each texture over them. A texture the GPU only samples is a linear image over the pages. One the GPU renders to or writes is a shadow image: m2v copies the pages in before the first command of each command buffer that uses it, and merges the changed words back at the end of each encoder that wrote it. The copy-in is the whole texture: the graphics device takes no dirty-page source, whose resolution of the surface's pages cost the host more per command buffer than the copies it saved (measured on the 5080). Nothing consults the seed or a lock.
  • The copy: at each commit the bundle copies every surface of the process whose seed moved into its block, and at each completion writes every written surface back under a lock.

The relaxation

Hold one GPU copy per surface (m2v's shadow image is that copy), keyed by the surface, not the texture:

  • In: copy the pages to the GPU copy only at the first GPU use after a CPU read-write unlock took the seed past the GPU copy's. Record the seed after each GPU write as the GPU copy's own.
  • Out: copy the GPU copy back to the pages only when a CPU lock comes after a GPU write. That is rgk-lock's page-off (op 0) at the kext's lock callback, which op 2 then waits for.
  • Unlocked CPU readers and writers then see what they see on x86.

What it needs:

  • the surface's seed at the host at each use (the copy path's block header holds it; the in-place path would report it);
  • the lock callback (rgk-lock);
  • every texture over a surface reading the one GPU copy, where a sampled-only texture today reads the pages in place;
  • the host's scanout or present reading the GPU copy. AMD scans out of VRAM; a present that read the pages would need the copy back once a present.

Expected win: WindowServer composites into the 3840 x 2400 display surface every frame and nothing locks it on the CPU, so the steady state copies nothing. Today each composite copies 36.9 MB in and merges back the changed words; pl1 measured CLTD 28.2 ms against stock's 0.53. Surfaces apps draw on the CPU (backing stores) are copied in once per read-write unlock, as on x86.

Q2: Managed storage

Probe: oracle_storage DEVICE mbuf 4096|67108864 and mtex.

AMD Intel 630 and M3
buffer: CPU write without didModifyRange: (next command buffer, 200 ms later) never seen seen at once
buffer: didModifyRange: of [0,256) after an unnamed whole-buffer write the whole buffer uploaded (4 KiB and 64 MiB) (one copy)
buffer: GPU write pending (no sync), then CPU [0,256) + didModifyRange: of it only [0,256) uploaded; the GPU's bytes stay elsewhere (one copy)
buffer: GPU write without synchronizeResource: (completion, 200 ms) never seen by the CPU seen at once
buffer: didModifyRange: after the reading command buffer was encoded, before its commit seen: the upload happens at commit seen
texture: GPU write without synchronizeTexture:, then getBytes: old bytes, also 200 ms later new
texture: unsynchronized GPU write, then replaceRegion: of a 16 x 1 corner the whole CPU copy is uploaded: the GPU's write is lost outside the corner corner new, GPU's write kept

Our stack: on a discrete host Managed resources are two copies. didModifyRange: copies exactly the named range to the GPU copy, ordered before the next commit; synchronizeResource: copies back inside the blit encoder; replaceRegion: uploads its region (decode/managed.rs). On a unified host they are one copy, as on Intel. Relaxation: none. AMD is looser than Metal in one way that costs us nothing: it uploads more than the named range when the GPU copy is clean, so an app with a short didModifyRange: works on AMD, where ours uploads the range alone.

Q3: Shared storage

Probes: oracle_storage DEVICE shtex, lintex shared|managed, spin.

  • Shared textures (newTextureWithDescriptor: of storage Shared) are made on AMD, Intel and the M3. On AMD such a texture behaves like an unsynchronized Managed one: getBytes: never sees a render clear or blit write (also 200 ms later), and replaceRegion: of a corner uploads the CPU copy whole over the GPU's write. Intel and the M3 are coherent. Ours: CPU access goes through a staging blit the call waits for (RgfxTexture.mm), which is coherent.
  • A linear texture over a Shared buffer is in place on both x86 GPUs: a CPU write to the buffer is seen by the next GPU read of the texture, and a render clear of the texture lands in the buffer at completion. Over a Managed buffer it follows Managed's rules. That is our design (Decided 4).
  • A Shared buffer while the GPU runs: a 1.3 s kernel polling a word (atomic and plain loads) never saw a CPU write made 20 ms after scheduling, on either x86 GPU; a kernel storing its progress was never seen by a CPU polling every millisecond before completion. Shared memory is coherent at command-buffer boundaries only. (Over a 6 s kernel the 5300M saw the CPU's write at 5.8 s, once.) Ours is in place and at least as coherent.

Relaxation: only the Shared texture's CPU access (ranked 4), and only on a discrete host.

Q4: render-pass load and store actions

Probe: oracle_passes DEVICE actions private|managed|iosurface, depth, stencil, msaa. A 256 x 256 RGBA8 attachment, cleared to A and stored, then one pass of the row's actions with or without a draw of B over its left half (Clear rows clear to C).

load store draw AMD and Intel: left, right M3: left, right
Load Store B B, A B, A
DontCare Store B B, A B, 25% zeros + A
Load DontCare B B, A A, A
DontCare DontCare B B, A A, A
Clear DontCare B B, C A, A
Clear DontCare - C, C A, A

The same for Private, Managed and IOSurface attachments. Depth32Float cleared with store DontCare keeps the clear on AMD and drops it on Intel and the M3. The stencil of a Depth32Float_Stencil8 attachment cleared with store DontCare keeps the clear on AMD and Intel, and drops it on the M3, which keeps the stencil stored before. A 4x MSAA attachment resolved with its samples DontCare keeps its samples on all three. (class 2: what a DontCare store leaves is divergent for color, depth and stencil.)

Our stack: m2v copies a shadow in for a DontCare load, as for Load, and copies nothing back for a DontCare store; a whole-texture Clear copies nothing in. Relaxation: none: x86 keeps every color write a DontCare store discards on the M3, so skipping a copy-in on a DontCare load would lose pixels x86 keeps. The DontCare store rule is a difference from x86 (above). Under Q1's device cache it no longer decides anything for IOSurfaces, whose merge-back moves to the lock.

Q5: memoryless, tile and imageblock, framebuffer fetch

Probe: oracle_passes DEVICE features.

AMD Intel 630 M3
memoryless texture Metal asserts: "MTLResourceStorageModeMemoryless is not a supported storage mode on this device." (the process ends) the same made
tile pipeline nil, error nil nil, error nil made
framebuffer-fetch pipeline ([[color(0)]] input) made; the fetch reads 0 made; reads the attachment made; reads it
isFramebufferReadSupported (SPI) 0 1 1
raster-order-group pipeline made (areRasterOrderGroupsSupported 1) made (1) made (1)
supportsTileShaders, supportsImageBlocks (SPI) 0, 0 0, 0 1, 1

Our stack: memoryless textures are made (m2v). The lane answers isFramebufferReadSupported no, as AMD does (class 2: the Vulkan platform's fetch costs most), and supportsTileShaders and supportsImageBlocks no, as both x86 GPUs do (4ee4bcaf0). Relaxation: none. With no Apple family claimed, guests should ask for none of these; a guest that makes a memoryless texture ends on x86 and goes on with ours.

Q6: hazard tracking

Probe: oracle_cmdbuf DEVICE hazards. A ~30 ms kernel writes 7 to 1M words (each thread spins first); a second dispatch copies them. Runs where any copied word is not 7, of 5:

ordering AMD Intel 630 M3
tracked, two compute encoders 0 0 0
untracked, two compute encoders, no fence 0 0 0
untracked, one serial encoder 0 0 0
untracked, one concurrent encoder, no barrier 0 5 5
untracked, concurrent encoder + memoryBarrierWithScope: 0 0 0
untracked, compute encoder then a blit copy, no fence 5 0 5
untracked, two command buffers, one queue 0 0 5
from an untracked heap, two compute encoders 0 0 0
tracked, two command buffers, two queues, the second committed once the first's commitAndWaitUntilSubmitted returns 0 0 0
untracked, the same 0 0 5
tracked, two queues, the second committed right after the first's commit 0 0 0

On AMD a blit runs beside compute work: a tiny blit command buffer committed behind a 200 ms compute one ran at once (GPU time 0.38 to 0.39 ms after commit), though its completion was reported after the compute one's.

Our stack: tracked resources are ordered; untracked ones are left to the program, serial encoders run in order, and the bundle has its own fence across every 8 encoders. Relaxation: none. Untracked compute across encoders and command buffers is ordered on every x86 GPU, so guests may rely on it; whether the Vulkan platform orders successive command buffers' untracked work is worth a check. A tracked resource is ordered across two queues by commit on all three, the later buffer committed as soon as the earlier one's commitAndWaitUntilSubmitted returns, or right after its commit (class 3); an untracked one is ordered so on x86 and races on the M3 (class 2).

Q7: command-buffer timing and handlers

Probe: oracle_cmdbuf DEVICE timing. Times are from commit.

AMD Intel 630
a tiny buffer behind a 200 ms one, same queue: scheduled handler 0.36 ms 0.30 ms
its waitUntilScheduled returns 0.38 ms 0.34 ms
its commitAndWaitUntilSubmitted returns 0.29 ms 0.41 ms
its completed handlers after the long one's (202.5 ms), in the order added the same (197.4 ms)
a tiny buffer on a second queue completed at 0.46 ms 0.72 ms
a buffer that first waits on an unsignalled shared event, signalled at 300 ms scheduled at the signal (302.2 ms) the same (309.1 ms)
idle GPU, tiny buffer, median: scheduled / completed / waitUntilCompleted 0.20 / 0.42 / 0.49 ms 0.22 / 0.50 / 0.55 ms
handler threads Metal's com.Metal.CompletionQueueDispatch queue, never the main thread the same
GPUStartTime/GPUEndTime real, on the host clock (the long one +0.59 to +202.28 ms) real
kernelStartTime/kernelEndTime +0.08 / +0.16 ms +0.06 / +0.09 ms
async compute and render pipeline creators return with the handler pending; it runs about 60 ms later on Device serial queue the same

oracle_cmdbuf DEVICE submitted: a tiny buffer's commitAndWaitUntilSubmitted, 20 runs each, times from the first commit (medians), on the 5300M, the 630 (both macOS 26.7.1) and the M3 Max (macOS 27.0.1):

AMD Intel 630 M3
behind a ~100 ms buffer, same queue: the call returns 0.35 ms 0.27 ms 0.15 ms
its scheduled handler 0.29 ms 0.26 ms 0.15 ms
status at the return Scheduled 18, Committed 2 Scheduled 20 Scheduled 19, Committed 1
scheduled handler run by the return 18 of 20 20 of 20 17 of 20
idle queue: the call returns / scheduled handler 0.13 / 0.20 ms 0.15 / 0.20 ms 0.05 / 0.06 ms
idle queue: status at the return Committed 20 Committed 20 Committed 20
waitUntilScheduled right after the return, idle queue blocks 0.12 ms 0.09 ms 0.01 ms
waiting on a shared event a second thread signals at 100 ms: the call returns at the signal (107.1 ms) the same (105.5 ms) the same (106.0 ms)
the same: status at the return Committed 20 Committed 20 Committed 20
behind a buffer of its queue that waits on such an event: the call returns at the signal (105.2 ms) the same (109.5 ms) the same (110.1 ms)
the same: status at the return Scheduled 18, Committed 2 Scheduled 18, Committed 2 Scheduled 20

So the call returns once the buffer is submitted, which for a buffer waiting on an event, or behind one on its queue, is at the signal (class 3); whether the buffer is Scheduled by then, and its scheduled handlers have run, is a race on all three (class 2), and an idle queue returns while it is still Committed (class 3).

The M3 also runs a creator's handler after the creator returns, on the global default-QoS queue (com.apple.root.default-qos) (class 3 that it runs after the return; class 2 which queue).

Our stack: commitAndWaitUntilSubmitted and waitUntilScheduled return at submission (c95fca750), and handlers run on the process's completion thread in Metal's order. A buffer commitAndWaitUntilSubmitted commits asks for its submission (CB_SUBMITTED, design.md, "Submitted"), and the call returns at the host's answer: as the host takes it, or at the signal for one that waits on an event or is behind one that does, so an idle queue's buffer returns while it is still Committed, as on all three. The host sends the platform's GPU times, from which the bundle answers GPUStartTime and GPUEndTime, and the async creators run their create and handler on the global default-QoS queue, after the creator returns, as the M3 does. Relaxations: ranked 2 and 3.

Q8: errors and refusals

Probe: oracle_errors DEVICE [purgeable|creates|residency|timeout].

failure AMD Intel 630
a buffer and a texture set purgeable Empty, then used completes, no error the same
6 x 1 GiB Private buffers filled in one command buffer (AMD has 4 GB of VRAM) completes in 836 ms, no error completes, no error
a buffer of maxBufferLength + 4096 made nil
a Private heap of 4x recommendedMaxWorkingSetSize made (17 GB) nil
a 32768 x 32768 texture Metal asserts (width and height over 16384); the process ends the same
one kernel past the watchdog status Error after 20.2 s status Error after 16.1 s

The timeout's error, on both: domain MTLCommandBufferErrorDomain, code 2, NSLocalizedDescription "Caused GPU Timeout Error (00000002:kIOAccelCommandBufferCallbackErrorTimeout)", and, with MTLCommandBufferErrorOptionEncoderExecutionStatus, MTLCommandBufferEncoderInfoErrorKey naming the encoder with status 2. No NSUnderlyingErrorKey: x86 has no nested IOGPU error for it. GPUStartTime and GPUEndTime are 0. The Intel kernel's writes were lost; the AMD kernel's were kept. An 8 s kernel completes on both.

Our stack: the bundle's code 2 carries the M3's "Caused GPU Hang Error (00000003:kIOGPUCommandBufferCallbackErrorHang)", and code 9 an underlying IOGPUCommandQueueErrorDomain error (measured on the M3). Relaxation: none.

Q9: limits and formats

Probe: oracle_caps DEVICE. Where the x86 GPUs' answers differ from the M3's or from our device's (an x86-64 guest on the RTX 5080 host, metal_enum):

answer AMD Intel 630 M3 ours (5080)
maxBufferLength 3208642560 2147483648 41747087360 12821200896 (4ee4bcaf0; 1099511627776 before)
maxThreadgroupMemoryLength 65536 65536 32768 32768
maxArgumentBufferSamplerCount 2048 2048 500000 0
readWriteTextureSupport 2 1 2 2
minimumLinearTextureAlignmentForPixelFormat:, linearTextureAlignmentBytes 256 256 16 256 (4a329e614)
iosurfaceTextureAlignmentBytes 16 16 16
isDepth24Stencil8PixelFormatSupported 1 0 0 0
supports32BitMSAA, supportsPullModelInterpolation 1, 1 1, 1 1, 1 the runtime's: 1, 1 on the 5080 (metal2vulkan 7da81ee3d8; 0, 0 before)
supportsTextureSampleCount:(8) 1 1 0 0
barycentrics 1 0 1 1
supportsRaytracing, supportsFunctionPointers, supportsDynamicLibraries 1 1 1 0 (lane)
supportsPlacementSparse raises (not implemented) raises 1 0
sparse tile sizes 0x0x0 n/r 64x64 and up 64x64 and up
families Mac2, Common1-3, Metal3; no Apple the same Apple1-9, Metal4 too as AMD
supportsFeatureSet:(10002) 1 0 0 0
featureProfile (SPI) 10002 10002 10 10, the M3's (Q11)
heapTextureSizeAndAlign alignment 65536 4096 128

Formats (F lines): both x86 GPUs make every uncompressed color format but B5G6R5, A1BGR5, ABGR4 and R8/RG8 sRGB (BGR5A1 is made), and every BC format, the 4:2:2 formats and the depth formats (D24S8 and X24S8 on AMD only). Metal asserts, ending the process, at the create of every ASTC, ETC2, EAC and PVRTC format, B5G6R5, A1BGR5, ABGR4, R8Unorm_sRGB, RG8Unorm_sRGB and the XR10 formats (552-555), and at a 4x MSAA BGR5A1 or RGB9E5 texture. minimumTextureBufferAlignmentForPixelFormat: answers on x86 for every format (the format's bytes per pixel, or a compressed block's), where the M3 asserts for compressed and depth ones. Our device makes ASTC and the packed formats (m2v), which no x86 Mac does; with no Apple family claimed, frameworks should not ask for them.

Relaxation: none for performance. Two answers help the host, and the lane gives both, as choices inside the envelope (class 2): minimumLinearTextureAlignmentForPixelFormat: and the SPI linear alignments 256 for every format, as both x86 GPUs answer, which suits the Vulkan hosts' linear images (4ee4bcaf0, 4a329e614); and maxBufferLength at most three quarters of recommendedMaxWorkingSetSize, the rule the 5300M and the M3 answer by (4ee4bcaf0).

Q10: runtime source compile

Probe: oracle_source DEVICE [OUT]. A source of a vertex, a fragment and a kernel function, compiled by newLibraryWithSource:options:error:, by the base class's implementation called on the device, and by _MTLDevice's compiler-task form called on the device with no task.

AMD Intel 630 M3
library _MTLLibrary the same the same
its bytes (libraryDataContents) a .metallib (MTLB) of AIR, 12324 bytes the same bytes as AMD 12324 bytes (macOS 27)
the three routes the same bytes the same the same
a source that does not compile nil; MTLLibraryErrorDomain 3 with the compiler's log the same the same
a source that compiles, also with an unused variable the library; *error nil the same the same

How the base class compiles (dtrace on the AMD device's classes, and method swaps on all three): its form without a task calls the compiler-task form on the device, which reaches Metal's compiler service through _MTLDevice's own getCompilerConnectionManager:, on the caller's thread. It never asks the device for its compiler: a compiler answered nil, or one made with a plugin that does not exist, changed nothing. Of the device it reads featureProfile (AMD and Intel answer 10002, the M3 10), supportsFamily:withFamilyArray:count:, and Metal's own settings for the compiler service and for shader capture. Six sources (a kernel, framebuffer fetch, an imageblock, simdgroup matrices, bfloat and ray tracing) compiled under featureProfile 10 and 10002 made the same bytes, in either order.

Our stack: the device's source forms run that compiler-task form on super, over the device, and make the device's library of its bytes through newLibraryWithData:, as an app's .metallib is made; Metal's library is kept as the shadow, and Metal's error and nil pass through unchanged (class 3). Before this, the device refused every source, which lost Chrome's WebGL contexts at their first link.

Q11: mipmapped textures over a buffer, and the feature profile

Probe: a scratch probe, not kept. A 256 x 256 BGRA8 texture over a buffer, rows 1024 bytes apart, with 1, 2 and 7 mipmap levels, by each form: the public newTextureWithDescriptor:offset:bytesPerRow: of a Shared buffer, the buffer's SPI newTiledTextureWithDescriptor:offset:bytesPerRow: (descriptor Managed, buffer Shared), and the device's SPI newTiledTextureWithBytesNoCopy:length:descriptor: offset:bytesPerRow:, which asks the buffer it makes for the second.

form, 2 or 7 levels AMD Intel 630 M3
public Metal asserts: "Linear texture: cannot be mipmapped"; the process ends the same the same
the buffer's tiled SPI made, with the levels asked, storage Shared; level 0 over the buffer's bytes; levels 1 and up rendered to and read by a blit and a kernel, their pixels nowhere in the buffer the same the buffer does not answer the selector
the device's tiled SPI as the buffer's the same an unrecognized-selector exception (the device asks its buffer for the buffer's SPI)

(class 2: the tiled forms are x86's alone.) WindowServer's tiled backings use the buffer's SPI (RgfxBuffer.mm). Our stack: the public form ends the process at more than one level with Metal's words (class 3), sending the host nothing; the tiled forms answer nil for one, logged once, until the host carries levels 1 and up. With the lane answering featureProfile 10002, an x86 Mac's, WindowServer asked the lane for a 7-level texture over a buffer, which the host's platform refused, and every later command buffer naming it faulted, so its composition stopped (boot ro1-p2, 11-02); answering 10 it asked for none (ro1-p1 and its control). The x86 answer on that path is not one the host keeps cheaply: levels 1 and up live in the GPU's own memory, apart from the buffer's. Core Image made no texture over a buffer by any of the three forms, under 10 or 10002, for blurs, scales and renders to a texture on the AMD and the Intel GPU. WindowServer on the oracle cannot be traced, being protected, so which framework reads the profile for it is not measured. The lane keeps the host's answer, 10 on every host so far (class 2: the cheapest); the frontend makes the same bytes under either (Q10).

Q12: texture descriptors Metal's validation ends the process at

Probe: a scratch probe, not kept, one case a process, with MTL_DEBUG_LAYER unset: a 64 x 64 Private texture by the device's newTextureWithDescriptor: and by an Automatic heap's, of the three-channel formats 45 and 100, and 2DMultisample ones (4x, 2x and 1x) of BC1, ASTC (186, 222), GBGR422, BGRG422 and Unspecialized (263). The guest's x86 macOS 26.6 makes these descriptors and sent them on (boot pm29, oracle_caps); the oracles' answers, alike at the device and the heap:

descriptor AMD Intel 630 M3
a three-channel format (45 to 48, 95 to 100, 120 to 122) the process ends at the descriptor's setter: "pixelFormat (45) is not a valid MTLPixelFormat." the same the process ends at the create: "MTLTextureDescriptor has invalid pixelFormat (45)."
multisample, of a compressed or 4:2:2 format the process ends at the create, Metal listing each rule broken: the format "does not support multisample textures", "a compressed pixel format set with a sample count greater than one" (at 1x: "sampleCount must be > 1"), compressed formats' types, and the 4:2:2 formats' 2D the same the same
multisample, of Unspecialized (263) the process ends: "invalid pixelFormat (263)", and Invalid "does not support multisample textures" the same the process ends: Unspecialized "does not support multisample textures"

The x86 GPUs name a format they lack (ASTC) as an invalid one, where the M3 names it. Every message is -[MTLTextureDescriptorInternal validateWithDevice:]'s "Texture Descriptor Validation", but the x86 setter's. Our stack: the device's and the heaps' creators end the process at each of these with the words of the M3's create, sending the host nothing (class 3), rather than sending a create the host refuses (rgfxEndAtInvalidTextureDescriptor, RgfxTexture.h).

Q13: two-plane Y'CbCr textures

Probe: oracle_ycbcr DEVICE. A 64 x 64 CVPixelBuffer over an IOSurface, of OSType 420v (video range) or 420f (full range), its kIOSurfaceYCbCrMatrix set to ITU_R_709_2 or ITU_R_601_4, by CoreVideo's propagated kCVImageBufferYCbCrMatrixKey or on the surface itself, or left unset; each quadrant holds one patch of known codes. A texture of MTLPixelFormat 500 (YCBCR8_420_2P) over plane 0, by newTextureWithDescriptor:iosurface:plane:, read by read() at each quadrant's middle. Each case runs in a child process.

AMD Intel 630 M3
the texture the process ends at the create: "MTLTextureDescriptor has invalid pixelFormat (500)." the same made
what it reads the codes converted by the surface's range and matrix, within one level on every channel: BT.709 under ITU_R_709_2, BT.601 under ITU_R_601_4 and with no matrix

The surface reads back the matrix as set, by either route, on all three. (class 2: the two-plane Y'CbCr formats are the M3's alone; a guest that made one on an x86 Mac would end its process.) Our stack makes them as the M3 does (the host's surface creator converts by the surface's facts, RgfxSurfaceFacts).

Where the guest meets Y'CbCr on the desktop (boot ycc4, 11-02, with the bundle's texture creates traced): the default wallpaper is an aerial, a 3840 x 2160 frame of OSType x420 (10-bit 4:2:0, video range) tagged ITU_R_709_2. No process made a two-plane Y'CbCr texture of it. VideoToolbox's decoder service made textures of its planes, R16Unorm (20) over plane 0 and RG16Unorm (60) over plane 1, and a RGBA16Float (115) one over an RGhA surface it writes; WindowServer made the same two plane textures and composites the frame from them. The matrix is a constant of Apple's own shaders there, read from the surface's tag, and the frame shows by BT.709 on the lane. On the stock lane the same frame shows by BT.601: the lane's desktop is the stock's colours re-encoded by BT.601 and decoded by BT.709, within 1.1 levels on average (the guests' captures), with no parameter fitted.

What the frameworks convert such a frame by on a Mac (probe: oracle_ca_ycbcr DEVICE, 11-02): 64 x 64 CVPixelBuffers over IOSurfaces, of OSType x420 and 420v (both video range), tagged ITU_R_709_2 or ITU_R_601_4 by CoreVideo's propagated kCVImageBufferYCbCrMatrixKey, or untagged; each quadrant holds one patch of known codes. CoreAnimation draws each as a layer's contents, by a CARenderer into a BGRA8 texture of the device on a queue of the device; VideoToolbox converts each to a 32BGRA pixel buffer by a VTPixelTransferSession, on a device it picks itself. Every read is within 0.0044 of one matrix's conversion of the codes and at least 0.085 from the other's.

AMD Intel 630 M3
CoreAnimation, x420 and 420v by the tag: BT.709 under ITU_R_709_2, BT.601 under ITU_R_601_4 and untagged the same the same
VideoToolbox, 420v the same as CoreAnimation the same the same
VideoToolbox, x420 by the tag; untagged, BT.709 the same by the tag; untagged, BT.601

With the surface's primaries and transfer function set to ITU_R_709_2 and the renderer's colour space sRGB, CoreAnimation's colour-matched reads still move with the tag, by 0.13 between the two matrices, on all three. (class 3 for a tagged frame: all three convert ITU_R_709_2 by BT.709, as our lane shows the aerial; class 2 for VideoToolbox's untagged x420.) On the lane the guest's own frameworks convert, by the tag our surfaces keep as set, so the lane has no answer of its own to change.

Q14: sampler lodBias and reductionMode

Probe: oracle_sampler DEVICE (11-03). A 256 x 256 RGBA16Float texture of 9 levels, level i holding i everywhere, so a linear-mip sample's R is the LOD the sampler used. It is sampled with lodBias 0, +1, -0.5 and +2.5 at LOD 0, 2 and 3.25, from an explicit level(), a gradient2d() and a fragment shader's implicit LOD. Then a 2 x 2 RGBA16Float texture of 2 levels (level 0 R = [0.1 0.9; 0.3 0.7] and G = [0.8 0.2; 0.6 0.4], level 1 R 0.05 and G 0.95), sampled with each reductionMode under linear min and mag filters. Both properties are new in macOS 26, and the lane's wire 2 does not carry them.

AMD Intel 630 M3
supportsSamplerReductionMode, samplerReductionModeSupport (SPI) 1, 2 1, 2 0, 0
supportsExtendedSamplerLODBiasRange (SPI) 0 0 0
lodBias the LOD used is clamp(LOD + bias, 0, 8), from level(), gradient2d() and a fragment's LOD alike the same no effect; Metal's validation layer accepts it
min and max at the small texture's centre, LOD 0 (0.1, 0.2) and (0.9, 0.8) the same the weighted average, (0.5, 0.5); under the validation layer the sampler's create ends the process: "Use of minimum or maximum reductionMode requires device support"
min and max at LOD 0.5, linear mip filter across both levels: (0.05, 0.2) and (0.9, 0.95) the same the weighted average
min and max with a nearest mip filter reduced within the level read the same the weighted average
at one texel's centre (weight 1) that texel in every mode: texels of weight zero do not count the same the same
a nearest-mip LOD of exactly .5 rounds up up in compute, down in a fragment down
the fraction of a linear-mip LOD of 3.25 3.1875 3.0 in compute, 3.2461 in a fragment 3.25 from level(), 3.2422 otherwise
  • lodBias (class 1; class 3 for an explicit LOD). The header documents the bias "when sampling from a texture". It says only the LOD clamps are ignored for an explicit LOD. Both x86 GPUs add the bias to level() too. The lane applies it to every LOD source.
    • The M3 lacks the feature (metal2vulkan's family table: Apple10 only). A host on an Apple9 GPU cannot carry it, which is a ledger gap.
  • reductionMode (class 1, though both x86 GPUs diverge from the docs). The header says the sampler ignores the mode when the mip filter is nearest or none, or the min or mag filter is nearest. Both x86 GPUs reduce with a nearest mip filter anyway.
    • Decided: the documented rule, kept until a boot shows a guest relying on the x86 GPUs' behaviour. The host passes the mode only where all three filters are linear.
  • The answers (class 4). A yes that samples the weighted average is outside the envelope. So the guest answers the x86 GPUs' 2 and yes only where the host realizes min and max, and the M3's 0 and no elsewhere.
  • The rounding at exactly .5 and the LOD's fraction (class 2). The three GPUs differ, so the host takes its own GPU's.

Wire 2 drops both properties, so the lane samples with Metal's defaults (bias 0, the weighted average). The next wire change carries them in a tail of the sampler's create.

Q15: indirect command buffers after a reset, and after a release

Probe: oracle_icb DEVICE resets and oracle_icb DEVICE freed (11-03).

resets encodes two render commands and two compute commands with a pipeline state, buffers and a draw or dispatch. It resets command 0 with the command's reset and command 1 with the buffer's resetWithRange:, then encodes their buffers and draws again without the state. The compute commands add 5 into an output.

AMD Intel 630 M3
render, after either reset both draw: the state is kept neither draws neither draws
compute, after either reset the command buffer times out neither adds both add 5: the state is kept
  • What a reset keeps of the state (class 2: divergent. The M3 keeps a compute command's state, the Intel 630 drops it and the AMD times out; the AMD alone keeps a render command's. The lane takes the cheapest answer). The lane's Vulkan arm keeps a compute command's state after its reset, as the M3 does. A range reset, one platform call for the range however many commands it spans, leaves every command fresh, as the Intel 630 does. A render command's reset leaves it fresh on both arms.

freed executes commands whose buffers the app released before the execute:

  • a render command's fragment buffer, then also its vertex buffer, then buffers made since at the same size;
  • a heap's buffer, its heap resident;
  • a dispatch's 16-byte input, released before the execute, then behind a spin while the execute waits, and at 1, 8 and 64 MiB;
  • the dispatch's output.
AMD Intel 630 M3
the command buffer completes with no error, every case the same the same
a released 16-byte input the dispatch runs, reading the buffer's last bytes the same the same
a released input of 1 to 64 MiB the dispatch runs, reading zero it runs, reading other bytes it runs, reading zero
a released fragment or vertex buffer nothing draws draws with the last bytes draws with the last bytes
a buffer of the same size made since the command reaches it the same the same
  • No error, and the command runs (class 3). Every case completes, and every dispatch runs and writes its live buffers.
  • What a released buffer reads (class 2). The lane's Metal arm reads what the host's Metal reads. Its Vulkan arm reads zero, the runtime resolving the address to no live buffer, except in an indirect command buffer resident for writing, which runs nothing there yet (below).
  • A buffer made since at the same address (class 2 for the lane). All three Macs reuse the address. The guest's next-fit picks do not reuse a range soon after its release, so the lane's commands do not reach a buffer made soon after.
  • The command a miss skips (class 4). On the Vulkan arm over MoltenVK, a dispatch whose input was released runs nothing, with no error and no notice, where an encoder made its indirect command buffer resident for writing: the runtime then executes the buffer from its records on the host. Made resident for reading alone, the dispatch runs, reading zero there, as it does through a nil buffer at the same index. Skipping the command is no Mac's answer. It is handed to metal2vulkan, whose host replay is to run the command with the slot reading zero; the lane's test of it, a_command_naming_a_released_buffer_reads_zero_in_a_buffer_resident_for_writing, waits ignored until it does.

Q16: the order of IOSurface accesses across queues and processes, and its records

Probe: oracle_order DEVICE xproc|xqueue|xqueue1 raw|war|waw (11-03). A compute pass of about 210 ms on the 5300M (610 ms on the 630, 55 ms on the M3) writes or reads a 1024 x 1024 R32Uint surface S; right after its commit, a blit over S is committed with commitAndWaitUntilSubmitted by another process (xproc), or by another queue of the same process through a texture of its own (xqueue) or the pass's texture (xqueue1). Every other round the pass runs over an unrelated surface instead, as a control. Times are from the blit's commit, over 3 rounds of each of the cases each GPU ran:

AMD Intel 630 M3
commitAndWaitUntilSubmitted returns 0.05 to 0.81 ms 0.57 to 4.61 ms 0.04 to 0.12 ms; 1.7 to 4.7 ms in a run's first round
the blit's scheduled handler 0.07 to 0.83 ms 0.60 to 4.65 ms 0.05 to 0.14 ms; 1.8 to 4.7 ms in the first
status at the return Committed; Scheduled in 2 rounds Committed; Scheduled in 1 round Committed
another process's blit, read or write; another queue's write completes after the pass (207 to 213 ms) after the pass (609 to 760 ms) writes after the pass (52 to 60 ms); another process's read as another queue's (next row)
another queue's read of S after the pass's pending write after the pass in 3 of 6 rounds; at 2.7 to 2.9 ms, reading S before the write, in the others after it in 1 of 3, at 5.2 ms reading S before it in 2 after it in each run's first round only, at 0.7 to 1.7 ms reading S before it in the others, from another process too
the control rounds complete at 0.8 to 2.9 ms at 2.2 to 6.4 ms, or after the pass (the 630 runs other work in turn) at 0.7 to 1.7 ms from another process; at 36 to 56 ms from another queue, after the pass

So a Mac orders such an access on the GPU alone (class 3): the later command buffer is submitted and scheduled within a millisecond of its commit on AMD and the M3 (in 1.7 to 4.7 ms in the M3's first round of a run), and within the 630's usual 1 to 5 ms, whatever it is ordered behind, and then completes after the access it is ordered after. Our stack: the bundle names the order (SURFACE_ORDER, design.md "Surface order"), the host makes the later buffer wait on the GPU, and the wait holds back neither the buffer's CB_SUBMITTED nor its CB_SCHEDULED, which it posts at the buffer's commit, nor those of the buffers committed behind it on its queue (cmdbuf.rs, Line).

A divergence the lane does not use. A read on another queue of the same process (on the M3, of another process too) is not always ordered after a pending write: on all three GPUs some rounds read S before the write, the first round of each run excepted (class 2: how often differs). The probe commits the read right after the write's commit, which returns before Metal submits the write, so a read submitted first on its own queue may simply run first. Writes after a pending access were ordered in every round on all three, and so were reads across processes on the x86 GPUs, not on the M3. The lane orders all three cases on every queue pair: the read's wait is on the GPU and holds back no record, so the order costs the guest no time, and a guest that relies on it sees it kept.

The display's colour against the stock lane: deliberate divergences

Measured on a Linux host, in boots of 11-02: the stock lane's host shot of the desktop beside ours, 20 minutes apart, and each lane's guest capture (screencapture) beside its host shot.

  • The profile. The guest builds each display's ColorSync profile from its EDID. Ours (makeEdid, ReimsGraphics.cpp) sets the base block's "sRGB is the default colour space" bit (byte 0x18, bit 2), and macOS builds an sRGB profile: its tone curve is the sRGB curve (within 1e-5), its colourants and white sRGB's and D65's, whatever the chromaticity bytes say. The stock framebuffer's EDID, made from the host's display descriptor (its default colour space: sRGB's primaries and white 0.312727, 0.329023, each truncated to 10 bits), clears the bit and gives the same gamma byte, 2.2, and macOS builds a profile of gamma 2.2 and those chromaticities. Both profiles' video-card gamma (vcgt) is the identity.
  • The pixels. Both WindowServers render the same sRGB-encoded frame: text in the desktop's widgets matches within 1.5 levels (a mean of 0.3) once the stock host's curve is undone. Stock's display pipe then gives the host a gamma table and a colour matrix that re-encode the frame for its profile's gamma 2.2 (displayPresentFragmentWithGammaTableAndColorMatrix, shaders.metal): about enc2.2(dec_sRGB(v)) a channel, 16 to 23, 32 to 38, 64 to 67, 128 to 127 and 200 to 199. Our display pipe takes no gamma table (request 2 of RgfxDeviceControl answers none), and the host presents our frame as it is: the guest capture and the host shot agree within 2 levels for 98.5% of pixels. On the host, the stock lane's dark tones are lighter than ours, by up to about 7 levels.
  • Decided: the lane keeps its own. Colour management depends on the display, and each lane is consistent with what it declares: ours declares sRGB and shows sRGB pixels, which is right for the usual sRGB monitor showing the host's window without colour management, and stock declares gamma 2.2 and re-encodes for it. Real Macs differ by panel too. Matching stock would take its EDID's colour bytes, a profile change that may move no pixel, or a gamma table and a colour matrix on our display pipe, through the kext, the wire and the host, and would make our pixels less faithful on an sRGB monitor.
  • Y'CbCr images: decided, the lane keeps the tag's matrix. The default aerial wallpaper, a frame tagged ITU_R_709_2, shows by BT.709 on our lane and by BT.601 on the stock lane: that is the shift between the two lanes' guest captures, which the display pipe's gamma does not reach (Q13). CoreAnimation and VideoToolbox convert such a frame by BT.709 on the AMD, the Intel 630 and the M3 (class 3): ours is the Macs' answer, and the stock lane's BT.601 is its own.

Not measured

  • Cross-process lock waits for pending GPU work: rgk-lock's lock_probe (x86 matches the M3, except that a read-write lock does not wait for a buffer that only reads the surface).
  • Page faults: no probe made a GPU address fault, on a Mac whose Intel GPU drives the display.
  • Surfaces whose rows miss the host's alignment.