Skip to content

d3d12: SYNC_COPY waits for the CLEAR stage too, ordering WriteBufferImmediate before copies (OLD-10048) - #751

Merged
QemmHD merged 1 commit into
ProjectLeonida:mainfrom
abnalstlll-byte:restore/old-10048-sync-copy-clear-stage
Nov 24, 2026
Merged

QemmHD merged 1 commit into
ProjectLeonida:mainfrom
abnalstlll-byte:restore/old-10048-sync-copy-clear-stage

Conversation

@abnalstlll-byte

Copy link
Copy Markdown
Contributor

Restore old upstream PR 10048 (OLD-10048 / D3D-838).

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.

Clean-room verified; zero game data.

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 <noreply@anthropic.com>
@moffington

Copy link
Copy Markdown
Contributor

Independently reviewed a744fa8ab against merge base 2d73c242f on Linux with an RTX 3060 and Vulkan synchronization validation enabled.

Applying the new part K regression test to the base reproduces the READ_AFTER_WRITE hazard between vkCmdUpdateBuffer and vkCmdCopyBuffer. On the PR head, all parts A–K pass with zero validation errors, including the 360 sync/access combinations.

The updated stage mapping is consistent across global, buffer and texture barriers, and the transfer-only queue mask remains intact.

Full suite: 70 passed, 1 skipped, 1 failed. The vk_queue failure produces the same 10 WAW validation errors on both revisions.

No regressions found. LGTM.

@Timon360SB

Copy link
Copy Markdown
Contributor

Independent verification — Turing and Blackwell

Baseline: 2d73c242fddfe26d57b52ee150704e6c3b23cff4

PR head: a744fa8ab150c120babdbade56da470291d070cd

Environment

Configuration RTX 2060 SUPER RTX 5070
Architecture Turing Blackwell
NVIDIA 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
Configuration RelWithDebInfo RelWithDebInfo
Generator Ninja Multi-Config Ninja Multi-Config

Synchronization validation enabled. Three repetitions per revision on each GPU.

Results

Test 2060S BASE 2060S HEAD 5070 BASE 5070 HEAD
vk_command_replay 0/3 0/3 0/3 0/3
d3d12_state_map 3/3 3/3 3/3 3/3
vk_sync_validation 3/3 3/3 3/3 3/3
New part K N/A 3/3 N/A 3/3

Total: 36 CTest executions — 24 passed, 12 failed, 0 skipped.

Part K results are included in the vk_command_replay executions, not counted as separate CTests.

Targeted verification

All six HEAD executions successfully completed the new part K:

K: SYNC_COPY orders WriteBufferImmediate (vkCmdUpdateBuffer, CLEAR stage) before a copy

The updated state-map checks also passed on both architectures.

All 12 synchronization validation positive controls passed.

Existing failures

The overall vk_command_replay test fails on both revisions and both GPUs with the same reported depth-copy validation error:

VUID-vkCmdCopyBufferToImage-pRegions-07931
GPU BASE HEAD
RTX 2060 SUPER 30 30
RTX 5070 30 30

Each execution reports 10 instances, subject to the validation layer's duplicate message limit. Parts H and I report validation errors on both revisions.

Conclusion

  • The new WriteBufferImmediate regression scenario succeeds on Turing and Blackwell, with no new validation errors in part K.
  • No regression was observed in the selected tests.
  • The existing depth-copy failures remain unchanged.
  • Part K is absent from BASE, so this is independent verification of the fixed path, not a direct reproduction of the original hazard on the baseline.

Synthetic fixtures only. No game files used.

AI-assisted test automation and result analysis.

@SweatierKey SweatierKey left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Independent Windows 11 + NVIDIA GeForce RTX 5070 Ti (driver 616.92) verification applied cleanly on main@d0da7dade (portable clang-cl 23.1.6 + Windows SDK 10.0.26100):

  • d3d12_state_map_test.exe: PASS (RC=0, confirms SYNC_COPY maps to COPY | CLEAR).
  • vk_command_replay_test.exe on RTX 5070 Ti: PASS (RC=0, Parts A–K including new Part K ordering WriteBufferImmediate/vkCmdUpdateBuffer before CopyBufferRegion).
  • python3 -I scripts/check_no_game_data.py: PASS.

Clean, minimal fix; no game data. AI-assisted: yes.

QemmHD added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** D3D-CLEAR-DEPTH-RANGE: enables VK_EXT_depth_range_unrestricted where the device has it, so depth clears outside [0,1] (and NaN) behave like D3D12 instead of being clamped. Without the extension it keeps clamping, and NaN becomes 0. Four independent passes; on AMD (660M, 7900 XTX), d3d12_clear still fails only on the NaN rows, which is the driver issue tracked in #307, not this PR.

**Why it's good:** On the 4070 SUPER with validation on, main's d3d12_clear_test exits 1 with 4x VUID-VkClearDepthStencilValue-depth-00022. With this PR it exits 0 with no VUIDs, and the 1.5 / -0.5 / NaN clears match WARP. The new d3d12_clear_restricted_depth passes, and so do d3d12_clear and d3d12_clear_formats.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e2: no conflicts, and none of these touch the files #891/#882 changed. 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 added a commit that referenced this pull request Nov 24, 2026
Merging.

**Why merged:** VK-SAMPLER-UNNORM-BIAS: an unnormalized-coordinates sampler gets mipLodBias 0, which VUID-VkSamplerCreateInfo-unnormalizedCoordinates-01074 requires. kawaii-shakal ran it under ASan/UBSan and showed the new check fails on main.

**Why it's good:** gfx10_descriptors and d3d12_descriptor pass both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e2: no conflicts, and none of these touch the files #891/#882 changed. 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

QemmHD commented Nov 24, 2026

Copy link
Copy Markdown
Collaborator

Merging.

Why merged: OLD-10048: SYNC_COPY maps to COPY|CLEAR, so WriteBufferImmediate (vkCmdUpdateBuffer) and the query zero-fill are ordered before later copies. moffington reproduced the read-after-write hazard on the base, and Timon360SB and SweatierKey checked it independently. Part K of vk_command_replay_test covers it.

Why it's good: vk_command_replay, d3d12_state_map and replay_query_edges pass both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e2: no conflicts, and none of these touch the files #891/#882 changed. 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
QemmHD merged commit 9ca049e into ProjectLeonida:main Nov 24, 2026
9 of 13 checks passed
QemmHD added a commit that referenced this pull request Nov 24, 2026
…dup-wait

Merging.

**Why merged:** RT-RETIRE-TICKETS-DEDUP-WAIT: pending_through() merges entries per semaphore to the highest value, and completed_ can no longer move backwards. moffington (ASan/UBSan, with a differential test that fails on the base), Timon360SB, KernelSmoker and SweatierKey checked it independently.

**Why it's good:** retire_tickets passes both plain and under validation.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 3295055, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative: #516, #535, #751, #935 and #662 merged onto main 955d9be. There the repo-consistency set gives 571 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 307/309. The 2 failures are the same pre-existing ones as main (d3d12_execute_indirect_validation, d3d12_depth_resolve), with the same 11 skips. git merge-tree against current main 71f99e2: no conflicts, and none of these touch the files #891/#882 changed. 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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants