[PR #354] [CLOSED] vulkan_replay: order back-to-back buffer copies, as image copies already are (VK-BUFCOPY-ORDER) #407

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

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/354
Author: @natterman12
Created: 11/24/2026
Status: ❌ Closed

Base: main ← Head: vulkan/order-back-to-back-buffer-copies


📝 Commits (1)

  • b89bab1 vulkan_replay: order back-to-back buffer copies, as image copies already are

📊 Changes

3 files changed (+47 additions, -4 deletions)

View changed files

📝 runtime/src/vulkan_replay.h (+7 -0)
📝 runtime/test/replay_copy_offset_test.cpp (+35 -4)
📝 runtime/test/replay_query_edges_test.cpp (+5 -0)

📄 Description

Claimed in the coordination issue as: VK-BUFCOPY-ORDER (#14)

What and why

D3D12 runs consecutive copies on a buffer in order with no barrier from the application: the buffer stays in COPY_DEST / COPY_SOURCE, and that holds within one list and across lists on a queue. Vulkan orders nothing unless a barrier says so.

The replay already handles this for images. copy_layout says: "D3D12 orders back-to-back copies and resolves on a resource that stays in COPY_DEST or COPY_SOURCE without a barrier from the application; Vulkan does not", and emits a memory barrier after earlier transfer writes. The plain buffer-to-buffer copy had no such barrier, so two copies into the same buffer are unordered as far as Vulkan is concerned.

Synchronization validation reports it. On main d478a92d with LEONIDA_VK_VALIDATION=1, vk_queue fails with ten of these from its backlog case (the same 16 MiB copy submitted repeatedly):

vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] WRITE_AFTER_WRITE hazard detected. vkCmdCopyBuffer ... writes to
VkBuffer ..., which was previously written by another vkCmdCopyBuffer command ...

The change is one barrier ahead of a plain buffer copy: earlier TRANSFER_WRITE at the transfer stage, to this copy's TRANSFER_READ | TRANSFER_WRITE at the transfer stage, through the existing detail::memory_barrier (so it is restricted to the queue's stages like the others). It covers the read side too: a copy that reads what the copy before it wrote.

Cost: one transfer-to-transfer memory barrier per buffer copy, the same price image copies already pay.

Tests

  • replay_copy_offset_test (GPU-free, fake Vulkan): its barrier callback now records whether a transfer-write barrier came before each vkCmdCopyBuffer. It checks that for a single CopyResource, and for two overlapping CopyBufferRegion calls into the same buffer, where each copy needs its own barrier. Both checks fail without the change.
  • replay_query_edges_test: its fake Vulkan table set copy_buffer but no pipeline_barrier, so it crashed on the new call. It gets a no-op entry; nothing it asserts changes.

Tested

Windows 11 10.0.26300.9974, NVIDIA GeForce RTX 3080 Ti, driver 621.24, Vulkan SDK 1.4.363.0 (validation layer from the SDK), MSVC 19.44.35230. No game files. Everything recompiled for the "after" numbers.

before (main d478a92d) after
vk_queue, LEONIDA_VK_VALIDATION=1 failed, 10 WRITE_AFTER_WRITE validation errors: 0, vk_queue_test: OK
replay_copy_offset passes (did not check ordering) passes with the two new checks
Full ctest, LEONIDA_VK_VALIDATION=1 6 failed of 290 5 failed of 290

The five that remain fail the same way without this change: d3d12_vulkan_device (#262 / #238), d3d12_execute_indirect_validation (#337 / #306), d3d12_depth_resolve (#66), and two that only fail under validation and that I am reporting separately in #14 rather than fixing here: d3d12_clear (VUID-VkClearDepthStencilValue-depth-00022) and d3d12_mesh (VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076).

Not tested: other GPUs, Linux, and the full suite without validation on this branch (the validation run executes the same tests).

AI-assisted: yes (Claude Code)

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (not applicable: no translator change)

🤖 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/354 **Author:** [@natterman12](https://github.com/natterman12) **Created:** 11/24/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `vulkan/order-back-to-back-buffer-copies` --- ### 📝 Commits (1) - [`b89bab1`](https://github.com/ubiquitarianism/leonida/commit/b89bab16c1410834e2d1a9b264d1374d6fbde38e) vulkan_replay: order back-to-back buffer copies, as image copies already are ### 📊 Changes **3 files changed** (+47 additions, -4 deletions) <details> <summary>View changed files</summary> 📝 `runtime/src/vulkan_replay.h` (+7 -0) 📝 `runtime/test/replay_copy_offset_test.cpp` (+35 -4) 📝 `runtime/test/replay_query_edges_test.cpp` (+5 -0) </details> ### 📄 Description Claimed in the coordination issue as: VK-BUFCOPY-ORDER (#14) ### What and why D3D12 runs consecutive copies on a buffer in order with no barrier from the application: the buffer stays in `COPY_DEST` / `COPY_SOURCE`, and that holds within one list and across lists on a queue. Vulkan orders nothing unless a barrier says so. The replay already handles this for images. `copy_layout` says: "D3D12 orders back-to-back copies and resolves on a resource that stays in COPY_DEST or COPY_SOURCE without a barrier from the application; Vulkan does not", and emits a memory barrier after earlier transfer writes. The plain buffer-to-buffer copy had no such barrier, so two copies into the same buffer are unordered as far as Vulkan is concerned. Synchronization validation reports it. On `main` d478a92d with `LEONIDA_VK_VALIDATION=1`, `vk_queue` fails with ten of these from its backlog case (the same 16 MiB copy submitted repeatedly): ``` vkQueueSubmit(): pSubmits[0].pCommandBuffers[0] WRITE_AFTER_WRITE hazard detected. vkCmdCopyBuffer ... writes to VkBuffer ..., which was previously written by another vkCmdCopyBuffer command ... ``` The change is one barrier ahead of a plain buffer copy: earlier `TRANSFER_WRITE` at the transfer stage, to this copy's `TRANSFER_READ | TRANSFER_WRITE` at the transfer stage, through the existing `detail::memory_barrier` (so it is restricted to the queue's stages like the others). It covers the read side too: a copy that reads what the copy before it wrote. Cost: one transfer-to-transfer memory barrier per buffer copy, the same price image copies already pay. ### Tests - `replay_copy_offset_test` (GPU-free, fake Vulkan): its barrier callback now records whether a transfer-write barrier came before each `vkCmdCopyBuffer`. It checks that for a single `CopyResource`, and for two overlapping `CopyBufferRegion` calls into the same buffer, where each copy needs its own barrier. Both checks fail without the change. - `replay_query_edges_test`: its fake Vulkan table set `copy_buffer` but no `pipeline_barrier`, so it crashed on the new call. It gets a no-op entry; nothing it asserts changes. ### Tested Windows 11 10.0.26300.9974, NVIDIA GeForce RTX 3080 Ti, driver 621.24, Vulkan SDK 1.4.363.0 (validation layer from the SDK), MSVC 19.44.35230. No game files. Everything recompiled for the "after" numbers. | | before (`main` d478a92d) | after | |---|---|---| | `vk_queue`, `LEONIDA_VK_VALIDATION=1` | failed, 10 `WRITE_AFTER_WRITE` | `validation errors: 0`, `vk_queue_test: OK` | | `replay_copy_offset` | passes (did not check ordering) | passes with the two new checks | | Full `ctest`, `LEONIDA_VK_VALIDATION=1` | 6 failed of 290 | 5 failed of 290 | The five that remain fail the same way without this change: `d3d12_vulkan_device` (#262 / #238), `d3d12_execute_indirect_validation` (#337 / #306), `d3d12_depth_resolve` (#66), and two that only fail under validation and that I am reporting separately in #14 rather than fixing here: `d3d12_clear` (`VUID-VkClearDepthStencilValue-depth-00022`) and `d3d12_mesh` (`VUID-vkCmdDrawMeshTasksEXT-pipelineStatistics-07076`). Not tested: other GPUs, Linux, and the full suite without validation on this branch (the validation run executes the same tests). AI-assisted: yes (Claude Code) ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [ ] A new translator rule is in the contract table of `docs/design.md`, with how it was confirmed. (not applicable: no translator change) 🤖 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>
4ld0 2026-11-26 20:17:47 +01:00
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#407
No description provided.