Commit Graph
4465 Commits
Author SHA1 Message Date
Anees Iqbal 2724757bbf A host step waits for the batches that wrote what it reads, not every queue's work
A batch whose host step records indirect commands the GPU may write waited, once otherwise
ready, until every VkQueue completed what was submitted to it by then. A frame of a GPU-culling
renderer (a kernel encodes the draws and their execution range, then several render passes
execute them through the range) paid one GPU round trip per pass: each pass's step waited for
the passes before it in its command buffer, and for other queues' unrelated work, though it
reads only the records and the range the culling wrote. The range read made it worse: it was
read from a copy recorded right before the execution, in the batch of the previous pass.

Now the gate is taken from the hazard state where it can be (scheduler gate_of):

- CommandBufferShared::step_reads names what a batch's host step reads on the host of what the
  GPU may write, where each segment whose step waits for the GPU is an execution (outside a block
  of command predication) or a render pass of executions whose uses commit bounded: their
  records and ranges (Deferred::host_reads, ExecutionRange::host_reads), with their host
  aliases. Anything else (an indirect dispatch, a loop's check, a staged gather, an indirect
  sparse update) answers None.
- Tracker::last_writes answers, per VkQueue, the value of the last batch that wrote those bytes
  of the writes the state holds; None for an untracked resource. The state forgets only what
  completed, and a write that let an older entry go waited for it, so once each queue reached its
  value every GPU write to those bytes completed and reached the host (every batch ends with the
  barrier to the host). Every such writer is submitted by the time the gate is taken: earlier
  batches of the line went first, an earlier commit's conflicting batch on another line holds the
  head behind it (its footprint holds the step's reads), a later one waits behind it.
- Where either answers None the gate is every queue's last submission, as before.
- The range of executeCommandsInBuffer:indirectBuffer: is read in place where the host maps the
  bytes the GPU writes (Buffer::maps_gpu_bytes: not Private, not a Managed host copy on a
  discrete device, not a copied host buffer), through Buffer::read_mapped, which holds a no-copy
  buffer's pages while it reads 8 bytes so a detach and rebind meanwhile free none of them; a
  detached buffer runs nothing. The read is noted at the call as a command that reads the bytes
  (no GPU work), so the encoder's order, a detach and the hazard state see it as they saw the
  copy's. Other buffers keep the copy.
- WorkCounts::host_step_gates_narrowed counts gates that left out work submitted before them;
  the conformance cost tables report it and never gate it (QUEUE_DEPTH: whether a gate falls
  below a queue's last submission depends on whether the host had seen the writer complete).
- The HostReplayedIndirectCommands notice's cost, its catalogue entry in docs/API.md, the
  scheduler's and indirect_execute's module docs and the execution calls' docs say so.

Tests: tracker a_host_read_waits_for_the_last_writes_of_its_bytes_alone (the writer per queue, no
writer, a covering write on another queue, untracked, a queue past the count, retired). Lane
depth_executions a_frame_s_executions_wait_for_the_culling_alone: a culling command buffer on one
queue, a fill on another queue submitted before the frame, then a frame of two passes that
execute the commands through the range: two host steps, both gates narrowed, both targets hold
each kept chunk's depth. The existing depth_executions test now shares its workload.

No Metal-visible behaviour changes: what the steps read and record is the same; they start
earlier.
2026-11-12 04:53:27 -08:00
Anees Iqbal 5c3d492b4d hand_out_waits: the busy work fills the marker too, so its batch takes the marker's zeros
Since 781bd94935 a batch takes the fills of memory its commands may reach alone. The busy command
buffer filled only its target, so its batch no longer took the zeros of the marker made just
before it, and the test's first assertion ("the busy batch took the marker's zeros") failed on
the RTX 3090 run alone: m3-max-20563 at 7f3412bf64, m3-max-20540 at 0461db15d7. The busy work now
fills the marker first, so its batch reaches the marker and takes its zeros, as the test's premise
needs: a hand-out that waited for other queues' batches that did first work would wait for it.
2026-11-12 04:41:39 -08:00
Anees Iqbal efd15a61e1 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 04:30:54 -08:00
Anees Iqbal 0939eadbd9 Count what the spare command pools free and how often their pools are trimmed
What: WorkCounts gains spare_command_buffers_freed_past_recent_uses,
spare_command_buffers_freed_past_held, spare_command_buffers_shed and
spare_command_pool_trims, the free thread's command-pool work, which no count
showed: memory_frees_posted counts its blocks alone. The crate's tests had the
same three numbers (Spares::churn); production now counts them too.

Why: on an RX 7900 XTX (RADV) the device's free thread ran at 41% of a core
over a guest's 154 s benchmark run, 70% of its samples in libdrm's walk of its
free VA ranges (amdgpu_vamgr_free_va), which every buffer object's free takes:
a pooled or dedicated block's vkFreeMemory, and each command buffer's cs and
upload buffer objects that a vkTrimCommandPool returns. These counts, beside
memory_frees and memory_frees_posted, say which of the two it is.

Verified: tests::spares::device's burst test asserts the counts equal the
spares' own churn and that trims follow the frees (lavapipe run in the report);
api_signatures.tsv blessed (4 fields added).
2026-11-12 04:29:41 -08:00
Anees Iqbal 0691f04630 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 04:27:59 -08:00
Anees Iqbal d8f4f12741 RUNTIME_VERSION 2108: a texture over a Private buffer at a pitch the driver takes only explicitly lies in place
The commits before this one. A texture over a buffer whose GPU bytes only the runtime's ordered commands write, at a
row pitch other than the driver's own linear pitch, was a shadow: the kept arm refused route 2 (the explicit-pitch
image). It now lies in place there, its first move copying the bytes out to scratch and back around the layout change
(WorkCounts::first_moves_kept, first_move_bytes_kept), so the texels and the bytes between the rows read back as given.

Verified on the 3090 (m3-max-20505): reims's two shapes, BGRA8Unorm 1760 texels at 7168 bytes a row (the driver's own
7040) and 96 at 512 (own 384), in place, one keep each (114688 and 32768 bytes), a blit reading the texels and every
byte of the buffer, row padding included, back unchanged; RGBA8 101 at 416 and 448 stay shadows (Refused(Pitch), not
multiples of 128); kept_padding 4/4 and the validation lanes 71/71. lavapipe (m3-max-20429, same diff before the
rebase): route 2 takes both shapes, every byte unchanged; runtime 411/411, validation 322/322, api 43/43. Build and
gpucfg clippy (m3-max-20466). At development the same shapes were the standing shadow (no measured before).
2026-11-12 04:26:51 -08:00
Anees Iqbal c655c7379e Tests: a texture at a pitch the driver takes only explicitly is in place and kept
kept_padding: a BGRA8Unorm texture of 1760 texels at 7168 bytes a row (7040 its texels') and one
of 96 at 512 (384), over a Private buffer of named bytes, is in place on NVIDIA, not at its own
linear pitch, its first move kept once (WorkCounts::first_moves_kept) of at least the texels'
span; a blit reads its texels, and the buffer read back holds every byte it was given, the bytes
between the rows among them. The earlier tests now expect a keep exactly where a texture is in
place at a pitch other than the device's own, and no longer expect a shadow at every other pitch.
2026-11-12 04:26:42 -08:00
Anees Iqbal 605a99f639 A texture over a Private buffer at a pitch the driver takes only explicitly is in place: the GPU keeps its bytes
A Between::Kept texture (bytes only the runtime's ordered commands write; no render target) whose
pitch the device's linear image does not lay on its own now takes route 2, the DRM explicit-pitch
image (VK_EXT_image_drm_format_modifier, DRM_FORMAT_MOD_LINEAR), over the buffer's own memory,
where the driver's reported rowPitch equals the buffer's pitch at offset 0 and the image fits.
Checked per texture. Such an image starts UNDEFINED (VUID-VkImageCreateInfo-initialLayout-12478:
PREINITIALIZED only with TILING_LINEAR; 01443 for external memory), and 7.1.1 lets the move out of
UNDEFINED discard its range, so the first move keeps the bytes on the GPU: one span copied out to
a scratch buffer, the move UNDEFINED -> GENERAL, the span copied back, in one ordered sequence.
The submission taking a keep waits on every other queue's last submitted work, so the keep follows
every earlier access to the span; later work waits through the first move's owners. Afterwards the
image and the buffer alias as a linear resource (glossary, DRM_FORMAT_MOD_LINEAR; 12.11).

Counted: WorkCounts::first_moves_kept, first_move_bytes_kept.
2026-11-12 04:26:42 -08:00
Anees Iqbal ef3f12b572 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 04:26:20 -08:00
Anees Iqbal 569f03aa92 RUNTIME_VERSION 2107: an idle device frees its kept empty blocks and parked objects as they come due
The commits before this one. A kept empty block past its 10 s quiet period (KEPT_EMPTY_FOR) went only at a release in
its pool or at a creation call's sweep (keep_room -> sweep_stale), and parked images and buffers only at the next park
or take, so an idle device freed nothing: after a guest app quit (reims's as3-iris, Iris Xe), 11 empty pooled and 4
empty dedicated blocks sat 33 s with no counter moving, and 7 empty pooled blocks were kept for good ("one pooled block
per pool"). Now one idle-sweep thread per device (idle_sweep.rs), started at the first keep_room and joined at
teardown before the recyclers and memory go; it holds the memory, the recyclers, the functions and the counts, never
the device, and wakes when a kept block, a made-ahead block or a parked object comes due, at most once a second,
waiting with no timeout when nothing is due. Block frees still post to the free thread, which paces them. A pool's
last empty block stays only in the pools keep_room keeps room in (Memory::keeps_room), one 64 MiB block per such pool,
counted in WorkCounts::empty_memory_blocks_live; every other pool keeps none after 10 s (docs/FAST-PATHS.md row).

Verified on lavapipe (ms01): tests::idle_sweep, which makes objects across several blocks, drops them (one through a
refused commit, one through a failed one), idles and asserts what is left, FAILED before the fix (m3-max-20498: after
40 s idle, 32 images and 3 buffers parked, 8 pooled blocks live, 512 MiB in the heap) and passes after it
(m3-max-20535, 13.6 s), with 89 neighbouring memory, recycle, free and teardown tests (90/90); lint three ways and
rustdoc (m3-max-20536).
2026-11-12 04:25:02 -08:00
Anees Iqbal 89483d65cb An idle device lets go of its kept empty blocks and parked objects
What: a device keeps an emptied memory block for 10 s (KEPT_EMPTY_FOR) and a
released image or buffer parked for 1 s (recycle.rs), and only let either go
at a later call of the program: a release in the block's pool, a creation
call (sweep_stale, from keep_room), or a recycler's park or take. A device
whose program stopped making resources kept them until its next creation
call, however long that took. The consumer's Iris Xe rerun showed it: after a
guest application quit, 11 empty pooled blocks, 4 empty dedicated ones and
the parked objects sat 33 s with no counter moving; the first creation call
then freed 12 at once, and 7 empty blocks still stayed, the "one pooled block
per pool" kept for good.

How: one idle-sweep thread per device (idle_sweep.rs), started by the first
creation call that may wait (Device::keep_room). A block kept empty, a block
made ahead and an object parked each say when they may go (Due::by). The
thread waits for the earliest of those moments, sweeps (recyclers first, then
Memory::sweep_kept, the creation calls' sweep without its throttle), asks
what comes due next (Recycler::due, Memory::sweep_due) and waits again, with
no timeout when nothing is due. It sweeps at most once a second. It holds the
memory, the two recyclers (now Arc'd), the functions and the counts, never
the device. Its Vulkan calls run in an exit-guard section, and the teardown
stops and joins it before the parked objects and the memory go. Freed blocks
are posted to the free thread, which paces them as before.

The pool's last empty block now stays only in the pools the runtime keeps
room in for its own encodings' and commits' resources (Memory::keeps_room:
the kept list, not a small heap's). That block is the room the next creation
call's keep_room would make again. Every other pool keeps none past the 10 s.
So the lasting spare is bounded at one block per kept pool and counted in
WorkCounts::empty_memory_blocks_live. docs/FAST-PATHS.md's row says so and no
longer claims "held until 10 s after the dip" for blocks that stayed for good.

Verified: tests::idle_sweep (lavapipe, ms01). Private buffers and textures
over several blocks are used by a command buffer that completes, one refused
at commit (abandoned encoder) and one its submission check fails, then all
are released and the device idles. Before this change (b11d8115f1, job
m3-max-20498) it failed after 40 s idle: 32 images and 3 buffers parked,
8 pooled blocks live against 1 at the start, 512 MiB in the heap against
64 MiB. The unit test a_pool_without_room_lets_its_last_kept_block_go covers
stale/stale_at with and without room. The after-run is in the report.
2026-11-12 04:24:52 -08:00
Anees Iqbal 704700fdfd A device test: an idle device lets go of what its released resources held
Private buffers and textures over several pooled blocks, used by a command
buffer that completes, one whose commit is refused (an abandoned encoder) and
one whose submission check fails it, all let go of; then the program makes and
releases nothing. Within 40 s nothing may stay parked, each pool keeps at most
one empty pooled block, and the pooled blocks and heap bytes are back to their
start within one block a pool.

Committed ahead of the fix, to run against it: at this tip the kept empty
blocks and the parked objects go only at the next creation call, release or
park, so the test is expected to fail here.
2026-11-12 04:24:52 -08:00
Anees Iqbal a71653bd46 Re-bless the golden tables at pin 51 (f447a92d63)
The engine inventory, golden hashes and air_input printouts, blessed on the M3 at development f447a92d63 (job
m3-max-20513: inventory, golden and printouts each exit 0). Two changes, both the landings' own:
- engine/kernel_read_through_constant.air.ll goes from InvalidInput{Abi(TypeSizeMismatch)} to a module,
  0f64f6745460f65a on every row, equal to its opaque .ll row's (SV 2043: a plain buffer takes its stated size).
- The new fixture icb_depth_indexed_encode (.air.ll and .ll): its three entries' rows and its air_input printout.
The merged check at the same sha passed (m3-max-20512: gpucfg clippy of five crates, api_signatures, api_surface,
fast_paths, rustdoc).
2026-11-12 04:19:16 -08:00
Anees Iqbal f447a92d63 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 04:11:33 -08:00
Anees Iqbal 6d9bc9f096 RuntimeGap::IndirectRenderCommands names the rule that refused it (IndirectRule)
One gap stood for a dozen rules: an execution of the other encoder kind's commands, a range a
draw of the encoder may write, a command's memoryless texture slot, a color in another format,
the shader-side depth test, a shadowed texture the call did not gather, residency past the call
meeting a shadow's truth, an emulated mesh command's ordering, a memoryless attachment read past
the pass, and on an Apple10 device the render states the commands set themselves. A consumer's log
said "IndirectRenderCommands" for all of them, so a report could not say which one a program met
(a public GPU-culling sample's host step on an RX 550 did not).

The variant now carries IndirectRule (public, non-exhaustive, Copy), one value per site, and the
error's text prints it: "not implemented in the runtime yet: IndirectRenderCommands(UngatheredShadow)".
A family row of indirect render commands names FamilyRow, the summary of the others. No
behavior changes: every site refuses where it did, typed as before.

Tests that expected the gap now expect its rule: the other encoder kind (render_executions,
indirect_command_buffers), a range a draw wrote (render_executions), residency past the call
(buffer_texture_renders), mesh ordering (mesh_commands) and the Apple10 states (state_ids,
command_render_states, families). docs/REFUSALS.md and api_signatures.tsv regenerated.

A consumer that names RuntimeGap::IndirectRenderCommands names a rule now, or matches
IndirectRenderCommands(_).
2026-11-12 04:10:12 -08:00
Anees Iqbal 47f6e07847 Lane depth_executions: a later encoder's shadowed texture and a rate map beside the depth-only commands
The variants a culling sample's depth passes add: slice 1 of a 2D array (a shadow cascade), a
later encoder of the command buffer that makes a shadowed texture resident, and a pass over a
rasterization rate map of half quality, whose stored pixels the test does not judge yet. Each
run's status, refusal and depth are printed before the asserts, so one run names every variant
that refuses.
2026-11-12 04:10:12 -08:00
Anees Iqbal 7ae5eb55be Lane: a kernel's depth-only indexed commands drawn through the range it wrote
A GPU-driven depth prepass in its usual shape: the owned fixture icb_depth_indexed_encode's
dio_reset zeroes an execution range, and dio_encode keeps the chunks a mask names, each taking
the next command by an atomic increment of the range's length and encoding there its own vertex
buffers (the positions, and the address of its constant camera argument) and an indexed
triangle-list draw of its quad. A blit resets the commands first. The render encoder's state
(dio_vertex, a float3 attribute, no fragment function, Depth32Float) is inherited, with a
depth/stencil state and a depth bias set, and the commands run through
execute_commands_in_buffer_indirect over the range the kernel wrote. The test checks the stored
depth texel by texel, in a 2D target and in slice 1 of a 2D array (a shadow cascade's).

Why: a public GPU-culling sample's command buffers fail Refused with
NotImplemented(IndirectRenderCommands) at their host step on an RX 550, and the code alone does
not say which rule refuses them; this lane is the repro and the test of the fix.

Fixture compiled with scripts/regen-air-fixtures (metal 32023.922, SDK 27.2).
2026-11-12 04:10:12 -08:00
Anees Iqbal 79fc9eec07 stage_in_user_key.m: what the M3 Max answered for both forms 2026-11-12 04:10:11 -08:00
Anees Iqbal 9081edca8e Keep the plugin list a refusal; compare the typed fixture's module words
The empty !gld.plugin_info list is what this Mac's (macOS 27) OpenGL front end writes, and its
modules then stop at other module-level shapes (an `OpenGL GLSL` language version beside
Metal's, repeated versions, contradictory compile options); the guests' modules, from macOS
26, reached the entries. So the module-level shapes stay refusals, and only the two entry
shapes the guests met change. The engine test compares FunctionArtifact::module.words.
2026-11-12 04:10:11 -08:00
Anees Iqbal 797a440edd A kernel stage-in attribute named by its user key, on the lane and on Metal
The runtime lane's stage_in_strides takes the owned fixture kernel_stage_in with each
stage-in attribute's location followed by its name (`attrib_N`), as Apple's OpenGL front end
writes a kernel's stage-in node, and requires the fixed-stride words its unnamed form
answers. The probe stage_in_user_key.m makes both forms' stage_in_fetch on Metal and prints
their words.
2026-11-12 04:10:11 -08:00
Anees Iqbal 663e15af9f Bump SEMANTICS_VERSION to 2043: OpenGL front end shapes the ABI now decodes
A kernel stage-in attribute's user key, a plain buffer's declared size differing from its
typed pointee, and an empty !gld.plugin_info list were refusals and now decode, so the
outputs of such modules change (kernel_read_through_constant.air.ll among the fixtures).
2026-11-12 04:10:11 -08:00
Anees Iqbal 71f820395a ABI: OpenGL front end shapes: a stage-in attribute's user key, a plain buffer's declared size, the empty plugin list
Apple's OpenGL front end (GL on Metal) writes AIR that Metal makes pipelines of and the
metadata ABI refused:

- A kernel's per-attribute air.stage_in node follows its location with the attribute's
  name as a user key (`attrib_0`), as AIR 2.2 does for a vertex input. A stage-in attribute
  binds by its location, so the key is read and dropped, as the vertex input's is. Before:
  UnknownKey with no key at the argument.
- A plain buffer's air.arg_type_size is its declared type's (`uchar`, 1) while the typed
  pointer parameter points at a float or uint. Metal makes the pipeline, as it does for the
  owned fixture kernel_read_through_constant's one `char` behind a pointer to its 160-byte
  struct. The declared size now governs a plain buffer with no struct layout (alignment still
  a power of two, air.buffer_size a multiple of the declared size); an argument buffer's
  (its element stride for memory), a threadgroup argument's and a struct layout's pointee
  still agree. Before: TypeSizeMismatch at air.arg_type_size.
- Every module it writes names an empty !gld.plugin_info list, which carries nothing; a
  non-empty one stays UnknownKey.

Found from AIR this Mac's OpenGL wrote for GLSL of our own (scratch, not committed).
Unit tests for each shape; the typed fixture now compiles to its opaque form's module.
2026-11-12 04:10:11 -08:00
Anees Iqbal 1e659e16e1 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 04:09:47 -08:00
Anees Iqbal 5238c0855a RUNTIME_VERSION 2106: minimumLinearTextureAlignment answers the pitch every usage keeps in place
The commits before this one. minimumLinearTextureAlignmentForPixelFormat: probed only a read texture's images, so
ANV on an Iris Xe answered 16 and a render target at that alignment fell to a shadow (its rows not on the device's
memory line, the renders check failed). The probe now tries ShaderRead, then RenderTarget, then ShaderWrite, and
answers the largest of their smallest in-place alignments, at least nonCoherentAtomSize (Metal's 16 stays where no
usage is ever in place). The linear_alignment record's VERSION goes 1 -> 2, so every driver probes once again. The
answer promises the probe's pitch (the row's bytes rounded up to it); a wider bytesPerRow is not promised in place.

Verified: ANV Iris Xe (ms01, m3-max-20463) answers 64 for 96 formats where it answered 16; 9/9 render targets at 64
in place, the old answer's RGBA8 one at offset 16 a shadow; 72/72 reads in place. lavapipe (m3-max-20437) 64,
9/9 + 72/72; RX 550 (m3-max-20451) 256/512/1024 by texel size, 9/9. tests::linear_alignment, capabilities, families
39/39 (m3-max-20424); lint three ways and rustdoc (m3-max-20468). The probe's first query: lavapipe 17.2 -> 43 ms,
RX 550 119 ms, Iris Xe 124 ms (debug), once per driver identity and record version.
2026-11-12 04:08:45 -08:00
Anees Iqbal 1725128528 Linear alignments: the answers and the probe's time measured with its three usages
The README named the M3 Max's MoltenVK at 16 and RADV at 256 from probes of reads alone. It now
names what the lane measured with reads, renders and writes at d91a18ca98: ANV on an Iris Xe and
lavapipe 64, RADV on a Radeon RX 550 256 (512 and 1024 for 8- and 16-byte texels), and 16 for the
formats no texture of over a buffer is ever in place. The module doc's probe time (17 to 23 ms,
reads alone) is now the first query's with the record absent, in the same debug lane test: 43 ms
on lavapipe (m3-max-20437; 17.2 ms with reads alone, m3-max-5986), 119 ms on the RX 550
(m3-max-20451), 124 ms on the Iris Xe (m3-max-20463); reading the record took 0.20, 0.53 and
0.69 ms.

Verified: cargo fmt; docs only.
2026-11-12 04:08:33 -08:00
Anees Iqbal 56dbf31db5 Render targets at the answer: try the probe's pitch alone
The lavapipe lane (m3-max-20419) failed a_render_target_at_the_answered_alignment_is_in_place
at RGBA8Unorm 16x5, offset 64, rows 128 apart: a shadow at the answer of 64. The probe tries a
row's bytes rounded up to the alignment as the pitch, so the answer promises that pitch, not
one an alignment wider; the test now makes its render targets at the probe's pitch alone, and
its doc says a wider one is not promised. The tight case passed in the same run.

Verified: cargo fmt. The lane rerun follows.
2026-11-12 04:08:33 -08:00
Anees Iqbal 2edb063c6a tests::linear_alignment: skip a profile that states no nonCoherentAtomSize
roadmap-2022, a requirements profile, states none; the rule's sweep over
the committed profiles now reads the 18 that state their line and
checks that many do. Job m3-max-20418 failed on it.
2026-11-12 04:08:33 -08:00
Anees Iqbal 3e5293679e minimumLinearTextureAlignment: every usage's pitch, at least the device's line
The answer was, per format, the smallest power of two from 16 at which
a ShaderRead texture of every probed width took its in-place image. Two
things it did not cover:

- A texture that renders or that a shader writes takes the same
  in-place image with those usages, whose linear layout the driver may
  pitch otherwise. The probe now tries reading, reading and rendering,
  and reading and a shader's writes (USAGES), and answers the largest of
  the usages that ever lie in place (a usage the format's linear images
  cannot take has none).
- The device's check of images in place measures lines of
  nonCoherentAtomSize bytes (in_place::RowEnds), and on the Iris Xe its
  renders and writes of texels that share a line with bytes beside them
  fail (the line holding a row's last texels is written back whole). ANV
  answered 16 against a 64-byte line, so a guest that laid a render
  target out at 16 put its texels in a line with bytes before them: a
  shadow. The answer is now at least nonCoherentAtomSize, "the size and
  alignment in bytes that bounds concurrent access to host-mapped device
  memory" (vkspec, Limits) (placed_answer). At it, a texture whose rows'
  bytes fill whole lines shares none with other bytes. Rows whose bytes
  are no multiple of the line keep their padding in their last line at
  any alignment, so on ANV those stay shadows for renders and writes
  whatever the answer; the docs say so.

Metal's 16 stays where the device imports no host pages, for a format
no usage brings in place, and where a probe failed. The record's VERSION
goes to 2, so no answer of the old probe is read again. Expected answers
(the venues' read answers with the line): ANV 16 -> 64, lavapipe 64,
RADV 256, MoltenVK 16 (its line is 16).

Tests: tests::linear_alignment's the_answer_is_the_usages_largest_and_
at_least_the_line (the rule over every committed profile's line, ANV's
16 before and 64 after); the lane's render-target test (previous commit)
gains the same texture at Metal's 16, a shadow wherever the check failed
such renders.
2026-11-12 04:08:33 -08:00
Anees Iqbal 6e5a5594e8 Lane: a render target at the answered linear alignment is in place
A RenderTarget texture of RGBA8Unorm, RGBA16Float and RGBA32Float over
a no-copy buffer, at an offset of the format's
minimumLinearTextureAlignmentForPixelFormat answer and rows whose bytes
are a multiple of it (tight, or the answer apart past them), must share
no line of the device's memory (in_place_check_line, nonCoherentAtomSize)
with bytes beside its texels, and must be in place wherever the device's
check passed renders of such textures over pointer-imported pages; a
blit out of it reads the caller's texels.

The answer must be at least the device's line for that. On ANV the
answer is 16 and the line 64, so this test fails there until the answer
takes the line (the next commit). over_pages takes the texture's usage.
2026-11-12 04:08:32 -08:00
Anees Iqbal 7f3412bf64 Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 03:58:04 -08:00
Anees Iqbal a4466edfa6 RUNTIME_VERSION 2105: heap textures over host pages in the device's image, padded rows in place, reordered views of the image
The commits before this one (their own bumps to 2101-2103 were taken by other landings and are left out). Three
behaviour changes, each a shadow or copy that was a first option where the device has an in-place form:
- A texture Metal tiles in a Shared heap over host pages lies in the device's own image over the pages first; Metal's
  tiled byte layout is kept only as the fallback. Apple documents a heap texture's byte layout as private, and the
  consumer's guest code never reads or writes those bytes directly. The host-allocation linear image's requirements
  go through the requirements cache (counted), so making such textures every frame makes no extra VkImage.
- A texture over a buffer whose GPU bytes only the runtime's ordered commands write (a Private buffer, a Managed
  buffer's device copy) and whose rows are padded lies in place in route 1 (LINEAR, PREINITIALIZED, kept GENERAL)
  where the driver's rowPitch equals the buffer's pitch: Vulkan 7.1.1 (a transition from the current layout
  preserves the range) and 12.11 (host-accessible aliases are consistent). Not render targets. New counters:
  kept_padding_aliases; managed_ranges_modified / managed_bytes_modified, managed_resources_synchronized /
  managed_bytes_synchronized. New runtime query Device::linear_texture_bytes_per_row: the driver's own linear pitch.
- RGBA8Unorm, BGRA8Unorm and their sRGB twins, when they render, list their channel-order sibling and its twin in
  VkImageFormatListCreateInfo, so a pass renders into a BGRA8 view of an RGBA8 texture made without PixelFormatView
  (the view Apple documents as allowed) on the image itself, with no shadow; a linear image never loses a feature to
  the sibling formats (linear_keeping).

Measured (release, medians): the reordered view's clear, 3090 60.0 -> 17.8 us, RX 550 620.6 -> 228.8 us
(shadowed-texture-view notices 1 -> 0); the plain clear and copy unchanged within spread on both (3090 17.4/42.1 ->
18.3/44.1, RX 550 230.1/393.9 -> 229.0/392.2), so listing the siblings shows no measurable compression cost there.
Tests: kept_padding 3/3 and the view, sample and resource_ids lanes 71/71 on the 3090 (m3-max-20450); heap_layouts
counts tiled 1 -> 0 per shape with texels through every API path; lavapipe green (m3-max-20281, 20429); build and
gpucfg clippy (m3-max-20414).
2026-11-12 03:57:06 -08:00
Anees Iqbal f26ed9a694 Tests: the Shared contrast's shadow copies in for a kernel's read; reordered views within 1
kept_padding's Shared contrast read and wrote the shadowed texture with blits, which go to the
buffer's bytes, so the shadow never copied in (m3-max-20318, 20380 on the 3090). A kernel
(invert_texels) now reads it: the copy in is counted and the kernel reads row 7 as the CPU wrote it.

view_attachments' BGRA8Unorm view check allowed no difference; the 3090 stored 0x7f where Metal
stored 0x80, a unorm tie the device rounds its own way. It takes the slack of 1 the file's other
unorm checks take.
2026-11-12 03:56:51 -08:00
Anees Iqbal 944d3f11a9 image_plan: linear_keeping clears MUTABLE_FORMAT by difference
The crate's ImageCreateFlags has no remove (E0599 in m3-max-20332, the
gem10 build of 66b5cad4bb); difference is its form.

Verified: not yet built; the next gem10 build builds it.
2026-11-12 03:56:51 -08:00
Anees Iqbal 72a86e45f3 kept_padding: the Shared contrast counts the copy in before a blit that writes a row
On the RTX 3090 (m3-max-20318) the Managed test's in-place half passed
and its Shared contrast failed: the blit that reads the shadowed
texture into a buffer reads a texture over a buffer from the buffer's
bytes, so no shadow texel was copied in. The contrast now writes row 20
into the Shared texture by a blit, which writes its shadow after taking
its texels in (as blit_cover.rs's partial copy), and reads rows 7 and 20
back. The Managed texture's same blit is asserted to copy no shadow
texel in.

Verified: not yet run.
2026-11-12 03:56:51 -08:00
Anees Iqbal 47ccb574ba image_plan: a render target's sibling formats never cost its linear image
231a2cd061 lists a render target's channel-order sibling's formats
(BGRA8Unorm and BGRA8Unorm_sRGB of an RGBA8Unorm texture) in its plan.
The same plan is the linear image's of every texture over a buffer's or
host pages (route 1, the host-allocation image, Between::Kept), whose
check (linear_lack) asks every listed format's linear tiling for the
features the usages need. Where the sibling's linear tiling lacks one
(a color attachment, say) and the texture's own formats hold them, the
listing would have turned such a texture, a guest surface among them,
from the image over its bytes into a shadow.

linear_keeping returns the plan without the formats only the sibling
added where that plan's linear image lacks nothing and the listed one's
does: the linear routes keep their image, and the sibling's views of
that texture stay apart, as before 231a2cd061. Expected, not measured:
the committed profiles' linear tables give B8G8R8A8 and R8G8B8A8 the
same features, so nothing is left out there; the test prints any
profile where it is.

Test: image_plan::render_targets_take_their_channel_order_sibling_s_views
now asserts, where a sibling's views are not taken though the device
renders them directly, that the plan's linear image lacks nothing.

Verified: not yet built.
2026-11-12 03:56:51 -08:00
Anees Iqbal cdcd787fb8 A render target's channel-order sibling views are views of its image
A pass rendering into a BGRA8Unorm or BGRA8Unorm_sRGB view of an
RGBA8Unorm texture made without PixelFormatView usage (and the same for
BGRA8Unorm and the sRGB twins) rendered through a shadow image of the
view's format, copied in before the pass and back after it
(shadowed-texture-view, about 50-95 us a command buffer at 64x64): the
texture's image was mutable only for its sRGB twin's formats, so Vulkan
made no view of it in the sibling's format.

Basis, documented on both sides:
- Vulkan: VkImageFormatListCreateInfo (core 1.2), pViewFormats
  "specifying all formats which can be used when creating views of this
  image", with MUTABLE_FORMAT; the formats are of one class.
- Metal: MTLTextureUsage.pixelFormatView, "Don't set this option if your
  texture view only converts between linear space and sRGB. For example,
  if your texture uses the rgba8Unorm pixel format and your texture view
  uses bgra8Unorm_srgb." Plain Metal makes the BGRA8Unorm view too and
  renders through it (its API validation stops it; view_attachments).

Change (image_plan.rs): a color texture of those four formats with
RenderTarget usage lists, besides its sRGB twin's views, the views of
its sibling and the sibling's twin (reordered_views, reordered_formats),
in the single-sample and the multisample plan; a word attachment's view
is left out as for the twin. A texture that renders nothing lists none:
its sibling views already read the image through a swizzle. The view's
other uses then view the image too (takes_views_of).

Compression: expected, not measured. Mesa's sources suggest RADV before
GFX11 keeps no DCC for a list whose formats' channel orders differ, ANV
keeps CCS_E for formats of the same channel bits, RADV GFX11+ keeps DCC
for any list; NVIDIA documents nothing. The A/B lane
view_attachments::reordered_view_render_costs (the parent commit)
measures it per driver.

Tests: image_plan::render_targets_take_their_channel_order_sibling_s_views
(every committed profile: the sibling and its twin taken where the
device renders them directly, none for a texture that only reads, none
for RGBA16Float); runtime_lane::view_attachments::
a_render_target_s_reordered_views_render_in_place (draws through both
views, Metal's bytes, no shadowed-texture-view).
Docs: the ShadowedTextureView notice (degradation.rs, API.md), the
FAST-PATHS view bullet, view_shadow.rs.

Verified: not yet built.
2026-11-12 03:56:51 -08:00
Anees Iqbal 99d83d06f4 view_attachments: what a render target and its reordered view's pass cost the GPU
An ignored measurement, run by name: a 2048x2048 RGBA8Unorm Private
render target made without PixelFormatView usage, timed for a pass that
clears it and stores, a blit into another such texture, and a pass that
clears its BGRA8Unorm view, each its own command buffer (medians and
fastest of 40 after 8), with the notices printed (shadowed-texture-view
when the view's pass renders through a shadow).

It is the A/B for listing the channel-order sibling's formats in such a
texture's image (the next change): the first two numbers show whether
the driver keeps its compression with the longer list, the third what
the view's pass costs as a shadow against in place.

Verified: not yet built.
2026-11-12 03:56:51 -08:00
Anees Iqbal afff0e6cfe kept_padding: the Managed test's words by as_chunks
clippy's chunks_exact_to_as_chunks denied the constant-size
chunks_exact in the Managed test's host words (m3-max-20244's clippy
leg). The words are the same.

Verified: m3-max-20244 (lavapipe on msi, at 602a8bcc3e) ran the runtime
filter (248 passed, the three kept_padding tests among them), the
validation filter (332 passed, the heap_layouts lane among them) and
api_signatures/api_surface (15 passed); only this lint failed.
2026-11-12 03:56:51 -08:00
Anees Iqbal 946ee6e0b6 Device::linear_texture_bytes_per_row: the driver's own linear pitch for a 2D texture
A texture over a buffer whose rows hold bytes between them is the
device's linear image in place (route 1, and Between::Kept for a buffer
only the device's ordered commands write) only at the pitch the driver
itself reports for that image (vkGetImageSubresourceLayout's rowPitch);
the alias checks it exactly. A caller laying out rows had no way to ask
for that pitch: minimum_linear_texture_alignment_for_pixel_format
answers the alignment of images over host pages (16 where the device
imports none), and a pitch rounded up to it can miss the driver's.

The new query (a runtime extension, no Metal counterpart) plans the
image as the texture's making does (declared_plan), makes the plan's
linear image unbound, reads its rowPitch, and releases it. It answers
None where the texture is not one 2D level, layer and sample, or where
the device has no linear image of the plan.

Test (kept_padding.rs): at the answered pitch the texture over a
Private buffer is in place; at each other padded pitch it is a shadow.
Docs: the runtime README beside the alignment query, HOWTO beside the
kept-padding sentence; api_signatures.tsv.

Verified: not yet built; the lavapipe job and one GPU run follow.
2026-11-12 03:56:50 -08:00
Anees Iqbal 3918e6de0b requirements: Query derives no Debug
vk::ImageTiling has no Debug, so the derive on Query, the requirement
cache's key for host linear images and tilings, failed to compile
(E0277 on the lavapipe build of m3-max-20214). Nothing prints a Query.

Verified: not yet built; the next lavapipe job builds it.
2026-11-12 03:56:50 -08:00
Anees Iqbal 42e11abcd4 Textures over buffers only the device's ordered commands write hold their rows' padding in place
What: a texture that renders nothing over a buffer of the runtime's own memory whose rows lie
with the buffer's bytes between them is now the device's linear image, made PREINITIALIZED, at
the buffer's pitch, where only the device's commands, in the runtime's order, write those bytes:
a Private buffer, and a Managed buffer's own on a device without unified memory (a two-copy
no-copy buffer's device copy, or one with its own host copy), not one whose VkBuffer was handed
out or whose memory is exportable (Buffer::gpu_bytes_ordered). linear_plan::holding answers what
an image may hold besides the texels (Between::{Nothing, Unobserved, Kept}); Kept takes route 1
alone: the linear image whose rowPitch the driver reports equal to the buffer's
(vkGetImageSubresourceLayout, aliases with within_padding). No DRM_FORMAT_MOD_LINEAR image at
Metal's pitch, no image over exportable memory or in exportable blocks, as each is made
UNDEFINED. A render target stays a shadow. Counted: WorkCounts::kept_padding_aliases.

Also two pairs of counts of what the program asks of a two-copy Managed buffer, beside the bytes
the runtime copies: managed_ranges_modified and managed_bytes_modified (did_modify_range),
managed_resources_synchronized and managed_bytes_synchronized (synchronize_resource), to compare
with managed_bytes_copied_in and managed_bytes_copied_out.

Why: the RTX 2080 guest census (reims's v302 run) made 230 textures over Managed buffers, 200 of
them RGBA8 ShaderRead|ShaderWrite at 3884, 4208 and 2448 texels a row with rows rounded up to
256 bytes, every one a shadow for its padded rows ("its rows lie N bytes apart"): 2.52 G shadow
texels first copied in, 1.26 G kept, 1.26 G words examined by merges back. Owner's rule:
in place where possible, a shadow only where impossible. Main approved the route and its
conditions.

Basis (Vulkan 1.4, docs/API.md's shadowed-texture entry): 7.1.1 Image Layout Transitions, "Image
layout transitions may perform read and write accesses on all memory bound to the image
subresource range ... If the old layout matches the current layout of the image subresource
range, the transition preserves the contents of that range": the image's one transition is its
first move, PREINITIALIZED to GENERAL, out of the layout it is in, ordered after and before every
write of those bytes, as only the device's ordered commands write them. 12.11 Memory Aliasing:
"Buffers, linear tensors, and linear image subresources are considered host-accessible
subresources when they are in any of these layouts: VK_IMAGE_LAYOUT_PREINITIALIZED,
VK_IMAGE_LAYOUT_GENERAL ... If two aliases are both host-accessible, then they interpret the
contents of the memory in consistent ways, and data written to one alias can be read by the other
alias." VkSubresourceLayout's "size includes any extra memory that is required based on
rowPitch" puts the padding inside the range. A kernel's writes may change the padding as on the
x86 Macs (in_place::Padding::Free); a render pass's load and store "may read and write back" it,
so render targets keep the shadow.

Verified: not built yet. tests::kept_padding (a Private buffer at 416, 448 and 512 bytes a row,
the buffer read back whole after the image's first move; a Managed two-copy texture changed in
one row through did_modify_range, then a blit-written row synchronized out, every byte between
rows as given, against a Shared buffer's shadow), tests::linear_plan's holding cases and
tests::texture_placement run on lavapipe next, then one RTX 3090 run.
2026-11-12 03:56:50 -08:00
Anees Iqbal e1ba565ea3 Tests: a plain texture in a heap over host pages lies in the device's image over the pages, else in Metal's tiles
What: runtime_lane::heap_layouts follows the route e3b1cd42d1 gives a texture Metal keeps
uncompressed in a heap over host pages. The plain-shape test (renamed
a_host_heap_s_plain_texture_lies_in_place_or_in_metal_s_tiles) branches on the texture's count:
in place (counted untiled, the first announced heap-texture-untiled-layout with its ID, made with
no zeros) its texels round-trip through replaceRegion and getBytes, a blit in and out and a
buffer's fill over its bytes, and a blit into it writes no byte of the heap outside its answered
size; tiled, every assertion of Metal's tiles stands. It prints how many shapes lay each way: the
proof that the tiled count over host pages goes from one per shape to none where the device's
image serves. The made-again, beside-dispatches and two-ways tests check Metal's bytes only for a
tiled texture; the merge-scratch test skips, saying so, for one in place; the block rows count an
untiled row (in place, or decoded) beside a tiled one.

Verified: not run yet; the lavapipe run of the heap lanes follows.
2026-11-12 03:56:50 -08:00
Anees Iqbal 3689e5c9d6 Heaps over host pages: keep the linear image's requirements for host allocations as the plan's others
What: host_image_requirements (the linear image made for host allocations that a texture in a
heap over host pages lies in) now takes the answer kept for its plan on a device that enables
maintenance4, as planned_requirements does, and counts its limits query and its image
(WorkCounts::requirement_limits_asked, requirement_images_made). RequirementAnswers is keyed by
plan and a Query (a tiling for the device's own memory, or the host-allocation linear image).

Why: the commit before this one has every plain texture in a heap over host pages try that image
first, so each making (a window server makes its heap textures each frame) made and destroyed a
VkImage and asked the device's limits, uncounted, where the tiled route asked nothing after the
first. Vulkan fixes the answer by the creation parameters (Resource Memory Association: size by
the create info and its pNext chain, memoryTypeBits by tiling and handleTypes, alignment under
maintenance4), and an image whose handle type the limits take without DEDICATED_ONLY requires no
dedicated allocation ("requiresDedicatedAllocation will otherwise be VK_FALSE").

Verified: not built yet; runtime_lane::heap_layouts' made-again test checks the counts on the
lavapipe run that follows.
2026-11-12 03:56:50 -08:00
Anees Iqbal 9d184d13ec Heaps over host pages: a texture Metal tiles lies in the device's image over the pages first
In a heap over the caller's host pages (new_heap_with_bytes_no_copy), a single-sample texture
whose bytes Metal lays out in its tiles now takes the image bound to the pages wherever one
serves: its linear image made for host allocations, or over dma-buf pages the driver's
DRM_FORMAT_MOD_LINEAR image, in the driver's rows with no copy, announced
heap-texture-untiled-layout (Untiled::LINEAR). The shadow of Metal's tiles (AliasRoute::Tiled)
is the fallback where no such image serves, and stays the route of a copied heap.

The bytes in guest pages are now the device's layout, not Metal's tiles. Basis: Apple documents
a texture's layout in a heap's bytes as private to Metal, and the consumer confirms that no guest
code of theirs reads or writes a heap texture's bytes in guest pages (replaceRegion and getBytes
go through a staging blit; no buffer aliases a heap texture), so the copies in and out of the
tiles shadow bought nothing it could see (the owner's rule: shadows are a fallback, never a
first option). dma_buf_heap_plan now answers why its image does not serve instead of taking the
shadow itself, so a texture Metal tiles over dma-buf pages falls back to the tiles shadow before
the rows one.

Docs: host_heap_plan, AliasRoute::Tiled, the dma_buf module, the heap-texture-untiled-layout
declaration and catalogue entry, and the FAST-PATHS known-gap entry on heap textures in the
driver's layout.

Verified: cargo fmt only; builds and tests run as potluck jobs after this commit.
2026-11-12 03:56:49 -08:00
Anees Iqbal ee52d7e483 Tests: a layer pass's own shadow stands and its backdrop read copies its rectangle alone
The compositor-shaped probe now asserts what lavapipe measured (m3-max-20039, LAYER-STANDING):
from the second command buffer on, the Private plane's shadow is skipped by its standing (1024
texels), and the only texels copied in are the attached read's rectangle a pixel wider each way
(108), whose shadow holds part of the truth and so never stands (Missed::Partial).

Verified: m3-max-20039 printed these counts at d22a0902e5 on lavapipe; the assertions run in the
next job.
2026-11-12 03:56:49 -08:00
Anees Iqbal 658e8b4976 Tests: a compositor's layer pass over a Private plane, command buffer after command buffer
A probe of the standing of a shadowed texture over a Private surface plane that a pass loads,
draws into and reads at its own pixels (a backdrop), as a window compositor's layer passes do:
it prints each command buffer's copies in (LAYER-STANDING) and checks the bytes each pass
leaves.

Verified: cargo fmt only; the run is a potluck job after this commit.
2026-11-12 03:56:49 -08:00
Anees Iqbal 230c34472e Re-pin the runtime sources at the landing tip
The landed packet changed a runtime-sources input, so the committed digest no

longer described the sources and `the_runtime_sources_are_the_committed_ones`

would fail. Recomputed over the same inputs and committed by land-pkt.sh.
2026-11-12 03:45:55 -08:00
Anees Iqbal b5c0db3294 attached_levels: name the slot parts alias SlotParts
The exit-guard scan (tests::exit_guard::only_the_listed_modules_keep_the_device_s_functions)
finds the types that keep the device's functions by name, and device/mod.rs's visible `Parts`
keeps them: the private `type Parts<'a>` of render/attached_levels.rs, which holds `&Device`
and keeps no copy of the functions, read as one by name at its three by-value parameters.
Renamed, the module keeps nothing the scan lists.
2026-11-12 03:44:56 -08:00
Anees Iqbal 250438e30e Candidate rows: the argument-buffer sparse-sample cases on the RADV 780M
The two authored cases over tail_argument_sparse_samples (99b72141..., the sample's value where
resident; c8f6a438..., resident() states every texel resident) ran as Vulkan candidates on the
amd-780m-radv venue (AMD Radeon 780M Graphics, RADV PHOENIX, Mesa 26.2.6-arch3.1), stated and
robustness-off legs, against the M3 Max's Metal rows (apple-m3-max-macos27.0.1). All four runs
report Match, with candidate output hashes ebc81c32... and 67c145ea..., the Metal rows' own.

Lavapipe on that node is Mesa 26.2.6 with LLVM 23.1.4, not the venue's Ubuntu 26.0.8 identity, so
the venue check rejected those runs and no lavapipe row is recorded here; CI's Ubuntu lavapipe
qualification covers them.

Verified: potluck m3-max-20423 (homelab-um790-xtx-1, MESA_VK_DEVICE_SELECT=1002:15bf!, radeon
ICD only).
2026-11-12 03:43:53 -08:00
Anees Iqbal d714059dd0 Metal observations of the two heap-texture sparse-sample cases on the M3
corpus-metal qualified both on apple-m3-max-macos27.0.1 (job m3-max-20396, three runs each):
99b72141ffee (the value where resident) output_sha256 ebc81c32735a, and c8f6a438d16d (the residency
read) output_sha256 67c145ea102f, each the SHA-256 of the 2x2 rgba16_float pixels the rationale
states: Metal samples the argument buffer's texture that is not sparse as resident, its texels
exact.
2026-11-12 03:43:53 -08:00