The copy-cause test was inserted between the_host_page_is_known_on_unix and its #[cfg(unix)],
which then guarded the new test and left the host-page test unguarded. Each has its own now: the
cause test runs everywhere, the host-page test on unix alone, as before.
entry is public; its doc linked the private bound_texture, which rustdoc refuses under -D warnings
(AGENTS.md: public docs never link to private items). No code change.
degrade_copied's reason took a String's borrow in one arm of a nested match whose other arms are
string literals; the binding is now typed &str and the arm borrows the String as one, so every
arm coerces to the same type. No behaviour change.
What: AIR names an OpenCL C image's component `unknown` (`texture1d<unknown, read>`), which the
reflection's type grammar did not parse, so a pipeline of OpenCL mode with an image argument had
no reflection (Unsupported, Feature::Reflection, naming the type). Now:
- reflection/types.rs: a texture whose component AIR names `unknown` reflects data type
DataType::None;
- canon::opencl::entry, the entry as a pipeline of OpenCL mode binds it: a 1D image's texture is
the 2D one Metal's OpenCL binds (`texture1d<..>` -> `texture2d<..>`, `texture1d_array<..>` ->
`texture2d_array<..>`, bound_texture), as canon::opencl_1d already reads it, so its binding
reflects TextureType::Type2D / Type2DArray.
Only the reflection reads an argument's type name; lowering and binding are unchanged.
Why: Metal states exactly that. The probe opencl_image_reflection on the M3 Max (macOS 27.0.1,
job m3-max-16390) reflects every image of an OpenCL-mode pipeline as MTLDataTypeNone, whether
read as float, int, uint or half, written, only queried or unused; image1d_t as 2D and
image1d_array_t as 2DArray (as the clmode-images probe found on the M3 Max and a Radeon Pro
5300M). The data type is not the element type a kernel reads: Metal answers None for every one.
Tests: engine_opencl_mode::an_opencl_mode_pipeline_reflects_its_images_as_the_textures_bound_of_no_data_type
reflects an owned fixture (image1d_t arguments read as float, int, uint and half, an
image1d_array_t, a write-only image1d_t, a buffer) and holds each texture binding to the M3 Max's
answer (type, None, access, not depth, length 1) and the buffers to theirs; before this commit
its reflection is refused. reflection::tests::the_type_grammar_names_textures parses the
`unknown` component.
Docs: canon::opencl's module docs and docs/API.md's OpenCL-mode images.
SEMANTICS_VERSION 2033: a reflection the translator refused it now answers.
What: the copied-host-pages announcement of a no-copy buffer, heap or rebind made a copy because
the import the device and the gate admitted failed (WorkCounts::copied_host_buffers_degraded)
said only "their import failed". It now names the failure (FailedImport::cause in
buffer_descriptor.rs): for pages the runtime kept from a driver whose failed import of
unpinnable pages breaks it (RuntimeDriverDefect::UnpinnablePagesBreakHostMemory, NVIDIA's), that
the kernel cannot pin some of them (a dma-buf's mapping, VM_PFNMAP, or one it could not ask
about), and whether a source of their dma-bufs was asked (none given or the device imports no
dma-buf; or the caller's source made none, or the device refused them); for an out-of-memory or
other Vulkan failure, whose import failed (the pointer's, or the caller's dma-bufs' after the
pointer's refusal) and the error. The copy path carries the failure and whether the source was
asked (CopiedFor::Failed(FailedImport), the rebind's Err(Some(FailedImport))); copied_pages
borrows the error. Nothing else changes: the counts, the copies and every refusal are as before.
Why: on the RTX 5080 the consumer's no-copy buffer over a view mapped through two udmabufs was
copied (copied_host_buffers_degraded 1) with no notice line saying why, and finding the cause took
a round trip.
Docs: the CopiedHostPages declaration and docs/API.md's catalogue entry say the reason names the
cause.
Tests: tests::host_memory::a_copy_after_a_failed_import_names_the_failure (no device) holds the
four causes' words. tests::host_ram_device::pages_refused_before_the_driver_with_no_source_are_copied
now announces each copied-host-pages (DeviceOptions::announce_each) and, on a driver with the
defect, asserts each of the buffer's, heap's and rebind's three reasons names the unpinnable
pages, the defect and that no source was asked, printing each (HOST-RAM-COPIED). Before this
commit each reason was "their import failed", which names none of them.
Run on the M3 Max under macOS 27.0.1 (potluck job m3-max-16390): every image argument of a
pipeline of OpenCL mode reflects texture data type 0 (MTLDataTypeNone), through `arguments` and
`bindings` alike, whether the kernel reads it with read_imagef, read_imagei, read_imageui or
read_imageh, writes it as float, int or uint, only queries it, leaves it unused, or reads it
through a sampler; two images of one kernel read as float and int both answer None. image1d_t
reflects MTLTextureType2D, image1d_array_t 2DArray, image2d_t 2D and image3d_t 3D; read-only and
write-only as declared; not depth; array length 1. A __read_write image1d_t (OpenCL C 2.0) makes
no library ("Undefined symbol(s) for architecture 'air64'").
The library's serialization, meant to show the AIR's type names, is dropped: Metal answers
"MTLLibrary is not formatted as a MetalLib file" for a library of OpenCL C. The reflection part
is unchanged from the run.
Our own OpenCL C kernels, one library each: image1d_t, image1d_array_t, image2d_t and image3d_t
arguments read with read_imagef, read_imagei, read_imageui (and read_imageh where the compiler
takes cl_khr_fp16), written, only queried, unused, read through a sampler, two images of two
element types, and a __read_write image. For each, the pipeline of OpenCL mode's reflection
(arguments and bindings: texture type, texture data type, access, depth, array length) and the
texture templates the serialized library's AIR names.
Not yet run.
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.
Four always-on O(1) counters for an unshared queue's waits over 16 ms: the batches in flight
ahead of it (summed and most), the longest single run during it, and the waits behind one
run over 16 ms. They tell many batches queued ahead from one long batch, which decides the
compositor-isolation work on one-graphics-queue drivers. The queue_share example's frames
mode measured both shapes on the 780M (potluck m3-max-16449).
The compositor-isolation decision needs to know, for an unshared queue's command buffers that wait
over 16 ms behind another command queue's work on a one-queue GPU, whether they wait behind many
batches queued ahead or behind one long batch. Four counters, always on, for those waits:
- WorkCounts::unshared_waits_over_16ms_batches_ahead: the batches in flight ahead of each on its
VkQueue as its first batch took its value (timeline values past the one the host saw complete),
summed; ..._most_batches_ahead the most;
- ..._longest_runs_nanos: the longest run each waited for, summed, where a run is the host's view of
how long the VkQueue's oldest batch in flight was so (completion seen to completion seen, or from
its submission onto a VkQueue the host saw idle);
- ..._behind_one_long_run: those whose longest run alone was over 16 ms.
How (queue_wait.rs): each VkQueue keeps the host time its oldest batch became so, and, while a wait
is timed, a sliding maximum of the runs seen since the oldest timed wait began (a deque falling from
the front; a wait's longest run is its front once runs from before it are dropped). O(1) a
completion amortized, plus one clock read per completion; no more runs kept than the batches the
oldest wait was behind.
The queue_share example gains a `frames` mode: a compositor committing one draw every --period-ms
(16) beside an application keeping --in-flight long command buffers of --long-ms (30) in flight,
with the compositor's latencies, the application's rate and these counts.
The API signatures table is re-blessed (scripts/api-signatures/signatures.py --bless).
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 command buffer part that runs nothing gives its encoders' takes of a tiled texture's
copy back at State::fail_part, so the next use takes the copy again. Verified by the
branch's runs: lavapipe 3 of 4 new tests fail before (potluck m3-max-16419), 228/228
after (m3-max-16430); RADV PHOENIX 228/228 (m3-max-16429); lint m3-max-16404.
A tiled texture of more than one level over a buffer takes its copy of the
bytes at the first use encoded after its making or a did_modify_data,
which clears its mark. Where that encoder runs nothing because its command
buffer failed before it ran (committed as failed, an encoder a failure
names, a protection fault, a submission that fails EncodedUseRebound or
DetachedBacking, a hang's discard or recovery, a predication record that
drops it), the copy was never taken but the mark stayed cleared, so every
later use read zeros or an older copy until the next did_modify_data.
The take is now given back where the runtime knows its recording will not
run: State::fail_part, the one point every such failure releases a part
through. The mark is an AtomicU64 whose low bit is the mark and whose
upper bits count the takes; LevelsCopy::take returns the take's number,
and give_back(number) sets the mark again only where that take is still
the latest and nothing set the mark since (a later take holds its own
copy; a did_modify_data since already asks for one), so giving back twice,
or after a later take, changes nothing. shadow::Takes now holds each take's
number and a weak hold of the texture's copies; every ended encoder's
record keeps its takes (not only one whose log is kept), and a recorded
segment carries its own core's takes, both given back by fail_part.
ShadowSync::forget gives its takes back by number too.
An encoder split into parts at a host step gives back every take of its
own where any of its parts runs nothing, so a take that ran in an earlier
part is taken again at the next use when only a later batch fails; that
gap is in docs/FAST-PATHS.md's known gaps. docs/API.md and shadow.rs state
the rule.
Tests: tests::shadow gains a unit test of the give-back's rules (latest
take, a later take, a mark set since, twice, forget). The device tests of
the previous commit fail without this change; the runs of both commits are
in the report.
A tiled texture of more than one level takes its copy of the bytes at the
first use encoded after its making or a did_modify_data, which clears its
mark. Where the encoder that took it runs nothing (its command buffer
committed as failed, the one encoder a failure names, or a submission that
fails because a buffer it named was detached), the copy was never taken,
yet the mark stayed cleared: the next command buffer took no copy and read
zeros. These device tests fail such a command buffer and read the levels
through the next one, which must take the copy; and, as a control, keep a
take that ran when only a later encoder fails.
The re-encode test's helpers become pub(super) for the new file. Not run
yet: this commit only adds the tests.
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 runtime's creation log (METAL2VULKAN_LOG_PIPELINES) now writes one line per compute
pipeline, and the translator binds a swizzled view at a storage slot its function only
queries without the swizzle (SEMANTICS_VERSION 2033 on the branch). Verified by the
branch's runs on lavapipe, the RX 7900 XTX and the RTX 2080 (potluck m3-max-16392,
16397, 16413, 16421).
opencl_mode_vstore_half_stores_every_rounding_as_the_device_converts asserted
round-to-nearest-even on every device. The RTX 2080 (job m3-max-16397) stores
1 + 3 * 2^-12 as 0x3c00, rounding toward zero, and its pipeline announces
native-half-conversion: without RoundingModeRTE Vulkan leaves a conversion's
rounding to the device, and NativeHalfConversion's bound already names
NVIDIA's toward-zero rounding (the RTX 3090) and a flushed 16-bit denormal.
The test now listens for native-half-conversion at every occurrence and, where
the module records it, also accepts the half rounded toward zero (or the zero
of its sign for a denormal); where it does not (RADV, ANV under the float
controls), it still requires the nearest-even half. Every rounding form must
still store what vstore_half stores. noting_device takes the kind to hear.
Verified: lavapipe, the XTX and the RTX 2080 (job ids in the report).
The line named the SPIR-V entry point (main) and lacked the 'metal2vulkan: pipeline creation: '
prefix the render lines carry. Variant::of now takes the function's name and keeps it with the
kernel stage (VariantObjects::log_kernel, creation_log::LoggedKernel) while the log is on; the
variant objects' constructors keep nothing.
METAL2VULKAN_LOG_PIPELINES logged render VkPipelines only, so a consumer reading the log for a
compute state's notes (an OpenCL-mode kernel's native-nan-encoding) found nothing. A compute
variant now keeps its kernel stage while the log is on (VariantObjects::logged, None while it is
off), and each compute VkPipeline it makes logs one line through the device's sink (id name
metal2vulkan-pipeline-creation, Info): the kernel's entry, its SPIR-V (hash and words), each
specialization constant (id, meaning, value), the precision notes the stage holds under that
specialization, and the creation's wall time. No numbering, diff or split: a compute state's
pipelines differ by their specialization alone, which each line prints whole. Nothing is kept
or measured while the log is off.
Docs: creation_log's module docs, env_vars' METAL2VULKAN_LOG_PIPELINES, docs/API.md.
The consumer saw vstore_half_rtz of a NaN store 0x7fff on an RTX 5080 where Metal stores 0x7e00
(the device's own float-to-half conversion, kept by the native-arithmetic rule), with no
native-nan-encoding notice from the OpenCL-mode compute pipelines and no compute line in
METAL2VULKAN_LOG_PIPELINES. Three checks:
- the translator: an OpenCL-mode vstore_half_rtz and a plain fptrunc stored as half record
PrecisionNote::NativeNanEncoding on every committed profile (nvidia-rtx5080-laptop among them),
but where the device's narrowing is measured to move a NaN as Metal's (MetalNanMoves), which
the module then requires;
- the runtime: a vstore_half of four NaNs stores half NaNs in every rounding's form and the
compute pipeline announces native-nan-encoding (the device announcing the kind at each
occurrence, so a render pipeline's earlier notice cannot hide it);
- the creation log: with METAL2VULKAN_LOG_PIPELINES set, a child process's dispatch logs a line
for the compute VkPipeline, naming the kernel, its module, its specialization and its notes.
The last fails before the change that follows: the log names render pipelines only.
A guest's OpenCL kernel that only queries a write-only image Apple's OpenCL binds as a swizzled
view (CL_BGRA over an RGBA8Unorm view, and on an M3 Max every CL_UNORM_INT8 order but RGBA and
RGBx) failed: the plan joins a storage slot to the swizzled-storage variant only where its
function reads or writes texels, so a query-only slot kept the texture's swizzle on its storage
view, which Vulkan cannot swizzle, and the runtime refused the binding
(NotImplemented(TextureSwizzle)). The guest then read zeros.
A query reads no texel, and what it answers (the view's size, levels and layers; an OpenCL
image's order and data type, which the third hidden buffer holds) no swizzle reaches. Measured
on an M3 Max, macOS 27.0.1 (probe opencl_swizzled_images, job m3-max-16336): plain Metal's
get_width/get_height of a swizzled view at an access::write slot answer the view's size, and
OpenCL mode's width, height, order and data-type queries answer the size and the hidden words,
on every swizzle measured. So the plan now binds such a slot's storage view with no swizzle
(ImageViewDesc::shader_swizzle, under no variant): exact.
The same probe confirms the rest of the contract the crate already builds, in plain Metal and
OpenCL mode alike: reads (read(), read_write, sample, read_imagef with and without a sampler)
answer the swizzled texel, and writes (access::write, read_write, write_imagef) store it with
the swizzle undone. The channel order table and the swizzle never both apply: the table answers
queries only, the swizzle moves texels only.
Docs: ImageViewDesc::shader_swizzle, the runtime's binding_view and view_plan, docs/API.md's
OpenCL-mode images. REFUSALS.md regenerated, unchanged.
SEMANTICS_VERSION 2033.
The M3 Max's answers for swizzled texture views (probe opencl_swizzled_images, job
m3-max-16336, macOS 27.0.1), as device tests in OpenCL mode over 4 x 2 views of RGBA8Unorm and
R8Unorm made with the swizzles of OpenCL's BGRA, ARGB, A, INTENSITY and LUMINANCE orders (and
the identity):
- a write-only image the kernel only queries answers the view's width and height and the third
hidden buffer's order and data-type words;
- a write-only image's write stores each channel from the first lane whose source it is (the
swizzle undone);
- a read-only image's read, without a sampler and through a nearest one, answers the swizzled
texel;
- a read_write image (Metal's; Apple's OpenCL compiler takes no __read_write image) reads and
writes by the same two rules.
And a translator test: a storage slot (access::write, read_write) whose function only queries
the texture, bound to a swizzled view, plans no variant and binds the view unswizzled, on every
committed profile.
The query tests fail before the fix that follows: the binder keeps the swizzle on a storage view
it cannot swizzle and the consumer refuses it (NotImplemented(TextureSwizzle)).
Our own kernels over 4 x 2 views of RGBA8Unorm and R8Unorm textures made with the swizzles
OpenCL's channel orders imply (BGRA, ARGB, A, INTENSITY, LUMINANCE): plain Metal's
access::write, read_write, access::read, access::sample and a query-only write slot, and the
same shapes in OpenCL mode driven directly; plus a trace of the textures Apple's OpenCL binds
for an image of each CL_UNORM_INT8 order. Not yet run.
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 device's submission checks ran a "follows" check at every Linux device's creation: they
imported two pages of their own by pointer, submitted a copy, mapped new anonymous pages over
the first page (mmap MAP_FIXED) while that import lived, copied again, and only then freed the
import. That remap under a live host-pointer import is outside VK_EXT_external_memory_host's
contract ("Whether device memory objects imported from a host pointer hold a reference to their
payload is undefined ... the application must ensure that the imported memory range remains
valid and accessible for the lifetime of the imported memory object"), so the verdict rested on
undocumented driver behaviour, and it ran on every device's making.
Its one reader was the idle release of a no-copy buffer's pointer import (host_residency.rs,
Again::pointer). Under HostMemory::new's contract the pages at the pointer stay the same while
the buffer lives, so an import again at the same pointer reads what the kept one read on every
driver: "follows" mattered only for remaps that break the contract. The release is now gated on
what it is for, the per-submission cost of a held import, which the existing import tax check
measures (32 imports of 16 MiB in all held through timed submissions):
- RADV and ANV on i915 pay it: idle pointer imports are released, as before.
- NVIDIA's driver (RTX 5080 Laptop GPU, 615.71.09: 2.1-2.2 us a submission with and without
held imports) and MoltenVK pay none: pointer imports stay imported, as before on NVIDIA, now
because a release would save nothing and cost the next blit an import.
- lavapipe, which the follows check answered yes on, is released only where its tax check
answers Holds.
Buffers made before the check answered keep their imports, as before.
Changes:
- submit_check.rs: the follows check is gone (its remap, its bound buffer, its copy command
buffer, Check::Follows). A record holds two verdicts; CHECK_VERSION 6 -> 7, so earlier records
are never read and every driver measures again. The checks' pool no longer resets command
buffers (only the copy was re-recorded).
- Public API, breaking: Device::pointer_imports_follow_their_address is removed. A hidden lane
accessor, Device::releases_idle_pointer_imports, says whether the device releases idle pointer
imports. api_signatures.tsv re-blessed for both. reims-vgpu's no_copy_remap_linux.rs test
called the removed method (main is telling reims).
- Docs: HOWTO section 6, the FAST-PATHS known gap about remaps (now: what a no-copy buffer reads
after a remap under it is unspecified; a released import's next blit imports the new pages; the
RADV file-page loss stays), the RADV per-page cost gap's gate, Device::host_range_remapped,
host_memory.rs, host_residency.rs, KeptBecause and WorkCounts docs, the validation lane.
- Tests: the pointer residency and unmap-order tests hold the device to the release
(SubmitChecks::force on the import tax), so the release path runs on every Linux device
whatever load does to the check; a new test checks the natural gate
(an_idle_pointer_import_is_released_where_held_imports_cost_submissions), and a new device test
checks a device's checks make and bind no buffer and free every import by their answer
(a_device_s_checks_map_no_pages_over_a_live_import: on Linux it fails with the follows check,
which made and bound two buffers).
RUNTIME_VERSION is not bumped here (bumped and re-pinned at landing).
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 tiled texture of more than one level over a buffer is a copy of the bytes
taken at use: the first use encoded after its making, a did_modify_data or
a level-0 replace_region clears the texture's mark and records the copy in
and the later levels. A rebind of a no-copy buffer (or heap) the encoder
also named, before its command buffer's first submission, encodes the
encoder again and puts that recording in place of the first, which is never
submitted. The encoding again found the mark already cleared, recorded no
copy, and the texture's levels kept zeros or an older copy for good; a
did_modify_data made after the commit was cleared by the encoding again
instead of the next use.
The decision now belongs to the encoding. ShadowSync notes, in order, what
each first use of a copy taken at use decided (shadow::Takes); the ended
encoder's record keeps that with its log, and the core an encoding again
records into (EncoderCore::replaying, fed by reencode.rs through
State::replaying_takes) takes each copy where the use in its place took it,
never touching the mark. Its forget gives nothing back to the mark either.
Other per-encoding state checked for the same shape: the shadow carry (an
encoding again starts with none and copies the truth in, which earlier
encoders copied back to as they ended; drops-writes shadows are never
carried), gated copy-ins and standings (decided at batch submission, which
sees the recording put in place), heap tiled and multisample sample moves
(planned per recording, no mark), and segments recorded again on the GPU
alone or at a host step (their shadow copies were planned by the encoder,
not decided again). None consumes a mark at encoding.
Verified at the parent (66b00df138), lavapipe, jobs m3-max-16324/16333:
all four tiled_texture_reencode tests fail (levels read zero through the
encoding again; the next use after a did_modify_data took nothing). The
new CPU unit test in tests/shadow.rs covers the decisions directly. Runs
of this commit follow in the report.
A tiled texture of more than one level over a buffer takes its copy of the
bytes at the first use after its making or a did_modify_data, and the
encoder that first uses it consumes the texture's mark as it is encoded.
A rebind of a no-copy buffer that encoder also named, before its command
buffer's first submission, encodes the encoder again from its log and puts
that recording in place of the first, which is never submitted. These
device tests drive that sequence (a command buffer held behind a shared
event wait, its one encoder the texture's first use and a writer of a
no-copy buffer, the buffer rebound before the signal) and read what the
encoding again left in the new pages: a blit of every level, a kernel's
sample at LOD 1, two rebinds in a row, and a did_modify_data made after
the commit, which the next use must take.
The tiled texture test's helpers become pub(super) for the new file.
Not run yet: this commit only adds the tests.
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.
What: FAST-PATHS's known gap of NVIDIA exits now names the cause and the measured rates, and
HOWTO (section 8), the runtime README (at the process's exit) and API.md's accepted differences
tell consumers to drop the runtime's devices before the process exits on that driver.
exit_guard.rs and tests/exit_guard.rs, comments only, say that the 5080's fault in
libnvidia-glvkspirv.so also comes with no making in progress.
Why: reims-vgpu's test an_adopted_device_starts_its_in_place_check (device kept in a static,
check waited for to its end, then the test process exits) died with SIGSEGV after "ok" on the
RTX 3090. Reproduced with the runtime alone (a scratch example: device made on a named thread with
an empty shader cache of its own, in-place check started and waited for, device kept, main
returns). Every core shows the same thing: a worker thread of NVIDIA's driver, started from the
thread that made the device and so carrying its name, faulting at libnvidia-glvkspirv.so+0x363a8
(`mov 0x18,%rax; ud2`, a null dereference trap) while the main thread runs libEGL_nvidia.so's exit
handler inside exit(). No runtime thread was in a section or in the driver. reims's two cores
on that node (pids 106291, 170154) faulted on a thread named after the test thread, which libtest
joins before printing "ok", so a thread the driver started.
How verified (RTX 3090, NVIDIA 620.70.06, 8 processes at once, 80 exits each):
- exit right after the check ended, device kept: 6/80 SIGSEGV (potluck m3-max-16257)
- exit 3 s after the check ended: 0/80 (m3-max-16279)
- device dropped before the exit: 0/80 (m3-max-16280)
- no check, exit right after creation / 6 s after: 0/80 each (m3-max-16278, m3-max-16277)
- lavapipe (Mesa 26.2.6), exit right after the check: 0/20 (m3-max-16283)
Vulkan has no call that waits for the driver's worker, and a dropped device leaves none, so
the remedy is the consumer's drop, documented; no runtime behaviour changes.
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.
Two claims of "Unmapping host memory" cut to their evidence: with neither a deallocator nor a
keep-alive, a texture released while a command buffer submitted before may read it holds the import
until that command buffer completed (HostMemory::new's contract says so); and the failed
submission with the device lost after an unmap is ANV's (host_residency.rs's measurement), not
measured on RADV.
Verified: docs only.
A Radeon 780M under Linux 7.3.3 oopsed in amdgpu's mmu notifier (amdgpu_hmm_invalidate_gfx,
LIST_POISON2 in a bo_va's status list) while a consumer's thread unmapped a view whose pointer import
was still alive; the consumer dropped the import after the unmap. VK_EXT_external_memory_host
(VkImportMemoryHostPointerInfoEXT): "the application must ensure that the imported memory range
remains valid and accessible for the lifetime of the imported memory object". vkFreeMemory: a
bound buffer or image may hold the payload until it is destroyed. So the objects go first and the
pages after.
The runtime already keeps that order, and this commit changes no behaviour. A no-copy object's
keep-alive is dropped, and with none its deallocator runs, only after its import's vkFreeMemory
returned, on whichever thread freed it. That covers the releasing thread, a queue's thread at the
completion of the last command buffer that held it, a handler thread where a keep-alive alone
waits, and the import made again after the residency thread released it while idle. Imports never
go to the free thread. The one exception is a buffer lying in another live buffer's import, whose
own contract keeps the pages mapped.
The order was spread across private module docs. It now has one statement where consumers read:
- docs/HOWTO.md, "Unmapping host memory": the spec's rule, each object's signal, the threads that
free imports or submit over them, and what an unmap made first did;
- the runtime README's host-memory bullet;
- the rustdoc of HostMemory::new (the spec's rule, and when a command buffer lets go: after its
completed handlers, before wait_until_completed returns), Deallocator, KeepAlive and
Device::host_range_remapped. That call's "they may be unmapped" read as a licence to unmap under
a live buffer; it now says the call does not mend that.
New device test tests/unmap_order.rs (Linux, m2v_cpu_icd or m2v_gpu):
- 48 rounds. Each round covers a released buffer, a buffer released while a committed copy of it
waits for an event, and (where pointer imports follow their address) a buffer whose import was
released while idle and made again by a blit. Each case runs with a keep-alive and with a
deallocator.
- Another thread submits copies between the device's own buffers throughout.
- Each signal reads WorkCounts::host_imports_live, which must already be back at its baseline,
then unmaps the pages.
- It asserts that the held cases signalled on a runtime thread and not before the event, that the
idle releases and imports again counted 96 each, and that every command buffer completed with no
device loss or recovery.
`a_kept_pointer_import_reads_the_pages_a_remap_put_at_its_address` mapped new pages over a no-copy
buffer's pages while the device's import of them by their pointer lived. VK_EXT_external_memory_host
requires "the imported memory range remains valid and accessible for the lifetime of the imported
memory object" and leaves undefined whether the import holds its pages, so what that import reads
after the remap is not Vulkan's to answer. Removed rather than reordered: released first, it is the
test that already exists (`a_released_pointer_import_...`), and nothing in the product depends on
it. It only cross-checked the verdict of the device's own follows check (`submit_check.rs`), which
the residency reads and which measures itself.
The released-first test stays: its import is freed before the remap, so no import lives over the
pages as they change. It is renamed
`a_released_pointer_import_is_made_again_over_the_pages_mapped_at_its_pointer`, since no kept import
is left to compare it with. The module docs now say that only the hazard test
(`a_file_s_pages_mapped_under_a_kept_pointer_import`, opt-in under m2v_gpu_hazards) maps pages over
a live import, on purpose, to measure what a driver then does.
Verified: compiles under --cfg m2v_cpu_icd and m2v_gpu (the potluck jobs in the next commit's
evidence); no other file named the removed 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.
On a GPU with one graphics queue (RADV, ANV, lavapipe) every command queue, the unshared ones
included, submits to the same VkQueue in order, so a compositor's command buffer waits behind an
application's long one. Deciding whether to build compositor isolation needs to know how often
that happens in real use, so the runtime now counts it, always on:
- WorkCounts::command_buffers_behind_other_queues: command buffers whose first batch took its
value on a VkQueue while the latest batch of another command queue's before it there was not
seen complete;
- ..._over_16ms and ..._over_33ms: those whose wait, from the first batch's submission (or hold
in a group) to the host's observation of that other batch's completion, ran over 16 or 33 ms
(an upper bound: the host sees a completion after the GPU's end);
- wait_behind_other_queues_longest_nanos: the longest such wait;
- the same four with an unshared_ prefix for queues made with new_command_queue_unshared.
How (queue_wait.rs): each VkQueue keeps its last batch's value and command queue, the value of its
latest batch of another queue than that one, and the waits being timed, in the order of the value
each waits for, which never falls. The submission side runs under the scheduler's lock where a
batch takes its value (command_buffer/submit.rs); the completion side where the host publishes a
new timeline value (QueueSlot::completed). O(1) per batch and per completion; no command queue of
the device is scanned. The runtime's own submissions (staging, checks, a step's run again) are
not seen.
Test: queue_share_device::a_command_buffer_behind_another_queue_s_long_one_counts_its_wait (two
queues on one VkQueue, a ~30 ms command buffer then a short one: one wait from another queue,
bounded below by the long one's GPU work left and above by the host's time around it; none from
the same queue; the unshared tallies from an unshared queue). The API signatures table is
re-blessed; docs: WorkCounts, the runtime README's unshared queue entry, FAST-PATHS known gap.
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.
heap_texture_256 is held to 17.25 allocations a call (HELD), measured where its image lies in the
heap's memory. On the Radeon 780M (RADV PHOENIX) it does not: the group's optimal 256x256 BGRA8
image takes 262144 bytes at an alignment of 65536 there, where Metal answers 262144 at 128
(measured by a probe build, job m3-max-16243), so the texture is a shadow of Metal's tiles in
the heap's bytes (`heap_textures_tiled`), its image in memory of its own, and the gate failed
(75.25 a call at the base).
After the removals on this branch (one unzeroed staging buffer for the moves, the planes and
levels planned once, the shapes as arrays, the owned sets written from stack arrays) the path
makes 28.25 a call on the 780M: 11.25 for the texture's plan and object, 17 for the route (moves'
planes and levels 2, image 1, staging buffer 3 and its copies back 1, the kernel's two
descriptor sets from a pool of their own 5, copies into the image 1, the shadow's state 4), each
site traced by the probe. HELD_ON_PATH holds a call to its own bound where it moved the path's
mark (here `rt_heap_textures_tiled_at_call`), in place of HELD's row of that count; every other
call keeps HELD's row. check_held checks the mark and the count by name, as it does HELD's.
The route's check (`tiles_serve`, through `HeapTiledCopies::fit`) laid out the tight planes and
the kernel's levels, and the making laid them out again. `HeapTiledCopies::moves` now plans them
(with the depth clamp, which only the making applied) and hands them back as `TiledMoves`, which
the heap image carries on `AliasRoute::Tiled` (`HeapImage::moves`, set wherever that route is
chosen: the heap plan, its multisample shadow, the host-pages plan) into
`HeapTiledCopies::new`; the cheap checks (copies, size) come before the planning. The surface
depth twin plans its moves the same way and takes its copies from its planes
(`copies_into`) in place of `heap_planes`' three lists, filtered.
`TiledTexelsModule::shape` returns its bytes as an array of SHAPE_WORDS words, as the other
modules' shapes do, so a texture's two shapes take no allocation (api_signatures blessed).
OwnedSets::write takes each set's (buffer, offset, range) as an array of the kernel's N storage
buffers and writes each set from two stack arrays (its N buffer infos and N writes), one
vkUpdateDescriptorSets a set: no list of infos or of writes. Its callers pass their arrays as they
are, where each built a Vec a set (`vec![..]`, `.to_vec()`). A kernel whose storage buffers are
not N is refused (internal), as before a set of another length was.
On a tiled heap texture (heap_texture_256 on the Radeon 780M) this drops the two lists left per
making; the before/after per-call counts are in the branch's report.
- a_heap_shadows_planes_answer_alike_however_many_times_they_are_laid_out (tests/heap.rs):
heap_plane_bytes is heap_plane_layout's end, and copies_into of the planes laid out once is
heap_planes' copies into the image, over colour, block-compressed, two-aspect, 3D, array,
mipmapped, 4:2:2 and 4:4:4 textures (the latter two's rows share bytes).
- a_pools_descriptors_are_counted_from_its_sets_needs_as_its_room_holds_them
(tests/descriptor_arena.rs): SetNeeds::pool_descriptors is Room::of's descriptors, saturating
alike.
Run with the touched tests in the report's jobs.
On the 780M PHOENIX a heap texture is held as a shadow of Metal's tiles (heap_tiled.rs), and
its making allocated 75.25 times a call against the 17.25 the direct route measures (host_ab
percall heap_texture_256, job m3-max-16125; the allocation probe's call sites). Besides its
descriptor sets (the commit before), the work it repeated or made for nothing:
- Three buffers of the runtime's own for its moves (staging, tight elements, shapes), each
zeroed by a fill registered at its making: 12 allocations. They are now one buffer
(Scratch: the texture's bytes, then the tight elements, then the two shapes, each part at a
multiple of SHAPE_SLOT), made unzeroed: every move writes each byte it reads first, which
Scratch's docs show part by part; fit checks the one buffer against the device's buffer
length.
- The heap planes laid out four times: shadowable, which asks only their length, now counts
it without a list (heap_plane_bytes), as do the depth-stencil-apart route and the 4:2:2
answer; the tiled image takes its copies from the tight planes it lays out
(copies_into), and heap_planes builds no list per plane (each_plane_copy).
- Metal's tiles cloned twice: heap_plan keeps Metal's own where it tiles the texture and takes
the made ones only otherwise, and heap_texture_at moves them into the image, its notice and
count read first.
- The kernel's levels: no list of each part's planes (fit and new); new takes the planes and
the copies it keeps by value, offsets the copies in place, and makes its two moves without a
list; the sets' ranges are arrays; TiledTexelsModule::shape builds its words in an array.
Test (device cfgs): heap_tiled_scratch sets every byte of a 100 x 70 tiled texture's staging
buffer to a poison byte before its first use, a copy into every texel and a copy into a part,
and checks the texels each reads and leaves, and that no poison word reaches the heap's bytes.
Not run yet: the build, the PHOENIX and lavapipe percall runs and the lint, which the report
carries.
OwnedSets::write copied each set's ranges into an OwnedSet, the kernel into a list of
copies, and went through write_each, which built a list of image infos, one of storage
image infos and one of buffer infos per set, nested, and a writes list that grew as it was
pushed; and it took the kernel's set needs once per set. A tiled heap texture's two sets
cost 18 allocations that way on the 780M PHOENIX (host_ab percall heap_texture_256, the
allocation probe's call sites, job m3-max-16125).
- write takes any list of ranges (a slice, an array or a Vec, so every caller stays as it
is), checks them against the kernel, allocates the sets with the kernel's needs taken
once, and writes one list of buffer infos and one of writes, each sized up front.
- write_each and write share the opening checks and the pool's count (OwnedSets::opened).
- A fitted arena counts the descriptors of the pool it would open from the set's needs
(SetNeeds::pool_descriptors) instead of building that pool's Room to sum it.
Not run yet: the build, clippy and the PHOENIX percall run come with the commits after.
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.