runtime: order consecutive buffer copies on the same queue (RT-STREAM-TRANSFER-BARRIER) #1099

Manually merged
github merged 1 commit from gh-pr/1099/head into gh-pr/1099/base 2026-11-26 09:38:08 +00:00
Owner

@⁠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 UTC

Claimed 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=0 to 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.

cmake --build runtime/build/boot --target gta6rt replay_copy_offset_test replay_query_edges_test -j6
ctest --test-dir runtime/build/boot -j1 -R '^replay_(copy_offset|query_edges)$' --output-on-failure
(cd runtime/build/boot && LEONIDA_ORDER_BUFFER_COPIES=0 "$WINE" replay_copy_offset_test.exe --expect-unordered)
Configuration Single copy ordered Back-to-back copies ordered Result
Main plus tests 0/1 0/2 Both ordering assertions failed.
Child, default 1/1 2/2 Both replay fixtures passed.
Child, switch set to 0 0/1 0/2 The explicit unordered control passed.

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

  • One commit on upstream main at the cut. Clean merge check.
  • One copy-ordering change with a regression test and a rollback control.
  • Changed-file game-data guard and whitespace check passed.
  • No translator rule changed.

🤖 Generated with Claude Code

**@⁠Moriz82** on GitHub · 2026-11-24 18:21 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1099) `split/rt-stream-transfer-barrier` → `main` · +64 −5 · 3 files · 1 commits · merged 2026-11-25 00:02 UTC Claimed in the coordination issue as: RT-STREAM-TRANSFER-BARRIER ([claim](https://git.gtahub.st/github/ubiquitarianism--leonida/issues/14)). 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=0` to 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. ```sh cmake --build runtime/build/boot --target gta6rt replay_copy_offset_test replay_query_edges_test -j6 ctest --test-dir runtime/build/boot -j1 -R '^replay_(copy_offset|query_edges)$' --output-on-failure (cd runtime/build/boot && LEONIDA_ORDER_BUFFER_COPIES=0 "$WINE" replay_copy_offset_test.exe --expect-unordered) ``` | Configuration | Single copy ordered | Back-to-back copies ordered | Result | | --- | --- | --- | --- | | Main plus tests | 0/1 | 0/2 | Both ordering assertions failed. | | Child, default | 1/1 | 2/2 | Both replay fixtures passed. | | Child, switch set to 0 | 0/1 | 0/2 | The explicit unordered control passed. | 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 - [x] One commit on upstream main at the cut. Clean merge check. - [x] One copy-ordering change with a regression test and a rollback control. - [x] Changed-file game-data guard and whitespace check passed. - [x] No translator rule changed. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Vulkan transfer writes can overlap a later read or write when D3D12 submits
plain buffer copies in sequence.

Emit the transfer memory dependency from natterman12's #354 (GPL-3.0) before
every plain buffer copy. Allow an explicit rollback for comparison, and
record the access masks in the synthetic replay fixture.

The base failed both copy-ordering assertions. The child passed both replay
fixtures, and the rollback control observed no ordering barrier.


AI-assisted (Codex and Claude Code agents).

Co-authored-by: Plaaasma <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:38:05 +00:00
github manually merged commit ddcffa634e into gh-pr/1099/base 2026-11-26 09:38:08 +00:00
Author
Owner

@⁠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. Built replay_copy_offset_test, then ctest -C Release -R "^replay_copy_offset$" --output-on-failure --timeout 300:

  • replay_copy_offset: passed, 0.06 s
  • replay_copy_offset_test --expect-unordered on the PR build: exits 1, as intended

Cross-check: the PR's test built against the base's runtime/src/vulkan_replay.h fails 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.

**@⁠Plaaasma** on GitHub · 2026-11-24 18:36 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1099#issuecomment-7140889368) 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`. Built `replay_copy_offset_test`, then `ctest -C Release -R "^replay_copy_offset$" --output-on-failure --timeout 300`: - `replay_copy_offset`: **passed**, 0.06 s - `replay_copy_offset_test --expect-unordered` on the PR build: exits 1, as intended Cross-check: the PR's test built against the base's `runtime/src/vulkan_replay.h` fails 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.
Author
Owner

@⁠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:40 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1099#pullrequestreview-6045216617) · **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.
Author
Owner

@⁠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 in vulkan_replay.h, preserving LEONIDA_ORDER_BUFFER_COPIES=0 escape hatch and adding regression tests in replay_copy_offset_test.cpp. 0 game data.

Verdict: APPROVED

**@⁠abnalstlll-byte** on GitHub · 2026-11-24 18:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1099#pullrequestreview-6045401015) · **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 in `vulkan_replay.h`, preserving `LEONIDA_ORDER_BUFFER_COPIES=0` escape hatch and adding regression tests in `replay_copy_offset_test.cpp`. 0 game data. **Verdict: APPROVED**
Author
Owner

@⁠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_offset built from it passes.

**@⁠iFeyz** on GitHub · 2026-11-24 19:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1099#issuecomment-7142679570) 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_offset` built from it **passes**.
Author
Owner

@⁠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

**@⁠Deedlyy** on GitHub · 2026-11-24 20:18 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1099#issuecomment-7143330254) **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
Author
Owner

@⁠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: ddcffa6 on 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=1

  • ctest --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 are ms_clip and ms_wave_info_s3, the known AMD iGPU LLPC crashes (open fixes #802/#808). No new failures; no validation errors reported by the suite.
  • CPU replay tests (all 9 replay_*_test.exe, incl. the extended replay_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; only d3d12_execute_indirect_validation failed 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.

**@⁠whoalin1** on GitHub · 2026-11-24 20:39 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1099#issuecomment-7143877711) GPU verification (AI-assisted, overnight worker w4; independent run, not the author's). Head tested: ddcffa6 on 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=1` - `ctest --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 are `ms_clip` and `ms_wave_info_s3`, the known AMD iGPU LLPC crashes (open fixes #802/#808). No new failures; no validation errors reported by the suite. - CPU replay tests (all 9 `replay_*_test.exe`, incl. the extended `replay_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; only `d3d12_execute_indirect_validation` failed 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.
Author
Owner

@⁠moffington on GitHub · 2026-11-24 22:12 UTC · original

Independent GPU verification at ddcffa634 on 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.

Configuration SyncVal errors Incorrect bytes
Cut base 3aa975421 10 Up to 65536/65536
PR HEAD 0 0
HEAD with LEONIDA_ORDER_BUFFER_COPIES=0 10 Corruption reproduced

This 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.

**@⁠moffington** on GitHub · 2026-11-24 22:12 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1099#issuecomment-7145945636) Independent GPU verification at `ddcffa634` on 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. | Configuration | SyncVal errors | Incorrect bytes | |---|---:|---:| | Cut base `3aa975421` | 10 | Up to 65536/65536 | | PR HEAD | 0 | 0 | | HEAD with `LEONIDA_ORDER_BUFFER_COPIES=0` | 10 | Corruption reproduced | This 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.
Author
Owner

@⁠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-unordered fails; with the env var at 0, the ordered check fails and --expect-unordered passes. 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 main 507029d1e: 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 main 9c5e70661: 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-25 00:02 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1099#issuecomment-7148065935) 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-unordered` fails; with the env var at 0, the ordered check fails and `--expect-unordered` passes. 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 main 507029d1e: 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 main 9c5e70661: 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).
Author
Owner

@⁠Gefik23 on GitHub · 2026-11-25 05:51 UTC · original

Tested ddcffa634 on 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.
  • Full ctest -C RelWithDebInfo: 296/297. The one failure is d3d12_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.

**@⁠Gefik23** on GitHub · 2026-11-25 05:51 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1099#issuecomment-7154199789) Tested ddcffa634 on 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. - Full `ctest -C RelWithDebInfo`: 296/297. The one failure is `d3d12_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.
This discussion has been locked. Commenting is limited to contributors.
No description provided.