Shaders: automatically guard divergent single-console-wave barriers on narrower host waves #30

Open
rivaldodev wants to merge 1 commit from upstream-pr/30 into main
rivaldodev commented 2026-11-25 04:11:29 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by rivaldodev on 2026-11-25T03:59:21Z.


Split out from #20 per review feedback and narrowed to preserve cross-console-wave synchronization.

Scope & Semantic Note (Targeted Compatibility Workaround)

This change is a targeted compatibility workaround for narrow-wave hosts (e.g. NVIDIA wave32) running console wave64 shaders where a single-console-wave group spans two host waves:

  • Automatically switches divergent title barriers (fence_only) to drop SyncThreadGroup (keeping memory fences 2 | 8) only when:
    1. The host's widest wave (host_max_wave()) is narrower than the console wave width, AND
    2. The thread group fits in a single console wave (group_threads <= console_wave), where the console had no other wave in the group to synchronize with.
  • Multi-console-wave groups (e.g. 128+ threads in wave64) always keep SyncThreadGroup so cross-wave LDS producer-consumer accesses cannot race.
  • Preserves uniform barriers, translation-added meeting barriers, and explicit VICTORY_GROUP_SYNC overrides (0, 1, 2).
  • Includes host_max_wave() in the shader cache key (crates/victory-gpu/src/shader_cache.rs).

Tests

  • emit::lower::tests::automatic_barriers_keep_fences_and_only_drop_unsafe_sync (covers single-wave, multi-wave, unknown group size, uniform, wave64, and explicit overrides).
  • emit::lower::tests::automatic_barrier_flags_reach_the_emitted_shader (verifies emitted DXIL barrier mode for 64-thread vs. 128-thread groups on wave32 and wave64 hosts).
  • emit::wave64_tests::an_automatic_barrier_inside_a_lane_branch_runs_on_narrow_hardware (runs on live narrow-wave GPU hardware).
<!-- greyfinch-sync:Zettrox/ztrx:issue:6596893903 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/30). Originally posted by [rivaldodev](https://github.com/rivaldodev) on 2026-11-25T03:59:21Z. --- Split out from #20 per review feedback and narrowed to preserve cross-console-wave synchronization. ### Scope & Semantic Note (Targeted Compatibility Workaround) This change is a **targeted compatibility workaround** for narrow-wave hosts (e.g. NVIDIA wave32) running console wave64 shaders where a single-console-wave group spans two host waves: - Automatically switches divergent title barriers (`fence_only`) to drop `SyncThreadGroup` (keeping memory fences `2 | 8`) **only** when: 1. The host's widest wave (`host_max_wave()`) is narrower than the console wave width, AND 2. The thread group fits in a **single console wave** (`group_threads <= console_wave`), where the console had no other wave in the group to synchronize with. - Multi-console-wave groups (e.g. 128+ threads in wave64) always keep `SyncThreadGroup` so cross-wave LDS producer-consumer accesses cannot race. - Preserves uniform barriers, translation-added meeting barriers, and explicit `VICTORY_GROUP_SYNC` overrides (`0`, `1`, `2`). - Includes `host_max_wave()` in the shader cache key (`crates/victory-gpu/src/shader_cache.rs`). ### Tests - `emit::lower::tests::automatic_barriers_keep_fences_and_only_drop_unsafe_sync` (covers single-wave, multi-wave, unknown group size, uniform, wave64, and explicit overrides). - `emit::lower::tests::automatic_barrier_flags_reach_the_emitted_shader` (verifies emitted DXIL barrier mode for 64-thread vs. 128-thread groups on wave32 and wave64 hosts). - `emit::wave64_tests::an_automatic_barrier_inside_a_lane_branch_runs_on_narrow_hardware` (runs on live narrow-wave GPU hardware).
copilot-pull-request-reviewer[bot commented 2026-11-25 04:11:29 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by copilot-pull-request-reviewer[bot] on 2026-11-25T04:08:50Z.

Review: COMMENTED


Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

<!-- greyfinch-sync:Zettrox/ztrx:review:6051729375 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/30#pullrequestreview-6051729375). Originally posted by [copilot-pull-request-reviewer[bot]](https://github.com/copilot-pull-request-reviewer%5Bbot%5D) on 2026-11-25T04:08:50Z. **Review:** COMMENTED --- Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
iGoldenNinja commented 2026-11-25 05:09:08 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by iGoldenNinja on 2026-11-25T04:17:44Z.


Independent RTX 5080 check on PR head 52e06e5, Windows 11 Pro 26200, driver 617.14, Ryzen 9 5900X, 32 GB RAM, MSVC diag, DXC/DXIL validator 1.9.2609.5.

  • cargo test --profile diag --locked -p victory-shader --lib automatic_barrier -- --nocapture --test-threads=1 passed all three selected tests. The hardware fixture ran on wave32 and read back the expected result for 1, 10, 32, 33 and 64 active lanes.
  • An offline PSO check on the same four previously rejected wave64 compute samples produced 4/4 validated modules and 0/4 D3D12 PSOs at both base 90b529f8 and PR head 52e06e5. Each refusal was an incorrect-parameter error. The group sizes were 64, 64, 128 and 256. The two larger groups are outside the automatic barrier rule. The four samples were checked through PSO creation, and the synthetic fixture above performed execution and readback.

Method and results. Testing and reporting assisted by OpenAI Codex.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7152711800 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/30#issuecomment-7152711800). Originally posted by [iGoldenNinja](https://github.com/iGoldenNinja) on 2026-11-25T04:17:44Z. --- Independent RTX 5080 check on PR head `52e06e5`, Windows 11 Pro 26200, driver 617.14, Ryzen 9 5900X, 32 GB RAM, MSVC `diag`, DXC/DXIL validator 1.9.2609.5. - `cargo test --profile diag --locked -p victory-shader --lib automatic_barrier -- --nocapture --test-threads=1` passed all three selected tests. The hardware fixture ran on wave32 and read back the expected result for 1, 10, 32, 33 and 64 active lanes. - An offline PSO check on the same four previously rejected wave64 compute samples produced 4/4 validated modules and 0/4 D3D12 PSOs at both base `90b529f8` and PR head `52e06e5`. Each refusal was an incorrect-parameter error. The group sizes were 64, 64, 128 and 256. The two larger groups are outside the automatic barrier rule. The four samples were checked through PSO creation, and the synthetic fixture above performed execution and readback. [Method and results](https://github.com/iGoldenNinja/victory-fork/blob/f31b723185efcfac8fb9bebf7a6e0463ec581850/docs/ztrx-wave32-barriers-5080.md). Testing and reporting assisted by OpenAI Codex.
futurepro62 commented 2026-11-25 07:06:30 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by futurepro62 on 2026-11-25T06:38:44Z.


Full-suite run, to go with iGoldenNinja's RTX 5080 run of the three new tests above. Tested exact head 52e06e5 (on its base 90b529f).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (rust-toolchain.toml), DXC + dxil.dll 1.9.2602.17, debug.
  • cargo test --workspace --locked: 500 passed, 0 failed, 7 ignored (main 90b529f on this machine: 496 passed, 0 failed, 7 ignored).
  • cargo clippy --workspace --all-targets --locked -- -D warnings (the CI lint step): passed.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings (the CI lint step): passed.
  • The new tests ran and passed: automatic_barriers_keep_fences_and_only_drop_unsafe_sync, automatic_barrier_flags_reach_the_emitted_shader, group_sync_defaults_to_auto_and_keeps_explicit_overrides, an_automatic_barrier_inside_a_lane_branch_runs_on_narrow_hardware.

Not tested

  • AMD (ztrx targets NVIDIA), a release build, the game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
<!-- greyfinch-sync:Zettrox/ztrx:comment:7155008602 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/30#issuecomment-7155008602). Originally posted by [futurepro62](https://github.com/futurepro62) on 2026-11-25T06:38:44Z. --- Full-suite run, to go with iGoldenNinja's RTX 5080 run of the three new tests above. Tested exact head `52e06e5` (on its base `90b529f`). **Tested** - NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.98.1 MSVC (`rust-toolchain.toml`), DXC + dxil.dll 1.9.2602.17, debug. - `cargo test --workspace --locked`: **500 passed, 0 failed, 7 ignored** (main `90b529f` on this machine: 496 passed, 0 failed, 7 ignored). - `cargo clippy --workspace --all-targets --locked -- -D warnings` (the CI lint step): passed. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` (the CI lint step): passed. - The new tests ran and passed: `automatic_barriers_keep_fences_and_only_drop_unsafe_sync`, `automatic_barrier_flags_reach_the_emitted_shader`, `group_sync_defaults_to_auto_and_keeps_explicit_overrides`, `an_automatic_barrier_inside_a_lane_branch_runs_on_narrow_hardware`. **Not tested** - AMD (ztrx targets NVIDIA), a release build, the game (test run only). **AI use** - Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.
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/30:upstream-pr/30'
git switch 'upstream-pr/30'

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/30'
git switch 'upstream-pr/30'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/30'
git switch 'upstream-pr/30'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/30'
git switch 'main'
git merge --squash 'upstream-pr/30'
git switch 'main'
git merge --ff-only 'upstream-pr/30'
git switch 'main'
git merge 'upstream-pr/30'
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
Zettrox/ztrx!30
No description provided.