Shaders: LDS byte and half writes as one bounded compare-exchange, not AND then OR #913
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!913
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-913"
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?
@SpaghettiMaster545 on GitHub · 2026-11-25 12:34 UTC · original
SpaghettiMaster545:pr/lds-byte-cas→main· +92 −7 · 2 files · 3 commits · openWhat was wrong
ds_write_b8/ds_write_b16and their_d16_hiforms wrote their part of an LDS dword in two atomics: an AND that cleared the part, then an OR that set it. Lanes writing the same byte in one instruction ORed their values together (a value no lane wrote), and a lane reading the dword between the two atomics saw the part cleared.How it shows
Programs that pack bytes or halves of neighbouring lanes into shared dwords read back mixed bits, so whatever they build from them (masks, counters, packed indices) comes out wrong on the host GPU.
What the change does
The part now replaces its bits in one compare-exchange, retried while another lane changes the dword in between, bounded at 65536 tries so a fault cannot spin the GPU. Lanes writing other parts of the dword all land, and one value of the lanes writing the same part stays, as on the console.
How it was tested
cargo test --locked -p victory-shader --libpasses on this branch (215 passed, 3 ignored);cargo clippy -p victory-shader --all-targets --locked -- -D warningsis clean. (A workspace-wide clippy fails onmainalready, invictory-gpu, which this change does not touch.)_d16_hiwrites, masked byte writes that keep the other bytes, and every byte/half read form are exact with this change. Their harness is not in this fork, so they are not part of this PR.Developed with AI assistance (Claude Code).
@avt0m4t48 on GitHub · 2026-11-25 12:51 UTC · original
Independent Windows Server 2025 WARP check at
5cf45f7. I added a source-built 64-thread regression covering the byte and half writes and both_d16_hiforms. For each opcode, overlapping lanes must leave one of the two supplied values, and lanes writing adjacent fields must preserve both values and the other bits.All eight cases passed with the PR. With just the production change removed, the first overlapping-byte case returned 3 from lanes supplying 1 or 2. The job sets
VICTORY_WARP=1, so the first backend label in the negative-control log also refers to WARP.The test-only commit is available to cherry-pick. Windows run
AI-assisted. Synthetic shader and inputs only.
@eazyves on GitHub · 2026-11-25 13:07 UTC · original
Run on real RDNA4 hardware: RX 9070 XT, driver 32.0.32029.2010, Windows 11 26200, Rust 1.98.1, with avt0m4t48's test (
51a20b5) on this PR's head5cf45f7.ds_subword_writes_preserve_neighboring_bits_and_one_lanes_valuepasses, 4 of 4 runs.lower.rsput back to the merge basea253706: fails on its first case, with the test's ownhardwarelabel: op0x1e, got0xa5c3035a, so the byte is 3 from lanes that wrote 1 or 2.So the merged value is not a WARP effect; the card shows it too, and this change removes it. One run takes about 50 s in a debug build.
A small thing in the diff:
lds_mergesits betweenbegin_guardedand that function's doc comment, so "Starts code only the lanes whereguardholds run ..." now documentslds_merge.AI-assisted (Claude Code); run on my machine, synthetic shader only, no game data.
@SpaghettiMaster545 on GitHub · 2026-11-25 15:34 UTC · original
Thanks to both of you. I took the test commit as it is (
51a20b5).ds_subword_writes_preserve_neighboring_bits_and_one_lanes_valuepasses here on the RTX 5070 Ti (NVIDIA 621.40, Windows 11). I also movedbegin_guarded's doc comment back ontobegin_guarded(847ad17).cargo clippy -p victory-shader --all-targets --locked -- -D warningsis clean.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.