Commit Graph
164 Commits
Author SHA1 Message Date
Anees Iqbal a3214f16f7 RUNTIME 2237: a skipped inert dispatch still names what it binds, so its command buffer copies Managed buffers in
RUNTIME 2228 (3969e96010) records no Vulkan dispatch for a kernel with no loop that writes only its
own threads' and threadgroup memory, but compute::record returned at the top for such a pipeline,
before the dispatch's uses were made. Its bound buffers were never named by the batch, so a
Managed buffer the CPU wrote with didModifyRange kept its modified range for the next command
buffer that named it: the guest's timed kernel, which then paid a fill-queue submission and the
bytes over the link. Metal (and pin 69) copies it in with the command buffer that binds it. The
early return also skipped the detached/rebound check, holding resident buffers, the offset and
function-table checks, the stage-in reach check, fills and first work for what it binds, and the
table retain.

Now an inert dispatch plans and makes its uses as any dispatch, passes the detached-buffer check,
and names them (EncoderCore::name_uses: keys kept, host-page buffers held and named, resident ones
held; no hazard tracking and no write noted, as it runs nothing), retains its table, counts
dispatches_skipped_inert and records no vkCmdDispatch.

Found by gbreg from the consumer's Geekbench traces on the RTX 2080 (gbt pin 69 vs gbi
a2ac4433ca; the split run gbh, their tree on our pin-69 runtime, put the rise in our runtime):
solo import_image_rgba_to_rgb 0.228 -> 1.118 ms, color_look_up_tetrahedral 0.769 -> 2.651 ms.

Verified (gbreg, 5ac162c1ba on 84f68cc6d9):
- 2080 release harness examples/inert_uploads (26460; 330ca5a282 / a2ac4433ca / 84f68cc6d9 / fix,
  medians, two passes): batch shape (40 x 8 MiB Managed, CPU-written; A = 40 inert dispatches
  binding them, B = 40 dispatches reading 4 KiB of each): B 0.36 / 169.6 / 169.5 / 0.39-0.45 ms
  (the 335.5 MB copy-in back in A); frames shape (FT-like): frame wall 0.56 / 1.2-1.34 / 1.2 /
  0.17-0.20 ms, fill-queue submissions per frame 0 / 1 / 1 / 0. Inert dispatches alone: GPU 0.006
  ms at the fix as at a2ac4433ca (the skip's win holds); encode 0.9 us per inert dispatch.
- lavapipe inert_dispatch 5/5 (26452); negative control (fix reverted, tests kept) 4/5, the new
  detached test failing Completed vs Error(DetachedBacking) (26454).
- Owed on development: 2080 copy-in test runs, clippy in three configurations, rustdoc.

RUNTIME_VERSION 2236 -> 2237.
2026-11-13 12:58:22 -08:00
Anees Iqbal 574d199d67 RUNTIME 2236: a managed synchronize decides its copy as it is encoded and records it in place
RUNTIME 2231 split the guest's encoder at each synchronize of a Managed buffer into its own
deferred segment (Deferred::SyncOut): every command buffer holding one paid an extra continuation
VkCommandBuffer and a segment VkCommandBuffer, its batch could no longer fold its end (an extra
VkSubmitInfo), and the copy was decided at submission. On the consumer's 2080 Geekbench walk that
showed as ~1 extra no-dispatch command buffer per synchronize.

Now the copy is decided at encode, from the kept writes of other command buffers plus this command
buffer's own writes before the synchronize, and recorded in place with only the written regions;
an unwritten synchronize records nothing. The copy is whole where an earlier segment is unknown,
the command buffer writes memory no use names, or the buffer was handed out. At submission,
settle_syncs_out adds a top-up command buffer just before the part holding the copy, covering only
writes from other command buffers noted after the encode, between two all-stage barriers
(WorkCounts::managed_synchronizes_topped_up, new). The SyncOut segment is gone (deferred.rs is
back to its 041038a914 form); may_fold folds again.

Verified (mansync, 4e3e22f4d6 on 8a81350e13; 2080 release, one run each, 26257), per command
buffer, 041038a914 / 8a81350e13 / fix:
- all (40 written): VkSubmitInfos 1/2/1, VkCBs 2/4.1/2, GPU 95.61/95.66/95.62 ms
- mixed (30 written, 10 CPU did_modify_range): VkSubmitInfos 2/3/2, VkCBs 3/5/3, copied
  176/132/132 MB, GPU 95.4/71.6/71.6 ms
- none (40 unwritten): VkCBs 1/3/1, GPU 95.05/0.014/0.007 ms
- small (import shape: 1 MiB fill + 2 unwritten 335,872 B no-copy synchronizes): VkCBs 2/4/2,
  commit-to-completion 0.519/0.111/0.116 ms (keeps ~4.5x)
vkQueueSubmit calls equal in every row; topped_up 0 in every fix row. Tests on the 2080 (26258):
managed_copy_device, detached_contents, kept_padding, device_memory_overflow 41/41, with two new
steps (a write committed before but encoded after the synchronize: topped up 1 and every byte read
back; a write committed after: nothing copied, the next synchronize copies exactly that range).
clippy plain 26228, --cfg m2v_gpu 26227, --cfg m2v_cpu_icd 26229 all 0; rustdoc 26230 = 0.

RUNTIME_VERSION 2235 -> 2236.
2026-11-13 12:24:45 -08:00
Anees Iqbal c7d652ca5e RUNTIME 2232: the scheduler loses no wake for a batch held behind an unshared queue or a kept group
A guest's commitAndWaitUntilSubmitted could stay unanswered until the next commit (reims, XTX
RADV at pin 71, 2 of 77 runs under load: "A was never submitted"; the GPU idle; the scheduler
asleep with the batch held for 10 s; an empty commit on another queue released it at once).

Cause (reims's finding, /tmp/xqtest/m2v-finding.md): on a host whose one graphics VkQueue an
unshared queue also holds (RADV, ANV; WindowServer's queues are unshared), batch A behind H was
held by held_for_unshared() while H was in the Flight. QueueSlot::completed publishes `completed`
(fetch_max) before waits.completed takes H out of the Flight. When H completed between those two
steps, the hold read a stale Flight and gated on completed + 1, which nothing meets.

Fix:
- Unshared hold: QueueWaits::hold_ahead reads the published completed value under the waits lock;
  Flight::ahead(ran, completed) counts batches at or below it as gone; Room::Hold { after, through }
  carries the oldest still in flight; await_unshared_room gates on `through`, fences, and reads
  again (completed >= through wakes it at once). No reorder of QueueSlot::completed.
- Kept group (submit_ready, Group::keeps read before gate_on): sets the gate, fences, then reads
  again (Group::pending_through), the protocol gate_heads and check_heads use.
- A WAIT_SLICE that ends with a batch held makes a pass, as the module docs promise, counted in
  WorkCounts::scheduler_slice_rescues (0 wherever every wake comes). api_signatures and host_ab
  updated.

Verified (perdraw5, msi 26135, lavapipe, at 3bd14c83ac on a2ac4433ca): clippy all features and
--cfg m2v_gpu, rustdoc -D warnings, api_signatures/api_surface green; 36/36 of scheduler_held_wakes,
scheduler_wakes, completion_wakes, scheduler, unshared_hold. tests::scheduler_held_wakes forces
each interleaving with test-only hold points (completion::trace, cfg(test) + device cfgs; `Leave`
sits between QueueSlot::completed's fetch_max and waits.completed):
- unshared: H held at Leave while the next is committed; it goes with 0 slice rescues.
- kept group: both completions published between keeps and the gate; it goes in that pass, 0.
- lost wake: completion wakes dropped; the held group goes at the next slice (1 rescue, 99 ms).
Negative controls each fail only their own test: old gate (unshared held until the slice at
101 ms, and with development's code until the next commit, reims's symptom); kept recheck
removed (102.9 ms, 1 rescue); a slice making no pass (never completed within 5 s).

RUNTIME_VERSION 2231 -> 2232.
2026-11-13 11:22:48 -08:00
Anees Iqbal d38b5c4ef6 RUNTIME 2231: a managed synchronize copies out only the bytes the GPU wrote
On a device without unified memory, synchronizeResource: copied the whole Managed buffer (or a
texture's whole span over one) to its host copy every time. The runtime now keeps the GPU's
writes for each buffer that has been synchronized once (managed_sync.rs: GpuWrites, SyncCopy,
SyncOut), stamped in the scheduler's submission order across all queues. The copy-out is its own
segment (Deferred::SyncOut), decided when its batch is submitted, so it covers the writes of
earlier batches, of earlier encoders in its batch and of its own encoder, including a write
encoded after the synchronize but committed before it. Completion of the command buffer holding
the copy drops only the writes noted before the copy. It copies nothing when the GPU wrote
nothing since the last copy, and still copies the whole buffer where the writes cannot be known:
an untracked buffer; one whose VkBuffer was handed out or whose memory is exported; a buffer's
first synchronize; any batch since the last copy, not yet complete, that may write memory no use
names (State::writes_unnamed); and a synchronize recorded in place (a predicated loop's laying, or
no VkCommandBuffer could be made). Every barrier is still recorded. Pages no import maps copy back
only the regions copied. Textures over buffers take the same path (an image range counts as the
whole buffer). Touches command_buffer/submit.rs (record_syncs_out after record_scrubs) and
command_buffer/mod.rs (the footprint loop skips SyncOut segments), encoder.rs, tracker.rs,
deferred.rs, device/mod.rs. New WorkCounts: managed_synchronizes_unwritten,
managed_synchronizes_whole, managed_bytes_unwritten_skipped. FAST-PATHS managed bullet, API.md
managed section and the runtime README updated. No speed-for-accuracy choice.

Why: on the RTX 2080 the guest's Background Blur spent 0.90 s of GPU time copying out 3.5 GB
over 800 synchronizes (~176 MB a command buffer, the 2080's x4 link), whole resources each time.

Verified (mansync; step codes read inside the jobs):
- clippy --all-targets --all-features -D warnings, workspace: plain 25924, m2v_cpu_icd 25927,
  m2v_gpu 25928, all 0; rustdoc -D warnings 25935 = 0 (at b72228629c).
- RTX 2080 (um790) at ac0887e7f5, 25942: 41/41 (managed_copy_device, detached_contents,
  kept_padding, device_memory_overflow; hazard tests excluded). Counts (copied, skipped,
  unwritten, whole), both Import and Pages: first synchronize (1048576, 0, 0, 1); after no write
  (0, 1048576, 1, 0); after a fill in an earlier command buffer (16382, 1032194, 0, 0). Every
  byte checked after each step, including a write committed before the synchronize's command
  buffer but encoded after it, and a CPU write named by didModifyRange.
- Negative control (throwaway e1542d94c4, 26010): imports copy whole and pages drop kept writes;
  both legs fail.
- Release, 2080, examples/managed_sync_out (40 no-copy Managed buffers of 4,399,104 B, 176 MB
  synchronized a command buffer), median GPU ms over 20, base 010888b011 vs tip (25985):
  40/40 written 95.62 -> 95.58; 4/40 written 95.10 -> 9.57; 0/40 written 95.05 -> 0.014.
Not measured: Background Blur itself (the counters say how much of its 0.90 s goes); lavapipe
(unified memory, the copy-out legs return early).

RUNTIME_VERSION 2230 -> 2231.
2026-11-13 10:34:23 -08:00
Anees Iqbal 769410c51a pass_costs: fresh primaries per pass, untrimmed and trimmed, and --begins
Two shapes allocate each pass's primary and free it once its frame
completed: per-pass-fresh leaves the pool untrimmed (Mesa's common pool
recycles a freed command buffer), per-pass-fresh-trimmed trims it, so each
allocation makes a new command buffer with no command stream memory yet.
--begins times each vkBeginCommandBuffer and each instance's begin alone.
They test whether a fresh primary's command stream memory is the walk's
6.8 us vkCmdBeginRenderPass, which the reused primaries do not show.

Verified: cargo fmt; the build and the run are the next potluck job.
2026-11-13 07:42:58 -08:00
Anees Iqbal 4018fe2122 pass_costs: print whether the attachment is cleared (ash's load op has no Debug here) 2026-11-13 02:57:06 -08:00
Anees Iqbal 933d0030b0 pass_costs: --extent W,H and --clear, the attachment's size and load
The walk's vkCmdBeginRenderPass took about 6.8 us each (profile), the
bench's 1024x1024 loaded instance well under 1 us: the extent and a clear
load are the first two of the walk's passes' differences to measure.
2026-11-13 02:57:06 -08:00
Anees Iqbal 1f7c3be6e9 pass_costs: the primaries' shapes without a shared prefix, as clippy asks
clippy's enum_variant_names on Buffers (lint3 job m3-max-25117, its only
error under all three configurations; rustdoc and the API tables green).
2026-11-13 02:57:06 -08:00
Anees Iqbal b6534e8fe8 pass_costs: what a render pass instance costs the driver's CPU, by how it is recorded
A bench of its own Vulkan 1.3 device, no runtime: 150 passes a frame of
one draw each, 6 to a vkQueueSubmit (the walk's averages), recorded as
the runtime records them (a primary per pass, its 17 dynamic states set,
a VkFramebuffer made per pass for vkCmdBeginRenderPass) and as the
alternatives: a primary per submission, a framebuffer kept, dynamic
rendering. It prints each shape's CPU time a pass to record, submit and
reclaim, and the differences between shapes that differ in one thing:
the costs of the structural items in one run on one device.

Verified: cargo fmt only so far; built and run in the 780M job.
2026-11-13 02:57:06 -08:00
Anees Iqbal b37489e9e2 draw_costs: --worker, render lowering on the device's lowering thread 2026-11-13 02:57:06 -08:00
Anees Iqbal 312b1b2d78 draw_costs: --states N, the small passes' plain states 2026-11-13 02:57:05 -08:00
Anees Iqbal 3beb899549 draw_costs: the small passes rotate over six plain states, so a pass's first draw takes every step 2026-11-13 02:57:05 -08:00
Anees Iqbal 5373c76697 draw_costs: a window server's small passes (pass1, pass17) 2026-11-13 02:57:05 -08:00
Anees Iqbal 5039015420 An import several no-copy buffers over the same bytes lie in stays releasable
A no-copy buffer made over exactly the bytes a live one covers lies in that
buffer's import (host_aliases.rs, "One memory, one import"). Until now its
making read the import apart (ReadApart::SecondBuffer), which keeps a
releasable import imported for good. Such a buffer reads the import the way
the first one does, through the import: its blits take the import's objects,
imported again where released, and any other read of it exposes the import
just as a read of the first buffer would. So the import now stays releasable
while every read of each buffer in it was a blit's, or there was none. A
buffer that is never read, made only to keep the bytes imported, keeps the
import no more than a buffer read only by blits does.

Why: on the RX 7900 XTX (RADV), a guest's 3D benchmark kept 1,000 to 1,330
dma-buf imports live. RADV lists every one of them in every kernel submission,
at 0.43 to 0.44 us each (docs/FAST-PATHS.md, known gaps). Of those imports,
1,262 were held for good, and every held one had a second buffer lying in it.
The consumer keeps a holder for each view of guest pages: a no-copy buffer
over the whole view that nothing reads, with the block's buffer lying in its
import. The frames named about 0.6 imports per command buffer, while the
scheduler thread spent 0.63 to 0.90 s of each second in vkQueueSubmit, at
0.835 ms per call. Our own blocks on that device are plain VRAM, which RADV
makes local and lists in no submission.

What still keeps such an import imported for good:
- a no-copy heap's own bytes lying in it: the heap's placed buffers'
  addresses are the heap's, handed out without any read of the import noted;
- a rebound buffer lying in it, as a rebind's own import is kept;
- a buffer bound inside its memory with a VkBuffer of its own;
- a buffer made to share its buffer's range (BufferDescriptor::range_of),
  which is handed that buffer's address.

Counters: the gauge host_imports_read_apart_second_buffer is split into
host_imports_read_apart_inside, _shared_range, _heap and _rebound. The new
host_imports_joined_releasable counts the buffers that came to lie in a
releasable import beside another and left it releasable; a walk shows the
path ran when it is non-zero. host_residency.rs ("Several buffers in one
import"), host_aliases.rs, the WorkCounts docs, docs/HOWTO.md and the API
signature table say so.

Test: tests::host_residency::an_import_two_buffers_lie_in_is_released_while_idle_and_read_right_again.
It makes a never-read holder and a second buffer over the same 4 pages of a
udmabuf-backed memfd. Joining keeps the import releasable (nothing held for
good, no read apart) and imports nothing new. Read by a blit, the import is
released. The file's writes made while it is released are read by the next
blit through the second buffer, imported again from the kept descriptors. It
is released again. Then a kernel binds the second buffer, makes the holder
resident (useResource:, as Metal reaches a no-copy buffer through an address
only once a command buffer used it) and loads the holder's Metal address from
set_bytes; the binding imports the import again for good. The words the kernel
reads through the address, and the words it writes through it, are checked
against the pages. The source is called once, and the import leaves the gauges
once its buffers go.
host_import_counts now expects a second buffer over the same bytes to read
nothing apart.

Verified (the runtime's debug test binary, --cfg m2v_gpu, not a release build):
- m3-max-23710 (msi-laptop): cargo clippy --workspace --all-targets
  --all-features -D warnings, the runtime's clippy under --cfg m2v_gpu, and
  the runtime's rustdoc with -D warnings: clean.
- m3-max-23713 (msi-laptop): the API signature tests, 16 passed; the
  runtime's suite, 1502 passed, 6 skipped; on lavapipe (--cfg m2v_cpu_icd)
  the host_import_counts, host_residency, pointer_residency and host_aliases
  tests, 39 passed.
- m3-max-23761 (Radeon 780M, RADV PHOENIX): the host_residency and
  host_import_counts device tests, 15 passed, the new test among them ("1
  chunks of two buffers released twice, imported again twice"). The negative
  control, the same binary with a joining buffer reading the import apart as
  before, fails the new test at "the second buffer kept the import for good"
  (held for good 1, expected 0).
The lint and suite jobs ran one commit before the test's last change (the
holder made resident before the kernel reads through its address), a
test-only change that the 780M run's binary carries.
2026-11-12 18:52:11 -08:00
Anees Iqbal dc859fee56 Residency: host_imports_resident counts releasable imports alone; host_imports_held_for_good the rest
What: an import a read other than a blit's keeps for good (Residency::held_for_good) leaves the
host_imports_resident gauge and joins a new gauge, host_imports_held_for_good, as it already left
the device's count against its most (Shared::resident). Every move of an import's memory (a
release, an import again, let_go, the drop) now goes through one place, Residency::holds_memory,
which counts it as releasable or as kept for good, by the flag under the state lock, as the most
was counted. WorkCounts docs, host_residency.rs's Counted list and HOWTO.md say so; the API table
and host_ab's list name the new field.

Why: host_imports_resident's doc said 'the imports the device may release', but it went down only
at a release, a let_go or a drop, so it also counted every import kept for good. A guest walk on the
RX 7900 XTX showed about 1,040 'resident' beside a cap of 64 releasable imports, which read as the
cap failing. The two gauges show both numbers without subtracting.

Verified: the dma-buf and pointer residency tests now check the exposure step moves the import from
one gauge to the other, and that a gone import leaves both (job ids in the report).
2026-11-12 16:15:25 -08:00
Anees Iqbal c6fa636665 Hold large pipeline makings to one large compile at a time
A guest's run on RADV made kernels of up to 4.5 M SPIR-V words several at
once; on the Radeon 780M one such making alone peaks at 3.6 to 10.3 GiB
resident (1.9 to 4.5 M words). Nothing bounded how many large modules the
driver compiled at once beside the budget's turns, which count makings and
not their size.

The process now keeps a limit of SPIR-V words in flight
(pipeline/compile_memory.rs): a making whose stages hold 65,536 words or
more holds its words around its driver call, the counted makings in
flight holding at most 4,194,304 words, a larger one alone. One that does
not fit waits for those in flight, lending its turn (budget::without_turn)
and taking one again after; the waiters go in their turns' rank order and
none passes one waiting before it, so a large making never starves. The
compute making (objects.rs) holds its kernel's words, a whole render
pipeline its stages', a pipeline library its own part's. Each module
carries its words. WorkCounts counts the makings that waited
(makings_held_for_compile_memory) and their wait
(compile_memory_held_nanos); the conformance cost half reads the count
with the other making counts.

Unit tests: a making below the floor is not held; two that do not fit
never hold at once; no counted making passes a waiting one, waiters going
in rank order; a waiter lends its turn and takes it again.
2026-11-12 15:37:20 -08:00
Anees Iqbal 70d85cd94f draw_costs: the scene's materials sample textures of three sizes, each with its levels
A 3D engine's materials bind textures of other sizes and level counts, which
their bind states' shapes tell apart (TextureShape's level count) though their
plans do not (BindShape::for_plan). Material m's textures are now 64x64, 32x32
or 16x16 as m goes, each with its whole mipmap chain, so a material change
reshapes the bind state as such a frame's do.
2026-11-12 10:42:42 -08:00
Anees Iqbal b8e1a678ec draw_costs: scene and rebinds, a 3D engine's passes over four color targets
Two shapes of a 3D engine's frame as a layer over another graphics API
issues it: 8 command buffers of 10 passes of 24 indexed draws over the same
four color targets, each draw at its own slots of a transform and a material
scale (buffer offsets moved), drawing one of 64 pieces of a mesh read
through a vertex descriptor. Every 4 draws a material of 6 binds its pipeline
state, 8 fragment textures and 8 samplers. In rebinds, each draw binds its
material's textures and samplers again, the same objects within a run.

The functions are draw_costs_scene_vertex and draw_costs_scene in
draw_costs.metal. Steps gain Begin (a pass of a descriptor), the two offset
setters and the texture and sampler range setters, each tallied by --calls.
2026-11-12 10:42:41 -08:00
Anees Iqbal c8d8a2063d An A8Unorm texture over a buffer that only reads takes R8Unorm's linear image, read through (0, 0, 0, R)
Where the device reports A8_UNORM's linear tiling without what its optimal
tiling has for the texture's usage, and R8_UNORM's linear tiling with all of
it (vkGetPhysicalDeviceFormatProperties2's linearTilingFeatures and
optimalTilingFeatures, read through linear_plan::linear_lack), an A8Unorm
texture over a buffer's bytes that only reads (no RenderTarget, ShaderWrite,
ShaderAtomic or BlockWritesOnly usage; one level, one sample; its alpha not
read as one, not rotated) is made as an R8Unorm texture's storage over the
same bytes: the image in place over host pages, an image aliasing the
buffer's memory, or that texture's shadow where it would be one. Its record
reads the image as R8Unorm through the swizzle metal::format::swizzle_over
composes ((Zero, Zero, Zero, Red) composed with the texture's own), as an
A8Unorm view of an R8Unorm texture is read (ViewRecord::read_as): the same
byte, the same filter, the channels moved by the view's component mapping.

NVIDIA's linear A8_UNORM has no sampling, linear filtering or transfer
features (the consumer's RTX 2080 walk kept 195 glyph-sized A8Unorm textures
over Shared buffers as shadows): those are now in place where an R8Unorm
texture's image is. A texture that renders or is written keeps the A8_UNORM
route. Buffer::texture_placement answers the same route.

Counted: WorkCounts::alpha_textures_held_in_red (api_signatures.tsv
regenerated). a8_over_buffers asserts no shadow and the device's own
A8Unorm texture's reads; device runs pending.
2026-11-12 08:57:12 -08:00
Anees Iqbal c539698eb0 draw_costs: count each draw's L1 data read misses and cache misses on Linux
What a draw's memory touches cost the encoding thread, which its instructions do not show: the
thread's user-space PERF_COUNT_HW_CACHE L1D read misses and PERF_COUNT_HW_CACHE_MISSES (the L2 on
Zen, the last-level cache on Intel), opened beside its instructions and cycles and printed as
DRAW-COST l1d_read_misses and cache_misses a draw. Built and run in the next step's jobs.
2026-11-12 06:16:28 -08:00
Anees Iqbal 4b3eb3b253 draw_costs: the compositor's plan walks its passes' sizes, as clippy asks 2026-11-12 01:55:19 -08:00
Anees Iqbal 2a485c9b9e A shadow made before its verdict moves in place with its usage shadow of the bytes
A texture over host pages (or the device's pooled memory) made before its
class's in-place verdict is a shadow that moves in place at a quiet commit
once the verdict passes. The move was refused for good where a binding or a
pass had taken a usage shadow of the texture. In a compositor's frame, a
draw that reads its own pass's color attachment at its own pixel (an
attached read) takes that usage shadow in the first command buffer. So
every target made before the verdict stayed a shadow for the process's
life. Over host pages, each command buffer then copied back every texel
that its passes wrote: on the Radeon 780M, the whole 3840x2400
framebuffer, 9.2M texels a command buffer, in reims's first session.

A usage shadow of a texture over a buffer holds the buffer's bytes as its
truth (ShadowSource::Bytes). An image in place over those bytes is the
same truth, and an aliasing image's uses are uses of those bytes. So such
a usage shadow serves the moved texture exactly as it serves one made in
place. Now only a render shadow, or a usage shadow of another truth, keeps
the texture a shadow (ShadowCopies::copies_bytes).

draw_costs' compositor shape now settles the in-place check after making
its surfaces. A run with a fresh shader cache then measures a first
session after its verdict.

Test: runtime_lane::in_place_textures::a_texture_an_attached_read_copied_before_its_verdict_moves_in_place_too.
2026-11-12 01:55:19 -08:00
Anees Iqbal 27bca2eeab draw_costs: a pass step's arm answers as the other steps' do 2026-11-12 01:55:19 -08:00
Anees Iqbal e74e1b70d9 draw_costs: the consumer's compositor frame as a shape, shadow lines on stderr
The consumer's per-draw table on the Radeon 780M measures a window compositor's command
buffer: five passes that load a layer's surface and draw 4 quads each, then a pass that clears
a 3840x2400 framebuffer surface and draws 15, every surface a texture over its own buffer's
IOSurface plane. Its draws cost about 12 us each and its pass ends about 39 us on that host,
against draw_costs's 1.9 us: its surfaces are shadows. draw_costs had no shape of it.

- compositor: 8 command buffers of that frame (6 passes, 35 draws, 21 indexed), each pass
  opened with set_viewport, each draw setting a pipeline state where its kind changes (plain,
  masked, backdrop; blended), two vertex buffers and a fragment buffer at moving slots of one
  no-copy buffer over host pages, one or two fragment textures (a backdrop draw reads its own
  pass's color attachment at the fragment's pixel), a sampler and a scissor rectangle. Surfaces
  over Private buffers, or with --pages over host pages.
- Steps: a Pass step opens a compositor pass (a command buffer of other steps opens the
  bench's one pass as before); fragment textures take an index; indexed draws; the calls
  set_viewport and draw_indexed_primitives counted apart with --calls.
- With METAL2VULKAN_LOG_SHADOWS=1 the sink prints the shadow log's lines and each degrade
  notice's text on stderr.
- draw_costs.metal: the compositor's quad functions, written for this example.

Verified: the build and the 780M run follow in the next jobs (the metallib is compiled on the
M3 Max).
2026-11-12 01:55:19 -08:00
Anees Iqbal 99c40c6e28 draw_costs: a damage shape and a shadowed, loaded target
A guest's compositor pass loads its window surface, a texture over guest pages, and draws
inside damaged rectangles, so the pass's end plans a shadow's copy back and counts its tiles
against its draws' scissor rectangles (count_colors, DrawnArea::covered_tiles). draw_costs
had neither: its target is a cleared Private texture and its clips shape takes two
rectangles.

- damage: as clips, each draw after a scissor rectangle of its own, the next cell of a
  25 x 20 grid of 20x25 pixels (500 rectangles a pass).
- --shadowed: the target is a texture over a no-copy buffer of host pages at its packed
  rows, loaded, the device opened with HostPageTexturePolicy::Shadow so it is a shadow on
  every device.
- The host-page mapping is one helper (host_pages) for the chunks and the target.

Verified: built in the next commit's job; the before/after numbers are in its message.
2026-11-12 01:55:19 -08:00
Anees Iqbal 948a1f24f1 Count batches that waited for other queues' first work their commands and own first work reach none of
Each batch that did new resources' first work (images' moves, staged copies into them, fills at its start) is now kept until it completed with what owns the memory that work wrote: the owner under the image's key, the staged copy's image key or the fill's key (used_resources::owner_of), learned at the take on every device (FillTake::Owned where the device has no fill queue). WorkCounts::first_work_waits and first_work_waits_unused count the batches that waited for such work, and those whose commands and own first work reach none of it. Every batch still waits for all of it; the narrowing follows. tests::fill_waits gains a_batch_that_reaches_no_new_texture_waits_for_none_of_its_first_work (fails on unused until the narrowing), and the zero-reach test's textures are moved behind a long run of kernels on another queue.
2026-11-12 01:11:14 -08:00
Anees Iqbal 523de4d0c2 queue_plan_cost: the overlap phase function's doc wrapped too
Verified: text only; no line of the example past 100 columns.
2026-11-12 01:06:14 -08:00
Anees Iqbal 837d2c883b queue_plan_cost: the overlap phase's doc wrapped at 100 columns
Verified: text only; no line of the file past 100 columns.
2026-11-12 01:06:14 -08:00
Anees Iqbal c5379296b8 queue_plan_cost: wrap the overlap phase's doc line
Verified: text only.
2026-11-12 01:06:14 -08:00
Anees Iqbal b7f7719957 Runtime docs: why a refused device takes its least plan at once, measured against stepping down
made_within_resources now says why it takes the least plan at once rather than plans between: on a
GPU out of channels, what one refused device takes the next is refused. Measured with
queue_plan_cost --runtime-fill (one runtime device per process) at RUNTIME_VERSION 2084 against a
step-down branch (steelbrain/queuestep a595a24225: round robin halved on each refusal, 18 then
11, 7 and 3 VkQueues):
- RTX 2080 (Thunderbolt, 620.70.06): least at once 11 plan + 3 least devices, the 15th refused
  (m3-max-19615); stepping down 11 plan + one of 11, the 13th refused (19616).
- RTX 3090 (620.70.06): 58 plan + the 59th least either way; stepping down added 0.42 s to the
  59th (1111 vs 688 ms) and 0.21 s to the refused 60th (612 vs 398 ms) (19620, 19622).
- Refused vkCreateDevice of 7 to 15 VkQueues beside 12 runtime devices on the RTX 2080: 237 to
  270 ms each (19639, --runtime-rooms).
The example's overlap phase docs no longer speak of steps.

Verified: cargo fmt; the numbers are the jobs named.
2026-11-12 01:06:13 -08:00
Anees Iqbal c6c9e8f4be queue_plan_cost: the overlap phase, K processes making a device of each step's shape at once
For the plan's shape and each step a refused device takes (16+2, 9+2, 5+2, 1+2 on NVIDIA), K
processes make one device each at the same moment: each vkCreateDevice's time and the time until
all K were made, as when every device of a GPU is made again at once after a device loss. Asked
for by the orchestrator alongside the step-down measurements.

Verified: cargo fmt; built and run in the next jobs.
2026-11-12 01:06:13 -08:00
Anees Iqbal 66ac110484 queue_plan_cost: runtime rooms, and a runtime fill of distinct devices
Device::system_default_with returns the live device of equal options, so the runtime fill child
made one device per process and held five more handles of it (job m3-max-19562, on the RTX 2080:
0 ms for each after the first). Each device of a child now takes a shader cache directory of its
own. The runtime rooms phase holds N runtime devices and probes which bare queue counts the driver
still makes beside them: on the RTX 2080 a runtime device holds more than a bare device of its
queues (66 bare devices of 3 queues left room for 18; the 12th runtime device was refused 18).

Verified: cargo fmt; built and run in the next jobs.
2026-11-12 01:06:13 -08:00
Anees Iqbal 26230d0382 queue_plan_cost: rooms and runtime fill phases
The rooms phase holds K devices of the plan's shape and N of the least
plan's, then asks for a device of every graphics-family count from the
plan's down to one, timing each vkCreateDevice: which queue counts the
driver accepts beside what is held, and what a refusal costs. The
runtime fill phase fills the GPU with the runtime's own devices, each
printing its make time and the VkQueues it took. Both measure the step
down from a refused queue plan; neither runs unless asked.

Verified: cargo fmt; built in the next job.
2026-11-12 01:06:13 -08:00
Anees Iqbal 456177d8fe Count batches that waited on the GPU for fill-queue fills they reach none of
Every batch and internal submission waits on the GPU for the fill queue's last submission until
the host saw it complete (device/staging.rs), and a batch takes every fill waiting, whichever
buffers its commands name. Neither is counted: nothing says how often a batch waits for fills its
commands never use.

What: each fill notes what owns the memory it writes (Filled::owner: the program's buffer, kept
by its key among the device's owners, or the heap a buffer is placed in or whose own buffer it is;
None for the runtime's own buffers), each fill-queue submission keeps them until the host saw it
complete, and a batch that waited on the GPU for its own fills or another's is counted
(WorkCounts::fill_queue_waits), and counted again where its commands reach none of that memory:
no resource its encoders' uses name owns it and none of its commands may reach memory no use names
(WorkCounts::fill_queue_waits_unused, State::parts_reach). No wait changes here.

Tests: fill_waits (a compositor's batches beside an app that makes a new buffer each round, and
new memory read by name, through a loaded pointer and as a heap's texture) and the release bench
fill_waits_bench. fill_waits' count assertion fails on a device with a fill queue until the next
commit narrows the waits: it is the negative control.

Verified: cargo fmt; api_signatures.tsv blessed. Builds and device runs follow as potluck jobs.
2026-11-12 00:52:54 -08:00
Anees Iqbal 915222c8e5 Example queue_plan_cost: a fill phase, the runtime's device made where the plan's VkQueues just fit
--fills N,M,... holds that many devices of the least plan's shape, then
makes the runtime's device beside them: what device making answers
where the plan's vkCreateDevice still fits but little more does. To
find which step of device making answered OutOfMemory(Host) on an RTX
2080 under parallel test load, where a GPU filled to the refusal gives
ERROR_INITIALIZATION_FAILED and the runtime's least plan (job
m3-max-18924).
2026-11-11 21:51:23 -08:00
Anees Iqbal 65c06e2e4c Example queue_plan_cost: each refusal's VkResult, and the runtime's device made while the GPU is full
The exhaust phase now names the VkResult each refusing process got, and
while the processes hold their devices makes one more process's runtime
device of the plan: whether it came up (on its least plan, announced) or
what it answered. --exhaust-only skips the make and hold phases. Asked
for by a device test that got OutOfMemory(Host) from
Device::system_default_with on an RTX 2080 under parallel test load.
2026-11-11 21:51:22 -08:00
Anees Iqbal fa57e96133 Example queue_share: a churn mode, command queues made and dropped as a guest's processes make them
A compositor (unshared with --unshared) committing a draw every 16 ms beside three kept
queues and a churn of queues each made with one long command buffer and dropped 1 to 8
ticks later; --untimed answers GPU times from the host, as a consumer that does so does
not share VkQueues. Prints the compositor's latencies and the device's waits behind
other queues, the measure of the placement change that follows.

Not yet run.
2026-11-11 21:51:22 -08:00
Anees Iqbal 7f762845c3 Example queue_plan_cost: options set field by field (DeviceOptions is non-exhaustive) 2026-11-11 21:51:21 -08:00
Anees Iqbal 07d9391c99 Example: what a device's VkQueues cost the driver to make, drop and hold
A probe for the NVIDIA queue plan's cost: Vulkan devices of 1 to 18 queues made and
destroyed in turn (vkCreateDevice and vkDestroyDevice wall times, slope per queue), held
four at once with nvidia-smi's framebuffer and BAR1 use, the runtime's own device under
each queue limit, and an opt-in exhaust across processes (how many devices of the plan's
and the least plan's shape the GPU holds at once).

Not yet run; numbers follow from potluck jobs.
2026-11-11 21:51:21 -08:00
Anees Iqbal 1badfbfffc Keep-alives: a buffer bound inside an import holds it; count those releases, test them on every device
Since RV 2073 (cfd7bc829e, one page one import) a no-copy buffer made over part of a live one's
bytes, or over the same bytes as memory of another class, is bound inside the live one's import
(Device::bind_in_import, Placement::in_import holding the import) instead of importing the pages
a second time. It holds that import until it goes, so the first buffer's release is outlived: its
keep-alive is kept by the import, or, given none, its deallocator waits for the free. That is the
order the single import needs (it maps the pages the first buffer's keep-alive keeps), but the two
lane tests still expected the second buffer to be an import of its own: on the M3, where the
texture's image is a shadow, each waited 60 s for a keep-alive that goes only once the second
buffer goes (m3-max-18537, bisected: 269d7066c4 passes in m3-max-18841, 4f3bc2e7a3 fails in
m3-max-18861).

- HostImport counts the buffers bound inside it (Inside, one per buffer however many clones of its
  placement share it). A release that keeps a keep-alive, or delays a deallocator, while one lives
  is counted: WorkCounts::host_releases_held_inside (new). The delayed deallocator's announcement
  names that cause instead of a texture's command buffer.
- keep_alives.rs: a_kept_keep_alive_covers_later_buffers_over_its_bytes and
  a_narrower_live_buffer_covers_no_wider_released_one branch on whether the second buffer lies
  inside (object_churn.buffers_bound_in_import), watch the kept keep-alive stay, and show both
  keep-alives go once the second buffer is released, printing the counts at each step;
  a_buffer_inside_an_import_holds_a_deallocator_given_no_keep_alive (new) shows the deallocator
  given no keep-alive runs after the inside buffer's release, counted and announced once.
- host_ab prints the new count; api_signatures blessed for the field.

(The commit before this one names its test wrongly: the race rule's rows are held by
a_count_that_says_which_thread_arrived_first_is_never_gated.)
2026-11-11 21:51:08 -08:00
Anees Iqbal 73d706151e host_ab: hold a call's driver makings as its own thread's, with blocks it waited for
The per-call gate failed on the M3 Max once (buffer_texture_256: 0.0625 memory
allocations a call, held to 0). The allocation was a 64 MiB block of the images'
pool made ahead on the device's ready thread: texture_1024_target's first
creation call found its pool short (room 62.9 MB of a 64 MiB block, the pool
grown 1.1 s before) and asked for one; its making waited for a pause in the
queue uses (up to 50 ms) and landed in the next group's windows. No call waited
for it. The process-wide counts the gate read took it whenever it fell inside an
at-call window, so the row failed by timing alone.

ObjectChurn now also counts each driver making for the thread that made it, and
a pooled block made ahead for the thread of the call that waited for it (the
ready thread records what the block's making made; add_ready counts it on the
taking thread where the making was waited for). host_ab reads these and HELD
holds the `_this_thread` at-call counts; the process counts stay printed.

Tests: churn_counts::a_thread_s_makings_are_its_own_and_those_it_waited_for
(unit); blocks_ahead's growth test checks the blocks made ahead are not the
calling thread's, and the hurried test that the call that waited for its block
counts the block's memory as its own.
2026-11-11 20:19:15 -08:00
Anees Iqbal 8c0aeddfd5 Runtime: a batch's new buffers' fills go to the fill queue, a copy engine's second queue
On a device with a family of transfers alone that has a second queue (NVIDIA's copy engine), a
batch's buffers' fills (zeros, staged bytes, Managed buffers' copies in) are recorded in a
submission of their own on that queue, which waits for the batches before it on the batch's
VkQueue, what the batch waits for and what completed, and which the batch waits for. Every other
submission waits for the fill queue's last until the host saw it complete, as for the staging
queue. Buffers are already concurrent with that family (sharing.rs), so no ownership transfer.

Not yet built: a build and the device tests follow.
2026-11-11 19:08:57 -08:00
Anees Iqbal 3649b494dc Example copy_engine: print queue, memory and driver values raw (ash builds without Debug here) 2026-11-11 19:08:56 -08:00
Anees Iqbal 9c463dd892 Example copy_engine: host-device copies on the graphics queue and on a copy engine
A measurement of its own Vulkan device (no runtime): copies between host-visible memory and an
optimal image or a device buffer, 64 KiB to 256 MiB each way, on the graphics family's first
queue and on the first queue of a family of transfers alone (else another compute family), alone
and beside a compute load on the graphics family's second queue; and a copy the next dispatch
waits for, in one submission or across a timeline semaphore. Each phase prints its host time
span so nvidia-smi dmon samples can be placed in it.

Not yet built: the first build is a potluck job.
2026-11-11 19:08:56 -08:00
Anees Iqbal d76f7f7ee7 One page, one import: no run of a guest RAM chunk imported alone by its pointer
An object over a chunk not imported yet, and a copy over one, was bound in
an import of its own run alone, made by the run's host pointer while the
device's thread imported the whole chunk by its pointer: two live imports
of the same host addresses, the run's freed while the chunk's lived.
VK_EXT_external_memory_host leaves the same host allocation imported twice
undefined (issue 6). Runs are now imported alone only on a listed plan,
whose chunks and runs are dma-bufs of the RAM's source, and a run's import
never falls back to its pointer. Elsewhere every object and copy over a
chunk lies in its one import, made or waited for, as on MoltenVK and ANV.
The price is a making that waits for a chunk the window has not reached.

imports_inside_live now counts every import made over host addresses a
live import holds: a no-copy object's own import over another's (heaps
included) or over a live chunk import at the same addresses, and a
chunk's import over a live no-copy import, on the making and rebind
paths. A new evidence counter, imports_over_ram_chunk_pages, counts a
view's own import whose guest RAM pages a live chunk import holds at the
RAM's addresses. host_ab prints both and buffers_bound_in_import.

Not yet verified: built and tested next on lavapipe.
2026-11-11 19:01:50 -08:00
Anees Iqbal a57253e172 Tests: private_bandwidth times a Managed no-copy pair over read-only pages
A Managed no-copy buffer over pages the process maps read-only, whose import
the gate refuses, is two copies whose GPU writes are dropped: each command
buffer's completion copies the pages in whole again (managed_copy.rs). The
over-copy sequence gains such a pair, its check expecting the pages' zeros,
so its per-pass cost and WorkCounts (managed_write_undone,
managed_bytes_copied_in) can be read next to a consumer's.

The 2080 run of the over-copy sequence (m3-max-17175) already showed a
Managed no-copy pair over a copied Shared buffer's bytes as DeviceCopy at
403.6 GB/s, the speed of a plain Managed no-copy pair.
2026-11-11 13:20:45 -08:00
Anees Iqbal 3d3d3c1bc6 Tests: a Managed no-copy buffer over a copied Shared buffer's bytes, timed and checked for its two copies
The private_bandwidth example gains an over-copy sequence: a Managed no-copy
pair, each over exactly the bytes of a live Shared no-copy buffer whose
import a refusing gate made a copy, beside a plain Managed no-copy pair and a
Shared pair over a copy's bytes. Each BANDWIDTH line names the first buffer's
host backing.

managed_copy_device gains the same shape as a device test, through an import
and over pages no import maps: the Managed buffer is two copies (its device
copy in device-local memory), lies in no copy, and reads the pages' bytes.

Not run yet: the device test needs a discrete GPU.
2026-11-11 13:20:45 -08:00
Anees Iqbal 02cf25a3f6 Example: private_bandwidth idles 3 s before each pair, runs two rounds back to back, and stamps each pass
So a clock trace taken beside it lines up with each command buffer, and a
slow first round after an idle tells itself apart from a slow pair.
2026-11-11 13:20:45 -08:00
Anees Iqbal c943d6829c Example: private_bandwidth adds the guest's order, Managed pairs with no-copy CPU copies beside them and pauses
As a guest's Metal buffers come: Shared ones over its pages, Managed ones made
with a Shared no-copy buffer over pages beside each, then Private ones at
pinned addresses, three seconds waited between a pair's release and the next
making. The counts each pair's first timed pass and its last moved are
printed.
2026-11-11 13:20:44 -08:00
Anees Iqbal 9ad61b0fa6 Example: private_bandwidth prints the counts the last pass moved, and the guest-order Private pairs take plain options 2026-11-11 13:20:44 -08:00