Repository navigation
Shaders: lower remaining 32-bit integer and bitwise LDS atomics - #1606
Open
HumanlyDev wants to merge 1 commit into
Open
HumanlyDev wants to merge 1 commit into
HumanlyDev wants to merge 1 commit into
Conversation
Decode both data operands of ds_wrap_rtn_b32 in gfx10::fields, expose
the cmpxchg success bit in emit::bitcode, and lower ds_rsub{_rtn}_u32,
ds_inc{_rtn}_u32, ds_dec{_rtn}_u32, ds_mskor{_rtn}_b32, ds_wrap_rtn_b32,
and ds_wrxchg2{,st64}_rtn_b32 in Lower::ds.
DenRakEiw
approved these changes
Nov 24, 2026
DenRakEiw
left a comment
There was a problem hiding this comment.
Verified locally merged onto origin/main (Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):
cargo test -p victory-shader --lib emit::ds_tests::— 3 passed, 0 failed on both RTX 5090 hardware andVICTORY_D3D12_WARP=1cargo clippy -p victory-shader --all-targets— 0 warningscargo xtask policy— ok
Clean lowering of the remaining 32-bit integer and bitwise LDS atomics with cmpxchg_pair support and thorough end-to-end GPU+WARP test coverage in ds_tests.rs. Looks good.
AI-assisted (Gemini 4 Neon).
Owner
|
Automated triage for the maintainers. Needs rebase. This pull request conflicts with Generated by Claude Code |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Lowers the remaining GFX10 32-bit integer and bitwise LDS atomic instructions in
Lower::ds:ds_rsub_u32(0x002) /ds_rsub_rtn_u32(0x022): atomicmem = data0 - mem.ds_inc_u32(0x003) /ds_inc_rtn_u32(0x023): atomicmem = (mem >= data0) ? 0 : mem + 1(unsigned comparison).ds_dec_u32(0x004) /ds_dec_rtn_u32(0x024): atomicmem = (mem == 0 || mem > data0) ? data0 : mem - 1(unsigned comparison).ds_mskor_b32(0x00c) /ds_mskor_rtn_b32(0x02c): atomicmem = (mem & ~data0) | data1.ds_wrap_rtn_b32(0x034): atomicmem = (mem >= data0) ? mem - data0 : mem + data1(unsigned comparison), along with decoding its second data operand (DATA1) ingfx10::fields.ds_wrxchg2_rtn_b32(0x02e) /ds_wrxchg2st64_rtn_b32(0x02f): paired atomicRmw::Xchgat(offset0, offset1)scaled by 4 or 256 bytes, returning both prior values intovdst[0..2]and preserving inactive lanes' registers underguard.emit::bitcode::Module::cmpxchg_pairexposes both fields of{i32, i1}from LLVM 3.7cmpxchgso the single-block CAS loop branches directly on thei1success bit (CondBr(ok, exit, head)), avoiding ABA/no-op ambiguity whennew == expectedand keeping the exiting block as the loop latch.Verification
Added
emit::ds_testsand SP3 disassembly coverage ingfx10::sp3::tests:ds_rsub_inc_dec_mskor_wrap_and_wrxchg2_match_rdna2: validates every emitted DXIL container and container hash withdxil.dll, then executes all 11 opcodes (both_rtnand non-_rtnforms) on both the hardware SM 6.6 D3D12 adapter and WARP across boundary, wraparound, unsigned high-bit (0x8000_0000vs0x7FFF_FFFF), unmaskedDATA1bits inds_mskor, and stride-64 paired exchange cases.ds_atomics_handle_wave_contention_and_divergent_exec_guards: dispatches 64 threads contending on the same LDS dword (ds_inc_rtn_u32) and executesds_dec_rtn_u32+ds_wrxchg2_rtn_b32under a narrowedv_cmpxEXECguard, verifying exact histogram/wrap counts and confirming disabled lanes neither touch LDS nor overwrite destination VGPRs.ds_cas_loops_nest_inside_shader_loops: runs back-to-back CAS-loop atomics (ds_wrap_rtn_b32andds_mskor_rtn_b32) inside a multi-iteration guest shader loop.Local checks (Windows 11,
rustc 1.98.1):cargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test --workspace --locked: all tests pass (victory-shader: 123 passed, 0 failed;xtaskasset policy: 155 files ok)RUSTDOCFLAGS="-D warnings" cargo doc --no-deps -p victory-shader --locked: cleanAll test inputs and machine-code sequences are synthetic; no game files were used.
AI-assisted implementation and verification (Antigravity).