Shaders: lower 32-bit and 64-bit integer global atomics (cmpswap, csub, inc, dec, _x2) #1915
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1915
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1915"
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?
@ESAT586 on GitHub · 2026-11-25 00:51 UTC · original
ESAT586:shader/global-atomics-and-x2→main· +953 −71 · 2 files · 1 commits · openSummary
Completes
Lower::flat_writeincrates/victory-shader/src/emit/lower.rsfor the remaining 32-bit and 64-bit integer/f32 RDNA 2global_atomic_*instructions (20 newly lowered or upgraded opcodes), across both title-memory (self.memory) and direct root-UAV global accesses.What changed
global_atomic_cmpswap(0x31): lowers directly todx.op.atomicCompareExchange.i32(op 79) with RDNA 2(new, compare)vdataorder (vdata[0],vdata[1]).global_atomic_csub(0x34): unsigned clamping subtract CAS loop(old >= val) ? old - val : 0.global_atomic_inc(0x3c) andglobal_atomic_dec(0x3d): unsigned wrapping CAS loops ((old >= val) ? 0 : old + 1and(old == 0 || old > val) ? val : old - 1).global_atomic_fcmpswap(0x3e): IEEE-754 ordered equality (pred::OEQ) CAS loop with RDNA 2 FTZ (-0.0 == +0.0,NaN != NaN); exits without modifying memory on mismatch.global_atomic_fmin(0x3f) andglobal_atomic_fmax(0x40): replaces the previous!glc-only two-atomic integer workaround with a single linearizable CAS loop usingftz+max_min_flushed, enablingglc = 1return values and exact RDNA 2 IEEE-754 NaN (non-NaNwins) and-0.0 < +0.0semantics._x2global atomics (flags::INT64 | flags::ATOMIC64_HEAP, without falsely settingATOMIC64_TYPED):global_atomic_{swap,add,sub,smin,umin,smax,umax,and,or,xor}_x2(0x50,0x52..=0x5b) viadx.op.atomicBinOp.i64(op 78).global_atomic_cmpswap_x2(0x51) viadx.op.atomicCompareExchange.i64(op 79) with 4-VGPRvdata([new_lo, new_hi, cmp_lo, cmp_hi]).global_atomic_{inc,dec}_x2(0x5c,0x5d) via 64-bitatomicCompareExchange.i64CAS loops.oldvalue via an atomiccmpxchg(0, 0)read, which is coherent under contention and returns0on null/OOB views so unmapped title-memory pages exit cleanly on iteration 1.data_dwords(1,2, or4) fromaccess_bytes(4or8) when marking written title-memory pages dirty, socmpswap(4 B) andcmpswap_x2(8 B) do not over-mark adjacent 64 KiB pages.Fields::Flatstores/atomics inwrites_uavssos_barrieremits the UAV memory fence bit in shaders performing global writes/atomics.global_atomic_{fcmpswap,fmin,fmax}_x2until DXILdoubleis modelled.Tests added (
crates/victory-shader/src/emit/memory_tests.rs)global_atomics_32bit_cmpswap_csub_inc_dec_and_float_match_rdna2: 28 deterministic 32-bit cases (glc = 1memory + return checks forcmpswap,csub,inc,dec,fcmpswap,fmin,fmaxincluding unsigned high bit,u32::MAX, zero limits,-0.0/+0.0,NaN, subnormal FTZ) + unmapped title-memory CAS termination check.global_atomics_cas_loop_handles_contention_and_exec_mask: 32-lane wave with divergentEXEC(16 active lanes contending on the same global address viaglobal_atomic_inc glc, 16 disabled lanes verifying VGPR preservation).global_atomics_64bit_x2_match_rdna2: all 13_x2integer global atomics across 19 cases (carry/borrow across bit 31/32, signed vs unsigned min/max, 64-bitcmpswaphigh-dword mismatch,u64::MAX/zero wrap limits,glc = 0path), plus non-title-memory root-UAVglobal_atomic_add_x2andSFI0feature bit assertions.global_atomic_refuses_unsupported_f64_forms: verifiesfcmpswap_x2/fmin_x2/fmax_x2returnShaderError::Unsupported.Verification
Tested on Windows 11, NVIDIA GeForce RTX 3060 Ti (SM 6.6,
OPTIONS1164-bit heap atomics), Microsoft D3D12 WARP (SM 6.6,OPTIONS1164-bit heap atomics), and Windows SDKdxil.dllvalidator:cargo test -p victory-shader --lib memory_tests -- --test-threads=1 --nocapture: 6/6 passed (RTX 3060 Ti + WARP +dxil.dll; 64-bit_x2atomics verified on both adapters)VICTORY_WARP=1 cargo test -p victory-shader --lib -- --test-threads=1: 245/247 passed (the 2 failures are pre-existing upstreammaintests unrelated to this PR:gathers_at_a_level_match_the_hardwareandpermutes_read_the_lane_named_and_zero_from_lanes_left_out)cargo clippy --workspace --all-targets -- -D warnings: 0 warningscargo clippy --workspace --all-targets --all-features -- -D warnings: 0 warningscargo xtask policy:182 files okAI & Clean-Room Disclosure
Authored with AI assistance (Gemini 4 Neon — Extra High Mode). Clean-room implementation derived solely from public AMD RDNA 2 ISA and DXIL specifications and synthetic tests; no copyrighted game binaries, dumps, or assets were used.
@Headache3318 on GitHub · 2026-11-25 02:07 UTC · original
Tested on Linux (Arch, kernel 7.3.5, 3× RTX 4090 driver 620.73.04), Rust 1.98.1 (pinned). PR head
fd1adb3applied cleanly onto currentmainccfb029.cargo test -p victory-shader --locked: 142 passed, 0 failed, 2 ignored. All tests pass. The new global atomic tests are GPU-specific (require dxil.dll/WARP) and are skipped on Linux.cargo clippy -p victory-shader --all-targets -- -D warnings: 4 pre-existing errors in test code (fail identically on mainccfb029). The PR introduces no new clippy warnings.Not tested: Windows MSVC build, the title itself. AI-assisted.
@Marvisak on GitHub · 2026-11-25 02:17 UTC · original · edited 2026-11-25 22:22 UTC
Automated triage for the maintainers.
Needs rebase. This PR no longer merges cleanly into
main:mainhas moved since the last triage, and the branch now conflicts incrates/victory-shader/src/emit/lower.rsandcrates/victory-shader/src/emit/memory_tests.rs. It will be reviewed again once it is rebased onto currentmain.Previous verdict for this head: merge candidate.
Generated by Claude Code
@ESAT586 on GitHub · 2026-11-25 11:05 UTC · original
Rebased onto \main\ (\
940d32f) at \cb6cfb6\ (preserving \mark_view_write(h, off, access_bytes, None)\ from \cd94d35\ for view-backed 32/64-bit global atomics). Verified on RTX 3060 Ti + WARP: \emit::memory_tests\ 7/7 passed (64-bit atomics ran on 2 adapters), strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.@ESAT586 on GitHub · 2026-11-25 11:34 UTC · original
Scoped to integer global atomics + the \writes_uavs\ \Fields::Flat\ fence fix at $sha: removed the float CAS-loop changes so \main's existing two-pass \global_atomic_fmin/\max\ (!glc) behaviour is preserved untouched and \cmpswap\ stays refused until hardware-evidenced in a separate PR. Re-verified on RTX 3060 Ti + WARP: \emit::memory_tests\ 7/7 passed (64-bit atomics ran on 2 adapters), strict Clippy (--all-targets\ and --all-features) clean, \cargo xtask policy\ ok.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.