Shaders: lower buffer_atomic_{sub,csub,inc,dec,fcmpswap,fmin,fmax} #1342
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!1342
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1342"
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?
@AscilCH on GitHub · 2026-11-24 17:33 UTC · original
AscilCH:fix/buffer-atomic-sub-inc-dec→main· +278 −23 · 2 files · 1 commits · openGap
Lower::buffer()incrates/victory-shader/src/emit/lower.rswas missing lowering for seven 32-bit MUBUF atomic instructions, failing shader translation with:Missing ops:
buffer_atomic_sub(0x33),buffer_atomic_csub(0x34),buffer_atomic_inc(0x3c),buffer_atomic_dec(0x3d),buffer_atomic_fcmpswap(0x3e),buffer_atomic_fmin(0x3f), andbuffer_atomic_fmax(0x40).Fix
Added a
BufferAtomiclowering dispatch inLower::buffer():buffer_atomic_sub(0x33): negatesvals[0](0 - val) and emitsatomicBinOp.i32(Add)(matchingimage_atomic_sub).buffer_atomic_csub(0x34): structuredatomicCompareExchange.i32CAS loop computing(old >= val) ? old - val : 0.buffer_atomic_inc(0x3c) andbuffer_atomic_dec(0x3d): structured CAS loops with RDNA2 unsigned wrap semantics ((old >= val) ? 0 : old + 1and(old == 0 || old > val) ? val : old - 1).buffer_atomic_fmin(0x3f) andbuffer_atomic_fmax(0x40): structured CAS loops using RDNA2self.max_min(-0.0 < +0.0, non-NaN wins).buffer_atomic_fcmpswap(0x3e): structured CAS loop comparing with IEEE ordered equality (pred::OEQ, so+0.0 == -0.0andNaN != NaN) and exiting without writing on mismatch.Added hardware + WARP +
dxil.dlltestemit::valu_tests::buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2verifying both updated buffer memory and returned pre-op values (glc = 1) for all seven instructions across normal, clamp, wrap,-0.0/+0.0, andNaNcases.Verification
Tested on Windows 11, NVIDIA RTX 3050 6GB Laptop GPU, WARP, and Windows SDK
dxil.dll:rustfmt --edition 2024 --checkonvalu_tests.rs: cleancargo xtask policy:154 files okcargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test -p victory-shader --locked -- buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2 --nocapture --test-threads=1: passed (hardware + WARP +dxil.dll)VICTORY_WARP=1 cargo test -p victory-shader --locked -- --test-threads=1:121 passed, 0 failed, 1 ignored@ghost on GitHub · 2026-11-24 18:01 UTC · original
Ran on RDNA2 hardware through vkd3d-proton on a Steam Deck (not native Windows): AMD Van Gogh, RADV 26.1.99, SteamOS 3.8.28, Proton 11.0-3 (wine-11.0) with its vkd3d-proton 212991fc. Windows MSVC test binary (rustc 1.100.0) built from head
8448e91on mainffe310e.buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2passes: buffer_atomic_sub, csub, inc, dec, fcmpswap (-0 == +0, NaN != NaN), fmin and fmax, checking both the new memory value and the returned old value.stub_pipeline_is_created, fails on main too (likely vkd3d-proton accepting the zero DXIL digest the test expects refused; environment, not this PR).Not tested: native Windows AMD drivers; WARP (this setup has none, so the WARP leg ran on RADV too); whether the test fails without the fix on this host.
AI-assisted (Claude Code, Claude Opus 5.5); no game data.
@marquezinii on GitHub · 2026-11-24 18:10 UTC · original
Ran natively on Windows (not through vkd3d) on an RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1 at
8448e91.cargo test -p victory-shader --lib -- --test-threads=1gives 121 passed, 0 failed, 1 ignored.buffer_atomics_sub_csub_inc_dec_and_float_match_rdna2passes on the hardware adapter and WARP. Together with nullmarsh's Steam Deck run, that covers RADV and a native NVIDIA driver.I checked the compare-exchange loop bodies against the RDNA2 definitions:
csub:cur >= data ? cur - data : 0inc:cur >= data ? 0 : cur + 1dec:cur == 0 || cur > data ? data : cur - 1All three match.
@shortselow-byte on GitHub · 2026-11-24 19:06 UTC · original
For triage: #164 (older, open, already reviewed) lowers the same seven buffer atomics in its
buffer_atomic_path:sub,csub,inc,dec,fcmpswap,fminandfmax.git merge-treeagainst the current heads (8448e91here,825dbd9there) shows the two conflict inemit/lower.rs, so they need reconciling rather than both landing.For the record, this PR on its own also passes on a native AMD driver: isolated target directory, Windows 11, Rust 1.98.1 MSVC, RX 6900 XT, workspace 343 passed, 0 failed, both clippy runs clean.
@Marvisak on GitHub · 2026-11-25 01:23 UTC · original
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-shader/src/emit/valu_tests.rs). It will be reviewed once it is rebased onto the currentmain.Generated by Claude Code
@sinan-cmyk on GitHub · 2026-11-25 01:48 UTC · original
Offline measurement on a retail dump, and the shader tests on Ada
Result: no count change against
main.Offline. I merged head
8448e91ontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram by program (25,889 programs). Validated: 21,724 onmain, 21,724 with this PR.No program changes its failure reason either. That is the expected result for a fix whose instructions sit behind the earlier failures on
main. The count shows that the change rejects nothing. It does not show whether the output is right.Tests: with the same merge,
cargo test --locked -p victory-shader --libpassed 121, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
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.