Commit Graph
1165 Commits
Author SHA1 Message Date
Anees Iqbal b944f69bfa 🆕 Make the device's texture buffers over a buffer of its own
rt makes a texture buffer (a VkBufferView) only over a buffer its consumer
places, through Buffer::new_texture, and refuses one its device places
(Refusal::TextureBufferNotOverBuffer, a rule of rt's own), so a guest's
newTextureWithDescriptor: of MTLTextureTypeTextureBuffer was nil, counted
under rt-refused-ours.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

Ring messages, events and their order are unchanged; only which library
thread walks such a buffer changes.
2026-11-21 02:55:59 -08:00
Anees Iqbal 9c211e49a3 ✅ Run the held-create race tests on fair-share mutexes
The two race tests of 21e637db25 passed against the two-hold code they guard:
on libpthread's default mutex policy the committing thread took the held
messages' mutex again before the thread waiting on it, so the window between
the holds was never met. Each now runs in a child of its binary on the
fair-share policy (PTHREAD_MUTEX_DEFAULT_POLICY=1, rgfxRunFairShare), where an
unlocked mutex goes to its waiter, and checks that the child has it. The
protocol test's kext now refuses a held destroy, as a post that took every
held message leaves the old check a lock-free answer that waits for nothing.

Against the sources before the fix both fail, the serializer's at
postHeldCreates and the protocol's at the buffer missing from its ring; on
the fixed tree `make -C guest test` passes. The trap is in docs/lessons.md.
The bundle's tests are not among the sets' sources, so the sets stay as built.
2026-11-21 02:31:50 -08:00
Anees Iqbal 932e907844 🆕 Name and place a lost device's driver fault on its line
A lost device's line named the Vulkan call that met the loss and nothing of
the fault behind it, so a loss on the host left no trace of what the GPU read
or ran when it faulted. rt reads the driver's report (VK_EXT_device_fault) at
the loss and places none of its addresses: that is the platform's to do, as it
holds the guest's objects and the blocks they lie in.

On the host, a lost device's line is now followed by the fault's lines on
stderr: the driver's description and vendor records; each access it names,
rounded to its precision and placed among the decoders' live objects (buffers,
heaps, textures over a buffer, Managed textures' CPU-copy buffers) and the
mapped blocks the host sees (rt's pool allocations, the device's known blocks
and dma-buf imports, the blocks of live objects), with the offset in each that
holds it; where none does, the nearest live object and the nearest mapped
block below and above the address, each with its id or class and its distance
in bytes; each instruction pointer, placed the same way, with the note that no
range the host sees holds shader code; and what the placement saw and did not.
A loss that rt read no report for says so on one line.

The device gives rt a BlockMappings that maps nothing and refuses nothing, to
keep its pool allocations' ranges, and each import's range is kept beside the
record of where it was imported. The decoders' tables are walked only at the
loss, each walk waiting 500 ms in all for its locks, as the lines are written
on rt's completion thread. Nothing the guest sees changes.
2026-11-21 02:17:24 -08:00
Anees Iqbal 072b940f5b 🐛 Wait for the host's answers behind a compile with no deadline
A pipeline create waited 60 s for its reflection. On a slow host or a cold
compile the app got nil, and the destroy posted behind the create cancelled a
compile that would have succeeded. Other waits for host answers had the same
problem. A queue's create (30 s), SURFACE_PAGES (30 s), shared events (60 s),
a CPU lock's wait for its surface's writes and the host's copies (2 s), a new
block's wait for a write-back (10 s) and the bundle's library chunk acks
(10 s) all sit behind the context's earlier work on the host, a compile among
it. At their bounds a lock read whatever bytes the pages held.

Each of those waits now has no deadline, as Metal's own calls wait for the
GPU's driver (RgfxAnswerWait.hpp). It sleeps THREAD_INTERRUPTIBLE, so a caught
signal never ends it, and it ends only:
- at the answer;
- at the device's stop: quiesce wakes every waiter, and the waiter finds the
  device stopped;
- at the thread's abort (SIGKILL, a fatal signal, exit), returning
  kIOReturnAborted.
An aborted create still gets its destroy posted behind it. A CPU lock waits
with no deadline for the device to complete its writes' buffers. Its 2 s bound
now counts only from that completion to the bundle's retire, so a process
that locks a surface on the thread that would retire it still goes on.

The 64 lifecycle waiters are split by kind: 32 for the processes' creates and
shared events, 16 for surface pages and downloads, and 16 for the device's
own asks (queue create, close, pool takes, kept answers, video). Creates
waiting on compiles can no longer take the waiters WindowServer's surface,
queue and close asks need. A waiter take that ends unanswered returns
kIOReturnBusy, so a caller never mistakes an unposted message for a posted
one.

The waits that do not depend on host work keep their deadlines, each with its
reason in a comment: ring room, display commands, the start's kept answers,
a context's close, the display pipe, arm64 video sends and the region-room
wait.

What the guest now sees: a lock or present behind a slow compile waits for
it, and a create returns its pipeline however long the compile takes.
2026-11-21 00:55:09 -08:00
Anees Iqbal 14c00263ef 📝 Record the software decodes of refused HEIC items [ci skip]
The fix boot of the start refusals measured what the guest gets: sips's decodes
of a 4:4:4 thumbnail and of a monochrome alpha item now come out, decoded in
software and within 2/255 of the M3's decode, where today's tree left sips no
picture.
2026-11-21 00:06:32 -08:00
Anees Iqbal f597199008 🐛 Refuse VideoToolbox sessions of streams the host decodes none of
An arm64 guest's HEIC images hold items the host's arms cannot decode: Apple's
desktop thumbnails include HEVC Rext 4:4:4 streams, and its alpha items are
Rext monochrome. Every arm's decode of a picture runs the codec's
check_supported, which takes 4:2:0 alone, at 8 bits, or HEVC's at 10 too.
The paravirtual decoder still started tile sessions on such streams. dsts
named a 4:2:0 format in TDrs, CMPhoto lent a 444f buffer for the 4:4:4
stream, and every dtil failed at vt.rs's region_layout ("tiles in '444f'",
seen four times in an arm64 26 boot on a 780M host).

read_record now runs check_supported on the record's SPS, so these streams
are refused when their session starts instead of at each tile or frame:
- dsts answers kVTUnimplementedErr with no TDrs. That is the answer on which
  the guest's VideoToolbox decodes the image in software, as for a backend
  that decodes no tiles. Rext 4:4:4 thumbnails and monochrome alpha items
  now fall back to software decode at the session's start, where today each
  tile fails at region_layout.
- dsta answers kVTVideoDecoderUnsupportedDataFormatErr with no Dpba.
Every session that opens is then of 4:2:0 pictures, whose format TDrs and
Dpba name (420v, 420f, x420 or xf20), and region_layout lays out all four.

This also refuses HEVC streams deeper than 10 bits at their start. Before,
nothing refused them, although read_record's doc said it did. An H.264
stream deeper than 8 bits is now answered kVTUnimplementedErr at dsts
instead of kVTVideoDecoderUnsupportedDataFormatErr, so its tiles fall back
to software in the same way. The tests have a table of formats for each
codec: 4:2:0, 4:2:2, 4:4:4 and 4:0:0 at 8, 10 and 12 bits, in video and
full range, Main, Main 10, Main Still Picture and Rext. Each row lands in
its 4:2:0 format or is refused at the start of both kinds of session.
2026-11-21 00:06:32 -08:00
Anees Iqbal ca3d35a9aa 🐛 Make one video decode queue on each Direct3D 12 device of ours
The guest now gets right pictures from concurrent decode sessions on a
Windows host. Intel's Direct3D 12 video driver for the UHD Graphics 630
(igd12dxva64.dll 31.0.101.2145) decodes wrong pictures on a device's later
video decode queue while an earlier one lives, and Mesa's vaon12 makes a
queue for each VA context, all on the process's one device. Of two guest
sessions decoding at once, one got wrong pictures.

While a device of ours is held, its ID3D12Device::CreateCommandQueue (the
vtable's slot 8) answers every ask for a video decode queue with one queue
it keeps, a reference added for each asker. Other queue types, and devices
no hold holds, go to the slot's own method. No vendor decides: every device
gets the one queue. The slot gets its own method back when the last hold on
a device with that vtable goes, and the kept queues go with the last hold on
their device.

Measured on the UHD 630, 4K H.264, frames per second in all: one session
25.4-27.4, two 53.2-56.1, four 113.6-116.0 with one queue, against 22.9-26.9,
49.7-52.2 and 101.8-111.9 with a queue each, where the sessions decoding
wrong ran fastest. The new test of two decoders at once passes 3 of 3 with
the one queue and fails without it; the churn test decodes none wrong in 3
runs. docs/video/bugs.md U33 records the driver's bug and the split.
2026-11-20 23:59:36 -08:00
Anees Iqbal cc36995975 🐛 Keep a VA decoder's pool and config with its kept context
On Windows the kept-context change held only a context's teardown and
destroyed a pool's surfaces and its config at once, beside the display's
live contexts. That passed the two-thread test, but rounds of 2 and 4
decoders each decoding the stream at once, each picture waited for and not
read back, had a decoder's vaEndPicture fail in every run of 6 on vaon12 on
the UHD Graphics 630 (potluck jobs m3-max-61922, 61930, 61939), where
development, which holds every teardown, passed 4 of 4, and holding the
surfaces' teardown too passed 2 of 2 (m3-max-61948).

So every teardown is held again while a context lives, and a decoder's
context is kept with its config and its pool: Context::new_decoder makes
the three, or takes the three back for a decoder of the same shape (now
with the surface format and count), so beside a live context nothing is
made or destroyed for a shape kept. A kept pool lets go of its
video-processing context first, which as a live context would keep the
held teardowns from ever being made, and a stalled pool is neither kept
nor taken back. The release_teardown doc's measured claim that destroying
a pool's surfaces at once passed is corrected with these runs, and the
full-pace test runs their shape.
2026-11-20 23:49:26 -08:00
Anees Iqbal 4dde74e729 🐛 Keep a VA decoder's context for its shape, not its whole teardown
On Windows every teardown asked for while another VA context lived was
held until none did, which stopped Intel's Direct3D 12 video driver
faulting, and kept each short 4K decoder's memory (about 211 MB of DXGI's
local count) until the long decoder beside it ended.

Measured on the UHD Graphics 630 (job m3-max-61642): holding the
context's destroy alone passes the two-thread test, with the pool's
surfaces, or the surfaces and the config, destroyed at once. Held
contexts still grew DXGI's local count by 34,905,201 bytes each. So a
config's and a pool's surfaces' teardowns are now made at once, and a
decoder's context let go while another lives is kept with its config
and taken back by the next decoder of the same config, size, render
targets and DPB, instead of one made beside it. Kept contexts are
destroyed with the held teardowns once no context lives. Linux is
unchanged, and so is what the guest sees.

The churn test makes ten short decoders beside a long one, compares their
pictures with the long one's, and on Windows asserts DXGI's local count
grows by less than one held context over the last nine.
2026-11-20 23:49:26 -08:00
Anees Iqbal 5dcff9c2c5 🐛 Answer rate maps NO where the platform makes none
rt makes no rasterization rate map: its newRasterizationRateMapWithDescriptor:
refuses (Unbuilt::RateMap, rt-unbuilt-rate-map), yet the Vulkan platform
answered the M3's layer count, 2, and every host offered RATE_MAPS. A guest
asked supportsRasterizationRateMapWithLayerCount:1, heard yes, and its map's
create was refused at the host.

The Vulkan platform now answers max_rasterization_rate_layer_count 0, and so
the identity's largest_rasterization_rate_map_layer_count 0, and the device
offers RATE_MAPS only where that count is one or more (makes_rate_maps). What
the guest sees on rt: supportsRasterizationRateMapWithLayerCount: answers NO
for every count, the device info's largest rate map layer count is 0, and
newRasterizationRateMapWithDescriptor: returns nil in the bundle with no
message to the host. A platform that makes rate maps (the testkit's fake)
offers them as before. No GPU family's answer moves: Mac2 stands, and no
Apple family stood before or after.

The tests that held rt's answer of 2 now hold 0, and a new test pins the
feature bit to the platform's layer count.
2026-11-20 23:07:55 -08:00
Anees Iqbal b76d6ac4a9 📝 Record iHD's codes from linear encoder inputs as U32 [ci skip]
iHD codes a frame from a linear import other than as from a surface of its own, and
the encoder's imported inputs are laid out in its Y tiles for that: the row says what
was measured on the Iris and where our code lays them out.
2026-11-20 22:49:14 -08:00
Anees Iqbal 0b12ba407e 🐛 Lay out VA encoder inputs in the driver's own Y tiles on iHD
On an Intel GPU under iHD, a guest's encode session got other bytes from a
frame the rt GPU wrote into the encoder's input than from the same frame
uploaded. The input was imported linear, and iHD codes a linear import
differently from a surface of its own:
- H.264's P pictures differed at 640x360 and smaller;
- every HEVC Main 10 picture differed, intra ones too, at about ten times
  the bits.
iHD's own inputs are Y-tiled (I915_FORMAT_MOD_Y_TILED). Their pitch is the
coded row's bytes rounded up to 128, and their chroma plane sits at the pitch
times the coded height rounded up to 32 rows. An import declared and written
in that layout coded as the upload did, byte for byte, in every profile at
five sizes up to 1080p. The one exception is where iHD differs from one
upload to the next anyway (HEVC Main at 640x360 and 1080p). Measured on an
Iris Xe, iHD 26.3.5.

What changed for the guest: on iHD, the GPU-filled path's samples are the
ones the upload path would give. Nothing changes on radeonsi: its own inputs
are in AMD's 64 KiB swizzle, so its inputs stay linear at rows of 256, which
it codes as the upload.

The changes:
- `VideoEncoder::input_layout` makes one surface as the encoder's pool does
  and exports it. Where that surface is in Y tiles in this layout, the input
  takes its pitch, chroma offset and size. Otherwise the input is linear, as
  before.
- `import_input` takes the tiling, and `Target::import_as` declares Y tiles
  in the DRM PRIME descriptor.
- The fill asks the layout once per shape, sizes the input from it, and
  passes the kernel its tiling word.
- `TargetTiling::byte_at` is the Y-tile address the tests write and check
  by.

Tests:
- The VA crate's import test now writes its input in the encoder's own
  layout, so on iHD it writes Y tiles.
- The rt kernel test fills every case into a linear input and a Y-tiled
  one, and compares the whole input byte for byte.
- New unit tests cover the Y-tiled layouts iHD gave, the misfits that are
  refused, the tile address, the linear layout and the fill's declines.
2026-11-20 22:48:58 -08:00
Anees Iqbal 13fb154934 🆕 Write encode sessions' frames into VA inputs on the rt GPU
On Linux the rt platform's VA-API arm made no GPU filler, so an encode
session's frames could only be uploaded by the CPU, and the arm answered no
encoder (f716a52d2a: "rt releases no encoder's sources to the driver yet").

The arm's GPU copies on rt (`fill::DeviceFills`) now give each encode session
a filler. Its input is a dma-buf block of the device's, made when no input of
the shape is free and imported on the encoder's display; a frame's two planes
are read where they lie, in the surface's pages or its device caches, and
written into it by videoEncodeFill, margin included, so the encoder codes the
bytes the upload would have given it. A blit hands the block to the driver
(`release_to_external`) behind the kernel, and the frame is coded once the
GPU's write is waited for; no B pictures are coded, so the driver has read the
input before the next frame's write. An input the driver still holds is not
written; a plane in its cache's surface, or one the input cannot hold, is
declined and that frame uploaded, said once a session. A write that fails on
the GPU keeps its filler and input for the session's life, and the session's
later frames are uploaded. Decodes are unchanged: the copies make no copier,
for the same reason as before.

The session's end logs how many frames went each way. The arm still answers no
encoder here; the next commit turns them on.

New tests: the input's planes and the kernel's arguments on the testkit; the
kernel on the rt device writes frames of NV12 and P010, with and without
margins, at odd offsets and pitches, as the upload writes them, and nothing
past the coded rows; on the VA-API host, frames written by the GPU code byte
for byte as the uploaded ones, an x86 guest's session's and an arm64 guest's
paravirtual encoder's.
2026-11-20 22:48:57 -08:00
Anees Iqbal 3d3cd79924 🆕 Code a frame another device wrote into an imported VA input
The VA crate's encoder read its frames only from host bytes, which it uploaded
into a surface of its own pool. The rt platform can make the encoder's input
itself: a dma-buf block the encoder's display imports, which the device's GPU
writes the frame into where its planes lie, with no upload and no staging
copy.

`VideoEncoder::input_shape` names the input such an import must be: NV12 or
P010 at the encoder's coded size. `import_input` (Unix) imports a dma-buf as a
linear surface of that shape through DRM PRIME, as a decode's targets are
imported, keeping the caller's memory while it lives. `encode_target` codes
the frame written there, margin included, and reads none of the frame's
planes; an import of another shape is refused. A stalled frame's import is
kept with its session, as the driver may read it still.

Two ignored tests on the VA-API host: frames written into an import code byte
for byte as the same frames uploaded, for each profile the driver encodes, and
an import of another shape is refused.
2026-11-20 22:48:57 -08:00
Anees Iqbal d8f2d0ccbd ✅ Name vaon12's per-session leak where its tests wait
The two vaon12 tests of the adapter's device after a display's let-go fail
on Mesa 26.2.7's vaon12 over the UHD 630: the driver leaves one Direct3D 12
object of every decode session past vaTerminate, whatever our surfaces, and
nothing in our order of calls reaches it. Their ignore reasons and docs now
say so, and docs/video/bugs.md's new U31 records the measurements, so a run
of the ignored tests on the Windows host reads as the driver's and passes
once a driver frees what it made.
2026-11-20 21:40:06 -08:00
Anees Iqbal 8628a2fdd9 📝 Name the new rt refusals in the accuracy ledger [ci skip]
The pin's range refuses a render pipeline state that fetches or blends an
extended-range colour attachment on every device (Translation-Format), and makes
a fragment function whose SIMD-group operations read other lanes where the
device reports shaderQuadControl, refusing it elsewhere
(Translation-SubgroupOperations). The ledger's list of the translator's
refusals names both. It named no argument buffer sampling refusal, which the
range translates, so no row goes.
2026-11-20 19:49:14 -08:00
Anees Iqbal 415d453172 🆕 Name the guest's work in each command buffer lost in flight
The 3090's fault at job 60124 left no named cause: at a loss, the rt
platform wrote one line naming the GPU, the Vulkan call and its result,
and nothing of the work that was on the GPU.

Each command buffer rt ends as in flight at its device's loss now writes a
line after the device's, naming the guest's command buffer by its object
id and the object ids of the first compute and the first render pipeline
state its encoders set, or none; a command buffer of the host's own says
so. A command buffer cut in parts writes one line however many of its parts
are lost. The first 8 write theirs, the next one that the rest are counted
only, and each is counted, rt-device-lost-in-flight.

The record is the cheapest that holds them. The decoder makes the guest's
names for a command buffer's work once, at its begin, and hands them to the
platform before any encoder (CommandBuffer::names_work, a no-op by default
that makes no Metal call), which keeps them on the command buffer and each
part cut from it. A walk keeps its first pipeline state of each kind in a
cell, read at each set, and notes them in the names with relaxed stores
before each commit of what it walked: a cut, a dealt chunk's commit, which
notes its chunks' firsts in their order, and the last commit. Nothing per
draw, and nothing reaches the guest: the line is a diagnostic.
2026-11-20 17:57:10 -08:00
Anees Iqbal 3b001461c7 🐛 Land an HEVC picture NVDEC failed as NVDEC left it
What changes for the guest: an HEVC picture NVDEC answers failed once it ran
(its slice data damaged past what the parsers read) lands as NVDEC left it, its
command buffer completing as any, and the pictures after it decode from it, as
an H.264 picture NVDEC failed has. Before, its landing failed its command
buffer, which AppleGVA's HEVC path answers with kVTVideoDecoderMalfunctionErr
for that picture and every later one of the session.

Why: a Mac's hardware HEVC decoder hands such a picture on, as its H.264 one
does (measured with VideoToolbox on a MacBook Pro of 2019, macOS 26.7.1, on
the UHD 630: an HEVC P picture at 1080p whose last slice segment was cut to
half, and each picture after it until the IDR picture, came back with status
0 and an image). AnnexBDecoder::copy_failed_pictures now asks this for both
codecs, and its NVIDIA test cuts an HEVC P picture as it cut an H.264 one.
2026-11-20 17:13:30 -08:00
Anees Iqbal 0f7bccf103 🐛 Answer a picture that does not decode with no picture, not a fault
What changes for the guest: a host session's decode whose picture is one of
the stream's that does not decode no longer faults its command buffer. Such a
picture is one whose bytes do not read as H.264 or HEVC reads them, one that
predicts from a picture the decoder does not hold (a session or a seek that
starts at a P picture), or one after a picture that did not decode, before the
next I or IRAP picture. It now lands nothing: its command buffer completes as
any, its output keeps its bytes, and the session decodes again from the next I
or IRAP picture. This holds on VA-API and NVDEC, for H.264 and HEVC, and on
VA-API also covers a RASL picture the stream's random access skips, which
faulted there while NVDEC already landed nothing for it. A stream the decoder
does not take, an avcC or hvcC record's error, and the hardware's or the host
API's errors still fault.

Why: a Mac's hardware decoders answer each such picture alone and decode on
(measured with VideoToolbox on a MacBook Pro of 2019, macOS 26.7.1: H.264 with
no error, HEVC with kVTVideoDecoderBadDataErr or ReferenceMissingErr and no
image). Before, a guest boot on a Radeon 780M counted 85 decode faults
("a reference frame is missing", "PPS 4 has not been received", "no I picture
has decoded since a picture that did not decode") for H.264 streams started at
a P picture or with a damaged header, and an HEVC picture that faulted would
end AppleGVA's session with kVTVideoDecoderMalfunctionErr from that picture
on. The codec errors say which are one picture's (is_picture_error), and NVDEC's
error keeps them apart (Error::Picture), still reported as bad data.
2026-11-20 17:13:30 -08:00
Anees Iqbal b955213d27 📝 Keep the guest's RAM mapped until the process exits [ci skip]
The device's imports of the guest's pages into the host GPU can outlive its
release: rt frees them on a thread of its own once no GPU work uses them, and
the release of the last device keeps the GPU device for the process when its
wait runs out. So the memory map's host memory stays mapped, and is not
unmapped, mapped anew or discarded, until the process exits (the header's
RvgMemoryRange and memory_map, docs/api.md, and reims-vgpu's MemoryMap).

QEMU's side does not change: the machine holds its RAM backend until QEMU
exits (hw/core/machine.c:1216), and the VMs reims-ctl makes discard no guest
RAM: no balloon, free page reporting, virtio-mem or memory hot-unplug, and
their RAM is a shared mapping, which KSM does not merge.
2026-11-20 16:33:34 -08:00
Anees Iqbal 7a98159ca2 🐛 Owe a refill from each read-write lock, whatever filled the cache
A cached surface's device cache could hold the pages as they were mid-write
with no refill ever asked: the bundle recorded the surface's unlock seed only
as a commit first named a generation, so a fill the bundle never saw (a
present's, the first fill a block owes, a block named again) made while the
CPU held its read-write lock stood until the next lock. Such a present also
left the record to be made after the unlock, which then never asked.

The kext now writes each generation's refill record into the block's header
itself, as it caches the block and at each read-write lock, before the
generation, with the surface's unlock seed then (RgfxSurfaceRefill.hpp,
which the bundle shares). The first commit, in any process, once the unlock
seed has moved past the record's carries RGFX_SURFACE_USE_REFILL and settles
it; a commit while the lock is held or being taken asks nothing and leaves it
owed. For the host: a use after each read-write lock's unlock now carries the
flag, including the first use of that generation; the host ignores it where
the cache holds an older generation, as before, so a generation never filled
mid-write costs no extra fill. The record is one 64-bit word written by
compare-and-swap, so a holder never writes over a newer generation's record.
2026-11-20 16:26:09 -08:00
Anees Iqbal 83c4898877 🆕 Name a sole holder's anonymous memory unchanging
The bundle now names read-only anonymous memory unchanging where its maximum
protection has no write, the kernel answers it SM_PRIVATE at a shadow depth of
0, and mach_vm_page_info's VM_PAGE_INFO_BASIC answers its object's count as 1
at depth 0 with the region's object id (kRgfxAnonymousPrivate). The kext takes
such a block (kRgfxPagesSoleHolder, 1 << 3, where it sets
kRgfxKextFeatureSoleHolderPages, 1 << 20) and marks its SURFACE_PAGES
RGFX_SURFACE_PAGES_UNCHANGING without COPY_ON_WRITE, so the host reads its
pages once, as the view is imported. On P2's guest (macOS 26.7.2, the Windows
mini) the 4K block over such memory was copied whole at each commit that used
it.

A wire holds no reference, so the count leaves out wires for writing taken
while the memory was writable. The kext knows its own: it refuses the block
(kIOReturnNotPermitted) where, once its pages are wired, a writable block of
its own in the table or an in-place surface block covers a page of them, or a
block of writable memory is being made (writableMakes), and the bundle then
asks a read-only block, why RGFX_PAGES_WHY_REFUSED. The check sorts the
block's runs and walks every writable wire's segments under contextLock, once
per such make. What is left is a write another driver started before the app
removed write for good, still landing after the make.

The clause is on for every guest kernel, with no release gate. The facts it
rests on, read in xnu's published source at each tag from macOS 11.0.1 to
26.5, osfmk/vm/ lines:
xnu-               cnt   pid   rid  fake  prot   upl clamp  iopl  walk     id
7195.50.7.100.1  19154 19264 14459 19126  6172  6459 17037  9030 14915   1209
7195.60.75       19074 19184 14406 19046  6156  6459 16984  9030 14862   1209
7195.81.3        19074 19184 14413 19046  6157  6459 16984  9030 14869   1209
7195.101.1       19119 19229 14290 19091  5915  6457 17020  9010 14749   1190
7195.121.3       19158 19268 14329 19130  5916  6457 17059  9010 14788   1190
7195.141.2       19158 19268 14329 19130  5916  6517 17059  9070 14788   1190
8019.41.5        19330 19440 14493 19302  6007  6551 17227  9137 14952   1190
8019.61.5        19330 19440 14493 19302  6007  6551 17227  9137 14952   1190
8019.80.24       19330 19440 14493 19302  6007  6551 17227  9137 14952   1190
8020.101.4       19330 19440 14501 19302  6003  6543 17247  9143 14960   1188
8020.121.3       18885 18995 14245 18857  5918  6541 16960  9131 14704   1168
8020.140.41      18945 19055 14305 18917  5909  6542 17019  9135 14771   1168
8792.41.9        19527 19637 14780 19499  5939  6701 17519  9294 15246   1166
8792.61.2        19538 19648 14791 19510  5939  6753 17530  9346 15257   1167
8792.81.2        19538 19648 14791 19510  5939  6753 17530  9346 15257   1167
8796.101.5       19669 19779 14872 19641  5926  6750 17650  9273 15338   1164
8796.121.2       19669 19779 14872 19641  5926  6750 17650  9273 15338   1164
8796.141.3       19738 19848 14911 19710  5940  6774 17695  9297 15377   1164
10002.1.13       19897 20007 15074 19869  6032  6791 17854  9316 15540   1163
10002.41.9       19910 20020 15087 19882  6032  6771 17867  9296 15553   1165
10002.61.3       19910 20020 15087 19882  6032  6771 17867  9296 15553   1167
10002.81.5       20023 20133 15121 19995  6041  6771 17980  9296 15587   1167
10063.101.15     20254 20364 15180 20226  6098  6774 18210  9299 15646   1355
10063.121.3      20357 20467 15247 20329  6123  6774 18308  9299 15714   1355
10063.141.1      20359 20469 15249 20331  6125  6774 18310  9299 15716   1355
11215.1.10       20139 20249 14984 20111  5692  6843 18096  8188 15442   771i
11215.41.3       20139 20249 14984 20111  5692  6843 18096  8188 15442   771i
11215.61.5       20501 20611 15230 20472  5759  6817 18384  8162 15693   765i
11215.81.4       20507 20617 15236 20478  5765  6817 18390  8162 15699   765i
11417.101.15     20646 20756 15393 20617  5804  6766 18487  8111 15856   765i
11417.121.6      20694 20804 15441 20665  5843  6781 18535  8129 15904   766i
11417.140.69     20703 20813 15449 20674  5841  6777 18546  8124 15913   766i
12377.1.9        20960 21070 15518 20931  5974  6988 18734  8331 16004   776i
12377.41.6       22004 22114 16433 21975  6174  7198 19709  8562 16933   807i
12377.61.12      22037 22147 16463 22008  6204  7203 19742  8567 16963   808i
12377.81.4       22109 22219 16534 22080  6275  7209 19813  8573 17034   808i
12377.101.15     18688 18805 13571 18677  5743  7659 16128  8765 14068   824i
12377.121.6      18686 18803 13569 18675  5722  7659 16126  8765 14066   824i
 cnt   vm_map.c, vm_map_page_range_info_internal: the top object's count,
       less the query's own reference to 12377.81.4, read before it after
 pid   there: the id, VM_KERNEL_ADDRPERM to 10063.101.15, ADDRHASH after
 rid   vm_map.c, vm_map_region_recurse_64: the region's id, VM_OBJECT_ID
 id    vm_object.h (i: vm_object_internal.h): VM_OBJECT_ID, the low 32 bits
       of pid's macro in each tag
 fake  vm_map_page_range_info_internal: a footprint query's count of 1 and
       an id of no object (task_self_region_footprint)
 prot  vm_map.c, vm_map_protect (its preflight from 12377.101.15): no
       protection the maximum lacks
 upl   vm_pageout.c, vm_map_create_upl: no write UPL where the entry's
       protection lacks write; from 12377.1.9 through vme_allows_upl_write,
       whose test is at 6786, 6986, 6991, 6997, 7413 and 7413
 clamp vm_map.c, vm_map_remap_extract: a share's maximum is the source's at
       most, which memory entries take through vm_map_copy_extract
 iopl  vm_pageout.c, vm_object_iopl_request: the UPL keeps the object with
       no reference of its own
 walk  vm_map.c, vm_map_region_walk: the count less one while paging, so
       the share mode alone leaves it in doubt

Later releases are checked by test: guest/bundle/tools/sole_holder_probe.c,
which the lane gate's info phase (item sole-holder) and Ambrosia's
check-boot.sh (check sole-holder) run on each guest they boot, reads the count
as 2 with a memory entry or a second mapping holding the memory and 1 once it
goes, sees a footprint query answered otherwise, the kext's writable wire of
memory whose maximum lacks write refused, a sole holder's block made, and
refused while a writable block of the kext's covers it. A release where it
fails is a red leg. The kext's tests cover the wiring and the runs' sort and
search, and the bundle's a sole holder's block named and refused.
2026-11-20 14:02:42 -08:00
Anees Iqbal f76390e268 📝 Say what the rt platform does with read-only store-outs [ci skip]
design.md's no-copy buffers section and dgpu-oracle.md Q38 said a render
pass that stores or resolves into read-only memory fails its command buffer
with a page fault, as the M3 Max's does, and Q38 described the earlier
platform's Linux runtime and MoltenVK on macOS. On the rt platform, on every
host, the pass completes, its stores and resolves dropped with the copy's
other writes, as the 5300M and the UHD 630 complete one over read-only pages,
and is counted at the pass, rt-copied-store-outs, where the M3 Max faults it;
accuracy-ledger.md's read-only-pages-written row says so already.

Q39 described protection options the platform no longer keeps: rt builds
none (rt-unbuilt-protection), and a command buffer with them runs as one
without, which no Mac answers for encoders made under options 2 or 0x10. Its
type-9 draw is refused and counted, not a death.
2026-11-20 13:09:01 -08:00
Anees Iqbal 7ca9d53fa4 🐛 Skip a picture's cache copy the platform makes no blit encoder for
What the guest observes changes. Before, where the host's video landing found
no blit encoder for its copy of a picture's staged planes into the output's
device caches (on the rt platform, an encoder metal2vulkan-runtime refuses),
the landing failed: the decode's value was signalled, and the command buffer
that waits for it completed failed, with Metal's internal error, which the
guest's video driver answers as a decode error (HEVC:
kVTVideoDecoderMalfunctionErr).

Now the copy is skipped, as the decoder skips whole a pass the platform makes
no encoder of (4b7975b882, decode::cmdbuf's unmade): the caches keep their
bytes, the picture lands with them, its value is signalled and its command
buffer completes as any landed picture's, not counted as a failure to land. rt
counts the refusal under rt-refused-<kind>, as before; the process's first
skip has a line. No new degradation code.

An encode's copy of its source out of the caches keeps its answer: no blit
encoder fails the frame (RGFX_VIDEO_ENCODE_FAILED), since a skipped copy would
hand the encoder the staging buffer's earlier bytes, another frame's or what
the buffer held when it was made.

No test held the old failure. The new tests:
a_copy_into_caches_the_platform_makes_no_blit_encoder_for_is_skipped (no copy,
signalled, completes as landed, the next picture copied as any) and
a_source_whose_copy_out_has_no_blit_encoder_fails_its_frame, which pins the
encode's answer.
2026-11-20 13:09:01 -08:00
Anees Iqbal 62b3227c74 📝 Record that NVIDIA's driver keeps no disk cache without ~/.cache [ci skip]
NVIDIA's driver (620.70.06) keeps its own disk cache, nvidia/GLCache in the
user's cache directory, only for a Vulkan instance made while that directory
exists, and never makes it. A walk's cold boot started QEMU with a HOME made
wholly empty: Mesa's drivers and the runtime made .cache only after the
instance, so the boot left no NVIDIA cache and the next one started without
it. A user's HOME has .cache (scripts/install-ctl.sh makes ~/.cache/reims-ctl),
so a boot standing for a user's first one keeps an empty .cache in its HOME.
Measured on an RTX 2080 and an RTX 3090 with a probe of our own.
2026-11-20 12:31:26 -08:00
Anees Iqbal d03fa634dc 🐛 Name anonymous memory unchanging only with a copy pending
Anonymous memory read SM_PRIVATE is not provably unchanging: the region walk
takes one from the object's reference count while paging on it is in
progress (osfmk/vm/vm_map.c:16002-16005), and a wire holds no reference
(vm_object_iopl_request, osfmk/vm/vm_pageout.c:8331; upl_destroy, 5683-5685),
so a driver's wire for writing taken while the memory was writable, our own
kext's for a writable block among them, still writes its pages after the
maximum protection lost write, under a count of one. A once-made copy would
then be wrong for the block's life. Such memory is read-only again, why not a
file, and its blocks are copied whole at each commit as before.

What stays unchanging is SM_COW at shadow depth 0, with no write in the
maximum protection, which is sound against wires too (xnu main as read on
2026-11-20):
- such a pending copy is vm_object_copy_quickly's of an object whose copy
  strategy is still symmetric (osfmk/vm/vm_object.c:3586-3605), and a wire
  makes its object's strategy a delayed copy (vm_pageout.c:8404-8423), so the
  object was not wired before the copy;
- a wire through either side after it resolves that side's pending copy
  first, shadowing it (vm_map_create_upl, vm_pageout.c:7140-7188), as a write
  fault does (vm_map_lookup_and_lock_object, vm_map.c:14866-14897) and a share
  does (vm_map_remap_extract, vm_map.c:18314-18396), so the other side's writes
  and wires land in a copy of its own.

What the host sees: blocks of anonymous memory SM_PRIVATE no longer carry
RGFX_SURFACE_PAGES_UNCHANGING; those with a copy pending carry it with
RGFX_SURFACE_PAGES_COPY_ON_WRITE. The bundle's classification line drops the
private clause. The tests hold both.
2026-11-20 12:31:26 -08:00
Anees Iqbal cc05db2728 ✨ Name read-only anonymous memory of a process's own unchanging
A no-copy buffer over anonymous memory the process mapped read-only, with
no write in its maximum protection, was a read-only block not unchanging
(why 1, not a file): the host copied its pages whole into its copy at every
commit that used it. On the Windows host's 4K desktop that is a 4K block of
ImageIO's (share mode SM_PRIVATE, ref 1, shadow depth 0), 7.93 ms and
31,007 KiB a present.

The bundle now names two share modes of such memory unchanging, read from
xnu's main as of 2026-11-20 (osfmk/vm/vm_map.c's vm_map_region_walk,
16088-16098; the modes' values osfmk/mach/vm_region.h:129-130):
- SM_PRIVATE, the object held by the region alone; a share of it takes no
  protection past its maximum (vm_map.c:18037-18058, 18733-18734), and
  VM_PROT_COPY maps a copy in its place (vm_map.c:5832-5905);
- SM_COW at shadow depth 0, a copy pending on the region's own object
  (vm_object.c:3586-3605; vm_map.c:12727, 14046, 18604), where the other
  side's writes go to a copy of its own (vm_map.c:14866-14897,
  18314-18396), marked copy-on-write.
A depth of 1 or more, and every other mode, stays neither, why not a file.
SM_PRIVATE's one doubt is documented: the walk takes one from the object's
reference count while it pages (vm_map.c:16002-16005).

What the host sees: such blocks now carry RGFX_SURFACE_PAGES_UNCHANGING
(and _COPY_ON_WRITE for the pending copy), so the host reads their pages
once, as the view is made, instead of at every commit; the GPU's writes
there are dropped as before. The bundle's classification line counts the
two new clauses. The wire, kext and host docs say so.
2026-11-20 12:31:26 -08:00
Anees Iqbal 868dd01c16 📝 Record that kache drops a Windows cdylib's import library [ci skip]
The b357 merge's Windows leg failed the C harness's link: the build hit a
kache entry for reims-vgpu-c's cdylib that holds the DLL but not
libreims_vgpu_c.dll.a, which a test-only change leaves unrelinked. The
merge harness now relinks the crate past kache where the archive lacks it.
2026-11-20 11:52:58 -08:00
Anees Iqbal c8780ddf56 📝 Say which platform picks the blocks' addresses the host gives
The docs of POOL_ADDRESSES, PRIVATE_BLOCKS, IMPORT_ADDRESSES and
MANAGED_AT_COPY, in wire.rs and the header cbindgen makes of it, and their
sections in design.md, said what "the Vulkan platform before" the runtime did.
That platform is gone. The host picks those addresses now only on a platform
whose blocks have none, the testkit's (pool::addresses, HostBlocks), and that
platform is not offered MANAGED_AT_COPY: the docs say so. IMPORT_ADDRESSES also
said a read-only block's copy drops the GPU's writes as each command buffer
completes; a copy of changing pages is written whole at each commit that uses
it instead, so the doc cites the ledger's read-only-pages-written entry.
2026-11-20 11:47:58 -08:00
Anees Iqbal bd25f9d9f8 📝 Add the read-only-pages-written entry to the accuracy ledger [ci skip]
surface_pages.rs, design.md, dgpu-oracle.md and the bundle cite the entry
`read-only-pages-written`, which the ledger lost when the old platform's rows
went. It now says what the rt platform does with memory whose GPU writes Metal
drops: a copy of its pages, the pages never written; a GPU write stays visible
until the next commit that uses a copy of changing pages, or the next
completion of a command buffer that can write a copy of unchanging pages, where
Metal drops it at the write; a render pass over such a copy completes with its
stores dropped, where the M3 Max faults it (rt-copied-store-outs); and a pinned
bit-24 buffer in a block that is no such copy is written (rt-no-copy-read-only).
2026-11-20 11:47:58 -08:00
Anees Iqbal 3097832d50 🆕 Name the feature the translator refused in rt's refusal lines
rt's translator refusals (rt::Error::Translation) were counted only under
rt-refused-translation, with one first line for all of them, which printed the
translator's error as it displays and debugs: no feature apart from another,
and its location and symbol, names of the guest's functions.

Now the boot diagnostics' refusals line counts each by the feature it refused,
Translation-<feature> (metal2vulkan's Feature's variant, as
Translation-DivergentInterpolation), or by the translator's error's variant
where it refused none (Translation-Cancelled). The first of each name writes
its line in the refusal-detail form, with the feature, what it needs and the
attachment it is tied to, and no function's or symbol's name. The degradation
count stays one code, rt-refused-translation: no new degradation kind.
Diagnostics only; nothing the guest observes changes.
2026-11-20 11:47:58 -08:00
Anees Iqbal 4b7975b882 🐛 Skip whole a pass the platform makes no encoder of
What the guest observes changes. Before, at ENCODER_BEGIN_RENDER, _COMPUTE or
_BLIT, an encoder the platform answered none for (on the Vulkan platform, a
pass metal2vulkan-runtime refuses, as a 4x BGRA8Unorm_sRGB resolve it builds
none of, seen twice in a Mac walk) raised an op fault: the command buffer's
message failed, its CB_COMPLETE carried an internal error, and none of the
buffer ran.

Now the pass is skipped whole, as a pass that names an object whose create the
host refused already is (OpenEncoder::Skipped): its ops are dropped up to its
end, the encoders after it run, and the command buffer completes RGFX_CB_OK. A
Metal app's sends to a nil encoder do nothing and fail no command buffer. rt
counts the refusal under rt-refused-<kind>, as before; the decoder logs the
process's first skip of each encoder kind once. No new degradation code.

No test held the old fault. The new test,
a_pass_the_platform_makes_no_encoder_of_is_skipped_whole, sends a render pass
the platform refuses as a gap and compute and blit passes it answers nil for,
twice each in one buffer, and checks that no op of theirs reaches an encoder,
the encoders after them run, and the buffer completes OK.
2026-11-20 11:47:58 -08:00
Anees Iqbal 04544a4e78 🐛 Hold a test's rt platform to its end's let-go, not weakly
A test's end kept a weak hold of each rt platform the test used and let go
of the device of each one it could still upgrade. An Arc's last drop takes
the strong count to zero before the value's drop runs, so a platform whose
last hold was another thread's (a decoder's event-wait watch, a VA call
thread) failed the upgrade while its drop, and its let-go of the device,
still ran on that thread beside the process's exit. On an RTX 3090 a
cmdbuf test printed ok and died of SIGSEGV, the event-waits thread inside
vkDestroyDevice while the main thread ran libEGL_nvidia's exit handler
(measured from its core, 1 of 2440 tests under the suite's load); the 780M
saw the same test die after ok.

The end now holds each platform strongly to the let-go, which waits for
the device's other handles, tears the device and its instance down on the
end's thread, and leaves the platform no device for a later drop to tear
down. drop_last, the VA tests' wait for the platform's other holds, is no
longer needed and goes. A new test leaves a platform's last hold to a
thread nothing joins and checks from an exit handler that the device was
torn down before the exit; the weak end fails it.

Nothing the guest or the host sees changes: this is test code.
2026-11-20 11:35:51 -08:00
Anees Iqbal c50dfba740 🐛 Answer argument buffers' layouts on the rt platform
On rt, newArgumentEncoderWithArguments: and a function's
newArgumentEncoderWithBufferIndex: were an unbuilt piece
(rt-unbuilt-argument-layout). The host answered ARGUMENT_LAYOUT as refused,
the guest's encoder was nil, and a kernel then read through an argument
buffer whose words nobody wrote. On a guest's probe the RX 550 read zeros,
and the 780M faulted on the null pointers and timed out its gfx ring.

What changes for the guest: both calls now answer metal2vulkan's layout.
That is ArgumentBufferLayout::from_descriptors for descriptors, and
Function::argument_buffer_layout for a function's argument buffer, the
layout the function's translation reads. Every argument kind maps to the
core kind of the same name, nested layouts with their holders. Where Metal
makes no encoder, the call still answers nil, now counted under
rt-refused-metal; the translator's own failures are counted under
rt-refused-translation.

The unbuilt piece and its ledger row go. The tests read
tests/shaders/argument_buffers.metallib. sum_args answers 16 bytes,
aligned to 8, pointers at 0 and 8, from the function and from descriptors.
mixed_args lays out a pointer array, a constant, a texture and a nested
argument buffer. On the Vulkan platform, both kernels read back the words
written at those offsets.
2026-11-20 11:16:05 -08:00
Anees Iqbal a0441f2af0 📝 Record a first boot's pipeline makes against a second's [ci skip]
Walk A on the 2080 at metal2vulkan 9ea53f7acd booted the same guest twice,
with rt's cache directory empty and then kept. The planner closed the
two-step make and the early create reply on these numbers: a second boot's
makes in the benchmark's first load cut sum 442 ms against 4124 ms, so cold
makes are a first boot's cost. docs/qemu.md keeps VM measurements.
2026-11-20 11:13:03 -08:00