Shader: preserve scalar loop exits in native wave32 compute #647

Open
ANDREANIADS wants to merge 1 commit from upstream-pr/647 into a-publier
ANDREANIADS commented 2026-11-27 16:23:07 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ANDREANIADS on 2026-11-27T16:23:07Z.


Related to #352; complements the split-wave64 work in #366.

Native wave32 compute currently lets lanes leave a divergent loop before its scalar result has reached the final wave-wide value. On an RTX 3070 the synthetic 64-thread probe returned 1..64 instead of 32 for the first wave and 64 for the second.

This routes a conservative subset of native wave32 loops through the existing structured wide emitter: 1D compute, no LDS, spills or waterfalls, properly nested EXEC backedges, and scalar results used after the latch. Unsupported control flow, mask-as-data and cross-lane operations are rejected by the detector. The emitted wave width stays 32 even when the host allows 64. Translator cache version increases from 2 to 3.

Validation on Windows / NVIDIA RTX 3070 / driver 621.40 / Rust 1.98.1:

  • Original production code reproduced the incorrect GPU output.
  • Five targeted tests passed: original scalar probe, nested loops, scalar/vector output at 32/64/80/128 threads, vector-only control, and wave-width pinning. Seven GPU dispatches ran with matching output and DXIL validation.
  • A sixth test adds negative detector coverage for barriers, readfirstlane and forward SCC branches.
  • git diff --check passes.
  • Full shader library tests, Clippy and asset-policy checks were started, but the remote computer connection stopped returning results. Their completion is NOT yet confirmed; this PR remains a draft pending that validation.

Credit: the conservative loop detector is adapted from fladit123's #366; the synthetic scalar-loop fixture builds on adrianmjim's 471e11b. This does not claim to fix all of #352. No gameplay or performance claims.

AI-assisted with Codex.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5529851037 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/647). Originally posted by [ANDREANIADS](https://github.com/ANDREANIADS) on 2026-11-27T16:23:07Z. --- Related to #352; complements the split-wave64 work in #366. Native wave32 compute currently lets lanes leave a divergent loop before its scalar result has reached the final wave-wide value. On an RTX 3070 the synthetic 64-thread probe returned 1..64 instead of 32 for the first wave and 64 for the second. This routes a conservative subset of native wave32 loops through the existing structured wide emitter: 1D compute, no LDS, spills or waterfalls, properly nested EXEC backedges, and scalar results used after the latch. Unsupported control flow, mask-as-data and cross-lane operations are rejected by the detector. The emitted wave width stays 32 even when the host allows 64. Translator cache version increases from 2 to 3. Validation on Windows / NVIDIA RTX 3070 / driver 621.40 / Rust 1.98.1: - Original production code reproduced the incorrect GPU output. - Five targeted tests passed: original scalar probe, nested loops, scalar/vector output at 32/64/80/128 threads, vector-only control, and wave-width pinning. Seven GPU dispatches ran with matching output and DXIL validation. - A sixth test adds negative detector coverage for barriers, readfirstlane and forward SCC branches. - git diff --check passes. - Full shader library tests, Clippy and asset-policy checks were started, but the remote computer connection stopped returning results. Their completion is NOT yet confirmed; this PR remains a draft pending that validation. Credit: the conservative loop detector is adapted from fladit123's #366; the synthetic scalar-loop fixture builds on adrianmjim's 471e11b. This does not claim to fix all of #352. No gameplay or performance claims. AI-assisted with Codex.
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/647:upstream-pr/647'
git switch 'upstream-pr/647'

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 'a-publier'
git merge --no-ff 'upstream-pr/647'
git switch 'upstream-pr/647'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'upstream-pr/647'
git switch 'upstream-pr/647'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'upstream-pr/647'
git switch 'a-publier'
git merge --squash 'upstream-pr/647'
git switch 'a-publier'
git merge --ff-only 'upstream-pr/647'
git switch 'a-publier'
git merge 'upstream-pr/647'
git push origin 'a-publier'
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
Belobug/VIctory-Belobug-AMD!647
No description provided.