vulkan: every submission starts with a full memory barrier, as an ExecuteCommandLists boundary (VK-SUBMIT-BARRIER) #470

Manually merged
github merged 2 commits from gh-pr/470/head into gh-pr/470/base 2026-11-26 09:02:24 +00:00
Owner

@⁠Kokonotcu on GitHub · 2026-11-24 05:55 UTC · original
Kokonotcu:pr/submission-barrier → main · +71 −0 · 2 files · 2 commits · merged 2026-11-24 16:25 UTC

Claim: VK-SUBMIT-BARRIER (#14).

What was wrong: D3D12 ends every ExecuteCommandLists with its work done and its writes visible to the next submission on the queue. Implicit state decay relies on it, and a list may touch memory an earlier submission wrote without any barrier (two submissions copying into one buffer, say). Vulkan orders submissions on a queue only by their barriers, and nothing in a VulkanQueue's command buffer ordered it after the previous one. Synchronization validation reports it in vk_queue_test's back-to-back copies into one buffer: WRITE_AFTER_WRITE between submissions, 10 errors, the test fails under LEONIDA_VK_VALIDATION=1.

What changed: execute_now records an ALL_COMMANDS -> ALL_COMMANDS memory barrier (MEMORY_WRITE -> MEMORY_READ | MEMORY_WRITE) right after vkBeginCommandBuffer. The second commit skips it on a context without vkCmdPipelineBarrier: replay_query_edges_test's mocked context has none, and the first commit alone crashed that test.

Cost: one global memory barrier per submitted command buffer. Execution order between submissions is unchanged; the barrier only makes writes visible.

Tests: vk_queue_test 4b counts the command buffers begun and those whose first barrier is this one, over two submissions each on the direct and the copy queue: 4 of 4 (0 before).

Tested on Windows 10, i7-11800H, RTX 3080 Laptop (NVIDIA driver), on main 8f481cf16, with LEONIDA_VK_VALIDATION=1: vk_queue passes with 0 validation errors, replay_query_edges passes. On our cumulative branch the GPU tests (^(d3d12_|vk_)) under validation pass with this in place.

🤖 Generated with Claude Code

**@⁠Kokonotcu** on GitHub · 2026-11-24 05:55 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/470) `Kokonotcu:pr/submission-barrier` → `main` · +71 −0 · 2 files · 2 commits · merged 2026-11-24 16:25 UTC Claim: VK-SUBMIT-BARRIER (#14). **What was wrong:** D3D12 ends every `ExecuteCommandLists` with its work done and its writes visible to the next submission on the queue. Implicit state decay relies on it, and a list may touch memory an earlier submission wrote without any barrier (two submissions copying into one buffer, say). Vulkan orders submissions on a queue only by their barriers, and nothing in a `VulkanQueue`'s command buffer ordered it after the previous one. Synchronization validation reports it in `vk_queue_test`'s back-to-back copies into one buffer: WRITE_AFTER_WRITE between submissions, 10 errors, the test fails under `LEONIDA_VK_VALIDATION=1`. **What changed:** `execute_now` records an `ALL_COMMANDS -> ALL_COMMANDS` memory barrier (`MEMORY_WRITE -> MEMORY_READ | MEMORY_WRITE`) right after `vkBeginCommandBuffer`. The second commit skips it on a context without `vkCmdPipelineBarrier`: `replay_query_edges_test`'s mocked context has none, and the first commit alone crashed that test. Cost: one global memory barrier per submitted command buffer. Execution order between submissions is unchanged; the barrier only makes writes visible. **Tests:** `vk_queue_test` 4b counts the command buffers begun and those whose first barrier is this one, over two submissions each on the direct and the copy queue: 4 of 4 (0 before). Tested on Windows 10, i7-11800H, RTX 3080 Laptop (NVIDIA driver), on `main` `8f481cf16`, with `LEONIDA_VK_VALIDATION=1`: `vk_queue` passes with 0 validation errors, `replay_query_edges` passes. On our cumulative branch the GPU tests (`^(d3d12_|vk_)`) under validation pass with this in place. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
D3D12 ends every ExecuteCommandLists with its work done and its writes
visible to the next one on the queue (implicit state decay relies on it), so
a list may touch memory an earlier submission wrote without any barrier: two
submissions copying into one buffer, say. Vulkan orders submissions on a
queue only by what their barriers say, and nothing in a VulkanQueue's command
buffer ordered it after the previous one. Synchronization validation
reported it on leonida/work: vk_queue_test's back-to-back copies into one
buffer, WRITE_AFTER_WRITE between submissions (10 errors, the test failed
under LEONIDA_VK_VALIDATION=1).

execute_now now records an ALL_COMMANDS -> ALL_COMMANDS memory barrier
(MEMORY_WRITE -> MEMORY_READ | MEMORY_WRITE) right after
vkBeginCommandBuffer.

Test: vk_queue_test 4b counts the command buffers begun and those whose first
barrier is that one, over two submissions each on the direct and the copy
queue: 4 of 4 (0 before). Under LEONIDA_VK_VALIDATION=1 the whole test now
has 0 validation errors (RTX 3080 Laptop).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The full memory barrier each submission now starts with (0589ffe88) called
vkCmdPipelineBarrier unconditionally; replay_query_edges_test's mocked
query-only context supplies no such entry point and crashed (access
violation) in its queue segment case. A real device always has it; the
barrier is skipped when the pointer is null.

Test: replay_query_edges_test passes again (crashed after 0589ffe88);
vk_queue_test still sees 4 of 4 submissions start with the barrier.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:02:22 +00:00
github manually merged commit 9f9a503406 into gh-pr/470/base 2026-11-26 09:02:24 +00:00
Author
Owner

@⁠kawaii-shakal on GitHub · 2026-11-24 10:31 UTC · original

Independent check on Windows with Khronos synchronization validation: this PR removes the vk_queue hazards main reports.

LEONIDA_VK_VALIDATION=1 vk_queue_test.exe (RelWithDebInfo, MSVC 19.50, Vulkan SDK 1.4.363.0), NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 Pro 26300:

Build Validation errors Test
main 21625bca8 10, all WRITE_AFTER_WRITE: a vkCmdCopyBuffer writes a VkBuffer another submission's vkCmdCopyBuffer on the same queue wrote, with nothing between the submissions (the layer stops at the duplicate limit of 10) fails at line 394: d.validation_errors() == 0
this PR's head 9f9a50340 0 passes

Without validation both pass (backlog: 256 submits, 62 command buffers allocated, cap 64). The head was built as it is, on its own base 8f481cf; GitHub reports the PR mergeable with main. I did not run the rest of the suite on the PR head or measure the cost of the extra barrier.

AI-assisted.

**@⁠kawaii-shakal** on GitHub · 2026-11-24 10:31 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/470#issuecomment-7128904534) Independent check on Windows with Khronos synchronization validation: this PR removes the `vk_queue` hazards `main` reports. `LEONIDA_VK_VALIDATION=1 vk_queue_test.exe` (RelWithDebInfo, MSVC 19.50, Vulkan SDK 1.4.363.0), NVIDIA GeForce RTX 5070 Ti, driver 617.42, Windows 11 Pro 26300: | Build | Validation errors | Test | |---|---|---| | `main` 21625bca8 | 10, all `WRITE_AFTER_WRITE`: a `vkCmdCopyBuffer` writes a VkBuffer another submission's `vkCmdCopyBuffer` on the same queue wrote, with nothing between the submissions (the layer stops at the duplicate limit of 10) | fails at `line 394: d.validation_errors() == 0` | | this PR's head 9f9a50340 | 0 | passes | Without validation both pass (backlog: 256 submits, 62 command buffers allocated, cap 64). The head was built as it is, on its own base 8f481cf; GitHub reports the PR mergeable with `main`. I did not run the rest of the suite on the PR head or measure the cost of the extra barrier. AI-assisted.
Author
Owner

@⁠Timon360SB on GitHub · 2026-11-24 12:51 UTC · original

Independent verification — Turing and Blackwell

Baseline (exact merge base):
8f481cf16f261c7f37458aeb45e8f4e19994146d

PR head:
9f9a503406c581320bcd84d5a73dc77ae9626107

Test environment

Configuration RTX 2060 SUPER RTX 5070
Architecture Turing Blackwell
Driver 621.14 621.14
Windows 11 build 28000 26200
Vulkan SDK 1.4.363.0 1.4.363.0
MSVC 19.44.35230 19.44.35230
Build RelWithDebInfo RelWithDebInfo
Generator Ninja Multi-Config Ninja Multi-Config

Synchronization validation was enabled.
Three independent test runs per revision on each GPU.

CTest results

Test 2060S BASE 2060S HEAD 5070 BASE 5070 HEAD
vk_queue 0/3 3/3 0/3 3/3
replay_query_edges 3/3 3/3 3/3 3/3
vk_sync_validation 3/3 3/3 3/3 3/3

36 test executions in total.
No skipped or missing tests.

vk_queue validation errors

Run RTX 2060 SUPER RTX 5070
1 10 -> 0 10 -> 0
2 10 -> 0 10 -> 0
3 10 -> 0 10 -> 0

BASE consistently reports WRITE_AFTER_WRITE hazards
during vkQueueSubmit.

The baseline count is subject to the validation layer's
duplicate_message_limit of 10.

Every HEAD run reports:

ExecuteCommandLists boundary:
4 of 4 submissions start with a full memory barrier
validation errors: 0

Validation positive control

All 12 vk_sync_validation executions passed:

two copies into the same bytes:
1 validation error(s) without a barrier, 0 with one

vk_sync_validation_selftest: PASS,
synchronization validation is active

Conclusion

The fix is reproducible on both tested NVIDIA
architectures. All six baseline vk_queue failures
became passes on the PR head, with zero reported
vk_queue validation errors.

No regressions observed in the selected tests.
This is a targeted correctness check, not a full
runtime regression or performance benchmark.

Synthetic fixtures only. No game files used.
AI-assisted test automation and result analysis.

**@⁠Timon360SB** on GitHub · 2026-11-24 12:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/470#issuecomment-7132011216) ## Independent verification — Turing and Blackwell Baseline (exact merge base): `8f481cf16f261c7f37458aeb45e8f4e19994146d` PR head: `9f9a503406c581320bcd84d5a73dc77ae9626107` ### Test environment | Configuration | RTX 2060 SUPER | RTX 5070 | | --- | --- | --- | | Architecture | Turing | Blackwell | | Driver | 621.14 | 621.14 | | Windows 11 build | 28000 | 26200 | | Vulkan SDK | 1.4.363.0 | 1.4.363.0 | | MSVC | 19.44.35230 | 19.44.35230 | | Build | RelWithDebInfo | RelWithDebInfo | | Generator | Ninja Multi-Config | Ninja Multi-Config | Synchronization validation was enabled. Three independent test runs per revision on each GPU. ### CTest results | Test | 2060S BASE | 2060S HEAD | 5070 BASE | 5070 HEAD | | --- | --- | --- | --- | --- | | vk_queue | 0/3 | 3/3 | 0/3 | 3/3 | | replay_query_edges | 3/3 | 3/3 | 3/3 | 3/3 | | vk_sync_validation | 3/3 | 3/3 | 3/3 | 3/3 | 36 test executions in total. No skipped or missing tests. ### vk_queue validation errors | Run | RTX 2060 SUPER | RTX 5070 | | --- | --- | --- | | 1 | 10 -> 0 | 10 -> 0 | | 2 | 10 -> 0 | 10 -> 0 | | 3 | 10 -> 0 | 10 -> 0 | BASE consistently reports WRITE_AFTER_WRITE hazards during vkQueueSubmit. The baseline count is subject to the validation layer's duplicate_message_limit of 10. Every HEAD run reports: ExecuteCommandLists boundary: 4 of 4 submissions start with a full memory barrier validation errors: 0 ### Validation positive control All 12 vk_sync_validation executions passed: two copies into the same bytes: 1 validation error(s) without a barrier, 0 with one vk_sync_validation_selftest: PASS, synchronization validation is active ### Conclusion The fix is reproducible on both tested NVIDIA architectures. All six baseline vk_queue failures became passes on the PR head, with zero reported vk_queue validation errors. No regressions observed in the selected tests. This is a targeted correctness check, not a full runtime regression or performance benchmark. Synthetic fixtures only. No game files used. AI-assisted test automation and result analysis.
Author
Owner

@⁠DesertGamer on GitHub · 2026-11-24 13:19 UTC · original

Independent check of this PR on NVIDIA, as asked for in #14. Windows 11, RTX 5070, driver 617.14, MSVC, Vulkan SDK 1.4.363.0 validation layer, LEONIDA_VK_VALIDATION=1, vk_queue_test built from the same tree each time.

tree exit WRITE_AFTER_WRITE reports last lines
main 21625bca8 1 10 validation errors: 10
main + this PR (99eba8ab5) 0 0 validation errors: 0, vk_queue_test: OK

The backlog line is the same in both (256 submits, 62 or 63 command buffers of the cap 64, 3 waits that time out), so the barrier does not change the cap behaviour the test checks. No game files, no game data.

AI-assisted: yes (Claude Code, Sonnet 5.5)

**@⁠DesertGamer** on GitHub · 2026-11-24 13:19 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/470#issuecomment-7132667405) Independent check of this PR on NVIDIA, as asked for in https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14. Windows 11, RTX 5070, driver 617.14, MSVC, Vulkan SDK 1.4.363.0 validation layer, `LEONIDA_VK_VALIDATION=1`, `vk_queue_test` built from the same tree each time. | tree | exit | `WRITE_AFTER_WRITE` reports | last lines | |---|---|---:|---| | `main` 21625bca8 | 1 | 10 | `validation errors: 10` | | `main` + this PR (`99eba8ab5`) | 0 | 0 | `validation errors: 0`, `vk_queue_test: OK` | The backlog line is the same in both (256 submits, 62 or 63 command buffers of the cap 64, 3 waits that time out), so the barrier does not change the cap behaviour the test checks. No game files, no game data. AI-assisted: yes (Claude Code, Sonnet 5.5)
Author
Owner

@⁠QemmHD on GitHub · 2026-11-24 16:25 UTC · original

Merging.

Why merged: Every queue submission now starts with a full memory barrier, which matches D3D12's ExecuteCommandLists boundary. Under synchronization validation, main's vk_queue_test fails with 10 WRITE_AFTER_WRITE errors; with this PR it reports "4 of 4 submissions start with a full memory barrier" and 0 errors. Three independent NVIDIA checks agree (kawaii-shakal, Timon360SB, DesertGamer).

Why it's good: Cost, measured here because it was the open question: d3d12_bindless_churn (96 frames, many ExecuteCommandLists on 2 queues), 5 alternating runs, median, main vs PR: deferred 437.7 vs 433.8 ms, async 432.6 vs 437.3 ms, old-wait 438.3 vs 433.4 ms, old-wait async 440.2 vs 443.6 ms. vk_queue_test: 0.374 vs 0.370 s. All within run-to-run noise (about ±2%). These are synthetic tests, so there's no game-load number yet.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Alone on main, its tests passed both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #388, #418, #421, #434, #470, #484, #485, #486 and #488 merged onto main 1504c1af6 (a225e593e). There the repo-consistency set gives 566 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 306/308. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same skip set. git merge-tree against current main 98a977b4b: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

**@⁠QemmHD** on GitHub · 2026-11-24 16:25 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/470#issuecomment-7137636543) Merging. **Why merged:** Every queue submission now starts with a full memory barrier, which matches D3D12's ExecuteCommandLists boundary. Under synchronization validation, main's vk_queue_test fails with 10 WRITE_AFTER_WRITE errors; with this PR it reports "4 of 4 submissions start with a full memory barrier" and 0 errors. Three independent NVIDIA checks agree (kawaii-shakal, Timon360SB, DesertGamer). **Why it's good:** Cost, measured here because it was the open question: d3d12_bindless_churn (96 frames, many ExecuteCommandLists on 2 queues), 5 alternating runs, median, main vs PR: deferred 437.7 vs 433.8 ms, async 432.6 vs 437.3 ms, old-wait 438.3 vs 433.4 ms, old-wait async 440.2 vs 443.6 ms. vk_queue_test: 0.374 vs 0.370 s. All within run-to-run noise (about ±2%). These are synthetic tests, so there's no game-load number yet. Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Alone on main, its tests passed both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #388, #418, #421, #434, #470, #484, #485, #486 and #488 merged onto main 1504c1af6 (a225e593e). There the repo-consistency set gives 566 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 306/308. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same skip set. git merge-tree against current main 98a977b4b: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes. AI-assisted (Claude Code, Claude Opus 5.5).
This discussion has been locked. Commenting is limited to contributors.
No description provided.