Preserve divergent-loop scalar results across Wave32 halves on a-publier #366

Open
github-bot wants to merge 1 commit from github-bot/gh-366 into a-publier AGit
Owner

@⁠fladit123 on GitHub · 2026-11-26 22:24 UTC · original
fladit123:fix/wave64-divergent-loop-scalars → a-publier · +573 −0 · 3 files · 1 commits · draft

Problem

Related to #352.

On a-publier@cd8dfc06, divergent EXEC-controlled loops can lose wave-level scalar semantics when lowered into independent per-lane control flow.

The two synthetic regressions adapted from #299 returned individual lane iteration counts rather than the console wave's final scalar values.

Implementation

Reuse the existing wave-wide branch lowering for eligible compute groups containing one complete console Wave64 on a Wave32-only host.

The correction:

  • Identifies eligible divergent loop nests with escaping scalar values.
  • Keeps their loop latches synchronized across both host waves.
  • Preserves per-lane EXEC guards for vector operations.
  • Excludes unsupported control-flow shapes and multiple-console-wave groups.
  • Rejects the selected synchronized path when VICTORY_GROUP_SYNC=0.

Physical NVIDIA validation

Environment: RTX 4060 8 GB, driver 610.88, Windows 11, Rust 1.98.1.

Regression Baseline Candidate
Simple divergent scalar loop 1–64 64 in every lane
Nested divergent scalar loops Per-lane iteration products 16 in every lane
Consecutive loops with phi dependency and two escaping scalars — 95 in every lane

Final focused validation: 12 GPU tests and 3 CPU-only controls passed.

The fixtures perform CPU emission checks independently of hardware availability, select GPU execution according to actual D3D12 capabilities, and report capability skips explicitly.

Pipeline creation, dispatch and readback failures remain test failures on eligible hardware.

Additional validation

The earlier bounded library comparison reported:

  • Baseline: 300 passed, 0 failed, 4 ignored.
  • Candidate: 308 passed, 0 failed, 4 ignored.
  • Identical capability-skip diagnostics.
  • Two dispatch-heavy tests excluded from both runs.
  • Both original baseline regression failures reproduced separately.

This comparison predates the final fixture-only portability improvements. Production code remained byte-for-byte unchanged.

PR #345 passed a static patch applicability check against the final worktree. Combined runtime behavior has not been tested.

Scope and limitations

This is a deliberately narrow correctness fix for eligible single-console-wave compute groups on hosts with a maximum wave size of 32.

Native Wave64 execution, the separate native Wave32 scalar regression in #352, and more general control-flow forms remain outside scope.

Physical AMD validation and gameplay performance are unverified.

Independent testing and review are welcome.

Attribution

  • loyodea — #299 and the original synthetic regression fixtures.
  • alexdeliu, MamaLeVrai and adrianmjim — investigation of scalar semantics and wave-size dependence.
  • God489 — related synchronized split-wave control-flow work in #68 and #128.
  • TheHoracio — related loop-exit scalar recovery in Marvisak/VIctory#269.
  • ANDREANIADS — independent NVIDIA reproduction in #352.

AI disclosure: OpenAI ChatGPT assisted with source review, experimental design and independent patch review. OpenAI Codex assisted with implementation and local validation. All GPU results were obtained on physical hardware using synthetic fixtures.

**@⁠fladit123** on GitHub · 2026-11-26 22:24 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366) `fladit123:fix/wave64-divergent-loop-scalars` → `a-publier` · +573 −0 · 3 files · 1 commits · draft ## Problem Related to #352. On `a-publier@cd8dfc06`, divergent EXEC-controlled loops can lose wave-level scalar semantics when lowered into independent per-lane control flow. The two synthetic regressions adapted from #299 returned individual lane iteration counts rather than the console wave's final scalar values. ## Implementation Reuse the existing wave-wide branch lowering for eligible compute groups containing one complete console Wave64 on a Wave32-only host. The correction: - Identifies eligible divergent loop nests with escaping scalar values. - Keeps their loop latches synchronized across both host waves. - Preserves per-lane EXEC guards for vector operations. - Excludes unsupported control-flow shapes and multiple-console-wave groups. - Rejects the selected synchronized path when `VICTORY_GROUP_SYNC=0`. ## Physical NVIDIA validation Environment: RTX 4060 8 GB, driver 610.88, Windows 11, Rust 1.98.1. | Regression | Baseline | Candidate | |---|---|---| | Simple divergent scalar loop | 1–64 | 64 in every lane | | Nested divergent scalar loops | Per-lane iteration products | 16 in every lane | | Consecutive loops with phi dependency and two escaping scalars | — | 95 in every lane | Final focused validation: **12 GPU tests and 3 CPU-only controls passed.** The fixtures perform CPU emission checks independently of hardware availability, select GPU execution according to actual D3D12 capabilities, and report capability skips explicitly. Pipeline creation, dispatch and readback failures remain test failures on eligible hardware. ## Additional validation The earlier bounded library comparison reported: - Baseline: 300 passed, 0 failed, 4 ignored. - Candidate: 308 passed, 0 failed, 4 ignored. - Identical capability-skip diagnostics. - Two dispatch-heavy tests excluded from both runs. - Both original baseline regression failures reproduced separately. This comparison predates the final fixture-only portability improvements. Production code remained byte-for-byte unchanged. PR #345 passed a static patch applicability check against the final worktree. Combined runtime behavior has not been tested. ## Scope and limitations This is a deliberately narrow correctness fix for eligible single-console-wave compute groups on hosts with a maximum wave size of 32. Native Wave64 execution, the separate native Wave32 scalar regression in #352, and more general control-flow forms remain outside scope. Physical AMD validation and gameplay performance are unverified. Independent testing and review are welcome. ## Attribution - loyodea — #299 and the original synthetic regression fixtures. - alexdeliu, MamaLeVrai and adrianmjim — investigation of scalar semantics and wave-size dependence. - God489 — related synchronized split-wave control-flow work in #68 and #128. - TheHoracio — related loop-exit scalar recovery in Marvisak/VIctory#269. - ANDREANIADS — independent NVIDIA reproduction in #352. AI disclosure: OpenAI ChatGPT assisted with source review, experimental design and independent patch review. OpenAI Codex assisted with implementation and local validation. All GPU results were obtained on physical hardware using synthetic fixtures.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 00:58:34 +00:00
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 22:56 UTC · original

Ran on an RX 6950 XT (RDNA 2, max wave 64, driver 32.0.21045.29003), Windows 11 build 26300, Rust 1.98.1, release, at ac445ea:

  • pr299_ and scalar_loop_control_: 11 passed. On this card, though, the GPU part of the two pr299_ fixtures reports GPU SKIP: the synchronized route requires a physical adapter with max wave 32. Only their CPU part (production emission and DXIL validation for max wave 32) ran here, so nothing here exercises the new route on a card.
  • With #352's probe commit 471e11b merged on top: the three scalar_counted_* tests still fail on this card, each lane reading its own count. scalar_counted_in_a_divergent_loop_read_after_it reads [1, 2, ..., 64] where the console gives 64 everywhere. That is expected, since the PR is limited to max-wave-32 hosts, but it confirms that RDNA hosts (which run these programs as wave64) keep the per-lane count.

So for RDNA 2/3 the 64-lane route is still open. I can run a version of it on this card when there is one.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-26 22:56 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7205110211) Ran on an RX 6950 XT (RDNA 2, max wave 64, driver 32.0.21045.29003), Windows 11 build 26300, Rust 1.98.1, release, at `ac445ea`: - `pr299_` and `scalar_loop_control_`: 11 passed. On this card, though, the GPU part of the two `pr299_` fixtures reports `GPU SKIP: the synchronized route requires a physical adapter with max wave 32`. Only their CPU part (production emission and DXIL validation for max wave 32) ran here, so nothing here exercises the new route on a card. - With #352's probe commit `471e11b` merged on top: the three `scalar_counted_*` tests still fail on this card, each lane reading its own count. `scalar_counted_in_a_divergent_loop_read_after_it` reads `[1, 2, ..., 64]` where the console gives 64 everywhere. That is expected, since the PR is limited to max-wave-32 hosts, but it confirms that RDNA hosts (which run these programs as wave64) keep the per-lane count. So for RDNA 2/3 the 64-lane route is still open. I can run a version of it on this card when there is one. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠fladit123 on GitHub · 2026-11-26 22:57 UTC · original

Thanks, @⁠MamaLeVrai! These results are consistent with the intended scope of #366.

I have also been investigating the native-wave path independently on a-publier@4eb6cfdf.

On the physical RTX 4060, the experimental native Wave32 correction now passes both the simple and nested scalar-loop regressions using the existing wave-wide branch mechanism.

The bounded library comparison reported 303 passes and two expected failures on the baseline, versus 305 passes and zero failures on the candidate, with identical filters and capability skips.

I am investigating whether the same native-wave mechanism can safely cover RDNA hosts without introducing cross-wave LDS synchronization.

Your offer to validate the native Wave64 path on RDNA2 would be very helpful. No AMD correctness claim is being made yet.

**@⁠fladit123** on GitHub · 2026-11-26 22:57 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7205129762) Thanks, @⁠MamaLeVrai! These results are consistent with the intended scope of #366. I have also been investigating the native-wave path independently on `a-publier@4eb6cfdf`. On the physical RTX 4060, the experimental native Wave32 correction now passes both the simple and nested scalar-loop regressions using the existing wave-wide branch mechanism. The bounded library comparison reported 303 passes and two expected failures on the baseline, versus 305 passes and zero failures on the candidate, with identical filters and capability skips. I am investigating whether the same native-wave mechanism can safely cover RDNA hosts without introducing cross-wave LDS synchronization. Your offer to validate the native Wave64 path on RDNA2 would be very helpful. No AMD correctness claim is being made yet.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 23:00 UTC · original

RDNA3 data for ac445ea: RX 7900 XT, max wave 64, Windows 11 26300, --test-threads=1. #352's probe commit 471e11b is on top for both trees.

victory-shader --lib a-publier (cd8dfc0) + probes this PR + probes
passed 302 313
failed 3: the three scalar_counted_* probes the same 3
  • The PR's 11 tests (pr299_*, scalar_loop_control_*) pass here. On this card the GPU part of the pr299_ fixtures skips, as on the RX 6950 XT, because the route is for max-wave-32 adapters. So only the CPU emission and validation part ran.
  • The three probes fail the same way with and without the PR. Each lane reads its own count, so on RDNA3 too the per-lane result is unchanged, as the scope says. Nothing else changes outcome: the other 302 tests pass on both.
  • One small thing in the description: cargo test --locked -p victory-shader --lib pr299_ scalar_loop_control_ -- ... fails with unexpected argument 'scalar_loop_control_', since cargo takes one name filter before --. Putting both after it works: cargo test --locked -p victory-shader --lib -- pr299_ scalar_loop_control_ --nocapture --test-threads=1.

Glad to run the native wave64 version on this card when there is one.

**@⁠adrianmjim** on GitHub · 2026-11-26 23:00 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7205168574) RDNA3 data for `ac445ea`: RX 7900 XT, max wave 64, Windows 11 26300, `--test-threads=1`. #352's probe commit `471e11b` is on top for both trees. | `victory-shader --lib` | `a-publier` (`cd8dfc0`) + probes | this PR + probes | |---|---|---| | passed | 302 | 313 | | failed | 3: the three `scalar_counted_*` probes | the same 3 | - The PR's 11 tests (`pr299_*`, `scalar_loop_control_*`) pass here. On this card the GPU part of the `pr299_` fixtures skips, as on the RX 6950 XT, because the route is for max-wave-32 adapters. So only the CPU emission and validation part ran. - The three probes fail the same way with and without the PR. Each lane reads its own count, so on RDNA3 too the per-lane result is unchanged, as the scope says. Nothing else changes outcome: the other 302 tests pass on both. - One small thing in the description: `cargo test --locked -p victory-shader --lib pr299_ scalar_loop_control_ -- ...` fails with `unexpected argument 'scalar_loop_control_'`, since cargo takes one name filter before `--`. Putting both after it works: `cargo test --locked -p victory-shader --lib -- pr299_ scalar_loop_control_ --nocapture --test-threads=1`. Glad to run the native wave64 version on this card when there is one.
Author
Owner

@⁠fladit123 on GitHub · 2026-11-26 23:02 UTC · original

Thanks, @⁠adrianmjim! The RDNA3 comparison is very helpful, and thanks for catching the Cargo filter syntax.

The native Wave32 follow-up has now completed its local validation on the physical RTX 4060:

  • Five GPU tests passed, with 320/320 correct readback dwords.
  • One additional CPU-only group-size exclusion control passed.
  • Software-adapter runs passed CPU checks with explicit GPU skips.
  • DXIL disassembly confirms one WaveAnyTrue call site for the simple loop and two for the nested loop, with no group barriers or additional LDS in either shader.
  • The earlier bounded library comparison reported 303 passes and two expected failures versus 305 passes and zero failures. Production code is unchanged since that comparison.

The follow-up is available here:
https://github.com/fladit123/VIctory-Belobug-AMD/tree/fix/native-wave32-divergent-loop-scalars

It currently targets max-wave-32 hosts only.

Since both corrections reuse the same scalar-loop selection logic, would you prefer a separate native-wave follow-up or an extension of #366 once the AMD path is ready?

I would also appreciate independent RDNA2/RDNA3 testing when the native Wave64 candidate becomes available.

AI-assisted investigation and implementation using OpenAI ChatGPT.

**@⁠fladit123** on GitHub · 2026-11-26 23:02 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7205202048) Thanks, @⁠adrianmjim! The RDNA3 comparison is very helpful, and thanks for catching the Cargo filter syntax. The native Wave32 follow-up has now completed its local validation on the physical RTX 4060: - Five GPU tests passed, with 320/320 correct readback dwords. - One additional CPU-only group-size exclusion control passed. - Software-adapter runs passed CPU checks with explicit GPU skips. - DXIL disassembly confirms one WaveAnyTrue call site for the simple loop and two for the nested loop, with no group barriers or additional LDS in either shader. - The earlier bounded library comparison reported 303 passes and two expected failures versus 305 passes and zero failures. Production code is unchanged since that comparison. The follow-up is available here: https://github.com/fladit123/VIctory-Belobug-AMD/tree/fix/native-wave32-divergent-loop-scalars It currently targets max-wave-32 hosts only. Since both corrections reuse the same scalar-loop selection logic, would you prefer a separate native-wave follow-up or an extension of #366 once the AMD path is ready? I would also appreciate independent RDNA2/RDNA3 testing when the native Wave64 candidate becomes available. AI-assisted investigation and implementation using OpenAI ChatGPT.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 23:05 UTC · original

@⁠fladit123 the maintainer's preference matters more than mine here. Since #366 is still a draft and both corrections share the scalar-loop selection, I'd extend #366: one review of that selection logic, and the route that applies to each host stays visible in one place. Keeping each route in its own commit inside the PR would still let either be reverted alone. Yes to the native wave64 candidate: I'll run it on the RX 7900 XT (RDNA3, native wave64) with the three scalar_counted_* probes and victory-shader --lib, before and after, when it's up.

**@⁠adrianmjim** on GitHub · 2026-11-26 23:05 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7205245161) @⁠fladit123 the maintainer's preference matters more than mine here. Since #366 is still a draft and both corrections share the scalar-loop selection, I'd extend #366: one review of that selection logic, and the route that applies to each host stays visible in one place. Keeping each route in its own commit inside the PR would still let either be reverted alone. Yes to the native wave64 candidate: I'll run it on the RX 7900 XT (RDNA3, native wave64) with the three `scalar_counted_*` probes and `victory-shader --lib`, before and after, when it's up.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-26 23:12 UTC · original

Following up on my comment above: a small extension makes the same route work on 64-lane hosts. It is one commit on top of ac445ea: github.com/MamaLeVrai/VIctory-Belobug-AMD@52a3bc4 (branch MamaLeVrai:scalar-loops-whole-wave), offered for you to take into this PR if you want it.

Change (emit/mod.rs, 5 lines): the route also runs when host_max_wave() >= 64, and there it does not require group_sync(). On such a host the 64-thread group is a single host wave. The emitted program declares WaveSize(64) (the new tests assert PSV0 (64, 64)), so the votes at the latches are wave-wide and need no group synchronization.

Tests (wave64_tests.rs): whole_wave_divergent_scalar_loop and whole_wave_nested_divergent_scalar_loops take your pr299_ shapes through emit_scalar_loop(.., 64) and run them on the card when it has 64-lane waves (they skip otherwise).

On an RX 6950 XT (RDNA 2, driver 32.0.21045.29003):

without the change with it
whole_wave_divergent_scalar_loop each lane reads its own count, [1, 2, ..., 64] 64 on every lane
whole_wave_nested_divergent_scalar_loops per-lane products [1, 2, 3, 4, 1, ...] 16 on every lane

cargo test --release -p victory-shader --lib, twice: everything passes apart from #352's three probe tests (merged in for this check), which call lower::lower directly and so never reach emit()'s route. Your 11 tests and the two new ones pass.

Not covered: the wave32 console case (scalar_counted_in_a_wave32_divergent_loop_read_after_it), and RDNA 3. @⁠adrianmjim, your RX 7900 XT would be the card to check the second on.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-26 23:12 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7205348306) Following up on my comment above: a small extension makes the same route work on 64-lane hosts. It is one commit on top of `ac445ea`: https://github.com/MamaLeVrai/VIctory-Belobug-AMD/commit/52a3bc4 (branch `MamaLeVrai:scalar-loops-whole-wave`), offered for you to take into this PR if you want it. **Change (`emit/mod.rs`, 5 lines):** the route also runs when `host_max_wave() >= 64`, and there it does not require `group_sync()`. On such a host the 64-thread group is a single host wave. The emitted program declares `WaveSize(64)` (the new tests assert PSV0 `(64, 64)`), so the votes at the latches are wave-wide and need no group synchronization. **Tests (`wave64_tests.rs`):** `whole_wave_divergent_scalar_loop` and `whole_wave_nested_divergent_scalar_loops` take your `pr299_` shapes through `emit_scalar_loop(.., 64)` and run them on the card when it has 64-lane waves (they skip otherwise). On an RX 6950 XT (RDNA 2, driver 32.0.21045.29003): | | without the change | with it | |---|---|---| | `whole_wave_divergent_scalar_loop` | each lane reads its own count, `[1, 2, ..., 64]` | 64 on every lane | | `whole_wave_nested_divergent_scalar_loops` | per-lane products `[1, 2, 3, 4, 1, ...]` | 16 on every lane | `cargo test --release -p victory-shader --lib`, twice: everything passes apart from #352's three probe tests (merged in for this check), which call `lower::lower` directly and so never reach `emit()`'s route. Your 11 tests and the two new ones pass. Not covered: the wave32 console case (`scalar_counted_in_a_wave32_divergent_loop_read_after_it`), and RDNA 3. @⁠adrianmjim, your RX 7900 XT would be the card to check the second on. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠LTraina0 on GitHub · 2026-11-26 23:22 UTC · original

We reproduced both divergent-loop regressions on a GeForce RTX 4060 Laptop GPU (8 GB, Windows 11, NVIDIA driver 621.40) while testing for the Brazilian project VIctory-RTX4060-Laptop-BR. We ran the same two synthetic fixtures from this PR on both revisions and read the results back from the GPU.

Fixture Expected value in each lane Correct lanes on cd8dfc06 Correct lanes with ac445ea90
Simple divergent scalar loop 64 1/64 64/64
Nested divergent scalar loops 16 4/64 64/64

DXIL validation passed in all four runs. The GPU readback caught the incorrect values on the baseline and confirmed the fix for both fixtures on this Wave32 GPU.

OpenAI Codex assisted with running the tests and writing this report.

**@⁠LTraina0** on GitHub · 2026-11-26 23:22 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7205493677) We reproduced both divergent-loop regressions on a GeForce RTX 4060 Laptop GPU (8 GB, Windows 11, NVIDIA driver 621.40) while testing for the Brazilian project `VIctory-RTX4060-Laptop-BR`. We ran the same two synthetic fixtures from this PR on both revisions and read the results back from the GPU. | Fixture | Expected value in each lane | Correct lanes on `cd8dfc06` | Correct lanes with `ac445ea90` | | --- | ---: | ---: | ---: | | Simple divergent scalar loop | 64 | 1/64 | 64/64 | | Nested divergent scalar loops | 16 | 4/64 | 64/64 | DXIL validation passed in all four runs. The GPU readback caught the incorrect values on the baseline and confirmed the fix for both fixtures on this Wave32 GPU. OpenAI Codex assisted with running the tests and writing this report.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-26 23:37 UTC · original

@⁠MamaLeVrai RDNA3 result for 52a3bc4 (your 64-lane extension on ac445ea): RX 7900 XT, max wave 64, Windows 11 26300, --test-threads=1, #352's probes 471e11b on top.

  • whole_wave_divergent_scalar_loop and whole_wave_nested_divergent_scalar_loops pass. On this card they run on the hardware, not skipped, since it has 64-lane waves. Both assert PSV0 (64, 64) and 64 (resp. 16) on all 64 lanes.
  • pr299_* and scalar_loop_control_* all pass. As before, the pr299_ GPU parts skip here (the synchronized route is for max-wave-32 adapters).
  • Full victory-shader --lib: 315 passed, 3 failed, 4 ignored. The 3 are #352's scalar_counted_* probes. They call lower::lower directly and so never reach emit()'s route, as you said. They still read per-lane counts and declare no wave size.

So the whole-wave route gives the console's values on RDNA 3 too, which makes two RDNA generations with yours. The wave32 console case (scalar_counted_in_a_wave32_divergent_loop_read_after_it) is still the open one.

**@⁠adrianmjim** on GitHub · 2026-11-26 23:37 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7205706746) @⁠MamaLeVrai RDNA3 result for `52a3bc4` (your 64-lane extension on `ac445ea`): RX 7900 XT, max wave 64, Windows 11 26300, `--test-threads=1`, #352's probes `471e11b` on top. - `whole_wave_divergent_scalar_loop` and `whole_wave_nested_divergent_scalar_loops` pass. On this card they run on the hardware, not skipped, since it has 64-lane waves. Both assert PSV0 `(64, 64)` and 64 (resp. 16) on all 64 lanes. - `pr299_*` and `scalar_loop_control_*` all pass. As before, the `pr299_` GPU parts skip here (the synchronized route is for max-wave-32 adapters). - Full `victory-shader --lib`: 315 passed, 3 failed, 4 ignored. The 3 are #352's `scalar_counted_*` probes. They call `lower::lower` directly and so never reach `emit()`'s route, as you said. They still read per-lane counts and declare no wave size. So the whole-wave route gives the console's values on RDNA 3 too, which makes two RDNA generations with yours. The wave32 console case (`scalar_counted_in_a_wave32_divergent_loop_read_after_it`) is still the open one.
Author
Owner

@⁠MamaLeVrai on GitHub · 2026-11-27 00:12 UTC · original

One more commit on the same branch, covering the case the 64-lane one left out, console wave32 programs: github.com/MamaLeVrai/VIctory-Belobug-AMD@2aa9847 (on top of 52a3bc4).

  • emit(): the native.wave64 condition is dropped, so console wave32 programs with a 64-thread group, no LDS, no spill and no waterfall also take the scalar_loop_latches + structure_wide route. The group-synchronization refusal now applies only to wave64 on a 32-lane host. Once a branch is taken wave-wide, the lowering declares WaveSize(32) for a wave32 program on either host. Each console wave is then one host wave, and its latch vote is its own.
  • Test: wave32_divergent_scalar_loop, the DIVERGENT_COUNT_W32 shape from #352, emitted for a 32-lane and a 64-lane host and both run on the card.

On the RX 6950 XT:

PSV0 range (32-lane emission, 64-lane emission) readback (both)
52a3bc4 (0, u32::MAX), (0, u32::MAX) [1, 2, ..., 64]
2aa9847 (32, 32), (32, 32) lanes 0-31: 32, lanes 32-63: 64

Full cargo test --release -p victory-shader --lib, twice: 316 passed, 0 failed, 4 ignored.

Caveats: this assumes each WaveSize(32) host wave holds 32 consecutive threads. That holds for a [64,1,1] group, the only shape tested, and the existing wave32 lane code assumes it too. I kept the wave64 gate (64-thread group, no LDS) although wave32 does not need the group vote. It has not been run on a 32-lane-only card.

AI-assisted (Claude Code); no game data.

**@⁠MamaLeVrai** on GitHub · 2026-11-27 00:12 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7206263823) One more commit on the same branch, covering the case the 64-lane one left out, console **wave32** programs: https://github.com/MamaLeVrai/VIctory-Belobug-AMD/commit/2aa9847 (on top of `52a3bc4`). - **`emit()`:** the `native.wave64` condition is dropped, so console wave32 programs with a 64-thread group, no LDS, no spill and no waterfall also take the `scalar_loop_latches` + `structure_wide` route. The group-synchronization refusal now applies only to wave64 on a 32-lane host. Once a branch is taken wave-wide, the lowering declares `WaveSize(32)` for a wave32 program on either host. Each console wave is then one host wave, and its latch vote is its own. - **Test:** `wave32_divergent_scalar_loop`, the DIVERGENT_COUNT_W32 shape from #352, emitted for a 32-lane and a 64-lane host and both run on the card. On the RX 6950 XT: | | PSV0 range (32-lane emission, 64-lane emission) | readback (both) | |---|---|---| | `52a3bc4` | `(0, u32::MAX)`, `(0, u32::MAX)` | `[1, 2, ..., 64]` | | `2aa9847` | `(32, 32)`, `(32, 32)` | lanes 0-31: 32, lanes 32-63: 64 | Full `cargo test --release -p victory-shader --lib`, twice: 316 passed, 0 failed, 4 ignored. Caveats: this assumes each `WaveSize(32)` host wave holds 32 consecutive threads. That holds for a `[64,1,1]` group, the only shape tested, and the existing wave32 lane code assumes it too. I kept the wave64 gate (64-thread group, no LDS) although wave32 does not need the group vote. It has not been run on a 32-lane-only card. AI-assisted (Claude Code); no game data.
Author
Owner

@⁠fladit123 on GitHub · 2026-11-27 00:15 UTC · original

Thanks, @⁠MamaLeVrai, @⁠adrianmjim and @⁠LTraina0, for the independent implementations and hardware validation!

The native-wave investigation I was running in parallel has also completed.

On my physical RTX 4060:

  • Eight dispatches passed with 512/512 correct readback dwords, including four native Wave32 scalar cases and the existing split-wave regressions.
  • The four native Wave32 scalar cases also passed with group synchronization disabled.
  • A bounded library comparison using the same fixtures and #366 split-wave implementation reported 318 passes and four expected failures without native opt-in, versus 322 passes and zero failures with it.
  • Native Wave64 emission and DXIL validation passed under simulated capabilities, but I have not physically executed that path on AMD.

One portability concern with the proposed Wave32 extension is that a maximum wave width of 64 does not necessarily imply support for WaveSize(32). My experimental path requires the actual min/max wave range, WaveOps and SM 6.6, and restricts the native route to a linear 64-thread group.

However, it is currently an explicit uncached entry point rather than a default runtime change. Integrating these capabilities into normal translation would also require reviewing their propagation and cache fingerprinting.

I would prefer to consolidate our work rather than submit competing implementations. Your commits provide valuable physical AMD validation, while the experimental branch provides capability exclusion, mixed scalar/vector and consecutive-loop controls.

Would you be comfortable with incorporating your commits with their original authorship and then refining the capability checks and test portability?

Thanks again for collaborating on this.

AI-assisted investigation using OpenAI ChatGPT and Codex.

**@⁠fladit123** on GitHub · 2026-11-27 00:15 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7206311841) Thanks, @⁠MamaLeVrai, @⁠adrianmjim and @⁠LTraina0, for the independent implementations and hardware validation! The native-wave investigation I was running in parallel has also completed. On my physical RTX 4060: - Eight dispatches passed with 512/512 correct readback dwords, including four native Wave32 scalar cases and the existing split-wave regressions. - The four native Wave32 scalar cases also passed with group synchronization disabled. - A bounded library comparison using the same fixtures and #366 split-wave implementation reported 318 passes and four expected failures without native opt-in, versus 322 passes and zero failures with it. - Native Wave64 emission and DXIL validation passed under simulated capabilities, but I have not physically executed that path on AMD. One portability concern with the proposed Wave32 extension is that a maximum wave width of 64 does not necessarily imply support for WaveSize(32). My experimental path requires the actual min/max wave range, WaveOps and SM 6.6, and restricts the native route to a linear 64-thread group. However, it is currently an explicit uncached entry point rather than a default runtime change. Integrating these capabilities into normal translation would also require reviewing their propagation and cache fingerprinting. I would prefer to consolidate our work rather than submit competing implementations. Your commits provide valuable physical AMD validation, while the experimental branch provides capability exclusion, mixed scalar/vector and consecutive-loop controls. Would you be comfortable with incorporating your commits with their original authorship and then refining the capability checks and test portability? Thanks again for collaborating on this. AI-assisted investigation using OpenAI ChatGPT and Codex.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-27 00:17 UTC · original

RDNA3 result for 2aa9847 (wave32 on top of 52a3bc4): RX 7900 XT, the driver reports waves of 32 to 64, Windows 11 26300, --test-threads=1, #352's probes on top.

  • wave32_divergent_scalar_loop passes on the hardware. PSV0 is (32, 32) for both the 32-lane and the 64-lane emission. Readback is 32 on lanes 0–31 and 64 on lanes 32–63, both times, i.e. the console's values. That matters on this card: RDNA3 runs a compute program with no WaveSize as wave64. #352's wave32 probe shows that, with each lane reading its own count. So the declared WaveSize(32) is honoured here.
  • All the PR's tests pass, 16 with the whole_wave_* and wave32_* ones. Full victory-shader --lib: 316 passed, 3 failed, 4 ignored. The 3 are #352's probes, which call lower::lower directly and never reach emit()'s route.

On @⁠fladit123's portability point, it's a real case: WellyngtonSantos's RX 580 on #204 reports waves of 64 to 64 (GCN), so WaveSize(32) is outside its range. Gating the wave32 route on the adapter's actual WaveLaneCountMin <= 32, rather than on host_max_wave() >= 64, would keep such a card on the current path. Here min is 32, so the route applies and works.

**@⁠adrianmjim** on GitHub · 2026-11-27 00:17 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7206331094) RDNA3 result for `2aa9847` (wave32 on top of `52a3bc4`): RX 7900 XT, the driver reports waves of 32 to 64, Windows 11 26300, `--test-threads=1`, #352's probes on top. - `wave32_divergent_scalar_loop` passes on the hardware. PSV0 is `(32, 32)` for both the 32-lane and the 64-lane emission. Readback is 32 on lanes 0–31 and 64 on lanes 32–63, both times, i.e. the console's values. That matters on this card: RDNA3 runs a compute program with no `WaveSize` as wave64. #352's wave32 probe shows that, with each lane reading its own count. So the declared `WaveSize(32)` is honoured here. - All the PR's tests pass, 16 with the `whole_wave_*` and `wave32_*` ones. Full `victory-shader --lib`: 316 passed, 3 failed, 4 ignored. The 3 are #352's probes, which call `lower::lower` directly and never reach `emit()`'s route. On @⁠fladit123's portability point, it's a real case: WellyngtonSantos's RX 580 on #204 reports waves of 64 to 64 (GCN), so `WaveSize(32)` is outside its range. Gating the wave32 route on the adapter's actual `WaveLaneCountMin <= 32`, rather than on `host_max_wave() >= 64`, would keep such a card on the current path. Here min is 32, so the route applies and works.
Author
Owner

@⁠TinkerBell-90 on GitHub · 2026-11-27 01:58 UTC · original

The two pr299_ GPU parts skip on AMD cards only because of the test's condition. They need an adapter that runs 32-lane waves, not one whose waves are at most 32 lanes. RDNA runs a WaveSize(32) program in waves of 32 (@⁠adrianmjim showed RDNA 3 honours it above), so an AMD card can run the 32-lane emission, which is the route this PR adds. With this change to check_scalar_loop (test only):

-    if wave_size == Some(32) && max_wave != 32 {
-        eprintln!("GPU SKIP: the synchronized route requires a physical adapter with max wave 32");
+    if wave_size == Some(32) && waves.WaveLaneCountMin > 32 {
+        eprintln!("GPU SKIP: the synchronized route requires an adapter that runs 32-lane waves");
         return;
     }
-    let shader = if max_wave == 32 {
+    let shader = if max_wave == 32 || wave_size == Some(32) {

On an RX 9070 XT (RDNA 4, waves of 32 to 64), Linux, Wine 10 + vkd3d-proton 3.1, Mesa 26.0.8 RADV, at ac445ea:

GPU readback pr299_divergent_scalar_loop pr299_nested_divergent_scalar_loops
this PR 64 on all 64 lanes 16 on all 64 lanes
same tests, emit/mod.rs as on cd8dfc0 1, 2, ..., 64 per-lane products, 16 on 4 lanes

The second row is the RTX 4060 baseline from the description and from @⁠LTraina0. With the change, all 11 pr299_ and scalar_loop_control_ tests pass on this card, the two pr299_ GPU parts included. A card that only runs 64-lane waves, like the RX 580 on #204, still skips. So the maintainer's AMD cards could check this route on hardware too. Nothing was run in game.

AI-assisted.

**@⁠TinkerBell-90** on GitHub · 2026-11-27 01:58 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7207728754) The two `pr299_` GPU parts skip on AMD cards only because of the test's condition. They need an adapter that runs 32-lane waves, not one whose waves are at most 32 lanes. RDNA runs a `WaveSize(32)` program in waves of 32 (@⁠adrianmjim showed RDNA 3 honours it above), so an AMD card can run the 32-lane emission, which is the route this PR adds. With this change to `check_scalar_loop` (test only): ```diff - if wave_size == Some(32) && max_wave != 32 { - eprintln!("GPU SKIP: the synchronized route requires a physical adapter with max wave 32"); + if wave_size == Some(32) && waves.WaveLaneCountMin > 32 { + eprintln!("GPU SKIP: the synchronized route requires an adapter that runs 32-lane waves"); return; } - let shader = if max_wave == 32 { + let shader = if max_wave == 32 || wave_size == Some(32) { ``` On an RX 9070 XT (RDNA 4, waves of 32 to 64), Linux, Wine 10 + vkd3d-proton 3.1, Mesa 26.0.8 RADV, at `ac445ea`: | GPU readback | `pr299_divergent_scalar_loop` | `pr299_nested_divergent_scalar_loops` | |---|---|---| | this PR | 64 on all 64 lanes | 16 on all 64 lanes | | same tests, `emit/mod.rs` as on `cd8dfc0` | 1, 2, ..., 64 | per-lane products, 16 on 4 lanes | The second row is the RTX 4060 baseline from the description and from @⁠LTraina0. With the change, all 11 `pr299_` and `scalar_loop_control_` tests pass on this card, the two `pr299_` GPU parts included. A card that only runs 64-lane waves, like the RX 580 on #204, still skips. So the maintainer's AMD cards could check this route on hardware too. Nothing was run in game. AI-assisted.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-27 02:00 UTC · original

Native confirmation of @⁠TinkerBell-90's test change on RDNA3: RX 7900 XT (waves 32 to 64), Windows 11 26300 native D3D12 (no vkd3d), ac445ea with only that 3-line change in check_scalar_loop, --test-threads=1.

  • All 11 pr299_ and scalar_loop_control_ tests pass, with 8 GPU runs and 0 skips.
  • The two pr299_ fixtures now run the 32-lane emission (PSV0 (32, 32)) on the card. pr299_divergent_scalar_loop reads 64 on all 64 lanes, and pr299_nested_divergent_scalar_loops reads 16 on all 64.
  • The other GPU runs match their expected dwords too, including the vector-only control, which stays per-lane (1, 2, ..., 64).

So with that condition, the synchronized route this PR adds is checked on AMD hardware natively as well as under Proton. A card with 64-lane waves only (the RX 580 on #204) still skips, as it should.

**@⁠adrianmjim** on GitHub · 2026-11-27 02:00 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7207749931) Native confirmation of @⁠TinkerBell-90's test change on RDNA3: RX 7900 XT (waves 32 to 64), Windows 11 26300 native D3D12 (no vkd3d), `ac445ea` with only that 3-line change in `check_scalar_loop`, `--test-threads=1`. - All 11 `pr299_` and `scalar_loop_control_` tests pass, with 8 GPU runs and 0 skips. - The two `pr299_` fixtures now run the 32-lane emission (PSV0 `(32, 32)`) on the card. `pr299_divergent_scalar_loop` reads 64 on all 64 lanes, and `pr299_nested_divergent_scalar_loops` reads 16 on all 64. - The other GPU runs match their expected dwords too, including the vector-only control, which stays per-lane (`1, 2, ..., 64`). So with that condition, the synchronized route this PR adds is checked on AMD hardware natively as well as under Proton. A card with 64-lane waves only (the RX 580 on #204) still skips, as it should.
Author
Owner

@⁠k5tvbn7f5r-maker on GitHub · 2026-11-27 11:30 UTC · original

Independent hardware validation on a desktop RTX 5070 (Blackwell, physical wave size 32), NVIDIA 621.40 WDDM, Windows 11 26H2.

I ran the restored #259 scalar fixtures through the production translator and checked all 64 lanes after D3D12 dispatch. The original base cd8dfc06 returned 1/64 correct values for the simple loop and 4/64 for the nested loop. Both returned 64/64 on ac445ea9. I independently tested the local integration 4b17e2d7 against unpatched a-publier@4eb6cfdf and reproduced the same correction. Two additional fixtures with reversed half-wave workloads also returned 64/64 for both 64×1 and 32×2 groups on the integration.

The eight author GPU cases passed on both candidate builds. VICTORY_GROUP_SYNC=0 gave the expected translation refusal for the synchronized path. The pre-existing #259 loop-exit mask mismatch persisted. The attached ZIP contains commands, per-lane readbacks, and dispatch and coverage logs.
qa-002-pr366-evidence.zip

**@⁠k5tvbn7f5r-maker** on GitHub · 2026-11-27 11:30 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7217155513) Independent hardware validation on a desktop RTX 5070 (Blackwell, physical wave size 32), NVIDIA 621.40 WDDM, Windows 11 26H2. I ran the restored #259 scalar fixtures through the production translator and checked all 64 lanes after D3D12 dispatch. The original base `cd8dfc06` returned 1/64 correct values for the simple loop and 4/64 for the nested loop. Both returned 64/64 on `ac445ea9`. I independently tested the local integration `4b17e2d7` against unpatched `a-publier@4eb6cfdf` and reproduced the same correction. Two additional fixtures with reversed half-wave workloads also returned 64/64 for both `64×1` and `32×2` groups on the integration. The eight author GPU cases passed on both candidate builds. `VICTORY_GROUP_SYNC=0` gave the expected translation refusal for the synchronized path. The pre-existing #259 loop-exit mask mismatch persisted. The attached ZIP contains commands, per-lane readbacks, and dispatch and coverage logs. [qa-002-pr366-evidence.zip](https://github.com/user-attachments/files/35510353/qa-002-pr366-evidence.zip)
Author
Owner

@⁠fladit123 on GitHub · 2026-11-27 17:28 UTC · original

The consolidated candidate is ready for independent hardware validation:

https://github.com/fladit123/VIctory-Belobug-AMD/tree/integration/native-scalar-wave

Commit: 9b85a81075d100c0d74f46bb7e62af37e95a9800

Both of @⁠MamaLeVrai's native-wave commits have been incorporated with their original authorship preserved.

The consolidation retains the original #366 split-wave route and adds:

  • Device-specific min/max wave capability checks, WaveOps and SM 6.6 requirements.
  • Conservative native-wave selection.
  • Worker-local capability scoping and suppression of the native route under explicit width overrides.
  • Separate persistent cache identities and translator version invalidation.
  • All three original #352 probes through the production emit::translate entry point.
  • Additional mixed scalar/vector, consecutive-loop and capability exclusion controls.

Local validation on my RTX 4060:

  • 319 library tests passed, zero failures, four ignored and two filtered.
  • The matched control with native selection disabled had seven expected PSV0 assertion failures.
  • Twelve physical GPU dispatches passed, with 768/768 correct readback dwords.
  • Four native Wave32 cases also passed with group synchronization disabled.
  • Four cache tests and three worker tests passed.
  • Persistent cache separation was verified across independent CLI processes.
  • A separate integration with #345 at 29e7a59 passed 21 focused tests.

@⁠MamaLeVrai, @⁠adrianmjim and @⁠TinkerBell-90, independent validation of this exact revision on RDNA2, RDNA3 and RDNA4 would be very valuable.

Native Wave64 emission and DXIL validation passed locally under simulated capabilities, but physical AMD execution of this revision remains unverified.

The current #366 branch remains unchanged pending that validation and maintainer feedback.

Thanks to everyone who contributed implementations, regression fixtures and independent hardware results.

AI-assisted investigation, consolidation and review using OpenAI ChatGPT and Codex.

**@⁠fladit123** on GitHub · 2026-11-27 17:28 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/pull/366#issuecomment-7224449914) The consolidated candidate is ready for independent hardware validation: https://github.com/fladit123/VIctory-Belobug-AMD/tree/integration/native-scalar-wave Commit: `9b85a81075d100c0d74f46bb7e62af37e95a9800` Both of @⁠MamaLeVrai's native-wave commits have been incorporated with their original authorship preserved. The consolidation retains the original #366 split-wave route and adds: - Device-specific min/max wave capability checks, WaveOps and SM 6.6 requirements. - Conservative native-wave selection. - Worker-local capability scoping and suppression of the native route under explicit width overrides. - Separate persistent cache identities and translator version invalidation. - All three original #352 probes through the production `emit::translate` entry point. - Additional mixed scalar/vector, consecutive-loop and capability exclusion controls. Local validation on my RTX 4060: - 319 library tests passed, zero failures, four ignored and two filtered. - The matched control with native selection disabled had seven expected PSV0 assertion failures. - Twelve physical GPU dispatches passed, with 768/768 correct readback dwords. - Four native Wave32 cases also passed with group synchronization disabled. - Four cache tests and three worker tests passed. - Persistent cache separation was verified across independent CLI processes. - A separate integration with #345 at `29e7a59` passed 21 focused tests. @⁠MamaLeVrai, @⁠adrianmjim and @⁠TinkerBell-90, independent validation of this exact revision on RDNA2, RDNA3 and RDNA4 would be very valuable. Native Wave64 emission and DXIL validation passed locally under simulated capabilities, but physical AMD execution of this revision remains unverified. The current #366 branch remains unchanged pending that validation and maintainer feedback. Thanks to everyone who contributed implementations, regression fixtures and independent hardware results. AI-assisted investigation, consolidation and review using OpenAI ChatGPT and Codex.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/366/head:github-bot/gh-366'
git switch 'github-bot/gh-366'

Merge

Merge the changes and update on Forgejo.
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-366'
git switch 'github-bot/gh-366'
git rebase 'a-publier'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-366'
git switch 'github-bot/gh-366'
git rebase 'a-publier'
git switch 'a-publier'
git merge --no-ff 'github-bot/gh-366'
git switch 'a-publier'
git merge --squash 'github-bot/gh-366'
git switch 'a-publier'
git merge --ff-only 'github-bot/gh-366'
git switch 'a-publier'
git merge 'github-bot/gh-366'
git push origin 'a-publier'
This discussion has been locked. Commenting is limited to contributors.
No description provided.