Three changes to how the runtime holds device memory, and a diagnostic to see it.
What changes:
- METAL2VULKAN_LOG_MEMORY, a default-off diagnostic (set to anything but empty or 0). A device
logs one line per VkDeviceMemory it allocates, imports or frees, through its message sink at
Info severity (id metal2vulkan-memory), else on stderr: what it is (a pooled or dedicated block,
a host-memory import with its host address, a dma-buf import), its handle, memory type, bytes
and device address range. Memory with the device-address flag but no buffer of addresses is
asked through a buffer made over it and destroyed at once; on NVIDIA that address is the GPU
virtual address a fault report names. A block parked until the batches in flight complete is
named as it starts to wait. Each pooled placement of at least 4 MiB also prints a line as it is
placed and as it is returned. Off, nothing changes: the switch is read once, no buffer is made
and no line formatted. Documented in env_vars.rs and docs/API.md.
- A pool keeps up to two empty pooled blocks (at most 128 MiB a pool), where it kept one. Every
kept empty block but one goes once it stayed empty for one second, checked as a placement
returns, and every kept empty block of a memory type goes before a block of that type fails to
be made, and the make is tried again. New WorkCounts pooled_memory_blocks_made and
pooled_memory_blocks_freed.
- Neutral images and interlocked passes' storage placeholders take a pooled block of images on
ANV and RADV, and a block of their own elsewhere (memory::binds_wait, from the driver id).
Why:
- An RTX 5080 run of the consumer lost its device on a copy engine's write to an unmapped page,
and the fault report names only a GPU virtual address; the log places it against the memory the
runtime held.
- With one kept empty block, the block made so the encodings find room was mostly the kept one,
so a frame's buffers returned each frame cost a vkAllocateMemory and a vkFreeMemory a frame (a
guest boot on ANV showed the alternation in its buffer pool through the log).
- ANV on i915 and RADV on amdgpu list every VkDeviceMemory in every kernel submission at a cost
per object; in the consumer's frames on the UHD 770 those images were 15 of the 17 dedicated
blocks. A bind into a block with queued work waits for that work on NVIDIA's driver, and
lavapipe waits for its queue lock at the view's making, so those keep their own blocks.
Verified:
- tests/memory_log.rs (device test): a block's address asked through a buffer made over it equals
its buffer of addresses' address; a CPU test holds a placement line's words.
- runtime_lane::pool_churn (new): seven 9 MiB private buffers a frame, filled, waited for and
dropped; over 32 frames no pooled block made or freed. Blocks made and freed a frame went 1.00 /
1.00 -> 0.00 / 0.00 on RADV (RX 7900 XTX) and ANV (UHD 770); the test took 1.20 and 0.96 s
before and 0.52 and 0.47 s after on ANV. tests::memory (17) passed.
- A probe outside the runtime measured a bind into a block with pending work at 0.2-1.8 us and
the view at 1.8-5.1 us on ANV (UHD 770), 0.0-0.6 us and 0.6-2.0 us on RADV (Radeon 780M and RX
7900 XTX), the submission still pending after both, as with a fresh block. The kernel_textures
neutral lane now checks that a pipeline state's neutral images add no dedicated block on ANV and
RADV; it, the first-use neutral lane and the placeholder framebuffer lane passed on the UHD 770;
the runtime's heap and memory unit tests 83 passed.
- clippy -D warnings (plain, m2v_gpu, m2v_cpu_icd) and rustdoc.