a-publier: a scalar counted in a divergent loop is read per lane after it (each lane reads its own iteration count) #352
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/Belobug--VIctory-Belobug-AMD#352
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
@adrianmjim on GitHub · 2026-11-26 21:41 UTC · original
On
a-publier(cd8dfc0), a scalar counted inside a loop whose lanes leave at different iterations is read after the loop as each lane's own count, not as the console's. Found while checking whether #110's wave-size rule (which targetsmain) applies to this line. It doesn't apply, because the mechanism it adjusts is not here.What the console does. A scalar register (SGPR) is one value per wave. In a loop where lane
istays fori + 1iterations, ans_addinside the loop runs once per wave iteration while any lane is still in it. So after the loop every lane reads 64 for a wave64 group of 64 threads.mainlowers this withleave_loops/find_loop_exitsinemit/lower.rs. Those come frommain's first commit and are not on this line. #110 then makes such a program ask for the console's wave size.What
a-publiergives. The three tests frommain(two from #110, one from its follow-upc20a5d0), ported to this line's test harness with the same shader words, all fail on an RX 7900 XT (Windows 11 26300). They run on the hardware adapter:scalar_counted_in_a_divergent_loop_read_after_it(wave64, 64 threads)ireadsi + 1(1, 2, …, 64)scalar_counted_in_nested_divergent_loopsscalar_counted_in_a_wave32_divergent_loop_read_after_it(wave32, 64 threads)ireadsi + 1Each lane gets its own value, so this is not a wrong wave size. The emitted programs also declare no
WaveSize(PSV0 range(0, u32::MAX)). The scalar is lowered per lane, and its join after the loop doesn't take the wave's value. The rest ofvictory-shader --libpasses on this line (302 passed, 4 ignored, besides these three).Reproduction: branch https://github.com/adrianmjim/VIctory-Belobug-AMD/tree/publier/divergent-loop-probes (
471e11b, one commit oncd8dfc0, tests only, inemit/valu_tests.rs):Not known: how many of the title's programs have this pattern, and what it does in the game. Fixing it here would mean porting
main's loop-exit handling first, and then #110 andc20a5d0on top. #204 targetsmainand doesn't change the per-lane count.@ANDREANIADS on GitHub · 2026-11-26 21:49 UTC · original
I reproduced all three fixtures on a physical GeForce RTX 3070, NVIDIA driver 621.40, Windows build 26300. I used your test commit
471e11b, based ona-publier@cd8dfc0, selected the adapter withVICTORY_D3D12_ADAPTER=RTX 3070, and ran withVICTORY_WARP=0and one test thread. All three shaders created pipelines, executed and returned all 64 words.i + 1i + 1(1 + i % 4) * (1 + (i >> 4))All three emitted a PSV0 range of
(0, 4294967295). The compiler in these fixtures lowers before selecting the device, with the default unknown host width. The results match your RX 7900 XT observations on another vendor. Release build, Rust 1.98.0 MSVC and offline dependency versions. No game assets or in-game inference. Tested with Codex.@adrianmjim on GitHub · 2026-11-26 21:50 UTC · original
Thanks @ANDREANIADS. The same per-lane values on an NVIDIA card (32-lane waves only) as on the RX 7900 XT (which runs these as wave64) rule out the driver and the host's wave size: it is the translation on this line, the scalar lowered per lane with no wave-level join after the loop.
@fladit123 on GitHub · 2026-11-26 22:04 UTC · original
I independently reproduced the two Wave64 scalar-count regressions on
a-publier@cd8dfc06using a physical NVIDIA RTX 4060 (driver 610.88).The incorrect per-lane results were identical with the default configuration,
VICTORY_WAVE_LOCAL=0, andVICTORY_WAVE_LOCAL=idiom.I now have a local experimental correction targeting eligible single-console-wave compute groups. It makes divergent loop branches vote across both Wave32 halves while preserving per-lane EXEC guards for vector operations.
Current results:
The separate native Wave32 scalar-count failure remains outside the current patch's scope.
I am reviewing the synchronization and control-flow implications before submitting a PR targeting
a-publier.Thanks to the contributors of #110, #299 and #352 for the prior investigation and regression fixtures.
No physical AMD validation or gameplay performance claims are being made.
AI-assisted investigation, implementation and testing using OpenAI ChatGPT and Codex.
@adrianmjim on GitHub · 2026-11-26 22:04 UTC · original
Thanks @fladit123, good to have it on a third card. When you open the PR against
a-publier, I can run it on the RX 7900 XT. That's the AMD side you haven't covered: an RDNA3 host that runs these console programs as wave64 natively, where the wave32 test (scalar_counted_in_a_wave32_divergent_loop_read_after_it, lanes 0–31 should read 32 and lanes 32–63 64) also gives each lane its own count today. I'd run the three fixtures from471e11bplusvictory-shader --lib, before and after.@fladit123 on GitHub · 2026-11-26 22:06 UTC · original
Thanks, @adrianmjim! Independent RDNA3 validation would be very helpful.
The current implementation is intentionally restricted to single-console-wave compute groups on hosts with a maximum wave size of 32. It does not yet address the native Wave32 scalar regression or native Wave64 execution.
I am finishing the portability and synchronization review before opening the PR against
a-publier. I will include the reproduction instructions and limitations so that the AMD results can be compared accurately.@fladit123 on GitHub · 2026-11-26 22:25 UTC · original
@adrianmjim The draft PR is now available: #366.
The final revision is
ac445ea90803500b610c801df236d98f5bff47eb.The portability changes are complete, and the RTX 4060 passed 12 GPU tests and 3 CPU-only controls.
The targeted tests can be run with:
The fixtures perform CPU emission checks for the Wave32-only path independently of hardware availability and report explicit GPU capability skips.
As discussed, the correction does not target native Wave64 execution or the separate native Wave32 scalar regression. Your RX 7900 XT comparison would be valuable for checking that the existing AMD execution paths remain unaffected.
Thank you for offering independent validation!