rdna2spirv: add --int64-atomics option for 64-bit OpAtomicExchange on *_atomic_swap_x2 (SHADER-868) #251
Closed
leonida/mandy
kotekompotek wants to merge 0 commits from
work/shader-868-atomic-swap-x2 into main
pull from: work/shader-868-atomic-swap-x2
merge into: leonida:main
leonida:main
leonida:github-pr/3295
leonida:beta
leonida:docs/changelog-3483-3500
leonida:github-pr/3294
leonida:github-pr/2975
leonida:github-pr/2815
leonida:feat/gate-driver-start
leonida:feat/skip-pipelines-release
leonida:perf/lazy-compare
leonida:perf/mwaitx-wait
leonida:test/prio-ceiling-main
leonida:fix/ab-cpu-stdout
leonida:fix/gate-old-crashes
leonida:diag/ab-cpu
leonida:test/main-0312
leonida:github-pr/3291
leonida:diag/indirect-clamp-census
leonida:feat/barrier-enhanced
leonida:perf/texture-frame-ceiling
leonida:perf/dstorage-threads
leonida:fix/console-queue-dma-tables
leonida:fix/port-descriptors-record-parts
leonida:fix/frame-waits-fence
leonida:fix/console-sampler-words
leonida:fix/graphics-userdata-spill
leonida:fix/xg-reserved-layout-rotation
leonida:fix/barrier-console-flags
leonida:fix/switches-wait-test-child
leonida:test/list-value-waits
leonida:test/lot-gxdk-0412
leonida:fix/bvh-compacted-size
leonida:docs/i18n-quickstarts
leonida:feat/native-pipeline-slots
leonida:fix/clippy-leonida-gpu
leonida:fix/list-value-producers
leonida:fix/descriptor-page-straddle
leonida:fix/xmem-low-window
leonida:fix/ffx-jitter-never-zero
leonida:fix/run-stdout-closed
leonida:github-pr/2892
leonida:github-pr/2896
leonida:feat/warm-save-every
leonida:github-pr/2980
leonida:github-pr/2994
leonida:github-pr/3005
leonida:github-pr/3010
leonida:github-pr/3136
leonida:github-pr/3303
leonida:github-pr/3220
leonida:github-pr/3143
leonida:github-pr/3330
leonida:github-pr/3226
leonida:github-pr/3187
leonida:carry/3395
leonida:github-pr/2946
leonida:github-pr/2947
leonida:github-pr/2945
leonida:github-pr/2983
leonida:github-pr/3001
leonida:github-pr/3372
leonida:github-pr/3128
leonida:github-pr/3296
leonida:github-pr/2588
leonida:github-pr/3119
leonida:github-pr/3378
leonida:fix/crash-diagnostics
leonida:feat/dlss-mip-bias
leonida:fix/retired-out-of-order
leonida:fix/dxr-postbuild-barrier
leonida:fix/amd-relay-default
leonida:fix/removed-report-wait
leonida:feat/heap-twin
leonida:feat/vram-margin
leonida:github-pr/2472
leonida:github-pr/3123
leonida:github-pr/3088
leonida:assets/annonce-v1
leonida:github-pr/2794
leonida:github-pr/3300
leonida:github-pr/3304
leonida:github-pr/3308
leonida:github-pr/3367
leonida:github-pr/3369
leonida:fix/launcher-dlss-diagnostics
leonida:github-pr/3269
leonida:github-pr/2957
leonida:github-pr/3205
leonida:fix/crash-zero-guard
leonida:github-pr/3185
leonida:github-pr/3099
leonida:github-pr/3104
leonida:github-pr/3348
leonida:github-pr/3379
leonida:github-pr/3377
leonida:perf/darner-title-priority-ceiling
leonida:github-pr/3376
leonida:gh-readonly-queue/main/pr-3311-b5c45b663dbc5a9c3532bb3f307e5f81b32faefa
leonida:gh-readonly-queue/main/pr-3088-af22e7847ff5808f72d1a1881c24be2fafd20b54
leonida:gh-readonly-queue/main/pr-3123-7f3fa026a94c6646e89244f28e1ce22290361867
leonida:github-pr/3373
leonida:github-pr/3368
leonida:github-pr/3198
leonida:gh-readonly-queue/main/pr-3354-637baa0b77ba47222e7280b17c1a59c6a1781d57
leonida:gh-readonly-queue/main/pr-3365-d7a0e0196a43834813014b4bd3aa5502a8263b14
leonida:gh-readonly-queue/main/pr-3361-5dfe8bbd05ed12fb2f2e1718d9af77a7c5f46fd8
leonida:gh-readonly-queue/main/pr-3366-8da9148204e9d12c585efa9ac2b7cc1ab08c7682
leonida:github-pr/3346
leonida:github-pr/3375
leonida:github-pr/2958
leonida:github-pr/3151
leonida:github-pr/3307
leonida:github-pr/3278
leonida:github-pr/3374
leonida:fix/runtime-test-conservative-fixtures
leonida:github-pr/3366
leonida:ci/shard-semantic-linux
leonida:github-pr/3354
leonida:docs/fg-limit-fps-switch
leonida:github-pr/3365
leonida:fix/read-file-hard-link
leonida:github-pr/3364
leonida:fix/book-slot-heap-never-read
leonida:github-pr/3361
leonida:github-pr/3263
leonida:github-pr/3360
leonida:github-pr/3353
leonida:github-pr/3331
leonida:fix/alias-later-queued-submissions
leonida:github-pr/3352
leonida:github-pr/3228
leonida:github-pr/3349
leonida:claude/gallant-sagan-aamatr
leonida:github-pr/3200
leonida:github-pr/3132
leonida:github-pr/3323
leonida:github-pr/3332
leonida:github-pr/3340
leonida:github-pr/3311
leonida:github-pr/3334
leonida:github-pr/3297
leonida:github-pr/3256
leonida:github-pr/2567
leonida:github-pr/2851
leonida:d3d12/agility-sdk-621
leonida:github-pr/3164
leonida:github-pr/3114
leonida:github-pr/3050
leonida:github-pr/3113
leonida:github-pr/3326
leonida:github-pr/3144
leonida:github-pr/2642
leonida:github-pr/3072
leonida:github-pr/2789
leonida:github-pr/2643
leonida:github-pr/3009
leonida:github-pr/3035
leonida:github-pr/3031
leonida:github-pr/2686
leonida:github-pr/2834
leonida:github-pr/3321
leonida:github-pr/3325
leonida:github-pr/3290
leonida:github-pr/3324
leonida:github-pr/3130
leonida:claude/fervent-curie-m19lnr
leonida:github-pr/3309
leonida:github-pr/3305
leonida:github-pr/3306
leonida:github-pr/3302
leonida:github-pr/3301
leonida:github-pr/3345
leonida:github-pr/3211
leonida:github-pr/3027
leonida:github-pr/3286
leonida:github-pr/3235
leonida:github-pr/3265
leonida:github-pr/3275
leonida:codex/skip-no-hit-ray-passes
leonida:github-pr/2823
leonida:github-pr/2911
leonida:github-pr/3262
leonida:github-pr/3125
leonida:github-pr/3206
leonida:github-pr/3250
leonida:github-pr/3238
leonida:github-pr/3188
leonida:github-pr/2952
leonida:github-pr/3217
leonida:github-pr/3168
leonida:t3/preserve-fsr-sdk-restart-path
leonida:t3/propagate-host-failure-hresult
leonida:github-pr/3209
leonida:t3/launcher-custom-parameters
leonida:github-pr/3207
leonida:github-pr/3183
leonida:github-pr/3160
leonida:github-pr/3201
leonida:ci/less-to-run
leonida:github-pr/2930
leonida:github-pr/2797
leonida:github-pr/2999
leonida:perf/native-compute-shader-forms
leonida:github-pr/3191
leonida:github-pr/3011
leonida:github-pr/3019
leonida:github-pr/2996
leonida:gh-readonly-queue/main/pr-2789-45dc41f95c1cd0dcc29c2c50582e0e9af8a77259
leonida:claude/blissful-franklin-ukp7ag
leonida:github-pr/3141
leonida:github-pr/3156
leonida:github-pr/3150
leonida:github-pr/3153
leonida:github-pr/3163
leonida:github-pr/3142
leonida:github-pr/3139
leonida:github-pr/2841
leonida:github-pr/3069
leonida:github-pr/3098
leonida:github-pr/3107
leonida:github-pr/3071
leonida:github-pr/2774
leonida:github-pr/2889
leonida:github-pr/3075
leonida:github-pr/2661
leonida:github-pr/3064
leonida:github-pr/3054
leonida:github-pr/3049
leonida:github-pr/2855
leonida:github-pr/2943
leonida:github-pr/3016
leonida:github-pr/2887
leonida:github-pr/3006
leonida:github-pr/3003
leonida:github-pr/2993
leonida:notes/card-time-and-plant-flicker
leonida:github-pr/2989
leonida:feat/vulkan-rs
leonida:github-pr/2985
leonida:github-pr/2951
leonida:github-pr/2982
leonida:github-pr/752
leonida:github-pr/792
leonida:github-pr/2877
leonida:github-pr/2654
leonida:github-pr/2893
leonida:github-pr/2948
leonida:github-pr/2944
leonida:github-pr/2919
leonida:github-pr/2915
leonida:archive/ci/less-to-run/20261202T1121Z
leonida:github-pr/2800
leonida:github-pr/2822
leonida:github-pr/2833
leonida:github-pr/2840
leonida:github-pr/2831
leonida:github-pr/2832
leonida:github-pr/2801
leonida:github-pr/2890
leonida:github-pr/2891
leonida:github-pr/2664
leonida:github-pr/2807
leonida:rt-call-trace
leonida:github-pr/2755
leonida:perf/ahead-split
leonida:github-pr/2587
leonida:github-pr/2698
leonida:github-pr/2609
leonida:github-pr/3219
leonida:docs/readme-runtime-proposal
leonida:github-pr/2017
leonida:github-pr/1741
leonida:github-pr/1667
leonida:codex/coord-claim-check-20261124-7e48
No reviewers
Assignees
Clear assignees
No assignees
Labels
Clear labels
bug
Something isn't working
dependencies
Pull requests that update a dependency file
documentation
Improvements or additions to documentation
enhancement
New feature or request
missing claim
Needs a claim in #14
needs rebase
Conflicts with the base branch: rebase it on main
needs-triage
Needs maintainer evaluation before the next triage state
question
Further information is requested
ready-for-agent
Fully specified and ready for an AFK agent
submodules
Pull requests that update submodules code
No labels
bug
dependencies
documentation
enhancement
missing claim
needs rebase
needs-triage
question
ready-for-agent
submodules
Projects
Clear projects
No items
No project
Milestone
Clear milestone
No items
No milestone
Dependencies
No dependencies set
Notifications
1 participant
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".
No due date set.
Reference
leonida/mandy!251
Loading…
Reference in a new issue
No description provided.
Delete branch "work/shader-868-atomic-swap-x2"
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?
Pull request closed
This pull request cannot be reopened because the branch was deleted.
Claimed in the coordination issue as: SHADER-868 (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7140050149)
What and why
ds_wrxchg_rtn_b64is untouched).--int64-atomicsflag forwarding inmake_game.py(FALLBACK_FLAGSand CLI parser) alongsidetools/rdna2spirv.pyandruntime/test/shaders/build.py(LEONIDA_INT64_ATOMICS=1).Global atomicsandbuffer_atomic_{and,or,xor,swap}_x2rows indocs/design.mdto document opt-in--int64-atomicsvs the default 32-bit dword-pair approximation.runtime/test/shaders/cs_atomic_swap_x2_int64.asm, registered it inruntime/test/shaders/check.py,scripts/run_gpu_tests.py, andtests/semantic/regen_fixtures.py(tests/semantic/fixtures/disasm/cs_atomic_swap_x2_int64.s).14eaf6052: enabledshaderBufferInt64AtomicsonVkPhysicalDeviceVulkan12Featuresinruntime/shims/d3d12_vulkan_device.cpp(recorded inruntime/shims/d3d12_com.h, asserted inruntime/test/d3d12_vulkan_device_test.cpp), replaced the single-threadcs_atomic_swap_x2_int64.asmfixture with a 64-thread tearing check, and added dedicated--int64-atomicsrunner pass inscripts/run_gpu_tests.py.Tested
On commit
14eaf6052:python -I tests/semantic/regen_fixtures.py --check(OK)python -I tests/semantic/test_atomic_swap_x2_int64.py(6/6 OKviaspirv_mini_interp.run_workgroup, 64 threads + 14= OpAtomicExchange %ulong)tests/semantic/test_fixtures.py&tests/semantic/test_regen_fixtures.py(OK)tests/test_docs_*.py(OK)compileall(OK)/W4compile-check ofruntime/shims/d3d12_vulkan_device.cpp&runtime/test/d3d12_vulkan_device_test.cpp(OK)GPUs tested: n/a
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.I tested this on a GPU. The 64-bit path works, and it fixes a real tearing problem. Some suggestions to help it land are at the end.
Hardware: Intel Meteor Lake graphics (ANV, Mesa 26.2.7, Fedora 45,
shaderBufferInt64Atomics = true). I usedvk_compute_testfrommain84347bbb6and this branch at06de9fea0.1. Single thread, exact. This is a temporary variant of
cs_global_mem_ext(one thread) that doesglobal_atomic_swap_x2 … glcandbuffer_atomic_swap_x2 … offen glc, then reads back the old values and the memory.main, this PR without the flag and this PR withLEONIDA_INT64_ATOMICS=1all give the expected0xF 0xF00000 0xAAAA0001 0xBBBB0002 0x12345678 0x9ABCDEF0 0xCCCC0003 0xDDDD0004. With the flag,spirv-disshowsOpAtomicExchange %ulongtwice andOpCapability Int64Atomics, and the module passesspirv-val.2. Contention. Here 40 groups × 64 threads each swap
{x, ~x}(withxunique per thread) into the same 8 bytes usingbuffer_atomic_swap_x2 glc. A returned old pair is counted as torn whenhi != ~lo; the0xEEEEEEEEfill is excluded. Results over 8 runs of 2560 threads each:mainLEONIDA_INT64_ATOMICS=1On RDNA2 these instructions are single 64-bit atomics, so the returned old value never tears. Two 32-bit atomics per element (what
mainemits) tear almost every time under contention. With the flag on, this PR gets that right.The contention fixture (hand-written, no game data). It replaces
cs_global_mem_ext.asmto reuse its FSSM header and run line:vk_compute_test <spv> 40 dumpSuggestions:
--int64-atomicsis off by default, and onlybuild.pyturns it on, throughLEONIDA_INT64_ATOMICS.make_game.pyandscripts/run_gpu_tests.pynever pass it, so no game shader and no CI or GPU-suite run uses the 64-bit path. One option is to turn it on by default: the module already recordsshaderBufferInt64Atomicsin its metadata, so pipeline creation can refuse it on a device without the feature. The other is to havemake_game.pypass it when the device reports the feature.ds_wrxchg_rtn_b64(LDS), but the diff changes onlyglobal_atomic_swap_x2andbuffer_atomic_swap_x2. Retitling it, for example to "rdna2spirv: 64-bit OpAtomicExchange for global/buffer_atomic_swap_x2 (SHADER-868)", would avoid confusion. Note thatds_wrxchg_rtn_b64would needshaderSharedInt64Atomics, which this Intel GPU reports asfalse.docs/design.mdcontract table saying how the rule was confirmed;scripts/run_gpu_tests.py.No game files. AI-assisted (Claude Code).
Not merging yet. This adds an opt-in feature rather than fixing a bug, and
ds_wrxchg_rtn_b64isn't touched. Please:buffer_atomic_{and,or,xor,swap}_x2row indocs/design.md, which currently calls the dword-wise tearing an accepted approximation;runtime/test/shaders, built withLEONIDA_INT64_ATOMICS=1, and say which device and driver ran it;make_game.py; today onlybuild.pyreads it.Tested a48dc6e7 on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere, subgroup 32..32), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300): pass, regression check
Runtime built at this head with
scripts\build_runtime.ps1(MSVC 19.51, VS Build Tools 2026);llvm-mc23.1.6 (conda-forge), SPIRV-Tools 2026.4, Vulkan SDK 1.4.363.0. No game files. This PR adds no GPU fixture, so this checks the translator change on the GPU suite.run_gpu_tests.py: 257 shaders, 257 translated, 257 pass spirv-val; native 197/248 passed, 49 skipped;LEONIDA_W64_EMULATE=1229/248 passed, 17 skipped, the same counts asmainece4ba5b. The only failures,cs_imgload_tfeandcs_imgload_d16_tfe, fail identically onmainece4ba5bon this card (main: native 197/248, emulated 229/248), the same pair as #31 / #336.tests/semantic/test_atomic_swap_x2_int64.py4 OK.Updated per feedback and rebased cleanly onto current
mainas a single commit (8435a8069):--int64-atomicsonbuffer_atomic_swap_x2/global_atomic_swap_x2(ds_wrxchg_rtn_b64untouched).Global atomicsandbuffer_atomic_{and,or,xor,swap}_x2rows indocs/design.md.runtime/test/shaders/cs_atomic_swap_x2_int64.asm(wired intobuild.pyviaLEONIDA_INT64_ATOMICS=1,check.py,run_gpu_tests.py, andtests/semantic/regen_fixtures.py). Note:llvm-mc/spirv-asare not installed locally, so physical GPU execution could not be run on this host; CPU verification viaspirv_mini_interpand all translator/doc/CI tests pass.--int64-atomicsthroughmake_game.py(FALLBACK_FLAGSand CLI parser, tested intest_atomic_swap_x2_int64.pyandtest_docs_cli_flags.py).I ran
8435a8069merged ontomaina28927849on two AMD GPUs, Mesa 26.3.1 RADV on Linux, with the validation layer on. Both reportshaderBufferInt64Atomics = true:The 64-bit path does fix tearing. I used Mouad-Scriptz-0's contention test: 2,560 threads swapping
{x, ~x}into one element withglc, 8 runs.--int64-atomics, buffer / globalNo regressions.
run_gpu_tests.py:main231/249, this PR 232/250 (+ the new fixture) on both GPUs.*_atomic_swap_x2.Still open from Mouad-Scriptz-0's review: the claim in #14,
run_gpu_tests.pypassing the flag, and a multi-thread fixture. The new fixture passes with and without the flag here, because a single thread can't tear.Two more points:
shaderBufferInt64Atomicson its device (runtime/shims/d3d12_vulkan_device.cpp:9565-9593).make_game.py --int64-atomicsoutput would use a feature the device wasn't created with.docs/design.md:289and:497still end with "Not GPU-verified", and the Global atomics row keeps the old unconditional tearing sentence. The docstrings attools/rdna2spirv.py:3011and:3156describe the old behaviour.AI-assisted (Claude Code, Claude Opus 5.5).
@aslan2142 @Mouad-Scriptz-0 Updated in commit
14eaf6052:shaderBufferInt64AtomicsonVkPhysicalDeviceVulkan12Featuresinruntime/shims/d3d12_vulkan_device.cpp, recordedshader_buffer_int64_atomicsinruntime/shims/d3d12_com.h, and asserted it inruntime/test/d3d12_vulkan_device_test.cpp.cs_atomic_swap_x2_int64.asmfixture (and regenerated.sviaregen_fixtures.py) with a 64-thread (2 wave32 waves, 4 rounds = 256buffer_atomic_swap_x2+ 256global_atomic_swap_x2vias_barrierand Device-scope atomics) tearing check (EXPECTED_FIXTURE = [0, 0, 256, 256, 1, 1, 0xDEAD0001, 0x9ABCDEF0]).runtime/test/shaders/build.py,runtime/test/shaders/check.py,scripts/run_gpu_tests.py(int64_atomics()helper + dedicated--int64-atomicspass merging itsindex.jsonentry without clobbering 32-bit defaults),tests/semantic/test_atomic_swap_x2_int64.py,tools/rdna2spirv.pydocstrings, anddocs/design.md.14eaf6052:regen_fixtures.py --checkOK,test_atomic_swap_x2_int64.py(6/6 OK),test_fixtures.py&test_regen_fixtures.pyOK, all 12test_docs_*.pyOK,compileallOK, MSVC/W4compile-check ofd3d12_vulkan_device.cpp&d3d12_vulkan_device_test.cppOK. (llvm-mc, CTest Vulkan run, and RDNA2 hardware are not present on this Windows GTX 1050 host, so CI / hardware GPU run on the updated fixture is pending.)Rebased on current ubi/main (3f81d46ac) and pushed. Conflicts resolved against the newer main changes; test suite for the touched area passes locally (xs_proxy_mock_test PASS on Windows; the int64-atomics semantic tests 6/6 and test_rdna2_decode 21/21 where applicable).
AI-assisted: yes
Hi @kotekompotek, thanks for this pull request. It currently conflicts with
main(conflicting file(s):make_game.py,runtime/test/shaders/build.py,tools/rdna2spirv.py), so it carries theneeds rebaselabel. CONTRIBUTING.md asks authors to rebase their branch onmain; once it merges cleanly the label goes within the hour, and reviews start with the pull requests that do. Could you update the branch when you have a moment? If you no longer plan to continue with it, please say so here.AI-assisted (Claude Code, Claude Opus 5.5).
Closing this PR because the legacy C++ Vulkan runtime (and legacy Python shader compiler) is now considered deprecated in favor of the new Rust Vulkan runtime (in progress) and the Rust DX12 runtime (
d3d12/) available now. Thank you for the contribution! If you believe this PR was closed by mistake (for example, if it still applies to active tools,d3d12/, or general docs), please feel free to reopen it.