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

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

@⁠MartinIndra02 on GitHub · 2026-11-24 20:24 UTC · original
MartinIndra02:feat/fxceless-descriptor-phi → main · +381 −61 · 2 files · 1 commits · open

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.

**@⁠MartinIndra02** on GitHub · 2026-11-24 20:24 UTC · [original](https://github.com/fxceless/victory-fork/pull/25) `MartinIndra02:feat/fxceless-descriptor-phi` → `main` · +381 −61 · 2 files · 1 commits · open ## 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.*
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:34:50 +00:00
Author
Owner

@⁠adriaespii on GitHub · 2026-11-24 20:54 UTC · original

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.

**@⁠adriaespii** on GitHub · 2026-11-24 20:54 UTC · [original](https://github.com/fxceless/victory-fork/pull/25#issuecomment-7144219456) 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.*
Author
Owner

@⁠m335671 on GitHub · 2026-11-24 21:02 UTC · original

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.

**@⁠m335671** on GitHub · 2026-11-24 21:02 UTC · [original](https://github.com/fxceless/victory-fork/pull/25#issuecomment-7144390194) 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.
Author
Owner

@⁠arminkhaleghirod on GitHub · 2026-11-24 22:23 UTC · original

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.
**@⁠arminkhaleghirod** on GitHub · 2026-11-24 22:23 UTC · [original](https://github.com/fxceless/victory-fork/pull/25#issuecomment-7146177332) 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.
Author
Owner

@⁠nuiiv on GitHub · 2026-11-25 05:14 UTC · original

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.

**@⁠nuiiv** on GitHub · 2026-11-25 05:14 UTC · [original](https://github.com/fxceless/victory-fork/pull/25#issuecomment-7153584950) 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.
Author
Owner

@⁠JRamos1993 on GitHub · 2026-11-25 06:08 UTC · original

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.

**@⁠JRamos1993** on GitHub · 2026-11-25 06:08 UTC · [original](https://github.com/fxceless/victory-fork/pull/25#issuecomment-7154491418) **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 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/25/head:github-bot/gh-25'
git switch 'github-bot/gh-25'

Merge

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