A texture over a buffer in host memory's import (Device::import_host_memory) used to be the counted
copy at every use. Its bytes were copied into an image of its own before each submission that used
it, and back after each write. Now it is in place: the device's linear image, made for host
memory's handle, bound in the import's own memory. The condition is that the external image query
for VK_EXTERNAL_MEMORY_HANDLE_TYPE_HOST_ALLOCATION_BIT_EXT answers the linear image importable,
compatible and not dedicated-only, and that the image passes the tests of any texture over a
buffer in place.
This is not a new copy. It is the existing last form made smaller: one copy pair in the texture's
life, in place after it, on documented behaviour only.
- Created UNDEFINED: an image bound in imported memory names the import's handle type
(VUID-vkBindImageMemory-memory-02989), so it starts undefined
(VUID-VkImageCreateInfo-pNext-01443).
- Saved and written back around the one transition: a move out of the undefined layout may
discard the bytes (Vulkan 1.4, section 7.1.1).
- Host access by memory-domain operations: host memory has no other side whose release an acquire
could match (section 11.2.6).
The image's one move home is in the upload ahead of the first command buffer submitted after the
making, from any queue, in this order:
1. a barrier from every earlier command's writes, including earlier submissions on the one
queue, to the save;
2. a copy of the bytes bound under the image into a Private block taken at the making;
3. the move, in a barrier that waits for the save's reads;
4. the write-back, with a barrier between write-backs, since two imports of the same pages may
meet;
5. a barrier from the write-backs to every later command and the host.
The block goes back once the upload retires. A later use copies nothing. Where the query offers no
linear image of the format and usage, the texture stays the counted copy at each use. On the Mac
driver that is every render target, since it makes no linear colour attachment.
Counts:
- the two copies count in Metrics::over_copies_host_memory (and over_copies, over_copies_imported,
bytes_copied), each of the bytes bound under the image;
- new: Metrics::textures_in_place_over_imports counts each texture in place over an import, host
memory's or a dma-buf's, at its making;
- the replay's frame metrics carry it.
Docs, in this commit:
- AGENTS.md rule 3's first exception gains the planner's clause verbatim;
- the runtime README's Imported blocks gives the form, and states the two VUIDs' rule in plain
words;
- its known gap gives the pair, the window while the upload runs (a host write may be lost, and a
host read may see the bytes undefined), and which formats and usages keep the per-use form on
which driver, by query;
- REPLAY-STREAM.md and Buffer::new_texture's doc follow.
Tests:
- host_in_place gains two checks: a fill submitted before the making and not waited for is in the
first read, and the texture counts once at its making;
- over_causes, import's texture test and imported_aliases now take either form, asserting in
place on lavapipe and the copy where the query refuses.
Verified on the system lavapipe (llvmpipe, LLVM 23.1.4), job m3-max-81271, filter host_in_place,
over_causes, import's texture test, imported_aliases, import_overs and layouts: 17 tests.
- Red at the commit before: host_in_place fails at its in-place assertion; the other 16 pass.
- Green, at a tree whose code equals this commit's: 17 of 17 pass. The restore pair is 2 copies,
512 bytes. In imported_aliases, the Half textures are in place, two pairs for two textures over
one import. Clippy -D warnings under --cfg m2v_cpu_icd is clean for the runtime and validation.