Files
reims-vgpu/guest
Anees Iqbal 61084eab14 🆕 Tell the host which bytes of a new Managed buffer read zero
On a GPU without unified memory the runtime makes a Managed buffer's GPU copy
by copying all of its CPU copy over the link as the buffer is made. Most of
those bytes are zeros the guest never wrote: on the RX 7900 XTX, Geekbench 7.1
Metal's making copies carried ~4.5 GB beyond what the guest marked written, up
to ~0.94 s of GPU time (one 131 ms job copied six new buffers' 631 MB, 12 MB
of it written). The guest knows which bytes read zero; the host cannot.

What changes for the guest and the host:
- MANAGED_BUFFER_CREATE takes a tail, RgfxManagedBufferZero at byte 56
  (RGFX_MANAGED_BUFFER_ZERO_OFFSET): its CPU copy reads zero from zero_from to
  the length as the create is posted. The bundle sends it with every create:
  0 for a buffer made with no bytes, whose slab range take() zeroed; the
  length, which says nothing, for one made with bytes or over the app's own
  memory. The kext's SubmitBatch takes the create at its new size, 64 bytes.
- The host passes a zero_from below the length to the platform
  (BufferDesc::zero_from), and the Vulkan platform to the runtime
  (HostMemory::with_zero_from): the GPU copy starts with zeros the GPU writes
  there, rather than with those bytes copied in. A guest write there reaches
  the GPU copy by a didModifyRange:, as on a Mac's discrete GPU, whose GPU
  copy is made at the buffer's making; before, a write made before the host
  took the create reached it too. A GPU that shares the CPU's memory keeps one
  copy, unchanged, and a create without the tail (an older guest's) is copied
  in whole, as before. An older host reads the create and ignores the tail.

Tests: the decoder passes the tail's offset and none without it or at the
length; the platform's zero bytes are the device's on a GPU of its own memory;
the serialiser, the slabs and the device buffers send each make path's value.
Both guest sets and the ROM's record are rebuilt in the next commit.
2026-11-15 18:44:04 -08:00
..