On NVIDIA's drivers a linear image takes no feedback-loop or input-attachment usage, so a draw
that read such a color at its own pixels after a memory barrier split the pass and copied the
texture's scissor box (the whole surface for a guest that sets no scissor) before the new
instance: in a consumer's autoscroll on an RTX 2080 about 21 readers a present each copied a
3648x2038 surface, ~29 ms of a 45 ms take-to-show.
Such a reader now splits the pass with no copy: its snapshot draws record in an instance of
their own ahead of the reader's (LOAD/STORE_NONE, empty masks), a "leading snapshot". The device
enables VK_KHR_load_store_op_none, else VK_EXT_load_store_op_none, below Vulkan 1.3 (the
runtime's instance is 1.2, so STORE_OP_NONE was core on no device); the version comes from the
device's properties.
A leading snapshot reads the texture at every pixel its draw covers, so over host pages it is
not cheaper than the split at every area: on an RTX 5080 Laptop GPU (split_parts, 8 readers a
frame over a 2648x1658 surface over host pages) whole-surface readers took 22.98 ms a frame
leading against 17.99 split, quarter-surface readers 6.06 against 8.55; the forms cross near
half. weigh_snapshot takes whether the reader leads and skips over_bytes for it, so the area
rule weighs its first pass and, where the device measures readers (occlusionQueryPrecise),
learned coverage decides from the second: a reader keeps the leading form within the existing
bound (SNAPSHOT_PIXEL_COST 20: 20% of a 4-byte color) and splits above it. A rebound kept reader
weighs with the same flag. New WorkCounts: reading_draws_snapshotted_leading,
reading_draws_leading_covered_within / _to_half / _over_half (where the guest's readers fall
against the bound). docs/FAST-PATHS.md's row records the 5080 A/B.
Also: the split_parts lane (ignored by default, run by name) measures what split readers cost and
reads its fixtures from the crate directory the runner names.
From steelbrain/nvscroll (81915c28de..3cdbfe9256, 11 commits). Verified on potluck at 3cdbfe9256:
clippy gpu (28377), cpu_icd and plain (28379) 0; rustdoc -D warnings 0; api_signatures and
api_surface 15/15; lavapipe 478/478 (copy form unchanged there). 5080 A/B nvscroll-ab-233300
(kind t). The tip's 5080 device test and lane (b5080 batch 28393) are pending; the 2080 and XTX
runs wait for um790.
A consumer's game on the RX 7900 XTX (RADV, one graphics VkQueue) ran a frame of two command
buffers (about 9.5 ms and 0.3 ms of GPU time, two frames in flight) at 22 ms a frame against
9.9 ms of GPU time, its batches held 5.5 ms a frame for the compositor's unshared queue
(WorkCounts::batch_hold_nanos, heads_held_for_unshared_isolation). This mode runs that shape
on the runtime alone: the frame period, GPU time and GPU idle share, each command buffer's
commit to kernel start, the GPU gap before each frame, the completion's lateness, and the
device's hold and scheduler counts a frame, under either UnsharedIsolationPolicy, with the
compositor's queue committing nothing or a draw every --period-ms.
Verified: cargo fmt; built and run on the XTX in the following jobs.
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.
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.
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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).
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.
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.
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.
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.
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.
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.
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.
--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).
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.
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.
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.
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.)
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.
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.
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.
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.
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.
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.