Shaders: lower immediate samplers chosen by uniform control flow (100% mesh, +37 PS) #25

Open
MartinIndra02 wants to merge 1 commit from upstream-pr/25 into main
MartinIndra02 commented 2026-11-24 20:24:31 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by MartinIndra02 on 2026-11-24T20:24:31Z.


Summary

Lowers immediate (constant) samplers chosen by uniform control flow (Source::Phi of Source::Constant) in crates/victory-shader/src/emit/lower.rs, without requiring phi %dx.types.Handle or dynamically indexed static sampler arrays (both rejected by DXIL / D3D12):

  • Collects the distinct immediate sampler constants reachable across a Source::Phi (recursively through nested Source::Phis).
  • If every reachable predecessor resolves to the same immediate sampler, emits a single static sampler handle (self.s.sampler_handle) with no phi or branch.
  • If predecessors select distinct immediate samplers, builds a uniform i32 phi of the choice index at the join block and emits a uniform branch chain at the image sample/gather site, where each arm binds its own standard static sampler (s<n>) and merges the 4 sampled f32 channels via scalar phi f32.

Verification

  • Hardware GPU + WARP tests (RTX 3080, SM 6.6):
    • New end-to-end test emit::waterfall_tests::immediate_sampler_chosen_by_control_flow passes on both RTX 3080 hardware and WARP for both identical and distinct immediate samplers across branches.
    • cargo clippy --workspace -- -D warnings (default + --features diagnostics): 0 warnings.
    • cargo xtask policy: 167 files ok.
  • Offline shader corpus A/B on 7b0f736 (aggregate counts only, no game data):
    • emit: a descriptor chosen by control flow: 40 → 0
    • Mesh programs emitted: 8,762 → 8,765 of 8,765 (100% of all mesh shaders) (+3 terrain/shadow mesh shaders)
    • Vertex & pixel programs emitted: 14,140 → 14,177 of 14,247 (+37 material, puddle, and reflection pixel shaders)

AI-assisted contribution (Antigravity); all code, tests, and hardware verification run and reviewed locally. No game data.

<!-- greyfinch-sync:fxceless/victory-fork:issue:6590707505 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/25). Originally posted by [MartinIndra02](https://github.com/MartinIndra02) on 2026-11-24T20:24:31Z. --- ## Summary Lowers immediate (constant) samplers chosen by uniform control flow (`Source::Phi` of `Source::Constant`) in `crates/victory-shader/src/emit/lower.rs`, without requiring `phi %dx.types.Handle` or dynamically indexed static sampler arrays (both rejected by DXIL / D3D12): - Collects the distinct immediate sampler constants reachable across a `Source::Phi` (recursively through nested `Source::Phi`s). - If every reachable predecessor resolves to the same immediate sampler, emits a single static sampler handle (`self.s.sampler_handle`) with no phi or branch. - If predecessors select distinct immediate samplers, builds a uniform `i32` phi of the choice index at the join block and emits a uniform branch chain at the `image` sample/gather site, where each arm binds its own standard static sampler (`s<n>`) and merges the 4 sampled `f32` channels via scalar `phi f32`. ## Verification - **Hardware GPU + WARP tests (RTX 3080, SM 6.6):** - New end-to-end test `emit::waterfall_tests::immediate_sampler_chosen_by_control_flow` passes on **both RTX 3080 hardware and WARP** for both identical and distinct immediate samplers across branches. - `cargo clippy --workspace -- -D warnings` (default + `--features diagnostics`): 0 warnings. - `cargo xtask policy`: 167 files ok. - **Offline shader corpus A/B on `7b0f736` (aggregate counts only, no game data):** - `emit: a descriptor chosen by control flow`: **`40 → 0`** - **Mesh programs emitted: `8,762 → 8,765` of `8,765` (`100%` of all mesh shaders)** (`+3` terrain/shadow mesh shaders) - **Vertex & pixel programs emitted: `14,140 → 14,177` of `14,247`** (`+37` material, puddle, and reflection pixel shaders) *AI-assisted contribution (Antigravity); all code, tests, and hardware verification run and reviewed locally. No game data.*
adriaespii commented 2026-11-24 21:30:40 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by adriaespii on 2026-11-24T20:54:38Z.


Independent test run on commit cb80bf0 (AMD RDNA4):

  • Hardware: AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (x86_64-pc-windows-msvc)
  • cargo clippy --workspace --all-targets -- -D warnings: 0 warnings
  • cargo test --workspace: 497 passed, 0 failed, 7 ignored (victory-shader: 211 passed, 0 failed, 2 ignored; victory-gpu: 110 passed, 0 failed, 1 ignored)
  • Not tested: retail shader pack / live game run (no game files on this machine)

AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7144219456 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/25#issuecomment-7144219456). Originally posted by [adriaespii](https://github.com/adriaespii) on 2026-11-24T20:54:38Z. --- Independent test run on commit `cb80bf0` (AMD RDNA4): - **Hardware:** AMD Radeon RX 9070 (driver 32.0.32015.7029), AMD Ryzen 5 7600, Windows 11 Pro, Rust 1.98.1 (`x86_64-pc-windows-msvc`) - `cargo clippy --workspace --all-targets -- -D warnings`: 0 warnings - `cargo test --workspace`: 497 passed, 0 failed, 7 ignored (`victory-shader`: 211 passed, 0 failed, 2 ignored; `victory-gpu`: 110 passed, 0 failed, 1 ignored) - **Not tested:** retail shader pack / live game run (no game files on this machine) *AI use: Antigravity (Gemini 4 Neon) ran clippy/tests locally and wrote this report.*
m335671 commented 2026-11-24 21:30:41 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by m335671 on 2026-11-24T21:02:14Z.


Test run on cb80bf0 (this PR's head) with #23's one-line pad change on top (input only). RTX 4070, Windows. No regression, and no visible change in the prologue scene I tested.

Tested

  • NVIDIA GeForce RTX 4070 12 GB (32-lane waves), driver 32.0.16.2124, default TDR; AMD Ryzen 9 7900, 32 GB; Windows 11 Pro 26300; Rust 1.97.1, release build.
  • Own 1.0.2.1, Series X, started from the prologue checkpoint. VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024, the same pipeline library as the run it is compared with (#27, run 4 on 7b0f736).
  • About 7 minutes, no device removal.
  • Counts and log lines only.

What changed

  • Because 1684989 and this PR change many translations, about 2,000 pipelines had to be rebuilt. For the first few minutes, frames took up to 9 s and the screen was black or frozen.
  • Once the library had caught up (samples with 20 or fewer pipelines being made, n = 24): 4.3 fps median, 232 ms/frame, 5,035 draws/frame, 334 dropped without a host pipeline.
  • 7b0f736 in the same scene (#27, run 4): 4.1 fps, 246 ms, 4,973 draws, 355 dropped. That is within run-to-run noise.
  • The shaders that fail in this scene are the same set before and after: 14 distinct shader does not translate hashes and 6 distinct refused pipelines, with identical hashes. So none of the programs this PR fixes is bound in this part of the prologue on my run.

Not tested

  • Scenes past the prologue's first minutes, where the material, puddle and reflection programs this PR adds may be bound.
  • The PR's own tests, clippy, and the offline corpus count.

AI use: the run was done on my machine. Claude Code (Claude Opus 5.5) built it, ran it, read the logs, worked out the figures and wrote this comment.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7144390194 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/25#issuecomment-7144390194). Originally posted by [m335671](https://github.com/m335671) on 2026-11-24T21:02:14Z. --- Test run on `cb80bf0` (this PR's head) with #23's one-line pad change on top (input only). RTX 4070, Windows. No regression, and no visible change in the prologue scene I tested. **Tested** - NVIDIA GeForce RTX 4070 12 GB (32-lane waves), driver 32.0.16.2124, default TDR; AMD Ryzen 9 7900, 32 GB; Windows 11 Pro 26300; Rust 1.97.1, release build. - Own 1.0.2.1, Series X, started from the prologue checkpoint. `VICTORY_LATE_WAIT=3 VICTORY_WIDE_BACK=1 VICTORY_CARD_BUFFERS_MIN_MB=1 VICTORY_CARD_BUFFERS_MB=1024`, the same pipeline library as the run it is compared with (#27, run 4 on `7b0f736`). - About 7 minutes, no device removal. - Counts and log lines only. **What changed** - Because `1684989` and this PR change many translations, about 2,000 pipelines had to be rebuilt. For the first few minutes, frames took up to 9 s and the screen was black or frozen. - Once the library had caught up (samples with 20 or fewer pipelines being made, n = 24): **4.3 fps** median, 232 ms/frame, 5,035 draws/frame, 334 dropped without a host pipeline. - `7b0f736` in the same scene (#27, run 4): 4.1 fps, 246 ms, 4,973 draws, 355 dropped. That is within run-to-run noise. - The shaders that fail in this scene are **the same set before and after**: 14 distinct `shader does not translate` hashes and 6 distinct refused pipelines, with identical hashes. So none of the programs this PR fixes is bound in this part of the prologue on my run. **Not tested** - Scenes past the prologue's first minutes, where the material, puddle and reflection programs this PR adds may be bound. - The PR's own tests, clippy, and the offline corpus count. AI use: the run was done on my machine. Claude Code (Claude Opus 5.5) built it, ran it, read the logs, worked out the figures and wrote this comment.
arminkhaleghirod commented 2026-11-24 23:09:35 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by arminkhaleghirod on 2026-11-24T22:23:48Z.


Merged onto main 90228a7 and ran victory translate --validate over the full title (26,148 programs) on Windows 11 / RTX 4080.

  • a descriptor chosen by control flow: 40 → 0
  • DXIL emitted: 14,168 → 14,205
  • No new failure reason. 39 of the 40 land in the blanket PSV mismatch on main, so their real validator result only shows with #61.
<!-- greyfinch-sync:fxceless/victory-fork:comment:7146177332 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/25#issuecomment-7146177332). Originally posted by [arminkhaleghirod](https://github.com/arminkhaleghirod) on 2026-11-24T22:23:48Z. --- Merged onto main 90228a7 and ran `victory translate --validate` over the full title (26,148 programs) on Windows 11 / RTX 4080. - `a descriptor chosen by control flow`: 40 → 0 - DXIL emitted: 14,168 → 14,205 - No new failure reason. 39 of the 40 land in the blanket PSV mismatch on main, so their real validator result only shows with #61.
nuiiv commented 2026-11-25 06:06:36 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by nuiiv on 2026-11-25T05:14:45Z.


Test run of this PR on AMD RDNA 2 (merged onto current main 310c6eb, clean merge).

Setup

  • AMD Radeon RX 6650 XT, driver 32.0.21045.29003; Ryzen 5 7500F, 16 GB; Windows 11 Pro 26300; rustc 1.98.1, release build.
  • Validator: dxil.dll from Windows SDK 10.0.26100.0.

Results

  • The 40 programs that failed with a descriptor chosen by control flow (selected with VICTORY_TRANSLATE_ONLY), translate --validate --pipelines: 40 of 40 translate, 40 validate, 40 host pipelines created on the card (37 Ps, 3 Ms).
  • immediate_sampler_chosen_by_control_flow passes on the RX 6650 XT hardware device and WARP (neither was skipped).

A possibly simpler alternative, for what it is worth
Independently, I tried picking the sampler by number instead of branching at the sample site: a uniform i32 phi of the immediate sampler numbers at the join, then one createHandleFromBinding over the range s<lo>..s<hi> of the pipeline's static samplers, indexed by that phi (like s[i] of a SamplerState s[]). On this machine, for the same 40 programs, that form also passed dxil.dll 10.0.26100 and the driver created all 40 pipelines. A full translate --pipelines over the title showed 40 gained and none lost. I have only tested it on this one AMD card, so the "rejected by D3D12" case in the description may be NVIDIA-specific or about a different binding shape. I'm only mentioning it as an option, not asking for a change.

In the title with this PR (own 1.0.2.1, Series X, fresh shader cache, about 5 minutes into the prologue, full log kept): no device removal, no error. None of the 40 programs was bound: the log has a shader translated line for every program used, and none of the 40 hashes is among them (the runtime and offline hashes match; checked with the programs that do fail). That is the same as the RTX 4070 run above. World frames averaged 1.7 fps, 3,883 draws/frame. The programs that failed in this run are 2 Ps "a descriptor read only as data" and 1 Cs "a wave sum of 16-bit floats", none of them this PR's.

Not tested: a scene that binds these programs; a visual check of the sampled result.

AI use: Claude Code (Claude Opus 5.5) built the PR, ran the tests and the translation on my machine, and wrote this comment.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7153584950 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/25#issuecomment-7153584950). Originally posted by [nuiiv](https://github.com/nuiiv) on 2026-11-25T05:14:45Z. --- Test run of this PR on **AMD RDNA 2** (merged onto current `main` `310c6eb`, clean merge). **Setup** - AMD Radeon RX 6650 XT, driver 32.0.21045.29003; Ryzen 5 7500F, 16 GB; Windows 11 Pro 26300; rustc 1.98.1, release build. - Validator: `dxil.dll` from Windows SDK 10.0.26100.0. **Results** - The 40 programs that failed with `a descriptor chosen by control flow` (selected with `VICTORY_TRANSLATE_ONLY`), `translate --validate --pipelines`: **40 of 40 translate, 40 validate, 40 host pipelines created** on the card (37 Ps, 3 Ms). - `immediate_sampler_chosen_by_control_flow` passes on the **RX 6650 XT hardware device and WARP** (neither was skipped). **A possibly simpler alternative, for what it is worth** Independently, I tried picking the sampler by number instead of branching at the sample site: a uniform `i32` phi of the immediate sampler numbers at the join, then one `createHandleFromBinding` over the range `s<lo>..s<hi>` of the pipeline's static samplers, indexed by that phi (like `s[i]` of a `SamplerState s[]`). On this machine, for the same 40 programs, that form also passed `dxil.dll` 10.0.26100 and the driver created all 40 pipelines. A full `translate --pipelines` over the title showed 40 gained and none lost. I have only tested it on this one AMD card, so the "rejected by D3D12" case in the description may be NVIDIA-specific or about a different binding shape. I'm only mentioning it as an option, not asking for a change. **In the title** with this PR (own 1.0.2.1, Series X, fresh shader cache, about 5 minutes into the prologue, full log kept): no device removal, no error. **None of the 40 programs was bound**: the log has a `shader translated` line for every program used, and none of the 40 hashes is among them (the runtime and offline hashes match; checked with the programs that do fail). That is the same as the RTX 4070 run above. World frames averaged 1.7 fps, 3,883 draws/frame. The programs that failed in this run are 2 Ps "a descriptor read only as data" and 1 Cs "a wave sum of 16-bit floats", none of them this PR's. **Not tested:** a scene that binds these programs; a visual check of the sampled result. AI use: Claude Code (Claude Opus 5.5) built the PR, ran the tests and the translation on my machine, and wrote this comment.
JRamos1993 commented 2026-11-25 07:06:14 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by JRamos1993 on 2026-11-25T06:08:54Z.


Offline check on the retail shader pack: this PR, merged onto current main 310c6eb, fixes all 40 "descriptor chosen by control flow" programs, loses none, and changes nothing else.

Setup: RTX 5090, Windows 11. victory translate --validate --list over the title's full shader pack (26,084 programs), with a local DXIL hash on each validated line.

main 310c6eb + this PR
validated 25,382 25,422 (+37 Ps, +3 Ms)
lost 0
DXIL changed among programs validating on both 0
  • Branch: it is 10 commits behind main, and it still merges cleanly.
  • Duplicate closed: I had opened #718 for the same 40 programs without seeing this PR, and closed it. This one is the better fix (one sample through the chosen sampler).

AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.

<!-- greyfinch-sync:fxceless/victory-fork:comment:7154491418 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/25#issuecomment-7154491418). Originally posted by [JRamos1993](https://github.com/JRamos1993) on 2026-11-25T06:08:54Z. --- **Offline check on the retail shader pack: this PR, merged onto current `main` `310c6eb`, fixes all 40 "descriptor chosen by control flow" programs, loses none, and changes nothing else.** **Setup:** RTX 5090, Windows 11. `victory translate --validate --list` over the title's full shader pack (26,084 programs), with a local DXIL hash on each validated line. | | `main` `310c6eb` | + this PR | |---|---|---| | validated | 25,382 | **25,422** (+37 Ps, +3 Ms) | | lost | | 0 | | DXIL changed among programs validating on both | | 0 | - **Branch:** it is 10 commits behind `main`, and it still merges cleanly. - **Duplicate closed:** I had opened #718 for the same 40 programs without seeing this PR, and closed it. This one is the better fix (one sample through the chosen sampler). AI use: Claude Code with Claude Opus 5.5 ran the pack and wrote this. Nothing from the title is in it.
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/25:upstream-pr/25'
git switch 'upstream-pr/25'

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