A guest's window server makes dozens of textures over each of its large Private surfaces
(BGRA8Unorm and R32Uint, shader read and write, 6016x6016 at 24,576-byte rows) and writes and
reads a few each frame; past the pooled bound each texture is a LinearCost shadow of its own.
aliased_surface_costs (ignored, release) measures the guest's surface with 36 live textures and
with four made each frame: forms, shadows made, a frame's GPU time, shadow copies and texels
copied, and peak device memory (DRM fdinfo, resident set). Two checks over a small surface past
the bound: four textures over one surface's bytes take one shadow (fails until the fix), and a
kernel's write through each is what every other reads and the bytes hold.
Verified: cargo fmt; builds follow as potluck jobs.
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.
The commits before this one. Two causes made shadows copy an unchanged truth in again at every
command buffer:
1. A usage shadow whose truth is an image (a Private texture bound beyond its usage, a view's
shadow) never stood across command buffers: ShadowCopies::stands_across required
ShadowSource::Bytes, and view_shadow.rs made image shadows with a default StandingAcross. So
each command buffer's first use copied the whole image in.
2. An attached read (a draw sampling the texture its own pass renders): render/shadows.rs gave
the pass's first instance's writes of the attachment no bound, so ShadowSync::after marked the
read's shadow Lost::Written, the command buffer's end left it NotCurrent, and the next frame
copied every texel again, even when the pass drew inside a small scissor.
Now an image truth of a tracked Private (or Memoryless) runtime image whose VkImage was never
handed out may stand across command buffers (ImageTruth, ShadowCopies::stands_across and
only_commands_write; StandingAcross gets an image form, which view_shadow.rs's image_shadow sets).
A standing keeps a stale rectangle across command buffers instead of letting go, and the copy in
covers that rectangle alone. render/shadows.rs bounds the first instance's writes of a loaded
colour by its drawn rectangle. A draw that writes every pixel still copies the whole texture.
The attached read's copy before any barrier stays: in place it would race the pass's own writes
(Vulkan's memory model forbids the data race, and a by-region barrier orders one pixel only), and
with a barrier ordering earlier draws it would read their texels where Metal reads the texels from
before the pass.
Numbers (lavapipe, frames whose texture didn't change; texels copied per frame and mean GPU time):
- Private texture sampled through a 64x64 scissor in the pass that renders it: 2,680,832 -> 4096,
2334 -> 395 us.
- The same read on a surface plane in a Private buffer: 2,680,832 -> 4096, 2073 -> 390 us.
- Private texture sampled beyond its declared usage: 2,680,832 -> 0, 3771 -> 1529 us.
Verified (potluck jobs, on the branch): lavapipe device run (m3-max-18689): 99 of 99 shadow,
attached-read, standing, self-read, snapshot and feedback tests, plus the new ones, including a
self-sampling mip pyramid (each level drawn while sampling the level above, checked per level).
Lint: clippy plain (18657), --cfg m2v_gpu (18699), --cfg m2v_cpu_icd (18700); rustdoc (18658);
api_signatures, api_surface and fast_paths (18659).
Not yet run: the 780M (RADV) device run, which also confirms the copy before a barrier on a device
with the feedback-loop feature.
What: iterate the made levels' bytes with their index instead of indexing MADE by the loop
variable, and read a texel's red through as_chunks, as clippy's needless_range_loop and
chunks_exact_to_as_chunks ask under --cfg m2v_gpu and --cfg m2v_cpu_icd.
Why: clippy -D warnings failed on both device configurations (jobs m3-max-18678, -18679).
Verified: the device-config clippy runs again after this commit.
What: a usage or attached-read shadow whose truth is a tracked Private or Memoryless image the
runtime made in memory of its own (not shareable, its VkImage never handed out) now stands
across command buffers, as a shadow of a Private buffer's bytes already did
(Backing::PrivateImage, StandingAcross::over_image). A standing also keeps the rectangle its
image is stale in when the command buffer ended with it current there alone, and the next
command buffer's gated copy in moves only those texels (Standings::standing,
GatedCopyIn::standing_copy). The first render pass instance of a pass now bounds its loaded
colors' writes by its draws' scissors as later instances did, so a draw that samples the
texture its pass renders leaves that texture's shadow stale inside the drawn rectangle alone.
Why: on the 780M a 2618x1024 texture read through such a shadow was copied in whole once per
frame although its texels changed only every 4th frame: 2,680,832 texels a frame, about
200-370 us of GPU time, for a draw beyond the texture's usage and for one that samples it in
the pass that renders it through a 64x64 scissor. An image truth never stood (stands_across
took bytes alone), and a one-instance pass's attachment writes were never bounded, so the
shadow lost the truth whole. The copy an attached read takes before any barrier stays: read in
place through the feedback loop it would race the pass's own writes, which Vulkan forbids
(attached_reads.rs now names it).
New WorkCounts fields: shadow_texels_first_copied_in_private_images,
shadow_texels_unskipped_stale_within.
Tests: unchanged_truth_copies now asserts that a frame that changed nothing moves no texel the
shadow holds (0 beyond usage, the scissor's 4096 for the small attached read); image_standing
checks the stale-rectangle copy's texels and counts, the let-go after another write, and the
mip chain (clear level 0, render level 1 sampling the whole texture, then level 2, then sample
every level) with and without a usage shadow, its passes apart and in one command buffer. Run on
lavapipe and RADV PHOENIX after this commit (job ids in the report to main).
A device test that counts, frame by frame, the copies in, the texels they
move, those a standing took off and the GPU time of frames that read a
2618x1024 BGRA8Unorm texture through its shadow: a draw sampling the
texture its own pass renders (whole, and through a 64x64 scissor), and a
draw sampling it beyond its declared usage; over a Private texture of its
own and over a surface plane in a Private buffer. The texture changes (a
clear) every 4th frame; each frame checks the texel its draw wrote.
Measurement only so far: it prints UNCHANGED-TRUTH lines.
Verified: cargo fmt only; it runs as a potluck job.
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.
The commit before this one. The M3 per-call gate (host_ab --only percall) failed once at d0f800ddd0
(m3-max-18148): buffer_texture_256 read rt_vk_memory_allocations_at_call 0.0625 a call. It wasn't
the call's: it was a 64 MiB block of the image pool (memory type 0), made on the device's
metal2vulkan-ready thread (memory::ready -> BlockMaker::make). texture_1024_target's first
creation started it: keep_room keeps one whole block of room ahead for KEPT_EMPTY_FOR (10 s) after
a growth, and the pool had grown 1.10 s earlier. The making waits up to QUIET_MOST (50 ms) for the
queue uses to pause, so it lands about 51 ms later, in whichever group's window is open. No call
waited for it (blocks_ahead_waited_for moved in no group's window). The policy is the deliberate
margin from the RX 550 and 780M evidence, and is unchanged.
churn_counts.rs now also keeps a per-thread count of each kind of Vulkan object the runtime makes
(images, buffers, views, memory allocations, image and buffer bindings). memory/ready.rs records
what each block's making made, and when a call waited for that block, add_ready credits it to the
thread that took it. ObjectChurn gains vk_{images_made, buffers_made, image_views_made,
memory_allocations, image_bindings, buffer_bindings}_this_thread. host_ab's HELD now holds the
_this_thread at-call count in the 24 rows that hold a Vulkan making count; the process-wide counts
are still printed. Counts only: no runtime behaviour changes.
Verified (potluck jobs, on the branch at 87246c3b8c, base bb113bd5eb):
- M3, MoltenVK 1.4.2, host_ab --only percall: 30/30 passed (m3-max-18641), plus 5/5 (18624) and
3/3 (18625). Across the 30 runs the process count still landed in buffer_texture_256 at the call
in 3 runs (0.062 a call, the failing reading), at the commit in 18 and in timed windows in 21,
and in sampler (6) and shared_event (2). The this-thread counts read 0 in all of them. Every
group's own makings read the same on both counts (buffer_no_copy_1m 1.0, texture images and
bindings 1.0, commit_no_copy_dispatch 0.125).
- Tests: churn_counts::tests::a_thread_s_makings_are_its_own_and_those_it_waited_for; blocks_ahead's
growth test asserts blocks made ahead don't count on the calling thread; the hurried test asserts
the call that waited for its block counts its memory allocation. lavapipe 190/190 (18643).
- Lint (18615): clippy plain, --cfg m2v_gpu, --cfg m2v_cpu_icd; rustdoc -D warnings;
signatures.py --check.
Not yet run: the 780M and XTX submit_per_surface and RADV runs of churn_counts and blocks_ahead
(18617, 18618 queued).
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.
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.
runtime_lane::pipeline_records::a_later_device_makes_every_pipeline_an_earlier_one_made_from_its_records
failed on every device that links its pipelines from libraries in the round at
d0f800ddd0 (Iris Xe, RTX 3090, RTX 5080 Laptop, RX 7900 XTX, Radeon 780M):
"the points' making wrote its record", 0 saves where it expected 1 (on the 780M,
"the driver reported (1, 2), not (0, 3)" instead). It passed at 892e4b230b.
The change that did it is 5a1e043784 (RUNTIME_VERSION 2068), which made a library
of shaders under its part's record (GraphicsContent::record_parts) in place of its
library name. A part's record leaves out the depth bias, as a whole pipeline's
record already did, and names no topology (the point class is in a whole
pipeline's record alone). The points' pre-rasterization state differs from the
triangles' only in the bias (Metal biases triangles alone), so the points' library
is now made under the triangles' pre-rasterization record, in the cache the
state's creation made. The product lost nothing: every one of those drivers
reported the points' library found in that cache (pipeline_hits 0 -> 1 at the
points' draw, PIPELINE-RECORDS "first device, drawn"). The driver compiled
nothing, so no data was added and no record was written. A later device loads
that record at the state's creation, and its points' library is found there. The
test's expectation of a record of the points' own was stale on these devices.
The test now counts the records the makings name apart from the makings
(Makings::points_own: 1 where pipelines are made whole, 0 where they are linked).
On the first device, the points' makings load nothing and each reads its data:
unchanged, or written again where the driver's data grew (the 780M's RADV wrote
the shared record again, saves 2 -> 3). A making under a record of its own writes
it. The driver reports the shared ones found and the rest compiled. On the second
device, assert_loaded takes the records loaded and the makings from them apart:
the points' library loads nothing and is handed the loaded cache. The record
counts are the creation's plus the points' own. The module docs drop "the driver
reports no hit or miss of a library", which has been false since libraries report
(5cd5f93c9e). record_parts' doc says the points' library shares the record, and
on which drivers it was seen found.
Verification: the pipeline_records lane tests on lavapipe and the Iris Xe at this
tip, in the report to main.
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.
The branch before this commit fixes a host process abort on MoltenVK. texture/recycle.rs keeps a
book of live images keyed by their VkImage handle, so a released image can be parked under its
making and handed to a later texture of the same descriptor. A texture's first image, which its
storage form swaps out, was destroyed with the swapped-out ImageObjects when the switch's command
buffer completed, but it never left the book. MoltenVK's handle is the image object's address, so
a later image often got the same handle. When that image was one the book doesn't hold (a Shared
or Managed texture's host-copy image, or a shadow), its release found the stale entry and parked
it under the old making. The next texture of that making took an image of another format and
size: a BGRA8Unorm render target over an RGBA16Float image. Copies and views between the two then
failed (vkCmdCopyImage between incompatible formats) and Metal's view validation aborted the
process. Now ImageObjects::drop takes the VkImage out of the book before destroying it, which
covers every image destroyed there: a storage form's first image, a storage form image that
never swapped in, and the detach swaps. Every other image in the book leaves it at
Image::release, parked or forgotten.
WorkCounts::object_churn.swapped_out_images_forgotten counts the images ImageObjects::drop takes
out of the book, the entries that went stale before the fix. It is a new field, so object_churn
recordings gain a key wherever a case takes a storage form (re-blessed on development).
Verified:
- The consumer's Dock-restart boots on the M3 (cold 26.6.2 arm64 guests under HVF, MoltenVK
1.4.2, its tree at pin 41): with the fix (566d8170c7), 0 of 5 died (m3-max-18407); at base
269d7066c4, 3 of 3 died (m3-max-18370) with the same assertion (RGBA16F base, RGBA8Unorm or
BGRA8Unorm view). Earlier rates at pin 39: 2/2, 2/3, 2/4, 2/3.
- Before the fix on the M3 (m3-max-18359, 911eacfa3c), the storage-form recycle test FAILED with
the whole chain: storage forms 1, the first image left the book false, its handle given again
true, parked images the next target took 1; MoltenVK gave the handle to a Shared RGBA16F 64x64
host-copy image, which parked under the BGRA8 target's making, and the next target's pass
failed at commit with EncoderAbandoned.
- After it, lavapipe with the Khronos validation layer (m3-max-18441): 61 tests passed (the new
swapped_out_book and texture_holds tests, recycle, first_move, staging, blit_holds,
encoder_holds, self_read_storage); validation errors 0; swapped_out_book: the image left the
book, counted 1, the next target took 0.
- texture_holds (a texture released while its committed command buffer is pending) found no
VUID-vkDestroyImage-image-01000 under the layer.
- Lint: clippy -D warnings on the runtime plain (m3-max-18426), --cfg m2v_gpu (18429) and
--cfg m2v_cpu_icd (18436); rustdoc -D warnings (18437); signatures.py --check.
Not yet run: the post-fix M3 runs of the new tests (18430, and under the layer 18433), and the
negative control (the forget removed, swapped_out_book expected to fail, 18451).
tests/texture_holds.rs commits work a command buffer waits behind (blit_holds'
busy fills), then the command buffer, then releases the texture it uses, and
checks the texture's image is not released (images_own_memory) while the
command buffer is still pending; under a validation layer, that no
VUID-vkDestroyImage-image-01000 is reported. Legs: a Private RGBA16Float
render target with mipmaps that a blit copies a buffer into and generates the
mipmaps of, and a render pass clears; a Shared RGBA16Float texture a
replace_region wrote, read back by a blit, whose bytes it checks; new Private
render targets released at once, whose zeros may still be queued.
The consumer's validation boot on the M3 stopped at VUID-01000 under a
texture's Image::drop; these legs are the Private and host-call shapes asked
about.
Verified: see the landing report's job ids (lavapipe under the Khronos layer,
and the M3).
texture/swapped_out_book.rs checks ImageObjects::drop on the objects
themselves, so it needs no storage form, which lavapipe's passes never take
(its fetch is not through the pixel interlock, and its readers split): the
storage-form recycle test says "nothing to check" there.
An image is made as a Private BGRA8Unorm render target's is
(Device::recycled_image, noted in the book under the target's making), then
dropped in ImageObjects that destroy it, as a storage form's swapped-out first
image goes. The test asserts the book no longer holds the handle and that
swapped_out_images_forgotten rose by one. Then it makes Shared RGBA16Float
textures, kept, until one's image takes that handle where the driver gives it
again (printed), releases it, and asserts a texture of the target's
descriptor made after took no parked image (images_recycled), which a handle
left in the book would have handed it.
first_move_lifetimes.rs's device and scratch helpers are shared with it within
the texture module (pub(super)).
Verified: see the landing report's job ids (built and run on lavapipe and the
M3, and failing with ImageObjects::drop's forget removed in a job-only
negative control).
WorkCounts::object_churn.swapped_out_images_forgotten counts the VkImages
ImageObjects::drop takes out of the recycler's book of live images before
destroying them: a texture's first image, which its storage form swapped out,
whose handle the book held. Each is an entry the previous commit's fix removes
and that before it stayed in the book, where the driver's next image at that
handle would have been parked as the old image's making. A nonzero count says
the path ran; its size says how often the book would have gone stale.
Recycler::forget now answers whether the book held the handle; the other
callers ignore it. The storage-form recycle test asserts the count rose for its
target's first image. The recycler's module docs name the count, and say what a
stale entry would do in the present tense. The API signature table has the new
field.
Verified: scripts/api-signatures/signatures.py --check passes; builds and the
test runs are in the landing report's job ids.
The host process aborted on MoltenVK (the consumer's guest, its dock restarted on
the M3): Metal's texture view creation asserted on a BGRA8Unorm (or RGBA8Unorm)
view of an RGBA16Float image, made lazily at a draw's vkUpdateDescriptorSets,
after MoltenVK refused one of the runtime's own vkCmdCopyImage calls between
formats of two sizes.
The cause is the image recycler's book of live images (recycle.rs), keyed by the
VkImage handle. A texture's first image, which its storage form swaps out
(texture/storage_form.rs), is destroyed with the swapped-out objects
(ImageObjects) as the switch's command buffer completes, and never left the
book. MoltenVK's handle is the MVKImage's address, which its next image takes: an
image the book does not note (a Shared texture's host-copy image, here an
RGBA16Float one) then parked, as it went, under the first image's making, and the
next texture of that making (a BGRA8Unorm render target of the same shape, which
the guest's window server makes again) took it. Its views and copies were of
BGRA8Unorm over an RGBA16Float image.
ImageObjects::drop now takes a VkImage it destroys out of the book first, so
every image the book holds leaves it before it is destroyed: at its texture's
release (parked or forgotten, as before) or as the objects it was swapped out with
go. The recycler's module docs say so ("The book"), and the storage form's.
Verified: see the job ids in the landing report (the test of the previous commit
fails without this change and passes with it, on the M3 and lavapipe).
The recycler books each live image it may park by its VkImage handle, and a
driver gives a destroyed image's handle to a later one (MoltenVK's handle is the
MVKImage's address). A texture's first image, which its storage form swapped out,
is destroyed with the swapped-out objects (ImageObjects) and never leaves the
book: the next image the driver makes at that handle, of a kind the book does not
note (a Shared texture's host-copy image), parks as the first image's making when
it goes, and the next texture of that making takes an image of another format.
The test takes a forced storage form on a Private BGRA8Unorm target (the
self_read_storage passes, whose helpers it now shares), waits for the switch's
command buffer and the switch to end, and checks that the book no longer holds the
first image; then makes Shared RGBA16Float textures until one lands at the first
image's handle (printed: the driver's choice), releases it, and checks that a
texture of the target's descriptor takes no parked image and renders and reads
what a new one does.
Expected to fail at this commit (the fix follows).
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.
The two commits before this one. A compute state whose descriptor requires no threadgroup size
predicts no VkPipeline at its creation: the local size and the threadgroup memory lengths come
from the dispatch. So its creation's record warmed none of its dispatches' pipelines, and each
was a cold driver compile at the program's first dispatch of that shape. On the Iris Xe these are
the compute kernels FAST-PATHS names.
Now a compute state's direct dispatch (dispatchThreadgroups: or dispatchThreads:) whose regions'
pipelines weren't all made hands the record hook one more record. It holds the creation's
descriptor and the dispatch: the threadgroup size, a dispatchThreads: grid cut down to one whole
threadgroup plus its ragged edge per axis, and the encoder's threadgroup memory lengths. Each
dispatch shape is recorded once per state, at most 16 per state (pipeline/dispatch_record.rs).
The warm pass creates the state, plans each recorded dispatch with nothing bound and the recorded
lengths, settles its variant through compute::settle_direct as the program's direct dispatch
does, and makes each region's VkPipeline on the pass thread. The program's making is then handed
the driver cache the pass filled. WarmStatistics::dispatch_pipelines_warmed counts them. Indirect
dispatches, threadgroup-range dispatches and tile dispatches record nothing. The record format
goes from 6 to 7; a format-6 record reads as none. The codec caps a record at 16 dispatches and
31 lengths each, on write and on read. The warm budget is unchanged.
Not covered: the program's dispatch still calls vkCreateComputePipelines (warm states share no
live variant with the program), and a dispatch whose bindings specialize its regions still makes
its own pipelines at first dispatch.
Verified (potluck jobs, on the branch at 42d9d77e54):
- lavapipe (m3-max-18386): 50/50, the warm, warm_record, dispatch_pending, dispatch_making,
deferred_calls, driver_pipeline_compile and creation_log tests. The new device test: on a device
warmed with both records, records_warmed 2 and dispatch_pipelines_warmed 1, and the program's
first dispatch gave [makings handed a cache the device held, pipelines made, functions
translated] = [1, 1, 0]; on a control warmed with the creation's record alone, [0, 1, 0] and 0.
lavapipe reported 0 driver hits and 1 miss on both devices; the cache sharing is the only
structural check there.
- An earlier run (18374) caught the pass making 2 pipelines the program never asks for (settled
through ComputePipelineState::settle alone); 42d9d77e54 fixes it.
- Lint (18388): fmt check, clippy in all three configurations, rustdoc, api_signatures and
api_surface 15/15, fast_paths 27/27, warm_record 5/5.
Not yet run: a driver hit on a real GPU (the Iris run is queued).
The warm pass settled a recorded dispatch's variant through
ComputePipelineState::settle alone, while the program's direct dispatch
first takes a ragged dispatchThreads: grid's flat variant
(compute::flat_direct): one region on one VkPipeline. On lavapipe the
program's 1000-thread dispatch in groups of 64 made 1 pipeline and the
pass made 2 others (the split's interior and edge), so none of the pass's
makings was one the program's dispatch asks for (lavapipe job 18374,
a_warm_pass_makes_the_pipelines_of_the_dispatches_its_records_name:
dispatch_pipelines_warmed 2 against 1).
Both now settle through compute::settle_direct (the flat variant where
the dispatch takes one, else settle), so they ask for the same variant
and region keys. Verification: the lavapipe and lint jobs on this tip,
in the report to main.
A compute state whose descriptor requires no threadgroup size predicts no
VkPipeline at its creation: the local size and the threadgroup memory
lengths are the dispatch's own calls, so its creation's record made none of
its dispatches' pipelines on a later warm pass, and each was a cold driver
compile at the program's first dispatch of its shape (the 12.7.6 kernels'
case in FAST-PATHS).
Now, where the device hands records over, a compute state's direct dispatch
(dispatchThreadgroups: or dispatchThreads:) whose regions' pipelines were not
all made hands the hook one more record: the creation's descriptor, as its
own record holds it, and the dispatch (its threadgroup, a dispatchThreads:
grid reduced to one whole threadgroup and its ragged edge per axis, and the
encoder's threadgroup memory lengths). Each such dispatch once per state, at
most 16 a state (pipeline/dispatch_record.rs). A warm pass that creates such a
record's state then plans the dispatch as a creation's prediction plans its
first one (nothing bound but the default samplers), with the recorded
lengths, settles its variant as a dispatch does, and makes each region's
VkPipeline on the pass's thread, so their driver data lands in the records
under the names the program's dispatch of that shape asks for.
WarmStatistics::dispatch_pipelines_warmed counts them. Indirect dispatches,
dispatches of a threadgroup range and tile dispatches record nothing.
Records are immutable, one per dispatch shape, so a consumer keeps each once
and needs no rule for which supersedes which. The record format moves to 7:
a compute record's bytes now end in its dispatch list (count, then each
dispatch), so a format-6 record reads as none. The codec bounds the list at
16 dispatches and 31 lengths each, both when writing and when reading.
Tests: warm_record round-trips a compute record with a dispatchThreadgroups:
and a ragged dispatchThreads: carrying two threadgroup lengths, and bounds the
list (more than 16 is unwritable; bytes claiming 17, resealed, are no record;
16 read back). The device test
a_warm_pass_makes_the_pipelines_of_the_dispatches_its_records_name records a
state's creation and first dispatch, checks that the same dispatch again and a
grid of the same edge make and record nothing, warms both records on a
device over the same directory (dispatch_pipelines_warmed equals the regions
the recording dispatch made), and checks that the program's first dispatch
there hands each of its makings the driver cache the pass filled
(caches_shared) and translates nothing. A control device warmed with the
creation's record alone makes no dispatch pipeline and shares no cache.
Verification is in the report to main (potluck lint and lavapipe jobs).
Docs: the runtime README, HOWTO and FAST-PATHS ("Made again before the
program asks") describe the dispatch records; api_signatures gains the
WarmStatistics field.
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.
The branch before this commit adds the fill queue. On a device whose transfer-only queue family
has two queues or more (NVIDIA's copy engine), a batch's copies in (a Managed buffer's modified
range) and new buffers' fills, 1 MiB or more in all, run on that family's second queue. They go in
a submission of their own after the batches before it, and the batch waits for it on the GPU
(device/staging.rs, WorkCounts::fill_queue_submissions). Smaller fills, and every fill on other
devices, still run at the start of the batch's own work on its queue. A batch that finds all of its
command buffers already pending keeps its fills. Metal's order is kept: a copy in comes after the
work before it and before the commands that take it.
Numbers (managed_copies_bench, p50 ms per frame, fill queue / batch's start):
- Beside another queue's kernels, 1 MiB: RTX 3090 1.80 / 3.53, RTX 2080 1.84 / 3.60, RTX 5080
Laptop 1.15 / 1.20. 64 MiB: 36.0 / 49.4, 37.8 / 48.2, 3.31 / 5.90.
- Alone, 1 MiB and up: at worst 1.04x as long (the 3090 at 1 MiB in two runs of three, the 2080
at 64 MiB in one run of two). FAST-PATHS states the trade. Under 1 MiB, no gain past the bench's
own spread, hence the 1 MiB least.
- Every other submission of the device waits on the GPU for the fill queue's last until the host
sees it complete (FAST-PATHS records it).
Verified (potluck jobs, on the branch at 24d29ef09c; later commits are docs and comments):
- fill_queue and the bench, 49/49 each: RTX 3090 (m3-max-18358), RTX 2080 (18309), RTX 5080
Laptop (18379, exclusive): fill queue family 1 (flags 0xc), 2 submissions, the second command
buffer still running when the third committed; 0 fill-queue submissions in the check just under
1 MiB. RX 7900 XTX (18310), 780M (18345), lavapipe (18286): no fill queue, 0 submissions.
- 0 NVRM intermapRegisterDmaMapping lines and no hung submit on the three NVIDIA GPUs.
- Lint (18317): clippy -D warnings in all three configurations on the runtime, conformance and
validation; rustdoc; api_signatures/api_surface 15/15; cost tests 10/10; plan and first-move
tests 52/52. At the tip: fmt, rustdoc -D warnings (18390), clippy under m2v_gpu and none (18401).
At the tip the RTX 3090's 1 MiB frame alone took 0.93 times as long through
the fill queue (18358), against 1.04 in the two runs before (17900, 18199),
and the RTX 2080's 64 MiB one 1.04 times (18309, against 1.00 in 18167): the
trade sentence names both, and the swept size from which the fill queue was
within 1% alone in every run is 256 MiB, not 64 MiB. The tip's runs, whose
two devices both copy at the batch's start under 1 MiB, put them 0.31 to
1.85 times apart there (RTX 2080 18309, RTX 3090 18358, RX 7900 XTX 18310);
64 MiB beside the kernels at the batch's start took up to 49.4 ms, and the
other queue's share moved -11 to +8 points on the RTX 3090 and RTX 2080.
Verified: cargo fmt.
The ledger bullet and staging.rs's fill-queue docs take the ranges of all
the runs: 1 MiB beside another queue's kernels 1.80-1.84 against
3.53-3.60 ms on the RTX 3090 and RTX 2080 (18199, 18167, 18309), 64 MiB
35.9-37.8 against 40.6-48.9 ms, and on the RTX 5080 Laptop GPU 3.31-3.39
against 5.90-5.92 ms (18316, 18108). Under 1 MiB the fill queue's frames
took 0.51-2.03 times the batch's start's, but at the tip, where both of
the bench's devices copy at the batch's start under 1 MiB, the same bench
put them 0.31-1.39 times apart (18309): the sub-1 MiB differences are not
past the bench's spread, which the docs now say instead of a 2.0x loss.
Verified: cargo fmt.
At 1 MiB alone the RTX 3090's frame took 1.04 times as long through the fill
queue (jobs 17900 and 18199), and beside another queue's kernels half as
long; the swept size from which it is within 1% alone on all three NVIDIA
GPUs is 64 MiB. The owner's coordinator kept 1 MiB; the bullet says the trade.
Verified: cargo fmt.
The fill queue's own submission and the batch's wait for it cost small
copies more than the copy engine saves them. The sweep of
managed_copies_bench (a Managed buffer's copy in each frame, the fill queue
against the batch's start, p50) placed the crossover:
- RTX 2080 (18167): 128 KiB 1.04x alone and 1.11x beside another queue's
kernels; 256 KiB 2.03x alone (0.94 against 0.46 ms), 1.09x beside;
512 KiB 1.31x alone; from 1 MiB up 0.98-1.00x alone and 0.51-0.91x
beside (1 MiB 1.81 against 3.57 ms).
- RTX 3090 (18199): faster or within 4% everywhere; 1 MiB alone 1.04x
(reproduced, 17900), beside 0.51x (1.80 against 3.53 ms).
- RTX 5080 Laptop GPU (18108, before the sweep): 64 KiB 1.44x alone and
1.06x beside; from 1 MiB up 0.93-0.99x alone and 0.56-0.96x beside.
So FILL_QUEUE_LEAST is 1 MiB, the smallest swept size from which the fill
queue is no slower beside the kernels on any of the three and at most 1.04
times as long alone: Taken::take_fills takes the batch's fills only where
they write that many bytes in all (copies and zeros), and fewer stay at the
batch's start, as on a device without a fill queue. Decided from bytes, not
from the device.
The fill-queue test gains a last command buffer whose fills (a new Managed
buffer's zeros and its copy in, under half the least each) make no
fill-queue submission and read back exactly. The ledger's costs of
matching Metal gain the fill queue's bullet; the staging, create, bench and
README docs say the least and the measured numbers (the create.rs 82% came
from the raw example and is gone).
Verified: cargo fmt; device runs, lavapipe and lint follow.
On an RTX 5080 Laptop GPU a 64 KiB copy in a frame took 0.336 ms (p50)
through the fill queue and 0.234 ms at the start of the batch's work, and
1 MiB the same either way (job 18108): the sizes between them place the
crossover, and 4 KiB the smallest copies.
Verified: cargo fmt; device runs follow.
The order leg wrote the Managed buffer's host copy again once the command
buffer that took the first copy in was only submitted. That copy reads the
host copy when the GPU runs it, so the write raced it: the leg failed on an
RTX 2080 with the fill queue and on an RX 7900 XTX without one (jobs 17974,
17975), the inline path too. Metal leaves the host copy to the CPU only once
the copy in ran, so the test now takes the first copy in with a command
buffer of its own that completes, then keeps a second one, whose blit reads
the device copy behind a long run of kernels, in flight while the CPU writes
again and a third takes that copy in, which must follow the blit.
Verified: cargo fmt; device runs follow.
A copy in noted before a committed command buffer's submission is that submission's, as the
runtime's contract says (the device's next submission takes it): on the RTX 3090 the first
command buffer's submission took both copies in, read the second bytes, and made the one
fill-queue submission.
A Managed buffer there is one copy, which the CPU's write races while a command buffer reads it,
as on Metal; lavapipe read the second pattern in the first command buffer.
A fill-queue submission waits for the batches before its batch, and one of those may wait for a
signal the caller reserved, so taking a command buffer by a wait on the host could hold the
scheduler's thread until the caller submits. The batch checks for room first (a command buffer
whose submission the host saw complete, or fewer than BUFFERS) and keeps its fills at its start
where there is none.
device/staging.rs documents the fill queue: why (a copy through the graphics family runs on the
engine the kernels run on; the 3090 and 5080 numbers so far), why not the staging queue, what it
waits for, what waits for it (with the spec's semaphore and sharing text), what it holds, and what
stays where it was. first_move.rs and managed_copy.rs say where a batch's fills go. Queue counts:
the plan takes 18 queues on NVIDIA now, so the measured 17- and 2-queue devices are named by their
queues, and the least plan keeps the fill queue as it keeps the staging queue.
The bench runs both paths on one build: the default device, and one whose extra transfer queue
takes the copy engine's second queue, so its fills stay at each batch's start; and sizes from
64 KiB, for a size crossover.
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.
Each frame the CPU writes a Managed buffer of 64 or 256 MiB whole and tells it (did_modify_range,
which the runtime copies into its device copy by the next submission), and a command buffer runs
a kernel over its first floats into a Shared buffer, checked. Beside it, optionally, another
queue's command buffers of 24 dispatches over 64 MiB Private buffers, two in flight. Prints the
frame's wall time, the load's rate against the load alone and each phase's host time span, for
the copy-engine work's before and after on discrete GPUs.
Not yet built: the first build is a potluck job.
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.
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.
The branch before this commit stops importing the same host addresses twice. A buffer or texture
over a guest RAM chunk that wasn't imported yet, or a copy over one, was bound in an import of
its own run, made from the run's host pointer, while the device's thread imported the whole chunk
from its pointer. That left two live imports of the same host addresses, and the run's was freed
while the chunk's lived. VK_EXT_external_memory_host leaves importing the same host allocation
twice undefined (issue 6). It is the lead for the NVIDIA present stall on the 3090 and the 2080
eGPU.
Now a run is 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. Everywhere else an object or a copy
over a chunk lies in that chunk's one import, made or waited for, as on MoltenVK and ANV. The cost:
a making waits for a chunk the import window hasn't reached yet. imports_inside_live now counts
every import made over host addresses a live import holds (heaps included, on the making and
rebind paths). A new evidence counter, ObjectChurn::imports_over_ram_chunk_pages, counts a view's
own import over guest RAM pages that a live chunk import holds. host_ab prints both, plus
buffers_bound_in_import. HOWTO and API.md describe the single import and its cost.
Verified (potluck jobs, on the branch):
- lavapipe, full runtime suite: 2200/2200 at the tip (m3-max-18365) and at c6f775cefe (18331).
- The one_import device tests' counts show their paths ran: [pointer imports, bound in import,
copies over live, imports_inside_live] = heap first [1, 2, 1, 0], buffer first [2, 1, 1, 0].
- Lint (m3-max-18364): clippy workspace all targets all features; the runtime with --cfg m2v_gpu
and with --cfg m2v_gpu --cfg m2v_gpu_hazards; rustdoc -D warnings; api_signatures/api_surface.
- metal2vulkan with no feature and with each alone (18340).
Not yet run: the NVIDIA device tests at the tip; the opt-in hazard test
(tests::import_overlap_hazard) on gem10's 3090, before and after; the consumer's NVIDIA walks.
Two tests under m2v_gpu with m2v_gpu_hazards, on Linux. One makes objects
over chunks of a fresh guest RAM the device's thread has not imported
(each a jump past its window), writes and reads them by blits, makes a
second buffer over the same pages, and drops the first: 6 RAMs of 24
chunks. The other maps 32 views of 512 scattered memfd pages, makes a
no-copy heap over each, a buffer over exactly its bytes and 32 buffers of
64 to 384 KiB inside it, each blitted and dropped while the heap lives.
A runtime that imports those runs or sub-ranges by their own pointer
frees each such import while the larger import of the same pages lives.
Each prints the import and placement counts that say which path ran;
the job reads the kernel log. Not yet run.
API.md's copied-host-pages entry gains the over-a-live-import cause
(copied_over_live_imports, announced once per device as the others are).
HOWTO's listed-plan paragraph described its runs alone "as above", text
the previous commit removed: it now says what a listed RAM's run import is
(a dma-buf), what it costs, how it orders, and that MoltenVK and ANV import
the chunk instead.
host_ram_device's window, down-the-RAM, margin and ordering tests expected
an object over a chunk not imported to lie in an import of its own run on
every device but MoltenVK and ANV. A RAM with no source of dma-bufs has
chunks imported by their pointer, and its runs are no longer imported
alone beside them (RamOnDevice::runs_alone): each test now asserts the
object imports its chunk and no run import lives. The two ordering tests
are renamed for what they order now (two buffers in one chunk's import, a
chunk-bound buffer and copies). runs_alone moves to the dma-buf tests,
whose listed RAMs still import runs alone, and kept_in_its_run goes with
the run imports it kept. The defect's evidence keeps its measurements
without the old test names.
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.