Commit Graph
1199 Commits
Author SHA1 Message Date
Anees Iqbal 4c8033a817 🆕 Let deferred dormant blocks age out again
This reverts cd369b7457, which kept deferred dormant blocks out of the
10 s age rule. That commit followed the reading's fixed rule, whose
item 2 tripped on a let-go's BLOCK_RELEASE answered in 27.451 ms, 10.2 s
after the browser's close.

The planner amended item 2 (02:4x): it trips only on a let-go's own work
on the answer's line, meaning its copies and rt's release and free
calls. The wait for the context's command buffers to end does not
count. The with-walk's trace splits that answer: its ring-0 job took
0.447 ms. The one command buffer it committed holds only event waits,
on values signalled 64 to 70 s before, and a signal. rt stamped that
buffer's GPU start 26.244 ms after its submission, and it ran in 0 ms
on the GPU. No other command buffer ran in the 9.4 s before it, so the
wait was the host GPU's start after an idle stretch, not other work.
The answer came 0.507 ms after the buffer completed.

Over the whole walk, no BLOCK_RELEASE answered in 16.7 ms or more has
own work that long. The jobs took 1.614 ms at most, and the longest
command buffer committed between a job and its answer, from any
context, ran 7.660 ms on the GPU.

Items 1 and 3 held as measured: frames -0.86%, and the Mac's footprint
90 s after the close was 12893 MiB with the deferred part against 15381
MiB without it. So the deferred part stays, with its footprint gain.
The option ROM's record goes back to its build before cd369b7457, and
both guest sets are rebuilt from this tree.
2026-11-22 03:50:35 -08:00
Anees Iqbal 88fa50cd8f 🔥 Keep deferred dormant blocks out of the 10 s age rule
Walks m3-max-66747 (without the age rule) and m3-max-66749 (with it), arm64
macOS 27.0.1 on the M3, headless, read the rule fixed for the deferred part: it
stays only if frames are within 1%, no guest answer of 16.7 ms or more names a
let-go, and the Mac's footprint after the close is not higher than without it.
Frames were 5402 against 5449 (-0.86%), and the footprint 90 s after the close
12893 MiB against 15381. But 10.2 s after the browser closed, the release of a
block let go for its age was answered in 27.451 ms, and the walk's
BLOCK_RELEASE answers of 16.7 ms or more rose from 311 to 445. The trace does
not say whether that block was deferred; the rule removes the deferred part.

So a deferred block goes past its caps and for the other causes alone, as
before the age rule, and the age timer waits for the others alone. A dormant
block not deferred still goes once it has slept 10 s.

What the guest sees: a deferred surface's pages take the GPU's writes at its
next lock, or at its block's let-go past a cap, as before the age rule.

guest/prebuilt and guest/prebuilt-arm64e are rebuilt from these sources, and
firmware/prebuilt/ReimsGraphics.toml records the wire header's new comment.
2026-11-22 03:50:35 -08:00
Anees Iqbal 447f14fe10 🆕 Let go of dormant surface blocks once they have slept 10 s
A dormant block kept its surface's cache on the host, and a non-deferred one
its surface's memory wired, until a cap, a client's going or a new block's want
of room let it go. After a browser closed, walk m3-max-66448 (arm64 macOS
27.0.1 on the M3) kept 250 dormant deferred blocks, 1013 MiB of caches that
held the only copy of surfaces other processes still held, and 3 to 5 wired
blocks of 6016x6016 surfaces with nothing to copy, 432 to 580 MiB.

Each dormant block now also goes once it has slept 10 s (kRgfxDormantAgeMs),
the host's age for a shape no texture references (UNREFERENCED_FOR). The
release worker lets it go, run by a timer armed for the next block's age; none
is armed while no block sleeps. The let-go is the one the caps make:
- a block whose cache the GPU has not written since its last copy is released
  with nothing to copy, and the host drops the cache;
- a written block's release copies the cache into its pages, a deferred one's
  pages named first where its surface lives on. One such release is in flight
  at a time, the next let go at its answer, so the copies the blocks a close
  leaves owe come one after another, not as one burst beside the frames.
The surface's next ask makes a new block over its pages.

What the guest sees: a surface's pages take the GPU's writes when its block
ages out rather than at its next lock, so only a CPU read without IOSurfaceLock
sees the bytes earlier, and IOSurface leaves that read undefined. A lock reads
what it read before.

The release worker also logs, for eight a minute at most of the blocks let go
for their age with clients of the surface left, which processes with a context
open find the surface by its ID: a diagnostic, for who holds them.

guest/prebuilt and guest/prebuilt-arm64e are rebuilt from these sources.
2026-11-22 03:50:35 -08:00
Anees Iqbal bdce155511 🐎 Keep the GL shader variants the bundle lowered across runs
A GL app's variants were lowered again in each of its runs, on the app's own
thread: the GL code generator, our text round trip and the metallib's
writing. Heaven on 26.7.2 (an RTX 3090) lowers 411 variants in each run, the
second as many as the first, 2 ms at the median and up to 37 ms, 2.1 s in
all, and a scene change waits on the lowerings of its variants. Metal's
compiler service keeps what it compiled for an app in the app's cache
directory; the device lowers GL variants in the app's process, so the bundle
keeps them itself, beside Metal's.

The store (src/RgfxGLStore.hpp) keeps each lowered variant and stage-in
kernel in a file of its own under the user's cache directory, the app's
bundle identifier (or its program name) and ai.aneesiqbal.reims-graphics/gl:
the path Metal's own cache takes (com.apple.metal there), which a sandboxed
app can write too, measured in a 26.7.2 guest. The key holds everything the
lowering reads: the variant's IR and plugin data, its bitcode and function
types, and the identity of the bundle, the generator, the system's LLVM, the
OS build, the builtins file and the generator's environment variables. An
entry carries its key and the SHA-256 of its bytes, which a read checks; an
entry that does not read whole is removed and the variant lowered again.
Writes are atomic (a file of their own, renamed into place). Past 64 MiB an
app's least recently used entries go first: Heaven's 298 variants and 34
stage-in kernels take 9.5 MB, so the cap keeps an app's variants at several
settings. Any failure leaves the variant to the lowering, as before, and the
first is logged once per process.

A run asks for some variants more than once: Heaven asks for 75 of its 298
again, 113 lowerings and 490 ms a run, and for 8 of its 34 stage-in kernels
again. A memo (RgfxGLMemo, 32 MiB) answers a variant the process asks for
again with the bytes it answered first, with or without a store.

What the guest reads does not change: a hit answers the bytes the lowering
answered (tests/gl_store_tests.mm, a hit and a memo's answer equal to the
lowering's byte for byte).

tests/bundle_files_check.sh's rule changes on purpose: the bundle now writes
a second kind of file of the app's own, in the app's own cache directory,
through Foundation as its binary archive is, and still imports none of
open(2)'s family.
2026-11-22 03:38:36 -08:00
Anees Iqbal f35f6fa8fc 🆕 Give each pool make's start and end on a slow answer's line
At the pin, rt's AllocationInfo states when a make of its pool began and how
long it took (make_start, make_nanos), so the device's BlockMappings keeps both
for each of the last 16 makes instead of reading the clock as rt tells it of
one. A slow answer's line now gives each make that ran during the answer by its
start and end after the ask, a start before the ask negative, with its ms, its
allocation's MiB and storage mode and its thread, for example:

  over 2 makes of rt's pool that ran during it, the last ending 5.000 ms before
  the answer (each from its start to its end after the ask, a start before it
  negative: -4.000 to 10.000 ms, 14.000 ms, a Private 16.000 MiB on
  reims-vgpu.test-maker; 12.000 to 15.000 ms, 3.000 ms, a Shared 32.000 MiB on
  reims-vgpu.test-maker)

A make is among an answer's where it ran during it, from its start to its end:
one that began before the ask counts, and how much of the answer each make
covered can now be read. rt tells of a make only once it ended, so one still
running when the answer is given is still not among them. The docs of overlap,
slow_answers and the device's BlockMappings say so, and the cost paragraph drops
the clock read a make took.

Diagnostics only: nothing changes for the guest or for the C API's host. The
counts' codes are unchanged; slow-answer-over-make counts the answers a make ran
during.
2026-11-22 03:34:45 -08:00
Anees Iqbal a19cbf4fdd 🐛 Acquire a stalled landing's caches once its kept work is let go
A picture whose landing in its output's device caches ran past the
hardware's deadline (a stall) was signalled with the caches never acquired:
the backend kept the work, which may still write them, and the device's
reads of the caches came after the signal with no acquire of what the
hardware wrote, then or later. The guest's next command buffer read them
regardless.

Each arm now takes a mark on the landing's thread before the hardware call
that may stall (VA-API's sync of a decode into a cache, and its video
processing's write into one; NVDEC's copies into CUDA's imports of the
caches), and a stalled landing (Landing::failed_in_caches) waits for the
work its thread kept since the mark to be let go, the device done with it,
then acquires the caches and signals the failure. The VA-API arm drops the
frame first, which keeps its target where its pool stalled. The wait is
bounded: STALL_HOLD, 10 s on the session's clock, past the hardware's own
5 s; past it the process dies at a fault of the decode, since the caches can
be neither read before their acquire nor waited for unbounded.

For the guest: a stalled decode's command buffer completes failed, as before,
once the hardware is done with the caches rather than at once, with the
caches acquired, so its reads and the next picture's see what the hardware
left; a hardware that is not done 15 s after the frame's first wait ends the
process. A stall that kept nothing (a decoder stalled on an earlier frame,
which writes nothing more) is acquired at once. Tests:
a_failed_landing_in_a_cache_says_it_written_before_its_signal (its stall now
acquired before the signal),
a_stalled_landing_in_a_cache_says_it_written_once_its_kept_work_is_let_go,
a_stalled_landing_whose_kept_work_is_not_let_go_ends_the_process.
2026-11-22 02:01:32 -08:00
Anees Iqbal b65568bf02 🐛 Acquire a video cache a failed landing wrote before its signal
Since rt copies a texture over an exported block in only at a change of the
block's bytes (the pin's bef2ec1df4), a cache's acquire (external_write_done)
is the one change a write by the host's video makes. A picture that failed
to land in its cache returned before the acquire, so the device kept reading
the cache's bytes from before the hardware's write. The paths: VA-API's
frame.sync() error for a picture decoded into its cache, and the video
processing's write_in_place error into a cache; NVDEC's write_into_device
outer error.

Each now ends through video_host::failed_in_caches, which says the planes
written as the landing would have, then fails with the landing's own error,
so it is logged and counted as any failure and its signal follows the
acquire. Where the error is a stall, the work may still write past its
deadline, so no acquire is said. A refused acquire is logged. A test pins
the pattern: a stopped failure acquires once before its value is signalled,
a stalled one acquires nothing, and both count as failed with their command
buffers completing failed.

The session's end line also counted a picture that the VA-API arm's GPU
copier landed from its scratch as "in a device cache, by the hardware". It
now counts it as "staged by the hardware and copied" (Landing::copied_by_gpu,
Way::Staged), with a test.

What the guest observes changes only where a landing fails: its texture reads
what the hardware left in the cache, as it would on a Mac, rather than the
cache's last picture. The rest is diagnostics.
2026-11-22 02:01:31 -08:00
Anees Iqbal f0ec246215 📝 Record what Metal answers past a length or a heap's size [ci skip]
The oracle doc's Q8 named one bound, a buffer past maxBufferLength. The bounds
case measured the rest on the AMD 5300M and the Intel 630: lengths, bytes,
no-copy bytes, heaps and the tiled texture SPI at maxBufferLength and past it,
and a Placement heap's buffer and texture at its end and past it. The table
says what each answers, which class each is read in, and what the bundle
answers now; the M3's no-copy bound goes in the list of what is not measured.
2026-11-22 01:29:34 -08:00
Anees Iqbal c31ac47ad0 🐛 Answer nil for a no-copy buffer past maxBufferLength
newBufferWithBytesNoCopy: made a buffer of any length, and the host then
refused its BUFFER_OVER_PAGES past the device's maxBufferLength, so the app
held a buffer whose uses in its command buffers the host dropped. Metal's
answer, measured with oracle_errors bounds under macOS 26.7.1: the Intel 630
makes one at its maxBufferLength and answers nil one byte and one page past
it, its process going on; the AMD 5300M makes both. Nil is inside what the two
answer and is the one that keeps the app's view true, so the bundle now
answers nil past the device's maxBufferLength, posting nothing, with its
noteNil line, wherever the bytes lie. The tiled no-copy texture goes through
the same factory and follows.

For the guest: a no-copy buffer or tiled texture past maxBufferLength is nil
where it was an object the host refused. The factory takes the limit
(maxLength, 0 for none), so the tests that made no-copy buffers pass 0 and
hold what they held; a new test holds the bound. The host's comments that said
the bundle made such buffers at any length now say what it does.
2026-11-22 01:29:34 -08:00
Anees Iqbal 839d1f0527 ✅ Run the seam's and the pool's rt tests on a Mac
Twelve tests were ignored on macOS because rt's floor refuses MoltenVK: the
seam's blit and sampler-ID tests (9) and the pool's rt-block tests (3). A Mac
now runs the rt platform over Mesa's KosmicKrisp, and cargo xtask check links
it in ../lib of each test binary's directory, so they can run there.

The pool's three tests take the platform's device and passed on the M3 Max as
they were. The seam's nine failed: seam::test_device made rt's own instance,
whose loader search found no Vulkan loader on the Mac ("rt's instance: no
Vulkan loader: dlopen(libvulkan.dylib ...)"), and would have found only
MoltenVK where it did. test_device now makes the platform's instance
(os::rt_instance), which is rt's own instance off the Mac, as before, and over
KosmicKrisp on it.

Tests only: nothing the guest or the host sees changes.
2026-11-22 01:18:25 -08:00
Anees Iqbal 2c65a71fcb 🐎 Fill no video planes at their make; their first decode takes it
A video cache's planes took their fill at their make: a clear of each on the
transfer queue, which the first decode op into each new surface then waited
for on its thread before the hardware could write. A macOS guest's walk of
1080p H.264 and HEVC and 4K 10-bit HEVC measured that wait at every new 4K
10-bit surface's first op on a Radeon 780M over VA-API, 14 of 14, 1.9 ms at
the median and 2.6 ms at most (26.1 ms in all), and on 12 of 14 on an RTX
3090 over NVDEC (0.23 ms, 0.32 ms at most); 4 of 21 and 7 of 28 of the 1080p
surfaces' first ops waited, up to 0.9 ms.

The planes now owe their fill as any new shape does. A decode that takes a
new cache's first fill as met takes the planes' fills as met too, on every
host (on Windows it did already), so its begin fills nothing and its op
waits for no fill. The guest reads the same zeros wherever no picture
lands:
- a picture short of the planes has the host's video zero the rest
  (the commit before this one);
- a picture that fails to land in planes whose fill its decode took has
  them cleared whole by the session, on its queue, before its value is
  signalled (SurfaceTarget::zeros);
- a decode op that fails, at any step after its command buffer's begin,
  makes the cache's fill from its pages, as one that answers no picture
  does (Caches::decode_failed);
- planes that a video command buffer landed no picture in owe a fill from
  the buffer, which a use makes by clearing them where the buffer holds no
  memory, from the surface's own clear passes, rather than making the
  buffer's memory to copy its zeros: SurfaceCaches::fill_shapes now clears
  wherever the fill at the planes' make did.

What changes for the guest: a decode's first picture into a new surface
starts without that wait. A picture that fails to land in a new surface
now leaves its planes all zeros, where the hardware's partial write over
the make's zeros showed before. The counts line names the plane fills a
decode took ("taken as met by a decode over zeros"); its "filled at their
make" and "owing theirs past their make" counts are gone.

Tests: the tests that held the fill at the make now hold the planes owing
it and the decode taking it, with no wait (surface_shapes); new tests hold
the clears of planes no picture landed in, and a failed landing's clears
(video_host).
2026-11-22 00:39:13 -08:00
Anees Iqbal a95ee55035 🐛 Land zeros past a short decoded picture on every way
A decoded picture smaller than its output's planes (its crop, or its coded
size, short of the guest's surface) left the texels past it as they were: the
staging buffer's earlier bytes where a plane in a device cache took the CPU's
copy, and whatever the plane held where NVDEC or VA-API's video processing
wrote the crop alone, or VA-API decoded a smaller coded picture straight into
a cache. Every way now lands zeros there, as a new IOSurface reads:
- the CPU's copy zeros past what it copies, in the pages and in staging;
- a backend whose hardware writes the picture says first what the write
  covers (`Landing::writes_only`), and the session zeros the rest of each
  plane in host bytes, and clears a plane in a device cache whole on its
  queue before the write: a render pass of a surface plane's image, a fill
  of a buffer cache's bytes;
- VA-API decodes straight into a cache only a coded picture that covers the
  planes' crop; a shorter one decodes elsewhere and lands as above;
- on Windows, a draw into textures larger than its crop clears them first.

For the guest: the texels of a decode's output surface past the picture's
crop read zeros, where they could read an earlier picture's bytes or the
staging buffer's. The bytes past each row, and a plane's rows of room below
its crop, keep what they held. No walk has shown a short picture yet (a
780M VA-API walk checked 1436 pictures, a 3090 NVDEC walk 1184, none short);
the tests pin each way the unit tests reach.
2026-11-22 00:39:13 -08:00
Anees Iqbal 1271804ce8 🆕 Count the guest's slow answers that ran over a pool make
A ring-0 answer that reaches the guest a frame or more after the device read
its command stalls whatever the guest's frameworks wait on, and the makerstall
walks tied some of those to rt's 16 MiB pool makes only with a diag build.
Every boot and walk now carries it:

- reims-vgpu-graphics times each answer given through a CompleteAnswer,
  PoolAnswer or PrivateAnswer (a clock read at its make and one at its post;
  none for PRESENT_SURFACE, whose answer waits for the display's refresh) and
  tells the host of one of 16.7 ms or more (Host::answer_slow).
- The rt platform keeps when each of rt's last 16 pool makes ended
  (rt_platform::overlap, from the device's BlockMappings), and folds rt's
  first-use variant waits of compute dispatches onto the counts line:
  rt-first-use-variant-waits, -wait-ns and -wait-max-ns.
- reims-vgpu counts a slow answer during which a make ended,
  slow-answer-over-make with slow-answer-over-make-max-ns, logs the first of
  each command type with its makes and, for a BLOCK_RELEASE or a POOL_GIVE,
  the split of its waits, and counts the first-use waits that met any slow
  answer, slow-answer-first-use-waits.

A diagnostic: nothing the guest sees changes.
2026-11-22 00:12:56 -08:00
Anees Iqbal 4e2e8b1aa3 📝 Give the GPU copier's log example its measured times [ci skip]
The example of the line a session logs for its GPU copies left its times
as ellipses. It now carries what an RX 550 (radeonsi) logged in a cold
boot's Safari video beside the guest's 3D work: 303 HEVC 1080p pictures,
5.087 ms each from the driver's write to the copy's end and 8.387 ms at
most, and 591 H.264 1080p pictures, 2.145 ms each and 30.980 ms at most
(walk job m3-max-66397).
2026-11-22 00:02:58 -08:00
Anees Iqbal 6fdc5a3ee4 🐎 Copy VA pictures into caches the driver refuses on the GPU
On the rt platform on Linux a decode's picture lands in its output's device
cache by the driver's video processing writing the cache in place, and where
the driver's import refuses the cache's layout, by the CPU: the frame read
back into host memory, copied into the session's staging and from there into
the cache. The guest's decoder asks its outputs of CoreVideo, which lays them
out itself (measured: at 1920x1080, rows of 1920 bytes, the luma plane at
byte 32 and the chroma at byte 2088992), and radeonsi's import refuses that
on the AMD GPUs we have: the RX 550's refuses rows below its pitch of 2048
bytes, the 780M's rows off a multiple of 256. On the RX 550 a walk's 1080p
H.264 and HEVC clips took that way for each of their 894 pictures (walk b1,
m3-max-66052).

Now the session's copier, gpu_copy's ScratchCopier, takes such a picture at
that refusal: the driver's video processing writes the picture into a
scratch of the session's, laid out as the driver's imports must be (each
plane at its dma-buf's first byte or whole rows after it, the even width's
rows at a pitch on 256), and fill's videoEncodeFill kernel copies each
plane's crop from it into the cache at the cache's own offset and pitch, as
plain words; the copy is waited for before the picture counts as landed, as
the CPU's copy is. The copier is reached only where the in-place write was
refused, for a plane in a device cache outside its surface, whatever the
GPU or its driver: every host whose import refuses the guest's rows takes it
(the RX 550 and the 780M), and none is chosen by name. It declines, so that
the CPU copies as before, a plane in the guest's pages or in a surface, a
crop that does not fill its rows in whole 32-bit words (rows of 1366 or 642
bytes), and an offset or pitch off a word.

Where the platform "makes no GPU copies" on Linux: f716a52d2a opened VA-API
on rt with no copier, and 13fb154934 kept it ("the copies make no copier,
for the same reason as before"), the reason f716a52d2a gave being only "as
no GPU copier is given". Neither, nor docs/conventions.md or lessons.md,
records a measured cost, a driver trap or a rule for it: the copier was not
built yet. This crosses no rule of the Vulkan platform's.
GPU memory stays the runtime's: the scratch is rt's, a dma-buf buffer made
through rt and exported through rt's API, one per session, zeroed by a blit
at its make. It is host-only: the guest never maps it, nothing read from it
decides anything, and the kernel's bounds come from the planes' layouts the
host computed. The driver writes it as it writes an in-place cache, the
runtime acquires it after (external_write_done), and the kernel reads only
bytes the driver wrote.

Guest-invisible: each plane's crop rows are the bytes the CPU's copy writes
and every other byte of the cache is as its fill left it, the layout the
device answers is unchanged, and the picture lands at the same point of its
decode. The ignored test
a_picture_copied_by_the_gpu_from_its_scratch_is_the_cpus_copy
compares every byte of the cache with the CPU's copy: 32 pictures of 8
streams (H.264, HEVC and HEVC Main10, 640x360 to 3840x2160) equal on the
RX 550 (m3-max-66105) and the 780M (m3-max-66127), the 1366x768 and 642x362
streams declined.

Each picture so copied counts video-pictures-gpu-copied and its crop's KiB
video-gpu-copied-kib, and a session logs its copies at its end. The fills'
test that held "the platform makes no GPU copies" now holds that the
device's fills make a copier each decode session.
2026-11-22 00:02:58 -08:00
Anees Iqbal 21d91340b4 📝 State that CoreVideo, not our answer, lays out VT's outputs
The guest driver's comment said AppleGVA makes its frames' IOSurfaces as
GetPixelBufferInfo answers. A walk on an x86-64 macOS 26.7.2 guest over an
RX 550 measured otherwise: an H.264 decoder's 1080p request was answered
pitches of 2048 at an alignment of 256, and its outputs' rows stayed 1920
bytes, the first plane 32 bytes in; HEVC decoders never asked. The comment
and docs/video/devices.md now say the outputs are CoreVideo's own layout.
2026-11-22 00:02:58 -08:00
Anees Iqbal f2e2801297 🐎 Make a walk's untaken pre-pass shapes at its first dispatch
A command buffer's pre-pass hands its dispatches' new pipeline shapes to the
compile pool, which makes them on all of its threads but one. On a cold boot on
um790's RTX 2080 (m3-max-65818), the boot's 52 makes ahead queued 4265.6 ms in
all behind one another at that cap, and the walk waited at each dispatch whose
shape was still queued or being made: 31 waits, 1044.5 ms, before the desktop
came up, 384.6 ms of it at 15 shapes it made itself, one at each dispatch, while
the compile threads were idle.

Each shape handed is of one of the buffer's own dispatches, whose commit waits
for it in any case. So the walk's thread now makes the shapes no compile thread
took yet at its first dispatch, beside the compile threads, then dispatches. The
pool's order and cap are unchanged, so library and pipeline creates keep the
thread left to them. The makes the walk ran are counted
(dispatch-prepass-made-on-walk) and logged at debug.

The test that held a queued make waiting for a compile thread now sees the walk
make it at its first dispatch, and not before; a new one sees a walk that ends
before its first dispatch drop them; the device release's test expects the one
shape its walk made.
2026-11-21 22:33:42 -08:00
Anees Iqbal 468c97bbc5 📝 Say the Shared pool's pieces change the VM's memory map [ci skip]
design.md's section 5 said that blocks are ranges inside the BAR, so making or
freeing one never changes the VM's memory map. That holds for the region's
blocks, but Shared memory lies in the pool now: pool.rs places each block it
takes from the runtime as a piece of its own, which QEMU adds to the VM as a
RAM region on its main loop and removes when the piece goes back
(reims-graphics-pci.c's header). The section now says so, and that a block
carved from a piece already mapped changes nothing.

The same section put "the staging rings" in the pool and the slabs and upload
chunks in the process's own pages. The rings, command buffers' bodies and
library staging chunks are region blocks (RgfxRegion.cpp's allocateRingPair,
RgfxBodyPool and RgfxLibraryStream), and with a pool every slab is a pool block
("Shared and Managed buffers lie in slabs" and "The Shared pool"). The BAR 2
table's row for the kext's blocks named Shared buffers and heaps unqualified;
they lie there only where the device offers no pool (an arm64 guest on a
Windows host).
2026-11-21 22:33:42 -08:00
Anees Iqbal 96cc4a9344 🆕 Add oracle probes of a queue's depth and the GL renderer's
The guest's GPU benchmark scene keeps about 3.4 to 3.8 frames of command buffers
in flight on our device, against about 1.7 on the 5300M Mac. The question was
whether an answer of ours lets the app run further ahead than a Mac would.

oracle_depth measures how many buffers one queue keeps uncompleted in front of a
busy GPU, where -commandBuffer blocks, whether commit or
commitAndWaitUntilSubmitted blocks before that, and when each buffer is
scheduled. oracle_gldepth hooks the Metal device's queue creators and the
queues' command-buffer creators under a CGL context that draws into an FBO, so
it reads what Apple's GL renderer over Metal asks for and how many buffers it
keeps in flight.

Q49 holds what they found:
- On the 5300M, the 630 and the M3, a queue keeps its maxCommandBufferCount of
  buffers uncompleted (34 on the 630 for an ask of 32), and blocks only in
  -commandBuffer.
- Each buffer is scheduled within 0.8 ms of its commit, 32 deep. The M3 alone
  schedules at most 36 of a queue ahead.
- Apple's GL renderer asks for 32 and keeps 32 in flight when the GPU is the
  slower side, as the guest's does on our device.
- The 5300M's 1.7 frames belong to AMD's own GL driver, which is not over Metal.
2026-11-21 22:06:20 -08:00
Anees Iqbal 8b7135e521 🐎 Make a video cache's memory at the video's first use of it
In the per-shape form a cache made for the host's video is now a deferred
exportable buffer (an exported block for NVDEC, a dma-buf for VA-API) whose
memory is made where something first reaches it: a decode or an encode whose
buffer is the cache's, or a copy of the caches' through it. Its make on the
guest's SURFACE_PAGES call makes no memory and records no zeros.

The zeros the video's memory needs ahead of a write of the host's video,
which waits for no work of the platform's, are recorded as the video first
uses the memory, on the transfer queue, and the decode's op waits for them as
for the cache's last fill. A cache's planes, whose fill at their make read the
buffer's zeros, copy them from a 1 MiB buffer of zeros made with the surface
for that fill alone. A fill of the pages into a video cache whose memory is
not made goes straight into its shapes, as any deferred cache's does, and a
decode into the buffer then takes the pages into it over the zeros.

What changes for the guest: nothing it reads. Each plane, shape and buffer
holds the same bytes at the same points; a video cache whose pictures all
land in its surface holds no memory of its buffer.
2026-11-21 21:03:42 -08:00
Anees Iqbal 298283ea71 📝 State a pool piece's length as its block's, on 64 KiB
pool_add's doc said a piece's length is a multiple of 2 MiB, but a piece is
its block's length: the length asked rounded up to the block source's granule,
64 KiB on rt (or the GPU's bufferImageGranularity where that is larger), and
HostBlocks' unit or 2 MiB. On rt an x-pool-grow of a length not whole 2 MiB
maps such a piece, and so does every guest take that fits no piece and is not
whole 2 MiB: every one over 16 MiB, and smaller ones where no piece has room.
Benchmark boots mapped up to 98 of them.

Nothing relies on whole 2 MiB lengths: first_fit starts the next piece at the
first 2 MiB boundary past one, carves stay on 64 KiB, and QEMU's add and its
populate take any page multiple (the populate's last slice ends at the
piece's end). The header's pool_add comment, its Rust source and pool.rs now
state that rule, and a test on a source of 64 KiB blocks, as rt's are, holds
it. No change in behaviour.
2026-11-21 19:14:42 -08:00
Anees Iqbal d7fec652de 🐛 Let a decoder's state go off rt's completion thread at a loss
At a device's loss the table walk (fault_walk) upgrades each decoder's
Weak<Shared> on the thread that read the first failed command buffer, rt's
completion thread among them. Where the decoder went during the walk, the
walk's hold was the last one, and the decoder's objects were dropped there: a
drop that waited for a command buffer's completion would hang the thread that
completes it.

TableWalk::each now hands a last hold to a thread of its own,
reims-vgpu.graphics-tables-let-go, through the platform's threads, so a
refused spawn ends the process as theirs do. The test drops the decoder in
the walk's callback and checks that its state went on that thread, and that a
walk of a decoder that outlives it spawns nothing. The host sees only a new
library thread name; nothing the guest sees changes.
2026-11-21 19:14:23 -08:00
Anees Iqbal 36655c417b 🐛 Name the x86-64 guest's GPU "AMD - " without Intel or NVIDIA
WindowServer died while QuickTime Player played a 4K video full screen: a
user's 780M host, and measured here on a 780M (macOS 26.7.2 and 15.8.2) and on
an Iris Xe (26.7.2), each time on a walk's second clip. Read from their code,
SkyLight's compositor takes a Metal device whose name holds "Intel" for an
Intel GPU, and scales a full-screen video's YUV layer through Intel's video
pixel processor (AppleGVACore). That keeps only plugins of Intel's renderer
IDs, so with ours it has none and asserts. The naming rule gave integrated
hosts "Intel - ", and an Intel host's own name holds "Intel" under any prefix.

What an x86-64 guest sees now, on every host (the owner's rule):
- MTLDevice.name, and the GPU's `model` that System Information shows as its
  Chipset Model, are "AMD - " and the host's name with "Intel" and "NVIDIA"
  taken out, in any case, each with a mark directly after it ("(R)", "(TM)",
  "®", "™") and one space:
  - 780M: "AMD - AMD Radeon 780M Graphics (RADV PHOENIX)" (was "Intel - ...")
  - Iris Xe: "AMD - Iris(R) Xe Graphics (RPL-P)" (was "Intel - Intel(R) ...")
  - UHD 630: "AMD - UHD Graphics 630 (CFL GT2)", on Windows "AMD - UHD
    Graphics 630"
  - Arc A770: "AMD - Arc(tm) A770 Graphics (DG2)"
  - RTX 3090: "AMD - GeForce RTX 3090" (was "AMD - NVIDIA GeForce RTX 3090")
  - 7900 XTX and llvmpipe: unchanged, "AMD - " and the host's name
  The kext's `model` was the host's name whole, and none for no name; it is
  now the same name as Metal's, "AMD - reims-graphics" for no name.
- vendorName is "AMD" on every host (was "NVIDIA" or "Intel(R)" by the host
  name's first word), so the GL renderer takes NVIDIA's settings on every
  host, as on a 5300M, where an Intel host's guest took Intel's
  (design.md, "The renderer's settings").
- SkyLight's NVIDIA name test finds nothing on an NVIDIA host either: it takes
  an AMD GPU's path there (MetalTiledBacking's +0x71 now set).

The device info's `integrated` byte stays on the wire and the host still
writes it; nothing in the guest reads it now, as its docs say. arm64 guests
see what they saw. The ROM's bytes are unchanged: its record changes for the
wire header's comment alone.

Tests: serializer_tests' test_metal_names, test_vendor_names and
test_metal_answers_hold_no_vendor_word; the kext's device_name_test, now built
for the x86-64 kext's rules and, as device_name_arm64_test, the arm64e kext's.
2026-11-21 18:40:44 -08:00
Anees Iqbal 0b3bb668b7 🐛 Give back slabs let go while a buffer's create waited
A Shared or Managed newBuffer in the guest could answer nil while the process's
own memory was on its way back to the region. A create that found no room let
the process's empty, cached and doomed slabs go, waited for the slabs other
threads were giving back at that moment, and asked once more. Under CPU load the
slabs' background thread, at utility QoS, falls behind on its drops: the slabs
other threads let go while the wait lasted stayed doomed, their memory out of
the source, and the second ask was refused while 26 to 52 of them held it.

A create now goes round again for as long as a round gave memory back, so its
answer is nil only where the region, or the pool, is full. A round after the
first asks again only where it gave something back, so a create in a quiet
process does what it did.

test_slab_take_gives_back_slabs_let_go_while_it_waited holds the slabs' releases
at the test source's gate while a create waits, so the slabs let go meanwhile
stay doomed: it failed in 20 of 20 runs on the old code and passes in 20 of 20.
test_slab_thread, which saw it once under Rosetta beside a 16-job cargo build,
refused a 3 MiB take in 6 of 3,828 runs beside 48 busy loops and 8 dd copies on
the M3 Max's 16 CPUs before, and in none of 3,144 after.

Both prebuilt sets are rebuilt from the change.
2026-11-21 16:59:23 -08:00
Anees Iqbal e6f3c2f9cd ⬆️ Build on metal2vulkan development 03a7e267ff
Moves the runtime pin from 8ca94bca19 to 03a7e267ff, on metal2vulkan's
development, for heavy kernels that need less driver memory to compile and
the indirect offset refusal split by its basis.

For the guest:
- A variable a loop carries that no later trip reads is ended at each trip's
  top, so the driver carries nothing for it: heavy kernels compile in less
  memory and time (metal2vulkan's clean cold creates: a heavy kernel on a
  Radeon 780M 10,269 -> 7,773 MiB and 73.5 -> 56.0 s, one on an RTX 3090
  1,770 -> 1,376 MiB, one on an Iris Xe 444 -> 411 MiB). What they compute
  is unchanged.
- An indirect draw or dispatch at an offset off a multiple of 4 is Metal's
  documented refusal (Refusal::IndirectOffset), counted as Metal's; one that
  leaves the buffer fewer bytes than its arguments is rt's own
  (Refusal::IndirectArgumentsPastEnd), counted rt-refused-ours. Each still
  draws or dispatches nothing; indirect_draws_on_vulkan's counts move one
  from ours to Metal's for each pair.
- rt's floor takes maintenance4 (core in Vulkan 1.3): a device without it is
  refused at creation.

For the host: the translator's SEMANTICS goes 2263 -> 2264, so a first boot
translates its kernels again; the pipeline cache's blob is kept.
2026-11-21 16:59:02 -08:00
Anees Iqbal ad48374fae 🆕 Ask for Linux 6.13 or later for KVM VMs on our GPU
A user's x86-64 VM hung at boot on Linux 6.12 (Debian 13) with amdgpu, on
both an RX 9070 XT and the Granite Ridge iGPU. QEMU logged "kvm run failed
Bad address" at the guest's first write to Shared memory. The guest's Shared
memory is the runtime's blocks: host-cached memory the driver allocates,
which QEMU maps into the guest. Before 6.13, KVM's hva_to_pfn_remapped maps a
page of a VM_PFNMAP mapping only where it can take a reference on the page.
TTM's ttm_pool_alloc_page makes its higher-order pages without __GFP_COMP, so
their tail pages have no reference to take, and KVM returns EFAULT. 6.13
resolves the pfn without a reference. Our hosts run 7.3, so no boot of ours
met it.

The owner's ruling (11-21): require Linux 6.13 or later, with no fallback.

For the host: reims-ctl refuses to start a VM on reims-vgpu's GPU under KVM
on a Linux older than 6.13, and says why and what to do, where the guest
used to hang at boot. reims-ctl doctor gains a kernel line, a failure below
6.13. The README states the requirement, and design.md no longer says that
Shared memory is anonymous memory KVM maps on any kernel.
2026-11-21 15:54:01 -08:00
Anees Iqbal 594299c3c0 ✅ Count a sampler state at an unreserved index as rt's own
The basis commit's list of the counts that move from rt-refused-metal to
rt-refused-ours missed one test, which its GPU run on a Radeon 780M failed:
- states_on_vulkan: a sampler state the guest places at an index it did not
  reserve (Refusal::IndicesNotGranted, whose basis metal2vulkan-runtime's
  error/basis.rs marks Ours), 1; its Metal's refusals go from 2 to 1, the
  address mode rt has no value of.

The test now checks each count after its own refusal, and the module doc and
the accuracy ledger name the refusal among rt's own. Nothing changes for the
guest: the kind feeds only the host's counts and log.
2026-11-21 15:14:47 -08:00
Anees Iqbal 2d9b86edf5 🎨 Count each rt refusal under the basis rt declares for it
metal2vulkan-runtime now declares where each refusal's rule comes from
(Error::basis): Metal's, documented or measured, or rt's own. The degradation
counts put every Error::Refused under rt-refused-metal but one,
TextureBufferNotOverBuffer, under rt-refused-ours, so a walk's counts mixed
Metal's refusals with rt's own rules.

RtRefusal::of now takes the kind from the refusal's basis (of_basis): rt's own
under rt-refused-ours, Metal's under rt-refused-metal. The device's basis,
which no refusal declares at the pin, and any later one stay under
rt-refused-metal, where they counted before. A heap texture's place that
Metal's own rule refuses too stays Metal's; one Metal places keeps its own
code, its kind now rt's own. rt's limits and gaps, and the loader and
below-floor codes, keep their own codes. A test pins each basis arm.

What moves from rt-refused-metal to rt-refused-ours, by the tests that held
it as Metal's:
- indirect_draws_on_vulkan: an indirect argument offset off a multiple of 4,
  or without the arguments' bytes after it (Refusal::IndirectOffset), 2.
- a_layered_pass_renders_each_slice_on_vulkan: a layered pass's slices past
  its texture's last (Refusal::AttachmentPlace), 1.
- compute_encoders_on_vulkan: a buffer offset set on an empty slot
  (Refusal::NoBufferAtIndex), 1; its Metal's refusals go from 8 to 7.
- command_buffers_on_vulkan: waitUntilCompleted in a scheduled handler
  (Refusal::InScheduledHandler), 1.
- shared_events_on_vulkan: waitUntilSignaledValue: in a notification on rt's
  thread (Refusal::WaitOnOwnThread), 1.
- buffers_on_vulkan: a Managed buffer's didModifyRange: past its end
  (Refusal::ModifiedRange), 1; its Metal's refusals go from 4 to 3.
Every other refusal of rt's whose basis is its own moves too (the variants
metal2vulkan-runtime's error/basis.rs marks Ours).

Nothing changes for the guest: the kind feeds only the counts, the stderr
lines, and the text of an NSError or a raise's detail, which reach the host's
log alone.
2026-11-21 15:14:47 -08:00
Anees Iqbal a6a3254612 📝 Say which ICB pieces rt-unbuilt-icb still counts [ci skip]
The accuracy ledger said rt-unbuilt-icb counts indirect command buffers
themselves, answered nil. Since 16eee4db90 rt makes them, of GPU-encoded indexed
draws, and executes and resets them on the GPU. The code now counts only the
pieces rt has no form of at 0429ff1bd4: commands the CPU encodes, a CPU
resetWithRange:, a blit copy between buffers, a descriptor of a resource index,
and the type-5 index reservation (rt_platform/icb.rs, device.rs). The row now
names those.

Re-read at 0429ff1bd4 by lane unbuiltsweep: every other Unbuilt piece is one
rt still lacks, so nothing else moves to rt.
2026-11-21 15:14:47 -08:00
Anees Iqbal ff96c37f07 🐎 Make a decode session's surfaces as its pictures need them
A VA-API decode session made its surface pool up front, its DPB, the picture
and two spare, at the stream's coded size, and gave them to its context as
render targets. A session whose pictures land in the device's caches decodes
only its references into surfaces of its own, so it held surfaces no picture
used.

The pool now starts empty and the context is made with no render targets. The
pool makes a surface when a picture is to be decoded into one of its own and
none is free, up to 48, and lends the one freed last first. A kept context's
shape no longer holds a surface count. Mesa's vlVaCreateContext reads no
render target (read from code, Mesa 26.2.4), and surface::lazy's tests check
the decision off the GPU and, on it, that streams of the driver's own encoder
decode to the same pictures with surfaces made as needed as made up front.

Measured with the process's DRM fdinfo, 8 surfaces at 1080p NV12, 4K NV12 and
4K P010:
- radeonsi (Mesa 26.2.6; Radeon 780M, m3-max-64940; RX 7900 XTX, -64945) makes
  no buffer until a surface's first use: +0.0 MiB once made, then 31, 108 and
  203 MiB on the 780M (41, 144, 279 on the XTX) once each held an image. Nothing
  changes there.
- iHD 26.3.5 (Iris Xe, m3-max-64988) makes each surface's buffer object at its
  full size when the surface is made, +28, +96 and +192 MiB drm-total, and
  backs none of it until first use (drm-resident +0.0). A session no longer
  holds the objects of surfaces it never decodes into.
- On Windows each surface made is a committed D3D12 resource
  (CreateCommittedResource in d3d12.rs's shared_texture, read from code), which
  allocates when it is made: a session whose pictures land in caches no longer
  holds its spare surfaces' memory there. Not measured.

A make takes 0.001 ms or less on radeonsi and 0.004 ms on iHD. The first
access unit, which holds the config, context and first surfaces, took the same
time either way within the runs' spread on all three GPUs (H.264 1080p on the
XTX 12.95 ms as needed, 13.18 up front), with two or three surfaces made as
needed against five up front.

Nothing changes for the guest: the device's answers, the pictures and their
order are the same.
2026-11-21 14:07:25 -08:00
Anees Iqbal 741ca9d519 🐎 Hand back the heap a heavy pipeline make left free
On Linux with glibc, a pipeline make's translation frees nearly all it used
as the make returns. glibc, though, keeps the free chunks below its heaps' tops
resident, so the VM's process stayed at its largest make's level, up to about
450 MiB. Now each compile-pool make of 250 ms or more asks a thread of its own,
reims-vgpu.heap-trim, to run malloc_trim(0). One trim runs at a time, and the
asks made while it runs become one more trim.

For the host, resident memory falls after heavy creates (the ledger's kernel:
158 MiB to 32 MiB). The first trim is logged at info and later ones at debug,
each with resident bytes before and after and the trim's time. The counts line
carries heap-trims, heap-trim-us and heap-trim-returned-kib.

Nothing changes for the guest. No reply, value or order it sees moves, and the
compile's thread only asks for the trim. macOS, Windows and musl do nothing.

What is left: a trim takes each glibc arena's lock in turn, so a thread the
guest waits on (a make's or the ring's) that allocates meanwhile can wait up to
the trim's own time. That was 5.04 ms at most in a cold launch of the modelling
app on a 780M, and the contention itself was not measured.
2026-11-21 13:39:25 -08:00
Anees Iqbal 4ae93c1409 🐛 Cap dormant deferred blocks at an eighth of the guest's memory
The kext let a dormant deferred block go past half the device's deferred
budget, a quarter of the host GPU's memory budget, and that half is sized
by the host's GPU, not the guest's memory: on an M3 Max it is about
5.3 GiB for an 8 GiB guest, so only the count of 1024 dormant blocks bound
them. Only the host's device cache holds a dormant deferred block's bytes,
and after the browser closed the dormant blocks' caches held 3,862 MiB of
images on the host (arm64 macOS 27.0.1 walk m3-max-63600).

trimDormant() now passes the smaller of half the deferred budget and the
dormant bytes' cap, an eighth of the guest's memory, through
rgfxSurfaceDormantDeferredCap(), with its test in surface_blocks_test.

What the guest observes: no change in contents. A deferred block let go
past the new cap is released as one past the count is today: where the GPU
wrote it and another process holds the surface, its release names its
pages and the host copies the cache into them first, and op 6 still
answers the old state volatile, the contents kept. The cost is time: a
surface asked again after its block went makes a new block (SURFACE_PAGES
and a fill) instead of reviving the old one. Volatile surfaces' blocks go
first, then the oldest, so quick revivals are kept. The dormancy line's
"past the deferred bytes" count rises.

What the host observes: fewer host-only textures and texture-block bytes
held for dormant blocks after the guest's scenes end, about 1 GiB of
dormant deferred caches at most on an 8 GiB guest beside the 1 GiB of
dormant wired blocks, and more BLOCK_RELEASE copies, which it already
paces one at a time.
2026-11-21 12:48:23 -08:00
Anees Iqbal 341c86217c 🐎 Bound the device caches on a GPU of its own memory too
What changes for the host on a GPU with memory of its own (a discrete
card): the IOSurface device caches now fit one budget together, two thirds
of the GPU's own memory's budget as the platform answers it at the device's
start. Past it, in the per-shape form the Vulkan platform takes, the shapes
no texture references are trimmed, least recently used first (never a dirty
or plane one), and a texture that takes one again has it made again and
filled from its cache's buffer. The guest reads the same bytes; only the
GPU's work and time change. Before, only a GPU that shares the CPU's
memory had a budget; its half stays as it was. The device's info line now
names the budget and the GPU's memory on both kinds.

Why: on a 4 GiB Radeon RX 550 (RADV) with no budget, QEMU asked the card
for more than it has in a browser's 3D page (by 201-270 MiB) and in a video
(by up to 1283 MiB, most of it the host's video decoder's). What did not fit
stayed in GTT after the card had room, and where long-lived allocations
stayed there a later benchmark scene ran at 17.2-17.5 frames a second
against 29.4-32.6 (jobs m3-max-63976 and 64138). The caches were the most
of what QEMU asked; of them the budget can trim only the unreferenced
shapes, 353-670 MiB at each over-asking moment, more than the 3D page's
over-ask, above a floor (buffers and referenced shapes) of 2912-3634 MiB.
Two thirds of the card is under every such floor, so it trims all it may
there, and in those walks would have trimmed elsewhere only where QEMU
asked within 415 MiB of the card's room; half would also have trimmed a
scroll that asked 2.2 GB of it.

The test that held the budget for unified memory alone takes both kinds,
and a new one checks a device on a GPU of its own memory sets it.
2026-11-21 11:24:19 -08:00
Anees Iqbal 00b884d33b 🐎 Answer presents once the window's draw is scheduled
A window draw held the answers of the presents after the one whose surface
it may read until the draw finished on the GPU. Behind a GPU-bound guest the
draw queues behind the guest's own work, so each answer waited for that work
too: on an Iris Xe under a 3D benchmark's scene, presents were answered
47.5 ms after their show at the median, and the scene presented 10.2 frames
a second against its own 26.4 (m3-max-63530).

A draw of a surface whose every write is the platform's work now lets go of
the answers as it is scheduled on rt: the present's texture lies over its
block's device cache, or a shape of it, and the cache was not made for the
host's video. The guest commits its next write of the surface only after the
answer, and rt submits every queue's work to its one VkQueue in commit order,
each segment ending in a full memory barrier, so that write runs after the
draw however long the draw waits on the GPU. A surface the guest's CPU or the
host's video may write (pages with no cache, a texture over the pages' view,
a video cache) still waits for the draw to finish, and the surface's block
hold still ends at the finish either way.

What the guest sees: a present of a device-cached surface is answered as soon
as the window's draw of it is scheduled, up to that draw's wait on the GPU
earlier, so a GPU-bound app gets its surfaces back sooner and presents more
often. The answers keep their order, and no write of the guest's reaches a
surface ahead of a draw that reads it. The timing line says "its draw
scheduled" or "its draw done", and "its draw under way" for "its draw
running".

Tests: a_later_answer_waits_for_the_scheduling_of_a_draw_of_an_earlier_surface
and the_guest_never_writes_a_surface_ahead_of_a_window_draw_that_reads_it
replace the two tests of the finish rule; sink's block test checks that the
hold waits for the finish, queued or not; a decoder test pins which presents
are queued; and rt_platform::command's
work_committed_after_a_scheduling_runs_after_it_on_vulkan fails if work
committed after a scheduling stops running after it on rt.
2026-11-21 10:54:47 -08:00
Anees Iqbal b944f69bfa 🆕 Make the device's texture buffers over a buffer of its own
rt makes a texture buffer (a VkBufferView) only over a buffer its consumer
places, through Buffer::new_texture, and refuses one its device places
(Refusal::TextureBufferNotOverBuffer, a rule of rt's own), so a guest's
newTextureWithDescriptor: of MTLTextureTypeTextureBuffer was nil, counted
under rt-refused-ours.

The device now composes Metal's call from two of rt's: a buffer of the
texture's bytes, its row of width texels rounded up to rt's texture-buffer
alignment of the format, of the descriptor's resource options and so its
storage mode; then the texture over it from offset 0, rows that rounded row
apart, at the index the device's make would give it (the guest's, where it
places one). The texture holds the buffer, which goes with the texture and
its views. The buffer takes no object ID, GPU address or resource index the
guest sees and shifts no numbering: the decoder names only the texture, rt
gives a buffer no resource index, and the buffer lies at rt's own address. A
recording keeps the device's call, which plays back through the same make.

What the guest sees: such a texture buffer is made, of the descriptor's
storage mode, where it was nil. One of a format rt makes no texture buffer of
is still nil, now counted under that format's code. A heap's texture buffer
is still rt's own refusal, nil, which rt-refused-ours keeps counting.

The five decoder tests that started from the refused texture buffer now
start from the made one, the guest's texture ids kept as a graphics device
keeps them; what they pin about the host's ranges covers its buffer. A test
on the GPU checks the composition, Shared and Private, and a refused format.
2026-11-21 10:54:47 -08:00
Anees Iqbal 14aaf2b0d8 🆕 Turn AVX-512 state on for guests on every AVX-512 host
reims-ctl gave an x86-64 VM `x-avx512-xstate=on` only where the host's
XSAVE layout was not Intel's, which meant Zen 4 and Zen 5: on Intel's, no
gain had been measured. The owner asked for it on every host with AVX-512
(2026-11-21), so a Linux KVM host whose OS keeps the AVX-512 state now
qualifies whatever its layout. On Intel's, XNU's own copy of the state is
right, and the gain stays unmeasured: no host here has that layout.

For the guest on an Intel host with AVX-512: CPUID leaf 0xD lists the
AVX-512 state components, RgfxGate promotes each user thread to them, and
hw.optional.avx512f still reads 0. Every other host's command is unchanged
byte for byte. The test that held Intel's layout out now holds it in.
2026-11-21 10:47:47 -08:00
Anees Iqbal 1010536fc2 🐛 Fail a buffer whose dispatch a failed or breached fill skipped
A dispatch whose stage's fill ended failed or breached was skipped and its
command buffer still completed with no error, so the guest read a finished
buffer whose work was never done. Such a buffer now completes with Metal's
MTLCommandBufferErrorInternal (1): the guest sees RGFX_CB_INTERNAL with error
code 1 instead of a success. The first error a command buffer is failed with
is kept, so a later out-of-memory mark does not replace it.

Only that case changes. A dispatch refused while its fill is pending, or after
a cancelled fill, keeps today's skip and count (rt-refused-gap). The skip is
counted under codes of its own, stage-skipped-failed and
stage-skipped-breached, with one stderr line per code per process.

held() now returns the fill's end with its refusal (Refused), which the rt
platform's dispatch reads. The testkit's fake command buffer carries the same
failure, so the graphics tests pin the guest's completion for both ends.
2026-11-21 09:46:10 -08:00
Anees Iqbal fd1316d5ac 📝 Add the cross-process backlog oracle and its answer [ci skip]
Q16 measured another process's access to an IOSurface behind one long pass.
It left open whether a read waits out the writing process's whole queue of
work ahead of the write, whether it also waits for what that queue commits
after the write, and whether a writer committed by a plain commit is ordered
at all.

oracle_backlog asks those three, as arms 1 to 3, each against control rounds
in which the read has nothing to wait for. Job m3-max-64081 ran it on the
MacBookPro16,1 oracle's AMD Radeon Pro 5300M and Intel UHD Graphics 630
under macOS 26.7.1, and dgpu-oracle.md's Q48 records the answers. On both
GPUs the read waits out the writer's queue ahead of the write, as our surface
order makes it. The 5300M orders the read by the surface alone and lets it
pass buffers the writer committed after the write; the 630 runs both
processes' work first in, first out, as our one VkQueue does. On the 5300M a
read after a plain-commit writer ran ahead of the write in 1 of 3 rounds;
our order, which never lets it, matches the 630 and is kept.

design.md's "Surface order" and surface_order.rs's module doc cite Q48 beside
Q16, the oracle README lists the probe, and build.sh builds it with the
others.

Docs, a doc comment and the source of a probe built only for the oracle Mac:
no check reaches it ("docs and comments" in AGENTS.md), and nothing was built
or run for this commit.
2026-11-21 09:32:44 -08:00
Anees Iqbal dbecd242be ⬆️ Build on metal2vulkan development 5ccd158e6d
The pin moves from 5a04298008 to 5ccd158e6d, metal2vulkan's development.
For the guest:
- Every compute pipeline a command buffer binds now goes through one bind
  that binds rt's descriptor set 1 first (rt 70dfe08320). The guest's
  dispatches after rt's own count kernel of an
  executeCommandsInBuffer:indirectBuffer:indirectBufferOffset: over a
  range the GPU writes found that set unbound, which lost the device in
  the rendering sample's indirect path on the RTX 3090 and the RX 7900 XTX.
- Texture buffers are made: a texture buffer over a buffer
  (newTextureWithDescriptor:offset:bytesPerRow: of a buffer) reads and
  writes the buffer's bytes through a Vulkan buffer view (rt 817463704e).
  Before, it was rt's gap (rt-refused-gap). rt refuses an offset off the
  device's texture-buffer alignment (TextureBufferAlignment) and rows or
  texels that do not fit the buffer (BufferTextureLayout), counted under
  rt-refused-metal. A blit copy to or from a texture buffer is rt's gap
  (Gap::TextureCopy).
- A texture buffer the device places (newTextureWithDescriptor: of
  MTLTextureTypeTextureBuffer on the device) is rt's own refusal, not
  Metal's (TextureBufferNotOverBuffer: rt makes a texture buffer only over
  a buffer its consumer places, and the host places none for it yet): nil,
  counted under a new code for rt's own refusals, rt-refused-ours, apart
  from rt-refused-metal.
- A copy between textures whose bytes share memory is cut into ordered
  slabs; where rt cannot cut it so, it is rt's gap (Gap::OverlappingCopy),
  and nothing is encoded.
- rt's floor adds six texel-buffer features of Vulkan 1.2 (uniform and
  storage texel buffers: update-after-bind, dynamic and non-uniform array
  indexing) and counts texel-buffer arrays against the descriptor limits.
- SEMANTICS_VERSION 2257 -> 2258: the translation caches are made again,
  so the first boot after this pin is cold.

The pin-range tests' texture buffer, a device-placed one, was rt's gap and
is now rt's TextureBufferNotOverBuffer, counted under rt-refused-ours
(RtRefusal::Ours); decoder_with_a_texture_buffer checks that, and
docs/accuracy-ledger.md names the code, the refusal and the two gaps. No
lock change: metal2vulkan's manifests did not change.
2026-11-21 09:26:38 -08:00
Anees Iqbal 81967c598b 📝 Document AVX-512 state for guests on Zen 4 hosts [ci skip]
qemu.md's CPU model section now says why a Zen 4 host runs a macOS guest's
code without its op cache, what QEMU's x-avx512-xstate property and
RgfxGate's xstate route do about it, the four conditions under which
reims-ctl adds the property, how a VM's cpu_flags turn it off for a KDK
kernel, and what was measured: op-cache shares, the route on six releases,
and the timed pairs on the 8745H.

lessons.md records the trap the route had to fix: XNU copies a thread's
AVX-512 state at Intel's XSAVE offsets, which on a Zen 4 core are not
where XSAVE put it, and nothing logs the loss.

known-issues.md tells users that a DEVELOPMENT or DEBUG kernel stops on
such a host, and how to start one.
2026-11-21 08:52:15 -08:00
Anees Iqbal 30e368e9ab 🆕 Ship the stage helper in the dist tree and beside QEMU
cargo xtask dist builds reims-vgpu-compile with reims-vgpu-c selected beside
its package, so the crates the two share resolve with the library's features
and build once, and installs it in the tree's bin on Linux, macOS and Windows.
The library starts the helper from beside the host's executable, so make qemu
copies it into build/qemu and install-ctl.sh into each QEMU install, with the
CLANG64 DLLs it loads on Windows. A QEMU without it refuses the pipelines past
rt's stage bound as before; --skip-qemu warns about such a kept install.
2026-11-21 08:33:12 -08:00
Anees Iqbal 07a227d677 🆕 Move vendor/qemu to the x-avx512-xstate CPU property
vendor/qemu c3e40185 adds the x86 CPU's x-avx512-xstate property, off by
default: on, CPUID leaf 0xD lists the AVX-512 state components (opmask,
ZMM_Hi256, Hi16_ZMM) while leaf 7's AVX-512 bits stay as the model sets them,
so a guest may turn the components on in XCR0 while it is told it has no
AVX-512. A Zen 4 core runs a thread's code from its decoders, not its op
cache, while the thread's XCR0 leaves them off.

For the guest: nothing changes until something sets the property; reims-ctl
does not yet.
2026-11-21 07:38:45 -08:00
Anees Iqbal 88f07d368f 🐛 Draw a shown surface through a view at an index of its own
The display's passes (the present shaders' conversion and the colour's) sampled
a presented IOSurface's texture through the texture's own resource index, which
is the guest's. The guest's indices belong to its processes: when one ends (a
logout, a window server restart), its indices go back to the guest's kext, and
the next process's texture made at one of them takes that index's element at
once. The display can still show the old texture and draws it again at each
refresh, so a refresh drew the new texture's pixels into the window, or
undefined ones once that texture had gone and emptied the element, until the
guest presented again.

The display now samples the texture through a view of its own: the whole
texture in its own pixel format, at one of the platform's own indices, made at
the texture's first such draw and kept with the decoder's entry and with each
of the display's holds of it, so a later present or refresh of that texture
makes no Vulkan call. The copy path reads the image through no index and is
unchanged. Where the platform refuses the view, the draw answers nothing: the
window keeps its last frame and the host's read of the display answers black,
counted as display-view-refused. No draw falls back to the guest's index.

For the host: a refresh after the guest reuses the shown texture's index still
shows that texture. a_color_draws_a_presented_surface_through_its_tables and
a_surface_takes_the_table_at_its_own_size_in_unorm now expect the view, not the
surface, in the fragment binds.
2026-11-21 05:31:47 -08:00
Anees Iqbal f73865a7d8 🐛 Give a destroyed object's ids back after the buffers before it
The host's runtime keeps a destroyed object for the command buffers
committed before its destroy, but a new object made with the old one's
resource id or at its GPU address takes them at once. A buffer still running
there then read the new object in place of the old one.

What a destroy gives back now waits until the host has completed every
command buffer the process committed before the object was let go, a failed
buffer included: its resource id and GPU address, its heap's bytes, its
region and pool blocks, its pages and its ICB slots
(RgfxRetireGate in RgfxSerializer.hpp). Every RgfxSerializer::destroy
`after` goes through the gate, stamped at the call. A command buffer takes a
serial at its commit and gives it back at its completion, or at its dealloc
where no completion came. makeAliasable still gives a heap range back at
once.

What the guest sees: ids and ranges are reused later than before. A texture
made while a buffer committed before another texture's release is in flight
takes a different resource id. A new buffer's address and a heap's usedSize
can differ the same way. With nothing in flight, everything goes back at once
as before. Under the game step's -r, no id is reused before frame f+3.

The serialiser's end, the context's, runs whatever still waits and logs once
the most that waited at once. A guest context ends only with its process, so
a new peak is also logged at each power of two from 64.

guest/prebuilt and guest/prebuilt-arm64e are rebuilt from these sources.
2026-11-21 04:19:18 -08:00
Anees Iqbal c70ffe89db 🆕 Hand the visibility mode and alpha test reference to rt
setVisibilityResultMode:offset: of Boolean or Counting and
setAlphaTestReferenceValue: were counted rt-unbuilt-render-command, though rt
has both calls at the pinned 8a36a49453. They now reach rt: Boolean and
Counting are rt's gap (Draw-VisibilityResults), counted rt-refused-gap, and the
reference is kept for rt's private alpha test, which no state of ours has.

Nothing the guest observes changes: the draws after an enabled mode still
write no result, and no draw reads the reference. Only the counts move. A
mode no Metal enumeration has is now Metal's refusal.

A line width other than 1 stays unbuilt, and the docs now say why: rt keeps
the width but refuses every draw of lines under it, which would draw lines
not at all where they draw 1 pixel wide now.

render_encoders_on_vulkan and the sub-encoders' counting-mode test count
rt-refused-gap where they counted rt-unbuilt-render-command.
2026-11-21 03:14:06 -08:00
Anees Iqbal 5866e4a2d9 🆕 Copy one depth or stencil plane between a buffer and a texture
Copies between a buffer and a texture with a blit option were counted
rt-unbuilt-blit and copied nothing. rt copies one aspect of a depth and
stencil format at the pinned 8a36a49453 (copy_from_buffer_with_options,
copy_from_texture_to_buffer_with_options), so the two plane options go there.

For the guest: a copy of MTLBlitOptionDepthFromDepthStencil or
MTLBlitOptionStencilFromDepthStencil now moves that plane, 4 bytes a texel of
Depth32Float_Stencil8's depth and 1 of a stencil. rt refuses a copy into a
32-bit float depth, and a plane option of a format without the plane, each
counted rt-refused-gap. PVRTC rows, more than one option, and copies between
textures with options stay unbuilt.

plane_copies_on_vulkan clears both planes in a pass and reads each back,
then writes a stencil and reads it back.
2026-11-21 03:14:06 -08:00
Anees Iqbal f9169e35b7 🆕 Render every slice of a guest's layered render pass on rt
A render pass of renderTargetArrayLength 2 or more was counted
rt-unbuilt-render-pass and rendered its attachments' own slice alone: its load
and store actions reached no other slice. rt's pass takes the length at the
pinned 8a36a49453 (render_target_array_length), so the descriptor now keeps it
and hands it to rt.

For the guest: such a pass loads, stores and resolves that many slices of each
attachment from its own slice, and, as rt documents, a vertex function's
[[render_target_array_index]] picks the slice it draws into. An attachment
with fewer slices than the length is rt's refusal, the encoder nil and counted
rt-refused-metal; a length past the device's layers is rt's gap.

a_layered_pass_renders_each_slice_on_vulkan checks both slices' texels; the
descriptor test no longer counts the length unbuilt.
2026-11-21 03:14:06 -08:00
Anees Iqbal 1ebd882aad 🆕 Draw the guest's indirect draws of primitives and patches on rt
The Vulkan platform answered drawPrimitives:indirectBuffer:, the indexed
indirect draw and the indirect patch draw as unbuilt: each encoded nothing and
counted rt-unbuilt-render-command, so the guest's indirect draws drew nothing.
metal2vulkan's runtime builds them at the pinned 8a36a49453 (aed460e0da): each
is one vkCmdDraw*Indirect that reads the guest's MTLDraw*IndirectArguments
from its buffer as the draw runs.

For the guest: indirect draws of primitives, indexed primitives and patches
now draw what their arguments say. An offset rt refuses (off a multiple of 4,
or without the arguments' bytes after it) is counted rt-refused-metal, and a
patch index buffer rt-refused-gap, as the direct patch draw's is. Indexed
patch draws stay unbuilt: rt refuses every state of a control point index
type.

indirect_draws_on_vulkan fills the arguments buffer and checks the pixels;
render_encoders_on_vulkan no longer counts an indirect draw unbuilt.
2026-11-21 03:14:06 -08:00
Anees Iqbal 0050cb2afd 🐎 Wake a queue's completion thread at its interrupt's filter
A command buffer's completion reached the bundle's completion thread only
after the framebuffer's work loop thread was woken and had taken the control
ring: on msi's RTX 5080 (v5, compute commits with a copy-in, n 9782) the
handler to the thread's take was 47.8 / 16.3 / 177.6 us mean / p50 / p90.
The vector's source is now an IOFilterInterruptEventSource whose filter, at
primary interrupt context, has the accelerator look at the watched rings and
wake each client with untaken records (queueFilter); the work loop's look
(queueInterrupt) then skips a producer the filter looked at
(RgfxQueueWakes.hpp, queue_wakes_test).

The filter returns true for every interrupt, so the work loop's pass runs as
before and in the same order: takeCompletions, the room wake, queueInterrupt,
rgfxSurfaceLocksWake, each display's service and the refreshes. The wake count
now rises once where both looks saw one completion; the bundle only waits on
its value. The count moves under a spin lock taken with interrupts disabled,
and the waiter asserts its wait under it and blocks after, as IOWorkLoop's
thread does.

Every call is in the SDK's Kernel.framework headers and defined by every
release's kernel collection we ship (kc-check: x86-64 11.7.11 to 26.7.2,
arm64 14.6.1 to 27.0.1). The kernel's own MSI path calls
thread_wakeup_thread at primary interrupt level with interrupts masked under
a spin lock (IOWorkLoop::signalWorkAvailable on 11.7.11, 26.7.2, 14.6.1 and
27.0.1), and thread_wakeup_prim enters the same waitq wakeup, which masks
interrupts itself (26.7.2); IOWorkLoop::threadMain asserts its wait under a
spin lock with interrupts disabled (11.7.11, 26.7.2): read from code.
2026-11-21 02:56:19 -08:00
Anees Iqbal a5a2328fa5 🐎 Walk a buffer alone on its ring on its queue's service thread
A compute buffer longer than the service thread walks itself (2 KiB) went to
its queue's lane, whose thread was woken for it as it was begun. Over the
Metal compute pass on the RTX 5080 Laptop host, those 4127 buffers waited
73.7 us at the mean (90.3 at the median) from the begin to their walk's start,
nearly all of it the lane thread's wake, where one walked on the service
thread started 3.0 us after its begin; their guest commit to rt commit took
204 us at the mean against 80. The lane is there so the queue's next buffers
are taken beside a long walk, but most of these had nothing behind them: the
guest published the next one after the walk in 7085 of 10690 cases.

A buffer of up to 8 KiB whose commit would wait for nothing is now walked
and committed on the service thread when the guest has published nothing
behind it on its ring as it is taken (QueueClaim::nothing_published), and no
lane thread is woken for it. A walk of 2 to 8 KiB took 51 to 72 us at the
median there, about one wake: what a buffer published during it waits for its
take. Its commit comes after this one's in its turn either way. The claim is
let go through the walk as for a short buffer, so a buffer that asks for its
CB_SUBMITTED behind it is answered at its doorbell.

Ring messages, events and their order are unchanged; only which library
thread walks such a buffer changes.
2026-11-21 02:55:59 -08:00