tests::import_free_hold_bench measures what a vkFreeMemory of an import of host pages holds of
another thread's submissions: a pinger commits a one-word fill every 250 us while the bench's
thread makes and frees, through the runtime's doors, 32 pointer imports of 512 KiB, four of 64
MiB, 32 dma-buf imports of 512 KiB (udmabuf) and 32 plain host-visible allocations, each kind's
frees in turn and paced (step_aside::pace), printing the frees, the runs and the pings beside
them. tests::posted_frees gains a burst of posted frees that runs paced, and the allocation at the
limit now checks that the frees it waits for are not paced. api_signatures re-blessed for the two
new WorkCounts fields.
NVIDIA's driver holds every other thread's vkQueueSubmit while it frees memory, a host-pointer
import's for 0.5 to 0.9 ms on an RTX 3090. The submission checks already pay their own
allocations and frees back before their next step (step_aside::OwnCall); this applies the same
owed time to the device's own threads that free in runs: the free thread before each block, the
residency thread before each idle import it releases, and a guest RAM's threads before each chunk
or list they give back or release. Each waits until as long as its frees before took has passed
since the last ended (now also the checks' rule), never while a caller waits for those frees (an
allocation at the limit, the device's teardown, a guest RAM use's end). The residency sweep holds
its imports weakly while it waits, so a program's release meanwhile frees its import in that
release, as before. Counted: WorkCounts::memory_frees_paced, memory_frees_paced_nanos.
Not yet built: the bench that measures the hold and the paced frees follows.
tests::submit_check_device::the_checks_answer_once_and_a_second_device_recalls_them held the
device that ran the checks to the cmd_copy_buffer count of the one that recalled them, which
held while every device was primed. Since 6ce451f452 a device made again on what stays loaded is
not, so the first (primed: priming's one copy within its buffer) counted 1 and the second 0
(lavapipe, gem10, m3-max-18039 and 18111, 3 of 3). Each count now leaves out the copies the
device's priming recorded, where ExitRegistrations::primings shows it was primed.
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.
RADV lists every imported memory in every kernel submission, 0.43-0.44 us each on the 780M and
the XTX (raw probe: 512 dma-buf imports of 1 MiB cost 229-234 us per submission against 7-8 us
with none; 64 pointer imports of 1 MiB 191-200 us). A texture in place over a no-copy buffer's
dma-buf import kept the buffer's import live for good, so each such surface listed two dma-bufs
per submission, though its DRM_FORMAT_MOD_LINEAR image has its own dedicated import.
Now HostPages::dma_buf reads the pages the way a blit does (blit_pages: imported again if
released, still releasable), and the in-place watch and dma_buf_unplaced take the offset from
Buffer::offset_in_host_pages() instead of a pinning memory() read; heap images take the same
path. Sampling and rendering go through the image's own import. A blit that names such a
texture runs on the buffer's bytes and imports the buffer again, as any blit does. The image's
own import stays listed for its life (RADV requires a dedicated allocation for it). The
per-import cost and the remaining limits (second buffers and bindings keep imports for good;
separate submit calls list every import again; no documented switch takes an import off the
list) are a FAST-PATHS known gap.
Tests: lane runtime_lane::submit_per_surface (128 surfaces of 64 KiB, each a no-copy buffer and
an in-place texture, measured after a 4 s idle); device test
host_residency::a_texture_in_place_over_a_dma_buf_import_leaves_it_releasable.
Verified (potluck jobs, on the branch):
- 780M PHOENIX, Mesa 26.2.6: before (17864) 256 dma-bufs listed per submission, 119 us in the
ioctl, 128 buffer imports kept for a texture; after (17939, three runs) 128 listed, 58-67 us,
0 kept. In use: 256 listed, 115-129 us.
- XTX NAVI31: before (17927, load ~20) 256 listed, 160 us; after (17999, three runs) 128 listed,
59-70 us; in use 256 listed, 108-109 us.
- The device test passed on the XTX (17999) and the 780M (18002): "1 chunks released under a
texture in place, rendered into, imported again by its blit and released again".
- lavapipe 164/164 (18007; the device test skips: lavapipe imports the pointer).
- clippy default, --cfg m2v_gpu, --cfg m2v_cpu_icd and rustdoc -D warnings (17978, at the last
code commit; later commits are docs).
In the consumer's 780M walk the saving is bounded: at most about 43 of 160 kept imports are kept
by a texture alone (about 18 us per submission, for surfaces idle past their window).
submit_per_surface on the RX 7900 XTX, three runs at the tip: 128 surfaces list
256 dma-bufs (108 to 109 us in the ioctl) while in use and 128 after their idle
window (59 to 70 us). Text only.
The idle-release bullet says a texture in place over a no-copy buffer leaves
the buffer's import to the release (its blit reads the buffer as any blit), with
the 780M lane's counts (submit_per_surface, three runs: 128 surfaces list 256
dma-bufs while in use, 128 after the idle window). A known-gap entry records the
per-entry cost the raw probe measured on the 780M and the XTX (0.43 to 0.44 us
per dma-buf import per kernel submission), what Vulkan offers that does not
change it (memory priority, no device address, no pageable extension listed),
that separate submission calls list every import again, and that each in-place
texture's own image import stays listed for its life (RADV requires a dedicated
allocation of such an image).
On the 780M the test's claim that the texture's blit imports nothing failed:
a blit that names a texture over a buffer runs on the buffer's bytes
(blit_texture.rs, the module's note), so it imports the released buffer again,
as any blit does, and leaves it releasable. The test now clears the texture in
a render pass while the buffer's import is released (written through the
image's own import, residency unchanged, the pages read back), then checks the
texture's blit imports the buffer again and that it is released again.
dma_buf_textures_in_place and host_imports_released are running totals, so the
64-surface phase printed 96 textures in place (32 + 64). The lane now reads both
at the phase's start and prints the difference. Report-only lane; built and run
on the 780M with the next runtime change.
The host_residency module doc and HOWTO section 6 told what a guest surface
listed before the in-place texture stopped pinning its buffer's import; docs
say what is true now. Text only.
HostPages::dma_buf now answers a Result (the pages read as a blit reads
them, imported again where released); the heap's dma-buf image maker
(texture/heap.rs) is its other caller and takes the change. A heap's import
is kept for good whatever reads it, so nothing of its residency changes.
Found by the lint job m3-max-17783 (E0271 at texture/heap.rs).
RADV lists every imported VkDeviceMemory in every kernel submission, about
0.43 us each on the Radeon 780M and the RX 7900 XTX (a from-scratch Vulkan
probe, Mesa 26.2.6, Linux 7.3.3: 64, 256 and 512 dma-bufs held cost 31.5,
111 and 229 us an empty vkQueueSubmit against 7.2 with none). A consumer's
guest surface is a no-copy buffer over its pages and a texture in place over
the buffer: on RADV the texture is a DRM_FORMAT_MOD_LINEAR image in a
dedicated import of a dma-buf of its own pages, and making it read the
buffer's import apart (ReadApart::Texture), which kept the buffer's import
for good. So each surface listed two imports in every kernel submission for
its whole life.
The image asks the buffer's source for its own pages and binds none of the
buffer's memory, so its making now reads the buffer's dma-buf pages as a
blit does (HostImport::blit_pages: imported again where released, left
releasable), and the in-place watch a rebind reads takes the texels' offset
from the buffer's place in its host pages (Buffer::offset_in_host_pages),
not from their import. The buffer's import is then released after its idle
window like any blit-only one; the texture's image keeps its own import.
Pointer-imported pages, shadows and texel views still read the import apart:
they bind or read the buffer's memory.
Test: tests/host_residency.rs
a_texture_in_place_over_a_dma_buf_import_leaves_it_releasable: the buffer
under an in-place texture is released (its chunks leave
dma_buf_memories_live, the image's import stays), the texture reads the
CPU's writes made meanwhile without importing anything, and the buffer's
next blit imports it again. Without the change the release never comes.
Docs: host_residency.rs, HostMemory::with_dma_buf, HOWTO.md.
runtime_lane::submit_per_surface holds 0, 32, 64 and 128 surfaces, each a
no-copy buffer over a run of memfd pages imported as dma-bufs and a texture
in place over it (HostPageTexturePolicy::InPlace), reads each texture once,
then times 300 single-fill command buffers at once and again after the
surfaces sat idle past the device's first idle window. It prints the
textures in place over a dma-buf, the dma-buf memories live of buffers and
of images, the buffer imports released while idle and those a texture keeps,
and, under the kernel-submission counter, the dma-bufs each kernel
submission lists. A measurement, ignored by default, Linux only.
Why: RADV lists every imported VkDeviceMemory in every kernel submission,
about 0.43 us each on the Radeon 780M and the RX 7900 XTX (a from-scratch
Vulkan probe, Mesa 26.2.6, Linux 7.3.3), and a consumer's guest surface may
list two: its buffer's import and its in-place image's dedicated import.
Not run yet: built and run by potluck jobs on the 780M and the XTX.
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.
A device is primed only when it will register the exit hook: the process's first device, the
first after a shared-object load, or a device of a new identity. A device made again on what stays
loaded registers nothing, and its calls are not the first ones (an earlier device's priming made
each), so it now skips priming. To answer that before priming, the device's functions and guard
identity are made earlier in the making. If a device registers without having been primed
(something changed between the check and the registration), the calls primed before are
forgotten, so each section's first call registers the hook again. ExitRegistrations (hidden)
gains a primings count.
Why: on the RTX 3090 (620.70.06) priming spends 112-144 ms in one call,
vkCreateIndirectCommandsLayoutEXT (m3-max-17899), and over 8 makings every device after the first
was made with no load (loads 67, at_devices 1; 17904): each re-made device paid priming for
nothing.
Tests: exit_guard::whether_a_device_registers_is_answered_before_its_priming,
exit_guard::a_device_registered_unprimed_forgets_the_primed_calls (fork test), primed_devices
(device cfgs); the two priming fork tests take the new signatures.
Verified (potluck jobs, on the branch at d36c330b67):
- lavapipe (m3-max-17994): clippy --cfg m2v_cpu_icd all targets and features clean; exit_guard
and primed_devices 59/59 ("4 of 4 devices made again with no load; primings 1, at_devices 1").
- default cfg (17995): clippy clean; exit_guard 58/58.
- RTX 3090 release A/B, 2 runs x 8 makings: the runtime's own share of a re-made device (making
minus vkCreateDevice) median 226 ms (140-459, busy node; 18001) -> 13.9 ms (13.2-15.6; 18000);
making median 831 -> 561 ms; primings per re-made device 3 -> 0. The first device in a process
still primes (own share about 293-336 ms with instance setup).
Not measured: the 5080 A/B; a lane whose validation layer reloads per instance still primes.
The properties read after priming bind `identity` again (a DeviceIdentity), which the
registration took instead of the guard's Vec<u64> (E0308 at 6ce451f452, m3-max-17990).
What. A device's making asks the exit guard, before priming it, whether it will register the
hook (`exit_guard::before_priming`, now given the device's identity, answers
`Devices::admits`: the process's first device, the first after a load of a shared object, or
one of an identity new since). Only such a device is primed. A device made again on what stays
loaded, after a device of its identity registered, registers nothing and is no longer primed:
its calls are not the first, an earlier device's priming made each. The device's functions and
identity are made before the priming for the question; nothing else moves. A device that
registers unprimed after all (a load or another device between the question and its
registration) forgets the calls primed before, so each section's first call registers the hook
again. `ExitRegistrations` (hidden, for the lanes) counts the primings.
Why. Bug 487/676: on NVIDIA a device's making spent 120-160 ms of its own beside
vkCreateDevice, nearly all in priming's vkCreateIndirectCommandsLayoutEXT (112-144 ms on the
RTX 3090, NVIDIA 620.70.06, scratch timers on steelbrain/triage2-scratch 2edaaa5afa; m3-max-17899).
On that GPU every device after the first was made on what stayed loaded (the loads count stayed
at 67 over 8 makings and at_devices at 1, e6e5c1a34b, m3-max-17904), so each re-made device
paid priming for nothing. Priming exists only so that a device's registration of the hook comes
after the statics its calls make.
Tests: tests::exit_guard::whether_a_device_registers_is_answered_before_its_priming (the
answer agrees with the registration and notes nothing),
a_device_registered_unprimed_forgets_the_primed_calls (fork: 42), the two priming fork tests on
the new signatures, and tests::primed_devices (device cfgs): the first device primes, each made
again with no load neither primes nor registers.
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.
On the Iris Xe (ANV 26.2.6) a cold guest login made three pipelines that differ only in their
colour attachments' formats, and each compiled its own fragment shader for 4.2-4.4 s inside
vkCreateGraphicsPipelines: the shader parts' driver cache records were named by the full pass,
formats included, so no creation found another's compile.
Now the two shader parts' VkPipelineCache records name the pass with PassShape::without_formats
(attachment presence, samples, fetch inputs, unread inputs, storage attachments, view mask and
locations kept). The library objects keep their full names: they link against VkRenderPasses
that must be compatible, so only the driver's cache record is shared. A format the translation
reads still names its own record through the stage's module words. Record-naming version 2 -> 3
(shader_cache/driver.rs). With METAL2VULKAN_LOG_PIPELINES on, each library's split says whether
its record loaded, missed or shared an earlier making's cache, and whether the driver found it
there. Docs: docs/API.md, env_vars.rs.
Tests: unit test record_pass_formats; device test
driver_pipeline_compile::creations_over_colour_formats_take_the_first_s_records (RGBA8Unorm, then
BGRA8Unorm, then RGBA16Float: each later creation takes the first's caches and makes one fragment
shader library; RGBA16Float under NearestEven rounding, which the translation reads, keeps its
own record); creation_log text test.
Verified (potluck jobs, on the branch at 538c7e8eb4):
- Iris Xe ANV 26.2.6 (m3-max-17968): 2 of 2 makings took an earlier making's cache, 1 fragment
shader library made, 2 driver hits and 0 misses, for BGRA8 and RGBA16F. lavapipe (17953): 2 of
2 shared, 1 library each. M3 MoltenVK 1.4.2 (17956): 1 of 1 shared, 1 hit each.
- The 26.7.2 module, cold, Mesa cache off, harness (17871) on the Iris: own cache per format 3.65,
3.53, 3.26 s; one shared cache 3.46 s, then 0.0 and 0.0 ms (APPLICATION_PIPELINE_CACHE_HIT).
- fmt, clippy plain, --cfg m2v_gpu and --cfg m2v_cpu_icd, rustdoc -D warnings (17965).
Expected, not yet run: the device test on the 3090 and the 780M, and the consumer's cold boots.
creations_over_colour_formats_take_the_first_s_records expected the
RGBA16Float creation under NearestEven rounding to hand one making the
first's cache where the device links (its pre-rasterization part). That
creation makes no pre-rasterization library at all: the RGBA16Float
creation before it made that library against the same pass, under the
same library name, and the runtime reuses it. Its one making is the
fragment shader library of the rounding module, under a record of its
own, so no making takes an earlier making's cache on any device.
Verified on lavapipe before this fix (job m3-max-17929, um870): the
first two creations printed 2 of 2 makings handed the first's cache and
1 fragment shader library made each; the third printed 0 makings shared
and 1 miss, which the old expectation (1) failed. The test now expects
0, one fragment shader library made where the device links, and one
answer per making from a reporting driver.
The test's doc gave the measured module's exact word count; round it.
Also, to correct the previous commit's body: the third creation there is
an RGBA16Float pass under NearestEven rounding, a format the translation
reads (the fragment function rounds the half channel itself), so its
fragment part keeps a record of its own and only its pre-rasterization
part, where the device links, takes the first's. Doc only.
A render making's record of the driver's data, and the libraries of its
pre-rasterization and fragment shader parts, were named by the pass
shape whole, formats included. A program that makes one state against
passes that differ only in a colour attachment's format (RGBA8Unorm,
RGBA16Float, BGRA8Unorm) so got one VkPipelineCache per format, and the
driver compiled the same fragment module once in each: on the Iris Xe
(ANV, Mesa 26.2.6) 3.3 to 3.7 s per compile for one large module, three
times over at a cold start.
No stage's conversion reads an attachment's format through the pass: a
format the translation reads is in the stage's own words and constants,
which name the part's record too. So a part's record now names the pass
by PassShape::without_formats (which attachments it has, its samples,
fetch inputs, unread inputs, storage attachments, view mask and
locations), and the depth bias is left out of it as before. The library
names the runtime keys its own library objects by keep the formats (the
libraries are made against VkRenderPasses, which must be compatible);
only the driver cache record is shared. A driver that does key a stage
by format keys that entry apart in the one cache: a compile, never a
wrong pipeline.
The record-naming version (shader_cache/driver.rs VERSION) goes to 3.
METAL2VULKAN_LOG_PIPELINES now says, per library, whether its record
was loaded, missed or its cache shared with an earlier making, and
whether the driver found it in that cache or compiled it (from
VK_EXT_pipeline_creation_feedback).
Measured before the change (a harness making the module's fragment
library against three passes on the Iris Xe, MESA_SHADER_CACHE_DISABLE):
a cache per format, 3.5 s, 3.7 s, 3.3 s; one shared cache, 3.5 s then
0.0 ms and 0.0 ms, the second and third APPLICATION_PIPELINE_CACHE_HIT.
Tests: record_pass_formats (a pass's record name drops formats, keeps
presence, samples, fetch inputs and view mask);
driver_pipeline_compile::creations_over_colour_formats_take_the_first_s_records
(two makings over BGRA8Unorm and RGBA16Float share the first's record,
caches_shared grows by the makings, one fragment library compiled,
while a constant that changes the module keeps its own record);
creation_log's text test.
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 queue-sharing isolation tests failed on the RTX 3090 (620.70.06) at development and at the
2059 fix alike (m3-max-17458): the unshared compositor stalled 2-47 times over 10 ms, and the
shared case's p99 reached 5.4-7.6 ms. The cause is the device's submission-check thread: a test
device starts with a fresh shader cache and no check record, so the checks run in the measured
window, and the import tax frees its 32 host-pointer imports back to back. On that driver each
vkFreeMemory of a host-pointer import holds every other thread's vkQueueSubmit for 0.5-0.9 ms, so
the scheduler's one thread got one submission in between two frees and the compositor's batches
backed up for the burst (commit to submission 21-23 ms). A raw Vulkan probe shows the driver's
behaviour alone: 32 imports of 512 KiB made and freed in turn beside 4,800 fills a second move the
fills' p50 from 0.12 ms to 3.9-8.3 ms, and from 0.74 to 11.4-12.7 ms beside 30 ms work on another
queue. Ruled out: timestamps, calibration, semaphore waits, submit infos, queue count, pageable
memory, device addresses, recording, kept barriers, one submitting thread, a fence-waited checker.
Now a check's own allocation or free, at the two doors that already count it (allocations::Busy),
owes its length to the thread's next step: step_aside waits that long first, then steps aside as
before, so the device's submissions go between the check's calls and the check holds the driver
at most half the time its calls run. A call of microseconds owes microseconds; a step a waiter
tells to go on pays nothing. Docs: step_aside.rs, submit_check.rs, the steps_aside doc comment.
Also measured: the unshared compositor's channel waits for NVIDIA's time-slicing only 0.62 ms at
p50 and 1.24 ms at p99 on the 3090 (0.64/1.27 on the 2080), never a stall; the driver documents no
time slice or global priority lever, and none is needed.
Tests: two unit tests in step_aside.
Verified (potluck jobs): lint three ways and rustdoc (17831); lavapipe step_aside, submit_check,
queue_share_device, in_place_check and host_ram 127/127 (17880); 3090 A/B of the three tests,
not exclusive, gem10 load 19-21 (17858): round 1 development 1/3, fix 3/3 (p99 about 2 ms, 0
stalls); rounds 2-3 starved by host load for both builds. The exclusive 3090 A/B (17886) and the
2080 A/B (17859) follow the merge.
On an RTX 3090 (NVIDIA 620.70.06), a vkFreeMemory of a host-pointer import holds back every
other thread's vkQueueSubmit while it runs. The submission checks' import tax freed its 32
imports back to back, so the scheduler's one thread got a submission in only between two
frees. A device made without a check record (every test device: a fresh shader cache) ran
that beside the queue-sharing isolation tests, and the compositor's command buffers beside
long work waited up to 21 ms from commit to submission. Those were the three isolation
failures of the 3090's GPU-time leg.
Now a check's own allocation or free of memory, at the two doors (allocations::Busy), owes
its length to the thread's next step: step_aside waits that long first, then steps aside as
before. The device's other threads' submissions go between the check's calls, and the check's
allocations and frees hold the driver at most half the time they run. A call of microseconds
is owed microseconds. A step told to go on (a caller waits for the verdicts, or the check
stops) pays nothing. Counted among the checks' steps aside.
How it was found (3090, gem10; diagnosis on a scratch branch):
- Traced runtime runs: each compositor vkQueueSubmit returned only after the GPU ran the batch,
in episodes. Traced with the check, an episode was exactly the import tax's frees: each
0.5 to 0.7 ms, the scheduler's submit returning between two of them.
- With the checks settled before measuring: 0 stalls in 4 of 4 runs (p99 1.7 to 2.4 ms), against
12 to 71 stalls over 10 ms with them running.
- A raw Vulkan probe: 32 imports of 512 KiB made and freed in turn beside 4,800 fills a second
put the fills' latency at p50 3.9 to 8.3 ms alone (0.12 without it) and 11.4 to 12.7 ms beside
30 ms work on another queue (0.74 without it). These did not block it: timestamps,
calibration, waits in vkWaitSemaphores, two submit infos, 16 queues, pageable memory,
device addresses, fresh recording, kept barrier command buffers, one submitting thread, or
a fence-waited checker on the same queue.
Tests: step_aside's a_check_s_own_call_is_owed_to_its_next_step and
a_call_on_another_thread_is_owed_nothing.
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 unit test of this_thread.rs started its second thread with std::thread::spawn inside the
module's own #[cfg(test)] block, under src/. exit_guard's
threads_and_the_program_s_code_go_through_the_guard reads every runtime source under src/ but
src/tests/ for thread starts outside exit_guard.rs, so it failed on that test's spawn (reported
by the halfnative worker's translator-suite run on msi at b8bb54e69f).
The test moves, unchanged, to src/tests/this_thread.rs, beside the runtime's other tests, which
that check leaves out by their directory; this_thread.rs keeps only id and runs. No allowlist.
Verified: the fail-first run at f3c9f748ce and the run at this commit follow (runtime crate,
threads_and_the_program_s_code_go_through_the_guard and a_thread_tells_itself_from_another).
The logic-operation lane on an RTX 3090 (driver 620.70.06, job
m3-max-17707, at bdb59d55de): every out-of-range integer channel
(RGBA8Uint, RGBA8Sint, R16Uint, RG16Sint under xor and and) stores Metal's
saturated code through Vulkan's logicOp and through the fragment
function's operation, as on lavapipe. The FAST-PATHS known-gap row and
the private_state docs name both measured devices. No note: the spec
leaves the value undefined, and neither device differs from Metal.
A measurement for the consumer, no product path: can a SPARSE_BINDING
buffer be bound to memory imported with VK_EXT_external_memory_host?
sparse_host_pages.rs (runtime src/tests, Linux, the GPU safety cfgs)
prints, on a VkDevice of its own made beside the runtime's device:
- sparseBinding, sparseResidencyBuffer and sparseResidencyAliased, the
sparse properties, sparseAddressSpaceSize and
minImportedHostPointerAlignment;
- for SPARSE_BINDING (and with SPARSE_RESIDENCY where offered) buffers of
transfer, storage, uniform, vertex and all four uses:
vkGetPhysicalDeviceExternalBufferProperties for the host-allocation
handle type, and memoryTypeBits, alignment and size without and with
that handle type;
- vkGetMemoryHostPointerPropertiesEXT's types for a page of a memfd mapped
shared and of anonymous memory, and the intersection;
- where the device imports into such a buffer and the intersection is not
empty: four separate memfd chunks (64 KiB or more, multiples of the
buffer's alignment, of minImportedHostPointerAlignment and of the page)
imported, bound in reverse order with vkQueueBindSparse, a GPU copy in
read back through each chunk's own mapping, and host writes through
the mappings copied out.
Every call follows the spec's valid usage (the buffer names the handle
type, VUID-VkSparseMemoryBind-memory-02731 and
VUID-VkBufferCreateInfo-pNext-00920; the type is in both answers,
VUID-VkMemoryAllocateInfo-memoryTypeIndex-01744; offsets and sizes per
VUID-VkSparseMemoryBind-resourceOffset-09491 and
VUID-VkMemoryAllocateInfo-allocationSize-01745). It asserts nothing a
device may answer either way: refusals, a failed bind and the round
trip's outcome are printed (SPARSE-HOST lines).
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.
Half arithmetic followed float's rule but for contraction: every half + - * was lowered
NoContraction, and a half fma-shaped pair as Fma(a, b, -0), whatever the AIR's fast-math flags
said. Now a half + - * whose flags allow contraction is left contractable, as float's is, so the
device may fuse it (rule 1: the device's native arithmetic).
Notes: on the float-controls basis (Iris, 780M) half's notes are float's. On the measured basis
(MoltenVK) a contractable half + - * records FastMathRewrites whatever its neighbours: Metal's fast
compile folds an undecorated 16-bit op's conversions away, so even a lone op can answer the
unrounded float result (M3, fast_half_chain: (1 + 2^-11) + 2^-11 with every sum fast stores
1 + 2^-11 on all 4096 threads, neither Metal's rounded 1 nor the held 1 + 2^-10). The exported
float_binop_notes predicts the same.
Holding half in 16 bits instead of widening was measured and not taken: on top of the
contraction it is no faster on the 780M and gives the gain back on the Iris.
Fixture hnq_half_layer_composite (a half layer-compositing fragment function: 16-tap filters, a
colour-op switch, a 40-case blend, its taps unrolled and live across two passes) and lane tests.
Verified (potluck jobs, on the branch):
- performance, hnq proxy, median ms per draw, two states x 16 draws twice interleaved: Iris base
25.49/25.15, contraction 23.52/23.16 (-7.5%; SIMD8 instructions 7652 -> 7091, 0 spills); 780M
base 7.39/7.19, contraction 6.71/6.52 (-9%).
- half lanes 24/24 on the M3 (c66c73c1ce), Iris, 780M and lavapipe (cce43e469c).
- fresh translation census on the M3, base 5cad27af52 against the tip, 17,057 rows over
moltenvk-m3, intel-irisxe-rplp-anv and amd-780m-radv: 0 rows changed outcome, 0 defects; 181 s
base, 204 s tip (the 8 slowest rows re-timed alternately: base 434/432/448 ms, tip 440/436/428
ms: host contention); slowest row 429-446 ms; peak worker resident memory about 216 MiB. Proxy
translation 0.04-0.17 s and about 46 MiB, base and tip alike.
- translator suite: 5464 passed; the golden tables and the air_input printouts are re-blessed on
development at the batch. Clippy three ways and rustdoc clean.
The M3 lanes at the contraction change failed twice:
- kept_apart::half_chains_without_float16_round_at_their_exits: fast_half_chain ((1 + 2^-11) +
2^-11, every sum fast) stored 0x3F801000 (1 + 2^-11) on every thread, under both chain
policies: neither the rounded sum (1) nor the held one (1 + 2^-10). Its 16-bit sums are now left
to Metal's fast compile, which folded one's conversions away. The stage records
PrecisionNote::FastMathRewrites, whose bound is the roundings skipped; the test now takes a sum
between the two where the stage records it, and prints how many.
- driver_deviations::half_arithmetic_answers_as_metal: the previous commit expected the fast-math
case to stop requiring VkProperty::MetalHalfArithmetic, but its half reads take the device's
widening and still require it (the M3 compile says so). The requirement is again the profile's
deviation for every case; the FastMathRewrites check for the fast-math case stays.
Checked by the M3 lanes run at this commit; results go with the branch's hand-off.
On a profile that takes DriverDeviation::MetalHalfArithmetic, a half fadd, fsub or fmul whose
flags allow contraction is now the device's 16-bit instruction left undecorated, and Metal's fast
compile folds its conversions away (the deviation's own measurement: billions of operand pairs
differ from the kept instruction). The lowering records PrecisionNote::FastMathRewrites for it, but
the exported float_binop_notes, which validation reads to tell which operations a compile answers
as a near-equivalent, did not predict it, so engine_float_call_notes'
exported_float_notes_are_the_ones_a_compile_records failed (fadd_f16_flagged on moltenvk-m3:
compile {FastMathRewrites}, exported {}). The exported notes now record it under the same
condition the lowering does (f16_arithmetic on the measured basis and contraction allowed). Float's
own contraction notes are unchanged; this note is for the fold, which a lone operation also takes.
Checked by the translator suite run at this commit; its result goes with the branch's hand-off.
half_arithmetic_answers_as_metal held every half arithmetic case to require
VkProperty::MetalHalfArithmetic where the profile takes DriverDeviation::MetalHalfArithmetic. Since
half + - * take the AIR's own contraction, the fast-math case's kernel (fadd fast / fmul fast half)
emits them undecorated and records PrecisionNote::FastMathRewrites instead, so it no longer requires
the property. The case table now says which kernels carry fast math's flags; the test requires the
property where the profile takes the deviation and the AIR forbids contraction, and checks the note
where it allows it. Every word is still held to Metal's on that basis.
Checked by the half lanes run at this commit on the M3, the Iris, the 780M and lavapipe; their
results go with the branch's hand-off, not here.
A half fadd, fsub or fmul on the device's 16-bit arithmetic (ArithStrategy::F16:
MoltenVK, measured, and the float-controls profiles) was always kept apart: a
sum or difference decorated NoContraction and a product as Fma(a, b, -0.0)
decorated NoContraction, whatever the AIR's flags allowed. That holds Metal's
exact half bits at the cost of every fusion the flags allow (AGENTS.md rule 1:
the device's native arithmetic). It now decides as float does (contraction()):
an operation whose flags carry both contract and reassoc is undecorated, its
product a plain OpFMul, and the device's compiler groups and fuses it; any
other keeps today's form.
Notes mirror float's: note_rewrites already records FastMathRewrites where a
neighbour can be rewritten. On MoltenVK, Metal's fast compile folds an
undecorated 16-bit operation's conversions away and answers the float result
unrounded (the MetalHalfArithmetic measurement), so there a fast operation
records FastMathRewrites, whose doc (and docs/API.md's catalogue entry and the
FAST-PATHS device-gap row) now says so, and requires no MetalHalfArithmetic,
which the kept form still requires.
On an owned proxy (hnq_half_layer_composite) on the Iris Xe, the step-1
prototype of this form cut the SIMD8 cycle estimate from 58584 to 33092.
Tests: f16_binary's rounded-result and one-instruction tests under both
contractions; half_arithmetic_on_the_device_takes_the_airs_contraction
compiles fast, contract-only and flagless half + - * on every profile that
computes them in 16 bits and checks the instruction, its decoration, the note,
the requirement and the interpreted answers.
The first proxy compiled SIMD8 and SIMD16 on the Iris Xe with no spills (max
72 live registers), unlike the shader it stands for. Each source is now the
taps' mean, then each tap weighed by its buffer weight and its distance from
the mean, normalized: all 16 half4 taps stay live across the passes, the
register pressure a 16-bit hold would halve. Companions regenerated.
Parked again before translating it; next: translate (Linux build job), retype
(scratch retype16.py), one Iris job of iris/a16/a16n.
Owned MSL of the shape of a fixed-function compositing shader that holds its
colours in half: two layers of three 16-tap half filters, a 17-case colour-op
interpreter run twice a layer, a half tint and a 40-case blend switch. A
measurement proxy for how half values are held on a device with shaderFloat16.
Companions from scripts/regen-air-fixtures.
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.
A copied host buffer (pages the driver can't import, so the GPU uses a copy in its own memory) kept
a whole host snapshot of the copy, 256 MiB of host RAM per 256 MiB buffer, and compared and merged
through it on every commit and completion: 14.4-15.8 ms each way at rest on gem10 for 256 MiB,
270-289 ms back when the GPU rewrote every float, 403-439 ms on the 5080's host.
Now:
- the base is tagged per 1 KiB block; a buffer the GPU only reads keeps none. A written buffer's
base lies in device memory on a device with a staging queue (5080, XTX), with 4 MiB of host tags
plus 1 KiB of host block per block both sides changed; elsewhere (2080, 3090, unified memory) on
the host, 260 MiB.
- the merge is exact and masked per 16 bytes (gpu = copy != agreed, cpu = pages == agreed): a
full store only where every byte qualifies, else the masked bytes (VMOVDQU8 with AVX-512BW),
on 4 threads.
- comparisons run in two passes. Host reads of a VRAM base run at the uncached BAR's speed (14-16
us a 1 KiB block awake, 170-206 us after 3 s idle on the 5080: a whole-written 256 MiB merge
took 175.6 s). So the first pass defers the blocks it would read from the device base; at 32 or
more (READ_BACK_BLOCKS, measured on the 5080 and XTX: copied_read_back_bench) one copy on the
staging queue reads them into a host-visible buffer, waited for; below that, or if the copy fails,
the host reads them, exactly. The staging queue waits only for work the host saw complete, so the
completion thread never waits on the program's queue.
Counters and gauges: copied_base_blocks_read_back, copied_base_host_bytes,
copied_base_device_bytes, copied_base_host_blocks. Docs: FAST-PATHS (base, cost and kernel
bullets with the bench numbers), HOWTO, API.md, copied.rs.
Test a_whole_written_device_base_is_read_back_by_the_gpu: a 256 MiB base both sides wrote whole,
merged after 3 s idle, every block read back and the merge exact, bound 2 s (the 5080 woke from
power-down in 0.94-1.28 s in 3 of 12 bench readbacks): 5080 187/213/267 ms, XTX 176/292 ms.
Verified (potluck jobs, on the branch): device tests 81/81 on the 5080, XTX, 2080 and lavapipe at
9cf5a01c34; unit tests 33/33 and runtime rustdoc at f768cd86d5; api_signatures at a3707a71a7;
clippy three ways at 974d19bb5e. tests::fast_paths runs after the merge.
The 256 MiB bench at the two-pass comparison's tip (gem10, job 17674, load 6-7) took
5.9-6.1 ms each way where nothing changed, 26.1-26.4 ms in and 26.7-27.3 ms back where
every byte changed, and 25.9-27.5 ms (47.4 without masked stores) for the GPU's rewrite of
every float, the snapshot 15.4-15.8, 146-152, 206-215 and 280-289 ms beside it: the ranges
in FAST-PATHS and copied.rs's module docs now cover both runs. And a module-doc line past
100 columns is wrapped.
FAST-PATHS' base bullet gives the host's uncached reads of a device base (9-16 us a block
awake, 170-206 us idle on the RTX 5080 Laptop GPU's host), the blocks kept on the host, the
read back of 32 blocks or more on the staging queue with the crossover bench's figures on
the 5080 and the RX 7900 XTX, the GPU's wake from power-down a copy may wait for, and the
first and later merges back of a 256 MiB copy both sides wrote whole. Its cost bullet gives
the quiet gem10 run's figures (job 17408), and its kernel bullet the 5080's pass figures
(job 17417). HOWTO and API.md name copied_base_host_blocks and
copied_base_blocks_read_back.
Earlier commits 4af4a8665b and 7a93903404 carried doc edits with their code (the split's
sentence in API.md and HOWTO, copied.rs's cost bullet).
The crossover bench (copied_read_back_bench, 256 MiB copy, every other block joined into
one region and every 32nd a region each) put the two reads within a millisecond of each
other at 32 blocks on the RTX 5080 Laptop GPU (9.2-10.0 ms host reads against 9.4-9.9
read back) and the RX 7900 XTX (6.7-7.2 against 6.9-8.3, other work running); from 64 the
copy costs less on the 5080 and no more on the XTX; and the 5080's host reads slow about
tenfold while its GPU idles (130-218 ms against 11.1 for 651 blocks after three seconds
idle), where the copy costs less from 16 blocks. READ_BACK_BLOCKS is 32.
The test of a whole-written 256 MiB base read back after three seconds idle took 187-267 ms
on the 5080 and 176-292 ms on the XTX; it is held under 2 s, not 1, as a copy that finds
the 5080 powered down waits for it to wake (0.94-1.28 s in 3 of 12 copies after three
seconds or more idle in the bench).
Verified: jobs 17623 (5080), 17624 (XTX), 17625 (2080 device tests 81/81) at 9cf5a01c34;
the constant's change itself is built next.
The crossover bench read back every other block of a 64 or 128 MiB copy, one region of the
copy each: the RX 7900 XTX's staging queue (its compute family) took about 6.6 us a
region, more than the host's own reads of its BAR there (about 4 us a block), and the RTX
5080 Laptop GPU's copy engine about 2.5 us. A region costs more than its bytes: 16 KiB at
those links' rates takes under 2 us. runs_of now joins a run with the next where at most
JOIN_GAP (16) blocks lie between them, copying the blocks between, unread, and gives each
block's place among the runs copied (ReadBack's at), where the second pass finds it.
Test: runs a few blocks apart join and blocks find their bytes, a copy's short last block
included. The bench reads every other block (joined) and every 32nd (a region each), over
a 256 MiB copy. Verified: built and run next on um790 and the 5080.
The 4096-block case ran past the 64 MiB copy's 65,536 blocks (its six merges of fresh,
every-other blocks after the smaller cases' need 67,488). 128 MiB holds them all, and
the idle cases take 16 blocks too.
Verified: the 5080 run panicked at 4096 blocks (job 17552); rerun next.
The host reads a base in the device's memory uncached, a block at a time across the bus,
and slower still while the GPU idles: on the RTX 5080 Laptop GPU's host 14-16 us a 1 KiB
block awake and 170-206 us after three seconds idle (COPIED-BASE-SCALE), so the first
merge back of a 256 MiB copy both sides wrote whole took 175.6 s, where the host
snapshot this replaced took about 0.4 s. The memory is DEVICE_LOCAL | HOST_VISIBLE |
HOST_COHERENT, not HOST_CACHED; four threads read it no faster than one.
A comparison now runs in two passes (two_passes, Fetch). The first compares every block
and leaves each block of a device base it would read, and no host block holds, for the
second (Tally::deferred). The second reads those: where they are READ_BACK_BLOCKS or
more, through one vkCmdCopyBuffer of their runs into a host-visible staging buffer on the
device's staging queue, waited for (Held::read_back, copied_base.rs); else, or where that
copy is not made (the device lost, the process exiting, no memory), each by the host as
before. The staging queue waits only for work the host saw complete, so a completion's
merge back waits for its own copy alone, never behind the program's work. A base lies in
the device's memory only on a device with a staging queue, now over a VkBuffer of its own
(TRANSFER_SRC, shared with the staging family) that the copy reads; allocate_copied_base
takes the buffer's requirements. Each block so read is kept on the host as before.
Counted: WorkCounts::copied_base_blocks_read_back. READ_BACK_BLOCKS is 64 until the
crossover bench (copied_read_back_bench) sets it.
copied.rs's module docs say so, and their cost figures are the quiet gem10 run's
(job 17408) in place of the loaded ones.
Tests: a comparison of many device blocks reads them back together (the stand-in's read
back made on the host), below the switch and without a read back each by the host,
keeping and dropping the GPU's writes, all exact; a device test that a 256 MiB base both
sides wrote whole, after three seconds idle, is read back whole in under a second and
merges exactly. Not yet built when committed: built and run next on gem10 and the 5080.