Commit Graph
334 Commits
Author SHA1 Message Date
Anees Iqbal eaa39e35eb 📝 Say what a Managed texture with no CPU copy is now [ci skip]
The design listed depth, stencil, PVRTC and three-component formats as the
Managed textures that keep no CPU copy. A depth or stencil one in Managed
storage ends the process before the bundle makes it, as on the x86 oracles
(882198139), and Metal has no three-component pixel format. What is left, a
PVRTC one, is the platform's texture alone, one copy on any GPU, reached by
the CPU through the staging blit a Shared texture's calls wait for, which sees
the GPU's writes with no synchronize: inside Q2's envelope, as the Intel 630's
and the M3's Managed textures behave.
2026-11-05 21:59:34 -08:00
Anees Iqbal 2cfd44fb18 🐎 Lay a one-level Managed 2D array over its CPU copy
On a GPU that shares the CPU's memory the host laid a Managed texture over
its CPU copy only where it was a one-level 2D texture: every 2D array kept two
copies there, the guest's CPU copy and the platform's own texture, so it took
its size twice in memory, each replaceRegion: was copied again on the host,
and the guest's getBytes: of it waited for a device copy. The platform makes a
one-level 2D array over a buffer too, by the linear SPI, which lays each slice
at its rows' bytes rounded up to 128 (measured on the M3 Max; the Vulkan
platform's runtime alike, array_over_host_memory_is_metals), and a CPU copy's
rows are multiples of 256 bytes, so its slices lie where the copy's layout
puts them.

For the host: on unified memory MANAGED_TEXTURE_CREATE of a one-level 2D
array of a linear format is newLinearTextureWithDescriptor: over the CPU
copy's buffer, its rows and slices the layout's, in place of a
newTextureWithDescriptor: beside it; TEXTURE_REPLACE_REGION and
synchronizeTexture: of it copy nothing. A texture of the one-copy shape whose
texture over its buffer the platform refuses is logged once. On a GPU of its
own memory nothing changes but where it has no memory for the GPU's copy,
where such an array now takes the one-copy form too.

For the guest: where the device answers hasUnifiedMemory yes, getBytes: of such
an array reads its CPU copy, as a one-level 2D texture's does, with no device
copy (rgfxManagedLiesOverCopy). A mipmapped texture, a cube, a 3D texture and a
block-compressed one stay two copies: no texture over a buffer has their shape,
and without the CPU copy an upload would be a staging blit the call waits for,
340 to 420 us a call where a Managed one's is 2 to 4 (dgpu-oracle.md Q17).

An older bundle on this host reads such an array through a device copy, which
reads the one copy: correct. This bundle on an older host would read a CPU
copy the host keeps apart: the two ship together.

Car 13's stack: resolved a comment in shell_tests.mm over
test_managed_texture_reads_on_unified_memory against c13-answers (16c2a86ad):
kept this commit's 2D-array wording and c13-answers' virtualAddress sentence.
2026-11-05 21:59:34 -08:00
Anees Iqbal dba9e9ce00 🐛 Give a queue its process's slot where a surface's record is full
Each surface's shared block holds four writer slots and four reader slots,
shared by every process's queues. A queue that found none free left its
access unnamed (logged once): a later write of another queue did not wait
for its reads, nor a later read or a present for its writes.

Where a record has no slot left for a queue, the bundle now gives it a slot
of its own process's that names a buffer of another of its queues which the
buffer runs after on the GPU, its post's SURFACE_ORDER having named that
buffer at the slot's seqno or later: whatever names the slot from then on
runs after both, as it ran after each. A read that finds no reader slot is
named among the writers instead (its queue's writer slot, a free one, or
one taken so), which every later buffer that uses the surface names. Only a
slot of this process's is written, and one raised past what the post named
is kept.

What the guest observes: an access to a surface whose record is full of
slots of this process's other queues is ordered against later accesses of
other queues as one with a slot is, where it was not ordered before; a read
named among the writers is also waited for by a later read of another queue
and by a present of the surface, which is later than a Mac would and never
sooner. An access whose records hold every slot for other processes' queues
is still not named.

Tests: test_iosurface_full_records_take_this_process_s_slots fails before;
test_iosurface_slots_free_at_completion's fifth queue's read is now named
among the writers until it finishes.
2026-11-05 21:59:34 -08:00
Anees Iqbal 0ac7209ebd 🐛 Set a timeline on the CPU only after its queue's earlier signals
Where a queue's buffer is not carried out and its queue makes no command
buffer for its stand-in, nor for a signal of its own (the platform out of
memory), the host set the queue's surface timeline to the buffer's seqno on
the CPU at once. A buffer of another queue that waited on the GPU for that
seqno then went on while the queue's earlier buffers, which named the same
surfaces, could still be running.

The host now notes, per queue, the highest seqno a committed command buffer
signals (a buffer whose walk faulted after its signal was encoded leaves it
as it was), and the CPU set waits first, with no lock held, for the timeline
to reach it, as a command buffer's signal would come after them. A reset of
the device ends the wait, as it ends the host's other waits for another
queue's buffers. A queue's destroy or close that has to set on the CPU waits
the same way.

What the guest observes, only where the platform makes no command buffer: a
buffer of another queue that runs after such a buffer now runs after the
queue's earlier work on the surfaces they share, not alongside it.

Test: a_cpu_set_for_a_buffer_not_carried_out_waits_for_its_queue_s_earlier_work
fails before. a_buffer_not_carried_out_still_signals finishes the queue's
earlier signals before its CPU set, which now waits for them.

Car 13's stack: resolved surface_order.rs's Release::signal, where
c13-decode-stalls (5e922707f) raises the done mark from the completion-seen
handler: kept that handler and took this commit's Arc clone of the marks for
it, and its committed mark after the commit. The CPU set's wait also ends on
the event's GPU-set value, so it still comes only after the queue's earlier
signals.
2026-11-05 21:59:34 -08:00
Anees Iqbal 39808c3a12 🐛 Know a queue in the surface order from its create's answer
The device answers a QUEUE_CREATE on its context's lane as soon as it has
made the queue's rings and started its service thread, and that thread then
hands the host the create, at which the host first learnt of the queue. In
between, a buffer of another queue whose SURFACE_ORDER named one of the new
queue's buffers found the queue unknown, counted it stale and waited for
nothing; a buffer of another queue of the process whose COMMIT_ORDER named
it was committed without waiting for it.

The device now tells the host of the queue before it answers the create
(Host::queue_made), and the host registers there what the queue's ring
publishes, for the surface order, the commit order and the presents, where
the service thread's create did it before.

What the guest observes: a buffer that names a buffer of a queue created
just before, while the host has yet to make that queue's handle, now runs
on the GPU after it (and, in its process, is committed after it), as it does
once the handle is made; it ran unordered before. Nothing else changes.

Tests: the_host_is_told_of_a_queue_before_its_create_is_answered (device)
and a_queue_s_buffers_are_waited_for_before_its_handle_is_made (host, with
the queue's service thread held before it hands on the create), each failing
before.
2026-11-05 21:59:34 -08:00
Anees Iqbal b5681a6e33 📝 Say why read-only no-copy memory never lies in place [ci skip]
Every Mac measured makes a no-copy buffer over read-only memory and drops
its GPU writes, a file under it included, where the host's buffer over a
pages block takes them: in place they would reach the process's read-only
pages. The shadow never writes back to read-only memory, so it drops them
as Metal does. The oracle README names oracle_bundle's new cases.
2026-11-05 21:59:34 -08:00
Anees Iqbal 814c527080 🐛 End the linear alignment query at every format x86 Metal ends it
minimumLinearTextureAlignmentForPixelFormat: answered 256 for every raw format
but the 105 of the SDK's that 3274b39d1 ended the process at. Both x86 Macs'
Metal (AMD 5300M and Intel 630, macOS 26.7.1, no validation layer; oracle_bundle
linalign over every raw value from 0 to 799 and 1000, 1023, 4096 and 65535)
answer 256 for 64 values alike, the SDK's 46 and 18 it has no name for (84, 85,
300 to 304, 313 to 315, 323 to 325, 556, 586, 587, 628, 629), and end the
process at all the others, with the compressed or depth words for those
formats and MTLPixelFormatInvalid for the rest.

What the guest sees now: the query answers 256 for those 64 values only, and
ends the process with Metal's words at every other: MTLPixelFormatInvalid (0),
the Y'CbCr formats, and values no format has among them, which answered 256
before. The bundle's own callers still ask the internal query, which ends
nothing.

Car 13's stack: resolved RgfxTexture.mm's rgfxEndAtUnalignableLinearFormat,
where c13-contract had moved the same lacked-format list into rgfxDeviceLacks
(kept for its other use): took this commit's answered-format list, which ends
at every lacked format too.
2026-11-05 21:59:33 -08:00
Anees Iqbal e828db91bc 🐎 Lay no-copy Managed buffers over the app's pages in place
A no-copy Managed buffer over writable app memory took a shadow: a range of
a slab as its CPU copy, synced with the app's memory at every commit that used
it and written back at every completion that might write it, and on a discrete
host a third copy, the platform's own Managed buffer, beside it.

Where the region has pages blocks it now lies over the app's own pages, as a
writable Shared one has since 2c09b2196: a BUFFER_OVER_PAGES whose buffer the
host makes Shared, so the memory is one copy on every host, as the Intel 630's
no-copy Managed buffer is (dgpu-oracle.md Q3; the AMD 5300M keeps two, and
Metal's contract for the mode allows either). The buffer still answers the
Managed options it was asked. Its didModifyRange:, and a blit's
synchronizeResource: or synchronizeTexture: of it or of a texture over it,
send the host nothing, as one copy has nothing to bring over.

What the guest sees: a GPU write to such a buffer shows in the app's memory as
the GPU makes it, not at its command buffer's completion, and a CPU write is
seen by the GPU's next read with no didModifyRange:, as on the Intel 630.
Read-only memory, and memory the kext or host makes no pages block of, keep
the shadow.
2026-11-05 21:59:33 -08:00
Anees Iqbal b4c0e4d67d 📝 Record what Metal does with textures over an IOSurface [ci skip]
Q20 holds oracle_surftex's answers on the AMD 5300M, the Intel 630 and the
M3 Max: the three steps where Metal ends the process, what a plane of a planar
surface takes, where the M3 answers nil, and which of the textures the x86
Macs make the host still refuses.
2026-11-05 21:59:33 -08:00
Anees Iqbal bd998e7ef8 🐛 Drop an ICB command's draws where it names a refused object
An indirect command buffer's CPU encode (an ICB_WRITE record or an ICB_SLOTS
field) that named an object whose posted create the host refused was skipped
alone, so the command kept its earlier binding or pipeline and went on drawing
or dispatching with it, where Metal would have drawn with the object the guest
named. The encoders already drop their draws and dispatches while a slot holds
such an object (94b7cb0b6); indirect command buffers did not.

What changes for the guest: such an encode is dropped and its command reset,
so it draws or dispatches nothing, and the command's later draws and
dispatches are dropped while its other encodes are carried out, until the
guest resets the command (a reset record or slot, a reset of a range, or a
blit's resetCommandsInBuffer:) or copies another command over it; a command
copied from a dropped one is dropped. The marks live with the indirect command
buffer's entry and cost one load a record where nothing was refused. A
command the GPU encodes is not seen by the host, as before.

Tests: an_encode_naming_a_refused_object_drops_its_draws_until_a_reset (the
records, each reset that ends a drop, a blit's reset and copy, a compute
command) and a_slot_naming_a_refused_object_drops_its_draw_until_a_reset (the
slots) fail at the base, where the draw after the refused binding is carried
out and no reset is.
2026-11-05 21:59:33 -08:00
Anees Iqbal 020fc3290f 🐛 Post a pipe transaction's colour and present as one
IOPresentment opens several display pipe clients for a display, and any may
submit a transaction. A transaction posts its colour as DISPLAY_COLOR parts,
then its PRESENT_SURFACE, and only its own client's submits waited for each
other: another client's present could land between them. The host applies
the parts it has staged to the next present it takes, so that present took
the other transaction's colour, and a stage whose parts it cut short was
dropped, its table unchanged.

The framebuffer now has a presents lock. A transaction takes it once it has
room, and holds it across its colour and its present; the PRESENT_SURFACE 0
the last client's going posts takes it too. What changes for the host: a
transaction's parts and its present reach the control ring with no other
present between them, where two clients submit at once (CGDisplayFade's
steps beside WindowServer's frames). One client's posts are unchanged.
2026-11-05 21:59:33 -08:00
Anees Iqbal 5b7c979bb3 🐛 Publish no framebuffer memory size after a mode change
The framebuffer published IOFBMemorySize, 134217728 (the scanout's room),
once WindowServer had set a new mode, and none before: IOFramebuffer's
setup for each new mode (setupForCurrentConfig, the only caller of its full
setup in macOS 26.7.1's IOGraphicsFamily, read) runs on the thread of the
task that set it, WindowServer's, which holds the server connection, so the
VRAM range went to it and IOFramebuffer published the range's size.

The framebuffer now marks the thread that runs that setup while it runs, and
gives it no VRAM range, as it gives the kernel's and the open's setups none.
What changes for the guest: IOFBMemorySize never appears in the
framebuffer's registry entry, as the Intel 630's and the stock paravirtual
framebuffer publish none (oracle Q19); before, it appeared after the first
mode change. IOFramebuffer's VRAM map offset stays 0, as before: our aperture
and VRAM range start at the same address. WindowServer's map of the VRAM
range through its connection is unchanged.

The setupForCurrentConfig override, a trace build's only, is now always
built.
2026-11-05 21:59:33 -08:00
Anees Iqbal b12a2e246c 🐎 Copy any read-back writer's output out early on a host queue
The early copy into a surface's pages (d718e066c) went only behind a command
buffer that holds a video encoder, on that buffer's own queue. Other writers
the CPU reads back after each write still downloaded at the lock: VT's pixel
transfer outputs (HEVC Main 10 to 420v, lock 0.53-0.55 ms on the RTX 5080,
decode-perf lk1), screen captures of a window server's surfaces, readers of
offscreen renders. A copy on such a writer's queue would hold the writer's
later work behind it.

A read-back surface's writer that holds no video encoder now has its early
copy on a host read-back queue, apart from the fills on the transfer queue.
The copy waits on the GPU for the writer's end value, copies the cache into
the pages, and signals the read-back queue's own end event. Later copies,
fills and writers of the cache wait for that event, as they wait for a queue's.
The download that follows is answered as the copy lands. The rules are the
video path's: the block reads back once a download copied a write that was the
only one since the cache's last copy, and a write no download followed ends
it. So a surface locked only now and then takes at most one copy that no lock
asked for.

What changes for the guest: on a host whose GPU keeps device caches (a
discrete GPU on the Vulkan platform), such a surface's pages hold the write
once the copy behind it lands, before any lock, and its lock's
SURFACE_DOWNLOAD is answered then. The writer's own command buffer, its
completion and its GPU times are unchanged, and so is the wire. Metal hosts
and GPUs that share the CPU's memory keep no caches and see no change. The
caches' log line counts the copies made on the read-back queue.

A commit on one thread racing a CPU lock of the surface on another, which
IOSurface leaves undefined, can name its write after the lock looked. On a
block that reads back, that write's early copy now lands in the pages whenever
the GPU runs it, among the CPU's writes, as a GPU's write lands where the GPU
shares the CPU's memory, and the newer generation's fill waits for it. Before,
the fill copied the CPU's writes over the GPU's. A block that does not read
back keeps that.

The read-back queue and its end event are made with the first command queue,
beside the transfer queue, never under the caches' lock.

Tests: a_read_back_queue_s_copy_in_flight_holds_the_next_writer (new);
a_write_no_lock_followed_ends_the_early_copies and
a_decode_read_back_is_copied_out_behind_the_next_decode now expect the copy
behind a writer with no video encoder, which the base did not make.
the_transfer_queue_is_made_unshared_with_the_first_queue,
an_unshared_queue_create_makes_the_platforms_unshared_queue and
creates_and_destroys_the_state_objects count the read-back queue and its end
event. a_newer_generation_fills_after_the_download_of_a_write writes twice
before its first download, so its block does not read back and its raced
write is filled over, as before.
2026-11-05 21:59:33 -08:00
Anees Iqbal ccb9ea0e1f 🐛 Hold three times WindowServer's measured blocks in its reserve
WindowServer's reserve kept the last 1024 of the block table's 16384 entries
for it, sized at three times the 366 blocks it held as five apps opened. With
some 70 processes open it held 1358 blocks, so once the other processes held
every entry outside the reserve, WindowServer was refused past its 1024th.

The reserve now keeps 4096 entries, three times the 1358, and the table's
sizes live in RgfxBlockTable.hpp, where the native test fills the kext's own
table with another process's blocks and checks WindowServer still gets them.
Its bytes stay at 160 MiB: most of the 169.7 MiB it held then were its no-copy
buffers' copies and its Managed textures' CPU copies, which lie in its own
pages now, as its Managed buffers' do.

For the guest: a process other than WindowServer is refused a block once the
table holds 12288 entries, where it was at 15360.
2026-11-05 21:59:33 -08:00
Anees Iqbal 3e33b3b66b 🆕 Grant texture resource ids 16 at a time in the kext
The kext's pool of texture resource ids held 255 chunks of 64, and every
process that makes a texture holds one until its close, so the 256th such
process found none and made no texture.

The kext now takes SMALL_ID_CHUNKS (bit 23) where the host offers it, keeps
the pool's owners by small chunk of 16 ids (1020 of them), and grants each
ask one small chunk with RESOURCE_ID_SMALL_CHUNK. From a host that does not
offer the bit it grants an aligned run of four, chunk k of 64, with
RESOURCE_ID_CHUNK, as before, and never posts RESOURCE_ID_SMALL_CHUNK. The
two kinds come from one table, so they never hand out the same id.

For the guest: each process's chunks of texture resource ids are 16 ids where
the host offers bit 23, so a process takes a chunk every 16 textures it holds
at once, and up to 1020 processes make textures at once.
2026-11-05 21:59:33 -08:00
Anees Iqbal 93ea42a435 🐛 Lay Managed buffers in the Shared slabs, not region blocks
A Managed buffer had slabs of its own options. Where the device does not
place Managed CPU copies in heaps (MANAGED_AT_OFFSET, offered only where the
GPU has memory of its own) those slabs were region blocks, each buffer a
BUFFER_OVER_HOST_MEMORY over its range, and past a superpage they were region
blocks on every host. So Managed buffers and the Managed no-copy buffers'
shadows held app-sized parts of the 1 GiB region every process shares, and
WindowServer's reserve in it: 256 MiB Managed buffers were nil 9 times in 10.

Where the device took MANAGED_BUFFER_SLABS, a Managed buffer lies in the
Shared class of its cache and hazard tracking modes: its range is a Shared
buffer's, made as any (BUFFER_AT_OFFSET in a superpage's or region slab's
heap, BUFFER_OVER_PAGES over a larger slab of superpages), and the Managed
buffer a MANAGED_BUFFER_CREATE over it, at an address of its own. Its range
goes back once the copy's destroy follows the buffer's. A device without the
feature keeps the slabs of their own. Nil, as before, where no source has
room.

For the guest: a Managed buffer comes as a Shared buffer and a
MANAGED_BUFFER_CREATE in place of BUFFER_OVER_HOST_MEMORY over a region range
or BUFFER_MANAGED_AT_OFFSET, and lies in the process's own superpages at any
size.
2026-11-05 21:59:33 -08:00
Anees Iqbal d225c9528f ⬆️ Build on metal2vulkan 52969c03d7's runtime
Pin move 14: stacks 28 to 30 on top of c7d79b43ef, in place of pin 13.
RUNTIME_VERSION 1769.

A host-replayed indirect command buffer keeps a step's chunks where two steps
read its records alike, draws whose plans list the same resident uses share
them, and a host step compares and decodes its records in place: on the RTX
5080 Laptop GPU the renderBundles page's host step took about 8.9 s a frame
at pin 13, 35-40 ms after stack 29, and about 33 ms after stack 30's cuts
(the runtime's measurements, the last before its own last two steps). A
device-local allocation that fails lies in system memory instead, announced
(device-memory-overflow, a performance kind). A pass that reads the clear
alone before any draw reads a copy cleared to it instead of splitting the
pass. A new Private texture starts as the Mac the device presents keeps it
(DeviceProperties::lossless_compression). On MoltenVK, whose blits through two
imports of the same pages are not ordered, a no-copy object over a guest RAM
chunk binds in the chunk's import. A batch waits for a staging submission only
where no earlier batch on its VkQueue did. A half read through an argument
buffer keeps the texel's half bits. A mesh the device draws takes its mesh
type's primitive, so a mesh of filled triangles draws no line.
max_buffer_length is three quarters of the largest device-local heap, rounded
down to 16 KiB: the RTX 5080's answer falls from 2^40, and the M3 Max's under
MoltenVK stays Metal's own 41,747,087,360, below its 48 GiB bound. The
graphics lane already answered at most three quarters of the device-local
heaps' sum.

New notices: device-line-ties at each draw of width-1 lines on a driver not
measured to break a diamond-vertex tie as Metal does, device-subpixel-snap at
each draw the band draws on a driver not measured to snap a half 1/256-pixel
step up, and device-nan-encoding for every half colour output to a half-float
channel on NVIDIA. MoltenVK on the M3 Max announces none of these anew: it
takes both facts, and it already noted every such half output.

The API grows by Degradation::DeviceMemoryOverflow, DeviceLineTies and
DeviceSubpixelSnap; RuntimeDriverDefect::AliasedImportBlitsUnordered;
DriverFact::LineTiesAreMetals, SubpixelSnapIsMetals and
ColorClearTakesEitherCode; DeviceProperties::lossless_compression and
MacClass; GraphicsState::mesh_corners; DriverDeviation and VkProperty
MetalUnaryDenormals; WorkCounts' new counters (device_memory_overflows,
attachment_read_clears, resident_uses_again_checked among them);
RecordView::record_into; and Device's Drop and hand-written Clone. It loses
VkProperty and DriverDeviation::MetalHalfColorNans, which nothing here used.

Cargo.lock is unchanged: the runtime's manifests are the same at both commits,
and the lock keeps its metal2vulkan source lines stripped.

The new kinds are placed by answer.rs's rules:
- device-memory-overflow is relayed, by its Exact statement.
- device-line-ties dies where its tie is not measured on MoltenVK, and a
  native device relays it, on the rule for native devices: the pixel a width-1
  line covers at a vertex two pixels' diamonds share is the driver's, which
  Vulkan's open diamond leaves to it with no control over it, and its only
  exact form is Metal's line rule run in the fragment function, an
  interpreter's. Every width-1 line draw on NVIDIA, lavapipe, RADV and ANV
  announces it.
- device-subpixel-snap dies on every device, as wide-edge-depth-bias does: the
  band is the runtime's own, and its endpoints snapped to Metal's grid before
  it offsets them would leave the rasterizer nothing to round, so the hardware
  allows the exact form. Only a band draw announces it, which on a native
  device under the default is a line below 1/16 pixel or past lineWidthRange.
- device-nan-encoding moves from what stays a death on a native device to what
  it relays, in the class of a native device's own maths and sampling: it
  differs in a NaN's bits alone, and there the runtime gives the device's NaN,
  its native form, and builds no path to Metal's bits where the device has one
  (its rule since 79166a74b1), as native-nan-encoding and
  device-texel-conversion's NaNs are relayed already. It still dies on
  MoltenVK. The placement test's list of the kinds that stay deaths on a
  native device loses it and gains device-subpixel-snap.
The accuracy ledger lists the device's width-1 lines among the device's own
answers and the band's snap under the wide_lines form.

Outside strict mode no new kind ends a run: a kind of DIES is relayed and
counted, and none of these is of DIES_BY_DEFAULT. The last good boots on the
RTX 5080 already relayed device-nan-encoding, at a draw that binds an
RG16Float texture, and relayed no kind of line.

Two tests pinned the runtime's old answers, and take its new ones:
- refused_icb_records_die_naming_the_execution: the runtime holds a commit's
  refusal of the records of a buffer the command buffer made resident for
  writing for the command buffer's host step, as a command buffer of another
  queue that this one waits for through an event, encoded after the commit,
  may still write the records before the work runs, and Metal runs what it
  wrote. Such records die as the command buffer ends, at the execution's
  selector, as at pin 11; records only the CPU wrote die at the commit, as
  before.
- the_default_filter_samples_within_its_bound_of_metals: the runtime gathers
  a two-plane 4:2:0 texture's planes in place too, so on MoltenVK a function
  that samples and gathers a YCBCR8_420_2P texture reads them in place: its
  floats and halves are Metal's bit for bit, and nothing that dies is
  announced (measured on the M3 Max). Its _sRGB twin keeps the default
  filter, within its bound, and dies of ycbcr-filter-not-exact in strict
  mode as before. The test gathers every observation before it asserts.
2026-11-05 21:59:33 -08:00
Anees Iqbal 85820d4dec 🐎 Commit a long command buffer in parts as it is walked
On the Vulkan platform a command buffer's GPU work starts at its commit, so
a long buffer's walk and its GPU work ran in series: WindowServer's
composite of a Liquid Glass desktop walked 2.6 to 3.5 ms and then ran 1.6
to 3.3 ms of GPU work each frame on an RTX 5080 Laptop GPU, against a
refresh of 8.33 ms, with its p90 at 7.5 to 8.5 ms.

At an encoder's end, once the part walked since the last took 250 us, the
walk now hands the platform that part (`CommandBuffer::split`) and goes on
in the command buffer it answers. A part is committed only where the whole
buffer could be committed then, waiting for nothing, and only for a buffer
of a context that waits for no event, is behind none that does and is not
a video buffer. While a buffer's parts are out, its context's other
commits wait at their commit and its range messages are carried out after
its last part, so each comes wholly before the buffer or wholly after it.

What the guest sees: one CB_SUBMITTED, CB_SCHEDULED and CB_COMPLETE per
buffer as before, the last two from its last part; a long buffer's
CB_COMPLETE sooner; its GPU times from its first part's start to its last
part's end; the first failed part's error. On the M3 Max (MoltenVK) a
frame of 60 passes completed in 6.0 ms from its message's take, where it
took 9.5 ms whole. A buffer whose walk faults after a part still fails at
its stand-in, but the parts committed before the fault have run, as the
encoders before a fault of Metal's GPU do; a whole buffer's walk fault ran
none of it.
2026-11-05 21:59:32 -08:00
Anees Iqbal f7778fec17 ✅ Check the colour records in the header; say why reset clears it
The header test now checks DISPLAY_COLOR's feature bit (24) beside
MANAGED_TEXTURE_SLABS's, the command's number, the two new records' sizes,
and PRESENT_SURFACE's flags word and RGFX_PRESENT_KEEP, as the kext compiles
them.

The device's reset keeps the scanout and turns every colour stage off. The
docs now say why: the scanout is the guest's own pixels, still in the
region, while the colour was set by transactions of a display pipe the
reset ended. Keeping it, a reset in the middle of a fade would leave the
window black with no transaction left to undo it. Docs and a test only.
2026-11-05 21:59:32 -08:00
Anees Iqbal a03b07c8ae 🐛 Complete a colour-only transaction when the display shows it
A display pipe transaction that sets only a colour (the boot fade's, a
CGDisplayFade step) completed at its submit, or with the transaction before
it, though the host shows its colour only at a later refresh. It now waits,
as a surface's transaction does, for the host's answer to its kept present,
and completes, and is notified, at the refresh that shows the colour. The
guest sees the later completion time and its waits (selector 9) return then.
2026-11-05 21:59:32 -08:00
Anees Iqbal 8da2022b04 🐛 Take the display pipe's gamma selectors and send their colour
WindowServer's IOAccelDisplayPipeTransactionSetPipePostGammaTable (selector
7) was refused kIOReturnBadArgument, as the kext took no structure there, so
CGDisplayFade (login, logout, sleep and mode-change fades), Night Shift and
ColorSync's calibration did nothing on the host's window.

Where the host takes DISPLAY_COLOR, the display pipe takes selectors 5 (plane
gamma), 6 (pre-gamma) and 7 (post-gamma) as macOS 26's IOAcceleratorFamily2
does (read): the structure inline or a descriptor mapped read-only, refused
BadArgument where shorter than its header or its entries or past 0x20000
entries, success with nothing changed for a transaction not begun, a plane
past 1 refused for the begun one. Each table is staged for the transaction
begun, dropped by the next begin, and its submit sends it, and the colour
matrix where the transaction's dirty mask has 0x40, as DISPLAY_COLOR parts
before its PRESENT_SURFACE. A transaction with no surface that sets a colour
goes as a kept present, and still completes as one with nothing to show.
Fields whose meaning nothing states are field_xx and logged. Selectors 10
to 13 stay refused: no WindowServer seen calls them.

Car 12: the kext carries bit 24 beside fx-capacity's bit 21 in
kRgfxCarriedFeatures, its doc and features_test, both kept, and the Makefile
runs both pipe_color_test and fx-kext-locks' ask_gate_test.
2026-11-05 21:59:32 -08:00
Anees Iqbal 5eb5c6f5cb 🆕 Carry the display pipe's colour on the wire
macOS's display pipe applies gamma tables and a colour matrix to what it
shows, set per transaction (CGDisplayFade, Night Shift, ColorSync). The wire
had no way to carry them, so the kext refused WindowServer's calls.

Wire 1, FEATURES_LO bit 24 (DISPLAY_COLOR): ring 0 carries DISPLAY_COLOR, a
colour stage of a transaction in parts of at most 256 entries, not answered,
and PRESENT_SURFACE's padding word becomes `flags`, whose RGFX_PRESENT_KEEP
asks for a present that keeps what the display shows and changes only its
colour. Both ride the presents' lane in ring order. The host trait gains
present_keep and display_color, whose defaults answer at once and drop the
colour. A present with an unknown flag, or a kept one naming a surface, is
refused INVALID_ARGUMENT. No host offers the bit yet.

Car 12: bit 24 sits beside fx-capacity's bit 21, MANAGED_TEXTURE_SLABS, in
wire.rs, the header, KNOWN_FEATURES and design.md's bit list, both kept.
2026-11-05 21:59:32 -08:00
Anees Iqbal 029cc3b229 📝 Record which types each form makes over a buffer [ci skip]
dgpu-oracle.md's Q11 now has the lintypes and linarray probes' answers on the
AMD 5300M, the Intel 630 and the M3 Max: the types each of the three forms
makes over a buffer, the words Metal ends the process with at the others, and
where the M3 lays a linear 2D array's slices, and what the bundle does with
each. The slice pitch's comment cited metal2vulkan's measurement and now cites
the M3's probe: slices of 48 bytes of rows lie 128 bytes apart and of 768
bytes 768 apart, whatever the bytesPerImage.
2026-11-05 21:59:32 -08:00
Anees Iqbal 87afae1b56 🐎 Hold a commit only for its own process's answered buffers
A command buffer answered CB_SUBMITTED at its take holds a ticket until its
commit, and every buffer begun after the answer was committed only once that
ticket was given back, on any queue of any context. So one process's slow
walk held up every other process's commits: each app buffer begun while
WindowServer's answered composite walked (2.6-3.5 ms a frame on the 5080)
waited for WindowServer's commit, and every WindowServer buffer begun during
an app's answered cold walk waited for that app's commit (car 8's 244 ms
WebKit walk, whose bystander queues went silent for 237 ms, and the video
CBs over 1 ms on their service thread).

A tracked resource is one process's, and Metal orders it by commit only
within a process (dgpu-oracle.md Q6). What processes share, an IOSurface, is
ordered on the GPU by SURFACE_ORDER and by the device cache's users, not by
commit, as a Mac orders it (Q16). Plain commits from two processes already
reach the platform in either order, so this adds no order the host could not
see before.

What changes for the host: a buffer of another context than an answered
buffer's may now be committed before it, where before it waited.
a_held_walk_answered_its_submitted_holds_only_later_commits becomes
a_held_walk_answered_its_submitted_holds_only_its_process_s_later_commits.
In it, another process's buffer is committed and completed while the held
walk is still held, and a buffer on the held process's other queue still
waits for it. Sequencer::wait_for now takes the waiting buffer's context. A
ticket or buffer of no context still orders against every one. The wait-free
check a short buffer's inline walk makes, Sequencer::reached, asks the same
per-process question.
2026-11-05 21:59:32 -08:00
Anees Iqbal 00dd1facf4 🐎 Walk a short buffer on its service thread when it waits for nothing
Every command buffer that held no video encoder had its walk and commit handed
to its queue's lane. On an idle lane that is a thread's wake (80 to 90 us on
the RTX 5080 laptop host, by decode-perf's measure). In a drain, each later
buffer's commit then waited on the turn before it, a second wake. On car 8 a
drain of 8 buffers took 70-90 us a buffer, against 35-53 on the AMD 5300M Mac.

Now a buffer whose message is 2 KiB at most, and whose commit would wait for
nothing at its begin, is walked and committed on the queue's service thread,
as a lone video buffer already was. "Wait for nothing" means: its turn is
next, no buffer answered before its begin is still to commit, none of its
context's range messages is pending, and every buffer its COMMIT_ORDER names
is committed (GraphicsDecoder::commits_at_once). The sequencer gets a
wait-free reached(mark) and a try-only ranges_done for that check. A longer
buffer, such as a compositor's frame, still goes to its lane, so the queue's
next buffers are taken beside its walk. The service thread runs only its
lane's oldest unfinished buffer, and that buffer waits for nothing, so the
waits still end. A buffer that asks for CB_SUBMITTED during such a walk is
still answered on its doorbell's thread, where it waits for nothing.

New test:
a_short_buffer_that_waits_for_nothing_is_walked_on_its_queue_s_service_thread.
The tests that hold a walk at the walk gate stand for a long walk, so they
send every buffer to its lane.
2026-11-05 21:59:32 -08:00
Anees Iqbal 9d9a1625b8 📝 Record the kache and LTO traps dist's SDL fell into [ci skip]
kache served dist's SDL from a run with none of its flags, as SDL's build
script declares none of them, and a release test link after a dist lost
std's __isPlatformVersionAtLeast to LTO; each says how to spot the next.
2026-11-05 21:59:32 -08:00
Anees Iqbal c9b243ff80 📝 Say what reims-graphics-pci calls and what its BAR 2 needs [ci skip]
QEMU's reims-graphics-pci writes every register through
rvg_graphics_device_mmio_write_taking, so a queue's doorbell may answer its
next command buffer on the vCPU; docs/api.md said it called everything but
that function. Its BAR 2 is the library's 1 GiB region, with the guest's
allocations from 0x400000, where the docs still said 256 MiB and 0x20000,
and a 1 GiB BAR needs the machine's max-ram-below-4g=1G, which docs/qemu.md
never named: reims-ctl does not add the device, so whoever adds it needs the
option too.
2026-11-05 21:59:32 -08:00
Anees Iqbal bfd0fc197b 🐛 Make a shared block's release wait for every holder's buffers
A BLOCK_RELEASE of a shared block waited for the command buffers of the
releasing context and of the holders whose BLOCK_UNSHARE the host had
received. The kext posts an unshare out of its lock, and gives up on it
after 5 s on a full ring, so another holder's last let-go can post the
block's release first. The host then answered while the first holder's
buffers could still write the surface in place. At that answer the kext
unwires the pages and lets the surface go, so GPU writes, such as the
white canvas a renderBundles frame draws, could land in pages macOS had
given out again. A close the kext takes for refused lets go of the
closing context's wire the same way, and the host's close had dropped
the context's holds without making the remaining holders' release wait.

The device now hands the host an unshare for every hold the release
ends whose unshare has not come, and for every shared block a close
leaves to other holders, before the release or the close. An unshare
that comes after the release or the close ended the hold is no longer
handed on. Before, it left a gate that a later, unrelated release at
the same offset waited on.
2026-11-05 21:59:32 -08:00
Anees Iqbal aafe9ba7ef 📝 Record when Metal's CPU sees a mid-buffer signal (oracle Q18) [ci skip]
oracle_cmdbuf events on the 5300M, the 630 and the M3: the CPU's value,
waits and listeners see a shared event's signal from the middle of a buffer
before the buffer ends, and the wait-then-set pattern completes on all three;
the AMD and the M3 see it within a few milliseconds of the GPU reaching it, the
630 about 100 ms after the commit. A trailing signal's listener runs within
0.3 ms of the completed handler.
2026-11-05 21:59:31 -08:00
Anees Iqbal dc6f82b8c9 🐛 Post a mid-buffer shared event signal as the GPU reaches it
A command buffer's signal of a shared event reached the guest only once the
whole buffer finished, ahead of its CB_COMPLETE. A guest thread that waits on
the CPU for a signal from the middle of a buffer, before it sets a value the
same buffer waits for later, deadlocked, where it goes on with Metal on the
5300M, the 630 and the M3 (oracle_cmdbuf events).

What changes for the guest: a signal the buffer has more work after (an
encoder, or a wait for an event) now reaches it as EVENT_SIGNALLED when the
host's event reaches the value, from a notification on one listener of the
device's, while the buffer may still run or wait to be scheduled. A value the
event already reached goes as the buffer is walked. A signal at the buffer's
end, and any no notification posted, still go with the completion, ahead of
CB_COMPLETE; each is posted once, whatever the outcome. A stand-in's signal
before its wait goes the same way. A signal of a shared event whose create the
host refused still goes with the completion wherever it lies: the host holds
no event to watch, and a post at the walk could come before the GPU's earlier
work. No wire or kext change: the bundle already takes the record wherever it
lies on the ring.
2026-11-05 21:59:31 -08:00
Anees Iqbal fa11c64788 🐎 Copy a decoder's read-back output into its pages as it ends
A CPU lock of a decoder's output took 1.4 to 1.6 ms at 1080p on the RTX 5080
(decode-perf's lk1 boot). The host copied the surface's device cache into its
pages only at the lock's SURFACE_DOWNLOAD, which the kext asks once it sees
the decode's CB_COMPLETE: 0.3 to 0.4 ms of it was the copy, and 0.25 to 0.35
ms the hops before and after it (the kext's wake and ask, the transfer
buffer's start, its completed handler). A client that keeps several frames in
flight locks most of them after their decode finished, and each lock then
paid the whole download: its locked runs were 10 to 20% behind the AMD 5300M
oracle (HEVC Main 10 1080p as x420, 547 against 627 to 685 fps; H.264 1080p
as 420v, 705 against 826).

The host now copies early where the CPU reads back. Once a download copied a
write that was the only one since the cache's last copy, the block reads
back: the next command buffer that holds a video encoder and is again the
cache's only writer is followed on its own queue, right behind it, by a
command buffer of the host's that copies the cache into the pages and signals
the queue's end event next, so the copy starts as the decode ends and later
copies of the cache wait for it. The lock's download is answered as that copy
lands, as the platform sees it done, with no handler thread woken between. A
write that no download followed ends the reading back until a download copies
again, so playback that never locks its frames copies nothing more. Other
writers take no such copy, as one on their queue would hold their later work
behind it. A copy in flight is waited for by a release before its answer, by
another queue's writer on the GPU, and by a decode into the surface on the
CPU, beside its wait for a fill.

What the guest observes: on a host whose GPU keeps device caches (a discrete
GPU on the Vulkan platform), a read-back decoder output's pages hold the
picture once the copy behind its decode lands, before any lock, and the
lock's SURFACE_DOWNLOAD is answered then. The decode's own command buffer,
its completion and its GPU times are unchanged, and so is the wire. Metal
hosts and GPUs that share the CPU's memory keep no caches and see no change.

The new tests fail at the base (no copy follows the second decode) and pass
here.

Car 12: download() and released() keep ce7f646db's behind_the_cpu beside
!written, with the early copy's landing in that branch, as the two owners
agreed; early_copies takes only CachePages::View pages (aud-r3-0906's enum),
copied ones taking no early copy; the counts line and the module doc keep
both sides.
2026-11-05 21:59:31 -08:00
Anees Iqbal 32b673e6e7 🐎 Answer a buffer behind ring 0 on the lane that lets it go
A command buffer whose process's ring-0 message is not yet carried out at
its doorbell waited for the message's lane and then for its queue's thread
to wake, before its CB_SUBMITTED. On msi that wake into an idle core was
85 us of the 150 us such a wait took on 11-02, a third of WindowServer's
frames.

For the guest: such a buffer's CB_SUBMITTED is now posted, and its vector
raised, on the lane's thread that carries the message out, before the queue's
thread is woken, wherever the host would answer it at its take. The queue's
thread files the buffer it took at the gate, the lane offers it to the host
once, with the gate's lock let go, and the thread hands it over once no offer
is under way, as one answered at its doorbell. Records keep their order and
each buffer is answered once. For the host: the lanes' threads, already named
for raise_interrupt, raise for these buffers too.
2026-11-05 21:59:31 -08:00
Anees Iqbal de3c2a8ac3 🐎 Return from a submit answered at its doorbell with no wake
A command buffer the host answers on its doorbell's vCPU has its
CB_SUBMITTED on the queue's completion ring before the doorbell write
returns. The committing thread still slept until the vector's interrupt
woke the framebuffer's work loop, which woke the completion thread, which
took the record and woke the committing thread: three guest thread wakes,
each a vCPU that may be halted, for a record already in place.

For the guest: a buffer that asks for its submission now looks for its
record on the ring as its post returns, after the bookkeeping a submitted
buffer is held to, and where it is there, commitAndWaitUntilSubmitted
returns at once, the buffer submitted and still Committed. The look reads
at most 64 records and takes none, so the completion thread still takes
each record in ring order and runs its handlers. A buffer not answered at
its doorbell waits as before. Nothing changes for the host.
2026-11-05 21:59:31 -08:00
Anees Iqbal 0d69e63a56 ✅ Hold a doorbell's write to freeing nothing on the vCPU
The vCPU tail measured on 11-02 was jemalloc's decay purge, 120-330 us,
inside frees the old inline take made on the vCPU. The answer at the
doorbell that replaced it is held to allocating nothing, but the count saw
no frees, where jemalloc purges as well. The unit tests' allocator now
counts frees beside allocations, and the doorbell test holds an answered
write and a write that only wakes the queue's thread to no allocator call
of either kind.
2026-11-05 21:59:31 -08:00
Anees Iqbal b826859585 🐛 Name a held buffer's surface accesses at its scheduling
Metal submits a command buffer that waits on an event below its value only
once the wait is met, and every buffer behind it on its queue with it. Until
then it orders no other queue's or process's access to an IOSurface after
the buffer: on the oracle's 5300M and 630 (macOS 26.7.1), another process's
blit of the surface, and its read-only CPU lock, went on at once while the
write waited on its event, the blit reading the surface as it was.

The bundle named every buffer's accesses at its post: its writer or reader
slots, which other queues' posts name in SURFACE_ORDER, and its writes to the
kext, which CPU locks wait for. So a read posted while such a write waited
was held behind it on the host's GPU, and a lock in the kext, for as long as
the event stayed below its value: a hang where a Mac has none, wherever the
event's signal waited on that read.

A buffer is now held at its post where it waits on an event below its value
as its process knows it (a shared event's value as the host posted it and
the CPU set it; a plain event's as the host finished the process's buffers
that signalled it), or is posted behind a held buffer of its queue. A held
buffer names its accesses at its CB_SCHEDULED, which the host posts once its
platform has scheduled the buffer, past its waits, or at its completion where
none came. A delivered buffer names nothing, so no write reaches the kext
after its retire.

What the guest observes: a read, CPU lock or present of a surface by another
queue or process, posted while a write of the surface waits on an event below
its value, goes on at once and sees the surface as it was, as on a Mac; it
waited for the write before. A wait already met holds nothing, and such a
buffer's accesses are named at its post as before.
test_iosurface_held_buffer_names_at_scheduling holds a write that waits on a
plain event nothing signalled, and the write behind it, until each is
scheduled, and names at the post a write whose plain or shared event is met.
2026-11-05 21:59:31 -08:00
Anees Iqbal 23e42f08f3 📝 Say a Mac drops a dead process's waiting buffer [ci skip]
Measured on the oracle's 5300M and 630 (macOS 26.7.1) with a probe of two
processes on one GPU. A child commits a buffer that waits on its own shared
or plain event, then fills a shared-memory buffer and clears an IOSurface. It
exits or is killed without signalling. Neither write lands, 2 s and 5 s
later, while the controls (no wait; a signal just before exit) land.

The host runs such a buffer at its context's close (357c35e51): it has
committed the buffer to its platform behind a GPU wait, which no platform
takes back, and holding it would keep its pins and the close's answer for
good. The design now says so, and that its writes land where a Mac's do not.

The same probe found that a Mac lets another process's read of the surface,
committed while the write waits on its event, complete at once with the
surface's old bytes, where the host's surface order holds the read until the
write finishes. The design says that too.
2026-11-05 21:59:31 -08:00
Anees Iqbal c147596f5d 🐛 Free a surface's order slots once the buffers they name finish
A surface's shared block holds four writer slots and four reader slots,
shared by every process's queues. A buffer's post names, from them, the
buffers of other queues it runs after (SURFACE_ORDER), and a present waits
for the writers. A queue kept its slot until the queue itself went, though
the buffer it named had long finished. So once four queues had used a
surface, WindowServer's and other long-lived processes' among them, a fifth
found no slot: its reads were named to no later write by another queue, and
its writes to no present or read. Per-process commit-order tickets take away
the last thing that ordered such a write after an answered read of another
process, its wait for the read's ticket.

A buffer's slots are now emptied once the host has finished it and its post
has named it, whichever comes second, where no later buffer of its queue has
raised them. A slot names a buffer only while it runs, and a buffer that
named a finished one would wait for nothing. The readers lie past the writers
in every block, as they did: the bundle laid out no block without room for
them, and two static checks of the layout now hold that.

What the guest observes: accesses to a surface by more than four queues
over time, with at most four of them in flight in each record, are each
ordered after the others' where one of two writes, as on a Mac; before,
every queue past the fourth went unordered. Waits for buffers that are
running are unchanged. test_iosurface_slots_free_at_completion reads a copy
another process writes, checks the slots a write of another queue reads
while the read runs and after it finishes, and gives a fifth queue the slot
a finished read left.
2026-11-05 21:59:31 -08:00
Anees Iqbal ec7ec3ff76 📝 Say the surface order is named at the post, and fits every block [ci skip]
The design said the bundle names a buffer's surface order as it commits; it
names it as it posts the buffer (3c4b77038). It also said a copy whose writers
end within 64 bytes of a page's end has no readers, so a write of it waits for
no read. No block the bundle lays out is such: a copy's planes start and end
on 256 bytes (kShadowRowAlign), which leaves its header, writers and readers,
152 bytes, room in the page, and a block in place holds the header and the
slots alone. Read from RgfxIOSurface.mm's layout.
2026-11-05 21:59:31 -08:00
Anees Iqbal 4d931d2339 🐛 Name a buffer's surface order as it is posted, not committed
Where the host orders command buffers of different queues over the IOSurfaces
they share (SURFACE_ORDER), the bundle names, for each buffer, the buffers of
other queues it runs after, from the surfaces' writer and reader slots. It
read the slots at the commit. A buffer committed behind one enqueued before
it and not yet committed goes on its ring only once that one is, so another
queue's access to the surface could be posted in between: the held buffer
named the access before it, and the access, which found the held buffer not
yet in the slots, named nothing of it. The two ran unordered, where Metal
submits the held buffer after the access, and so runs it after (read from
Metal's enqueue order; no oracle has measured a held buffer's surface order).

The slots are now read at the post, just before the buffer goes on its ring,
where the commit order's names are read too. The device-cache uses
(SURFACE_USE), with the CPU's generation as of the commit, are still named
at the commit. Each buffer named was still posted before the post that names
it, so the waits run from later posts to earlier ones and cannot meet in a
cycle.

What the host observes: a held buffer's SURFACE_ORDER names the accesses of
other queues posted up to its own post. A buffer posted at its commit names
what it named before. test_iosurface_order's new case posts another queue's
write while a reading buffer is held: the held buffer names it.
2026-11-05 21:59:31 -08:00
Anees Iqbal 3c8d03c741 🐛 Set a gone context's events past every value
A command buffer that waits on an event of its own process waits until a CPU
set or another buffer's signal reaches the value, as Metal's does. When the
process closed the device or died, or the device was reset, nothing was left
to set or signal its events: no event of the guest's crosses processes, and
its queues had ended. Such a buffer waited for good. It held its queue and
every object it names, the GPU addresses its buffers pin among them, and its
context's drain, so the close was never answered and the kext kept the
context's GPU address units from use for good. After a reset the rebooted
guest picks those addresses again, and the pins still held refuse its
buffers.

The decoder now sets each shared event of a gone context past every value
on the CPU, and signals its plain events past every value with one command
buffer on a queue of its own, made unshared at the first close that needs
it, so no buffer of the guest's holds it up. The close and the reset pass
the device for it.

What the guest and the host observe: a command buffer of a closed context,
or of one the reset dropped, that waits on one of its events now runs and
finishes then, as one in flight does, and lets go of what it holds; the
close's answer then comes. Nothing changes while the process lives.
a_gone_context_s_events_are_set_past_every_value checks the calls at a
close and a reset.

Car 12: close_tables keeps aud-r3-07's give-back of unbegun answers before
this commit's release_events, and its doc drops FailedContexts as fx-cascade
did; the reset test calls reset(&device) with aud-r3-07's assertion text.
2026-11-05 21:59:31 -08:00
Anees Iqbal b42ec184cf 📝 Record two refusals' words and IOFBMemorySize (oracle Q19) [ci skip]
oracle_names on the 5300M, the 630 and the M3: a function constant given a
value of another type is refused with the same type names on all three, in a
sentence each OS words its own; a mesh pipeline's binary archive add is refused
on x86 with or without its functions, where the M3 asserts on a descriptor
with no mesh function and records one with it; all three make the pipeline
itself, which ours refuses. The AMD's framebuffer publishes IOFBMemorySize and
the 630's does not, so ours publishing it after a mode change is inside the
envelope.
2026-11-05 21:59:31 -08:00
Anees Iqbal f28a9f09aa 🐛 Drop what names a refused create, not its command buffers
The bundle answers many creates at the call, without the host's answer:
buffers, heaps, textures and their views, depth/stencil states, events, fences,
shared events, video sessions, and pipelines equal to an accepted one. When
the host then refused one (the platform made nothing, or died at the create),
the id named nothing on the host. Every command buffer that named it failed
with an internal error, and so did every create over it and every buffer
naming that. One refused texture failed its process's frames from then on.

What the guest sees now: the id stands for a refused object until its
destroy, and only what names it is dropped. The command buffer completes.
- An op that uses it is dropped: a copy, a fill, a draw from it, a fence
  update or wait.
- A binding of it binds nil and marks its slot. The encoder's draws and
  dispatches are dropped while a slot is marked, until the slot is bound
  again. A refused pipeline is not set at all.
- A use list's entry of it is nil.
- A render pass with it as an attachment is skipped whole, and so is a video
  encoder of its session.
- A wait for it as an event is dropped. A signal of it as a shared event
  still reaches the guest's value.
- A compute predication over it skips the rest of its encoder.
- A create over it, such as a view, stands refused in turn.
- Its managed-memory updates and shared-event sets do nothing.

This also covers a texture the bundle answered that the host refuses later:
its command buffers no longer fail.

Tests: at the base,
a_command_buffer_naming_a_refused_pipeline_fails_in_order_and_signals_its_events
asserted the failure. Its replacement,
a_command_buffer_naming_a_refused_pipeline_drops_its_draw_and_completes,
asserts the buffer completes with its draw dropped.
what_names_a_refused_create_is_dropped_and_its_command_buffer_completes covers
a refused texture, its view, a refused shared event, a skipped pass, a nil
binding whose draw is dropped and a rebind whose draw runs. The refused
module's unit tests cover the slot marks and which creates stand refused.

Car 12: design.md's "One reason stays" paragraph keeps fx-managed's rewrite
(cbcad4945), with this commit's "whose draws with it are dropped on the host"
in place of "which fail on the host".
2026-11-05 21:59:31 -08:00
Anees Iqbal 916494dc3e 🐛 Fail only the command buffer whose completion was refused
A command buffer whose completion the platform refused on its own thread
(a death in its read that no Metal answer matches) failed its whole context.
The host then refused the context's later command buffers, creates, queue
creates, library lookups and heap-size and argument-layout queries until the
context closed. When this hit WindowServer's context, every later frame
failed and the display froze.

What the guest sees now: only that buffer fails, with an internal error
(MTLCommandBufferErrorInternal). The context's later command buffers
complete, and its creates, queue creates and queries are answered as any
context's. This matches a Mac, where a GPU error fails the command buffers it
strikes, WindowServer's among them, and their processes' later buffers run
(docs/lessons.md, measured on macOS 27.0.1).

No context is marked failed any more. The decoder keeps only the closed
contexts and the reset count (ClosedContexts). reims-graphics'
Host::context_refused hook has no caller left, so it goes, along with its
test.

Test: at the base, a_completion_the_platform_refuses_fails_its_context
asserted the refusals. Its replacement,
a_completion_the_platform_refuses_fails_that_command_buffer_alone, asserts
that the context's later buffer, sampler create and queue create are carried
out.
2026-11-05 21:59:31 -08:00
Anees Iqbal 998d692afc 🐛 Lay Managed textures' CPU copies in the slabs, not region blocks
Each Managed texture's CPU copy was a region block of its own, in the 1 GiB
region every process shares, so a desktop of apps with Managed textures ran
the region, and WindowServer's reserve in it, short.

Where the device took MANAGED_TEXTURE_SLABS, the copy is now a Shared buffer
of the process's slabs, as a device buffer of its size is: the process's own
superpages where the device takes them, else a range of a region slab shared
with other buffers. It reads zero as before, and MANAGED_TEXTURE_CREATE names
it. A device without the feature keeps the region block. Nil, as before, where
neither has room.

For the guest: a Managed texture's CPU copy comes as HEAP_OVER_* and
BUFFER_AT_OFFSET (or BUFFER_OVER_PAGES) in place of BUFFER_OVER_HOST_MEMORY
over a block of its own.

Car 12: kept fx-managed's test_managed_texture_reads_on_unified_memory
beside this test in shell_tests.mm, where both were added.
2026-11-05 21:59:31 -08:00
Anees Iqbal cc7c19f401 🐛 Put a no-copy buffer's GPU copy in a slab, not a region block
A no-copy buffer over memory the host does not use in place (read-only, a
Managed buffer's, or memory the kext or host makes no pages block of) took a
block of the device region of its own for its GPU copy. The region is the one
1 GiB BAR every process shares. At 75 processes the copies held 88 MiB of its
308 MiB in 1208 blocks, nearly all of them WindowServer's (libstage1 app load
on the RTX 5080 host). WindowServer's 160 MiB reserve then had to cover them,
and an app's copies could fill the room the others needed.

The copy is now a range of a slab of the buffer's options, as a device
buffer's is: the process's own superpages where the device takes them, the
region's slabs only where the kernel has none. It is synced with the app's
memory as before. For the guest, a Shared copy's buffer is now placed in a
slab's heap, so its GPU address is the heap's plus its offset. Nothing else
the app sees changes.
2026-11-05 21:59:31 -08:00
Anees Iqbal 859625a1f5 🐛 Keep the graphics display's scanout across a reset
A reset of the reims-graphics device (STATUS 0, or the host's reset) blanked
the display: the screen was told there was no scanout, and the window kept
its last frame. The kext's start resets the device to take it, and where the
start fails after that (the device lists no usable display, IOFramebuffer's
start fails) it resets it again on the way out. The OS then draws into the
firmware's framebuffer, but the firmware's scanout was gone. The host's
window stayed on the boot screen, and nothing the guest drew after that
reached it.

What the host sees now: a reset leaves the display's scanout as the last
SET_SCANOUT set it. A GPU's display engine does the same across a reset of
its driver. The screen is told nothing at the reset, and each refresh shows
the guest's writes there as before, until the guest sets another scanout or
blanks it. A reset while the display pipe shows a surface shows the kept
scanout in its place. The guest sees no change: nothing it reads names the
scanout.

The tests cover the failure after the take on the device and through the
window's sink on the testkit's platform. In the crate's tests the window
asks the host for no screen, so on Linux they start no UI thread.
2026-11-05 21:59:31 -08:00
Anees Iqbal b5846b36f7 🐛 Read a two-copy Managed texture's GPU copy on unified memory
On a GPU that shares the CPU's memory the host lays a Managed texture over its
CPU copy only where a texture over a buffer has its shape: one level, one
sample, 2D, of a linear format. Every other shape (mipmapped, an array, a cube
or a 3D texture, a block-compressed format) keeps two copies there too, and the
bundle's getBytes: read the CPU copy, which shows the GPU's writes only after a
synchronizeTexture:. On such a GPU Metal shows them with no synchronize (the
Intel UHD 630 and the M3, oracle_storage mtex), and the guest's device answers
hasUnifiedMemory as the host's platform does: yes on Apple silicon and on an
integrated GPU (or lavapipe) of the Vulkan platform, no on a discrete one.

For the guest: where the device answers hasUnifiedMemory yes, getBytes: of a
Managed texture of a two-copy shape now reads the GPU's copy through a device
copy (rgfxCopyRegion:), as a Shared texture's does, so it sees the GPU's writes
and every region replaceRegion: posted before it, and it waits for that copy's
command buffer. replaceRegion: is unchanged, and so is every texture on a
discrete GPU and every texture the host lays over its CPU copy.

The bundle knows the shape alone (rgfxManagedLiesOverCopy, the host's
in_place_shape), so a texture of the in-place shape whose texture over its
buffer the platform refuses still reads its CPU copy; the module doc says so.
2026-11-05 21:59:31 -08:00
Anees Iqbal 12d33abd3b 📝 Say why an equal pipeline create can still be refused [ci skip]
The design said a known pipeline create's one remaining refusal was the
platform running out of memory at the new state's own VkPipeline link, and
that the gap closes once metal2vulkan shares linked pipelines between equal
keys. At the pinned runtime (b01aec5cbe) an equal create already takes a live
earlier state's variant, its shader modules, layouts and VkPipelines, with no
driver call, or a released one's kept objects, and the VkPipeline a create
begins never refuses it. What can still refuse it is the runtime making the
variant's objects again where neither is left, or compiling it again under
the 20 s deadline where its memo and shader cache let it go. Read from the
runtime's pipeline/render.rs, memo.rs, kept.rs and options.rs.
2026-11-05 21:59:31 -08:00
Anees Iqbal c137c4a19a 🐎 Carry an out-of-line command buffer out from the device's copy
A command buffer was copied twice on its queue's service thread: the device
copied its message out of the region (a COMMAND_BUFFER_IN_REGION's out of its
block, a ring's off the ring), and the host's hand-off to the buffer's lane
copied that copy again (message.to_vec()). An out-of-line buffer paid two
fresh allocations of its whole length on a thread that takes its queue's
buffers one at a time.

Host::command_buffer now hands the host the device's copy, which the host
takes to the buffer's lane as it is; its default hands the message to
stage3_message, as before. The host still does not read the block in place:
the process may write its block at any time, and what the host checked must
stay what it carries out (region.rs).

an_out_of_line_command_buffer_is_carried_out_from_one_copy counts every
thread's allocations of the message's length while such a buffer is carried
out: two before, one now. command_buffer_copy_cost (ignored, by hand) prints
what each copy costs under the shipped allocator.
2026-11-05 21:59:30 -08:00
Anees Iqbal 9679523a17 ✅ Make the tests that fault or fill the Mac's GPU opt-in
metal_drops_small_blits_into_the_texture faults the GPU on purpose, and
a_reservation_of_2_31_minus_1_is_metals holds 16 GiB of its memory for about
a second. On a Mac every process shares the GPU, so each run failed the
in-flight work of every other process, the desktop's included: a stress loop
of the first restarted the GPU under the owner's WindowServer on the M3 Max.
Both are #[ignore]d now, run only for a change to what they test (nextest
--run-ignored only), and nextest.toml still runs them first and alone then.
AGENTS.md and docs/lessons.md say so.
2026-11-05 21:59:30 -08:00