victory-shader: omit NonUniform on provably uniform title-memory handles #198

Open
github-bot wants to merge 1 commit from github-bot/gh-198 into main AGit
Owner

@⁠Mhyster on GitHub · 2026-12-02 07:30 UTC · original
Mhyster:opt/shader-uniform-memory-nonuniform → main · +204 −19 · 4 files · 1 commits · open

Overlap note: Touches crates/victory-shader/src/emit/lower.rs, memory_flat.rs, and TRANSLATOR_VERSION (13 → 14), overlapping with open PRs #174 (opt/flat-load-run-and-shader-ir) and #169 (shader translation for host subgroups).

What

Omits NonUniformResourceIndex on title-memory descriptor heap handles (Lower::memory, Lower::memory_loads, Lower::root_memory) whenever the title address is provably uniform across every active lane of a host wave:

  1. Conservative host-wave uniformity taint analysis (non_uniform_values in crates/victory-shader/src/emit/lower.rs):
    • Seeds every lane mask (st.masks, st.highs), de-waterfalled descriptor read/load (waterfall.reads, waterfall.loads), every VGPR value (Reg::V), and every scalar phi at the frontier of a per-lane branch (lane_regions) as potentially non-uniform, then propagates taint to a fixed point (treating v_readfirstlane_b32 outside waterfall.reads as wave-uniform, and conservatively tainting all multi-predecessor phis if any uniform branch condition becomes tainted).
  2. Uniform title-memory handles (Lower::memory, Lower::memory_loads, Lower::root_memory):
    • memory_smem (s_load_dword* by title address) passes uniform = true when both base SGPRs and soffset are absent from non_uniform.
    • Scalar smem (s_buffer_load_dword* via root_memory) and constant-offset global loads through a root view pass uniform = true when the dynamic offset and soffset are absent from non_uniform and inside is None.
    • All per-lane vector memory paths (memory_flat, intersect.rs, buffer_* with VGPR offsets / inside.is_some()) keep nonuniform = true.
  3. Bumps TRANSLATOR_VERSION from 13 to 14 (crates/victory-shader/src/lib.rs).

Reproduces console wave-wide scalar loads (s_load_dword* / s_buffer_load_dword*), allowing RADV/ACO to lower uniform title-memory accesses without v_readfirstlane waterfall loops.

The reference

  • crates/victory-shader/src/emit/lower.rs (Lower::handle, lane_regions): Lower::handle already omits NonUniform for non-waterfall Source::Loaded, Source::Phi, and Source::Select descriptors (heap_handle_at(..., false, ...)), while Lower::memory previously hardcoded nonuniform = true for all callers including scalar s_load_dword* and scalar root_memory.

Evidence

  • Whole-store DXIL diff (translate-dir across all 19,161 containers in source.sqlite):
    • 19,161 / 19,161 translated with 0 failures on both vktory6/main and this branch.
    • 32 compute shaders changed (by_stage={'CS': 32}), including ray-walking / BVH compute shaders (8e5d070d8d4793ea5864d1c3795c71c3, 381ef16494cc782dd71de1090c34b2ab, f6e47efa50226beb5574b5038367bffe, a1b20bc47e3c9597942d18a198af9309).
    • SPIR-V validation (dxil-probe + spirv-val --target-env vulkan1.3): 32 / 32 (100%) of changed shaders passed spirv-val cleanly.
    • SPIR-V NonUniform reduction across all 32 changed shaders: 17,084 -> 16,790 (-294 NonUniform decorations, ~98 eliminated waterfall loops), with OpLoad unchanged (13,065 -> 13,065, +0 instructions).
  • Unit test added in crates/victory-shader/src/emit/lower.rs: uniform_smem_memory_load_omits_nonuniform_while_flat_keeps_it verifies s_load_dwordx2 from uniform SGPRs yields nonuniform_handles == 0 while global_load_dword from VGPRs keeps nonuniform_handles == 1.
  • Local CI checks passed (Linux x86_64):
    • cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked (241 passed, 2 ignored in victory-shader)
    • (cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked)
    • cargo clippy --all-targets --locked -- -D warnings on root native crates, greenfield, greenfield/wine, and greenfield/vkback/translate.
  • Not run: Windows-only on-card victory-shader tests under Proton, live game / AMD GPU A/B frame timing (frames.py), and Vulkan validation run (house scene) could not be run in this session (no live game / GPU run performed); cargo xwin clippy runs in GitHub Actions CI.

Checklist (docs/AGENTS.md)

  • One topic (rule 31); docs/TASKS.md not edited, the fixed item named above (rule 29)
  • "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen (it drops the maintainers' commits)
  • No fallback or second path for a case that can't happen, in title data or in our own setup (rule 33); unexpected input fails loudly (rule 9)
  • Constants come from the console, the hardware or the title's data, not tuned by eye or ear (rule 9b)
  • Every switch is listed, read in one place, and a bad value stops the start (rule 2)
  • Queues and other externally synchronized Vulkan objects are used under their lock (rule 35)
  • Every unsafe block has a // SAFETY: comment; no raw pointer around the borrow checker (rule 36)
  • Clippy clean; tests call the production code; TRANSLATOR_VERSION bumped if the translator's output changes (rule 27)
  • Comments say what is true now and name functions, not line numbers (rule 3)
  • Nothing from the title, and no pointers to where non-free data can be found (hard constraints)
**@⁠Mhyster** on GitHub · 2026-12-02 07:30 UTC · [original](https://github.com/vktory6/VKtory/pull/198) `Mhyster:opt/shader-uniform-memory-nonuniform` → `main` · +204 −19 · 4 files · 1 commits · open > **Overlap note**: Touches `crates/victory-shader/src/emit/lower.rs`, `memory_flat.rs`, and `TRANSLATOR_VERSION` (13 → 14), overlapping with open PRs #174 (`opt/flat-load-run-and-shader-ir`) and #169 (shader translation for host subgroups). ## What Omits `NonUniformResourceIndex` on title-memory descriptor heap handles (`Lower::memory`, `Lower::memory_loads`, `Lower::root_memory`) whenever the title address is provably uniform across every active lane of a host wave: 1. **Conservative host-wave uniformity taint analysis (`non_uniform_values` in `crates/victory-shader/src/emit/lower.rs`)**: - Seeds every lane mask (`st.masks`, `st.highs`), de-waterfalled descriptor read/load (`waterfall.reads`, `waterfall.loads`), every VGPR value (`Reg::V`), and every scalar phi at the frontier of a per-lane branch (`lane_regions`) as potentially non-uniform, then propagates taint to a fixed point (treating `v_readfirstlane_b32` outside `waterfall.reads` as wave-uniform, and conservatively tainting all multi-predecessor phis if any uniform branch condition becomes tainted). 2. **Uniform title-memory handles (`Lower::memory`, `Lower::memory_loads`, `Lower::root_memory`)**: - `memory_smem` (`s_load_dword*` by title address) passes `uniform = true` when both base SGPRs and `soffset` are absent from `non_uniform`. - Scalar `smem` (`s_buffer_load_dword*` via `root_memory`) and constant-offset global loads through a root view pass `uniform = true` when the dynamic offset and `soffset` are absent from `non_uniform` and `inside` is `None`. - All per-lane vector memory paths (`memory_flat`, `intersect.rs`, `buffer_*` with VGPR offsets / `inside.is_some()`) keep `nonuniform = true`. 3. **Bumps `TRANSLATOR_VERSION` from 13 to 14** (`crates/victory-shader/src/lib.rs`). Reproduces console wave-wide scalar loads (`s_load_dword*` / `s_buffer_load_dword*`), allowing RADV/ACO to lower uniform title-memory accesses without `v_readfirstlane` waterfall loops. ## The reference - `crates/victory-shader/src/emit/lower.rs` (`Lower::handle`, `lane_regions`): `Lower::handle` already omits `NonUniform` for non-waterfall `Source::Loaded`, `Source::Phi`, and `Source::Select` descriptors (`heap_handle_at(..., false, ...)`), while `Lower::memory` previously hardcoded `nonuniform = true` for all callers including scalar `s_load_dword*` and scalar `root_memory`. ## Evidence - **Whole-store DXIL diff (`translate-dir` across all 19,161 containers in `source.sqlite`)**: - `19,161 / 19,161` translated with **`0` failures** on both `vktory6/main` and this branch. - **`32` compute shaders changed** (`by_stage={'CS': 32}`), including ray-walking / BVH compute shaders (`8e5d070d8d4793ea5864d1c3795c71c3`, `381ef16494cc782dd71de1090c34b2ab`, `f6e47efa50226beb5574b5038367bffe`, `a1b20bc47e3c9597942d18a198af9309`). - **SPIR-V validation (`dxil-probe` + `spirv-val --target-env vulkan1.3`)**: **32 / 32 (100%)** of changed shaders passed `spirv-val` cleanly. - **SPIR-V `NonUniform` reduction across all 32 changed shaders**: `17,084 -> 16,790` (**-294 `NonUniform` decorations**, ~98 eliminated waterfall loops), with `OpLoad` unchanged (`13,065 -> 13,065`, +0 instructions). - **Unit test added** in `crates/victory-shader/src/emit/lower.rs`: `uniform_smem_memory_load_omits_nonuniform_while_flat_keeps_it` verifies `s_load_dwordx2` from uniform SGPRs yields `nonuniform_handles == 0` while `global_load_dword` from VGPRs keeps `nonuniform_handles == 1`. - **Local CI checks passed (Linux x86_64)**: - `cargo test -p victory-shader -p victory-formats -p victory-core -p xtask --locked` (241 passed, 2 ignored in `victory-shader`) - `(cd greenfield && cargo test -p umem -p frame -p vkback --lib --locked && cargo test -p vkback --test policy --locked)` - `cargo clippy --all-targets --locked -- -D warnings` on root native crates, `greenfield`, `greenfield/wine`, and `greenfield/vkback/translate`. - **Not run**: Windows-only on-card `victory-shader` tests under Proton, live game / AMD GPU A/B frame timing (`frames.py`), and Vulkan validation run (house scene) could not be run in this session (no live game / GPU run performed); `cargo xwin clippy` runs in GitHub Actions CI. ## Checklist (docs/AGENTS.md) - [x] One topic (rule 31); `docs/TASKS.md` not edited, the fixed item named above (rule 29) - [x] "Allow edits by maintainers" on; after review, no force-push and no close-and-reopen (it drops the maintainers' commits) - [x] No fallback or second path for a case that can't happen, in title data or in our own setup (rule 33); unexpected input fails loudly (rule 9) - [x] Constants come from the console, the hardware or the title's data, not tuned by eye or ear (rule 9b) - [x] Every switch is listed, read in one place, and a bad value stops the start (rule 2) - [x] Queues and other externally synchronized Vulkan objects are used under their lock (rule 35) - [x] Every `unsafe` block has a `// SAFETY:` comment; no raw pointer around the borrow checker (rule 36) - [x] Clippy clean; tests call the production code; `TRANSLATOR_VERSION` bumped if the translator's output changes (rule 27) - [x] Comments say what is true now and name functions, not line numbers (rule 3) - [x] Nothing from the title, and no pointers to where non-free data can be found (hard constraints)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-02 07:34:58 +00:00
Author
Owner

@⁠vktory6 on GitHub · 2026-12-02 15:28 UTC · original

Thanks. Dropping NonUniform where the address is uniform is a good idea, but a wrongly dropped NonUniform is silent wrong data on RADV, so the bar is high. Please:

  • Prove it. Show why SGPR values are host-wave-uniform outside lane regions in every stage (rule 6).
  • Use one analysis. Reuse or merge with the existing lane_uniform instead of adding a second taint pass (rules 3 and 33).
  • Fix the doc comments. is_uniform_value landed inside memory's doc comment, and both are garbled now.
  • Run the checks. On-card tests, a validation run, and an A B B A run (it's a speed change).
**@⁠vktory6** on GitHub · 2026-12-02 15:28 UTC · [original](https://github.com/vktory6/VKtory/pull/198#issuecomment-7350391600) Thanks. Dropping NonUniform where the address is uniform is a good idea, but a wrongly dropped NonUniform is silent wrong data on RADV, so the bar is high. Please: - **Prove it.** Show why SGPR values are host-wave-uniform outside lane regions in every stage (rule 6). - **Use one analysis.** Reuse or merge with the existing `lane_uniform` instead of adding a second taint pass (rules 3 and 33). - **Fix the doc comments.** `is_uniform_value` landed inside `memory`'s doc comment, and both are garbled now. - **Run the checks.** On-card tests, a validation run, and an A B B A run (it's a speed change).
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.rs
  • crates/victory-shader/src/lib.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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