d3d12: SYNC_COPY waits for the CLEAR stage too, so WriteBufferImmediate is ordered (D3D-838) #314

Open
github-bot wants to merge 1 commit from github-bot/gh-314 into main AGit
Owner

@⁠Andretuta on GitHub · 2026-11-24 03:07 UTC · original
ubiquitarianism:old-pr/10048 → main · +91 −5 · 4 files · 1 commits · draft

Carried over from old PR 10048 by kykifox1337-source in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch old-pr/10048, exactly that PR's last commit. All carried-over PRs are listed in #17.
Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it.
kykifox1337-source: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one.


Original description (mentions and #N references are disabled; the numbers refer to the old repository):

Claimed in the coordination issue as: D3D-838 (https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7117033945)

Re-submission of #8187, which was closed unmerged with the other open PRs between 22:25 and 22:49 UTC; the fix is not on main. Same commit, cherry-picked onto current main (de4c37383) without conflicts. #8187 has three independent passes on it: an RTX 5070 with the full ctest, an RTX 4080 SUPER under LEONIDA_VK_VALIDATION=1 with a negative control, and two CPU-only checks of d3d12_state_map_test (Windows and Linux) that fail without the change.

What and why

An enhanced barrier's D3D12_BARRIER_SYNC_COPY mapped to VK_PIPELINE_STAGE_2_COPY_BIT only (vulkan_sync, runtime/src/vulkan_replay.h). Two D3D12 copy-scope commands are not Vulkan copies:

  • WriteBufferImmediate is recorded as vkCmdUpdateBuffer, and a DEFAULT-mode write gets no barrier of its own (replay leaves it to the application's barriers);
  • ResolveQueryData fills never-written queries with vkCmdFillBuffer.

Synchronization2 runs both in the CLEAR stage, not COPY, so a SYNC_COPY barrier after either did not order it, and a copy after the barrier could read the word before the write landed. The legacy-state path already covers this (COPY_DEST maps to COPY | TRANSFER).

  • vulkan_sync: SYNC_COPY → COPY | CLEAR. Every access a copy barrier names stays valid in that mask (TRANSFER_WRITE is allowed in CLEAR; TRANSFER_READ keeps COPY).
  • vk_command_replay_test part K: WriteBufferImmediate into one buffer, a SYNC_COPY → SYNC_COPY buffer barrier (COPY_DEST → COPY_SOURCE), then CopyBufferRegion of the written word into another buffer. It checks the copied value and, under LEONIDA_VK_VALIDATION=1, that synchronization validation reports nothing.
  • d3d12_state_map_test: the two expectations that included SYNC_COPY, plus a direct check of the new mapping.
  • docs/d3d12_vulkan.md: one sentence on the mapping where the enhanced barriers are described.

Tested

Windows 10, NVIDIA GeForce RTX 2070 SUPER, driver 610.88 (Vulkan 1.4.341), MSVC 14.44 (VS 2022 Build Tools 17.14), Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0 validation layer with synchronization validation.

On this branch (current main + the commit):

  • d3d12_state_map_test: pass.
  • vk_command_replay_test with LEONIDA_VK_VALIDATION=1: parts A–K pass, 0 validation errors (part D's 360 sync/access pairs included, so the wider stage mask is valid on every barrier kind); vk_sync_validation_selftest confirms synchronization validation is active.

On #8187's base (dde82f27e):

Open PRs touching the same files merge with this one without conflicts (git merge-tree against each). No game files used.

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

**@⁠Andretuta** on GitHub · 2026-11-24 03:07 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/314) `ubiquitarianism:old-pr/10048` → `main` · +91 −5 · 4 files · 1 commits · draft > Carried over from **old PR 10048** by `kykifox1337-source` in the original Leonida repository, which went private on 23 Nov 2026. The code is the branch `old-pr/10048`, exactly that PR's last commit. All carried-over PRs are listed in #17. > Opened as a draft, and the CI runs the opening started were cancelled so 250 PRs don't fill the queue. Re-run CI here when you review it. > `kykifox1337-source`: this is your work. Feel free to take it over, by pushing to the branch or opening your own PR and closing this one. --- Original description (mentions and `#N` references are disabled; the numbers refer to the old repository): Claimed in the coordination issue as: D3D-838 (https://github.com/ProjectLeonida/Leonida/issues/9677#issuecomment-7117033945) Re-submission of `#8187`, which was closed unmerged with the other open PRs between 22:25 and 22:49 UTC; the fix is not on `main`. Same commit, cherry-picked onto current `main` (`de4c37383`) without conflicts. `#8187` has three independent passes on it: an RTX 5070 with the full ctest, an RTX 4080 SUPER under `LEONIDA_VK_VALIDATION=1` with a negative control, and two CPU-only checks of `d3d12_state_map_test` (Windows and Linux) that fail without the change. ### What and why An enhanced barrier's `D3D12_BARRIER_SYNC_COPY` mapped to `VK_PIPELINE_STAGE_2_COPY_BIT` only (`vulkan_sync`, `runtime/src/vulkan_replay.h`). Two D3D12 copy-scope commands are not Vulkan copies: - `WriteBufferImmediate` is recorded as `vkCmdUpdateBuffer`, and a DEFAULT-mode write gets no barrier of its own (replay leaves it to the application's barriers); - `ResolveQueryData` fills never-written queries with `vkCmdFillBuffer`. Synchronization2 runs both in the `CLEAR` stage, not `COPY`, so a `SYNC_COPY` barrier after either did not order it, and a copy after the barrier could read the word before the write landed. The legacy-state path already covers this (`COPY_DEST` maps to `COPY | TRANSFER`). - `vulkan_sync`: `SYNC_COPY` → `COPY | CLEAR`. Every access a copy barrier names stays valid in that mask (`TRANSFER_WRITE` is allowed in `CLEAR`; `TRANSFER_READ` keeps `COPY`). - `vk_command_replay_test` part K: `WriteBufferImmediate` into one buffer, a `SYNC_COPY → SYNC_COPY` buffer barrier (`COPY_DEST → COPY_SOURCE`), then `CopyBufferRegion` of the written word into another buffer. It checks the copied value and, under `LEONIDA_VK_VALIDATION=1`, that synchronization validation reports nothing. - `d3d12_state_map_test`: the two expectations that included `SYNC_COPY`, plus a direct check of the new mapping. - `docs/d3d12_vulkan.md`: one sentence on the mapping where the enhanced barriers are described. ### Tested Windows 10, NVIDIA GeForce RTX 2070 SUPER, driver 610.88 (Vulkan 1.4.341), MSVC 14.44 (VS 2022 Build Tools 17.14), Ninja `RelWithDebInfo`, Vulkan SDK 1.4.363.0 validation layer with synchronization validation. On this branch (current `main` + the commit): - `d3d12_state_map_test`: pass. - `vk_command_replay_test` with `LEONIDA_VK_VALIDATION=1`: parts A–K pass, 0 validation errors (part D's 360 sync/access pairs included, so the wider stage mask is valid on every barrier kind); `vk_sync_validation_selftest` confirms synchronization validation is active. On `#8187`'s base (`dde82f27e`): - Without the `vulkan_replay.h` change, part K fails with 1 validation error (the read-after-write hazard), so the test catches the bug. - Full `ctest -j 8`: 253 of 262 passed; the 8 failures reproduce without the change on the same build (details in https://github.com/ProjectLeonida/Leonida/pull/8187#issuecomment-7110226888 and `#166`). Open PRs touching the same files merge with this one without conflicts (`git merge-tree` against each). No game files used. AI-assisted: yes (Claude Code) ### Checklist - [x] No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here. - [x] 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)
An enhanced barrier's D3D12_BARRIER_SYNC_COPY mapped to VK_PIPELINE_STAGE_2_COPY_BIT only. Two D3D12
copy-scope commands are not Vulkan copies: WriteBufferImmediate is recorded as vkCmdUpdateBuffer and
ResolveQueryData's never-written queries as vkCmdFillBuffer, and synchronization2 runs both in the CLEAR
stage. A SYNC_COPY barrier after either therefore did not order it, and a copy after the barrier could read
the word before the write landed.

vulkan_sync now maps SYNC_COPY to COPY | CLEAR. vk_command_replay_test part K records WriteBufferImmediate,
a SYNC_COPY -> SYNC_COPY buffer barrier and a CopyBufferRegion of the written word; under
LEONIDA_VK_VALIDATION=1 it is a read-after-write hazard without this change. d3d12_state_map_test and
docs/d3d12_vulkan.md follow the new mapping.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:53:03 +00:00
Author
Owner

@⁠Sigtryggur-Mani-Gudmundsson on GitHub · 2026-11-24 04:05 UTC · original

On bbc8999d, the copy-queue stage filter still drops CLEAR. On a Linux RTX 4070 Ti (620.70.06), I ran the production VulkanQueue on transfer-only family 1 with Khronos synchronization validation. Copying out the old bytes, issuing WriteBufferImmediate and a never-ended timestamp resolve, then copying the new bytes back produced four hazards. Both vkCmdUpdateBuffer and vkCmdFillBuffer raced the preceding read and the following reads. Adding #354 alone still left the two write-after-read hazards.

A follow-up to kykifox1337-source's patch retains CLEAR for buffer writes and keeps colour image initialization on the zero-buffer path. The original byte snapshot, updated word, zero-filled timestamp and guard words all matched. With both corrected series, the full queue test reported zero validation errors. Credited patches and reproduction commands.

**@⁠Sigtryggur-Mani-Gudmundsson** on GitHub · 2026-11-24 04:05 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/314#issuecomment-7121697923) On `bbc8999d`, the copy-queue stage filter still drops CLEAR. On a Linux RTX 4070 Ti (620.70.06), I ran the production VulkanQueue on transfer-only family 1 with Khronos synchronization validation. Copying out the old bytes, issuing WriteBufferImmediate and a never-ended timestamp resolve, then copying the new bytes back produced four hazards. Both vkCmdUpdateBuffer and vkCmdFillBuffer raced the preceding read and the following reads. Adding #354 alone still left the two write-after-read hazards. A follow-up to kykifox1337-source's patch retains CLEAR for buffer writes and keeps colour image initialization on the zero-buffer path. The original byte snapshot, updated word, zero-filled timestamp and guard words all matched. With both corrected series, the full queue test reported zero validation errors. [Credited patches and reproduction commands](https://github.com/Sigtryggur-Mani-Gudmundsson/graphics-runtime-patches/blob/92c7fb79a968d235756a8985352a0e7b5577c7f6/tests/copy-queue-sync/README.md).
This pull request has changes conflicting with the target branch.
  • docs/d3d12_vulkan.md
  • runtime/test/vk_command_replay_test.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/314/head:github-bot/gh-314'
git switch 'github-bot/gh-314'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-314'
git switch 'github-bot/gh-314'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-314'
git switch 'github-bot/gh-314'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-314'
git switch 'main'
git merge --squash 'github-bot/gh-314'
git switch 'main'
git merge --ff-only 'github-bot/gh-314'
git switch 'main'
git merge 'github-bot/gh-314'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.