Commit Graph
1477 Commits
Author SHA1 Message Date
Anees Iqbal d92883f92a 🐛 Give back the lends of a VT_MESSAGE the device cannot read
The device answers a VT_MESSAGE it cannot read with VT_STATUS MALFORMED, and
the host never sees it. The guest's kext counts that message as posted, so
it holds each lend the message named until a rels names it, and none ever
came. Each such message kept its lends, out of the kext's 64, until the kext
stopped.

Where the message's RgfxVtMessage struct reads, the device now sends a rels
for the nonzero lends it names, among its first surface_count, before the
VT_STATUS. A guest that did not take VT_MESSAGES gets nothing, as before.

What the guest sees: a rels naming the lends of an unreadable message,
ahead of its MALFORMED answer, so the kext gets those lends back.
2026-12-03 07:59:11 -08:00
Anees Iqbal 3d4169adbb 🐛 End the VT sessions at a reset before it returns
A device reset left every paravirtual VideoToolbox session running. The
reset contract (reims-vgpu-graphics device.rs) says device_reset drops what
the host keeps for the guest's processes, and that the settle returns only
once nothing begun before the reset can write the guest's memory. Neither
held for these sessions. The guest's kext lets go of every lend at its stop,
but a session open at a panic or a hard reset kept its thread, its hardware
decoder, its kept views and its lent surfaces. A decode in flight at the
reset could still write a picture into the lent surface's pages after the
reset returned, and the rebooted guest may already be using those pages.

Both device_reset and the settle now end every session, as -all does
(paravirt::Host::end_sessions). A closed session sends nothing more, and its
requests end at once. Its thread carries out no message past the one in
hand and gives back what each message lent. The settle waits, within the
reset's 30 s bound on the platform's clock, for each closed session's thread
to end, so the reset returns only once no session can write. A session still
holding a message past the bound ends the process, as GPU work past the
bound does: a write a hardware decoder or GPU copy has begun cannot be taken
back.

What the guest sees: nothing of the boot before writes its memory after the
reset returns, and a message for an old session's UUID is answered as one
with no session.
2026-12-03 07:59:11 -08:00
Anees Iqbal e604a71d8b 🆕 Count a VT lend the host drops with no rels
vt-lends less vt-lends-given-back is not a leak count on its own. A walk
ends with QMP quit while the guest runs, and the device's release there can
end the open sessions before the exit counts line is written. Their rels
then go on an ended link, which sends nothing, and a reset closes every
older link the same way. So lends that were in flight at the quit or the
reset show in that difference without any leak, and the line cannot say
which.

A leak is a lent surface the host drops without letting go of it. The S8-1
reply in the race was one: no rels names it, and the kext holds the lend
until it stops. The host now notes each surface as it lets go of it, in
LentSurface::letting_go, before the rels is sent, whether or not it is sent.
A GuestSurface dropped without that note counts vt-lends-dropped-held, and
the first one is logged. The count is exact on any counts line, whatever
sessions are open. vt_message now checks its message's runs before it makes
its surfaces, so a refused message drops none unnoted. Nothing changes for
the guest.
2026-12-03 07:39:19 -08:00
Anees Iqbal 9ea707bc68 🆕 Count the VT lends the host holds and gives back
The guest's kext holds at most 64 lends of IOSurfaces at once for its
VideoToolbox messages, and once they are all taken, it answers every further
message kVTParameterErr without posting it. A lend the host never gives back
keeps its slot taken until the kext stops, so a leak slowly turns the guest's
hardware video off. Nothing on the host showed how many lends it held.

The host now counts each lend a VT_MESSAGE gives it as vt-lends, the most
it held at once as vt-lends-live-most, and each lend a rels it sent gave
back as vt-lends-given-back. This covers the rels a refused message sends
too. vt-lends less vt-lends-given-back is what the host holds, plus any
rels that went on a link a reset or the device's end had closed. Nothing
changes for the guest.
2026-12-03 07:39:19 -08:00
Anees Iqbal 04aef9e84e 🆕 Count deferrals refused for runs that are not whole pages
A deferred IOSurface block whose SURFACE_PAGES carries runs that are not
whole guest pages summing to its surface's bytes, or that carry no page, is
answered INVALID_ARGUMENT with nothing made. Until now that refusal showed
only as a warning, logged once per boot and then folded into the repeated
lines, so a walk could not say how often a surface was refused this way, or
how big those surfaces were.

The host now counts each such refusal as surface-carry-refused, and the
surface's bytes as surface-carry-refused-bytes, on the degradation counts
line. Nothing changes for the guest: the answer is the same refusal as
before. A deferral refused for its flags is not counted under these codes.
2026-12-03 07:39:19 -08:00
Anees Iqbal fca18a89bb 🐎 Keep the last sizes' VA-API processing contexts
A guest's previews make one short video session after another, each with
buffers of its own, and each size's video-processing context went with its
last import. So every session's first run was a new context's first run in
the driver, a few milliseconds on radeonsi. Measured before, on the Radeon
780M (Mesa 26.2.6, m3-max-83333): a 400x258 HEVC thumbnail's frame took 5.54
to 6.83 ms from its take to its signal across 12 sessions of one size, its
run's vaEndPicture 4.83 to 6.14 ms of that.

The imports' table now keeps the contexts of the 4 sizes imported last
(KEPT_CONTEXTS) past their last import, at most 4 at once beside those live
imports hold, and holds no surface: a context is made on none. A size
imported again moves to the back; a size imported past the 4 pushes out the
one imported longest ago, destroyed once no import holds it; the rest go with
the table, which the VA-API arm holds, so at the arm's teardown. No time
bounds it: the decoder cache's idle epoch is Windows' alone, where no dma-buf
is lent and so no import or processing context is made. A unit test fills
the table past its cap, and the 780M's hardware test pushes a kept context
out with 4 other sizes.

What 4 kept contexts, each run once, freed as they went, by the driver's
fdinfo for the process: nothing on the Radeon 780M (radeonsi, m3-max-83634),
and 7,244 KiB of drm-total-system0, 28 KiB of it resident, on the Iris Xe
(i915, intel-media-driver 26.3.5, m3-max-83635), about 1.8 MiB a context.

Measured after, the same thumbnail on the same 780M, in one job alternating
A (this change) and B (the tree without it), each arm a boot of 6 sessions 4
s apart and 6 back to back (m3-max-83795): with it, every session but a
boot's first took 1.11 to 1.97 ms from its take to its signal (median 1.55
ms, 22 sessions), against 5.29 to 6.83 ms without it (median 6.12 ms); a
boot's first session of the size, on a new context, took 5.8 to 6.8 ms in
both. The guest's warm qlmanage thumbnail took 0.072 to 0.081 s with it and
0.075 to 0.090 s without.
2026-12-03 07:23:27 -08:00
Anees Iqbal f29d3abfc5 📝 Say that the host does not bound a lock's hold wait [ci skip]
With the kext's 1 s bound gone, a lock waits as long as the host's span
lasts, and nothing on the host bounds that span: read from the runtime's
code, a make whose batch holds an upload into memory another API shares
waits for guest GPU work submitted with it. design.md now says the wait is
not bounded by the host, and gives the 57.9 ms span as what one walk on an
Iris Xe showed, not as a limit.
2026-12-03 07:22:33 -08:00
Anees Iqbal 1f21a92e10 📝 Give the hold's longest measured span alone [ci skip]
The span the docs gave came from one arm of the walk, with a reason for it
the walk did not establish. The longest span the walk measured on the Iris
Xe is 57.9 ms, its cause not yet split: design.md and HOLD_BEGIN_BOUND's
comment now give that alone, and design.md no longer says what the make
waits on.
2026-12-03 07:19:10 -08:00
Anees Iqbal f9cc3d5f91 📝 Give the hold's span on an Iris Xe as it stands [ci skip]
design.md's hold section held a placeholder for the longest span a lock
waits on the hold. A guest's walk on a Linux host's Iris Xe, with the
runtime's restoring make no longer sharing its batch with the guest's command
buffers, measured 57.3 ms at the longest and 62.2 ms over its 8 spans, no
begin's wait given up and nothing declined no-lock-hold.

HOLD_BEGIN_BOUND's comment now says what holds: how the runtime's restoring
make waits, and the span the walk measured against the bound, with no runtime
commit, date or job in it.
2026-12-03 07:19:10 -08:00
Anees Iqbal 8cff64e8f9 🐛 Wait out the host's hold span with no bound of its own
A read-write CPU lock waited 1 s at most on a raised hold word, then went
on with the word still raised. The bound was there because any process
holding the surface could store RAISED in the block's header and keep it up.
Now only the kext and the host write the word, so nothing but the host's
span keeps it raised, and a lock that goes on inside the span loses its
writes to the span's copy back.

A lock now waits as long as the host's span lasts. The wait still ends once
the word is lowered, the device stops or resets, or the thread is aborted.
kPastBound, the bounded wait, its count and the kext's log line for a lock
past the bound are gone, so a walk's count of such locks reads 0 from now.
What the guest sees: no lock goes on with the word raised.

Both kext sets, guest/prebuilt and guest/prebuilt-arm64e, are built again
from this tree.
2026-12-03 07:11:01 -08:00
Anees Iqbal 2e1b9c570f 🔒 Keep the surface hold word where no process maps it
The hold word lay at byte 8 of a cached block's header, which every process
holding the surface maps writable: any holder could store RAISED there and
hold the other holders' read-write CPU locks of the surface. The word now
lies in the block's own part, which no process maps. Each block laid out in
place keeps a 4 KiB hold page past the span its holders map and before its
runs, and the word is the page's first u32, at region offset runs_offset -
RGFX_SURFACE_HOLD_ROOM, where the host finds it from SURFACE_PAGES. The kext
maps the page with the header and stores 0 there as it caches the block, so
only the kext and the host write the word.

The hold moves to FEATURES_EXT bit 2 (feature bit 66). Bit 1, the hold in
the header, is retired: no host offers it, a write of it takes nothing, and
it is never reused. A mixed pair therefore takes no hold. A guest with an
older kext on this host, or this kext on an older host, gets no image made
in place over a cached surface's pages (declined no-lock-hold) and no
answered creates of textures over pages buffers. Mixed pairs come only from
a stale install, since reims-ctl carries the kext sets with the host.

The host refuses a word that would lie in the block's first 4 KiB, where the
header is: such a block has no hold word, is counted (rt-shape-hold-no-word)
and its makes that copy are declined no-lock-hold. Our kexts lay out none.
The host lowers the word on every exit of a make whose span it opened: rt's
after, or the fence's own drop where the make fails or unwinds past it. As
before, a lock's wait also ends where the device stops or resets, or the
thread is aborted; rgfxHoldSleep now carries those ends, and the native test
holds them. The kext logs the live in-place blocks and what their hold pages
take of the region, and the host logs its holds with the no-word count, so
one boot per guest reads both.

What the guest sees: each in-place block takes 4 KiB more of the region on
x86-64, and 0 or 16 KiB on arm64, where blocks are whole 16 KiB pages; no
process can hold another's locks through the word. The option ROM's record
takes the wire header's new hash; the ROM's bytes are unchanged. Both kext
sets are built again with the next commit.
2026-12-03 07:11:01 -08:00
Anees Iqbal 0fc8734741 🐛 Bound a CPU lock's wait on a raised hold word at 1 s in all
A read-write CPU lock of a cached surface waits while the block's hold word
is raised, 1 ms a sleep, ending only once the word is lowered, the thread is
aborted or the device stops. The word lies in the block's header, which each
process holding the surface maps writable: a process that stored RAISED there
held every other holder's read-write locks of the surface, WindowServer's
among them, for as long as it kept the word up. A Mac's locks wait for no
other process.

A lock now waits 1 s in all at most, then goes on with the word raised,
logging the boot's first such lock and counting each. Guests' walks measured
host spans of up to 63.9 ms on an Iris Xe (m3-max-83207) and 33.0 ms on a
UHD 630 (m3-max-83316), while the make shares its batch with the guest's
command buffers: the bound is about 15 times that. What the guest sees: a
lock on a word held up past 1 s goes on; a real span over 1 s, possible only
while rt shares its batch with a guest command buffer of over 1 s, could lose
that lock's write. The native test holds the bound and a span inside it.
Both kext sets are built again.
2026-12-03 06:05:46 -08:00
Anees Iqbal 3009883f65 🐛 Post an answered texture create as an ask its close waits for
The kext admits kRgfxSubmitAnswered for a texture over a pages buffer and
waits for its COMPLETE with no deadline. The host answers such a create only
while the buffer it names is the context's (answers_create). A Submit read
the context open under the list lock and posted after, and releaseContext,
which waits for the context's asks but not for Submits, could post the
context's CONTEXT_CLOSE in between. The create then reached the host after
the close, found no buffer, and was never answered: the creating thread
waited until its process ended.

An answered Submit is now an ask (rgfxSubmitOpen): begun only while the
context is open and its close has not begun, and ended once its wait ended,
so the close waits for its answer and its create goes before the
CONTEXT_CLOSE. The host answers it while the context is open, so the wait
ends. Other Submits read the context as before. The native test stages a
close arriving while an answered Submit sits between its read and its post.
What the guest sees: no answered create hangs at a close. Both kext sets are
built again.
2026-12-03 06:05:46 -08:00
Anees Iqbal 9497aa621d 🐎 Take a kept NVDEC decoder for a smaller 4:2:0 picture size
A kept NVDEC decoder now serves a new decoder of its codec, chroma format
and bit depth whose size is no larger on either side, with surfaces
enough, for 4:2:0 at 8 and 10 bits; other formats take a kept decoder of
their own size alone, as before (docs/video/bugs.md, D32). One of the
asked size is taken first, then the smallest larger one, so a larger one
stays for a larger stream. A taken decoder is reconfigured to the asked
size before its first decode where it was last set to another, and its
pictures decode into its larger surfaces at that size. Where that
reconfiguration fails, the kept decoder is destroyed and one is made.

What changes for the guest: a first video session of a new, smaller size,
after a larger session of its codec, format and depth whose decoder has
surfaces enough, no longer pays cuvidCreateDecoder, 43.3 ms of a 400x258
HEVC session's first decode call on an RTX 3090 (m3-max-83275). A kept
1920x1088 decoder taken for 400x264, its reconfiguration included, took
0.08-0.09 ms, against 18-25 ms for one made in the same process
(m3-max-83382). The pictures are the same: the hardware tests decode
H.264, HEVC Main and Main 10 streams of NVENC's, VP9 profile 0 and 2 and
the size-changing VP9 stream, and AV1 Main streams on a kept larger
decoder, each against its own MD5s (m3-max-83425). Left at the larger size
and reconfigured only to map, a 400x258 H.264 stream read back other
pictures (m3-max-83368), hence the reconfiguration at the take.

It does not reach the x86-64 macOS 26.7.2 guest's Quick Look thumbnail of
that 400x258 movie: its first session asks for 8 surfaces, and the one
larger decoder of its format kept by then, the wallpaper's 1024x1024 HEVC
at 8 bits, has 5 (m3-max-83451).
2026-12-03 04:56:42 -08:00
Anees Iqbal 64fa79edf5 🐛 Never destroy the bundle's statics as its process exits
A static or global object with a destructor is destroyed as the process exits,
while the app's other threads may still run the bundle's code: a command
buffer's completion, a decode, a log line. A thread that then took one of the
bundle's static locks would end the process with "mutex lock failed: Invalid
argument" as the app quit, so a guest app could abort at quit, with a crash
report. No run has shown it. A review after the shell_tests race found 42 such
objects in guest/bundle/src: locks, a condition variable, sets, strings, class
tables, a shared pointer, and the video driver's session and driver lists. None
has a destructor whose work the exit needs (a flush, a file's close).

Each is now never destroyed (static T &x = *new T(), as RgfxLibraryStream's
lock already was). A guest sees nothing new while it runs; at its exit the
bundle frees none of them, and a thread still in the bundle finds them whole.
tests/bundle_exit_check.sh, first in the bundle's make test, fails where the
bundle imports ___cxa_atexit, which the compiler calls to register a destructor
at exit, and names the objects that do: on the tree before this commit it fails
for x86_64 and arm64, naming 30 objects. The bundle is the guest's only
user-space code; the kexts do not exit. Both guest kext sets are rebuilt
(RgfxGate carries the bundle), and docs/lessons.md has the trap.
2026-12-03 04:15:27 -08:00
Anees Iqbal 019b98b4c0 ✅ Keep the protocol tests' queue fixtures past the test
A test's command queue can outlive the test: the block that runs a command
buffer's record on the queue's completion queue holds the queue until it
returns, and the test's wait wakes inside the record. The test can then return
and free its stack serializer, rings and region, and the queue's end, on the
completion queue's thread, posts its barrier fences' destroys through the freed
serializer. shell_tests aborted with "mutex lock failed: Invalid argument"
once in 30 runs on the M3 Max beside a CPU load, right after
test_commit_behind_an_untaken_write_fails.

protocol_tests' QueueFixture and its four tests that build their fixtures by
hand now never free what a queue borrows, as queue_tests' and shell_tests'
fixtures already did and as the guest's device never frees its serializer. The
bundle's code is unchanged: a guest's queues borrow the device's serializer,
which lives as long as the process. The trap goes in docs/lessons.md.
2026-12-03 04:15:27 -08:00
Anees Iqbal a26d61a3bd 🆕 Count rt's precision notes at each make, the first logged
metal2vulkan-runtime records where what it makes can answer otherwise than
Metal on the host's GPU, its precision notes, fixed at the make and never
decided at a draw, and pin R gives each a stable degrade code. Nothing here
read them, so a boot's log said nothing of them.

The rt platform now reads them right after each make that succeeds: compute
and render pipeline states, sampler and depth-stencil states, textures (views
among them) and a render encoder's pass. Each note is counted under rt's own
code, metal2vulkan-degrade-<note>, kept as rt names it so the counts line
matches rt's catalogue, and the process's first of each code writes one line
on stderr. The process holds one rt device, so that is once per device.

What the host's log shows: for each code, once,

  reims-vgpu: <call>: metal2vulkan-runtime made it with a precision note
  (<code>): its answers there can differ from Metal's on this device; the
  first of its kind, each make that carries it counted

and, on the degradation counts line, each code with how many makes carried
it. Nothing is read or counted at a draw, a dispatch or a blit, rt's notes of
commands are not counted, and there is no setting. The tests show one first
line per code, counts that run, and draws and dispatches under noted states
counting nothing.
2026-12-03 03:52:44 -08:00
Anees Iqbal 029fbe1ed7 🐛 Place the bundle only on a volume that takes writes
The placement writes below the VFS, which skips its read-only check, and it
wrote into /System/Library/Caches without making that check itself, where the
BaseSystem's install makes it for /Library. Every release we keep firmlinks that
path to the Data volume, so no boot has reached a read-only place, but where the
path resolved to the sealed system volume the kext would write into it.

rgfx_place.h's steps now ask the file system whether the volume a path resolves
to takes writes (KernelPlace::writable: vfs_isrdonly of the path's mount, or of
its nearest existing ancestor's): placing on a read-only volume writes nothing
there and leaves the tree at /Library/GPUBundles, and a placed tree on one does
not move back, so the install stages nothing and the placement stays as it was.
place_test covers both over a directory whose volume answers read-only while
its writes still succeed, as the kext's do. For the guest: nothing changes on
the releases we keep; the check adds one lookup per pass.
2026-12-03 02:57:54 -08:00
Anees Iqbal 59cb1b53ff 🐛 Answer a release or re-naming of pages after a make's span
A make in place copies a cached surface's pages out and back around its image's
first layout move. A BLOCK_RELEASE of the block, or a SURFACE_PAGES that names
the block's pages again, did not wait for that span: either one's answer lets
the guest take the pages back, and the make's copy back could then write the
bytes it saved over what the guest wrote there next.

Both now wait for the span before they are answered, as a begin that uses the
block does, at most the same bound, and count as the begin's waits do. The
tests take a release and a naming of the pages inside a make's span on a thread
of their own and find each answered only after it.
2026-12-03 02:57:49 -08:00
Anees Iqbal 40dc87b946 🐛 Refuse a make in place over pages that lack the cache's write
A command buffer that writes a surface's device cache can end between the
host's decision to make a texture in place over the surface's pages and the
make's fence. The cache then holds a write the pages lack, and nothing kept a
download of the surface out of the make's span: the download copied the write
into the pages, and the make's copy of the bytes back undid it, while the host
held the pages as having it. The guest's lock then read the old bytes.

The fence now refuses the make as busy wherever the decision's own "behind"
rule holds at the fence: the shape takes the host's own image, and a later
begin moves it in place once the pages hold the write. A block free of that
holds no write the pages lack, so a download inside the span copies nothing.

The test runs the write's begin on a sibling decoder between the decision and
the fence, and a download inside the span, and reads the write in the pages.
2026-12-03 02:57:49 -08:00
Anees Iqbal 94ec584792 📝 Note how a fake's own copy of guest memory hides a race [ci skip]
The first red test of a CPU write lost inside a make in place passed before any
fix (job m3-max-82675): the fake platform's import of the pages was a buffer of
its own, so the make's save and write-back never reached the pages the guest's
lock wrote. docs/lessons.md now says how to spot the next such test.
2026-12-03 02:57:49 -08:00
Anees Iqbal 0b44900694 🐛 Keep guest writes out of a make's copy of a surface's pages
On a host whose GPU shares the CPU's memory, rt makes a texture in place over
a cached surface's pages by copying the bytes under it out and back around the
image's first layout move. A guest write to those bytes inside that span was
lost (the two tests of the commit before), where a Mac keeps it. The make now
runs rt's RestoreFence around the span, which keeps its writers out:

- The guest's read-write locks. A new device feature, FEATURES_EXT bit 1
  (SURFACE_HOLD), is taken in a new register, DRIVER_FEATURES_EXT (0x05c).
  Where the driver took it, the host raises a hold word in the cached block's
  header (offset 8) before the copy out, rereads the surface's CPU generation
  after a full fence, and refuses the make as "unsettled" where a lock moved
  it. A lock that finds the word raised sets WAITED and waits. The host lowers
  the word once the bytes are back and, where a lock waited, posts
  SURFACE_HOLD_LOWERED (0x413), whose vector wakes it.
- The device's own writers. The make is refused as "busy" where a command
  buffer that uses the cache is begun and not ended, or a copy into its pages
  or a fill from them is in flight. Otherwise the block is marked made, and a
  begin that uses it waits for the span's end, at most 100 ms.
- The thread that made a texture over a buffer of its own pages. Where the
  driver took the hold, the host answers each TEXTURE_FROM_BUFFER and
  LINEAR_TEXTURE_FROM_BUFFER over a BUFFER_OVER_PAGES buffer with a COMPLETE
  once carried out, so the thread's writes after its create follow the span.
  This is a device-wide rule (A), not a per-block flag (A'): on Linux, whether
  a block's make restores (its import by address, not as dma-bufs) depends on
  the views' folds at their budget and on rt's refusals, which come after the
  pages are answered, so no answer can carry it exactly. The rule only waits
  more, and its waits are counted (rt-pages-texture-creates-answered, -ns).

A driver that does not take the hold, as the kexts before this change, gets no
make that would copy the bytes out and back: it is declined as no-lock-hold,
and the shape takes the platform's own image. That is decided up front where
every import of pages lies in host memory (a Mac, Windows), and per block on
Linux once a make over the block's import ran the fence.

What the hold does not cover: a guest thread writing those bytes with no lock,
or another device's DMA, inside the span; and a read under a read-only lock
then may see other bytes. docs/known-issues.md says so, with the hosts.

The two red tests pass. New tests cover a lock ahead of the hold, a command
buffer and a copy in flight, a begin inside the span, the device's register
and event, and the answered creates. Each writer kind's tests fail with its
check switched off (job m3-max-82923).
2026-12-03 02:57:38 -08:00
Anees Iqbal 30d1641878 📝 Record the placed update's trap in lessons.md [ci skip]
A step in front of an atomic replace removed the live tree the replace was to keep, and the rename's lookups followed a final link. Both were found in review; the lesson names place_test's red and green runs and how to spot the next one.
2026-12-03 02:32:00 -08:00
Anees Iqbal 95ca58c498 🐛 Correctness fix: keep a whole bundle through a placed update
A failed update on a placed system left no bundle at all. To write at the
bundle's path as before, the install removed the link and the placed tree,
the live bundle, before it staged; a stage or final rename that then failed
(a write error, a full Data volume) left nothing in /Library/GPUBundles or in
the placed directory, so that boot had no Metal device. Before placement the
swap always kept the old tree whole, as installBundle's comment promises.

The install now removes the link and moves the placed tree back to the
bundle's path, so the swap exchanges it whole and a failed install leaves it
there; the pass then places whichever tree is at the bundle's path, the new
one or the old. A link that cannot be removed, or a tree that cannot move
back (the link is made again), leaves the placement as it was and stages
nothing, and a link still at the bundle's path when the staged tree is to go
in stops the rename. A placement that finds no tree at the bundle's path
moves nothing, so a placed tree left by a pass that ended between the move
and the link stays for the next install to move back.

The rename looks both ends up without following a final link, as rename(2)
does: a followed link at the target handed VNOP_RENAME(X) the link's target,
a directory elsewhere, under the link's name and parent. The AppleGVA
preference's atomic write shares the rename.

The steps' order moves to rgfx_place.h, over the file system as a parameter,
and tests/place_test.cpp runs it over real directories with each step made to
fail in turn.
2026-12-03 02:32:00 -08:00
Anees Iqbal 0a7c92abfd 📝 Say what the device answers of samplers, tiles, dylibs [ci skip]
The oracle doc's Q9 "ours" column and Q30, and the register's %spi-no-dylibs
reason, still told what the device answered before the runtime became its
platform. Each now says what the code answers, citing it:

- maxArgumentBufferSamplerCount is 3999, the runtime's sampler indices, not 0;
- the sparse tile sizes are 0x0x0, the AMD's: the runtime has no sparse
  textures, and the device info carries no tile;
- supportsFunctionPointers is the runtime's YES, and supportsDynamicLibraries
  its NO, beside the lane's NO for supportsRaytracing;
- Q30: the device makes no dynamic library: both dylib queries answer NO, and
  a make that reaches the host answers its refusal, where the old paragraph
  said every answer was the AMD's;
- %spi-no-dylibs: the base's NO is the lane's answer, as no dynamic library
  is made, where it said the lane made a compute pipeline's.
2026-12-03 01:22:50 -08:00
Anees Iqbal cca4d4b7e5 📝 List the 3D model previews that quit on Apple silicon guests [ci skip]
On an arm64 guest on macOS 27, Preview and Quick Look quit when they show
a 3D model: macOS draws part of the model's lighting into a texture format
that Metal lets programs write only on a GPU that reports an Apple family,
and our device reports none until it can do everything a family promises
(docs/graphics-kext/design.md, item 10). Intel Mac guests show the models.
2026-12-03 01:22:50 -08:00
Anees Iqbal 55bed1857c 📝 Say rt refuses memoryless textures, in the oracle's Q5 [ci skip]
Q5 said our stack makes memoryless textures. At pin 208360ab6d
metal2vulkan's runtime refuses one at its create (Gap::MemorylessTexture),
and the platform answers the guest nil, counted under rt-refused-gap
(rt_refused_texture_create), so the note says that.
2026-12-03 01:22:50 -08:00
Anees Iqbal 3902b5dbe1 📝 Say the lane carries Apple1's to Apple3's pieces [ci skip]
design.md item 10 still said Apple3 waited on indirect command buffers. The
lane has carried them, with a compute one's memory barriers and binary
archives, since they joined WIRED in device_info.rs, which already says it
carries Apple1's to Apple3's pieces and holds every Apple family at none
until each piece up to Apple7's is carried. The item now says the same, and
names the first pieces it lacks, Apple4's tile pipelines and imageblocks.
2026-12-03 01:22:50 -08:00
Anees Iqbal 174f2a4d4e 🐛 Count the placed bundle's mappings in check-boot's amfi-map
On a full system RgfxGate now places the Metal bundle's tree under
/System/Library/Caches/ai.aneesiqbal.reims-graphics and links
/Library/GPUBundles/reims-graphics.bundle to it, and Metal maps the
executable by the placed path. amfi-map counted WindowServer's mappings of
GPUBundles/reims-graphics.bundle alone, so every arm64 boot with the
placement read "maps the bundle 0 times" and failed, while
windowserver-metal and metal-app passed on the device (arm64 26.6.2 under
TCG on the 780M). It now counts mappings by either path.

The placement was checked by walks that ran no check-boot; docs/lessons.md
gains the trap, and docs/qemu.md says which paths the check reads.
2026-12-03 01:22:18 -08:00
Anees Iqbal 8c6386f0b9 🐛 Place the Metal bundle under /System, linked from GPUBundles
A sandbox profile built on the system's base profile lets its process read
under /System, and /Library/GPUBundles only where it also takes the system's
graphics rules. Sandboxed processes without them were refused our bundle's
files and found no Metal device on our GPU, where on a real Mac they have
one: on arm64 the 3D-preview service, on x86 and arm64 the attributed-string
agent, and other agents.

On a full system RgfxGate now moves the installed tree to
/System/Library/Caches/ai.aneesiqbal.reims-graphics, a Data-volume directory
whose path is under /System, tags it like the bundle, and makes
/Library/GPUBundles/reims-graphics.bundle a tagged symbolic link to it, below
the MAC layer like the install's other writes. The signature pin and the
install writes take the placed directory too. An install or update removes
the link and the placed tree, writes the whole tree at the link's path as
before, and places it again; a pass that finds the link only tags it again.
Base systems keep the tree in /Library/GPUBundles.

For the guest: Metal follows the link and maps the executable by the placed
path, IOGPU trusts it there, and no process is refused a read of either path.
Walks with the placement (m3-max-82522, -82508, -82615), each on its first
boot and, on x86, again after the guest's own restart: arm64 27.0.1; x86
11.7.11, 12.7.6, 13.7.8 and 26.7.2. Every release we keep reads /System in its
base sandbox profile (read from the guests' files: arm64 13.6 to 27.0.1, x86
11.7.11 to 26.7.3). On arm64 the 3D-preview service then reaches the open of
our user client, which its profile still refuses.
2026-12-03 00:55:26 -08:00
Anees Iqbal ac3d0a2804 📝 Say what the docs' Apple claims rest on, not how learned [ci skip]
The docs named sources for Apple's behaviour that this public repository
does not cite. A claim here cites a public header or SDK, or a probe, walk
or test of ours, or states the behaviour plainly.

Each such clause in design.md, dgpu-oracle.md, lessons.md, qemu.md and the
video docs now states the behaviour, with the release it holds on, and
keeps every measurement and boot of ours it cited; dgpu-oracle.md's one
row of that kind is marked unmeasured. testing.md's "read" tag now names
only our code, an open-source driver's, and what a public header or SDK
states.
2026-12-02 21:58:12 -08:00
Anees Iqbal 0b19de3e09 📝 Say which device a shared texture's token names [ci skip] 2026-12-02 21:51:00 -08:00
Anees Iqbal 4614fc15d4 📝 Describe textures shared across processes and FEATURES_EXT [ci skip]
design.md says how a shared texture crosses processes: the token IOSurface
as the capability, the kext's two calls and their names, one host storage
with a view per holder, what holds the name and the storage, the bound on
names, the feature that negotiates it, and the residuals. The register
table gains FEATURES_EXT at 0x058, a guest-visible read, the selector map
gains 23 and 24, and the kext's word gains SharedTextures.
2026-12-02 21:51:00 -08:00
Anees Iqbal c0a9aa89d3 🆕 Share textures across processes in the guest's Metal bundle
What changes for the guest: where the device offers shared texture names
(FEATURES_EXT) and the kext offers its calls, newSharedTextureWithDescriptor:
makes a Private texture by SHARED_TEXTURE_CREATE, newSharedTextureHandle
answers Metal's own handle over the texture's token IOSurface, which the
kext names at the first handle, and newSharedTextureWithHandle: opens the
texture the token names through the kext, with its descriptor and the
handle's label. supportsSharedTextureHandles answers YES there, as Metal's
devices do, where the IOGPU base answered NO, and a shared or opened texture
is shareable. Each was nil before, so the image viewer's 3D window stayed
white: HydraRenderingService draws into a shared texture and hands it over.

A host or kext without them, or any storage but Private, still gives nil
and posts none of the four messages; the creators take the plain create's
nil rules, as Metal's devices answer both alike (oracle_shtex). The
withResourceIndex: twin stays unsupported: the device picks every resource
id itself. The ledger row now says the platform's own shared textures stay
unbuilt and the guest's do not take them.
2026-12-02 21:51:00 -08:00
Anees Iqbal 6ae98ac228 📝 Name in D30 the shape kind rt refuses in place on the M3 [ci skip]
The census's kind lines named the one kind of shape whose move in place rt
refused on the M3, as host-memory: RGBA8Unorm, 18 by 18, of usage 0x7 in all
its textures. D30 names it, so it is not found again.
2026-12-02 21:47:26 -08:00
Anees Iqbal 8ad2f6c454 📝 Say in D30 where shapes lie in place and where O still copies [ci skip]
With the shapes' images in place over their pages on a device of one memory,
and a deferred surface's shapes moved there once its pages hold them, D30's
straight download is left on discrete and virtual GPUs, where rt makes no
image in place over host memory, and for the shapes rt refuses in place. The
entry now says so, with the M3 census: 3,729 straight downloads without the
images in place against 24 with them, and the restore copies each make costs.
2026-12-02 21:47:26 -08:00
Anees Iqbal 5c91a5b507 🆕 View a video plane from a texture that writes it
A recording's colour conversion writes its NV12 (or P010) through R8Uint and
RG8Uint (R16Uint and RG16Uint) textures declaring ShaderWrite. Each took the
storage shape of its plane's extent, an image of its own beside the plane, so
rule 1 copied every write into the plane (rt-shape-order-case,
rt-shape-order-copies). The red test lays its surface out as an RTX 3090
recording boot's (m3-max-81235).

On Unix hosts a video cache's surface's planes are now asked ShaderRead |
ShaderWrite | RenderTarget | PixelFormatView (0x17, was 0x15), and a texture
over a plane whole that takes storage while declaring ShaderWrite and no use
the plane's image lacks is a view of the plane (Caches::writable_plane): no
storage shape and no order copy. Such a writer asks the surface where it comes
first. ShaderAtomic and the Unknown usage keep the storage shape, and so does
every texture of an extent whose storage shape the cache holds. The platform
picks the surface's form for that usage: in place, or rt's copy form where the
device holds no linear image for it (NVIDIA's dma-buf route); the path takes
the images rt answers and assumes neither.

The Windows drawn planes keep 0x15 under their own constant, DRAWN_USAGE:
their Direct3D 11 textures are bound RENDER_TARGET | SHADER_RESOURCE, without
UNORDERED_ACCESS, and rt refuses ShaderWrite on such an import, so a texture
that writes one keeps the storage shape and its counted copies, now ledger
line D31 in docs/video/bugs.md.

What changes for the host: the planes' usage the device asks of the
platform's exported surfaces on Unix hosts. For the guest: the same pixels,
through one image where there were two.
2026-12-02 20:05:33 -08:00
Anees Iqbal 0ed439f58c 🐛 Keep the accelerator's region and registers until it is freed
A CPU lock of an IOSurface in any process (the surfaces' control function,
RgfxAcceleratorLocks.cpp) and the release worker reach the accelerator with
no client of their own, and write a block's runs through its region
(writeRuns), which can come after the accelerator's stop. The stop's
teardown released the region and the registers' mapping, so such a write
would reach a released mapping, a kernel panic.

No path in the lab was shown to run this stop while such a write is due:
kmutil refuses to unload the kext from the boot kernel collection, QEMU
refuses device_del, and a restart was not shown to reach stop(). The hole is
in the teardown the tree ships, so it is closed now rather than once a guest
meets it.

The region and the registers' mapping now go at free(), and a failed start
leaves them to it too. Nothing changes for a guest: boots, a restart and a
shutdown, on the fixes' own kext set (potluck job m3-max-80704), are
unchanged.
2026-12-02 20:01:57 -08:00
Anees Iqbal be40fe5013 🐛 Keep the framebuffer's device mappings until it is freed
The accelerator and its user clients are the framebuffer's siblings on the
PCI device, not its clients, so IOKit stops them in no set order. The
framebuffer's stop released its rings, control data, cursor slot, registers
and region while an accelerator client could still post: tryPost reads the
ready flag outside submitLock and the doorbell is rung outside it, so a post
that read it ready as the framebuffer stopped would write through a released
mapping, a kernel panic.

No path in the lab was shown to run this stop with clients alive: kmutil
refuses to unload the kext from the boot kernel collection, QEMU refuses
device_del, and a restart was not shown to reach stop(). The hole is in the
teardown the tree ships, so it is closed now rather than once a guest meets
it.

Teardown now resets the device and lets the work loop go, and the mappings
go at free() (releaseMappings), once nothing holds the framebuffer; a head's
region goes there too. Nothing changes for a guest: boots, a restart with
clients holding the device, and a shutdown, on the fixes' own kext set
(potluck job m3-max-80704), are unchanged.
2026-12-02 20:01:57 -08:00
Anees Iqbal 868ae658ba 🐛 End the process where an encoder goes without its end
Metal ends the process where a blit, compute or render encoder is let go
without its endEncoding, on the M3 Max, the AMD 5300M and the Intel 630, in
_MTLCommandEncoder's dealloc; a parallel render encoder's sub-encoder let go so
ends it at its release on the x86 Macs and at the parallel encoder's end on
the M3 (dgpu-oracle.md, Q53). The bundle's encoders let go silently, and the
buffer went to the host with the encoder open at its commit.

Each encoder now ends the process in its dealloc where its command buffer's
hold, which only its end lets go, is still there, with Metal's words, before
anything reaches the host. A sub-encoder is held by its parallel encoder to
that encoder's end, so one let go without its end ends the process there, as
on the M3. What changes for the guest: such a process ends as the encoder
goes, as on a Mac, where it used to go on until its commit.
2026-12-02 20:01:57 -08:00
Anees Iqbal 1c90b78fb3 🐛 End the process at an encoder made with another open
The M3 Max and the Intel 630 end the process where a command buffer makes an
encoder while one of its encoders is open, a blit in a blit and a compute in a
render encoder measured; the AMD 5300M makes it, and fails the buffer of a
compute encoder made in a render encoder (dgpu-oracle.md, Q53). The bundle
began the second encoder inside the first, so the buffer's stream went to the
host with nested encoders, which it faulted.

Every encoder maker now ends the process there, before the buffer's stream
reaches the host, in the M3's words on every guest: the M3 is the
latest-macOS target, and no guest is given the AMD's second encoder (the
planner's ruling, 12-02). What changes for the guest: such a process ends as
the encoder is made, as on the M3 and the Intel 630, where its buffer used to
reach the host and fault.
2026-12-02 20:01:57 -08:00
Anees Iqbal 47e5f26fb0 🐛 End the process at a commit with an encoder open
Metal ends the process at a commit made with an encoder of the buffer open,
on the M3 Max, the AMD 5300M and the Intel 630, for a blit, compute, render or
parallel render encoder, and at the commit after a parallel render encoder
let go without its end (dgpu-oracle.md, Q53). The bundle posted the buffer,
whose stream then ended with the encoder open, which the host faulted.

The commit now ends the process there with Metal's words, the M3's on a
device that answers as an Apple GPU and the x86 Macs' otherwise, before the
buffer is posted. What changes for the guest: such a process ends at the
commit, as on a Mac, where its buffer used to reach the host and fault.
2026-12-02 20:01:57 -08:00
Anees Iqbal 1008f10458 🐛 End the process at an event call with an encoder open
Metal ends the process at encodeSignalEvent:value: and encodeWaitForEvent:value:
called with an encoder of the buffer open, on the M3 Max, the AMD 5300M and the
Intel 630, for a blit, compute, render or parallel render encoder and a shared
or a plain event, and the M3 at encodeSignalEventScheduled:value: too
(dgpu-oracle.md, Q53). The bundle kept no record of an open encoder, so the
call wrote its event op inside the encoder and the buffer's stream went to the
host, which faulted it as malformed.

The encoder stream now records whether an encoder is open (a begin op to its
end), and the three calls end the process there with Metal's words, the M3's
on a device that answers as an Apple GPU and the x86 Macs' otherwise, before
anything reaches the host. What changes for the guest: such a process ends at
the call, as on a Mac, where its buffer used to reach the host and fault. The
test's death cases fail where the submission ring holds anything.
2026-12-02 20:01:57 -08:00
Anees Iqbal 9d7ee77db0 🆕 Add oracle_cmdbuf's open-encoder cases and Q53
Metal ends the process at some command-buffer calls made with an encoder of
the buffer open, while the bundle keeps no record of an open encoder and sends
the buffer's stream to the host, which faults it as malformed. The probe asks
each GPU what Metal does with an encoder open at the event calls (a shared
event and a plain one, with a blit, compute, render and parallel render
encoder), at encodeSignalEventScheduled:value:, at the commit, at a second
encoder made, at an encoder let go without its end (a parallel encoder's
sub-encoder among them), and at the calls that pass (enqueue, the handlers, a
debug group). Q53 records its answers on the AMD 5300M, the Intel 630 and the
M3 Max, which the four commits after this one follow.
2026-12-02 20:01:57 -08:00
Anees Iqbal 5338b7f585 🐎 Copy dirty shapes straight into the pages at a download
A download or a release of a per-shape cache wrote its dirty shapes into
the cache's buffer, then copied the buffer out: on the rt platform, whose
IOSurface blocks take no view, the GPU into Shared staging pieces and the
host's CPU into the pages. Census B on the M3 (m3-max-81170) counted 3,772
such write-backs, two a recorded frame, each 3.1 MB a 1080p picture, and
the downloads made 119 deferred buffers' memory for them.

Where the buffer holds nothing the pages lack beyond those shapes' writes
(its record of the host's copies is empty, no texture lies over it, its
pages are a view or copied, laid out as the pages), the shapes' rows now
go straight into the pages' view or a staging piece that holds their
extent, and the CPU moves the rows alone into the pages: one GPU copy
less a plane a read-back, and no memory made for the buffer. The pages
take the same bytes as before. The buffer then lacks the shapes' writes,
as after a straight fill, so a copy through it takes the pages first.
The shapes copied are counted as rt-shape-downloads and
rt-shape-download-bytes; docs/video/bugs.md D30 records the copies left.

This is not a keeper: the batch that lays a Mac's surfaces' shapes in
place over an import of their pages deletes it, unless another caller is
named then. Its entry is SurfaceCaches::write_back's, with its own counts
and a test knob, Caches::set_no_straight_downloads, which the twelve
tests of the copy through the buffer now set: the caches still make that
copy wherever a straight one does not go. The red tests take the counts,
and a third holds the copy through the buffer after a write over it and a
release that goes straight.
2026-12-02 19:16:41 -08:00
Anees Iqbal 2221a41c20 📝 Record the slots boot's reading in the memory slots row [ci skip]
The memory slots row said what an iMac20,1 VM's System Information lists with
reims-ctl's slots; this records the boot that read it: one slot before
(m3-max-80826), and with the installed reims-ctl's command four, DIMM 1 to 3
"Empty", on um870's 780M (m3-max-80887).
2026-12-02 17:23:00 -08:00
Anees Iqbal 3e8cbbff4a 🐛 List an iMac20,1 VM's four memory slots, not QEMU's one
An x86-64 guest's System Information listed one memory slot, "DIMM 0": QEMU
makes only the memory devices RAM fills, one on current machines, and
OpenCore copies them into the guest's SMBIOS. An iMac20,1 has four SO-DIMM
slots.

reims-ctl gives -smbios type=17's slots=4,form_factor=13 for an iMac20,1,
read from the VM's OpenCore image at each start, as it gives the memory's
error correction: vendor/qemu's 445170b5 makes the slots past the RAM's
empty. A guest given four such devices lists DIMM 0 with the VM's RAM and
DIMM 1 to 3 as "Empty" (m3-max-80846; with reims-ctl's command,
m3-max-80887). The options go only to a QEMU that takes them, asked once
per binary; another model, an iMacPro1,1 among them, and another QEMU keep
one slot, the command as before.
2026-12-02 17:23:00 -08:00
Anees Iqbal 4ce2543a5e 🆕 Let reims-ctl's resolution give each display a size
A VM's resolution was one size, every window's first size and, on a
headless start, every display's mode, so a VM of displays on screens of
different sizes opened every window at the same size. The resolution
setting now takes one size for every display, as before, or one for each
display, comma-separated in the displays' order (--resolution
2560x1440,1920x1080 on create and set, and the same in the interface's
form). Another count of sizes than the VM's displays is refused with a
message that says what to give. It applies at the next start: the fork's
1d614106 lets reims-graphics-pci's resolution take the list, which
reims-ctl writes with each comma doubled (resolution=2560x1440,,1920x1080).
One size, or sizes that are all one, gives the device string reims-ctl gave
before, byte for byte (each_display_s_size_reaches_the_device). A VM's
summary names each window's size where they differ.

What the user sees: each display's window opens at its own size, and a
headless start offers each display its own mode.
2026-12-02 17:19:47 -08:00
Anees Iqbal dc87082ea8 🆕 Let a windowless device give each display its own first mode
A device without a window offered every display the one headless mode its
config gave (headless_mode_width and _height), so a host could not give a
VM's displays different sizes without windows. RvgGraphicsDeviceConfig's
eighth version appends headless_modes: NULL, or an array of display_count
sizes, display i's at i, each taken as the one mode is (a 0 in either side
is 1920 x 1080), in its place. NULL, and a host built before the field,
keeps every display at the one mode; with a window the field is unread, as
the one mode is. The Rust API's GraphicsConfig gains headless_modes beside
headless_mode, and refuses a list of another count than the displays.

What a host sees: a new optional field; a host that leaves it NULL gets the
device it got before.
2026-12-02 17:19:47 -08:00
Anees Iqbal c5a3079426 📝 Drop indexed patch draws from the unbuilt render commands [ci skip]
The accuracy ledger listed drawIndexedPatches, direct and indirect, under
rt-unbuilt-render-command. The platform draws them through rt since the
commit before this one, so the row lists only what is still not built.
2026-12-02 17:04:32 -08:00