Preserve divergent-loop scalar results across 32-lane waves #299

Open
loyodea wants to merge 1 commit from upstream-pr/299 into main
loyodea commented 2026-11-26 19:28:40 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by loyodea on 2026-11-26T19:28:40Z.


Related to #259.

On an eligible 32-lane host, scalar values read after a divergent console wave64 loop could come from different final iterations in the two halves. Route eligible single-console-wave compute groups through the existing synchronized split console flow when a divergent loop leaves a scalar value live after exit. If that lowering is refused, propagate the refusal so the translator cannot silently return the incorrect per-half results for the selected cases.

This addresses the two scalar-count cases. #276 and #260 address fixture selection and adapter capability handling.

Validation

  • On Windows with an RX 9060 XT forced to WaveSize(32), the original scalar results differed by half (32 and 64, then 8 and 16). Production translation with this patch returned 64 and 16 respectively in every lane. Both focused fixtures passed independent reruns with DXIL validation.
  • The full victory-shader library suite returned 277 passed and six ignored. With stock lowering restored, both focused regressions failed the explicit wave-size assertion.
  • Four-lane WARP still reproduces all four original failures. Physical NVIDIA validation and in-game behavior are unverified. The fixtures are synthetic.

Codex contributed the implementation, independent review, and verification.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:issue:5516009702 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/299). Originally posted by [loyodea](https://github.com/loyodea) on 2026-11-26T19:28:40Z. --- Related to #259. On an eligible 32-lane host, scalar values read after a divergent console wave64 loop could come from different final iterations in the two halves. Route eligible single-console-wave compute groups through the existing synchronized split console flow when a divergent loop leaves a scalar value live after exit. If that lowering is refused, propagate the refusal so the translator cannot silently return the incorrect per-half results for the selected cases. This addresses the two scalar-count cases. #276 and #260 address fixture selection and adapter capability handling. **Validation** - On Windows with an RX 9060 XT forced to `WaveSize(32)`, the original scalar results differed by half (`32` and `64`, then `8` and `16`). Production translation with this patch returned `64` and `16` respectively in every lane. Both focused fixtures passed independent reruns with DXIL validation. - The full `victory-shader` library suite returned 277 passed and six ignored. With stock lowering restored, both focused regressions failed the explicit wave-size assertion. - Four-lane WARP still reproduces all four original failures. Physical NVIDIA validation and in-game behavior are unverified. The fixtures are synthetic. Codex contributed the implementation, independent review, and verification.
fladit123 commented 2026-11-26 20:33:25 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by fladit123 on 2026-11-26T20:33:25Z.

Review: APPROVED


Independent physical NVIDIA validation of PR #299.

Both targeted regression tests pass on an RTX 4060 8 GB.

Environment:

  • NVIDIA GeForce RTX 4060
  • Driver 610.88
  • Windows 11
  • Intel Core i5-12400F
  • 32 GB RAM
  • Host target: lanes_min: 32, lanes_max: 32

Revisions:

  • Baseline: 4f62c2a5e27e7beebf3e8d68f77898e43dc7b77c
  • Candidate: be1f933e87d3d2f5b6a6afe17db1f296e2d58615
Test Baseline Candidate
scalar_counted_in_a_divergent_loop_read_after_it FAIL: 32/64 PASS: 64 in every lane
scalar_counted_in_nested_divergent_loops FAIL: 8/16 PASS: 16 in every lane

I also performed two negative controls using the candidate's updated fixtures with only lower.rs restored from the baseline.

The first control failed both explicit DXIL wave-size assertions (None instead of Some(32)).

For the second control, I replaced only that assertion with diagnostic output, allowing execution to proceed through GPU dispatch and readback. Both original incorrect scalar results were reproduced.

This isolates the effect of the production lowering change from the updated test fixtures.

All four negative-control executions failed as expected. Both unmodified candidate tests passed.

The physical NVIDIA validation therefore supports this correction for the two tested cases.

Full-suite, gameplay and a-publier compatibility remain unverified.

AI-assisted source review and experimental design using OpenAI ChatGPT. All tests were executed locally on physical NVIDIA hardware.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6080212839 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/299#pullrequestreview-6080212839). Originally posted by [fladit123](https://github.com/fladit123) on 2026-11-26T20:33:25Z. **Review:** APPROVED --- Independent physical NVIDIA validation of PR #299. **Both targeted regression tests pass on an RTX 4060 8 GB.** Environment: - NVIDIA GeForce RTX 4060 - Driver 610.88 - Windows 11 - Intel Core i5-12400F - 32 GB RAM - Host target: `lanes_min: 32, lanes_max: 32` Revisions: - Baseline: `4f62c2a5e27e7beebf3e8d68f77898e43dc7b77c` - Candidate: `be1f933e87d3d2f5b6a6afe17db1f296e2d58615` | Test | Baseline | Candidate | |---|---|---| | scalar_counted_in_a_divergent_loop_read_after_it | FAIL: 32/64 | PASS: 64 in every lane | | scalar_counted_in_nested_divergent_loops | FAIL: 8/16 | PASS: 16 in every lane | I also performed two negative controls using the candidate's updated fixtures with only `lower.rs` restored from the baseline. The first control failed both explicit DXIL wave-size assertions (`None` instead of `Some(32)`). For the second control, I replaced only that assertion with diagnostic output, allowing execution to proceed through GPU dispatch and readback. Both original incorrect scalar results were reproduced. This isolates the effect of the production lowering change from the updated test fixtures. All four negative-control executions failed as expected. Both unmodified candidate tests passed. The physical NVIDIA validation therefore supports this correction for the two tested cases. Full-suite, gameplay and `a-publier` compatibility remain unverified. AI-assisted source review and experimental design using OpenAI ChatGPT. All tests were executed locally on physical NVIDIA hardware.
ANDREANIADS commented 2026-11-26 21:16:08 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by ANDREANIADS on 2026-11-26T21:16:08Z.


Confirmed on an RTX 3070 (621.40): both scalar fixtures at be1f933e returned the expected count in all 64 lanes. I also tested an incremental patch that routes the two remaining mask fixtures through the normal emitter and adds a 5 + 23 bit regression. All five fixtures passed on hardware. The before/after results and build differences are in the #259 report.

The ZIP contains patches/pr299-mask-tests.patch, which applies directly to this PR head, plus the exact test logs.
VIctory-correcao-RTX3070.zip

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:comment:7203557790 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/299#issuecomment-7203557790). Originally posted by [ANDREANIADS](https://github.com/ANDREANIADS) on 2026-11-26T21:16:08Z. --- Confirmed on an RTX 3070 (621.40): both scalar fixtures at `be1f933e` returned the expected count in all 64 lanes. I also tested an incremental patch that routes the two remaining mask fixtures through the normal emitter and adds a 5 + 23 bit regression. All five fixtures passed on hardware. The before/after results and build differences are in [the #259 report](https://github.com/Belobug/VIctory-Belobug-AMD/issues/259#issuecomment-7203531846). The ZIP contains `patches/pr299-mask-tests.patch`, which applies directly to this PR head, plus the exact test logs. [VIctory-correcao-RTX3070.zip](https://github.com/user-attachments/files/35484299/VIctory-correcao-RTX3070.zip)
gut0to commented 2026-11-27 15:02:45 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-27T15:02:45Z.

Code review location: crates/victory-shader/src/emit/lower.rs; line 12291

@@ -12258,6 +12283,43 @@ impl<'a> Lower<'a> {
         }
     }
 
+    /// Does a divergent loop leave scalar data that must be shared by both
+    /// halves of the console wave?
+    fn split_loop_needs_scalars(&self) -> bool {
+        // An address-based dispatch can exit some threads before the first
+        // barrier. Resource waterfall loops are also lane-local.
+        if !matches!(self.s.threads, Some(threads) if threads.iter().product::<u32>() > 32)

AI-assisted static review: the new eligibility boundary is threads > 32, but the existing divergent-loop fixtures use 64 threads. Could the fixture builder cover both 32 and 33 threads? The 33-thread case exercises the first partially populated upper host wave, while the 32-thread control verifies the single-wave boundary.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review-comment:4720916325 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/299#discussion_r4720916325). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-27T15:02:45Z. **Code review location:** `crates/victory-shader/src/emit/lower.rs`; line 12291 ~~~~diff @@ -12258,6 +12283,43 @@ impl<'a> Lower<'a> { } } + /// Does a divergent loop leave scalar data that must be shared by both + /// halves of the console wave? + fn split_loop_needs_scalars(&self) -> bool { + // An address-based dispatch can exit some threads before the first + // barrier. Resource waterfall loops are also lane-local. + if !matches!(self.s.threads, Some(threads) if threads.iter().product::<u32>() > 32) ~~~~ --- AI-assisted static review: the new eligibility boundary is `threads > 32`, but the existing divergent-loop fixtures use 64 threads. Could the fixture builder cover both 32 and 33 threads? The 33-thread case exercises the first partially populated upper host wave, while the 32-thread control verifies the single-wave boundary.
gut0to commented 2026-11-27 15:02:45 +00:00 (Migrated from github.com)

Imported from Belobug/VIctory-Belobug-AMD. Originally posted by gut0to on 2026-11-27T15:02:45Z.

Review: COMMENTED


AI-assisted static review; I traced the new split-wave eligibility check and the existing fixtures. I did not run the test suite.

<!-- greyfinch-sync:Belobug/VIctory-Belobug-AMD:review:6090061383 --> Imported from [Belobug/VIctory-Belobug-AMD](https://github.com/Belobug/VIctory-Belobug-AMD/pull/299#pullrequestreview-6090061383). Originally posted by [gut0to](https://github.com/gut0to) on 2026-11-27T15:02:45Z. **Review:** COMMENTED --- AI-assisted static review; I traced the new split-wave eligibility check and the existing fixtures. I did not run the test suite.
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/299:upstream-pr/299'
git switch 'upstream-pr/299'

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