Preserve LDS atomic ordering between divergent half-waves #204

Open
feanorsun wants to merge 1 commit from upstream-pr/204 into main
feanorsun commented 2026-11-26 11:29:33 +00:00 (Migrated from github.com)

Imported from avatarmanz/VIctory-7900XTX. Originally posted by feanorsun on 2026-11-26T11:29:33Z.


Refs #182

The Wave32 lowering analysis for divergent regions classified every non-read LDS operation as write-only. An atomic minimum followed by an atomic add can therefore get synchronization only at the region boundaries. In a 64-lane wave with 33 active lanes, all lanes first clear one shared word and then increment it. The CPU reference ends at 33. If one half finishes before the other clears the word, the result can be 1 or 32.

Account for the read side of LDS read-modify-write instructions, including operations without a return register. A region containing just one kind of commuting, non-returning integer reduction can still take the existing lowering. The existing flag proof remains available.

The synthetic regression exercises both returning and non-returning adds. On upstream 0dec5dcc228b the original control flow was incorrectly accepted for Wave32. After the change, the public emitter uses the existing EXEC-skip rewrite for the mixed operations and emits Wave32 with the operations in blocks all lanes reach. Two identical non-returning adds still take the direct Wave32 path.

Tested on Windows with a CPU reference and the in-memory shader emitter. The new exact test failed before the fix. It and the existing positive and negative flag-region tests passed afterwards. The three tests were listed individually, then run with cargo test --offline --locked -j 1 -p victory-shader --lib <test> -- --exact --test-threads=1.

The 128- and 1024-thread programs discussed in #37 use LDS atomics. This test addresses an ordering hazard when lowering that class of operation. It does not reproduce the four reported shader binaries, establish why those particular programs were refused, or measure rendering on the RTX 3070. No GPU or driver validation was run locally.

<!-- greyfinch-sync:avatarmanz/VIctory-7900XTX:issue:6625696767 --> Imported from [avatarmanz/VIctory-7900XTX](https://github.com/avatarmanz/VIctory-7900XTX/pull/204). Originally posted by [feanorsun](https://github.com/feanorsun) on 2026-11-26T11:29:33Z. --- Refs #182 The Wave32 lowering analysis for divergent regions classified every non-read LDS operation as write-only. An atomic minimum followed by an atomic add can therefore get synchronization only at the region boundaries. In a 64-lane wave with 33 active lanes, all lanes first clear one shared word and then increment it. The CPU reference ends at 33. If one half finishes before the other clears the word, the result can be 1 or 32. Account for the read side of LDS read-modify-write instructions, including operations without a return register. A region containing just one kind of commuting, non-returning integer reduction can still take the existing lowering. The existing flag proof remains available. The synthetic regression exercises both returning and non-returning adds. On upstream `0dec5dcc228b` the original control flow was incorrectly accepted for Wave32. After the change, the public emitter uses the existing EXEC-skip rewrite for the mixed operations and emits Wave32 with the operations in blocks all lanes reach. Two identical non-returning adds still take the direct Wave32 path. Tested on Windows with a CPU reference and the in-memory shader emitter. The new exact test failed before the fix. It and the existing positive and negative flag-region tests passed afterwards. The three tests were listed individually, then run with `cargo test --offline --locked -j 1 -p victory-shader --lib <test> -- --exact --test-threads=1`. The 128- and 1024-thread programs discussed in #37 use LDS atomics. This test addresses an ordering hazard when lowering that class of operation. It does not reproduce the four reported shader binaries, establish why those particular programs were refused, or measure rendering on the RTX 3070. No GPU or driver validation was run locally.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/204:upstream-pr/204'
git switch 'upstream-pr/204'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/204'
git switch 'upstream-pr/204'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/204'
git switch 'upstream-pr/204'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/204'
git switch 'main'
git merge --squash 'upstream-pr/204'
git switch 'main'
git merge --ff-only 'upstream-pr/204'
git switch 'main'
git merge 'upstream-pr/204'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
avatarmanz/VIctory-7900XTX!204
No description provided.