Commit Graph
3972 Commits
Author SHA1 Message Date
Anees Iqbal d664d421a7 🎨 Allow the view's measurement its own threads
a_command_buffer_s_view_costs_beside_ring_0, the ignored measurement
2133b144f added, spawns its contending threads with std::thread::spawn,
which clippy.toml disallows outside the platform's Threads. As the other
measurements in decode do, the test allows disallowed_methods: real threads
contending for the view's lock are what it measures. Mac clippy -D warnings
failed on it in batch 79's merge leg (m3-max-30296).
2026-11-14 14:40:25 -08:00
Anees Iqbal 3e6b728911 🐎 Find a command buffer's compute names as its walk starts
A command buffer's walk looked up each object its compute ops name as it
reached the op, a hold of the table's read lock each time it met a name a
first time.

Now the walk reads the names its compute ops give before its first op,
the first 128 of the current context's, and finds them in its view at once
(View::find_all). compute::names reads each op's names with the types
decode_op reads its body with, and tail's records, and each_named walks the
stream as the walk does (next_op): it stops where the walk would fault, at a
malformed op, a body too short for its records, or a compute op the walk does
not decode. A name found early is the one the op finds as it is reached; one
not found is looked up then, as before.

Tested by a_walk_s_compute_names_found_at_its_start_are_its_begin_s: a walk
held after its start while ring 0 destroys the buffers and the texture it
binds, makes one again and destroys it, binds the objects it began with, kept
until it ends; one destroyed before its begin and made again mid-walk is found
by neither, and its op faults. every_compute_op_decoded_is_read_for_its_names
holds names to every compute op decode_op decodes: each is read for its
names or listed as naming none. names_reads_an_op_s_ids_in_its_order,
a_stream_s_compute_names_come_in_order and
a_short_or_malformed_stream_ends_the_reading check the reading.

Measured in Super Resolution on the Iris Xe host (Geekbench 7.1 Metal, macOS
26.7.2, perf at 499 Hz, one walk each): the lock's read-modify-writes are gone
from the walk, but the lookups' misses are not, so the view's work holds 4.05
+- 0.45 us of the graphics threads' samples a dispatch where it held 4.40 +-
0.47 (View::get 2.83 to 0.66, the finds at the walk's start 1.77), and the
graphics threads 197.5 us a dispatch where they held 193.6 (+2.0% +- 2.3%):
no change a walk resolves.

Nothing the guest or the host observes changes.
2026-11-14 14:19:24 -08:00
Anees Iqbal 2133b144fb 🐎 Find a view's names in batches of 32 a lock hold
A view looked up each name it first met under a hold of its own of the
table's read lock. In Geekbench Metal's Super Resolution on an Iris Xe host
(i9-13900H), a command buffer's walk met 26.8 names a first time, and
View::get held 1.5% of the graphics threads' samples, a quarter of it the lock
word's read-modify-writes. perf c2c finds no contention on that line: each is
a cache miss, paid once a lookup.

View::find_all finds a list of names, 32 under each hold of the lock
(FOUND_A_HOLD), letting it go between holds, so a make or a removal waits
for one hold at most. It keeps each entry it finds, as get keeps it, and
nothing for a name the table holds no entry of, which get then looks up
again. A view's answer for a name is set at its taking, and the gone list
keeps a removed entry while a view taken since its make is open, so a name
found early finds the entry, or none, that get would find later.

Tested by a_view_finds_at_once_what_it_would_find_later: through random
makes, makes over an id again and removes, a view that finds its names at
once and one taken with it that looks them up after the table changed answer
every id alike, and nothing is kept once both close. And by
a_view_finds_its_names_a_hold_at_a_time: 100 lookups take 4 holds, the lock is
free between them, makes between them are not seen, and a name the table
lacks is looked up again. a_command_buffer_s_view_costs_beside_ring_0
measures a view beside ring 0's makes and removals and another lane: 5.7k to
5.9k cycles a command buffer of 26 names, 3.8k to 4.4k found at once (Ryzen 7
8745H; measured).

Nothing the guest or the host observes changes.
2026-11-14 14:19:24 -08:00
Anees Iqbal d4bef3d875 ⬆️ Build on metal2vulkan ce54ad8b25's runtime
Pin 92 moves metal2vulkan from 6a9a05ccad (RUNTIME_VERSION 2304,
SEMANTICS_VERSION 2112, ARTIFACT_FORMAT_VERSION 522) to ce54ad8b25 (2310,
2114, 522). It carries:
- writes and passes into the 4:4:4 `_sRGB` two-plane twins (523, 527)
  stored as Metal's GPU stores them (RUNTIME 2305), where the runtime
  refused them;
- a texture over a bit-24 buffer that no image lies over read through a
  shadow of its read twin, so its commits compare nothing (2306);
- a write through an argument buffer into a two-plane YCbCr texture
  stored or dropped as the same write through a slot (SEMANTICS 2114,
  RUNTIME 2307), where the runtime refused it;
- on NVIDIA, no explicit LINEAR plane at a row pitch that is no multiple
  of 32 bytes, which the 5080 and the 3090 misread: such a texture takes a
  shadow or texel rows instead (2308);
- a texture over a buffer whose rows are in place making its shadow at
  the first reach of its image rather than at its making, so a texture
  only ever bound through its rows makes none (2309);
- an unshared queue's commit held only for its host step, its checks or
  a signal already submitted going before another queue's batch whose
  room came after it (2310), where it waited for that batch on the GPU;
- spare command pools taken before making new ones, a replayed indirect
  command buffer draw walking its plan's heap members and resident uses
  once, a parked compute core and kept record storage, a split keeping
  its encoder's kept draws, a split encoder carrying its kept draw into
  the next, a rebound draw gathering shadow uses that differ from its
  kept draw's instead of stopping, scissor-only restates, and refusals
  that name the unknown key or the stage's weight, none of which bumps a
  version.

What the guest sees changes:
- A kernel's or a fragment function's write, or a pass, into a texture of
  523 or 527 over a guest's surface plane completes and stores into the
  planes, where it ended the process at the runtime's refusal.
- A kernel's write through an argument buffer into a two-plane YCbCr
  texture over a guest's surface plane completes: the 4:4:4 formats'
  writes change the planes and the 4:2:0 500's leaves them, as the same
  write through a slot, where every format ended the process.
- On an NVIDIA host, textures at padded row pitches read the right
  texels.
- A read through the resource ID of a texture no command names, whose
  shadow is not made yet, reads the neutral, where it read an image
  nothing had copied into. The IDs themselves do not change.
- A compositor's frame on an unshared queue no longer waits on the GPU
  for another queue's batch sent while it was on its way.
- Timing changes, and every host's shader caches and records go cold once
  at the first run of each pipeline, as SEMANTICS moves; ARTIFACT_FORMAT
  stays.

The tests that held the refusals change with this commit. In
gpu/ycbcr/plane_writes.rs, writes_over_surface_planes_are_stored_or_die_where_encoded
becomes writes_over_surface_planes_are_stored, and
writes_through_argument_buffers_of_two_plane_ycbcr_textures_die_where_encoded
becomes writes_through_argument_buffers_of_two_plane_ycbcr_textures_are_the_slots,
which checks 500's write as the process runs by default: where the device's
own sampler conversion reads 500's planes (Iris Xe), the dispatch announces
ycbcr-filter-not-exact for the texture the argument buffer holds, though the
kernel only writes it, and strict mode dies there; the test takes that death
and no other.
gpu/ycbcr/sampling.rs's writes_of_444_textures_are_metals takes 523 and
527 among the formats whose kernel writes are stored, checking that their
writes change the planes; their bytes are not compared with Metal's, of
which none are recorded. gpu/ycbcr.rs's
notes on writes say the same.

The tests that tell a texture's shadow from the work counts
(gpu/pages_in_place/tests.rs's
the_answer_over_the_pages_is_what_the_runtimes_making_does, two of
gpu/device.rs's padding-alias tests and graphics/vaapi/tests.rs's cache
planes) count a shadow as shadowed_textures + shadows_left_unmade -
shadows_made_at_use, since a texture whose rows are in place is now made
with its shadow left unmade (2309). Where no shadow is left unmade, that
is the count they read before.

The runtime adds no Degradation kind (248) and RuntimeGap keeps its 80
names. WorkCounts gains command_buffers_made, read_twin_texture_shadows,
draws_restated_scissors, parked_compute_taken,
dispatches_settled_across_encoders, record_lists_grown,
record_storage_kept, kept_draws_rehomed, shadows_left_unmade and
shadows_made_at_use, which the work log flattens with the rest. The new
RuntimeDriverDefect::ExplicitPlanePitchMisread, RuntimeFact::HeapStorageReads
and SpecKey::HeapYCbCrWrites are matched nowhere here.

The checks it reaches are the library's on the Mac and on each Linux GPU
class, rustdoc, and, since the runtime's GPU results change for guest
frameworks, a cold boot of the x86 guest on each GPU class and the arm64
gate. The video crate, the window crate's register, the guest sets, the
option ROM and QEMU link nothing of the runtime's changes and cannot move.

ce54ad8b25 is metal2vulkan's GREEN.
2026-11-14 12:52:12 -08:00
Anees Iqbal ab8958afd0 🐎 Carry out the creates a buffer waits for on its queue's thread
A command buffer's queue thread waited at the gate while a ring-0 thread was
woken for its context's lane, then was woken itself once the lane was through.
Geekbench Metal's Super Resolution waits so for the BUFFER_AT_OFFSET creates and
OBJECT_DESTROYs the bundle flushes ahead of each commit: on the 780M, 4172 of
6823 buffers waited, 62.6 us at the median and 190 at the 90th percentile from
take to host begin, 12 and 38.5 of it the queue thread's own wake after the
last job (rtsr's walk A).

Now the queue thread carries out the lane's front job itself where the lane's
thread carries none out yet, the buffer waits for it, it is ready, and it is a
BUFFER_AT_OFFSET or an OBJECT_DESTROY of no queue (a queue's destroy routes its
doorbell, and the other kinds may wait long). The job is the lane's running one
meanwhile, so the lane's thread waits for it before its next: the lane keeps
one job at a time in ring order, and every wait for the lane sees it as before.
The buffer waits for the same messages, carried out through the same code
before its begin; only the thread that carries them out changes.

Tested by the new device tests in help.rs: with ring 0's threads holding off,
the buffer's thread carries its creates and destroy out in ring order, once,
before the buffer; it leaves an event's create to the lane's thread; what it
may take; and random runs of creates, destroys, slow messages and buffers keep
every buffer after its context's messages and ring 0 in order.
2026-11-14 10:14:02 -08:00
Anees Iqbal 06f4fb7561 📝 Say why textures over a surface's planes take no range
metal_space's docs said the guest's surface-plane textures take none of the
space, where Metal's take their surface's range, and the unfixed-bugs ledger
counted that as a difference the guest sees. It is not one: on the
reims-graphics device the guest's bundle picks every GPU address and resource
ID the guest reads, in its own part of the space from RGFX_CONTEXT_VA_BASE
(2^46), and the host pins them there (design.md, Decided 6). The ranges this
model places start at 2^40, and no host-placed address is written back to the
guest. The doc now says so; nothing the guest or host observes changes.
2026-11-14 10:04:24 -08:00
Anees Iqbal 8e97a01eeb 🐛 Drop untouched resolves into textures over a surface's planes
A 4-sample BGRA8Unorm or BGRA8Unorm_sRGB attachment's MultisampleResolve or
StoreAndMultisampleResolve into an RGBA16Float, BGR10_XR or BGR10_XR_sRGB
texture the guest made over an IOSurface ended the process at the pass's
making, named "not measured". The device makes such a texture over the
buffer that stands for the surface (new_texture_over_surface_plane), and
the drop of that resolve was measured only for textures of their own memory,
shareable ones and textures over an OS IOSurface.

oracle_surfresolve measured the rest (dgpu-oracle.md Q41). The M3 Max leaves
the texture untouched over a surface without planes and over planes 0 and 1
of a 420v surface, Shared, Managed and Private, as it does a texture of its
own (m3-max-29682, m3-max-29690). The 5300M and the UHD 630 write
RGBA16Float in every shape and make no XR texture (m3-max-29683, 29684,
29691, 29692). The GPUs differ, and the drop is the M3 Max's answer, which
costs nothing, as the runtime resolves into no other format.

So a texture over a surface's plane now tells itself apart (OverSurface;
Over::Surface and Over::Plane), and the drop takes it in any storage mode,
which the device picks (Private over a device cache), not the guest. A
dropped resolve no longer counts as a store into read-only memory: such a
pass completes with the memory unchanged, as the M3 Max completes it (Q38).

For the guest: such a pass now completes, the texture keeping its texels and
the samples kept as by DontCare or Store, where the process ended. A texture
over a buffer that stands for no surface still dies, named. The Metal
comparison test gets its IOSurface shapes back over stand-ins, and two new
tests hold the drop over surfaces and over read-only memory.
2026-11-14 10:04:24 -08:00
Anees Iqbal b3969d05a5 📝 Say the tiled form keeps the frameworks' texture layouts
A desktop and Finder walk on um870's Radeon 780M left 233 read twins of
textures over a buffer not in place, each refused as a LINEAR dma-buf plane
for a 32-byte offset or a row pitch off 256. Neither the bundle's placement
nor the device's answer causes them: WindowServer makes them through the
device's tiled form, which takes any offset and pitch as the 5300M's does,
over client images it maps read-only, page-aligned, with the images' own
layout, while the device answers RADV's 256 for every format they have.

Record that in the linear alignment's doc, with RADV's rule from Mesa
26.2.6 (ac_surface_override_offset_stride: offset and pitch at multiples of
256 bytes on GFX9 to GFX11), so the next reader of such a shadow looks at
the runtime's reading of the bytes in place, not at the answer.
2026-11-14 10:01:56 -08:00
Anees Iqbal b9a8bca897 ✅ Keep a test's parked check to one sleep of the thread
peer_wire2_traffic_is_the_same_each_run failed once under load on um870 (pin
90c's 780M leg, m3-max-29572): its first run's first ring0.submit header read
consumer_idle 0, where every other run and the recorded trace read 1. The
settle had waited for consumer_idle 1 and Device::parked, but Wake::parked read
its flag and then looked at the pipe: the control thread's poll could return
between the two, clear the flag and drain its wake, so the look found nothing
pending of a thread already awake, which then cleared consumer_idle
(Consumer::awake) before the header was read.

Wake now counts its sleeps' starts and ends (test builds only), and parked holds
only where one sleep spans the look. The device's behaviour and the recorded
trace are unchanged; every test that settles on Device::parked (the peer
scripts, through FakeGuest::settle and submit_idle) gets the fix.
2026-11-14 10:01:56 -08:00
Anees Iqbal c772b67ad0 🔥 Drop objc2-io-surface, which nothing uses since the surfaces went
The deletion of the host-OS surfaces removed os/macos/iosurface.rs, the
crate's one user of objc2-io-surface, and left the dependency behind, so
cargo warned of an unused dependency on every macOS build. It goes from
the Vulkan crate's manifest, the workspace's and the crate's lock entry;
the package itself stays in the lock, as another objc2 crate depends on
it. Nothing the guest or host observes changes.
2026-11-14 09:58:05 -08:00
Anees Iqbal 36ae39886e 🐛 Name ImportView in plain backticks, as os no longer exports it
The deletion of the host-OS surfaces dropped ImportView from crate::os's
re-exports, as nothing names the type through it any more, but four doc
comments in gpu/backing.rs and gpu/device.rs still linked to
crate::os::ImportView, so rustdoc of the private items failed on both
targets. They name it in plain backticks now, as the type lives in each
OS's module. Docs only.
2026-11-14 09:57:55 -08:00
Anees Iqbal b2ee453646 ✅ Keep the YCbCr shapes on every target for plane writes
The deletion of the host-OS surfaces made the YCbCr harness's Shape
macOS-only, while the plane-write tests, which run on every target, lay
their surfaces out by it (Shape::of, chroma_size, row_bytes), so the
Linux test build failed once both were on one tree. Shape and those three
methods are on every target again; layout and surface, which make the
harness's stand-in surfaces, stay macOS's. Tests only: nothing the guest
or host observes changes.
2026-11-14 09:30:26 -08:00
Anees Iqbal d3cd30088b 🔥 Delete the import twins, the files of zeros and their budget
A writable twin of read-only pages was made only for a surface's read-only
alias, and a file of zeros only for an alias's block past its ranges: both
went with the host-OS surfaces, which no production path has made since
110b53637. So import_view loses its twin argument, and with it the twins'
map (shown_at), their mappings in the views' budget, the notwin refusal and
its trace record. Read-only pages are given to the runtime as they are, and
the views' gate refuses them, so the runtime copies them, as before.

The dma-buf sources lose their files of zeros (Zeros), which only those
blocks' pages took, and the budget's claims their reach, as only a twin
reached into the headroom. An import's pages are made once, so its record
says whether that import is still being made rather than how many are. The
remap, budget, vm, files and host_ram docs, qemu.md, lessons.md,
architecture.md and conventions.md no longer describe the twins, the
stand-in or the IOSurface memory the library held; the measured facts about
what a remap under an import reads stay in remap.rs. ResourceAddressRange,
which only the surface aliases gathered, goes.

Nothing the guest or host observes changes, as no production path has made
an OS surface since 110b53637.
2026-11-14 09:27:31 -08:00
Anees Iqbal 5a31c8ab28 🔥 Delete the host-OS surfaces and the checks only they reached
Since 110b53637 nothing in production makes a host-OS surface: the
reims-graphics device's surfaces reach the Vulkan platform as buffers, and a
texture over a surface's plane is made with new_texture_over_surface_plane.
Only tests made IOSurfaces, and the previous commit moved those onto that
creator.

So the platform's surfaces go: the Surfaces trait and Platform::surfaces,
GpuDevice::new_buffer_on_surface and new_texture_on_surface, the resources'
iosurface getters, the OS modules (os/surface.rs, os/linux/surface.rs,
os/macos/iosurface.rs) and the testkit's counted surfaces. With them goes
what only an object over an OS surface reached:
- metal_space's surface ranges and Over::Surface/Over::Plane;
- backing.rs's surface aliases (Alias, gather_or_nil, its zeros);
- writes.rs's bound-memory and slot-writes queries, and encode_render's
  Reach and binds, which decided the refused writes of 523 and 527 into a
  texture over a surface, with the compute pipelines' kept descriptors that
  only those queries read (a render pipeline keeps its guest descriptor,
  which its encoders read);
- predication's dropped texel writes, and the message layer's fatal_send;
- allocate_zeros, TWINS_READ_ONLY and an import's second making on Linux.

The measured facts the live path relies on stay, in the live modules' docs:
metal_space's (the surfaces' address ranges Metal gives), ycbcr.rs's
("Writes": which YCbCr writes Metal stores, drops, or changes by a rule the
runtime does not hold) and resource.rs's (the plane Metal asserts or answers
nil at). out_of_host_memory is Linux's alone now, as only Linux's views and
imports run out of memory short of Metal. docs/architecture.md,
development.md and qemu.md no longer describe the OS surfaces.

Nothing the guest or host observes changes, as no production path has made
an OS surface since 110b53637.
2026-11-14 09:27:31 -08:00
Anees Iqbal 4585dc4e33 ✅ Retarget the surface-plane tests to the buffer creator
The tests of what a texture over a surface's plane does (its formats,
planes, usages, sampling, resolves, rotations, YCbCr reads and identifiers)
made their surfaces as host-OS IOSurfaces, which no production caller has
made since 110b53637. The live creator, new_texture_over_surface_plane, runs
the same machinery over a buffer and the plane's shape, so the tests now make
a stand-in: a buffer of the surface's bytes with its facts and planes
(resource.rs's StandIn), and keep their recorded Metal answers. The
device_lend tests make their out-of-order view of pages as the device's
views are made, with remap_runs_shared_overwrite.

The tests of the OS surfaces themselves go: buffers on surfaces, a
command buffer's retains and use counts of a surface, a texture's range
held until its command buffer completed, a released texture keeping its
surface's memory while imported, the pages a texture over a surface maps,
two buffers made over one surface at once, the creator's debug line
over a surface, an offset surface's base address, and the death of a write
the runtime refuses into a texture of 523 or 527, which only a texture over
an OS surface reached. The OS surfaces' own modules and their tests go
with them in the next commit.

Nothing the guest or host observes changes: only tests change.
2026-11-14 09:27:31 -08:00
Anees Iqbal 694f2178f3 🐛 Complete a depth resolve into read-only memory as Metal's GPU does
A depth attachment's StoreAndMultisampleResolve into a resolve texture over a
guest's read-only memory (bit 24, or pages mapped read-only) ended the process
where the pass was made, or at the late store action or resolve texture, as the
runtime faulted it where the M3 Max completes it with the texture unchanged.
The runtime now stores the attachment and drops the resolve (metal2vulkan
RUNTIME 2298, in this pin), so the pass is sent and the command buffer
completes with the pages unchanged, for the descriptor's action and a late one,
into the descriptor's resolve texture or one the setter's SPI named. That is the
M3 Max's answer, given to every guest; the x86 Macs write the texture.

Beside a stencil attachment that resolves, or whose store action is still
Unknown, the runtime faults the pass, and nothing measured Metal's GPU there, so
that pairing still dies at the same three sites. A late resolve texture over
such memory for an attachment the pass lacks still dies too: RUNTIME 2298 does
not reach it. The tests that held the death now assert completion with the
pages zeros, and the pairing's death at each site.
2026-11-14 09:23:11 -08:00
Anees Iqbal a4f948b0ae ✅ Pin where writes over a guest's surface planes die
A texture the reims-graphics device makes over a guest's surface plane
(new_texture_over_surface_plane with the surface's facts) was thought to take a
write of 523 or 527, the 4:4:4 _sRGB two-plane formats, without a refusal. It
does not: the runtime refuses a kernel's or a fragment function's write through
one at the slot's bind and a pass into one at its creation, each dying where it
is encoded, and a blit into one completes. Through an argument buffer it refuses
the write of every two-plane YCbCr texture, of the formats whose slot writes it
stores among them, which is the runtime's gap. Nothing changes for the guest;
the tests record it, with the formats the runtime stores still written and a
BGRA8Unorm texture written through an argument buffer as the control.
2026-11-14 09:15:10 -08:00
Anees Iqbal 98762c4033 🐛 Fail protected and two-way command buffers as Metal's GPU does
dgpu-oracle.md Q39 measured a command buffer that protection options fail,
alone and beside a render pass's store into read-only memory, on the M3 Max
and the dGPU oracle. What changes for the guest:
- An encoder made under options fails the command buffer as before, but the
  event signals encoded before it now fire, and only those after it are
  withheld, as on the M3 Max and the AMD 5300M. The runtime's injected
  failure fires every signal or none, so the platform no longer sends a
  signal encoded after such an encoder and injects the failure with its
  signals firing. Before, no signal fired.
- Options from 0x10 set after every encoder still fail it with code 1, every
  encoder running, but every signal now fires, as the M3 Max fires them.
- A store-out's page fault beside the command buffer's own protection failure
  is answered by that failure, its code and its signals, the encoders from the
  earlier of the two running nothing, as all three Macs answer it. Before, the
  commit ended the process. A type-9 draw's failure beside another way still
  ends it, as no probe takes on a draw that hangs the GPU.

The x86 Macs answer code 16 where the M3 Max answers 1, and complete a command
buffer whose options no encoder was made under; the platform answers the M3
Max's for every guest, which Q39 records as outside the envelope for the x86
lane.
2026-11-14 09:15:10 -08:00
Anees Iqbal cd42a5e857 🐛 Name base_in_pages in plain backticks, as os no longer exports it
deadsurf's part 1 dropped base_in_pages from the os module's
re-exports with the rest of the read-only surface code, so the
intra-doc link in remap.rs's module doc no longer resolved and rustdoc
-D warnings failed on both hosts (batch 74, m3-max-29490/29491). The
paragraph describes buffers over host OS surfaces, which deadsurf's
part 3 removes; until then it names the function as plain code.
2026-11-14 08:33:17 -08:00
Anees Iqbal c1fcbf5fd1 🔥 Drop read-only surfaces and the deaths through their twins
Only tests have made host-OS IOSurfaces since 110b53637: no production caller
reaches the platform's surfaces, so nothing the guest or the host observes
changes. The client direction goes from SurfaceSpec, so no surface is
read-only for the GPU, and with it what answered writes through one:
- Kept::Always, the deaths through a read-only surface's writable twin (a
  pass's attachment, resolve or visibility results, a draw's or dispatch's
  write, a blit), and the count of kept objects only those deaths read;
- the dropped-write class: gpu_read_only on buffers and textures, the blit
  extents measured to drop, the swizzled views and usage bits answered over
  read-only surfaces, the CPU write through a twin;
- macOS's kIOSurfaceClientDirection key and the Linux surface's read-only
  view of the guest's pages.

Read-only memory the runtime copies (Kept::Copied) is answered as before: the
pass-level check of a depth StoreAndMultisampleResolve into it now gates on
COPIES_READ_ONLY, which equals TWINS_READ_ONLY on both hosts. The tests of the
twin class go; those of the live classes bind the YCbCr formats whose writes
the runtime refuses instead. The measured swizzle-usage and Unknown-usage
facts move to view()'s and gpu::desc's docs, and the accuracy ledger's
read-only row keeps the guest's read-only objects alone.
2026-11-14 08:30:30 -08:00
Anees Iqbal 372f39e877 🔥 Delete the client-direction tests of host-made surfaces
tests/client_direction.rs made host-OS IOSurfaces read-only for the GPU
(kIOSurfaceClientDirection) and wrote through them, its blit test faulting a
Mac's GPU on purpose. No production caller has made a host-OS IOSurface since
110b53637: the reims-graphics device's surfaces are the guest's pages, which
the library reaches through buffers, so nothing the guest or the host observes
changes. nextest's override for the fault test goes with it, since a filter
that names a binary the workspace no longer has fails every run, and the
lesson it taught says the test was deleted.
2026-11-14 08:30:30 -08:00
Anees Iqbal 86b349fe70 🐛 Forward view_mappings through the platform's VM
Making room for a view (surface_pages' make_room_for, since 378353f71) asks
the platform's VM how many kernel mappings each cached view holds. The VM the
devices are given, remap::VulkanVm, wraps the OS's VM but did not forward
HostVm::view_mappings, so it answered the trait's default, None, read as 0:
on Linux a view short of the mappings' room let go of no cached view, and was
mapped through dma-bufs or refused where letting cached views go would have
made room. VulkanVm now forwards it, and the cache lets go of views by the
mappings they hold, as that commit meant. Nothing changes for the guest.

The same gap kept group dma-bufs off in a walk. VulkanVm's impl now denies
clippy::missing_trait_methods, so a method HostVm answers by default that the
wrapper does not forward fails clippy, and a test asks the wrapper and the
OS's VM the default-answered questions of one view.
2026-11-14 08:07:42 -08:00
Anees Iqbal 0650f401dc 📝 Give grouping's measured import counts and its projected gain [ci skip]
The design's figure of about 1,000 imports at Geekbench Metal Super
Resolution's midpoint counted no-copy objects, not imports. A third walk on
the Radeon 780M (2026-11-14) read the imports directly, from debugfs's
amdgpu_gem_info and the runtime's dma_buf_memories_live gauge. About 580 were
live, under about 1,573 no-copy objects, of the 945 buffer objects the process
held; about 605 of those are the runtime's own memory by its gauges.
vkQueueSubmit took about 494 us a batch.

The design doc and the module doc now give those numbers. The projected gain
becomes a batch of about 250 us or less. Feature Matching, Particle Physics
and Fluid Simulation hold 2,000 to 8,700 other buffer objects that are not
the runtime's, so grouping cuts less there. The replay's 81 to 86% is stated
as a cut in the live views' imports, which is what it measured.
2026-11-14 08:07:42 -08:00
Anees Iqbal 900f91e623 🐛 Keep a sealed group until its job has run every member's message
The seal took the group out of the forming list in the same lock section that
made its views the blocks', then ran the members' messages after letting the
lock go. A later BUFFER_OVER_PAGES or HEAP_OVER_PAGES over a member's block
that came in that gap found the block's view made. It ran at once on the
block's own key, ahead of the earlier messages still waiting on the group's
job. Messages over one block are carried out in their order everywhere else,
so the guest could see a later message's effects before an earlier one's.

The sealed group now stays registered until its job has taken and run every
message of its members:
- group_jobs hands them out under the lock and removes the group only once
  none are left;
- a message that joins a member meanwhile is taken on the next round.

join_group looks for a member before it checks whether the block's view is
made, so a block in a sealed group waits behind it however far the seal got.
The seal no longer carries the group's number.

Test: a_message_over_a_member_s_block_waits_behind_its_sealed_group_s_messages
holds the first member's buffer inside the seal's job and sends a message over
each member's block. Neither is carried out until the hold is let go, and the
group stays registered until then.
2026-11-14 08:07:42 -08:00
Anees Iqbal e9e9fb73b8 🐎 Group a context's pages blocks' views into shared dma-bufs
On RADV each live view of a pages block is a dma-buf import of its own, and
every vkQueueSubmit lists every import, at about 0.45 us each. Geekbench
Metal's Super Resolution holds about 1,000 of them at its midpoint, and its
submits took about 450 us (Radeon 780M, macOS 26.7.2 guest).

The surface worker now gathers a context's views for a short window and has
the platform put them in one shared file, so the driver lists one import per
group instead of one per view.

How a group forms:
- The BUFFER_OVER_PAGES or HEAP_OVER_PAGES job that makes a block's view
  maps it and joins its context's open group (SurfaceViews::join_group).
- A group stays open 1 ms from its first member, or until its runs or bytes
  reach the platform's limits.
- A job of its own, under the context's key, then seals it: group_views,
  then each view's import, made as a piece of its file.
- The seal hands back the members' messages in their order, those that
  joined while it sealed among them.
- The context's and the blocks' settles drop only after that, so the guest's
  later messages still see each buffer as right after its create.

What takes no group: a view over 16 MiB, a view past a group's limits alone,
a cached view, a heap over the guest's RAM, a read-only block, and a bit-24
buffer (the last two are made over a copy).

What falls back:
- A view the platform leaves alone, or whose piece the runtime refuses,
  leaves its group and is made alone.
- A context's close and the device's reset drop the groups being formed.

The guest sees the same objects, GPU addresses, refusals and order of events.
Only the timing changes: the first message after a burst waits up to 1 ms
more. Where the platform answers no limits (NVIDIA, ANV, the Mac), nothing
changes at all.

The views log line counts the grouped views and the groups.
docs/graphics-kext/design.md says what the guest sees, and that a member
whose buffers went keeps its pages pinned in its group's import, with each
group's bytes capped at 64 MiB.

Tests, all on the fake platform's virtual clock:
- a burst shares one group;
- contexts never share one;
- a reset or a close inside the window makes nothing;
- a refused group, and a refused piece, fall back per view;
- a view past 16 MiB and a read-only buffer take no group;
- a group closes at its limits.
2026-11-14 08:07:42 -08:00
Anees Iqbal 5e164f26a9 🆕 Answer a grouped view's import with its piece of the group's file
RADV lists every live import in every submission. Grouping the no-copy views
into shared dma-bufs is to bring a burst of a process's views down to one
import (the commit before made a group's file). This commit is the platform's
half of that: a registry of each view's place in its group, and the runtime's
dma-buf source answering from it.

- HostVm gains view_groups and group_views. The default and the Mac answer
  none.
- LinuxVm answers where the process's devices take views through their
  dma-buf sources and udmabuf opens (RADV). Its limit is udmabuf's limit as
  the host has it, with a group's bytes capped at 64 MiB of our own
  (GROUP_BYTES).
  - The cap: a member whose buffers went keeps its pages pinned while another
    member's import lives.
  - CachyOS's 7.3 kernels raise size_limit_mb to 2147483647 at boot, so
    udmabuf's limit alone would let one group grow to gigabytes.
- group_views makes the groups in order, registers each member's first byte
  with a weak hold of its file, and hands back the files and each member's
  membership.
  - A membership drops its own entry, and the view's owner drops it before it
    unmaps the view, so a later mapping at the same address is never answered
    with old pages.
- The import source (RUNTIME 2290's piece API) answers a buffer's or heap's
  request with the piece, a clone of the group's Arc at the member's offset.
  It does so only where the request allows shared files, the address is the
  view's own (not a twin's), the range lies in one live member, and the
  offset is a multiple of the request's alignment.
  - Anything else is answered as before, with dma-bufs of its own, so a
    device's recovery re-asks and gets the same piece while the group lives,
    or the view alone after.
  - Members start at the largest alignment a request has asked for.
- FakeVm groups with limits a test sets, and can refuse.

Nothing calls group_views yet: the surface worker's drain follows. The guest
sees no change.

Tests:
- in dma_buf: the limits, a group's pieces while it lives and after
  (recovery re-asks), alignment, and views left alone;
- of_group's limit test given explicit limits (1024 runs, 64 MiB), so its
  body does not depend on the host;
- on RADV only, grouped_views_are_imported_as_pieces_of_one_file: one import
  of the file, the other pieces joining it, the GPU reading and filling each
  view's own pages, and the import freed with the buffers.
2026-11-14 08:07:42 -08:00
Anees Iqbal bcceb87e18 🆕 Make one dma-buf of several members' pages (group dma-bufs)
On RADV every live import is listed in every submission, at about 0.45 us
each: in Geekbench's Super Resolution about 1,000 views of app no-copy
buffers stay imported, one dma-buf each, and vkQueueSubmit takes about
0.45 ms of the scheduler's CPU per command buffer, most of it with the GPU
idle (rtsr walks A and B on the Radeon 780M, um870).

A group dma-buf holds the pages of several such views back to back in one
file, each member at an offset aligned as the runtime binds it, within
udmabuf's limits as the host has them, so one import serves them all once
the runtime binds buffers at pieces of a shared file. of_group makes it: it
takes members while they fit, ends at the first that does not fit or whose
pages resolve to no file, and fills the gaps alignment leaves with a file of
zeros of its own. Nothing calls it yet: the surfaces worker's drain and the
import source's pieces follow, with the runtime's piece API.

The guest sees no change.
2026-11-14 08:07:42 -08:00
Anees Iqbal dcc7ab7d22 ✅ Walk the completion thread's arm-once in the ring's interleavings
The completion thread no longer arms a ring its last arm found empty while
`producer` reads as it did then (RgfxReplyReader::armAndCheck). The walk of
every interleaving of the host's post, the kext's look and the thread now
takes that path, and still ends with every record taken and the ring armed.
2026-11-14 07:50:59 -08:00
Anees Iqbal febd0da972 🎨 Make the read-only resolve tests' late setters eager
Clippy's unnecessary_lazy_evaluations: the late resolve setters the tests
build are plain values, so then_some takes them.
2026-11-14 07:26:40 -08:00
Anees Iqbal 3ba94c6eb5 📝 Record what each write into read-only memory answers [ci skip]
dgpu-oracle.md Q38 records oracle_readonly's runs on the M3 Max (macOS
27.0.1) and the dGPU oracle's Radeon Pro 5300M and UHD Graphics 630 (macOS
26.7.1), each shape with its class: agreed, divergent or outside the
envelope, and the x86 finding that bit 24 does nothing there. The accuracy
ledger's read-only-pages-written row, the writes module's docs, the command
module's note on read-only store faults and design.md's no-copy buffers say
what the platform now answers: a store-out faults as the M3 Max's does, every
other GPU write completes with its write dropped, a CPU write lands where the
pages are writable, and a depth StoreAndMultisampleResolve into such memory
still ends the process until metal2vulkan completes it.
2026-11-14 07:25:13 -08:00
Anees Iqbal 36e52d8da0 ✅ Test what a death names of an undetermined slot
The words a death gives where a pipeline state's slot writes leave a slot
undetermined (gap_named, through Whether::through) had no test. No committed
function leaves a slot undetermined, so the test reads the naming of each
gap the runtime names: a slot only a function constant states, a payload
argument of an unmeasured stage, an argument buffer member's role.
2026-11-14 07:25:13 -08:00
Anees Iqbal 657054c90d 🐛 Write the pages for a CPU write of a texture over bit-24 memory
replaceRegion: of a texture over the guest's read-only memory (a buffer or
heap made with bit 24, or over pages mapped read-only, which the runtime
copies on Linux) ended the process, as Metal's write through a read-only
mapping does. oracle_readonly measured it (dgpu-oracle.md Q38). Agreed
(class 3): on the M3 Max (macOS 27.0.1) and the Radeon Pro 5300M and UHD
Graphics 630 (macOS 26.7.1), a write of a texture over a bit-24 buffer of
writable pages lands in the pages, which the GPU then reads, and on the M3 Max
one in a Shared heap of bit 24 lands in the texture; a write over pages the
process maps read-only ends the process with SIGBUS, with the bit or without
(m3-max-29292 to m3-max-29294).

The backing now records whether its pages are mapped read-only, apart from
bit 24 (Backing::pages_read_only). A CPU write over bit-24 memory of writable
pages is sent: the runtime writes the caller's pages, and its copy takes them
at the next commit, so later command buffers read them. One over pages mapped
read-only dies, naming Metal's bus error. The last writes into memory the
runtime copies that kept_write ended the process at are gone with it, so
kept_write's words now name only the surface twin and the depth
StoreAndMultisampleResolve.

What the guest sees: the CPU write takes, as on Metal, instead of the process
ending; the test
a_cpu_write_of_a_texture_over_read_only_memory_takes_its_texels_on_linux
replaces the one that held the death. No boot: the guest bundle writes a
buffer's texels itself, and no walk reaches this path.
2026-11-14 07:24:59 -08:00
Anees Iqbal 6a48464ba7 🐛 Complete a blit's texture writes into read-only memory, dropped
A blit that writes a texture over the guest's read-only memory (bit 24, or
pages mapped read-only, which the runtime copies on Linux) other than by a
copy (a colour or bytes fill, mipmaps, an invalidation) ended the process
where it was encoded, as nothing had measured Metal there. oracle_readonly did
(dgpu-oracle.md Q38). Divergent (class 2): the M3 Max (macOS 27.0.1) completes
each and drops the write (m3-max-29292; m3-max-29309 for mipmaps, level 1 of
a heap's texture staying zeros where it is written without bit 24), the
Radeon Pro 5300M and UHD Graphics 630 (macOS 26.7.1) complete mipmaps and
write them, bit 24 doing nothing there, and end the process at the fill and
invalidation SPI with the bit or without, which their drivers lack
(m3-max-29293, m3-max-29294). Each is now sent and completes, its write
dropped by the runtime's copy, as the M3 Max's is and as a blit's copy
already was; only a write that would land in a surface's writable twin
(Kept::lands) still dies.

What the guest sees: such blits complete with no error, and the memory keeps
its bytes, instead of the process ending, as the test
blit_writes_of_a_texture_in_read_only_memory_are_dropped holds. No boot: no
walk reaches these paths.
2026-11-14 07:24:51 -08:00
Anees Iqbal 536f4e8ea7 🐛 Complete a draw's texture writes into read-only memory, dropped
A draw that may write a texture over the guest's read-only memory (bit 24,
or pages mapped read-only, which the runtime copies on Linux), through a
function's write() at a bound slot or by making it resident for writing,
ended the process where it was encoded, as nothing had measured Metal there.
oracle_readonly did (dgpu-oracle.md Q38):

- Divergent (class 2): a fragment or vertex function's write() of such a
  texture fails the command buffer with PageFault on the M3 Max (macOS
  27.0.1) every run, and completes on the Radeon Pro 5300M and UHD Graphics
  630 (macOS 26.7.1), which write the pages, bit 24 doing nothing there, and
  leave pages the process maps read-only unchanged (m3-max-29292, 29309;
  m3-max-29293/29294, 29310/29311). The draw is now sent and completes, its
  writes dropped by the runtime's copy: the cheaper answer, as faulting it
  would keep every such bind in the draws' reach and ask it at each draw.
- Agreed (class 3): a texture made resident for writing that no function
  writes completes on all three, and is now sent.

Kept::lands names what still dies where it is encoded: a write that would
land in a surface's read-only memory through the runtime's writable twin. A
texture over read-only memory the runtime copies no longer decides anything
a draw asks (texture_bind).

What the guest sees: such draws complete with no error, and the memory keeps
its bytes, instead of the process ending, as the test
a_draws_write_into_read_only_memory_is_dropped holds. No boot: no walk reaches
these paths.
2026-11-14 07:24:44 -08:00
Anees Iqbal caf1c7bef8 🐛 Answer every render pass store-out into read-only memory
A render pass that resolved into, or kept an attachment in, the guest's
read-only memory (a no-copy buffer or heap made with MTLResourceOptions bit
24, which the runtime makes over a copy of its pages on Linux) ended the
process at every shape no probe had measured. oracle_readonly measured each
on the M3 Max (macOS 27.0.1) and on the dGPU oracle's Radeon Pro 5300M and UHD
Graphics 630 (macOS 26.7.1), dgpu-oracle.md Q38, and each now gets an answer
inside that envelope:

- Divergent (class 2): a colour StoreAndMultisampleResolve, a stencil
  MultisampleResolve or StoreAndMultisampleResolve and a depth
  MultisampleResolve into such memory, the descriptor's action or a late one,
  into the descriptor's resolve texture or a late setter's. The M3 Max faults
  the command buffer every run, and the x86 Macs, on which bit 24 does
  nothing, complete them and write the pages. The pass now fails its command
  buffer with PageFault, as the M3 Max's does and as the runtime faults it
  itself, at no cost (m3-max-29292, m3-max-29309; m3-max-29293/29294,
  29310/29311), as a Store and a colour MultisampleResolve did already.
- Agreed (class 3): a colour or stencil CustomSampleDepthStore set late
  completes on all three, writing nothing, and the runtime stores it as
  DontCare: it is sent. One the descriptor names ends the process in Metal's
  validation on all three, over any memory: it now dies at the runtime's
  refusal, as for any memory, not as a read-only write.
- Outside the envelope (class 4): a depth attachment's
  StoreAndMultisampleResolve into such memory completes on all three Macs
  (the M3 Max leaving the texture unchanged), where the runtime
  (metal2vulkan 20f7e82bbe) faults it. It still ends the process, where the
  pass is made, or at the late store action or resolve texture, and the
  message now names the runtime's gap; metal2vulkan takes on completing it.

What the guest sees: these passes fail their command buffer with
MTLCommandBufferErrorPageFault, counted against the queue as Metal's are,
instead of ending the process. The tests change with them: the resolve and
depth tests cover StoreAndMultisampleResolve, stencil and the late setter,
and the depth SMSR deaths. No boot: no walk reaches these paths.
2026-11-14 07:24:23 -08:00
Anees Iqbal 15f99157b6 ✅ Make the read-only depth test's heap texture relaxed
a_depth_store_into_read_only_memory_faults_its_command_buffer died on
ms01's Iris Xe (ANV) as it made its Depth32Float texture in the bit-24
heap: on Linux that texture's image is a shadow of the heap's bytes, and on
a device without VK_EXT_depth_range_unrestricted the runtime announces
restricted-depth-upload as it makes it (degrade_shadowed_depth), which
dies in strict mode. The test checks the pass's fault, not that
degradation, so the texture is made under the default, as the heap is.

Only the test changes; nothing changes for the guest or the host. No boot:
no walk reaches the path.
2026-11-14 06:27:30 -08:00
Anees Iqbal f264ac73b8 🐛 Drop kernel and blit-copy texture writes into read-only memory
A kernel's write() of a texture over memory the process maps read-only
(Metal's private option bit 24, a no-copy buffer or heap the runtime makes
over a copy of the pages on Linux), and a blit's copy into such a texture,
ended the process where they were encoded (kept_write), as what Metal does
there was read as unmeasured. metal2vulkan measured both on the M3 Max,
macOS 27.0.1, plain Metal (probes/readonly_gpu_writes.m; the runtime's
read_only_view.rs): a texture over such memory takes a kernel's write() and
a blit's copy into it, out of a buffer or a texture, nowhere; each completes
with no error and leaves the pages as they were. The runtime's copy drops
those writes too: a texture over a copy lies in the copy's memory, or is a
shadow of its bytes, and each batch's completion writes back over every byte
the GPU changed in a copy that drops writes (copied.rs), so a later command
buffer reads the pages' bytes.

What changes for the guest: such a dispatch and such a blit copy complete
with no error, their writes dropped, where they used to end the process.

predication.rs's kept_write_through asks texture_twinned instead of
texture_kept for a texture a kernel writes, bound or made resident for
writing, so only a surface's read-only memory the runtime twins still dies
there. encode_blit.rs sends a copy into a texture over memory the runtime
copies (copy_dropped: CopyBufferToTexture, CopyTextureRegion,
CopyTextureSlices and their options forms).

What stays a death, as nothing measured it: a draw's write of such a
texture, another blit's write of one (a fill, mipmaps, an invalidation),
and a CPU write of one.

Tests: texture_writes_into_read_only_memory_are_dropped runs a kernel's
write, a copy out of a buffer and a copy out of a texture into a texture over
a bit-24 buffer and one in a bit-24 heap over pages: each completes with no
error, the pages stay zeros, and a later command buffer reads zeros.
a_blit_into_a_read_only_buffer_is_dropped's copy into a texture over the
buffer now completes where it died. gpu/writes.rs's docs and the accuracy
ledger's read-only row say the same.

No boot: no walk has reached this path (no app in our walks writes a texture
over read-only memory).
2026-11-14 06:10:59 -08:00
Anees Iqbal 68a94da601 🐛 Fault measured resolves and depth stores into read-only memory
A pass that resolved a multisample colour attachment into a texture over
memory the process maps read-only (Metal's private option bit 24), or kept a
depth attachment there by CustomSampleDepthStore, ended the process where it
was encoded, as what Metal does there was unmeasured. metal2vulkan has since
measured both on the M3 Max, macOS 27.0.1, plain Metal (m3-max-28796,
m3-max-28797): a colour MultisampleResolve into a texture over a buffer of
bit 24, and a depth attachment in a heap of bit 24 kept by
CustomSampleDepthStore, each by the descriptor's action or one the encoder
set, fail the command buffer with PageFault, as a Store there does. RUNTIME
2280 (pin 89) faults both itself (store_out.rs), and counts the fault toward
its queue's revocation.

What changes for the guest: those two shapes now fail their command buffer
with PageFault (3), the pass and the encoders after it running nothing, every
event signal firing, the pages unchanged, and the queue serving on until its
second fault, where they used to end the process.

kept_attachment and late_store let them through, and read_only_stores and
late_store tell the command buffer of the fault (faults_at_read_only_store),
as a Store there is told, so a command buffer that fails another way too
still dies at its commit. faults_over and faults_into name the store actions
that fault. A colour attachment's resolve texture over such memory, the
descriptor's, is marked Unsent::Copied while its store action is Unknown, so
a late MultisampleResolve into it faults.

The store-out shapes 2280 did not measure stay deaths where they are
encoded: StoreAndMultisampleResolve into such a texture (at the pass's
creation, or at its late store action), a depth or stencil resolve into one,
a resolve into a texture a late resolve setter named, a colour or stencil
attachment kept there by CustomSampleDepthStore, and a colour resolve into
such a texture that this platform drops because plain Metal leaves a texture
of that format untouched (now dying in read_only_stores, at the same
selector, where it died in kept_attachment before).

Tests: a_resolve_into_read_only_memory_dies becomes
a_resolve_into_read_only_memory_faults_its_command_buffer: MultisampleResolve
given at once or late faults and the queue runs on, while
StoreAndMultisampleResolve dies at renderCommandEncoderWithDescriptor: and at
setColorStoreAction:atIndex:. In
a_depth_store_into_read_only_memory_faults_its_command_buffer,
CustomSampleDepthStore at once or late, and Store, in a
heap of bit 24 over pages fault, the queue running on, and DontCare
completes. The read-only pass helper takes any pass (pass_line_on). The
module docs, gpu/writes.rs's and the accuracy ledger's read-only row say the
same.

No boot: no walk has reached this path (no app in our walks stores into
read-only memory).
2026-11-14 06:04:48 -08:00
Anees Iqbal 67e65365e5 🐛 Let a read-only store's fault revoke its queue, not end the process
A render pass that stores an attachment into memory the process maps
read-only (Metal's private option bit 24) faults its command buffer with
PageFault. This platform then made the commit of every later command buffer
of the process die (READ_ONLY_FAULTED), as Metal was read to fail them all.
Measured on the M3 Max, macOS 27.0.1, plain Metal, that reading was of the
probe's runs sharing one queue: one fault a process leaves the next command
buffer of the same queue Completed (m3-max-29110, twice, a process each), and
so do one on the same queue 100 ms on and one on a new queue (m3-max-28796,
m3-max-28797); four faulting runs on one queue fail every command buffer of
that queue after its second fault. That is the queue revocation the runtime
models in command_buffer/revocation.rs, measured on the same Mac: the
queue's second page fault or hang revokes it, every later commit on it
failing with AccessRevoked (4); other queues, and a new one, serve on.

What changes for the guest: a command buffer committed after such a fault
runs, where the commit used to end the process; the queue's second fault
revokes that queue, every later command buffer of it completing with
AccessRevoked, running nothing and signalling nothing; other queues run.

Since RUNTIME 2280 (pin 89) the runtime faults such a store-out itself, with
the same code, from the same pass on, every event signal firing
(store_out.rs), and counts it toward its queue's revocation. This platform
no longer commits the fault as failed (commit_failed of code 3): the command
buffer commits as any other, and the runtime faults it. The pass is still
told to the command buffer, now as a failure the runtime makes (the field
type_9 becomes by_runtime, holding type-9 draws' failures and these), so a
command buffer that fails another way too still dies at its commit as a
combination nothing measured, and is never cut into parts.

The executions of indirect command buffers in the encoders such a failure
runs nothing of stay unchecked at the commit, as they were while this
platform committed the failure. The same now holds for a type-9 draw's
failure, whose later encoders' executions were checked, and could die there,
though Metal runs nothing of them.

Tests: a_store_into_read_only_memory_fails_its_command_buffer and its late
store variant now see the next command buffer of the queue and of a new
queue run, the faulted one's blit after the pass not run and its signal
fired; read_only_faults_revoke_queues_as_metals holds the revocation at the
second fault, while a new queue runs and takes a first fault of its own
without revocation; a_command_buffer_failing_two_ways_dies_at_its_commit
gains the read-only cases and the first encoder that runs nothing. The
module docs, gpu/writes.rs's and the accuracy ledger's read-only row say
the same.

No boot: no walk has reached this path (no app in our walks stores into
read-only memory).
2026-11-14 05:50:22 -08:00
Anees Iqbal c3ed478a70 ⬆️ Build on metal2vulkan 20f7e82bbe's runtime
Pin 89 moves metal2vulkan from bc12f6d95a (RUNTIME_VERSION 2266,
SEMANTICS_VERSION 2107, ARTIFACT_FORMAT_VERSION 522) to 20f7e82bbe (2290,
2109, 522). Pins 87 and 88 were never cut: 87's lavapipe suite hung in the
read twins (fixed by RUNTIME 2278), and 88 (afba68e6e4) kept a buffer's
unobserved padding in an exportable image that starts UNDEFINED, a shadow
where in place passed (fixed by RUNTIME 2288). It carries:
- consecutive compute encoders of a command buffer recorded into one
  Vulkan command buffer (RUNTIME 2268), an encoder's open looking only at
  the encoders ended since the open before (2270), and a failure inside a
  group of folded encoders failing only the encoders it names (2272,
  2273);
- copies from a no-copy buffer made with Metal's read-only option, and
  slots that only read such a buffer, reading its pages in place through
  a read twin (2269, 2276; fixed forward by 2274 and 2278);
- the unshared-isolation hold's budget at 2 ms only while an unshared
  queue on that VkQueue committed within the last 50 ms, else 16 ms
  (2275): a guest's single-batch command buffers are no longer held for
  2 ms each while the window's queue is idle;
- a render pass's store-out into memory whose GPU writes are dropped
  (Metal's private bit 24) faulting its command buffer with PageFault off
  macOS too, as Metal's does (2280);
- a kernel's unaliased, never-written buffer arguments NonWritable
  (SEMANTICS 2108, RUNTIME 2283), and an 8-byte leaf at a proven 8-aligned
  offset moving as one uvec2 (SEMANTICS 2109, RUNTIME 2287): on the 780M
  Geekbench's convolution loops now load as the native driver's do;
- cheaper bookkeeping per dispatch and per command buffer: a part's first
  command ordered lazily (2281), recycled encoder state (2282), live-buffer
  tables rebuilt only where a chunk changed and compared in place (2284,
  2286), a compute encoder's memory barrier recording the least barrier
  (2285), a one-dispatch encoder keeping its instantiated commands (2289),
  bind memos (2277), a used heap's buffers listed once (2271) and an
  encoder carrying every kept draw (2267);
- buffers whose padding is unobserved laid in blocks of their own,
  exportable as dma-bufs, with the padding of a block never exported held
  in place (2279, 2288);
- pieces of one shared dma-buf file bound in one import of the file
  (2290).

Here:
- gpu/command.rs gains the test
  protection_options_fail_compute_encoders_from_the_one_made_under_them:
  two compute encoders that the runtime records together, the second made
  under protection options, where the first one's work runs and the second
  one's runs nothing. It failed at metal2vulkan 09068993d6, before RUNTIME
  2272. failure()'s doc says the encoders it fails are From the first that
  runs nothing, and that this encoder can directly follow compute
  encoders the runtime records with it, the ones before it running all
  the same.
- RUNTIME 2290 changes the runtime's DmaBufChunk to { file:
  Arc<OwnedFd>, offset, length }. os/linux/dma_buf.rs and host_ram.rs hand
  each chunk a file of its own at offset 0, which is the runtime's
  behaviour before 2290, and their tests read through chunk.file.

No Degradation kind or RuntimeGap changes (247 and 80, the same names).
WorkCounts drops kept_draws_carry_capped, which nothing here reads, and
adds counters for the changes above. SEMANTICS moves, so every host's
shader caches and records go cold once, at the first run of each
pipeline; ARTIFACT_FORMAT stays.

What the guest sees changes in timing, and in one case of the contract:
on Linux and macOS hosts alike a render pass that stores an attachment
into memory the process maps read-only now faults its command buffer in
the runtime as Metal's does, where this platform already failed it so.
Under protection options the encoders before a failed one still run, as
they did at pin 86, which had no fold; the test above holds that.

The checks it reaches are the library's on the Mac and on each Linux
GPU class, rustdoc, and, since the runtime's GPU results change for
guest frameworks, a cold boot of the x86 guest on each GPU class and the
arm64 gate. The video crate, the window crate's register, the guest
sets, the option ROM and QEMU link nothing of the runtime's changes and
cannot move.

20f7e82bbe is metal2vulkan's GREEN.

Cargo.lock keeps its lines.
2026-11-14 05:40:58 -08:00
Anees Iqbal 887b8f94a4 🐛 Name parts_cut in plain backticks, as rustdoc never sees it
note_part_cut's doc linked Self::parts_cut, which exists only under
cfg(test), so rustdoc -D warnings failed on an unresolved link (batch 69,
m3-max-29067 and 29068). The doc now names the counter without a link.
2026-11-14 05:15:49 -08:00
Anees Iqbal e5b4e2fa35 📝 Say why a buffer's parts out are not limited [ci skip]
Batch 64 doubled the walk a dispatch of Fluid Simulation's big command
buffers on a Radeon 780M, 17.2 to 33.6 us, cutting each into about 75 parts.
The question was whether fewer parts, committed only while few are out,
would keep the GPU's early start for less walk. Measured with dispatch_cost's
fluid shape and its heavy one (the decoder alone, release, median of 5 runs),
at most 2 or 16 parts out against no limit:

metal2vulkan afba68e6e4 (pin 88), latency in ms, walk us a dispatch:
  780M heavy   none 166.2 / 7.3   16: 167.0 / 7.0   2: 166.8 / 6.6
  Iris heavy   none 253.0 / 7.6   16: 252.2 / 7.3   2: 252.4 / 7.3
  M3 fluid     none  33.8 / 7.9   16:  35.7 / 7.9   2:  44.3 / 7.5
  M3 heavy     none 121.9 / 8.1   16: 127.2 / 8.0   2: 132.2 / 7.9
  (fluid on the 780M and the Iris: the GPU keeps up, no limit is reached)

So a limit is neutral on the hosts the library ships on, and loses on
MoltenVK, where completions come late and the GPU waits for the cut. The walk's
doubling was the runtime's at bc12f6d95a (pin 86): on the 780M the heavy shape's
walk took 55.8k cycles a dispatch against fluid's 34.5k for the same
instructions; at afba68e6e4, 30.2k against 33.3k. The rule stays batch 64's.

Runs: m3-max-28834, 28846 (M3, Iris, pin 86); 28855 (780M, pin 86); 28900,
28904, 28858 (M3, Iris, 780M, pin 88); 29014 (M3, parts that grow).
2026-11-14 05:14:09 -08:00
Anees Iqbal b9f9310405 ✅ Add a dispatch_cost shape whose GPU work outlasts its walk
dispatch_cost's fluid shape dispatches one threadgroup at a time, so its GPU
keeps up with the walk and each part completes about as soon as it is cut.
Geekbench 7's Fluid Simulation on a Radeon 780M runs about 200 us of GPU work
a dispatch against a walk of 12 to 20 us (perfscout4's gbr-780m), and with
batch 64 its buffers had up to 47 parts out. The heavy shape is fluid's ops
with 32,768 threadgroups a dispatch, so the GPU falls behind the walk on any
host. Both benches now also print how many parts the walk committed a command
buffer (a frame for composite_cost), from a counter only the tests' builds
keep.

Tested by the_fluid_shape_holds_an_encoder_a_dispatch.
2026-11-14 05:14:09 -08:00
Anees Iqbal ccbcdabd6d 🆕 Make pages blocks of memory a process maps read-only
A no-copy buffer over memory its process maps read-only cannot lie over its
own pages today: the kext refuses the pages block, and the host would lay a
buffer over it that takes the GPU's writes. So the bundle syncs a slab copy
of it at every commit that uses it. macOS 12's WindowServer wraps clients'
Core Animation backing stores, mapped read-only into it (8-30 MB each), that
way, and spent 14.1 s of a 451 s walk syncing them (appwalk14, 12.7.6 on the
Iris Xe). This makes the device and the kext ready to keep them in place; the
bundle takes the route in the next commit.

What changes on the wire:
- A new feature bit, RGFX_FEATURE_READ_ONLY_PAGES (bit 45, FEATURES_HI bit
  13), offered wherever PAGES_BUFFERS is, and taken by the kext.
- A new SURFACE_PAGES flag, RGFX_SURFACE_PAGES_READ_ONLY (1 << 5), meaningful
  with RGFX_SURFACE_PAGES_PRIVATE alone (else INVALID_ARGUMENT): the pages
  block holds pages its process maps read-only.
- BUFFER_OVER_PAGES needs no new field: its options already carry
  MTLResourceOptions bit 24 to the host, which hands it to the runtime as
  memory whose GPU writes it drops (accuracy-ledger.md,
  read-only-pages-written).

The host keeps every object over a read-only block from writing its pages: a
BUFFER_OVER_PAGES without bit 24, a HEAP_OVER_PAGES, an ICB_SLOTS_IN_PAGES
and a MANAGED_BUFFER_CREATE or MANAGED_TEXTURE_CREATE whose CPU copy lies over
one are refused, each logged as the guest error it is. The block's view stays
the writable mapping of guest RAM.

Where the kext took the bit, PagesBlock makes a block of read-only memory too:
it wires the pages with kIODirectionOut, which asks the VM system only for
read access, completes them for that direction at the unwire, and marks the
block read-only (rgfxPagesWiring). Without the bit it refuses read-only
memory as before.

Why a feature bit, though reims-ctl ships the host and the x86 set together:
the mark is where the host holds the line, not a hint. A process can post any
message on its rings, so a forged BUFFER_OVER_PAGES without bit 24 over a
read-only block would let the GPU write pages the process maps read-only, a
file's page cache among them. A host older than the mark ignores it, so the
kext makes such a block only where the host took the bit. The arm64e set also
reaches VMs through Ambrosia's config bundle, apart from the host. Old guest
sets never ask, and change nothing; a new set on an older host gets no block
and keeps its copy.

The header is regenerated, and the option ROM's record takes the header's
new hash (the ROM's bytes are unchanged); both guest sets are rebuilt with
the bundle's change, in the 📦 commit after it. Tests: the
header test, the peer and offer tests, a decoder test of what a read-only
block admits and refuses
(a_read_only_pages_block_holds_only_buffers_that_drop_their_writes), and the
kext's features and pages-block tests.
2026-11-14 03:39:14 -08:00
Anees Iqbal c2dbffc7bb 📝 Name the unshared queues and their log line as they are [ci skip]
GpuDevice::new_command_queue_unshared's doc listed the device's blit and
exec queues and the process's frame queue, which no code makes since the
paravirt lane went, and left out the decoder's release queue and the window
mirror's queue, which do exist. It now names the queues made unshared today,
each with the reason its own doc gives: the window sink's and its mirror's
(on a present's path), the IOSurface device caches' transfer queue (presents
and cache-drawn frames wait for its fills) and the decoder's release queue
(no guest command buffer may hold up the signal of a closed context's
events).

design.md said the host logs each unshared queue at info on
reims_vgpu::graphics; since f75493990 the line is at debug on its own
target, reims_vgpu::graphics::queues.
2026-11-14 03:33:56 -08:00
Anees Iqbal 89d2e8efd6 🐎 Index the spans the live objects lie over
A block's release is refused where an object of the decoder's lies in it
(Context::span_in), which looked at the span of every live entry of every
context, each in a box of its own: a cache miss an object. Particle Physics
spent 2.31 us a dispatch there on gbp-iris (perfscout4), about 0.5 ms for
each of its 106 releases on ring 0's thread, and Video Filter 11.33 us a
dispatch.

Each context's table now keeps the spans its live entries lie over, each
counted as entries come and go, and the longest it counted: a release looks
only at the spans that start no further before its block than that, a few
keys, and answers as before. The index is counted where an entry goes into
the live ones and taken out where it leaves, through the one function every
removal goes through, under the table's write lock with the change itself,
and an entry's span never changes while it is in the table, so it cannot go
stale. span_in_answers_as_a_look_at_every_live_entry holds both, through
random makes, makes over an id again, removes and closes with views open:
each step the index against the live entries' spans recounted, and the
answer against a look at every live entry.

Per run of gbp-iris (from perfscout4's profile and trace): Particle Physics
made 106 BLOCK_RELEASEs and spent about 50 ms on ring 0's thread in the
check, 0.47 ms a release; Video Filter 93 and about 19 ms, 0.2 ms each. The
index's check is a few BTreeMap steps under the read lock, about 1 us a
release (read from the cost test's 284 cycles over 8,192 objects; the real
tables' boxed entries cost cache misses the index never takes), so those 50
and 19 ms go to under 0.2 ms a run. Ring 0 carries out the guest's other
messages behind a release, so that is time the guest waits.

a_block_release_s_check_costs (homelab-ms01-1, release, user space: a check
over 8,192 objects of 6,144 blocks, median of 9 runs), before -> after:
  a check: 88,412 -> 589 instructions, 51,523 -> 284 cycles
(job m3-max-28671; a second pair of runs gave the same within 3%)
2026-11-14 02:24:30 -08:00
Anees Iqbal ddc2f9a450 ✅ Test and time the check that no object lies in a block
A block's release is refused where an object of the decoder's lies in it
(Context::span_in), which looks at the span of every live entry of every
context, each in a box of its own. Particle Physics spent 2.31 us a
dispatch there on gbp-iris (perfscout4), about 0.5 ms for each of its 106
releases, and Video Filter 11.33 us a dispatch.

A test sets span_in's answers beside a look at every live entry through
random makes, removes and closes with views open; a cost test prints its
user-space instructions and cycles a check over 8,192 objects.
2026-11-14 02:24:30 -08:00
Anees Iqbal abdc3a5d19 🐎 Keep the binding of a buffer bound again at its index
Each buffer a compute encoder's setBuffers names was cloned into the
encoder's bindings (predication's Bindings::bind_buffer), and the one it
replaced dropped, even where it was the same buffer bound again: an upload
chunk at its next offset before each dispatch, or a kernel's buffers set
again before each of its dispatches. Each such bind took the buffer's
reference count up and down, two locked writes, and a BTreeMap insert.
Super Resolution spends 1.30 us a dispatch there on gbp-iris (perfscout4).

The index's binding now keeps its reference where it holds the same object
already, and only its offset and stride change; another buffer is cloned
in, before the one it replaces drops, as before. The object's lifetime is
unchanged: the bindings hold it as long as before.

set_buffers_cost (homelab-ms01-1, Iris Xe, release, user space, a buffer
bound by a setBuffers of 8, median of 5 encoders of 4,096 sends), before
-> after:
  a buffer bound again where it is bound (same: an upload chunk at index 0
  at a moving offset, then 7 buffers set again): 166 -> 118 cycles (-29%),
  438 -> 444 instructions
  a buffer replacing another (fresh: from a pool of 64): 242 -> 224 cycles,
  507 -> 518 instructions
(job m3-max-28673; two pairs of runs, the same within 4%)

The two locked writes are the gain: the instructions stay within 2%, and
the 48 cycles a rebind saves are those two writes, about 24 cycles each
where the test's one thread keeps the count's line in its own cache. A line
another thread took last costs a locked write more.

decodeperf's dispatch_cost, one shape (2,600 dispatches in one encoder,
each after its bindings, Iris Xe, job m3-max-28744, two pairs of runs):
14,736 and 14,355 -> 14,146 and 14,457 cycles a dispatch, 33,263 -> 33,209
instructions, within its spread; its fluid and small shapes, an encoder a
dispatch, bind no buffer again (job m3-max-28732: the same within 1%).
2026-11-14 02:24:30 -08:00
Anees Iqbal 014b746caa ✅ Add a cost test of a compute encoder's setBuffers
Super Resolution spends 1.30 us a dispatch in predication's
Bindings::bind_buffer on gbp-iris (perfscout4): each buffer a setBuffers
names is cloned into the bindings, and the one it replaces dropped, even
where it is the same buffer bound again, as an upload chunk is at its next
offset before each dispatch.

The test sends setBuffers of 8 buffers to a compute encoder, the same 7
after a moving upload chunk, or 8 fresh ones each time, and prints the
user-space instructions and cycles a buffer bound.
2026-11-14 02:24:30 -08:00
Anees Iqbal 69499af6ac 🐎 Look a view's names up with one hash, in a map sized for them
Super Resolution spends 4.19 us a dispatch in tables::View::get on
gbp-iris (perfscout4), over 6,847 command buffers of about 6 dispatches;
gbl-iris's call graphs put 43% of View's samples in compute setBuffers'
binds and 18% in the views' drops. Each command buffer takes a view of its
table, and each object it names is looked up in the view's map, then in
the table under its lock, then put in the map: the map hashed the id twice
on a first lookup, and grew from nothing through four sizes as a command
buffer named its first 32 objects, moving every name at each growth. A
view's drop swept the gone list though nothing was on it.

The first lookup now hashes the id once (the map's entry, where the table's
answer goes in), the map starts with room for 32 names, and a drop with
nothing gone sweeps nothing. What a view finds is unchanged: the table's
tests of what a view sees hold it.

a_command_buffer_s_view_costs (homelab-ms01-1, release, user space: a
view over 4,096 objects naming 64 of them 4 times, median of 9 runs),
before -> after:
  a command buffer: 30,523 -> 25,144 instructions (-17.6%), 9,878 -> 8,161
  cycles (-17.4%); a name: 119.2 -> 98.2 instructions, 38.6 -> 31.9 cycles
(job m3-max-28671; a second pair of runs gave the same)

decodeperf's dispatch_cost, small shape (64 command buffers of 5 encoders,
Iris Xe, job m3-max-28732, two pairs of runs), does not tell it from its
spread: 74,250 and 74,113 -> 73,910 and 74,131 instructions a dispatch,
51,220 and 52,154 -> 50,554 and 49,858 cycles.
2026-11-14 02:24:30 -08:00