[PR #407] d3d12: CPU subresource copies wait for their own submission only (STAGED-COPY-OWN-WAIT) #458

Open
opened 2026-11-26 20:17:57 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/407
Author: @Kokonotcu
Created: 11/24/2026
Status: 🔄 Open

Base: main ← Head: pr/staged-copy-wait


📝 Commits (1)

  • 9b77601 CPU subresource copies wait for their own submission only (review D9)

📊 Changes

4 files changed (+231 additions, -11 deletions)

View changed files

📝 runtime/CMakeLists.txt (+7 -0)
📝 runtime/shims/d3d12_vulkan_device.cpp (+31 -9)
📝 runtime/src/vulkan_backend.h (+26 -2)
➕ runtime/test/d3d12_staged_copy_wait_test.cpp (+167 -0)

📄 Description

Claim: STAGED-COPY-OWN-WAIT

What was wrong

WriteToSubresource / ReadFromSubresource on a texture the host cannot copy (no VK_EXT_host_image_copy, or not in GENERAL) replay a CopyTextureRegion on a staging VulkanQueue and wait for it. The wait was VulkanQueue::idle(): vkQueueWaitIdle on info.queue (the VkQueue the first D3D12 direct queue also uses), held under the device's submit lock. Every such CPU copy waited for all the work queued on that queue, and no other queue could submit meanwhile.

What changed

  • VulkanQueue::wait_submitted() waits on the queue's own progress timeline for what it submitted, without the submit lock (100 ms slices, wakes on device loss). The staging copy uses it instead of idle().
  • The staging queue sits on a VkQueue the game's first queues are not on (CreateCommandQueue hands out each family's VkQueues from the first, so the last one): the copy family's for colour textures, whose engine runs beside queued graphics work; the graphics family's for depth/stencil and rgb96 textures (their copies may run the D24/rgb96 compute pass). A second graphics VkQueue alone did not help on NVIDIA: the timeline wait still took the full 32 ms. With one VkQueue in the family the copy shares info.queue as before.
  • No waits on other queues: D3D12 requires the application to have seen the texture's GPU work complete before a CPU copy (it waited on a fence its queue signalled); that host wait followed by this submission orders the work before the copy and makes its writes visible.

Testing

RTX 3080 Laptop GPU, i7-11800H, Windows 10 19045, NVIDIA driver, MSVC 2022 RelWithDebInfo, Vulkan SDK 1.4.350.

  • New d3d12_staged_copy_wait_test (standalone device): a staged 64x64 WriteToSubresource while the direct queue has ~32 ms of buffer copies queued: 31.8 ms before, 0.1-0.6 ms after (the direct queue still busy after it); the bytes round-trip. Fails before the change (its check that the write takes under half the queued work).
  • d3d12_subresource_copy (both paths, 109 steps against the host runtime and Microsoft's recorded answers): 0 mismatches. d3d12_rgb96: pass.
  • All three clean under LEONIDA_VK_VALIDATION=1 (0 validation errors).

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/407 **Author:** [@Kokonotcu](https://github.com/Kokonotcu) **Created:** 11/24/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `pr/staged-copy-wait` --- ### 📝 Commits (1) - [`9b77601`](https://github.com/ubiquitarianism/leonida/commit/9b77601d083af33b2658ef556104bae05fd87e32) CPU subresource copies wait for their own submission only (review D9) ### 📊 Changes **4 files changed** (+231 additions, -11 deletions) <details> <summary>View changed files</summary> 📝 `runtime/CMakeLists.txt` (+7 -0) 📝 `runtime/shims/d3d12_vulkan_device.cpp` (+31 -9) 📝 `runtime/src/vulkan_backend.h` (+26 -2) ➕ `runtime/test/d3d12_staged_copy_wait_test.cpp` (+167 -0) </details> ### 📄 Description Claim: STAGED-COPY-OWN-WAIT ## What was wrong `WriteToSubresource` / `ReadFromSubresource` on a texture the host cannot copy (no `VK_EXT_host_image_copy`, or not in GENERAL) replay a `CopyTextureRegion` on a staging `VulkanQueue` and wait for it. The wait was `VulkanQueue::idle()`: `vkQueueWaitIdle` on `info.queue` (the VkQueue the first D3D12 direct queue also uses), held under the device's submit lock. Every such CPU copy waited for all the work queued on that queue, and no other queue could submit meanwhile. ## What changed - `VulkanQueue::wait_submitted()` waits on the queue's own progress timeline for what it submitted, without the submit lock (100 ms slices, wakes on device loss). The staging copy uses it instead of `idle()`. - The staging queue sits on a VkQueue the game's first queues are not on (CreateCommandQueue hands out each family's VkQueues from the first, so the last one): the copy family's for colour textures, whose engine runs beside queued graphics work; the graphics family's for depth/stencil and rgb96 textures (their copies may run the D24/rgb96 compute pass). A second graphics VkQueue alone did not help on NVIDIA: the timeline wait still took the full 32 ms. With one VkQueue in the family the copy shares `info.queue` as before. - No waits on other queues: D3D12 requires the application to have seen the texture's GPU work complete before a CPU copy (it waited on a fence its queue signalled); that host wait followed by this submission orders the work before the copy and makes its writes visible. ## Testing RTX 3080 Laptop GPU, i7-11800H, Windows 10 19045, NVIDIA driver, MSVC 2022 RelWithDebInfo, Vulkan SDK 1.4.350. - New `d3d12_staged_copy_wait_test` (standalone device): a staged 64x64 `WriteToSubresource` while the direct queue has ~32 ms of buffer copies queued: 31.8 ms before, 0.1-0.6 ms after (the direct queue still busy after it); the bytes round-trip. Fails before the change (its check that the write takes under half the queued work). - `d3d12_subresource_copy` (both paths, 109 steps against the host runtime and Microsoft's recorded answers): 0 mismatches. `d3d12_rgb96`: pass. - All three clean under `LEONIDA_VK_VALIDATION=1` (0 validation errors). 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#458
No description provided.