A guest's samplers lost lodBias and reductionMode (macOS 26) on the way to
the host: SAMPLER_CREATE's extension, RgfxSamplerCreateExt, was on the wire,
but the bundle never sent it and new_sampler never read it, so every sampler
was made at bias 0 with weighted-average reduction. The guest's state cache
already keyed on both, so two descriptors that differed only there were two
guest samplers of one host shape.
The bundle now sends the extension with every create, on the posted and the
asked route. new_sampler sets the platform's reduction mode and its new LOD
bias from it, and leaves both unset for a create without one, which keeps
Metal's defaults. What the guest sees changes: a sampler of minimum or
maximum reduction samples that way, as Metal's does. The runtime's sampler
descriptor holds no bias yet, so a non-zero bias still samples at 0, and is
now relayed as inexact-sampler-lod-bias, with an accuracy-ledger row, until
the runtime takes one.
The header follows wire.rs's doc, the ROM's record that header (its bytes
are unchanged), and both guest sets are built again from these sources.
Since 18b642dab the guest's Metal device answered iosurfaceTextureAlignmentBytes
and iosurfaceReadOnlyTextureAlignmentBytes from the host's runtime, 128 on an
NVIDIA GPU and 256 on RADV, so that CoreAnimation would round its backing
stores' rows to what the host takes in place. CoreAnimation also refuses a
Metal texture of any surface whose rows or planes are not at a multiple of
that answer, and the surfaces other code makes keep their own rows. In macOS
26.7.2 guests on an RTX 3090 and an RTX 2080, WindowServer logged "Failed to
allocate MTLTexture from IOSurface ... Row bytes (5312) not 128 aligned" for
rows of 192 to 14272 bytes, and Safari drew pages blank and WebGL black on
every load (appwalk2 walks m3-max-16925, -17008). On a Radeon 780M, at 256, it
found Safari's 1080p and 2160p video frames without the proper alignment.
What the guest observes: the device answers 16 for both again, as Metal's
devices and the IOGPU base do, whatever the host's GPU answers. On RADV the
backing stores' rows go back to 64-byte multiples, so the runtime shadows
those 18b642dab moved in place (1399 textures over a cold boot and a Safari
scroll of macOS 11.7.11 on a 780M).
test_iosurface_alignments_divide_other_codes_surface_rows holds the answer to
the rows WindowServer refused; the member register lists both as Metal's. The
trap is in docs/lessons.md.
A no-copy Managed buffer over writable app pages was one copy on every host:
the bundle sent its BUFFER_OVER_PAGES with Shared storage, and its
didModifyRange: and a blit's synchronize of it, or of a texture over it, sent
nothing (e828db91b). Apple's OpenCL makes each default cl_mem such a buffer and
binds it to every kernel, so on a host GPU with memory of its own the kernels
read and wrote it across the bus in system memory. CL makes the calls Metal
requires of a Managed buffer: synchronizeResource: before a map, and
didModifyRange: after a map for writing (measured with cl_bw on a macOS 26.6.1
guest on the RTX 5080 host).
The buffer is now a Managed buffer over a Shared one, as the pages slabs'
large Managed buffers are: the BUFFER_OVER_PAGES buffer, still Shared, is its
CPU copy, and a MANAGED_BUFFER_CREATE over it, at an address of its own that
keeps the pointer's offset in its page, is the buffer the app gets. At its
release the Managed buffer goes first, then its CPU copy, then the pages
block. A device that makes no Managed buffer over a Shared one gives such
memory the shadow, as read-only memory has.
What the guest sees: the host's object for the buffer has storageMode Managed,
and the buffer's didModifyRange:, a replaceRegion: of a texture over it, and a
blit's synchronizeResource: or synchronizeTexture: of it or of such a texture
now reach the host. On a host GPU of its own memory the buffer is two copies,
as the AMD 5300M's is: the GPU sees a CPU write only after a didModifyRange:,
and the CPU a GPU write only after a synchronize. On a GPU that shares the
CPU's memory it stays one copy, as the Intel 630's is.
The shell tests that held one copy now hold the two messages, the ranges and
synchronizes sent, the release order, and the shadow where the device makes
no Managed buffer over a Shared one; the serializer tests hold the Managed
create's offset.
Each no-copy buffer over the app's own pages took a pages block of its own, so
two buffers over the same bytes had two host views of the same pages, and where
the views' gate refuses their import (a buffer of scattered guest pages at the
stock vm.max_map_count on NVIDIA), the runtime made a copy and a snapshot for
each. Apple's OpenCL makes such buffers: a Shared no-copy buffer over its
staging pages at each clEnqueueWriteBuffer, the same pages each time, while the
one before still lives. On the RTX 5080 host, each 256 MiB of them cost QEMU
512 MiB more Rss per write.
The region now gives a block asked for the same bytes, writability and join
again while it is joinable, so such buffers lie in one view and one copy, as on
a Mac they lie in the same pages. A block stays joinable until each buffer over
it has gone for the app, so a block is never joined over memory the app freed
and took again at the same address, and it goes back to the kext once the host
has dropped every buffer over it. A buffer of Metal's private bit 24, which the
host's runtime takes as read-only memory, joins only its own kind. Nothing
changes for the guest: each buffer keeps its object, GPU address and contents.
Tests: the region's joins and their release order, two no-copy buffers over
one block in the bundle, and the host's one view under two buffers.
The guest's Metal device left iosurfaceTextureAlignmentBytes and
iosurfaceReadOnlyTextureAlignmentBytes to the IOGPU base, which answers 16 from
its own state, so the host's answer in the device info never reached the guest.
CoreAnimation rounds the rows of its backing stores' IOSurfaces to
iosurfaceTextureAlignmentBytes (to no less than 64 bytes) and names them to
IOSurface, which keeps them. On RADV, which takes a linear image in place only
at rows a multiple of 256 bytes, those 64- and 128-byte rows are the runtime's
shadows. In a macOS 11.7.11 guest on a Radeon 780M, 1399 textures were shadows
for their pitch over a cold boot and a 15 s Safari scroll, and 11 with the
device answering 512.
The device now answers both from the device info, which carries the Vulkan
platform's answers. What the guest observes: since pin 37 the runtime answers
the device's linear row alignment there, so on RADV (GFX9 to 11) the guest
now sees 256 where it saw the base's 16, and CoreAnimation's backing stores
take rows the host's GPU takes in place; on other GPUs it sees that GPU's
linear row alignment. The device-info doc said an IOSurface's rows follow
none of the device's answers; it now says which answers they follow.
On macOS 12, Safari's web content process may call only the external
methods its sandbox lists on an IOAccelerator connection: 0-13, 15-18,
22-24, 28-31, 40, 42, 48, 256-265, 267, 268 and 512 in every Safari from
15.1 to 17.6. Its sandbox refused Features (0x10f) before the kext saw it,
and the bundle went on without the kext's features: it took 64-id chunks
where the kext granted 16, and the host refused the textures past each
chunk's first 16 ids (BadResourceId), so pages drew without their body and
text. Under Safari 15 and 16, SurfaceBlockRelease (0x10a) and
SurfaceRetire (0x10d) were refused too. macOS 11, and 13 and later, list
no numbers.
What the guest sees:
- New selector numbers, selector map 1: Features 3, PagesBlock 4,
TakeAnswers 7, SurfaceBlockRelease 8, SurfaceRetire 9, and a shared
event port's Export 10 and Import 11. 1, 5 and 6 stay reserved, 2 is
given to none, and the rest keep their numbers. No number of map 0
takes a new meaning, so a bundle or kext of map 0 is refused, not
misrouted.
- Features answers a third word, the selector map, and keeps its number
in every map. A bundle that meets another map has no Metal device.
- ResourceIds answers the chunk's size after its first id, and the bundle
takes its chunks at that size.
- Where the bundle's setup left a stubbed device (no features, the device
info unread or of another version, the context or the user client not
opened) or returned silently (the IOGPU base declined), the process has
no Metal device, with a log line that says why. A host's video caps of
another version still leave the device without video codecs, now
logged.
user_client_words_test holds the sandbox's set, checks every selector and
the kext's routing against it, and checks that every IOConnectCall*Method
in the bundle's sources names one of them. design.md's registry gives map
1 and what map 0 was. The kext set is built again.
What changes for the guest: the device's featureProfile is 10002 where it was
the host's, 10 on every host so far, wherever the guest's Metal has the
MTLArchitecture class (macOS 13 and later), on every host. Where it lacks the
class (macOS 11 and 12) the device still answers 10001. Both x86 Macs of the
oracle answer 10002 under macOS 26.7.1 (the Radeon Pro 5300M and the UHD 630),
and the guest's Metal keys its limits, families and feature queries on the
profile. 10 was the M3 Max's, kept only because macOS 26's WindowServer, under
10002, asks for tiled textures of 6 and 7 levels over a buffer, which the
device answered nil; the host makes those now (the two commits before), and
26.7.2 composes its desktop under 10002 with them.
The answer is made in one place, RgfxFeatureProfile.hpp, which no longer takes
the host's profile: the bundle stops reading it from the device info, whose
field the host still fills with its Metal device's or the M3 Max's.
The profile's unit test, which held the host's answer from macOS 13 on, holds
10002 there and 10001 below; the guest's kext set is built again with it.
macOS 12's Metal keys every limit of a device on its feature profile and has
none for the M3 Max's 10, which the device answered on every guest: it left
the limits 0 and ended WindowServer at device creation, so 12.x guests never
reached a desktop (launchd gave up after 14 runs).
The device now answers the host's profile only where the guest's Metal knows
it, told by what that Metal has: the MTLArchitecture class, which macOS 13
and later have (13.7.8, 14.8.9 and 26.7.2 boot with 10). Elsewhere (macOS 11
and 12) it answers 10001, as 12's drivers for the 5300M and the UHD 630 do.
26 keeps 10 rather than the x86 Macs' 10002: under 10002 its WindowServer
still asks for a mipmapped tiled texture over a buffer, which the device
refuses (dgpu-oracle.md, Q11, rechecked).
What changes for the guest: featureProfile on macOS 11 and 12 is 10001; on
13 to 26 it is unchanged.
The crate that holds the reims-graphics device's wire and transport now
carries the library's prefix, as reims-vgpu-video does: its directory is
crates/reims-vgpu-graphics, its package reims-vgpu-graphics, and its Rust
path and log target reims_vgpu_graphics. The guest's, the option ROM's and
Ambrosia's Makefiles include the wire header from the new directory, and the
prebuilt records name it there.
Nothing changes for the guest or the host. The device keeps its name
(reims-graphics, QEMU's reims-graphics-pci, PCI 1234:5247), and the wire
header keeps its file name and RGFX_ symbols. The C API header is unchanged,
and the prebuilt kexts and option ROM are byte-identical; only the records'
paths and source hashes move. A log filter names the crate's lines by its
new target (REIMS_VGPU_LOG=info,reims_vgpu_graphics=trace), a diagnostic.
The device answered the IOGPU base's vendorName, "Apple", beside the Mac2
family alone, a pair no Mac has. The system's GL renderer
(AppleMetalOpenGLRenderer) picks its settings by finding "AMD" or "ATI",
"NVIDIA" or "Intel" in the vendor name, else by the Apple GPU families 7 and
5 (read from its code). On any other device it ends every process that makes
a GL context ("Unknown GPU!!", measured: macOS 26.6.1, RTX 5080 host).
The answer is now the vendor the device name's first word names, in the
words the Macs answer: "NVIDIA", "AMD" (the AMD 5300M's) or "Intel(R)" (the
Intel 630's, measured: macOS 26.7.1). A name of any other vendor answers
"AMD", the x86 Macs' discrete GPUs' vendor, since the renderer knows no
other. The Macs diverge here (class 2); the register says so.
RgfxEncoder zeroed the field the decode ops used to keep reserved, which
is output_rows now: the rows the output surface holds go to the host as
the video driver set them. The serializer test checks they arrive.
shell_tests' check count changed between runs of one tree (262756 to
296306) because of test_commit_order_names_no_cycle. Its two threads often
ran one after the other, so no post named the other queue, and its cycle
check checked nothing (40002 checks in a run, against 72352 in another,
m3-max-5134). The threads now start together, and a run where either queue
names nothing runs again, up to 50 times, before the test fails.
The check counter is atomic: CHECK runs on the test's threads, and the
plain int could lose counts there.
Reverts 0825b1ea2, restoring 0afc30f37, e8d04b187 and ea13ccbca. A write-combined
mapping of the region does take: the region's descriptor is physically
contiguous, and xnu's fault path maps such an object's pages in its own cache
mode (vm_fault's pmap_map_block_addr, read from the public xnu source), which
the earlier reading missed. The page-table probe that seemed to agree saw only
the processes on the CPUs at its instant, not the bench.
Measured on the Radeon 780M host, draws.10k's encode: 9.2-9.5 ms at the base,
7.7 ms with the slabs in the process's own pages alone (936e3968d's set), and
1.05-1.3 ms with the spans write-combined as well (0afc30f37's and ea13ccbca's
sets). The kext's comment and the design doc say why, and docs/lessons.md the
probe's trap.
For the guest, as 0afc30f37: a queue's submission ring starts 3840 bytes into
its block, the kext's Alloc takes a third input and its feature word holds
1 << 7.
Reverts 0afc30f37, e8d04b187 and ea13ccbca. On x86-64 xnu every mapping of
the region in a guest process is uncached, whatever cache mode the kext asks:
vm_fault enters each page with no cache flags, and the pmap gives a page it
does not manage PCD alone, the guest PAT's UC- (read from the public xnu
source: pmap_get_cache_attributes and vm_fault's pmap_enter wrappers). Measured
on the Radeon 780M host with both the region's own descriptor and one of the
write-combined spans' own: every page of a process's over BAR 2 was PCD alone,
none PAT and PCD, and draws.10k encoded as fast as with the spans write-back.
For the guest, a queue's submission ring starts its block again, the kext's
Alloc takes two inputs and its feature word drops 1 << 7; the slabs in the
process's own pages (72c09eddc) carry the measured gains. The design doc says
why the region is uncached, as measured.
The guest's kernel maps the device region uncached whatever the kext asks:
xnu's pmap sets PCD on every page it does not manage, and the region is no RAM
of the guest's. An AMD host applies the guest's memory type (Intel's EPT
ignores it), so on the Radeon 780M host the guest's stores there ran at
13 MB/s and draws.10k spent 9.1 ms encoding against 0.5 ms on the RTX 5080.
The kext's Alloc now takes a third input, the byte from which the process's
mapping of the block is write-combined (kIOMapWriteCombineCache, PAT index 6),
behind a kext feature bit. The bundle puts there what it only writes: a
submission ring's data, which now starts its block's second page with the
ring's header ending the first, write-back as before, since the host writes
it too and the writer reads it; command buffers' bodies; and a library's
staging chunks, past the page of acks it reads. The ring writer fences its
stores (sfence) before it publishes a message, so write-combined stores reach
the host before the producer index that names them, as a release store
orders write-back ones. ICB slots stay write-back: their setters read fields
back and OR bits in with locked operations, which write-combined memory does
not keep atomic.
For the guest, a queue's submission ring now starts 3840 bytes into its block
where the kext has the feature; the wire is unchanged.
The GL renderer makes its no-copy buffers with resource option bit 20
(0x100000), a hint for the device's driver. The bundle passed every bit
to the host, and the host's runtime refuses a buffer with a bit Metal
gives no meaning, so each such buffer was refused (measured: macOS 26.6.1
on the RTX 5080 host).
Heap and buffer creates now carry only the CPU cache, storage and hazard
tracking modes, and Metal's private bit 24, which the host takes as Metal
does.
A buffer outside a heap now answers resourceOptions with its three modes
alone. On macOS 26.7.1 the AMD 5300M and the Intel 630 drop each of bits
10 to 31 from the answer, for length and no-copy buffers alike: they give
0x200, 0x210 and 0x220 for Shared, Managed and Private.
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.
For the guest: where the device takes MESH_PIPELINES, every
newRenderPipelineStateWithMeshDescriptor: form makes a mesh render pipeline. It
used to answer nil and an unsupported error. The render encoders send the object
and mesh stages' bindings and drawMeshThreadgroups:, drawMeshThreads: and the
indirect form, and the SPI's supportsMeshShaders answers YES. Without the
feature they answer as before. The state answers its object and mesh limits as
the host's platform answers them (maxTotalThreadgroupsPerMeshGrid NSUIntegerMax
past 32 bits) and the threadgroup sizes its descriptor required.
Measured with guest/bundle/tools/oracle/oracle_mesh, plain Metal, on the AMD
Radeon Pro 5300M and the Intel UHD Graphics 630 (macOS 26.7.1, 25G241) and the
M3 Max (macOS 27.0.1, 26A434), the creators now end the process where the x86
Macs' Metal does, with their words:
- supportIndirectCommandBuffers YES, on the 5300M and the 630 (the M3 Max makes
it): "validateWithDevice:1884: failed assertion `Mesh Render Pipeline
Descriptor Validation\nUse of mesh shader pipelines in indirect command
buffers is not supported by this device.\n'"
- no mesh function, on all three: "...\nmeshFunction must not be nil.\n'"
- no fragment function while rasterizing, on all three: "...\nfragmentFunction
must not be nil.\n'"
So no mesh pipeline supports indirect command buffers, and indirect commands
carry no mesh draw. This matches the families: supportsFamily: answers no for
Apple7 to Apple9 on the x86 Macs and on the device, and the SPI's
supportsMeshShadersInICB answers NO on the x86 Macs and the device (YES on the
M3 Max).
They refuse before the host is asked, in the x86 Macs' compiler's domain
(CompilerError):
- a payload past 16384 bytes, code 2, "payloadMemoryLength property of
MTLMeshRenderPipelineDescriptor (16385 bytes) exceeds maximum supported by
this device (16384 bytes)";
- a stage maximum past the device's 1024 threads, code 2, the 5300M's
"maxThreadsPerThreadgroup pipeline descriptor value (2048) exceeds maximum
supported (1024)\n" (the 630 makes it, the M3 Max refuses it);
- a vertex function as the mesh function, code 2, "RasterizationEnabled is
false but the vertex shader's return type is not void";
- any other function of another stage, code 1. The x86 Macs answer the
crashed compiler's XPC words; ours are the validation layer's;
- a mesh function as the object function, code 1, which the x86 Macs make
and the M3 Max refuses;
- an archive miss under MTLPipelineOptionFailOnBinaryArchiveMiss, code 2,
"Unable to find function \"f_col\" in binary archives. \n ". It names the
fragment function, else the mesh function. An x86 archive holds no mesh
pipeline, so every create naming an archive misses.
The creators with a reflection answer RgfxMeshPipelineReflectionOf's, the
reflection of the pipeline's functions, as the render pipeline creators answer
theirs.
Both x86 Macs read a binary archive's slice bytes only where the file holds the
device's own slice (its CPU type and subtype): then that slice and the AIR
slice are read, and either one junked is "an invalid format"; a file whose
slices are none of the device's is an archive of no keys, junk or not (AMD
5300M and Intel 630, macOS 26.7.1: oracle_bundle archive.slices, 21 files of
recombined and junked slices). No Metal slice is the device's, whose archives
are its own format, so the bundle, which never reads a Metal archive's slices,
already answers so; a junk AIR slice beside another GPU's slice now has a test.
The kext hands out chunks of 16 texture resource ids where it takes
SMALL_ID_CHUNKS (bit 23). The bundle now keeps its ids by small chunk, each
small chunk's free ids in a 16-bit mask, and takes each chunk from the kext
as the size its feature word says: 16 ids with bit 23, else 64, a chunk of 64
being four small chunks. A chunk not aligned to its size, past the pool, or
over a small chunk the process holds is no chunk.
Until the kext takes bit 23 its chunks are 64 ids, and the bundle takes and
hands out ids as before.
A guest app that makes a binary archive from a .metallib's URL now gets an
archive, holding none of the device's compiles, where the bundle answered nil
and "has an invalid format". Both x86 Macs' Metal makes one (AMD 5300M and
Intel 630, macOS 26.7.1; oracle_bundle archive.metallib). Bytes of the magic
MTLB whose header states another file size stay no archive, as the bundle reads
a fat file cut short.
The guest's IconRendering opens its binary.metallib, a fat file of magic
0xcafebabe and 18 slices of other GPUs, as a binary archive. The bundle read
only its own format and Metal's 0xcbfebabe, so it answered nil and "has an
invalid format". Metal reads the fat files of 0xcafebabe alike: on the AMD
5300M and Intel 630 under macOS 26.7.1 (oracle_bundle archive.*), that file
and an archive the device wrote with its magic changed each make an archive of
no keys with no error, and a file of no slices is an invalid format.
What the guest sees now: such a file makes an archive with no keys, which
misses every lookup, as another GPU's archive does.
A function made with a constant value of another type fails with Metal's
words, which name both types. The bundle named only the constant types (the
scalars and vectors) and printed any other value, a matrix, a texture or a
pipeline among them, as MTLDataType(N). Metal names every value of the enum
"MTLDataType" and its name in MTLDataType.h (measured with oracle_names on the
AMD Radeon Pro 5300M and the Intel UHD Graphics 630, macOS 26.7.1, each of the
95 values set for an int constant).
What the guest sees: the error's description names a value of a type no
function constant takes as Metal does ("... has type MTLDataTypeFloat4x4").
A value outside the enum still prints as MTLDataType(N).
The region gives an app about 440 MiB of slabs, past which its buffers'
creates fail. Where the host makes heaps over pages blocks (HEAP_OVER_PAGES)
and the kext wires them (PagesBlock), a heaped class's 2 MiB slab is now a
superpage of the process's own, one run of guest RAM, wired into a pages
block and made one HEAP_OVER_PAGES, its buffers placed in it as in a region
slab's heap: BUFFER_AT_OFFSET, and BUFFER_MANAGED_AT_OFFSET where the device
took MANAGED_AT_OFFSET. On the RTX 5080 such a heap takes 13.4 us and a
placed 4 KiB buffer 1.93 us, where a no-copy buffer over the block's view
took 65-75 us. A larger dedicated slab, which would be more than one run,
and a slab where the kernel has no superpage to give or the kext no pages
block, stay the region's. RgfxSlabs asks the first source before the
region's for each new slab, and a slab keeps the source it came from.
A process's first library over 8 KiB took a staging window of 64 MiB and kept
it for the process's life. On a busy desktop on the RTX 5080 host, nine
processes held 576 of the 731 MiB of the region outside WindowServer's
reserve that way (mediaanalysisd held nothing else), so the region ran out at
41 processes. From there, libraries, buffers and queue rings came back nil,
and Games, Photos, Photo Booth, Maps, the Dock's extras, NotificationCenter
and WebKit's GPU process crashed.
The window is now made for one stream and sized to its library: as few
chunks of at most 32 MiB as hold it, split evenly in whole pages, and a
second block only where there are two or more chunks. It goes back to the
region once the host has acked every chunk. Where the region refuses it,
smaller chunks are asked for, down to a page, so a library is made while any
room for three pages is left. A window whose chunk the host never acks is
kept, so nothing the host may still read is given out again.
The stream moves to RgfxLibraryStream.cpp, so the serialiser check covers it
against a host of its own: the shapes, the fallbacks and their bytes and
order, the window given back, and one kept when an ack never comes.
fillRenderPass carried no visibilityResultBuffer, so the host met each
setVisibilityResultMode:offset: of a mode in a pass with no buffer and failed
the command buffer. A render and a parallel render pass whose descriptor holds
one of our buffers now send it after their colour records and sample positions,
with the descriptor's visibilityResultType where its class answers it (macOS
26). The buffer is noted as the command buffer's write, as an attachment is,
so a copy of app memory or of an IOSurface under it takes the GPU's results
back and the buffer is kept to the completion.
The bundle's half of PagesBlock's plumbing, which no-copy buffers and
fix-shared-mem's guest-RAM slabs both build on, as its own commit.
RgfxRegion gains a pages block source: acquirePages asks it for the block of
the runs of the pages under an address range, which the kext wires for the
block's life. The block's pointer is null, since the process never maps a
pages block, and a block the region does not hold goes back through the
block source's release, as a surface block does. The device sets the source
to the kext's PagesBlock call (0x10e) only where the kext's own word holds
PagesBlock and the device's word holds PAGES_BUFFERS.
RgfxSerializer::createBufferOverPages posts BUFFER_OVER_PAGES. It picks the
GPU address and owns it as createBufferOverHostMemory does; the pick holds
the span from the page the buffer starts in, and the buffer's address keeps
its pointer's offset in that page, as Metal's no-copy buffer keeps its
pointer's. The answer's gpu_address is the pick, which releaseAddress gives
back; with an offset of 0 it is the buffer's address too.
The kext gave each process a context in one of 32 slots of 2 TiB, and refused
the 33rd: on the RTX 5080 host 17 processes held one on an idle desktop, and
opening the system's apps refused Freeform, the 13th, and every app after it
(57 processes, 25 refused). A refused process got a device whose every create
answered nil, and Maps and Journal aborted in VectorKit, Photos asserted and
Games faulted at their first objects. No Mac caps Metal processes like that.
The guest's [2^46, 2^47) is now 1024 units of 64 GiB, which the kext hands out
from a bitmap (RgfxContextSlots.hpp, with its native test) as aligned runs: one
unit a context, or the least power of two holding twice the device's
maxBufferLength where that is more than 32 GiB, so a buffer of maxBufferLength
always fits. Runs go round-robin, and the last 32 units free are WindowServer's
alone, as the blocks' and queues' reserves are.
OpenContext answers the span sixth under the kext feature bit ContextSpan
(1 << 5), and the bundle picks through it. A bundle that asks for five values
gets an aligned 2 TiB run, the span it picks through, so an old bundle keeps
working on a new kext, and a new bundle on an old kext takes its 2 TiB slot.
The host knows no slot: it pins each address as given, so it is unchanged, and
needs no device feature bit. Its test now pins at every unit's first address.
Past the last run the bundle answers no device in that process (init answers
nil), the answer every Metal client handles, in place of a device whose
creates answer nil.
A queue's ring writer logs its sleeps for room at the first sleep and then at
most once a second, so a process that slept for room for under a second after
that first line showed only the first sleep: in a ring-filling boot each
ringfill run's line read "1 sleeps" while the host posted about 2200 room
records in the same run, and how many more posts slept went unseen.
The writer now logs the counts once more as it goes (its queue's release) where
its posts slept since the last line.
A boot can now show how the commits that found a queue's submission ring
full waited: a line for each ring at its first sleep for room and then at
most every second, with the sleeps, how many a SUBMIT_ROOM record ended,
and their time in all and at most. Without SUBMIT_ROOM every sleep is the
backoff's; with it, the records end them. RgfxRingRoomSleeps counts and
paces the line, and the serializer tests pin both.
A commit that finds its queue's submission ring full rang the doorbell and slept
20 us, doubling to 1 ms, between looks, so its post went on up to the last
step after the host took room, and a stream of commits through a full ring ran
at the sleep's cadence.
Where the device's word holds SUBMIT_ROOM, a new queue's ring writer and its
completion reader share a room signal (RgfxRingRoomEvents). A post that finds
no room stores 1 in the ring's producer_waiting, fences and looks once more,
then waits on the signal, which the reader raises as it reads the host's
RGFX_EVT_SUBMIT_ROOM, with a 20 ms backstop; where no completion thread drives
the reader, the wait keeps the sleep's step, as the waiter's own pump takes the
record. Without the bit nothing changes. The signal is shared, so a record read
as its queue goes finds it alive.
serializer_tests' test_ring_post_waits_for_the_room_record pins it: the full
ring's post sets the flag, room taken with no record leaves it waiting, the
record ends the wait, and a reader hands its ring's record to the signal.
The kext destroys behind an ICB_CREATE it stopped waiting for, and the host
makes that ICB off the control thread. Were that destroy carried out out of
ring order, it could remove a later object under the same id.
The bundle gives each object id once in a context: ids only grow, a destroy
frees none, and only a new context's bases start them again. So within a
process no later object can take the id. A later context under a number given
again can, and the host test pins what then happens: the destroy waits for
the ICB's create, the ICB is made and destroyed, and the buffer created after
under the same id is made last and kept. Both tests fail with the destroy's
wait taken out.
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.
The video driver now offers AppleGVA HEVC decode where the host's video
caps list it: Main into NV12 ('420v', '420f') and Main 10 into P010
('x420', 'xf20'), in the profiles the host lists. Each picture goes to the
host as H.264's do, its slice segments copied out of AppleGVA's bitstream
buffer and the SPS and PPS written from AppleGVA's parsed form where they
changed (RgfxVideoH265.cpp, sharing the bit writer with H.264).
An HEVC decode command carries no output surface and no transfer command,
unlike H.264's: AppleGVA names the output frame in its decoded-picture
record, whose frame holds the surface's global IOSurface id, and the driver
looks it up there. AppleGVA holds each short-term set of the SPS by its
pictures, a predicted set's already derived, and the writer writes every set
by them. Both measured on the guest with the RTX 5080; the sets' layout
against hevc-main-720p-sets-sps, whose 25 sets AppleGVA held as 7-61 and
7-62 derive them, and whose SPS written from AppleGVA's struct decodes as
the stream's own.
A library loaded again re-read its whole function list each time, and one
from a URL re-hashed its bytes too: MPSImage's metallib (1,837 functions)
cost 4.4 to 5.1 ms on every newLibraryWithURL:, against 0.01 to 0.04 ms for
native Metal's repeat (scout-pipelines-05, measured on msi and the oracles).
Libraries of one content key now share one function table, read the first
time the process makes one. The key covers the function list, so bytes of
one key have one table. A URL load keys the file by its identity: device,
inode, size, and modification and status-change times to the nanosecond,
taken before and after the read. A load of an identity the process keyed
before takes that key without hashing. A rewritten file changes the identity
and is keyed again. The LIBRARY_LOOKUP round trip stays.
The bundle asks Features for both words now and keeps the kext's in
RgfxCaps::kextFeatures, with a copy of the kRgfxKextFeature* bits beside the
selectors it mirrors. A kext older than the call, or any failure, leaves the
device info's bits 0-2 and no kext feature. The probe test covers both words,
and its comment sits with it again rather than above the layout asserts.
The device now asks the kext's Features selector for the word it works by
and keeps it in RgfxCaps. A kext older than the call answers
kIOReturnUnsupported; on that, or any failure, the word is the device info's
features_lo bits 0-2, which is what the bundle used before. The queue's
asksSubmitted reads the word.
serializer_tests checks the fallback and the word, and asserts the
negotiation's wire layout as the bundle compiles it.
Every heapTextureSizeAndAlignWithDescriptor: and every texture placed in a heap
waited for a HEAP_TEXTURE_SIZE_AND_ALIGN round trip: 12 us a query and 19.3 us
a placed 1024 texture on the msi 5080, where the M3, the AMD 5300M and the
Intel 630 answer in 0.5-0.9 us (scout-resources RES-06, measured).
The host's device answers a shape alike every time (it asks its own Metal or
metal2vulkan, which do; the oracle's AMD and Intel answer a repeat equally,
measured), so the serializer keeps each answered shape's size and alignment,
by the wire descriptor's bytes, and asks only a shape it has not seen. A refusal
or no answer is not kept, and is asked again. Up to 4096 shapes are kept.
The IOGPU base answered the MTLDeviceSPI familyName "", which no Mac's
device answers. Each Mac answers its device name without the vendor and
the model number (measured: "M3 Max" for Apple M3 Max, "Radeon Pro" for
AMD Radeon Pro 5300M, "UHD Graphics" for Intel(R) UHD Graphics 630). The
Macs diverge, so the answer is the lane's choice inside what they give:
the same rule over the name the device already answers, "GeForce RTX" for
an RTX 5080. A serializer test runs the three Macs' names and the hosts'.
targetDeviceArchitecture stays the base's nil: each Mac answers its GPU
compiler's target, an instruction set the host cannot run, and nil names
none. The register records both as class 2 with the measured values.
The IOGPU base answers each supports* query of MTLDeviceSPI from the IOGPU
device info, which the kext gives all zero, so the device answered NO to
84 queries the M3 Max, the AMD 5300M and the Intel UHD 630 all answer YES
(measured with tools/base_answers_probe.m, aud-tests-04), contradicting
its own public answers: tessellation, argument buffers, heaps, binary
archives, 64-bit integers, SIMD-group functions and more. A framework that
asks the SPI before using a feature took the path for a device without it.
The device now answers 44 of them itself, each only where the lane
carries the feature out and from the host's answers: what the wire
carries, on a host of the Mac2 family; the Metal Shading Language's
features, on the same; four from the host's own flags; and read-write
texture arguments from its tier. RgfxCaps::spiFeature holds the decision
and a serializer test checks it against hosts with and without each
answer. The other 40 keep the base's NO: 18 name features the lane does
not carry (mesh shading, ray tracing, indirect command buffers, counters,
dynamic and pipeline libraries, shared textures), and 22 gate what is not
established; the register says which for each.
aud-bundle-07. A command buffer too large for half its ring was built in a
std::vector that re-grew about five times for a 10k-draw buffer (625 KiB).
The queue's reserve was capped at the ring's size, so the next large buffer
started small again. At commit the whole message was copied into a region
block, and the SURFACE_USE ops were inserted at its front with a memmove.
The message is now written where it is posted from:
- on the builder's heap, at most half the ring, while it fits the ring;
- once it outgrows the ring, moved once (at most 16 KiB copied) into a block
of the queue's body pool. The block is as large as the queue's recent
largest message, which rgfxMessageReserve no longer caps at the ring, and
it doubles from block to block after that.
The header and the commit's SURFACE_USE ops go into room kept before the
ops. finish() posts COMMAND_BUFFER_IN_REGION straight from the block and
hands the block to the command buffer before the post, since the completion may
come before finish() returns. The buffer gives the block back at completion,
or as it goes uncompleted, as before. RgfxBodyPool implements the encoder's
RgfxMessageBlocks, and its giveBack ignores an empty block: one a buffer
whose message found no block holds.
Design (Decided 3): encoders streaming as they end needs a command buffer in
several messages, which the wire does not have. That proposal went to
wire-v3 (~/.cache/rgk-audit/r1/fix-bundle-encode-streaming.md). design.md
now says what the bundle does today.
Wire bytes: COMMAND_BUFFER_IN_REGION's region_offset is now the block's
offset plus the room before the header, not the block's start. The format
is unchanged and still 8-aligned. The message's bytes are the same.
Measured natively on the M3 Max, headless (aud-bundle's audit bench), tree
before -> this, warm runs:
commit of a 10k-draw buffer (setVertexBytes + draw) 9.1-12 -> 0.2 us
the next large buffer's starting room 32 KiB -> 625 KiB
setVertexBytes + draw ~15 ns, unchanged
a command buffer's fixed cost 1.25 us, unchanged
A queue's first large buffer has no guess yet, so it grows from block to
block where realloc might have grown in place. On a fresh queue's parallel
pass of 2 x 5,000 draws that costs 1-2 ns a draw (10.2 -> 12 ns).
test_command_buffer_storage checks the ring path and the block path: the
one move, doubling, blocks handed back, and a refused block posting
nothing.
The driver now answers AppleGVA's decode commands itself: a host session per
decode context, and each picture a command buffer of the session's queue
whose op carries the access unit, the SPS and PPS written back out of
AppleGVA's records where they changed, and textures over the output
surface's planes. A command's token is answered done once its command buffer
completes, which is once the picture is in the surface.
AppleGVA asks for one bitstream buffer and writes the next access unit into
it as soon as a picture is scheduled, without waiting for the decode that
reads it. So the channel copies each access unit, compressed data only, into
the next of eight Shared buffers of its session, from its first 3-byte start
code and padded to the host's alignment, and the host reads it there in
place; AppleGVA's own buffers are plain pages. The kext hands the bundle the
host's video caps with the device info. The call recorder used to learn the
interface is gone, and AppleGVA's records are read with plain loads.
Checked on the RTX 5080: the 672 frames of eight streams equal ffmpeg's
MD5s, and 1080p decodes at 1546 frames a second, 4K at 144.
6ae625668 answered minimumLinearTextureAlignmentForPixelFormat: 256 for the
56 formats the host backs with a buffer and 0 for the other 95. No Mac
answers 0. The oracle's q9 tables give one value on every format a Mac
makes linear textures of: 256 on 46 formats on the Radeon Pro 5300M and
the UHD 630 alike, and 16 on 56 on the M3 Max. On every other format,
Metal's own assertion ends the process (SIGABRT): compressed, depth and
stencil formats, Invalid, and formats the device lacks. The x86 Macs also
end it on the M3's ten extra formats (11, 31, 40-42, 263, 552-555).
So no working guest asks for one of those formats. One that did would get
a 0 to align up by, a divide or mask by zero. Every format now answers the
device's linear alignment, 256.
The graphics lane's device answered what the host platform answers for
maxBufferLength and the linear texture alignment, and left the framebuffer
read, tile shader and imageblock answers to the base class. Each answer
steers the guest's frameworks, so each now picks, from the answers real
Macs give, the one the lane can keep cheapest (dgpu-oracle.md):
- maxBufferLength is the host's, but at most three quarters of
recommendedMaxWorkingSetSize rounded down to 16 KiB. That is the rule the
Radeon Pro 5300M and the M3 Max answer by. The Vulkan platform answers
the driver's maxBufferSize, a terabyte on an RTX 5080 that no allocation
reaches; the 5080 now answers 12821200896.
- minimumLinearTextureAlignmentForPixelFormat: and the SPI
linearTextureAlignmentBytes and deviceLinearTextureAlignmentBytes answer
256 (or the host's, where larger), as the 5300M and the UHD 630 answer.
RADV takes a texture over dma-buf pages in place only at rows a multiple
of 256 apart, and every 256-byte layout is one the host's 16 takes.
- isFramebufferReadSupported answers no, as the 5300M does. That keeps the
guest's frameworks off attachment reads, which cost the Vulkan platform
the most.
- supportsTileShaders, supportsNonSquareTileShaders and supportsImageBlocks
answer no, as the 5300M and the UHD 630 do. The lane carries none of
them.
The bundle answers all of these from the device-info blob, never through
the base class.
WindowServer on the x86-64 guest samples the aerial wallpaper's 4K HDR video
frames through a YCBCR10_420_2P texture over plane 0 of each decoded surface,
which reads plane 1's chroma as Metal does. The bundle copied each plane into
a block of its own, so the host's texture over plane 0 had no chroma to read.
A surface's copy is now one block holding every plane, in plane order, each
from a 256-byte multiple with its rows 256 bytes apart, then the header and
the writers. A texture over any plane lies in the copy's one buffer at its
plane's offset, so every texture over the surface reads and writes the same
bytes, as Metal's over one surface do. The shared block is found by plane 0's
pages, which no other surface holds. Upload and write-back copy every plane.
A surface without planes is laid out as before.
Each TEXTURE_FROM_IOSURFACE now carries the surface's facts after its struct
(RgfxSurfaceFacts): IOSurfaceGetPixelFormat, the plane count, the size, plane
1's offset and pitch in the copy, and the YCbCr matrix. The matrix is the
surface's IOSurfaceYCbCrMatrix value, where CoreVideo leaves a propagated
kCVImageBufferYCbCrMatrixKey attachment (measured on the M3 Max under macOS
27.0.1 for all six of its constants). It is read from the surface, not
through CVPixelBufferCreateWithIOSurface, which holds the surface in use while
the pixel buffer lives.
The new shell test covers a 64 x 48 'x420' surface's one block, both planes'
textures, the facts, CPU access to plane 1, a missing plane, and a surface
without planes.
Apple2's rows need programmable sample positions, and the bundle dropped them:
a pass's setSamplePositions:count: never left the guest, and
setDepthStoreActionOptions: was a logged no-op. The device answers
areProgrammableSamplePositionsSupported from the host, so apps that asked got
the default positions with no sign of it.
A pass's positions now travel after its colour records
(RGFX_PASS_FLAG_SAMPLE_POSITIONS, RgfxRenderPassSamplePositions), and the host
sets them on its pass; RENDER_SET_DEPTH_STORE_ACTION_OPTIONS (0x104f) carries
the encoder's options to Metal, and to the Vulkan platform as late options over
a store action left Unknown, as the stencil and colour ones go.
Metal ends the process at positions it does not take (measured on the M3 Max,
macOS 27): its descriptor's setter at a count other than 2, 4 or 8 or a
coordinate outside [0, 1), its pass validation at a count the device makes no
texture of (8 there), whatever the attachments' sample count. The guest's
descriptor stops the first; the bundle answers no encoder for the second; and
the host faults a pass that holds either, so no guest bytes reach the abort.
SamplePositions joins WIRED with its cap test: Apple2 now waits only on Metal
IO queues.
A compositor commits the command buffer that draws its frame into an
IOSurface and then submits the display pipe's transaction for it, without
waiting for the buffer. The buffer rides its queue's ring and the present
ring 0, which the host takes on separate threads, so the window could show
the surface before the buffer had run, or before the host had taken it.
Each guest process that commits a buffer writing a surface's copy now names
its queue and the buffer's seqno in the copy's RgfxSurfaceWriters, four
slots past the block's header, before the commit returns, and
TEXTURE_FROM_IOSURFACE carries where they lie. A PRESENT_SURFACE reads
them, and the host's PresentQueue shows it once each named buffer's
CB_COMPLETE is posted, in the order the presents came, with no wait on
anything else: buffers of other queues or surfaces hold nothing. A queue's
destroy, or its context's close, releases what waits on it.
A process writes only slots naming its own queues: it raises its queue's
seqno, takes back a slot of a queue of its own that is gone, or claims an
empty one, and it empties its slots when its copy goes. A slot given to
another queue has its seqno emptied first, so the host's queue, seqno,
queue read never pairs one queue with another's seqno.
The bundle's argument encoders were stubs: newArgumentEncoderWithArguments:
and a function's newArgumentEncoderWithBufferIndex: answered nil, so no
app or framework could fill an argument buffer.
Each now asks the host for the layout (ARGUMENT_LAYOUT) through the
serializer's asker, the kext's submit that waits for the answer, into a
page of the region it gives back once the answer is read, and asks once
more into a block of the size the host needs where the layout outgrows the
first. The encoder parses the layout into a tree, checked whole, and writes
each argument's word where Metal's encoder writes it: in the last member
holding the index, at its element, through struct elements, and at the
arguments' offset 0 for an index no argument has. A buffer writes its GPU
address plus the offset, a texture or pipeline its resource id, nil 0. A
nested argument buffer's encoder takes its layout from the same answer.
What the wire does not carry logs its first use: a sampler's resource id
(its word is 0), a depth/stencil state's (the bytes stay), and the
argument's reflection. Indirect command buffers, acceleration structures
and function tables take only nil, which writes 0, since the device makes
none. A setter with no argument buffer set, where Metal's process ends,
writes nothing and logs it.
CA in WindowServer logged "nil buffer from memory": newBufferWithBytesNoCopy:
answered nil for every pointer outside the device region, which is all of an
app's own memory. Metal makes one over any range the process maps readable, at
any alignment and length (measured on an M3 Max at 16 KiB and, under Rosetta,
4 KiB pages: malloc'd, vm_allocate'd, read-only and file-mapped memory), and
answers nil only for a length of 0 or a range not wholly mapped.
Such a buffer now lies over a region block of its own, and its contents stay
the app's pointer. The block syncs with the memory as the IOSurface copies do:
the CPU's bytes go in at the commit of each command buffer that uses it, and the
GPU's come back when one that may write it completes, before its completion is
reported. Only the bytes each side moved since the two last agreed move, byte
by byte, so CPU and GPU writes beside each other both stand. The encoders note
each use as a read or a write, and they look up a buffer only while a shadow
lives. A null pointer gets zeroed contents of the buffer's own, and its
deallocator gets null, as Metal's does.