Lay a no-copy buffer over a live copied host buffer's bytes in its copy

What: a copied host buffer (the caller's gate refused the import, or an
admitted import failed) now joins its memory and is placed as an import is
(`HostAliases::join` with `Kind::Copy`, `HostAliases::place`). A later
no-copy buffer over exactly the same first byte and length, of either
storage mode, finds it (`HostAliases::import`: an import of its class,
else the live copy), lies in it through `Device::buffer_in_import`, is
named to it (`copied_as`) and joins its key, with the gate not asked. A
rebind onto such bytes lies in the copy too where its textures were
planned at the copy's offset (its first byte) and no image in place rides
on it; an import keeps the old `!moved` rule. A heap's own copy is placed
but joins nothing; a buffer whose writes are dropped keeps its read-only
view. New counter `WorkCounts::copied_host_buffers_shared`.

Why: two copies of one memory agreed only through the pages (merge back
at the writer's completion, copy in at the reader's commit). reims-vgpu
measured on the M3 (MoltenVK) two textures over one 64x64 BGRA8 surface,
each over its own refused no-copy buffer: a blit write then a blit read in
one command buffer, and a reader committed first on a second queue waiting
on the writer's event, both read all 16384 bytes stale, where Metal and
the runtime in place read the write. The consumer also made a full copy of
the surface per texture per present.

The remaining GPU-to-GPU gap, between a copy and another copy or import of
overlapping but different bytes, is recorded in copied.rs, docs/API.md,
docs/HOWTO.md and docs/FAST-PATHS.md's known gaps.

Verified: cargo check of the runtime with tests; the lane in the next
commit, run on the M3 (see its message).

(cherry picked from commit 69feb791dc6ec3bc2405dbf5b6ae5d0b27d936aa)
This commit is contained in:
Anees Iqbal committed 2026-11-04 21:54:19 -08:00
1 parent 7127ca8035
commit 6c4b409fb0
12 files changed
+247 -63

No files matched your search

+10 -2
View File
@@ -2727,7 +2727,13 @@ bound.
private option bit 24 drops is never copied. A buffer's or heap's rebind is copied the same way,
its heap's bound textures and its images in place made again over the copy, and a buffer's
rebind to bytes at another offset in their page under a texture planned at the old one is a copy
laid out there (the detail says which). Counted: `WorkCounts::copied_host_buffers_made`, of them
laid out there (the detail says which). A buffer made over exactly the bytes (the same first
byte and length) a live copied buffer was made over, of either storage mode, lies in its copy,
as one over a live import's bytes lies in that import, and makes no copy of its own
(`copied_host_buffers_shared`, the gate not asked): one memory, ordered as one resource's
accesses; a rebind to them does too where its textures were planned at the copy's offset and no
image in place rides on it. A heap's own buffer and memory whose GPU writes are dropped keep
their own. Counted: `WorkCounts::copied_host_buffers_made`, of them
`copied_host_buffers_refused`, `copied_host_buffers_degraded` and `copied_rebind_pages_moved`
(and `copied_heaps_made`, `copied_rebind_pages_made`, `copied_rebind_images_made`); each such
buffer, and each buffer placed in such a heap, answers `Buffer::host_backing` with
@@ -2739,7 +2745,9 @@ bound.
reads before the batch completes, is not seen, and each commit and completion compares every
byte of every copy. An event signal submitted while a copy is live is seen once its batch's
writes are back in the pages, as Metal's: its value at the completion turn, and a wait for it
held on the host until then (`event_signals_behind_merge`).
held on the host until then (`event_signals_behind_merge`). A copy and another memory over
overlapping but not the same bytes agree GPU to GPU only through the pages, so a read committed
before the write's completion reads the bytes from before it (docs/FAST-PATHS.md, known gaps).
- `metal2vulkan-degrade-grouped-completion` (precision). `GroupedCompletion`: Batches of command
buffers committed on one queue that the scheduler found ready together, or held while two or more
earlier submissions of their queue ran, went to the driver in one `vkQueueSubmit`, only the last