Files
reims-vgpu/guest/bundle/tools/oracle
Anees Iqbal 818d5099db 🆕 Answer the encoders' and indirect commands' SPI both Macs answer
The rest of the SPI members the AMD 5300M's and the Intel 630's objects both
answer, for the encoders, the command buffer and the indirect command buffers,
each as Metal's base classes answer it (read from code, macOS 27.0.1) and as a
fresh object of both x86 Macs answers it (measured on macOS 26.7.1):

- render, compute, blit and parallel encoders: what Metal's base encoders
  raise an unrecognized selector for raises, the members that end an encoding
  end it and answer no program address table, the GPU's conditionals and loops
  close as none was open, a split handler is never called, the fills raise as
  Metal's IOAccel blit encoder's do, and separate commits, vertex
  amplification modes and kernel debug info are none (the last two logged);
- the command buffer: Metal's own residency sets are used as the caller's;
- indirect command buffers: the resource SPI a buffer answers (complete,
  written, not purgeable, an allocation of its own, the options as asked), and
  no driver header (logged);
- their commands: what Metal's base command raises for raises, the mesh ones
  among them, and the members that read back what a command was given answer
  what a fresh command answers, logged: a command keeps what it was given in
  its buffer's slots or on the host (tools/oracle/oracle_icb.m spi measured
  both Macs' answers fresh, encoded and reset).

No member of Metal's SPI is left pending in the register.
2026-11-08 14:33:55 -08:00
..

The dGPU oracle probes

Small Metal programs of our own that measure what a real Mac GPU does where Metal's documented contract leaves room: when CPU and GPU writes meet, what render passes keep, what the device orders on its own, its timing, its errors and its answers. Run them on an Intel Mac with an AMD discrete GPU and an Intel iGPU (the x86-64 guest's frame of reference), and on an Apple-silicon Mac where it shows the gap. What they found is in docs/graphics-kext/dgpu-oracle.md.

probe answers
oracle_iosurface when a texture over an IOSurface sees CPU writes, and when the surface's pages see GPU writes, with and without IOSurfaceLock, in one process and across two; the cost of each sync
oracle_storage Managed buffers and textures with and without didModifyRange: / synchronizeResource:; Shared textures; linear textures over Shared and Managed buffers, their replaceRegion: and didModifyData among them, and the offsets and pitches each form of a texture over a buffer takes; no-copy Managed buffers; argument encoders writing Shared and Managed argument buffers; Shared buffers written while the GPU runs
oracle_passes what load and store actions (DontCare, Clear) leave in color, depth, stencil and MSAA attachments; memoryless textures, framebuffer fetch, raster order groups and tile pipelines
oracle_cmdbuf the order the device keeps for tracked and untracked resources, fences, barriers and command buffers; scheduled and completed timing, handler threads and order, GPU times (one long buffer's among them), asynchronous pipeline creators; when the CPU sees a shared event's signal from the middle of a buffer
oracle_caps limits, feature answers (public and the SPI getters core reads) and per-pixel-format answers
oracle_errors the errors and refusals for purged resources, oversized creates, oversubscribed memory and a GPU timeout
oracle_source what a runtime source compile makes (newLibraryWithSource:options:error:): the library, its bytes (a .metallib of AIR) and its errors, through the device's public selector, its Metal base class's, and that class's compiler-task form, which reaches Metal's compiler service without the device's compiler
oracle_surftex which textures newTextureWithDescriptor:iosurface:plane: makes over a surface's plane, answers nil for, or ends the process at, by the descriptor's type, size, depth, array length, levels, samples, format, usage, storage and swizzle and the surface's OSType and planes
oracle_texdesc which texture descriptors the device's newTextureWithDescriptor:, a Private heap's and a Shared buffer's newTextureWithDescriptor:offset:bytesPerRow: make, answer nil for, or end the process at, by the descriptor alone: its type, size, depth, array length, levels, samples, format, usage and storage
oracle_nilbind what a command buffer does with nil where an object belongs: a draw or dispatch reading a texture, sampler or buffer bound nil or never bound, a texture written bound nil, a render pass with a nil attachment, a pipeline state set nil, a blit from or to nil and a use of nil
oracle_ycbcr what a two-plane Y'CbCr texture (MTLPixelFormat 500) over plane 0 of a 420v or 420f surface reads, by the surface's kIOSurfaceYCbCrMatrix (709, 601 or none, set by CoreVideo or on the surface), or whether Metal refuses it
oracle_ca_ycbcr which matrix CoreAnimation (a CARenderer drawing the surface as a layer's contents into a texture of the device) and VideoToolbox (VTPixelTransferSession to 32BGRA) convert an x420 or 420v surface by, tagged 709, 601 or untagged
oracle_sampler what a sampler's lodBias and reductionMode do to its samples, by the LOD's source (level(), gradient2d(), a fragment's implicit LOD) and the mip filter, and the device's SPI answers about them
oracle_order when a command buffer that runs after another queue's or another process's pending access to the same IOSurface is answered submitted (commitAndWaitUntilSubmitted), scheduled and completed, and whether the GPU ran it after that access
oracle_names the words Metal gives where a function is made with a constant value of another type, for every MTLDataType (a bfloat constant's among them), and what a binary archive answers for a mesh pipeline added to it, with no mesh function and with one
oracle_mesh what a mesh render pipeline answers for each descriptor shape an app sets (object functions, the maxima, the payload, required sizes, no fragment or no mesh function, functions of another stage, archive misses, indirect command buffer support), what each mesh draw form draws, and the mesh commands of indirect command buffers
oracle_spi_members which members of each Metal protocol and its SPI counterpart (MTLLibrarySPI for MTLLibrary, ...) the device's own objects answer (respondsToSelector:), for each kind of object the guest bundle makes: the verdicts tests/protocol_members.txt gives as %spi-both, %spi-neither and %spi-differ, and the class that answers each; with answers, what a fresh object answers to each getter that does not act (run it once: a getter that asserts ends the process, and is listed in the tool)
oracle_bundle what the device answers where the guest bundle answered otherwise: buffers' allocatedSize (plain, heap and no-copy), event creators with options, binary archives over Metal's and other fat files and a pipeline's hit there, newFunctionWithDescriptor: failing on an archive miss, each function stage's TYPE tag and type, a dynamic library's type and install name, minLOD, bufferClass, heap sizes by allowGPUOptimizedContents, the libraries of a function array or a package, textures' gpuAddress and virtualAddress by storage, shape, heap, buffer, view and IOSurface (texaddr) and what a CPU write at a texture's virtualAddress shows to getBytes: (texmem), what a no-copy buffer over read-only memory, anonymous or a file, does with GPU writes (nocopy.ro) and how many copies a writable no-copy Managed buffer keeps (nocopy.copies), minimumLinearTextureAlignmentForPixelFormat: for one raw value (linalign.N), depth/stencil states in argument buffers and encoders made from a buffer binding or with their reflection, the IOSurface SPI (copyIOSurfaceSharedTextureProperties:, newBufferWithIOSurface:), a shared event's port and coding, and which slices of a binary archive Metal reads
oracle_events a shared event made in one process and used in another: its Mach port (eventPort) and handle, the events made back from either, their coding (keyed and NSXPC), and the value, listeners and waits two holders share, in one process and across two; it runs the same on the guest's device
oracle_reflection the reflection a render, mesh or compute pipeline is made with (reflection: and the completion handlers' argument), by options, over oracle_reflection.metallib: every getter of its bindings, built-in arguments, types and struct members, recursively, and with ORACLE_IVARS set their instance variables, then the reflection classes' members (shared with ../pipeline_reflection_check.mm through oracle_walk.h)

Each probe picks its device by a substring of its name from MTLCopyAllDevices (AMD, Intel, Apple). It never calls MTLCreateSystemDefaultDevice, which switches a dual-GPU MacBook's display to its discrete GPU. A case that may end the process (Metal's validation asserts on some creates) runs in a child process of its own, and the line says how it died. The header of each .m lists its cases and the meaning of every column.

Build

On a Mac with Xcode's toolchain, never on the oracle:

guest/bundle/tools/oracle/build.sh /tmp/rgk-oracle/x86 x86_64   # for an Intel Mac
guest/bundle/tools/oracle/build.sh /tmp/rgk-oracle/arm arm64     # for an Apple-silicon Mac

Each probe that runs shaders loads oracle.metallib from its own directory, so copy it along.

Run

On the oracle (ssh macbook-pro-2019), from ~/oracle/bin/rgk-oracle, holding the shared GPU lock and keeping the machine awake:

/usr/bin/lockf -k ~/oracle/gpu.lock caffeinate -s ./oracle_iosurface AMD single
/usr/bin/lockf -k ~/oracle/gpu.lock caffeinate -s ./oracle_iosurface Intel timing 3840 2400
/usr/bin/lockf -k ~/oracle/gpu.lock caffeinate -s ./oracle_storage AMD

On an Apple-silicon Mac of this repository, hold the GPU lock: scripts/internal/gpu-locks.sh -- /tmp/rgk-oracle/arm/oracle_passes Apple.

oracle_iosurface also takes a script of its own steps in place of a scenario name (the steps are listed in its header). oracle_errors DEVICE timeout SECONDS runs one long kernel to meet the GPU's watchdog (about 16 s on the Intel 630, 20 s on the 5300M): run it only on a GPU that does not drive a display. The other kernels stay near a second.