Repository navigation
Conversation
global_atomic_swap_x2 and buffer_atomic_swap_x2, with and without glc, were one 32-bit OpAtomicExchange per dword, so two lanes swapping into one element could get back halves of two different values (ItsNotRexed#4964 measured 96.7% of contended pairs torn on an RTX 5070 Ti; 76.4% here on an RTX 5080). They are now one 64-bit OpAtomicExchange on a uint64 PhysicalStorageBuffer pointer, declaring Int64Atomics (index feature shaderBufferInt64Atomics). --no-int64-atomics keeps the per-dword exchange as the fallback. The Int64Atomics plumbing uses ItsNotRexed#3908's names (INT64_ATOMICS, --no-int64-atomics, uses_int64_atomics, %_ptr_PSB_ulong, split64, shader_buffer_int64_atomics) and the same runtime/test-program lines, so the two compose. The runtime and the test programs enable shaderBufferInt64Atomics where the GPU has it; vk_compute_test and vk_harness exit 77 without it. New GPU fixture cs_w32_swap_x2_whole (2048 lanes, all four forms, every returned pair and final element must be a pair really written), translator tests in test_translate.py, fallback value tests, 64-bit PSB atomics in spirv_mini_interp, and a docs/design.md row. Found by Etr0p. AI-assisted (Claude Code).
|
Independent check — pass, GPU-verified on real NVIDIA hardware (Windows 11, RTX 5090, driver 617.42, Vulkan SDK 1.4.363, native llvm-mc,
AI-assisted (Devin); no game data. |
Kam471
left a comment
There was a problem hiding this comment.
Ran this at 89dcffd92 on Windows 11, RTX 5070 Ti.
tests/semantic/test_buffer_atomics_x2.py-> 6 tests, OK;test_global_atomics_x2.py-> 5 tests, OK.pytest tests/test_shader_checks.py -q-> 85 passed, 268 subtests passed.tests/test_translate.pywithLLVM_MC-> 600 passed.- GPU:
run_gpu_tests.py --filter swap_x2-> 1/1 passed,cs_w32_swap_x2_whole->2048 x 4 swaps, every pair whole; translator 1/1 +spirv-val. git diff --checkclean.
Atomic swap x2 on buffer/global now swaps all 64 bits as one Int64 atomic when the device has shaderInt64, instead of two 32-bit atomics that can tear between lanes; the fallback and single-dword paths are unchanged, and the new fixture pins the whole-pair result at scale. No blocking issue.
|
For the open question about retail contention, neither That leaves zero static swap-x2 sites to exercise in this DXBC corpus. The contention fixture supplies coverage the retail DXBC shaders cannot. This count excludes FSPX programs. CPU only, counts only, AI-assisted. |
|
Tested
I ran the PR's
In the first parent dispatch, the checker found 30 torn pairs out of 2,049 for global glc and 22 out of 2,049 for buffer glc. The PR passed every dispatch. This run covers the AMD path with 64-bit buffer atomics. AI-assisted. |
|
Tested
This adds an NVIDIA Ampere run next to the RTX 5090 (Windows), RTX 5080 (Linux) and AMD runs above. Not run: #4964's AI-assisted. Synthetic tests only; no game data. |
|
Tested 89dcffd on Intel UHD 630 (CFL GT2, subgroup 8..32), Mesa 25.2.8 ANV, Ubuntu 24.04, LEONIDA_VK_DEVICE=Intel: pass, and this GPU runs the Int64 path rather than skipping.
The --no-int64-atomics fallback was not run on the GPU: run_gpu_tests.py has no flag for it, so the fallback is covered only by the CPU tests above. AI-assisted. |
|
Tested
|
|
Independent Windows CPU verification on
|
main still swaps buffer/global swap_x2 as one 32-bit exchange per dword, which can tear; this branch's one 64-bit OpAtomicExchange (Int64Atomics, with --no-int64-atomics as the per-dword fallback) merges into main's translator without conflict. Resolved: the docs/design.md global atomics row merged sentence by sentence (main's wording plus this branch's swap_x2 change), the buffer _x2 row and the new 64-bit swap_x2 row as on this branch; VulkanDeviceInfo keeps shader_buffer_int64_atomics next to main's shader_dir comment; test_shader_checks.py keeps main's cs_fmt_all and this branch's cs_w32_swap_x2_whole (TOTAL + 15). Tested on an RTX 5080: run_gpu_tests.py cs_w32_swap_x2_whole passes (2048 x 4 swaps, every pair whole); translated with INT64_ATOMICS off it fails (global glc 1856 of 2049 pairs torn, buffer glc 771, buffer element torn). Full run_gpu_tests.py: 184 of 233 passed, 48 skipped, 1 failed (ms_wave_info_s3, which fails the same way on main). clang-cl build under Wine: d3d12_com, d3d12_vulkan_device, d3d12_compute, d3d12_stores_atomics pass. test_buffer_atomics_x2, test_global_atomics_x2, test_shader_checks, test_translate and tests/test_docs_*.py pass.
|
Independent Windows GPU check of 0363e3de on 561b65a8. Windows x64, RTX 3080 Ti / 621.35, MSVC, LLVM MC 23.1.6, Vulkan SDK 1.4.363.0, CPython 3.12.8. The stock wave32 Synthetic inputs only. AI-assisted. |
|
Tested
No new failure compared with |
shayderrr
left a comment
There was a problem hiding this comment.
Review
Reviewed change in PR #5100: rdna2spirv: global/buffer atomic_swap_x2 swap all 64 bits at once with Int64 atomics, no torn pairs (SHADER-868).
Scope: docs/design.md, runtime/shims/d3d12_com.h, runtime/shims/d3d12_vulkan_device.cpp, +14 more
Diff: +335 / -42 across 17 file(s).
The change stays inside the stated scope and the touched files line up with the description. No unrelated production paths are pulled in, and the stated behavior is directly exercised by the diff. I'm approving this one.
Reviewed by shayderrr via automated batch review.
|
Thanks @tedin7 - I went through rdna2spirv: global/buffer atomic_swap_x2 swap all 64 bits at once with Int64 atomics, n... and the diff around |
Claimed in the coordination issue as: #4933 (comment)
Found by Etr0p: under contention, almost every pair that
global_atomic_swap_x2 ... glcreturned on NVIDIA was torn (96.7% on an RTX 5070 Ti Laptop GPU, measured with #4964'sswap_x2_contend.py; finding in #4933 (comment)).What and why
Gen.global_atomic_x2andGen.buffer_atomic_x2intools/rdna2spirv.pyswapped a 64-bit element as one 32-bitOpAtomicExchangeper dword. The console swaps the element whole. With two exchanges, two lanes swapping into one element can each get back halves of two different values (A's low dword with B's high one), and the element can end up mixed too. A shader that takes a 64-bit value out of a shared slot this way (a free-list head, a packed pointer) then gets a value nobody wrote.global_atomic_swap_x2andbuffer_atomic_swap_x2, with and withoutglc, are now one 64-bitOpAtomicExchangeon auint64PhysicalStorageBuffer pointer (Gen.atomic_swap64). The address, the bounds check and the 8-byte alignment guard are the same as before. Inactive, out-of-range and unaligned lanes still don't touch memory.Int64Atomics, and the index lists the device featureshaderBufferInt64Atomics.--no-int64-atomicskeeps the old translation, one 32-bit exchange per dword, for a device without the feature.and/or/xor_x2are unchanged: a bitwise op gives the same memory one dword at a time.Overlap with #3908 (Vonsek, open). #3908 adds the 64-bit
smin/umin/smax/umax/inc/dec/cmpswap_x2atomics and does not touchswap_x2. This PR uses the same mechanism with the same names, so the two compose:INT64_ATOMICSand--no-int64-atomics,Gen.uses_int64_atomics, theInt64Atomicscapability,%_ptr_PSB_ulong,Gen.split64, and theInt64Atomics -> shaderBufferInt64Atomicsindex mapping.VulkanDeviceInfo::shader_buffer_int64_atomicsind3d12_vulkan_device.cpp(with itsd3d12_vulkan_device_testcheck),vk_test_device.h,vk_compute_test,vk_harness,vk_pipeline_check, and the 64-bit PhysicalStorageBuffer atomics intests/semantic/spirv_mini_interp.py.--no-int64-atomics, rdna2spirv + runtime: 64-bit buffer/global smin/umin/smax/umax/inc/dec/cmpswap atomics (Int64Atomics, measured on RDNA2) #3908's forms stayUnsupported, andswap_x2falls back to the per-dword exchange.vk_compute_test.cpp, the Int64Atomics check sits after the Float64 block's closing brace. The current rdna2spirv + runtime: 64-bit buffer/global smin/umin/smax/umax/inc/dec/cmpswap atomics (Int64Atomics, measured on RDNA2) #3908 head puts it inside that block and does not compile (reported on rdna2spirv + runtime: 64-bit buffer/global smin/umin/smax/umax/inc/dec/cmpswap atomics (Int64Atomics, measured on RDNA2) #3908).--no-int64-atomics, theshader_metaline, and the two atomic rows ofdocs/design.md. GPU test: contended global_atomic_swap_x2 glc, dword sets exact, torn pairs counted (TEST-561) #4964 also adds cases tocheck.py,run_gpu_tests.pyand thetests/test_shader_checks.pytotal, so the same applies there.Tests (fail before, pass after):
runtime/test/shaders/cs_w32_swap_x2_whole.asm: 64 workgroups of 32. Every invocation swaps its own pair (low = (0x51 + form) << 24 | i,high = ~low) into one shared element per form: globalglc, bufferglc, global, buffer.glcform, the returned pairs plus the element's final pair must be the fill plus every pair written, each exactly once. So no pair is torn, lost or handed out twice.glcmust end as a pair that was written.check.py(swap_x2_whole_words/swap_x2_whole_test) andscripts/run_gpu_tests.py. It reports SKIP where the device has noshaderBufferInt64Atomics(vk_compute_test exits 77).tests/test_translate.py::test_swap_x2_is_one_64bit_exchangetranslates that fixture and passesspirv-val. It checks fourOpAtomicExchange %ulongon%_ptr_PSB_ulongpointers andOpCapability Int64Atomics. With--no-int64-atomicsit checks eight 32-bit exchanges and noInt64Atomics.tests/semantic/test_global_atomics_x2.pyandtest_buffer_atomics_x2.py: the existing swap cases now run the 64-bit path in the interpreter. A new case pins the fallback's values, including an out-of-range buffer lane.tests/test_shader_checks.py: the checker accepts a whole heap and reports a torn returned pair (global and buffer) and a torn final element. Also covers the fake-harness case and the total.docs/design.md: a new row, 64-bitswap_x2(buffer and global). The global atomics row and thebuffer_atomic_{and,or,xor,swap}_x2row point to it instead of the tearing approximation.Tested
NVIDIA GeForce RTX 5080, Linux, driver 580.65.06, Vulkan SDK 1.4.363.1, llvm-mc on PATH, Python 3.13. Test programs built with GCC + Ninja (
-j64),mainat3faac557and this branch side by side.Torn pairs, #4964's
swap_x2_contend.py --runs 200 --strict(2,048 invocations ofglobal_atomic_swap_x2 ... glcinto one element, 409,800 pairs):main(one 32-bit exchange per dword)New fixture
cs_w32_swap_x2_whole, repeated dispatches:main's translator: 50 of 50 dispatches fail. The first had 1,860 of 2,049 global pairs and 780 of 2,049 buffer pairs torn.LEONIDA_W64_EMULATE=1.scripts/run_gpu_tests.py: 222 shaders translated, all 222 passspirv-val, 0 failed.mainLEONIDA_W64_EMULATE=1The new line in both runs reads
PASS cs_w32_swap_x2_whole 2048 x 4 swaps, every pair whole.CPU tests:
python -m pytest tests/test_translate.py: 600 passed (main: 596).python -m unittest discover -s tests/semantic -p "test_*atomic*.py": 424 OK (main: 422).tests/semantic/test_buffer_swizzle.pyandtest_interp.py(pytest): 48 passed, the same asmain.tests/test_shader_checks.py,test_design_contract_rows.py,test_docs_design_rows.py,test_docs_cli_flags.pyandtest_docs_repo_paths.py: OK.Windows runtime:
d3d12_vulkan_device_test.execross-builds with clang-cl 21 + lld-link against the xwin sysroot. It was not run under Wine, because the Wine prefix on the test machine did not start (could not load kernel32.dll).Not covered
shaderBufferInt64Atomicson RDNA2. AMD numbers from a tester would be welcome.shaderBufferInt64Atomics: the fixture SKIPs there, and the fallback is checked only on the CPU.make_game.pydoes not forward--no-int64-atomics(itsFALLBACK_FLAGS), the same as in rdna2spirv + runtime: 64-bit buffer/global smin/umin/smax/umax/inc/dec/cmpswap atomics (Int64Atomics, measured on RDNA2) #3908.d3d12_vulkan_device_testunder Wine or on Windows.No game files.
AI-assisted (Claude Code).