Testing on a Steam Deck (or any integrated GPU)

Nothing of the game leaves the machine: the steps below compare numbers and screenshots on the Deck itself.

  1. Build the runtime from this branch on the Deck (or take the build it gives), and check the log's line vulkan: the device shares system memory (UMA); guest buffers read in place where they can be (vk_memory=auto). If it says copied, the driver has no VK_EXT_external_memory_host: say which driver it is (the vulkan: line with the device name and driver version).
  2. Pick a scene that comes back the same way each run: a save, and a script of inputs that ends there (--script, --press-len, snx-run skill), with a screenshot every few seconds (--shot=DIR/s --shot-every=60). Run with -H --fps-limit=0 --vsync=0 --vk-gpu-profile=1 --vk-buffer-stats=1 so that the frame rate is the renderer's, not the display's.
  3. Run the scene three times with --vk-memory=1 (copy) and three times with --vk-memory=2 (in place), one after the other, with nothing else running. Keep each run's log and screenshots apart.
  4. Compare, for each pair:
  5. Report the numbers of the three pairs, not one: a single run's frame rate on a handheld moves with its temperature and power limit.

The copy path, and what keeps it correct

On a GPU that shares system memory, guest vertex, index and read-only storage ranges are imported into Vulkan (VK_EXT_external_memory_host, or on Android with vk_memory=2 moved into AHardwareBuffers) and read in place, as the sections above say. Every other range takes the copy path that this section is about: vk_buf_copy copies bytes out of guest RAM into a buffer that vk_stage maps and the GPU reads. Exporting the final image as a dma-buf, as desktop compositors do, would not remove this copy: ScarletNX already presents its Vulkan image without an app-managed dma-buf handoff.

Measured workload

With the constant-buffer cache enabled, a 600-present interval of a cave scene in one game staged 3,688,879,936 uncached bytes in 63,098 calls. The largest call was 58,848 bytes and none were zero-filled. The only nonzero-address staging-copy path with that cache enabled is vk_buf_copy_writable for writable graphics storage buffers in stage_set. A per-draw wait or allocation is therefore not a viable replacement for the staging ring. The test machine has a discrete RTX 2080; it cannot establish a unified-memory speedup.

Correctness requirements

The input to each draw is a snapshot. Guest CPU threads can write the same pages while recorded GPU work is in flight, and GPU virtual ranges can map fragmented host pages. The current asynchronous userfaultfd write tracker reports writes after they happen; it does not freeze pages. Guest mapping and decommit operations can also change backing memory. Importing g_mem directly would let the GPU see later CPU writes, and a shader could write guest memory before the guest's synchronization point. A direct import must therefore own and pin the imported pages, intercept writes to them or use copy-on-write, and wait for GPU completion before remapping or releasing them.

Mapping changes now acquire the renderer's memory lock before the guest memory manager's lock. CPU backing changes land all pending storage output because a CPU page may have several GPU aliases. GPU-VA changes land overlapping output before changing the page table and mark the virtual range dirty for buffer caches. This closes the backing-lifetime gap for staged outputs; it does not pin guest pages or make direct host-pointer import safe.

Graphics storage writes now retain each draw's input bytes, destination range, and GPU buffer. A completed frame invalidates noncoherent output memory and lands only bytes the shader changed where the guest still holds the input value. Overlapping guest reads and writes, and stream synchronization points, wait for pending outputs. Draws can reuse an earlier result in the same frame with a storage barrier when the binding is contained and aligned and its guest input is unchanged; other overlaps land before taking another snapshot. Frame-ring reuse processes output before freeing its staging allocation. The compute and graphics paths share vk_write_changed.

A compute program of the SM86 translator logs the bytes its stores write instead (see Ounce): its results keep no input bytes, and land exactly the bytes logged, the shader's value winning over a CPU write made to the same byte while the result was pending.

The byte-value reconciliation cannot distinguish a later CPU write that restores the original value from no write. Games must synchronize CPU and GPU writes to the same bytes for deterministic ordering. When writable bindings in one draw share guest backing, the bindings involved in that overlap use a shared page atlas. Each such binding maps its logical word indices to atlas pages, so partially overlapping ranges, fragmented mappings and different GPU virtual aliases see the same bytes. The atlas starts after earlier graphics and compute output has landed. A draw whose atlas would exceed the device's maximum storage-buffer descriptor range is skipped with a warning, rather than rendered with independent snapshots.

The 110-second run of that cave scene with graphics writeback and same-frame reuse completed 1,757 frames, compared with 1,754 for the earlier staging run on this machine. A 600-present interval reused 7,429 GPU buffers but still forced 1,985 lands, totaling 14.7 seconds of waits. The scenes and shader caches vary, so this is a correctness smoke test, not a controlled performance comparison. The resulting cave image still has known cyan rendering artifacts.

Vulkan references: host pointer import, host/device synchronization, and placed memory mapping.


Made from docs/layers/gpu/ownership.md at 69237645142c. GPL-3.0-or-later.