Graft 1.3.0 signs each inherited slot of the arm64e display's synthesized
vtable with the live parent's pointer-authentication discriminator. Our
arm64 firmware, Ambrosia, measures those discriminators from the Boot
kernel collection and hands them over in the device tree, but only for
the vtables its configuration names. Without that, Graft refuses the bind.
Our config.plist named none, so every boot that bound ReimsGraphics ran on
a local configuration that named the vtable.
Our configuration now names __ZTV25IOMobileFramebufferLegacy under
Kernel > ExportVtableDiscriminators. stage-config.py keeps every Kernel
key but Add, so make config-bundle carries the key into Config.cpio, and
make bundle carries it as well.
arm64 macOS 11 to 13 are not supported for now (owner, 2026-11-09): macOS
13.6 offers the reims-graphics device no MSI, and the kexts have no INTx
path. AGENTS.md's statement of support, the design's arm64e set and
docs/qemu.md's boot check now name macOS 14 as the first arm64 release, and
the boot check's releases are 14.6.1, 15.6.1, 26.6.2 and 27.0.1.
A 2 MiB slab of a process's own pages was a superpage the slabs' thread
asked for ahead of its take. Asking still stalled the process: the kernel's
search for a contiguous 2 MiB runs in vm_map_enter with the task's map
interlock held and the new entry locked exclusive (public xnu-12377.101.15
vm_map.c), so any walk of the map past it waits. Tailspin on an 8 GiB
macOS 26.7.2 guest on the Radeon 780M host: WindowServer's slabs thread was
in cpm_allocate while its main thread, making a texture over a layer's image
in a live resize, waited in mach_vm_region behind it, and Safari's page drew
no frame for 179 ms. No thread placement avoids that, superpages run out
minutes after a boot anyway, and the held one cost up to 38 MiB across the
19 processes that map the bundle.
So every slab of the process's own pages is plain pages, taken by the take
that needs it, as it already was once superpages ran out. The superpage
call, its record in the kext and the VM-guard tool go.
What changes for the guest: the kext no longer answers selector 12
(Superpages) nor sets kext feature bit 8; both lived only between the kext
and the bundle, which ship together, and reims_graphics_wire.h never had
them. The host sees the same pages blocks as a guest out of superpages
does: HEAP_OVER_PAGES and BUFFER_OVER_PAGES over plain pages' runs.
The guests for every x86-64 release a change to the guest's kexts boots are
on homelab-um870-1, 14.8.9 and 15.8.2 among them since they were copied from
msi-laptop: the list says which, at what path, how the copies were checked,
and what a boot of them holds.
A take of a slab asked the kernel for its superpage on the thread that took
it, and the kernel's search for a contiguous 2 MiB (cpm_allocate) runs on
the asking thread, given or refused. Sampled with tailspin on an x86-64
macOS 26.7.2 guest on the Radeon 780M host: WindowServer's main thread,
making a texture over a layer's image as a window moved, was in that search
in two samples 100 ms apart, and Safari's page drew no frame for 151 ms.
Now the slabs' background thread (RgfxSlabs::run) asks for one superpage
ahead (RgfxPagesSlabSource::prepare), at its start and after each slab of
the process's own pages, while the guest's superpage record is open. A take
of a 2 MiB slab uses the superpage held, or takes plain pages at once; no
thread that takes a slab asks the kernel. A process holds at most one
superpage it does not use. A dedicated slab larger than 2 MiB is plain
pages, as every slab was once the kernel ran out minutes after a boot; the
superpage module's several-superpage path is no longer reached by the
slabs.
The slab tests step the thread's work where a superpage is to be held, and
test_pages_source_asks_on_its_thread_alone runs the thread and checks that
every superpage ask came from it, not from the taking thread.
bf7d61a94's ReimsGraphics counts a surface's pages through mach_vm_region over
kernel_map and, inside IOKit's pageable maps, IOIteratePageableMaps: strong
imports whose arm64e path has never run. check-boot.sh gains page-count, read
after the boot's Metal work: it fails where the guest booted again during the
run (kern.boottime moved since the login), wrote a panic report in it (marked
where it names our kexts or the count's calls), or stopped answering. Its line
carries the host's last count of IOSurface device caches (made, deferred,
carrying pages, refused) and the kext's own count lines (counted, not counted).
Zero deferred while caches get made, no count line, or no count that counted
is printed as a check-boot: finding: line under the verdict, not a failure:
each is a result to report, not a fault in the path.
The region count deferred nothing on any release: IOKit maps a pageable buffer
into the kernel inside one of its pageable maps, a submap of the kernel's, so
mach_vm_region on kernel_map found one 512 MiB region with nothing to count
(SM_EMPTY) around the mapping, and the region rule refused it. Measured on
11.7.11 (20G1443) with a diagnostic build, serial on.
When the kernel's map shows such a region around the mapping, the count finds
the pageable map that holds it through IOIteratePageableMaps (kpi.iokit, every
release checked, x86-64 11.7.10 to 26.7.2 and arm64 13 to 26) and walks the
mapping's regions there, under the same rule: they must be the mapping exactly.
The callback answers KERN_FAILURE for a map that does not hold the address, so
IOKit never makes a map for it, and a walk that finds none refuses the count.
For the guest, fresh surfaces defer again: on 11.7.11 253 of 253 caches
deferred, WebContent 1622 -> 121 MB, guest wired 2631 -> 1121 MiB.
set-check let a weak import through when OpenCore bound it to 0, but 0 at link
time is not 0 at run time: the kernel rebases the word by the collection's
slide, and the kext read the result as a definition and called it on 11.7.11.
No word tells an absent weak import from a present one under OpenCore, so the
check now fails on any weak import in the set; a name some release lacks is
bound through Graft, which binds it to gOSKextUnresolved. The lessons entry
says so, and that set-check proves a kext links and injects, not that it runs.
The fresh test called IOMemoryDescriptor::getPageCounts(resident, dirty,
swapped) through a weak import, and on 11.7.11 every boot panicked at the
first fresh-surface test. OpenCore binds the absent symbol's word to 0, then
the kernel rebases it by the collection's slide, so the kext read
0xffffff8040000000 plus the slide as a definition and called it (WindowServer,
page fault in rgfxSurfaceLocksFresh, caught on serial).
The kext now maps the surface's memory read-only into the kernel's map for the
count and walks the mapping's regions with mach_vm_region's
VM_REGION_EXTENDED_INFO. That walk counts each page resident or compressed or
paged out (pages_swapped_out), measured on 11.7.11 against each page's
disposition with the pages in the compressor and on swap. mach_vm_region and
kernel_map are strong imports from com.apple.kpi.unsupported, which every
release kernel checked exports (x86-64 11.7.10 to 26.7.2, arm64 13 to 26),
so one route serves every kernel and both architectures.
The counts count only where the regions are the mapping exactly
(rgfxRegionPageCounts, tested). A region past it, a gap, a pager's memory or a
region with nothing to count refuses the count, so the rule can only refuse a
deferral. For the guest, macOS 11 to 15 defer fresh surfaces again, as 26
does, and no kernel calls an unbound word. A count's time is logged when it
is the longest yet, and for the first large surfaces.
The arm64 boot check read Metal enumeration and an on-screen app, but not
the two steps RgfxGate owns, so a boot with an empty /Library/GPUBundles or
an AMFI refusal of the bundle failed only downstream, with no reason. Add
bundle-install (RgfxGate's Graft client state reads installed, tagged or
present; the bundle carries the restricted flag and the
KernelExtensionManagement rootless class) and amfi-map (WindowServer maps
the bundle's executable, read with sudo lsof, which SIP allows; and the
boot's log names it in no AMFI or library-validation denial).
A version-keyed allow-list for a private kernel-struct offset refuses
releases where the offset is in fact correct; prove the offset in-kernel by
data reads, never by calling through an unproven pointer. And a "pass ended"
flag is not a "pass succeeded" flag.
A kernel address looked up at runtime and cast to a function-pointer type
panics an arm64e kext at the call site under FEAT_FPAC, because the cast
authenticates a raw value. Sign it for the schema the call site uses.
guest/graft now carries Graft-arm64e.kext, so the arm64e set takes it as
the x86-64 set takes Graft.kext: staged first, before RgfxGate, which
names com.steelbrain.Graft, and checked against the vendored binary.
Ambrosia's config bundle takes it as GRAFT=. The docs that said the set
lists no Graft yet now say what it lists, and what a pass still needs:
Graft 1.3.0's IOMobileFramebuffer synthesis for the display's bind.
The design's deferred pages and its feature bits now say how a surface no CPU
lock touched, a few of whose pages a process wrote without a lock, is deferred
carrying them (SURFACE_DEFERRED_CARRY), and the SurfaceBlock call's list of
them.
Two builds of one tree gave two arm64e RgfxGate binaries, alternating
(three clean builds on the M3 Max: A, B, A). They differed only in the
Metal bundle's arm64e image inside RgfxGate: its UUID, its signature and
__objc_stubs. ld (ld-27106.1) makes two slots for objc_msgSend in the
authenticated GOT, one for the message-send stubs and one for
objc_msgSend's own call stub, and gives each stub its slot in either order
from one link to the next. The arm64 image, whose GOT is not
authenticated, was the same every time.
The arm64e bundle now links its message-send stubs in their small form,
which branch to objc_msgSend's call stub and take no GOT slot of their
own, so the one slot leaves nothing to order. docs/lessons.md records the
trap.
OpenCore's linker binds an unresolved weak import to 0, and the kext's
direct call to IOMemoryDescriptor::getPageCounts's three-count form is
relative to the instruction, so it cannot reach 0: on the Boot KCs of
11.7.11, 13.7.8 and 15.8.2 the linker reported "RIP-relative overflow ...
target=0x0" and left ReimsGraphics out of the kernel collection, which
would boot those guests with no display driver (make -C guest set-check
with OpenCore's TestKextInject; 26.7.2's links, the symbol resolved).
The function is now reached only through a volatile function pointer in
data, whose whole address the linker binds, 0 or gOSKextUnresolved where
it is absent, and the code reads that word, never the symbol.
make -C guest set-check now passes a weak import the linker bound to 0,
where the kext was injected, and names it; any other import bound to 0
fails as before. docs/lessons.md records the trap.
A's fresh test read a surface fresh with its lock seed 0 and none of its
pages resident. A page a writer that takes no lock dirtied (seed 0 still,
as VTDecoderXPCService writes), then compressed or paged out by the guest,
is not resident but holds its bytes: the surface read fresh, its block was
deferred, and the host's cache of zeros took the place of those bytes.
Fresh now means no page has bytes anywhere: the seed 0, under the
read-only lock, and none of the surface's pages resident, compressed or
paged out (rgfxSurfaceHoldsOnlyResident, one verdict the carry calls too,
over rgfxSurfaceLocksPageCounts, which takes no lock). The count of the
compressed and paged-out pages is IOMemoryDescriptor::getPageCounts's
three-count form, referenced weakly: the release kernels of 26.6.1 and
26.7.2 export it in com.apple.kpi.iokit, those of 11.7.10 to 15.8.2 do
not, nor any routine of any KPI set that tells a page compressed or paged
out (each kernel's symbol sets). Where it is unresolved no surface is
counted, so no block is deferred and every block's pages are named at its
ask, as before deferral. Only a buffer the kernel allocated
(IOBufferMemoryDescriptor, anonymous memory) is counted: a descriptor over
a client's own memory may be a file's, whose pages not resident hold the
file's bytes, which no count shows.
What the guest sees: on 26.x kernels, a surface with a compressed or
paged-out page has its pages named at its ask instead of being deferred;
on 11.x to 15.x kernels no block is deferred. The host side is unchanged.
Safari's WebKit tiles, which the GPU alone draws, each wired 7 MiB of an
8 GiB guest at its first use on the Iris and the 780M. About 400 tiles of a
long page took WebContent's footprint past its 2 GB limit, since wired pages
count in their owner's footprint though WebKit marked the tiles volatile,
and the corpse and the memory pressure that followed stalled its frames for
100 to 800 ms (jobs m3-max-10419, m3-max-10438, m3-max-10517).
Where the host offers SURFACE_DEFERRED_ASK the kext takes it beside
SURFACE_CACHE_REFUSED and defers a fresh cacheable surface as on a GPU of
its own memory, its SURFACE_PAGES carrying ASK_CACHE and the surface's
layout. Refused, past the budget, or not fresh, it names the pages asking as
before: answered a cache, it posts them again cached; answered in place, the
device cache's entry the deferral made goes (rgfxSurfaceLocksUngate) and the
block is not cached. A deferred block's pages are wired, named and copied
only at a CPU lock that needs them, as on such a GPU.
These surfaces cannot lie in place on that host whatever their pages, so a
deferral chooses no copy over in place; it only stops eagerly wiring and
zero-filling guest pages the CPU never touches. guest/prebuilt is built
again from these sources.
On a GPU that shares the CPU's memory the host keeps a device cache only of
the surfaces whose pages its textures cannot use in place
(SURFACE_CACHE_REFUSED), and it offered no deferral there. So a fresh surface
that needs one had its pages wired and zero-filled by the kext at its first
texture, and copied into the cache once, though the CPU never touched them.
The host now offers SURFACE_DEFERRED_ASK (FEATURES_LO bit 30) beside it,
with the budget a host of a GPU of its own memory gives (DEFERRED_BUDGET, a
quarter of the device-local heap's budget). A deferral then asks with the
surface's layout (DEFERRED with ASK_CACHE and no runs), and the host defers
the block only where the surface would need a cache whatever its pages
(GpuDevice::fresh_surface_never_in_place). Every other is refused with
nothing made and counted, as is one past the budget, so the kext names its
pages asking, as without the feature: a full budget fails safe to today's
wire and ASK_CACHE path.
This is inside the rule that surfaces are used in place, cost and all, only
because these surfaces genuinely cannot be placed in place: their layout
needs a device cache either way (on the Iris, rows ending inside the GPU's
64-byte lines; on the 780M, runs exceeding one udmabuf). So it does not
choose a copy over in place; it only stops eagerly wiring and zero-filling
guest pages the CPU never touches.
What the guest reads changes on a unified-memory host: FEATURES_LO gains
bit 30 and DEFERRED_BUDGET is no longer 0, and the test that held both
changes with them. The wire header's new bit moves the option ROM's and the
guest set's records of their sources; their bytes stay.
The arm64e set, guest/prebuilt-arm64e, joins guest/prebuilt among the committed
outputs, with what writes it (make -C guest prebuilt-arm64e) and what checks it
(prebuilt-check, which cargo xtask check runs), and the guest/ row of the checks
asks for both sets. design.md records why the arm64e kext has its own Graft
declaration and Info.plist, and the owner's call on the arm64 display: an
IOMobileFramebufferLegacy subclass, since an arm64 WindowServer drives no
IOFramebuffer. qemu.md's arm64 boot check names the set's kexts for Ambrosia's
config bundle and what a pass still needs.
An 8 GiB x86-64 macOS 26.7.2 guest on the Radeon 780M host has no 2 MiB
superpage left a minute after its boot, yet every pages slab still asked the
kernel for one first. Each refusal cost the asking thread the kernel's search
for a contiguous 2 MiB: 140 to 190 ms in cpm_allocate, sampled with spindump,
in the first slabs of every process, which then took plain pages anyway. A
video decoder session's first access unit waited that long (the AVPlayer
probe's start hold there was 283 ms, against 133 to 150 ms on a native Mac),
and so did Safari's GPU process's layer drawing as a page opened.
The kext now keeps one record for all the guest's processes: 'RGFX' selector
12, Superpages, kext feature bit 1 << 8 (RgfxSuperpageRecord.hpp). A superpage
the kernel refuses for want of contiguous RAM closes it, a slab of superpages
given back to the kernel opens it, and while it is closed a pages slab takes
plain pages without asking, as a refused take did. A refused slab of several
superpages, or a refusal past the wire budget, leaves it as it was.
What the guest observes: the same slabs as before, without the search. The
host sees the same pages blocks, a superpage's one run or plain pages' many.
Where the kext lacks the bit, the bundle never calls the selector and asks the
kernel at every take, as before; where the call fails, the take asks too. A
bundle that knows no record leaves a kext's record untouched. The host plays
no part. test_pages_source_superpage_record holds the record's closing, the
takes it spares in another process and its reopening on a superpage slab
given back; user_client_words_test holds the selector, the bit and the
kext's record.
The boot harness's 60/s wheel ran on the clock the refresh grid ticks on, so a
scroll run's clicks kept one offset into the refresh for the whole run. Runs
whose clicks fell at a frame's edge composited at 30 Hz for seconds with every
present on time, and read as a device stall that came and went. A boot that
set the offset (0.3 and 15.2 ms against 9 ms) showed the offset alone decides
it.
The documented VA-API check, `cargo nextest run -p reims-vgpu-video
--run-ignored only -E 'test(/^vaapi::/)'`, failed from a clean checkout:
the target probe's ignored test, in that set, needs RVG_VA_STREAMS, the
streams the conformance scripts write with x264, x265 and ffmpeg.
The probe becomes a tool rather than a test, since the target check's own
tests are the check. The probe prints how many pictures of each way came
out as the driver's own surfaces', and asserts only that it decoded
something; the target check's tests check every byte of their targets'
memory after each picture, and run in the set with no streams. Taking the
streams where the scripts leave them would still fail from a clean
checkout, and running the probe inside the scripts would add its decodes,
about 150 s on a 780M, with no verdict, to every conformance run.
The tool is an ignored test at the crate's root (`probes::`), outside the
`vaapi::` and `nvidia::` sets the hardware hosts' checks run, as the
fuzzers' long runs and reims-vgpu's RVG_VA_STREAMS tests sit outside them.
It is not an example: an example reaches only the public API, and the
probe's import hook (`surface::MAKE_SURFACE`), which has every surface a
decoder's pool makes imported over the probe's memory, exists only in a
test build. Its code and unsafe blocks stay in the `va` module. Without
RVG_VA_STREAMS it still fails, naming it. Nothing it compares changed.
Adds U28 to the video bugs: radeonsi's decodes write an imported surface only
within the bytes its declared planes span from the luma plane's first byte, and
what the targets do about it.
Graft 1.0.0 published ReimsGraphics' personalities after binding it. 1.1.0
keeps them in the kext, each gated by an IOPropertyMatch on the device nub
that Graft sets once it has bound the kext, then re-registers the nub. The
gate is passive, so IOKit constructs none of our classes, whose parent
constructors run through Graft's sites, until those sites are written; an
IOResourceMatch would hold back only start(), and a gate probe deriving
from IOAccelerator panicked on 11.7.11 and boot-looped on 26.7.2 that way.
The passive gate booted clean on both, with its forced refusal holding.
Vendored by Graft's tools/vendor.py from v1.1.0 (1b17bb7c5ec3) with its
record.
A scroll A/B of two metal2vulkan pins on the 780M showed vkQueueSubmit
stalls of 8 ms or more falling from 22 to 1, which read as the new pin's
gain. The same arms in the reverse order gave 20 and 1: the boot that ran
first, right after a build or a perf run on the host, stalled, and the
second did not, whichever pin it ran. The lesson says how to spot it and
how to run an A/B that the order cannot decide.
The cut of the VA arm's H.264 answer to 65,535 macroblocks kept the driver's
largest width and lowered the height. radeonsi answers 4096x4096, which came
out as 4096x4080, but iHD answers 8192x8192 in VAConfigAttribMaxPictureWidth
and Height, which came out as 8192x2032: the guest's video driver would then
refuse 3840x2160 and every H.264 stream taller than 2032 at its create, and
VideoToolbox would decode 4K H.264 in software on Intel hosts.
iHD decodes nothing wider than 4096: its surfaces' bound is 4096x4096, and
ffmpeg's VA-API decode refuses every size from 4112x2160 to 8192x1024 on an
Iris Xe (iHD 26.3.5). So where the driver's largest size holds more than the
bound, the answer is at most 4096 wide and as tall as the bound leaves there:
4096x4080 on both drivers, holding 3840x2160 and 4096x2160. The test now
feeds iHD's answer too, and the sizes users play.
For the guest: on an iHD host H.264's largest size is 4096x4080, where it was
8192x2032 since the bound came in.
A boot of the guest on a Radeon 780M decoded the item's 30 H.264 streams, on
the hardware decoder alone and as a player takes them, beside the MacBook Pro
16 2019's answers: interlaced streams, 4:2:2, 4:4:4, monochrome, lossless and
8192x4320 fail their session's create in the guest as on the Mac's 5300M, and
a 4096x4096 stream now fails it too, at the driver's size check, and decodes
right in software. High 10, FMO, data partitions and SP slices reach the host
only with a picture, and give the 5300M's frames.
T3 says what interlaced streams do now, D25 what is left of it, and devices.md
and design.md where an H.264 decode is checked.
iHD and radeonsi answer 4096x4096 as their largest H.264 decode, yet give
every frame of a 4096x4096 stream back with its luma all zeros, every call
succeeding: ffmpeg's VA-API decode as ours, on an Iris Xe, an RX 7900 XTX
and a Radeon 780M. 4096x4080, 4080x4096 and 15 other sizes decode right.
4096x4096 is the one size within the drivers' bound of 65,536 macroblocks.
So the VA decoder refuses a picture of more than 65,535 macroblocks at its
SPS, and the graphics device answers H.264's largest size under the bound,
4096x4096 as 4096x4080: the guest's video driver then refuses such a stream
at its create, and VideoToolbox decodes it in software, where before every
frame reached the guest black. Recorded as bugs.md U28.
The codec module refused every SPS of profile_idc 88, at the first picture,
which through the graphics device reaches the guest as undecoded frames:
AppleGVA's H.264 decoder hears of no failure. Apple's AVC decoder on an x86-64
Mac decodes such a stream in hardware (measured on a Radeon Pro 5300M's
AppleGVA flow and an Intel UHD 630's, macOS 26.7.1: JM 19's Extended stream of
CAVLC B slices decoded as JM's reconstruction). Its pictures are Main's where
they use none of Extended's own tools, so the SPS is taken, the VA-API arm
asks for VA's Main profile, else High, and data partitioning and SP and SI
slices stay refused at the slices that use them.
For the guest: an Extended stream now decodes on the host where it reached the
client as undecoded frames.
At each Mission Control open WindowServer captures a window list for Dock
into a new IOSurface. It composites the capture with
commitAndWaitUntilSubmitted, and Dock's main thread waits for the capture.
The surface's first use fills its device cache from its pages. The host
held that buffer's CB_SUBMITTED until its scheduling: after the fill's
encode and commit, and after the walk. On the 780M host the guest waited
about 4 ms per open in that call, of Dock's 14 ms wait for the capture
(guest sample of WindowServer and Dock, 3 opens).
What the guest sees now: a buffer that asks for CB_SUBMITTED, waits for no
event and follows no deferred copy of a device cache gets its CB_SUBMITTED
as the host takes it, before the fills its begin makes at once. It used to
get it at its scheduling. It also gets CB_SCHEDULED there, where no buffer
begun before it on its queue owes its own. The ring keeps its order:
CB_SUBMITTED is still the buffer's first record, ahead of CB_SCHEDULED and
CB_COMPLETE, and a queue's CB_SCHEDULED records keep the queue's order. A
fill made at once no longer holds the buffer's queue, so the buffers behind
it are answered at their takes too.
A buffer whose fill must wait for buffers begun before it, or that follows
a copy asked and not yet made, still holds its queue and keeps its records
at its scheduling, as a buffer that waits for an event does: its copy waits
for those buffers, and they may wait for the guest.
Why nothing reorders:
- the buffer's ticket in the commit order is issued before the post, as at
any take;
- a fill made at once waits on the GPU for nothing the guest has yet to
send, since no buffer begun and not finished uses the cache;
- from the answer until the fills are made, the caches hold the buffer's
blocks. Another begin that names one of them waits, so it cannot count a
use that would turn a fill decided at once into a deferred one.
The doorbell still answers no buffer that needs a fill. It cannot know the
fill will be made at once, because another queue's begin before the take
may count a use of the cache.
Tests: a_buffer_behind_a_fill_is_submitted_at_its_scheduling becomes
a_buffer_whose_begin_fills_a_cache_is_submitted_before_the_fill: the
CB_SUBMITTED is posted before the fill's copy and the buffer's commit.
a_buffer_behind_a_deferred_fill_is_submitted_at_its_scheduling keeps the
old order for a deferred fill.
a_begin_waits_while_another_answered_before_its_fills_makes_them covers the
hold on the blocks.
Measured on the 780M host (um790), two boots of each, with guest samples of
WindowServer and Dock over 3 opens. Before is development d2a27d46a.
- WindowServer's capture spent 12 and 7 samples in
commitAndWaitUntilSubmitted before the change, and 0 and 1 after.
- Its handling of the capture took 20 and 11 samples before, 10 and 9
after.
- Dock's wait for the capture was 52 and 23 samples before, 34 and 30
after. It varies with WindowServer's main thread.
- The first Mission Control frame lands no earlier: a median of +122 and
+125 ms after the key before, +129 and +131 ms after. The fill was not on
that frame's path.
- In the boot pair whose guests were in the same state, frames lost per
open were 2.4 before and 2.6 after.
Two traps the macOS 11 WebGL work found: a guest framework that looks for the
GPU by what a Mac's GPU states and gives up without a word, and a system
LLVM whose exported C API differs by release, which the build Mac's tests
never meet.
On macOS 11, Safari's WebGL runs on WebKit's ANGLE over OpenGL, and ANGLE
refused to start on our device ("Unable to query ANGLE's SystemInfo."), so
Safari 14.1.3 made no WebGL context. ANGLE lists the Mac's GPUs by their PCI
devices' class-code, which reads 0x038000 for ours, a display controller of
class "other"; both GPUs of an Intel Mac state 0x030000 (measured, macOS
26.7.1).
The accelerator now sets class-code to 0x030000 on its PCI device's registry
entry when it starts. Configuration space keeps the device's own class, so
the firmware and the PCI family's matching see what they saw. On a macOS
11.7.11 guest, ANGLE then starts, in a plain process, without WindowServer
and inside the web content sandbox, and Safari makes its WebGL context.
AppleGVA's decode flow takes every query of a decode for its completion
and reads no status or error from it (read from its code on macOS
26.7.1); the one failure it reports to VideoToolbox is a failed
schedule. The driver answered a query of a decode the host was still
running as running and never looked at its token again, so a host
failure that came after the query was lost: the guest got the untouched
surface as a decoded frame and no error. Only a failure the host had
already reported at the query failed the session's next schedule, two
pictures late.
Now the schedule of an HEVC picture waits for the host's verdict on it,
out of the lock that orders the sessions' pictures, and fails where the
host failed it. What changes for the guest: an HEVC decode's
ScheduleCommands returns once the host has decoded the picture, and a
picture the host fails gets kVTVideoDecoderMalfunctionErr itself, from
that frame on, instead of two frames later or never. H.264 is unchanged:
AppleGVA's H.264 pipelines keep no decode's result, so its schedule waits
for no verdict (docs/video/bugs.md D25, now H.264's alone).
The tests that held the deferred failure (failsLaterSchedule,
queryReport) change with it, and checkHostVerdict drives the schedule
through a host that fails one picture.
The exit lesson's VA shapes now carry the runs that followed the fix on the
Iris Xe: 60 full-workspace runs under glibc's malloc checks with no failure at
exit, against 2 in 100 before it, and a program of its own whose vaTerminate
after iHD's destructors ends cleanly in 400 runs, so the abort needs live
decode state in the display.
The install and boot checks of the prealloc change through reims-ctl: QEMU's
first vCPU 0.53 s after its start on um870, reims-ctl start returning in 0.8 s
there and in 8.9 s on ms01, both at the desktop with the guest's RAM in 2 MiB
pages; and what a host without the memory now shows.
On a Linux host, reims-ctl's q35 VMs now have QEMU allocate the guest's
memfd RAM whole at start (prealloc=on), with as many threads as the VM has
vCPUs (prealloc-threads).
Without it, the guest's first touch of each page faulted on a vCPU, and
KVM resolved the fault through get_user_pages under the process's mmap
lock. Where the host backs shmem with transparent huge pages (CachyOS's
shmem_enabled=advise, with QEMU's MADV_HUGEPAGE), the fault allocated a
2 MiB page with direct reclaim and compaction. On a fragmented host that
mostly failed and took up to 1.8 s, and any writer queued on the lock held
every other vCPU behind it. On msi-5080 playing Safari's 4K HEVC clips,
two boots without prealloc spent 15 and 22 s with vCPUs blocked on the
lock, and the clips presented 1.1 to 57 frames a second, dropping up to
1,570 frames each. Two boots with prealloc had no vCPU take the lock at
all; the clips presented 50 to 58 frames a second, dropping 0 to 4.
For the host: QEMU takes 5.3 to 6.5 s longer to reach its first vCPU on
that fragmented host (16 GiB, 8 threads), the VM holds all its RAM from
the start (17.1 GiB at the guest's first Safari page, against 10.9 GiB),
and a host without the free memory for a VM's RAM refuses the VM as QEMU
starts instead of overcommitting. For the guest: the same RAM, with no
stalls on first touch.
A process's exit runs its exit handlers and its libraries' destructors on the
exiting thread while the library's other threads go on. A device's display let
go as a test process exited made its last vaTerminate on the device's thread
beside the driver's exit-time destructors: on the Iris Xe (intel-media-driver
26.3.5) test processes aborted after "ok" in iHD's frees, "double free or
corruption (out)" and "free(): invalid pointer", in 2 of 90 runs of the
workspace's tests. A host that quits with a display open meets the same race.
Two holes let the call through. The exit gate's handler was last registered
before vaInitialize loaded the driver, so the driver's destructors ran before
it; and the VA crate's Calls made its at-once calls on the caller's thread
(where its call thread is idle, and in its paths with no thread) without a
step of the gate. The video runtime now registers the gate's handler again
after each vaInitialize (Runtime::arm_exit, the platform runtime's
exit_gate::arm), and every VA call takes a step, so the exit waits out a call
in progress before the driver's destructors run, and parks a thread that
would make the next.
For the host: a process that exits with a VA display open no longer aborts in
the driver; a thread that would call VA once the exit began parks until the
process ends. The C API's release is unchanged.
no_call_runs_beside_a_drivers_exit_time_destructors holds the pattern without
a driver: a child process with a stand-in for the driver's destructors and a
runtime gated as the host's exits while another thread makes Calls' at-once
calls; without the steps the child ends as a call reaches the stand-in after
its destructors ran.
An HEVC picture that the host refuses was sent anyway, and the refusal came
back only at the host. AppleGVA takes such a picture, and the one after it,
for decoded (D25), so VideoToolbox delivered two wrong frames before
-12911. The refused pictures were: one whose coded size was outside the
caps; one whose PPS had a tile column narrower than the host decodes; and one
whose current reference sets held more pictures than the caps'
max_references, as kvz-720p-ref15's tenth picture does.
The driver now checks each picture against its HEVC decode entry and the
entry's decode caps before it sends it (hevcTaken). It reads NumPicTotalCurr
from the first slice segment's header (h265::currentReferences): its own
short-term set or the SPS's, with prediction, and its long-term pictures.
It works out the PPS's narrowest tile column with 6.5.1's layout
(h265::narrowestTileColumn). A picture that fails the check fails its
schedule. VideoToolbox reports kVTVideoDecoderMalfunctionErr for that frame
and every one after it, where it used to deliver two wrong frames. A bound
of 0 refuses nothing, and a header the driver cannot read leaves the verdict
to the host. kvz-720p-ref15 now decodes 9 frames and then fails, as it does
on an M3's VideoToolbox. H.264 gets no such check: AppleGVA's H.264 decoder
delivers a picture whose schedule failed.
The kext set is built again with the bundle.
The host refuses an HEVC picture whose PPS has a tile column under 128 luma
samples (MIN_TILE_COLUMN_WIDTH), and nothing on the wire said so. The guest
could learn it only after it had scheduled the picture, which AppleGVA takes,
with the picture after it, for decoded.
RgfxVideoCaps gains decode (at 0x510), an RgfxVideoDecodeCaps for each entry.
Its min_tile_width is 128 for HEVC decode on both arms, and 0, no bound, for
every other entry. The kext copies the device info and the caps by their
sizes, so the kext set is built again with the header. The option ROM's
record names the header, so the record is written again too.
The HEVC decoder refused a PPS with a tile column under 256 luma samples or a
row under 64, the Main profiles' bounds (A.3.2 to A.3.4), after the guest had
scheduled the picture. kvazaar writes such streams without a warning. The
hardware decodes them: columns of 128 and 192 samples and rows of 16 and 64
matched kvazaar's MD5 SEI and reconstruction on every frame on radeonsi (a
Radeon 780M), on iHD (an Iris Xe), on NVDEC (an RTX 5080 Laptop GPU), and on an
x86-64 Mac's Apple decoders (Intel UHD 630, and AMD's driver on a Radeon Pro
5300M). A column of 64 samples, one CTB of 64, came out wrong on every frame,
with no error, on radeonsi and on the Mac's AMD driver, and right on NVDEC and
the Intel ones.
The decoder now refuses only tile columns under MIN_TILE_COLUMN_WIDTH, 128.
No driver reports the bound, so it is the same on every host. For the guest,
kvz-720p-tiles-narrow (a 192-sample column) and a stream with a row of 16
decode on every frame. A stream with columns of 64 is still refused.
hevc-check.sh decodes kvz-720p-tiles-narrow and kvz-720p-tiles-short, and
expects kvz-720p-tiles-col64 to be refused at its PPS.
The HEVC decode entries said 15 for max_references on both arms: the size of
VA's ReferenceFrames, and the DPB bound on NVDEC. Neither host decodes a
picture with more than 8 pictures in its current reference sets. VA-API's
decoder refuses it (va.h: NumPocTotalCurr "should be equal to or smaller than
8"), and radeonsi decodes one wrongly when it is sent. NVDEC's
CUVIDHEVCPICPARAMS holds 8 a set, so 8 in all is the most with which every
picture decodes there. kvz-720p-ref15 is refused from its tenth picture, with
9 current references.
The guest now reads 8 for max_references in its HEVC decode entry on both
arms. H.264's 16 stays: the hosts take a reference list of 16 frames
(ReferenceFrames[16], NVDEC's dpb[16]), which is the standard's bound.
The framebuffer names its accelerator in IOAccelTypes by the accelerator's
service-plane path, which IOAccelFindAccelerator follows, and with it OpenGL's
list of renderers in a process with no WindowServer connection. The framebuffer
starts first and names it through the PCI device's name; the accelerator then
renames the device GFX0, so the path led nowhere. IOAccelFindAccelerator failed
for our framebuffer (0xe00002bc), and on macOS 11.7.11 such a process was
offered the software renderer alone (measured: CGLQueryRendererInfo after
CGSSetDenyWindowServerConnections).
The accelerator now names itself again whenever it finds the framebuffer, where
the path there is not its own as it stands (RgfxAccelTypes.hpp, with its native
test). On 11.7.11 IOAccelFindAccelerator then answers 0 and that process is
offered the accelerated renderer too. Safari 14.1.3's WebGL on 11.7.11 still
fails to make a context, for a cause not yet found.
OpenCore now injects Graft, ReimsGraphics and RgfxGate from Darwin 20
(macOS 11) instead of Darwin 23 (macOS 14). x86-64 guests on macOS 11, 12
and 13 now get our set, so their display and Metal run on the reims-graphics
device. Before this commit OpenCore left these guests without the set.
These releases' x86-64 matrix rows now pass in full. Graft 1.0.0 binds what
each release's kernel has. The set chooses the completion words each
release's family exports. The HEVC search finds the frame description in
each release's layout. With pin 22, the library compiles 11's Core Image
metallibs.
The bound's comment in guest/tools/prebuilt.py and the design doc now say
macOS 11. The set is regenerated with it: set.toml's MinKernel, and
sources.toml's record of prebuilt.py.
The register's check walked only the public protocols the bundle's classes
adopt, so it could not see the class of member macOS 13's Maps died on: a
member of Metal's SPI counterpart (MTLLibrarySPI for MTLLibrary), which
Metal's own objects adopt and the guest's frameworks send without asking. It
now walks each protocol's SPI counterpart too, and adds the members only
older guest releases' protocols carry, which the Mac it runs on lacks
(tests/protocol_members_releases.txt: macOS 11.7.11, 12.7.6, 13.7.8 and
26.7.2 against 27.0.1).
The register lists every SPI member: the forwarders as implemented, the
constant answers as Metal's with why, and the rest by what the AMD 5300M's
and the Intel 630's objects answer (measured with respondsToSelector:, macOS
26.7.1), counted by class family: pending where both answer (305, to be
answered as Metal's), absent where neither does (54) or they differ (6),
pending where the oracle's macOS lacks the member (14). A new kind, pending,
is checked as absent. The 31 members only older releases carry are absent:
no app pass on those releases showed a framework sending one, and the 4 of
MTLDeviceSPI are answered there by the device's own IOGPU base.
tools/protocol_dump.m dumps a Metal's protocols for the releases list, and
tools/oracle/oracle_spi_members.m asks a Mac's own objects for the verdicts
and what their getters answer. docs/lessons.md says what the trap was.
Each new IOSurface of the guest's video pool cost its device cache a fill
from the guest's pages as the cache was made: 12 to 24 MB copied by runs, 1.06
to 1.70 s each on the 5080 at pin 22 (m3-max-8949). The decode that writes the
surface waited for that fill on the CPU, so a clip's start and each growth of
the pool held the decoder for a second or more, and Safari dropped frames
behind it.
A new cache is now made as zeros on the transfer queue and owes its first
fill from the pages, which the first thing that reads it makes: a named use, a
present, a command buffer of render, compute or blit work in the context that
made the block's first buffer, or a buffer over the block in another context.
A command buffer of decodes alone that writes both planes of a new two-plane
4:2:0 surface whole takes that fill as met: its picture lands over the zeros,
and from then on the cache's downloads, releases and early copies copy those
planes' rows alone, so the pages' other bytes (CoreVideo's header) stay as the
guest's CPU wrote them. A decode that answers no picture (a picture the
stream's random access skips) makes the owed fill before anything reads the
cache.
For the guest, nothing observable changes, except that a decoder's new output
whose picture fails to land, or lands short of its planes, reads zeros where
the picture did not write, where it read the pages' bytes before; no other
memory's bytes reach it. Such a decode's command buffer completes failed, which
leaves what it wrote undefined, and a new surface's pages are zeros unless its
client wrote them under a lock, which moves the count and has the decode's use
fill the cache (docs/graphics-kext/design.md).
The caches' tests now see the first fill at the first use instead of at the
make. New tests: work in the context of a new cache's buffer fills it, and so
does a buffer over it in another context; a decoder's new output takes no fill
and copies out its planes alone, header bytes kept; a failed landing into one
reads zeros and no host bytes; a skipped picture fills its new output.
A macOS 13.7.8 test base booted and answered SSH, but Safari, Preview and
Maps never opened a window, with our kexts and without them. The test
user's home carried the BSD flag restricted, which SIP guards, so the
user's containermanagerd could not make its directories and launchd
restarted it every 10 s. chown and resetUserPermissions cannot clear the
flag under SIP. The note says how to spot it (ls -lOd ~ ~/Library) and how
a copy is repaired with one SIP-off boot, the base's later boots running
with SIP on as before.
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: on a host whose GPU shares the CPU's memory
(RGFX_FEATURE_SURFACE_CACHE_REFUSED), with VA-API's hardware video (the
Radeon 780M's radeonsi, the Iris Xe's iHD), the video caps now say
RGFX_VIDEO_CAPS_OUTPUT_CACHED, with no output layouts, as a host of a GPU
of its own memory says them where its video lands pictures in caches. The
guest's video driver then asks its output surfaces cached, with their
layout, as any other surface (RgfxAskUncachedScope no longer covers them),
and the device keeps a cache of those it answers RGFX_STATUS_CACHE: an
output whose textures would not lie in place in its pages, or whose view
has no room for its mappings. A picture lands in such a cache by the
runtime device's copy of the decode surface (or the CPU's, through the
session's staging, where that copy is refused), and a CPU read of a decoded
frame has the cache copied out into its pages first. An output that lies
in place stays in its pages, as before.
For the host: VaapiVideo::lands_in_device_caches is true, and the device
offers cached outputs wherever the kext makes caches (video_caps, out of
GraphicsDevice::with_platform). The caches lay the first plane on 256
bytes of their memory (the commit before), so textures over the decoded
planes lie in them rather than in the runtime's shadows.
Measured on guest boots of macOS 26.7.2, Safari playing 4K60 HEVC clips
(8-bit, then 10-bit; then two and three at once), against development
81f187735 on the same host, vm.max_map_count 1048576, before this change
was rebased onto development's df50639ea (a laid-out cache's bytes between
rows declared unobserved), which the boots did not include:
- Radeon 780M (radeonsi and RADV, Mesa 26.2.6): the runtime's shadow
texels copied in per presented frame fell from 10.2-15.6 M to 0.00-0.03 M.
18 of 85 sessions landed in caches (4K outputs whose planes exceed
udmabuf's 1024 pieces), the rest in place; 148 caches were made aligned.
Presented fps 55.8/55.5 single, 53.9/57.0 two, 52.1/51.9/54.0 three
(development 57.0/57.2, 56.0/57.5, 53.9/53.3/52.6), drops 14/14/6 at
three (13/15/5). Mappings 5.7-6.6 k both.
- Iris Xe (iHD, ANV Mesa 26.2.6), where ANV answers a cache for every
surface: all 85 sessions landed in caches, and the process's mappings
peaked at 13.3 k (311 k on development). Shadow texels 0.07-0.32 M per
frame both. Presented fps 53.3/54.0 single, 54.4/53.6 two,
54.5/55.2/55.0 three (development 57.1/56.6, 55.4/53.9, 54.0/51.8/54.0),
at most 2 drops a clip; a second pair of boots, development's first,
gave 56.5/55.4 single (development 54.1/55.7): the single clips' spread
is the boots', not the change's.
- Both: 0 pictures copied by the CPU, 0 fatal lines. A guest process
reading every decoded frame on the CPU (decode_md5 against ffmpeg's
framemd5) matched on 63 of 75 streams both ways, the same 12 failing on
development, the three 4K streams (in caches) among those matching. The
byte-exact test lands every third of 4951 pictures of the conformance
streams in a cache made as the device makes one, equal to the CPU's copy.
- RTX 5080 Laptop GPU (NVDEC): its caps and caches are as before (no cache
made aligned); the boot's playback swung as development's does there.