Shaders: lower static samplers and uniform descriptor trees across control flow #135

Open
VastyViz wants to merge 1 commit from upstream-pr/135 into main
VastyViz commented 2026-11-25 14:11:01 +00:00 (Migrated from github.com)
First-time contributor

Imported from Zettrox/ztrx. Originally posted by VastyViz on 2026-11-25T13:39:21Z.


Support immediate (static) samplers chosen by uniform control flow (Source::Phi / Source::Select), and generalize uniform descriptor lowering to arbitrary nested Loaded / Phi / Select trees:

  • Add SamplerChoice, resolve_sampler, sampler_tag, and with_sampler in crates/victory-shader/src/emit/lower.rs:
    • Walks uniform Source::Phi and Source::Select trees containing Source::Constant static samplers (optionally mixed with Source::Loaded heap samplers), deduplicates static sampler descriptors in self.samplers, and produces a wave-uniform i32 selector tag (collapsing straight to SamplerChoice::Single with no extra blocks when all paths pick the same static sampler).
    • Dispatches the DXIL sampling/gather/LOD call across one branch per distinct sampler binding so every D3D12_STATIC_SAMPLER_DESC keeps a constant binding handle (no dynamic indexing of static samplers), extracting the active scalar channels in each arm and joining them with scalar phis in a fresh join block while preserving wave-uniform derivatives.
  • Replace the separate descriptor_phi and two-leaf Source::Select paths with a unified recursive uniform_heap_index helper handling nested Source::Loaded, Source::Phi, and Source::Select descriptor trees.
  • Add end-to-end synthetic GPU + WARP test emit::waterfall_tests::static_samplers_chosen_by_control_flow_and_select_sample_correctly testing Source::Phi (static WRAP vs static CLAMP), Source::Select (s_cselect_b32), and mixed Source::Phi (static WRAP vs heap CLAMP) on a 2x1 texture at u = 1.25.

Verification

  • Full title shader archive sweep (26,503 containers, dxil.dll validation):
    • emit: a descriptor chosen by control flow: 40 -> 0 (all 40 eliminated).
    • Vertex & pixel shaders: 14,156 -> 14,193 emitted (+37), 14,045 -> 14,082 validated (+37, 100% of new emissions validated).
    • Mesh shaders: 8,762 -> 8,765 emitted (+3, reaching 8,765 / 8,765 = 100% mesh emission), 8,657 -> 8,660 validated (+3).
    • Zero regressions across all 26,084 translated programs.
  • Verified D3D12 pipeline creation on an RTX 3080 for both a previously failing mesh shader and pixel shader (2/2 pipelines created).
  • cargo clippy --workspace --all-targets --locked -- -D warnings — passed.
  • cargo clippy --workspace --all-targets --all-features --locked -- -D warnings — passed.
  • cargo test --workspace --locked — passed (victory-shader: 211 passed, including the new RTX 3080 + WARP sampler dispatch tests).
  • cargo xtask policy and git diff --check — passed.
<!-- greyfinch-sync:Zettrox/ztrx:issue:6605782119 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/135). Originally posted by [VastyViz](https://github.com/VastyViz) on 2026-11-25T13:39:21Z. --- Support immediate (static) samplers chosen by uniform control flow (`Source::Phi` / `Source::Select`), and generalize uniform descriptor lowering to arbitrary nested `Loaded` / `Phi` / `Select` trees: - Add `SamplerChoice`, `resolve_sampler`, `sampler_tag`, and `with_sampler` in `crates/victory-shader/src/emit/lower.rs`: - Walks uniform `Source::Phi` and `Source::Select` trees containing `Source::Constant` static samplers (optionally mixed with `Source::Loaded` heap samplers), deduplicates static sampler descriptors in `self.samplers`, and produces a wave-uniform `i32` selector tag (collapsing straight to `SamplerChoice::Single` with no extra blocks when all paths pick the same static sampler). - Dispatches the DXIL sampling/gather/LOD call across one branch per distinct sampler binding so every `D3D12_STATIC_SAMPLER_DESC` keeps a constant binding handle (no dynamic indexing of static samplers), extracting the active scalar channels in each arm and joining them with scalar phis in a fresh join block while preserving wave-uniform derivatives. - Replace the separate `descriptor_phi` and two-leaf `Source::Select` paths with a unified recursive `uniform_heap_index` helper handling nested `Source::Loaded`, `Source::Phi`, and `Source::Select` descriptor trees. - Add end-to-end synthetic GPU + WARP test `emit::waterfall_tests::static_samplers_chosen_by_control_flow_and_select_sample_correctly` testing `Source::Phi` (static WRAP vs static CLAMP), `Source::Select` (`s_cselect_b32`), and mixed `Source::Phi` (static WRAP vs heap CLAMP) on a 2x1 texture at `u = 1.25`. ### Verification - Full title shader archive sweep (`26,503` containers, `dxil.dll` validation): - `emit: a descriptor chosen by control flow`: `40 -> 0` (all 40 eliminated). - Vertex & pixel shaders: `14,156 -> 14,193` emitted (`+37`), `14,045 -> 14,082` validated (`+37`, 100% of new emissions validated). - Mesh shaders: `8,762 -> 8,765` emitted (`+3`, reaching **8,765 / 8,765 = 100%** mesh emission), `8,657 -> 8,660` validated (`+3`). - Zero regressions across all `26,084` translated programs. - Verified D3D12 pipeline creation on an RTX 3080 for both a previously failing mesh shader and pixel shader (`2/2` pipelines created). - `cargo clippy --workspace --all-targets --locked -- -D warnings` — passed. - `cargo clippy --workspace --all-targets --all-features --locked -- -D warnings` — passed. - `cargo test --workspace --locked` — passed (`victory-shader`: `211 passed`, including the new RTX 3080 + WARP sampler dispatch tests). - `cargo xtask policy` and `git diff --check` — passed.
azimaus970 commented 2026-11-25 15:08:46 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by azimaus970 on 2026-11-25T14:51:16Z.


Independently tested a989523 on Windows build 26300.9974 with NVIDIA driver 32.0.16.2140. The focused static_samplers_chosen_by_control_flow_and_select_sample_correctly test passed (1 passed, 0 failed, 0.89 s).

A rerun from a temporary copy with adapter logging confirmed that all three sampler cases passed on both the NVIDIA GeForce RTX 3060 Laptop GPU and Microsoft WARP (Microsoft Basic Render Driver). The rerun passed in 0.90 s with Cargo exit code 0. No game files were used.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7165918606 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/135#issuecomment-7165918606). Originally posted by [azimaus970](https://github.com/azimaus970) on 2026-11-25T14:51:16Z. --- Independently tested a989523 on Windows build 26300.9974 with NVIDIA driver 32.0.16.2140. The focused static_samplers_chosen_by_control_flow_and_select_sample_correctly test passed (1 passed, 0 failed, 0.89 s). A rerun from a temporary copy with adapter logging confirmed that all three sampler cases passed on both the NVIDIA GeForce RTX 3060 Laptop GPU and Microsoft WARP (Microsoft Basic Render Driver). The rerun passed in 0.90 s with Cargo exit code 0. No game files were used.
Artking175 commented 2026-11-25 15:08:46 +00:00 (Migrated from github.com)
Author
First-time contributor

Imported from Zettrox/ztrx. Originally posted by Artking175 on 2026-11-25T15:01:27Z.


Independent synthetic sampler retest on a989523, Windows 10 22H2, RTX 2060, driver 531.41. I applied #121 for the unit-test executable's Agility SDK 1.608.2 support and logged each adapter and readback. The validator was pinned to dxil.dll 1.8.2505.32.

The RTX 2060 reported SM 6.6. All three cases (static Phi, static Select, and mixed static/heap Phi) created compute pipelines and returned 1 for cond=0 and 4 for cond=1, as expected. The complete emit::waterfall_tests group had 6 passed, 0 failed. The new test skipped its WARP executions because WARP on this machine reported SM 6.2. No game files were used.

<!-- greyfinch-sync:Zettrox/ztrx:comment:7166182131 --> Imported from [Zettrox/ztrx](https://github.com/Zettrox/ztrx/pull/135#issuecomment-7166182131). Originally posted by [Artking175](https://github.com/Artking175) on 2026-11-25T15:01:27Z. --- Independent synthetic sampler retest on `a989523`, Windows 10 22H2, RTX 2060, driver 531.41. I applied #121 for the unit-test executable's Agility SDK 1.608.2 support and logged each adapter and readback. The validator was pinned to `dxil.dll` 1.8.2505.32. The RTX 2060 reported SM 6.6. All three cases (static `Phi`, static `Select`, and mixed static/heap `Phi`) created compute pipelines and returned `1` for `cond=0` and `4` for `cond=1`, as expected. The complete `emit::waterfall_tests` group had **6 passed, 0 failed**. The new test skipped its WARP executions because WARP on this machine reported SM 6.2. No game files were used.
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/135:upstream-pr/135'
git switch 'upstream-pr/135'

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