runtime: order consecutive buffer copies on the same queue (RT-STREAM-TRANSFER-BARRIER) #1099
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!1099
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1099/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Moriz82 on GitHub · 2026-11-24 18:21 UTC · original
split/rt-stream-transfer-barrier→main· +64 −5 · 3 files · 1 commits · merged 2026-11-25 00:02 UTCClaimed in the coordination issue as: RT-STREAM-TRANSFER-BARRIER (claim).
Part of the split of #984 into small pull requests.
Depends on: none
Overlaps: #354 (closed without merging) supplies the transfer dependency. This child credits that contribution, adds the rollback switch and tests the emitted commands.
What and why
A D3D12 queue can submit overlapping buffer copies back to back. Without a Vulkan memory dependency, a later copy can read or overwrite bytes before the earlier transfer write finishes. Emit a transfer-stage memory barrier before each plain buffer copy, including the first one in a list. A preceding list on the same queue can have written those bytes. Real Vulkan contexts provide the barrier entry point. The existing query mock also exercises a context that omits it. Set
LEONIDA_ORDER_BUFFER_COPIES=0to restore the old behavior.Tested
Cross-built with clang-cl 23 and the xwin SDK. Ran the command-recording fixtures under Proton Experimental (Wine 11) on CachyOS Linux 7.3, Ryzen 5 5600X, 16 GB.
GPUs tested: none. The fixtures record Vulkan commands and check the stage and access masks. Native Windows, AMD, Intel and a game boot were not tested.
AI-assisted: yes
Checklist
🤖 Generated with Claude Code
@Plaaasma on GitHub · 2026-11-24 18:36 UTC · original
Native Windows check, AI-assisted (Claude Code). Windows 11, i9-13900K, 64 GB, RTX 4070 Ti 12 GB (NVIDIA 630.20), MSVC 2022 (VS 17 generator, Release), Vulkan.
Head
ddcffa634. Builtreplay_copy_offset_test, thenctest -C Release -R "^replay_copy_offset$" --output-on-failure --timeout 300:replay_copy_offset: passed, 0.06 sreplay_copy_offset_test --expect-unorderedon the PR build: exits 1, as intendedCross-check: the PR's test built against the base's
runtime/src/vulkan_replay.hfails both new checks (a buffer copy is ordered after earlier transfer writes ...,each back-to-back buffer copy is ordered after the transfer write before it) and passes with--expect-unordered, so the test does catch the missing barrier.1 passed, 0 failed.
@abnalstlll-byte on GitHub · 2026-11-24 18:40 UTC · original · approved these changes
Audited and verified. Emits TRANSFER_WRITE -> TRANSFER_READ | TRANSFER_WRITE transfer barrier before kCmdCopyBuffer in
untime/src/vulkan_replay.h, matching D3D12's implicit queue ordering on back-to-back buffer copies. Configurable via LEONIDA_ORDER_BUFFER_COPIES. Tests in
untime/test/replay_copy_offset_test.cpp pass cleanly. Approved.
@abnalstlll-byte on GitHub · 2026-11-24 18:54 UTC · original · approved these changes
Clean-Room Audit — PR #1099 (
RT-STREAM-TRANSFER-BARRIER)Well-scoped transfer ordering barrier (
TRANSFER_WRITE -> TRANSFER_READ | TRANSFER_WRITE) before queue buffer copies invulkan_replay.h, preservingLEONIDA_ORDER_BUFFER_COPIES=0escape hatch and adding regression tests inreplay_copy_offset_test.cpp. 0 game data.Verdict: APPROVED
@iFeyz on GitHub · 2026-11-24 19:51 UTC · original
AMD run (the gap the description lists): RX 9070 XT (RDNA4, GFX1201), AMD proprietary Windows driver 26.11.2 (LLPC, Vulkan 1.4.359), Windows 11, MSVC 2022 RelWithDebInfo.
Head
ddcffa634:replay_copy_offsetbuilt from it passes.@Deedlyy on GitHub · 2026-11-24 20:18 UTC · original
Recommendation: [MERGE]
Reasoning: Emits a transfer-stage memory barrier between back-to-back buffer copies on the same queue, fixing a real RAW/WAW hazard in the Vulkan replay, with a rollback switch and a test that fails on the base header. Verified on NVIDIA (Plaaasma, including a negative control) and AMD RX 9070 XT (iFeyz). Synchronization changes affect every title copy, so the rollback switch is useful. CI (label, change-scope, no-game-data and the Runtime jobs) is still queued awaiting maintainer workflow approval, so nothing has run in CI yet; GitHub reports no merge conflict with
main. Merge once the queued checks are green.Impact level: 5/10
@whoalin1 on GitHub · 2026-11-24 20:39 UTC · original
GPU verification (AI-assisted, overnight worker w4; independent run, not the author's).
Head tested:
ddcffa6on this machine's two GPUs.AMD Radeon iGPU (gfx1035, RDNA2, driver 24.10.24, Vulkan 1.3.280) — env:
VK_LOADER_DRIVERS_SELECT=*amd-vulkan* LEONIDA_VK_DEVICE=radeon VK_LOADER_LAYERS_DISABLE=~implicit~ LEONIDA_VK_VALIDATION=1 LEONIDA_PC_TAIL_UBO=1ctest --test-dir runtime/build -R "d3d12|vk_" --output-on-failure -j4: 115/142 passed, 27 failed. I rebuilt main (6293c1c4f) in a separate worktree and re-ran the same 27: identical failure set on main — pre-existing/environmental, not this PR.python -I scripts/run_gpu_tests.py --build runtime/build --work <dir>: 230/252 passed, 20 skipped, 2 failed — the 2 arems_clipandms_wave_info_s3, the known AMD iGPU LLPC crashes (open fixes #802/#808). No new failures; no validation errors reported by the suite.replay_*_test.exe, incl. the extendedreplay_copy_offset_test): all pass.NVIDIA RTX 4070 SUPER — env:
VK_LOADER_DRIVERS_SELECT=*nv-vk* LEONIDA_VK_DEVICE=4070 VK_LOADER_LAYERS_DISABLE=~implicit~ctest -R "d3d12|vk_" -j4: 141/142 passed; onlyd3d12_execute_indirect_validationfailed with 5 parity cases — the same 5 failures reproduce on unmodified main (verified on the baseline build), so pre-existing.run_gpu_tests.py: 203/252 passed, 49 skipped, 0 failed.Verdict: no regressions found on either GPU; barrier ordering holds under validation on the AMD iGPU. LGTM from this hardware.
@moffington on GitHub · 2026-11-24 22:12 UTC · original
Independent GPU verification at
ddcffa634on Linux, RTX 3060, NVIDIA 615.78.08.Added a synthetic chained-copy/readback probe covering intra-list and same-batch cross-list dependencies on both direct and copy queues.
3aa975421LEONIDA_ORDER_BUFFER_COPIES=0This confirms actual GPU data corruption from the missing dependency, beyond the command-recording assertions. All ten cases pass with the fix enabled.
No blocking issues found. AI-assisted testing.
@QemmHD on GitHub · 2026-11-25 00:02 UTC · original
Merging.
Why merged: RT-STREAM-TRANSFER-BARRIER: a transfer-write → transfer-read/write barrier goes before every vkCmdCopyBuffer, so back-to-back streamed copies are ordered. moffington measured SyncVal at 10 errors on the base and 0 on the head. Plaaasma (4070 Ti), iFeyz (RX 9070 XT) and whoalin1 (gfx1035) passed it. LEONIDA_ORDER_BUFFER_COPIES=0 turns it off (documented in docs/d3d12_vulkan.md).
Why it's good: replay_, vk_bc_zero_init, vk_queue and d3d12_close_parity: 16/16 both plain and under validation. A negative control on the cumulative build checked that the test really catches a missing barrier: with the barrier on,
--expect-unorderedfails; with the env var at 0, the ordered check fails and--expect-unorderedpasses. It also passes on top of #1055's vulkan_replay.h change. It adds one barrier per buffer copy, a small sync-policy cost with an opt-out.Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main
0f98d193c, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative with the rest of this batch on main507029d1e: the repo-consistency set gives 578 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 317/318 with the usual 11 skips; the only failure is main's pre-existing d3d12_depth_resolve. All d3d12_* tests under validation: 119/120 with 0 VUIDs. The semantic suite has only the known environment-only failure. git merge-tree against current main9c5e70661: 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).
@Gefik23 on GitHub · 2026-11-25 05:51 UTC · original
Tested
ddcffa634on NVIDIA GeForce RTX 4060 (Ada), driver 617.42, Windows 11 Pro build 26200, native Windows: pass.Built at this head with
scripts\build_runtime.ps1(MSVC 19.44, VS 2022 Build Tools, Ninja, RelWithDebInfo, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0).ctest -R ^replay_copy_offset -V: passed.ctest -C RelWithDebInfo: 296/297. The one failure isd3d12_execute_indirect_validation, which also fails on main on this host (stock Windows 11 d3d12core 10.0.26100.7309) and is fixed by #1066; this branch predates it. Game-data tests skipped (LEONIDA_GAME_DIR unset).AI-assisted (Claude Code ran the build and tests). No game files.