VTDecoderXPCService writes page 0 of each new decoder output before its first
decode, the output's other pages not resident (measured on the 780M in a macOS
26 guest: all 208 pool surfaces of a 4K HEVC session in Safari). A deferral
takes only a surface none of whose pages is resident, so each decoder output
had its 12 MiB wired and filled with zeros at its first ask: 5 to 7 ms of the
guest's on the 780M and about 3 ms on the 5080, for each of the seventeen or
more surfaces a 4K60 playback's start makes.
The host now offers SURFACE_DEFERRED_CARRY (FEATURES_HI bit 0, feature bit 32)
where it offers either deferral. A guest that takes it may defer such a
surface carrying its resident pages: the deferral's runs are the surface's
bytes in order, each run of pages not resident RGFX_PAGE_RUN_ZEROS. The host
makes the cache of zeros as for any deferral and owes a first fill of the
carried pages, as a new cache owes one of its pages: copied in through a
staging buffer after the zeros on the transfer queue, before what reads the
cache next, or taken as met where a decode writes the planes whole first. The
carried pages are watched until the block's pages are named.
A deferral with runs is refused as INVALID_ARGUMENT where the guest did not
take the bit, or where its runs are not whole guest pages summing to the
surface's bytes, lie outside the guest's RAM, or carry none.
What the guest reads changes: FEATURES_HI offers bit 32 where either deferral
is offered, and the test that held the feature words changes with it. The
wire header's new constants move the option ROM's and both guest sets' records
of their sources; their bytes stay.
The x86-64 and arm64e sets from the tree with the page count reached
through a pointer in data and the arm64e bundle's small objc stubs. Each
ReimsGraphics imports getPageCounts's three-count form weakly, from one
word of data only. Four clean arm64e builds of this tree gave one RgfxGate,
its bundle with one objc_msgSend slot. make -C guest set-check injects the
x86-64 set into the Boot KCs of 11.7.11, 13.7.8, 15.8.2 and 26.7.2.
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.
The x86-64 and arm64e sets, built on the Mac from the tree with the fresh
test that counts compressed and paged-out pages. Each ReimsGraphics binary
imports IOMemoryDescriptor::getPageCounts's three-count form weakly.
RgfxGate's arm64e binary comes out different from the last build's (its
UUID and a span of about 24 KiB) though none of its sources changed; the
sets' check passes with either.
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.
A deferred IOSurface has no pages yet, so the host cannot ask over a view of
them whether its textures would lie in place. Before it defers one on a GPU
that shares the CPU's memory, it has to know that the surface would need a
device cache whatever pages it comes to have.
GpuDevice::fresh_surface_never_in_place answers that from the surface's
layout alone. On a device whose views are dma-bufs (RADV), a plane of more
pages than one dma-buf takes pieces needs one, each page counted a piece of
its own as the guest's fresh surfaces come (measured on the 780M: Safari's
tiles of 1,824 pages came in 1,379 to 1,824 runs, over udmabuf's default
list_limit of 1,024); else the runtime's verdicts by layout decide, as
surface_pages_never_in_place reads them. The fake answers as the world says.
Nothing asks it yet.
RgfxGate's payload now admits every slice of the bundle's executable, so both
prebuilt sets are rebuilt from development e5000382b with this branch's
sources (job m3-max-10762). The x86 set's RgfxGate, ReimsGraphics and Graft
are byte-identical to development's, its record of the sources aside: its
payload keeps its one slice. The arm64e set's RgfxGate is new, its payload
admitting the bundle's arm64e and arm64 slices; its ReimsGraphics is
development's.
On macOS's bash, 3.2, a script that stops at an unset variable under set -u
exits 0 where an EXIT trap is set, and $? is 0 inside the trap too, so a check
that aborted read as a pass (measured: the same script exits 1 with no trap).
payload_test.sh showed it; seven more scripts pair set -u with an EXIT trap:
check-boot.sh, check-imports.sh, walk_window_macos.sh, opencore-add-kexts.sh,
ship-commit.sh, msi-boot.sh and msi-image.sh.
Each now keeps an ended flag, set at each deliberate success end, and its trap
does its cleanup as before, then turns an exit 0 short of that end into 1 and
keeps any other status. payload_test.sh takes the same form in place of the
trap its last fix removed, so it cleans its scratch on an abort again.
payload_test.sh's new fat-bundle case never ran: bundle() read its directory
argument after shifting it away, so set -u stopped the script at the first
bundle. And the stop read as a pass: the script removed its scratch from an
EXIT trap, and bash 3.2, macOS's, exits 0 from a set -u error where an EXIT
trap is set, so make test went on green (measured: the same script exits 1 with
no trap, 0 with one, even one that exits with the status it saw).
bundle() keeps its directory in a local before it shifts, and the scratch is
removed at the end of a run that finishes instead of from a trap; one that
aborts leaves it for the next run, which removes it first.
The arm64 Metal bundle is universal, arm64e and arm64, and a process maps the
slice of its own architecture: platform processes such as WindowServer map the
arm64e slice, and third-party apps, built arm64, map the arm64 slice. Each
slice has a code-directory hash of its own, but RgfxGate admitted only the
guest arch's (arm64e), so a hardened, library-validated third-party app would
have had our bundle refused and no Metal device.
pack-payload.py now also writes kExecCDHashes, every slice's cdhash with the
guest's first, and the arm64 hooks admit all of them. kExecCDHash stays as it
was, and the x86 hooks keep admitting it alone; the x86 bundle has one slice.
payload_test.sh packs a fat arm64e+arm64 bundle of our own for an arm64 guest
and checks that the hooks' decision (rgfx_cdhash_allowed over the payload's
allowed set) admits both slices' hashes and no other; it fails on the payload
pack-payload.py wrote before this change.
An arm64 WindowServer drives no IOFramebuffer (measured: a bound IOFramebuffer
consumer got no user client on 27.0.1 with SIP on), so the arm64e ReimsGraphics
is an IOMobileFramebuffer. It subclasses IOMobileFramebufferLegacy, as Apple's
own paravirtual display does on every release from 13 to 27, and drives the same
device, rings and pipe as the x86-64 IOFramebuffer front end: the arm64e build
swaps the front end, not the transport.
The class has no SDK header, so src/IOMobileFramebufferLegacy.hpp declares the
part ReimsGraphics overrides or calls, each method with the signature its symbol
in the config-2 kernel collections names. Its fields are a reserve inside which
the live class's own fields lie; Graft sizes the subclass to the live parent at
bind time and places each override by its selector (its vtable grows release to
release), so this declaration's layout is not the live one.
ReimsGraphicsMobile.cpp is the front end: it answers the class's pure methods
(no frame info, no factory configuration, no CRC), forwards the swap and
hardware methods to the class and logs them, and presents a swap's layer-0
IOSurface on the device by its surface ID, driven by the device's refreshes as
the class's vblank note. This first cut learns the class's call sequence; the
swap pipeline's exact wiring follows the trace boot.
The arm64e set is built again with it; the x86-64 kexts are byte for byte as
before. ReimsGraphics imports no Graft client symbol: Graft binds it from its
manifest, and its only arm64 deps are IOGraphicsFamily (the accelerator) and
IOMobileGraphicsFamily (the display).
RgfxGate's sources changed for its arm64 install and admission routes, so both
prebuilt sets are rebuilt from them (make -C guest prebuilt and
prebuilt-arm64e, job m3-max-10718). The x86 set's RgfxGate, ReimsGraphics and
Graft are byte-identical to the ones before: only its record of the sources
changes. The arm64e set's RgfxGate is new, and no longer imports the seven
VNOP_* functions an arm64 kernel collection does not export; what it imports
beyond the kernel's exports is Graft's four graft_* calls.
The arm64 guest kexts need RgfxGate to install our Metal bundle with SIP on,
but two things the x86 path relies on are not there on arm64:
- Seven of the VNOP calls the below-MAC install makes are not exported as
symbols (VNOP_MKDIR, VNOP_REMOVE, VNOP_RMDIR, VNOP_RENAME, VNOP_RENAMEX,
VNOP_REMOVEXATTR, VNOP_READDIR), and file creation needs VNOP_CREATE, also
unexported. RgfxGateVnop.hpp rebuilds each the way the kernel's own wrappers
do: fill the vnop_*_args struct and call through the vnode's op vector at the
index the exported _vnop_*_desc descriptor names. The op vector sits at a
measured offset in struct vnode, 0xd0 on all five config-2 releases (13.6,
14.6.1, 15.6.1, 26.6.2, 27.0.1); the install refuses on any other Darwin
major and unless a live getxattr through the op vector answers as the
exported VNOP_GETXATTR does. The arm64 writeFile creates and truncates below
the MAC layer, since no create/open/truncate MAC route is installed there.
- The admission hooks cannot inline-hook the MAC dispatchers (kernel text is
read-only and five of the six are unexported). Graft instead shadows AMFI's
mac_policy_ops table, so RgfxGate routes three operations by name
(file_check_mmap, file_check_library_validation, vnode_check_signature) and
its wrappers are called as the raw policy ops. Their signatures differ from
the x86 dispatchers by an inserted struct label* (mmap arg3, signature arg2),
and each saved original is AMFI's own mpo pointer, signed key IA under the
operation's constant discriminator with no address diversity, so it is a
__ptrauth-qualified pointer called through directly.
The arm64 code sits behind defined(__arm64e__) beside the x86 code, which
keeps its text as it was. The operation names and discriminators are checked
constants (rgfx_amfi.h), pinned by tests/amfi_test.cpp, which make test runs.
The ABI facts were measured by Ambrosia and confirmed by graft-31 (2026-11-08).
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.
The arm64 macOS 13 and later guests Ambrosia boots get a set of their own,
guest/prebuilt-arm64e: ReimsGraphics and RgfxGate for arm64e, the Metal bundle
inside RgfxGate for arm64e (system processes such as WindowServer) and arm64
(apps). `make -C guest set-arm64e` builds it and `prebuilt-arm64e` writes it with
its own sources.toml; prebuilt-check, which cargo xtask check runs, now checks
both sets.
The build picks per-architecture files with ARCH_NAME. An arm64 kernel collection
has neither AppleGraphicsDeviceControl nor IOAcceleratorFamily2, so the arm64e
kext has its own Graft declaration (src/graft-arm64e.json: IOFramebuffer and
IOAccelerator, both from IOGraphicsFamily) and its own Info.plist
(src/Info-arm64e.plist: no device control, no library of either). It leaves
RgfxDeviceControl out and references no IOAccelMemoryMap function. Graft's
consumer rules read src/Info.plist only, so the kext Makefile replaces that one
recipe for arm64e until Graft's rules take the path; make says so with a warning.
RgfxGate packs the guest's slice's cdhash, arm64e for this set.
The x86-64 set's kexts build byte for byte as before; only its record of the
sources changes. The arm64e set does not list Graft yet: it takes Graft's arm64e
build once guest/graft carries one. Its ReimsGraphics' imports all resolve in the
kernel collections of macOS 13.6, 14.6.1, 15.6.1, 26.6.2 and 27.0.1; RgfxGate's
install still calls VNOP functions an arm64 collection does not export.
Graft 1.1.1 carries the consumer SDK's fix for arm64e: its layout probe now
compiles for the consumer's own architecture and reads that architecture's
relocations. 1.1.0 always laid parents out for x86_64, which gives
IOAccelerator 266 slots where the arm64e kernels have 272, so an arm64e
consumer staged by it cannot bind. guest/graft is Graft's tools/vendor.py copy
of the v1.1.1 tag, with its record.
The x86-64 set is built again with it. Only Graft.kext changes, by its version
string: ReimsGraphics and RgfxGate stage byte for byte as before (x86-64
layouts are still 266), so the x86 guests see the same kexts.
pages_after's case 3 unmaps the second of its two pages, and every caller then
unmapped both pages again. Whatever the process had mapped into that freed page
in between, such as a new thread's malloc cache or the GPU driver's command
buffer shared memory, was unmapped under it, and the process's next touch of it
faulted. On the M3 the child of pages_without_access_on_vulkan died of SIGSEGV
at exit under GPU load (merge leg 10332), the faulting write lying in the
second 16 KiB page of the freed range.
The tests now let go through let_go_pages_after, which unmaps only the first
page after case 3. metal2vulkan's measurements of the pattern: case 3's steps
beside thread starts crashed 33 of 309 children, and unmapping once, 0 of 308;
a probe with case 3's cleanup, 34 of 6253, and unmapping only the first page,
0 of 5792.
ReimsGraphics keeps the guest's superpage record (selector 12, kext feature
1 << 8), and RgfxGate carries the bundle, whose pages slabs ask the kernel for
superpages only while the record is open (the commit before). Built by make -C
guest prebuilt on the M3 Max; make -C guest test and prebuilt-check pass on
it.
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.
RgfxGate carries the Metal bundle, whose video driver now holds a lock per
decoder context across a schedule of its pictures instead of one lock for
the process (the commit before). Built by make -C guest prebuilt on the M3
Max; make -C guest test and prebuilt-check pass on it.
ScheduleCommands held one lock across every context's list, so while the
driver made the first textures over a new output surface of one session
(which wait for the host: on the Radeon 780M about 10 ms a surface, 17 of
them as playback starts), every other session of the process waited too.
With three AVPlayers in one process the guest's first decodes ran in
lockstep, one session at a time, and the start of three players took
800-870 ms to their clocks against 183-217 ms on a native Mac.
Each context now holds a lock of its own across its list, so its pictures
still reach its session in AppleGVA's order while other contexts' lists go
on.
The exit gate's two commits left two imports out of rustfmt's order and a test's
argument list on one line past the width, which the merge's rustfmt check
refused. No code changes.
A device's VA display let go on another thread as a test process exited made its
last vaTerminate after, or beside, the exit-time destructors intel-media-driver
registers as vaInitialize loads it (73 of them, 75 after a video-processing
context), and iHD's vaTerminate then double-freed state those destructors had
already freed: test processes aborted after "ok" in iHD's frees ("double free or
corruption (out)", "free(): invalid pointer") in about 2 to 3 of 100 runs of the
workspace's tests on the Iris Xe (an i9-13900H, iHD 26.3.5, libva 2.24.1). The
exit gate (reims_vgpu_vulkan::exit_gate, armed again as each display opens) fixed
it by parking the thread that would make that late call. This records the trigger
and holds the fix.
a_display_let_go_once_its_drivers_exit_time_destructors_ran_calls_nothing opens a
real display, and on another thread drops it from an exit handler registered
before the open, so the drop runs after the driver's destructors. With the gate
armed the drop parks and makes no call; without it the drop's vaTerminate runs.
Measured on the Iris Xe (iHD 26.3.5), 20 children an arm: on this tree every
child parked (no vaTerminate), and with the gate's steps and its arming-after-
vaInitialize undone every child made the late vaTerminate. It is ignored, as the
other tests that need a VA-API GPU are, and runs on the VA-API host.
A process's exit runs its exit handlers and its loaded libraries' exit-time
destructors on the exiting thread while the library's other threads go on. The
VA crate's Calls already run every driver call as a step of the host's exit
gate, so no call of a display's runs beside those destructors (b22). But
Display::open made its own calls of libva outside that gate: vaInitialize, the
vendor query, and a failed init's vaTerminate. An open begun on another thread
as the process exits could run them beside the driver's destructors, the same
race the Calls steps close.
The open now takes one step of the gate around its libva calls: once the
process's exit began, the open's thread parks for good before it loads libva,
and an exit that begins during the open waits for it to end. The stand-in gate
the exit tests use moves from the Calls test module to va/gated.rs, so the
display's test can use it too.
For the host: a VA display opened on a thread as the process exits no longer
calls libva beside the driver's exit-time destructors. Nothing else changes;
the open's result is as before.
an_open_once_the_exit_began_makes_no_call_of_libva holds it without a GPU: a
child process whose gate is closed opens a display on another thread, and the
open parks before it would otherwise fail at once on a nonexistent node.
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.
The test of pictures decoded into dma-buf caches read each cache back by a
blit of its buffer, which copies the buffer's bytes and never reads a texture
over them. A shadow the runtime keeps of a texture over a cache's plane could
have gone on reading its first copy in after the driver's write, as an NVIDIA
host's guest saw before external_write_done let go of the shadows over a
buffer, and the test would still have passed.
It now makes a texture over each of a cache's planes, reads it once in a
kernel before the decode writes the cache, as a guest's texture over a pool's
surface is used before a decode lands in it, and compares what the kernel
reads after the decode and the platform's acquire with the CPU's copy, texel
for texel of the crop.
Each plane's texture is also made over a twin of the cache, a laid-out cache
made as any other whose memory is exported nowhere, and the route the runtime
announces for the two, in its count of shadowed textures, must be the same: an
export of a cache's memory changes no texture's route, so a runtime that made
the exported cache's textures shadows fails the test at once. On the Radeon
780M and the RX 7900 XTX every plane's texture lies over the cache's memory
(240 of 240, none a shadow).
The VA arm takes a decode's output for a target where both planes lie in one
device cache, and exports the cache's memory as a dma-buf for the import. A
cache is made a dma-buf only where its ask laid the surface out, but every
cache gave the host's video its identity, so a cache made as any other buffer
was taken for an import too: a deferred block's, and so every cache of a host
whose GPU keeps its own memory, where no ask lays a surface out. Each picture
decoded for such a cache tried the export, the platform refused it as an
invalid use (NotExportable), and the picture was copied as before. The XTX's
boot logged the refusal in every session.
A cache now keeps its life, and so gives its identity, only where its memory
was made for the host's video, exportable or a dma-buf, and the arms take
those alone. A picture for any other cache goes straight to the copy.
For the guest nothing changes: its pictures land where and as they did. For
the host no export of a cache that has none is tried, and no session logs its
refusal. The fake platform logs a dma-buf cache's make, for the test.
The Vulkan platform now makes the buffers the VA arm decodes into: a laid-out
device cache whose memory metal2vulkan's runtime makes exportable as a dma-buf
(BufferDescriptor::with_exported_as, MemoryExport::DmaBuf), at the address
Metal's space gives any such cache, with its padding unobserved and its first
plane's byte on 256 bytes of its memory as before. Its export is the runtime's
export_memory_dma_buf. A device that exports no dma-buf of a buffer's memory
(MoltenVK, or a driver without VK_EXT_external_memory_dma_buf) refuses the
making, logged at debug, and the cache is made as any other.
Once the driver's decode into such a cache is done (vaSyncSurface), the arm
says so to the platform (Buffer::external_write_done), whose device's next
submission records the acquire of the memory from VK_QUEUE_FAMILY_FOREIGN_EXT
before any of its commands, so the device's reads of the cache see what the
driver wrote. A platform whose devices need no such acquire answers Ok.
For the host: on a VA-API GPU whose Vulkan driver exports dma-bufs, the arm's
open now makes and exports a probe cache and runs the driver's target check
(kept under device-checks/va-targets), and where it passed, the device's
laid-out caches are made exportable and pictures are decoded straight into
them, with no copy. For the guest nothing changes but the time a picture
takes to land: the caches' addresses, contents and layout are as before.
The tests: the Vulkan crate's dma-buf cache test (the export's offset puts the
aligned byte on 256 bytes, the acquire is taken, a plain buffer exports none,
and MoltenVK makes none), and the VA arm's ignored test of pictures decoded
into dma-buf caches, each read back by the GPU after the acquire and compared
with the CPU's copy of the same picture, row for row of the crop.
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.
radeonsi's decodes write an imported surface only within the bytes its planes
as declared span from the luma plane's first byte: the luma's pitch times the
import's height, and the chroma's times half of it. A target whose chroma plane
lies past the luma's rows, as CoreVideo lays out the guest's outputs, lost its
chroma's last rows and had its luma's first row overwritten, with no error
(measured on a Radeon 780M and an RX 7900 XTX, Mesa 26.2.6), so the target
check failed there.
A target is now imported as tall as its planes need to be declared to span the
chroma plane's rows of the picture, the luma plane declared over the gap; the
driver writes the coded rows, and an import whose declared planes run past the
dma-buf is refused before the driver is asked. Nothing calls targets for the
guest yet, so nothing changes for the guest or the host.
The check's failure names, beside the first wrong byte, where in the memory
each plane's first row of samples is, if anywhere: the layout a driver wrote
the picture in, for the log. Nothing changes for the guest or the host.
The VA arm decodes a picture straight into its output's device cache where
it can: both planes in one cache whose memory the platform made a dma-buf,
the driver's check passed the codec and format (TargetChecks, kept under
device-checks/va-targets in the library's cache directory), the planes' rows
and starts on multiples of 256 bytes of the memory, and their rows holding
the coded picture's. The cache's memory is exported once, kept by the
cache's identity while it lives, and imported as the decode's render target
once, a new import made while the decoder still holds the last as a
reference. The picture is then in the cache once its decode is done, and the
session counts it "decoded there"; every other picture lands as before,
each reason one of a dma-buf cache was not decoded into logged once a
session.
For that, the platform's device gains a maker of padding-unobserved buffers
whose memory is also a dma-buf, and its buffers an export of it, both
refused by default; the device's laid-out caches are made so where the
host's video decodes into caches (GraphicsVideo::decodes_into_device_caches),
which the VA arm answers where a cache of a 4K picture's bytes made so
exports and the driver's check passed a codec. A host decoder is handed its
decode's output.
Nothing changes for the guest or the host yet: the Vulkan platform makes no
such buffer until metal2vulkan's runtime exports a buffer's memory as a
dma-buf, so the arm declines at its open, logged at info, and runs no check.
An opt-in GPU test decodes each of the check's streams into the decoder's own
surfaces, reads every picture back by the CPU's copy, and compares it with
the samples the stream codes: where a driver decodes a stream wrong there,
the check's failure is the stream's, not the target's. Nothing changes for
the guest or the host.
TargetChecks::of answers, for H.264 into NV12, HEVC Main into NV12 and HEVC
Main 10 into P010, whether a decode may be handed a target over the
caller's memory. It decodes short streams written here (an IDR picture of
PCM, then pictures that skip every block, so every decoded sample is known)
into targets over memfd memory laid out as a caller's must be: rows and
planes on multiples of 256 bytes, the luma plane 256 bytes in, a gap before
the chroma plane, and the HEVC picture's last row of coding tree blocks
half in it. After each picture it checks every byte of the memory: the
samples, and everything around them but each row's padding untouched. A
target's samples are overwritten once read, the next picture decoded into
another, then one over its own reference's memory, and H.264's picture
after a gap in frame_num into a target the decoder let go of, so that a
driver that reads a reference from its render target fails.
The answers are kept in a file the caller names, under a key of the
vendor string, the node's PCI IDs, libva's version and the kernel's
release, so only the first display after one of those changes runs it.
FFmpeg 9.0.2 decodes the three streams to exactly the samples the check
expects. Two opt-in GPU tests run the check, and compare a stream of the
driver's own encoder decoded into scribbled targets with the decoder's own
surfaces wherever the check passes.
Nothing changes for the guest or the host yet: nothing runs the check.
The VA crate's decoders take, per access unit, what gives that unit's
picture a render target over the caller's memory (decode_into, TargetFor):
a dma-buf of both planes imported as a linear DRM_PRIME_2 surface of the
picture's format and coded size (Target::import). The decoder asks for the
target as it makes the picture's storage, with the picture's shape, and
lends it as a surface of its pool; a target of another shape, or none, gives
a surface of the decoder's own, as before, and the frame says which
(Frame::is_in_target). A target holds its descriptor and what the caller
gives it to keep until the last picture decoded into it goes, and one of a
stalled pool is kept until the GPU is done with it.
A target stays its picture's name as a reference while the decoder holds
it (Target::is_held), so a caller makes a new import of the same memory for
a decode while the old one is held. H.264's stand-in for a lost frame copies
a target by one video-processing run rather than through vaGetImage and
vaPutImage: the driver's CPU map of an imported surface may fault, as it did
for imports of udmabuf memory on radeonsi.
Nothing changes for the guest or the host yet: no caller hands a decode a
target.
An opt-in test, for the VA-API hosts: the conformance streams decoded into the
driver's surfaces, into targets imported over memfd memory at a device cache's
linear layout (read from that memory), and into such targets each overwritten
once read, while the decoder may still reference it. It prints how many
pictures each way matched the first's, to learn where a decode can land in a
cache directly and whether the driver reads references from its targets.
Graft 1.1.0's binary, and ReimsGraphics staged by its SDK: the personalities
gated by the nub's graft-bound property and the manifest's 112-byte header,
which 1.1.0 requires. Built by make -C guest prebuilt in m3-max-10354, where
prebuilt-check and make -C guest test pass.
Graft 1.1.0's staging keeps ReimsGraphics' personalities, each gated by an
IOPropertyMatch on the property Graft sets on the device nub once it has
bound the kext. The set's stager refused any personality, as 1.0.0 staged
none; it now requires each to carry that gate.
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.
RgfxGate carries the Metal bundle, whose video driver now refuses an H.264
decode of a coded size the host does not decode at its context's create. Built
on development's sources with make -C guest prebuilt on the M3; make -C guest
test, and the guest's and the firmware's prebuilt-check, pass on this tree.
Graft and ReimsGraphics are unchanged.