shader: lower nested control-flow descriptors and immediate sampler phis #739

Open
github-bot wants to merge 3 commits from github-bot/gh-739 into main AGit
Owner

@⁠powplusplus on GitHub · 2026-11-25 06:06 UTC · original
powplusplus:shader/control-flow-descriptors → main · +608 −250 · 2 files · 3 commits · open

Summary

Eliminates all 40 remaining emit: a descriptor chosen by control flow failures across shaders.rpf (reaching 100% of mesh shaders emitted):

  1. Dead incoming edge pruning on phi fallback (resource::Tracer::phi):
    • Keeps the happy path zero-overhead when all predecessors classify cleanly.
    • When classifying all predecessors fails, prunes provably dead acyclic incoming edges via Tracer::meet, storing None for dead edges in Source::Phi { block, args: Vec<Option<Source>> } and unwrapping a single live Constant or non-dynamic Built source directly.
  2. Arbitrary nested uniform Phi / Select descriptors (emit/lower.rs):
    • Replaces the depth-limited descriptor_phi helper with uniform_heap_index, handling arbitrarily nested Source::Phi and Source::Select over heap-indexed descriptors.
    • Adds const_sampler_choice and const_sampler_index to dispatch image sampling and calculateLOD across distinct immediate constant samplers chosen by control flow (Phi / Select).

Verification

  • Unit tests: cargo test -p victory-shader --lib (173 passed, 0 failed, including new dead_incoming_phi_edge_is_skipped_for_scalar_descriptor and descriptor_chosen_by_control_flow_and_constant_sampler_phi_lower tests).
  • Windows-target clippy (victory-shader -- -D warnings) and workspace check clean on 8dd30ab.
  • Full shaders.rpf census (26,084 programs):
    • VS+PS: 14,164 -> 14,201 / 14,247 (+37, 0 lost)
    • MS: 8,762 -> 8,765 / 8,765 (+3, 100% of mesh programs emitted)
    • CS: 2,672 -> 2,672 / 2,682 (0 lost)
    • emit: a descriptor chosen by control flow: 40 -> 0
**@⁠powplusplus** on GitHub · 2026-11-25 06:06 UTC · [original](https://github.com/fxceless/victory-fork/pull/739) `powplusplus:shader/control-flow-descriptors` → `main` · +608 −250 · 2 files · 3 commits · open ## Summary Eliminates all 40 remaining `emit: a descriptor chosen by control flow` failures across `shaders.rpf` (reaching 100% of mesh shaders emitted): 1. **Dead incoming edge pruning on phi fallback (`resource::Tracer::phi`)**: - Keeps the happy path zero-overhead when all predecessors classify cleanly. - When classifying all predecessors fails, prunes provably dead acyclic incoming edges via `Tracer::meet`, storing `None` for dead edges in `Source::Phi { block, args: Vec<Option<Source>> }` and unwrapping a single live `Constant` or non-dynamic `Built` source directly. 2. **Arbitrary nested uniform `Phi` / `Select` descriptors (`emit/lower.rs`)**: - Replaces the depth-limited `descriptor_phi` helper with `uniform_heap_index`, handling arbitrarily nested `Source::Phi` and `Source::Select` over heap-indexed descriptors. - Adds `const_sampler_choice` and `const_sampler_index` to dispatch image sampling and `calculateLOD` across distinct immediate constant samplers chosen by control flow (`Phi` / `Select`). ## Verification - Unit tests: `cargo test -p victory-shader --lib` (173 passed, 0 failed, including new `dead_incoming_phi_edge_is_skipped_for_scalar_descriptor` and `descriptor_chosen_by_control_flow_and_constant_sampler_phi_lower` tests). - Windows-target clippy (`victory-shader -- -D warnings`) and workspace check clean on `8dd30ab`. - Full `shaders.rpf` census (26,084 programs): - VS+PS: `14,164 -> 14,201 / 14,247` (+37, 0 lost) - MS: `8,762 -> 8,765 / 8,765` (+3, **100%** of mesh programs emitted) - CS: `2,672 -> 2,672 / 2,682` (0 lost) - `emit: a descriptor chosen by control flow`: `40 -> 0`
Handle arbitrary combinations of Source::Phi and Source::Select for both
uniform heap-indexed descriptors and immediate constant samplers:

- In resource::Tracer::phi, when classifying all predecessors fails,
  prune provably dead incoming edges with Tracer::meet so dead edges
  become None in Source::Phi (while unwrapping single live constant or
  root-descriptor edges).
- In emit::lower, replace descriptor_phi with uniform_heap_index for
  arbitrary nested Phi/Select over heap descriptors, and add
  const_sampler_choice/const_sampler_index to dispatch image sampling
  and LOD calculation across distinct immediate constant samplers chosen
  by control flow.

Archive census on shaders.rpf: +37 VS+PS (14,164 -> 14,201 / 14,247),
+3 MS (8,762 -> 8,765 / 8,765, 100%), reducing 'a descriptor chosen by
control flow' from 40 to 0 with 0 regressions.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:50:00 +00:00
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 06:07 UTC · original · edited 2026-11-25 06:19 UTC

Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T06:19:11.016473Z 49bb897 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review" or "@⁠codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 06:07 UTC · [original](https://github.com/fxceless/victory-fork/pull/739#issuecomment-7154459528) · edited 2026-11-25 06:19 UTC <!-- codex-pull-request-review-summary --> <!-- codex-review-state:v1 {"code_review":{"commit_sha":"49bb8979678e1d533e855432eeb2d6a711b63eec","has_any_findings":true,"has_unresolved_findings":true,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} --> <details> <summary><strong>Codex Review Summary</strong>: ✅ Completed</summary> This comment shows the latest Codex review activity on this pull request. | Review | Status | Commit | Review trigger | | --- | --- | --- | --- | | 📝 **Code Review** | ✅ **Completed** <relative-time datetime="2026-11-25T06:19:11.016473Z">2026-11-25T06:19:11.016473Z</relative-time> | `49bb897` | PR opened | <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review" or "@⁠codex security review". Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. </details> </details>
Author
Owner

@⁠Flyander on GitHub · 2026-11-25 06:55 UTC · original

I reproduced both P1 cases on this head and opened a focused follow-up against this feature branch: https://github.com/powplusplus/victory-fork/pull/1

It restores the safe direct Loaded source for a one-live-edge ResourceHeap phi and hoists matching join-local sampler selects so their SCC is only used after the join. The sampler regression test panicked with forward reference outside a phi before the fix and now passes; the generated pipeline also creates on the RTX 5070 Ti.

Validation on the follow-up: shader lib tests 216 passed, 0 failed, 3 ignored; Clippy is clean. WARP still rejects this synthetic pipeline with E_INVALIDARG; that limitation is recorded in the follow-up description.

**@⁠Flyander** on GitHub · 2026-11-25 06:55 UTC · [original](https://github.com/fxceless/victory-fork/pull/739#issuecomment-7155303217) I reproduced both P1 cases on this head and opened a focused follow-up against this feature branch: https://github.com/powplusplus/victory-fork/pull/1 It restores the safe direct `Loaded` source for a one-live-edge `ResourceHeap` phi and hoists matching join-local sampler selects so their SCC is only used after the join. The sampler regression test panicked with `forward reference outside a phi` before the fix and now passes; the generated pipeline also creates on the RTX 5070 Ti. Validation on the follow-up: shader lib tests 216 passed, 0 failed, 3 ignored; Clippy is clean. WARP still rejects this synthetic pipeline with `E_INVALIDARG`; that limitation is recorded in the follow-up description.
Author
Owner

@⁠MKmajster on GitHub · 2026-11-25 11:53 UTC · original

Tested on a combined tree, offline: it clears the whole "descriptor chosen by control flow" class there. Two spots need care if this lands together with #353 or #386.

Tree. skornuta/victory-fork main (this repo's 310c6eb plus ZSlayerHQ next), with the LooperSalty/victory lot that carries #353 and #386, plus #188, #258 and #806 of this repo, then this PR (49bb897).

Offline, victory translate --list over the title's shader pack (26,084 programs, all reach IR; counts are refusals at emission). "Before" is the tree without #806, this PR and #215; "after" has all three, so the split per PR is my reading of the reasons, not measured one by one:

Reason Before After
a descriptor chosen by control flow 40 0
a hardware SGPR input (#215) 10 0
everything else 203 203

cargo test -p victory-shader --lib: 238 passed, 0 failed, 3 ignored (235 on the tree before the three PRs).

Two conflicts, and how I resolved them:

  1. sampler_slot. This PR's version keeps one static sampler per set of words and makes it a comparison sampler if any use compares. #386 (in the LooperSalty lot) gives a sampler used both ways two slots, because the DXIL validator wants the kinds to match, and changes samplers to (words, comparison) pairs. I kept your call sites and moved #386's two-slot logic into sampler_slot, including the cmp_samplers bit being cleared for the non-comparison slot.
  2. sampleLevel LOD from texels. This PR computes Log(texels) * LOG2_E, as main does today. #353 changes that line to Log(texels) alone, because DXIL Log (opcode 23) is already base 2. On the merged tree I kept #353's version inside this PR's new tail_args structure. Whichever of the two lands second will hit this line.

Not verified: a game run with this tree. The numbers above are the offline pack and the unit tests only.

AI-assisted (Claude Code). No game data attached.

**@⁠MKmajster** on GitHub · 2026-11-25 11:53 UTC · [original](https://github.com/fxceless/victory-fork/pull/739#issuecomment-7161634876) Tested on a combined tree, offline: it clears the whole "descriptor chosen by control flow" class there. Two spots need care if this lands together with #353 or #386. **Tree.** `skornuta/victory-fork` `main` (this repo's `310c6eb` plus ZSlayerHQ `next`), with the LooperSalty/victory lot that carries #353 and #386, plus #188, #258 and #806 of this repo, then this PR (`49bb897`). **Offline, `victory translate --list` over the title's shader pack** (26,084 programs, all reach IR; counts are refusals at emission). "Before" is the tree without #806, this PR and #215; "after" has all three, so the split per PR is my reading of the reasons, not measured one by one: | Reason | Before | After | |---|---|---| | a descriptor chosen by control flow | 40 | 0 | | a hardware SGPR input (#215) | 10 | 0 | | everything else | 203 | 203 | `cargo test -p victory-shader --lib`: 238 passed, 0 failed, 3 ignored (235 on the tree before the three PRs). **Two conflicts, and how I resolved them:** 1. **`sampler_slot`.** This PR's version keeps one static sampler per set of words and makes it a comparison sampler if any use compares. #386 (in the LooperSalty lot) gives a sampler used both ways two slots, because the DXIL validator wants the kinds to match, and changes `samplers` to `(words, comparison)` pairs. I kept your call sites and moved #386's two-slot logic into `sampler_slot`, including the `cmp_samplers` bit being cleared for the non-comparison slot. 2. **`sampleLevel` LOD from `texels`.** This PR computes `Log(texels) * LOG2_E`, as `main` does today. #353 changes that line to `Log(texels)` alone, because DXIL `Log` (opcode 23) is already base 2. On the merged tree I kept #353's version inside this PR's new `tail_args` structure. Whichever of the two lands second will hit this line. Not verified: a game run with this tree. The numbers above are the offline pack and the unit tests only. AI-assisted (Claude Code). No game data attached.
@ -1345,0 +1361,4 @@
| Source::Built {
address: Address { dynamic: None, .. },
..
}
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 06:19 UTC · original

P1 Badge Preserve direct loaded sources when only one phi edge is live

For a statically addressed ResourceHeap descriptor with one live edge and a non-descriptor on a dead EXECZ skip edge, the old anywhere() fallback returned Source::Loaded directly. This whitelist instead leaves the load inside a one-live-arm Source::Phi, but slot_stride() returns None for phis. Consequently, smem() loses its stride-based SRV/CBV dispatch and unconditionally annotates the heap entry as a CBV and calls cbufferLoadLegacy, even when the entry is a buffer SRV. This breaks previously supported buffer reads. Preserve the safe direct-loaded case, or make the stride/type lookup follow the new phi.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 06:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/739#discussion_r4691133500) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Preserve direct loaded sources when only one phi edge is live** For a statically addressed `ResourceHeap` descriptor with one live edge and a non-descriptor on a dead EXECZ skip edge, the old `anywhere()` fallback returned `Source::Loaded` directly. This whitelist instead leaves the load inside a one-live-arm `Source::Phi`, but `slot_stride()` returns `None` for phis. Consequently, `smem()` loses its stride-based SRV/CBV dispatch and unconditionally annotates the heap entry as a CBV and calls `cbufferLoadLegacy`, even when the entry is a buffer SRV. This breaks previously supported buffer reads. Preserve the safe direct-loaded case, or make the stride/type lookup follow the new phi. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
@ -6099,0 +6228,4 @@
let idx = match arg {
Some(arg) => {
let here = std::mem::replace(&mut self.cur, at);
let idx = self.const_sampler_index(arg, cmp, slots);
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 06:19 UTC · original

P1 Badge Keep nested sampler selects below their SCC definition

When one immediate-sampler word comes from a control-flow phi and another is chosen by s_cselect after that join, Tracer::phi() produces phi arguments containing selects whose SCC is defined in the join block. Switching self.cur to the predecessor here emits those selects before their SCC definition, violating dominance. A two-arm sampler phi followed by a join-local compare/select and image_sample_lz reproduces a panic in Module::write() with forward reference outside a phi; the parent returned an unsupported-translation error instead. Factor post-join selects outside the phi, or otherwise ensure their conditions dominate the insertion block.

Useful? React with 👍 / 👎.

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 06:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/739#discussion_r4691133511) **<sub><sub>![P1 Badge](https://img.shields.io/badge/P1-orange?style=flat)</sub></sub> Keep nested sampler selects below their SCC definition** When one immediate-sampler word comes from a control-flow phi and another is chosen by `s_cselect` after that join, `Tracer::phi()` produces phi arguments containing selects whose SCC is defined in the join block. Switching `self.cur` to the predecessor here emits those selects before their SCC definition, violating dominance. A two-arm sampler phi followed by a join-local compare/select and `image_sample_lz` reproduces a panic in `Module::write()` with `forward reference outside a phi`; the parent returned an unsupported-translation error instead. Factor post-join selects outside the phi, or otherwise ensure their conditions dominate the insertion block. Useful? React with 👍 / 👎. <!-- codex-code-review-finding:v1 -->
Author
Owner

@⁠Flyander on GitHub · 2026-11-25 06:16 UTC · original · reviewed

I locally added the sampler-choice GPU regression from #718 to this branch and ran it on the RTX 5070 Ti and WARP. The selected wrap/clamp sampler produced the expected texel in both cases. With that test registered, cargo test -p victory-shader --lib --locked --no-fail-fast -- --test-threads=4 passed (217 passed, 0 failed, 3 ignored), and cargo clippy -p victory-shader --all-targets --locked -- -D warnings was clean.

The current descriptor_chosen_by_control_flow_and_constant_sampler_phi_lower test checks emission, while this render test checks the result reaches the target correctly. I recommend keeping that coverage with this implementation, since #739 is the path replacing #718. In a separate local experiment, merging dx.types.ResRet as an aggregate phi caused WARP to remove the device (0x887A0005); the per-channel f32 merges in this branch passed.

**@⁠Flyander** on GitHub · 2026-11-25 06:16 UTC · [original](https://github.com/fxceless/victory-fork/pull/739#pullrequestreview-6052719208) · **reviewed** I locally added the sampler-choice GPU regression from #718 to this branch and ran it on the RTX 5070 Ti and WARP. The selected wrap/clamp sampler produced the expected texel in both cases. With that test registered, `cargo test -p victory-shader --lib --locked --no-fail-fast -- --test-threads=4` passed (217 passed, 0 failed, 3 ignored), and `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` was clean. The current `descriptor_chosen_by_control_flow_and_constant_sampler_phi_lower` test checks emission, while this render test checks the result reaches the target correctly. I recommend keeping that coverage with this implementation, since #739 is the path replacing #718. In a separate local experiment, merging `dx.types.ResRet` as an aggregate phi caused WARP to remove the device (`0x887A0005`); the per-channel `f32` merges in this branch passed.
Author
Owner

@⁠chatgpt-codex-connector[bot] on GitHub · 2026-11-25 06:19 UTC · original · reviewed

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 49bb897967

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@⁠codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback".

**@⁠chatgpt-codex-connector[bot]** on GitHub · 2026-11-25 06:19 UTC · [original](https://github.com/fxceless/victory-fork/pull/739#pullrequestreview-6052745051) · **reviewed** <!-- codex-review-receipt:v1 --> ### 💡 Codex Review Here are some automated review suggestions for this pull request. **Reviewed commit:** `49bb897967` <details> <summary>ℹ️ About Codex in GitHub</summary> <br/> [Your team has set up Codex to review pull requests in this repo](https://chatgpt.com/codex/cloud/settings/general). Reviews are triggered when you - Open a pull request for review - Mark a draft as ready - Comment "@⁠codex review". If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@⁠codex address that feedback". </details>
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/lower.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/739/head:github-bot/gh-739'
git switch 'github-bot/gh-739'

Merge

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