Shaders: support multi-way and nested immediate sampler phis #3117

Open
github-bot wants to merge 2 commits from github-bot/gh-3117 into main AGit
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 08:43 UTC · original
fuzeofficlal:feat/shader-multi-way-nested-sampler-phi → main · +421 −133 · 6 files · 2 commits · open

Summary

  • Generalize immediate sampler Source::Phi lowering in crates/victory-shader/src/emit/lower.rs beyond flat two-way [Constant, Constant] pairs to arbitrary multi-way and nested Source::Phi graphs, with cycle protection (active visited set), never_taken edge handling, and comparison-mode (cmp_samplers) preservation.
  • Plan the selector tree before mutating self.samplers or emitting IR so mixed (non-constant) Source::Phi graphs fall back cleanly to the existing heap-index path without side effects.
  • Collapse single unique sampler targets directly to that static sampler handle (zero selector phi); for 2+ unique samplers, emit an i32 selector phi and dispatch via generalized Shader::sampler_choices, Module::chosen, and Module::select_indexed (preserving per-field extract selection on dx.types.ResRet.f32).
  • Add synthetic GPU + WARP end-to-end tests in crates/victory-shader/src/emit/stride_tests.rs covering a 3-way flat immediate sampler phi and a nested immediate sampler phi exercising both regular and comparison sampling.

Verification

  • cargo test -p victory-shader --locked -- sampler --test-threads=1 (RTX 5090 hardware + WARP): 11 passed, 0 failed.
  • VICTORY_WARP=1 cargo test -p victory-shader --locked -- sampler --test-threads=1: 11 passed, 0 failed.
  • cargo test -p victory-shader --locked -- emit::lower::: 33 passed, 0 failed.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean.
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean.
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed, 0 failed.
**@⁠fuzeofficlal** on GitHub · 2026-11-26 08:43 UTC · [original](https://github.com/Marvisak/VIctory/pull/3117) `fuzeofficlal:feat/shader-multi-way-nested-sampler-phi` → `main` · +421 −133 · 6 files · 2 commits · open ## Summary - Generalize immediate sampler `Source::Phi` lowering in `crates/victory-shader/src/emit/lower.rs` beyond flat two-way `[Constant, Constant]` pairs to arbitrary multi-way and nested `Source::Phi` graphs, with cycle protection (`active` visited set), `never_taken` edge handling, and comparison-mode (`cmp_samplers`) preservation. - Plan the selector tree before mutating `self.samplers` or emitting IR so mixed (non-constant) `Source::Phi` graphs fall back cleanly to the existing heap-index path without side effects. - Collapse single unique sampler targets directly to that static sampler handle (zero selector phi); for 2+ unique samplers, emit an `i32` selector phi and dispatch via generalized `Shader::sampler_choices`, `Module::chosen`, and `Module::select_indexed` (preserving per-field `extract` selection on `dx.types.ResRet.f32`). - Add synthetic GPU + WARP end-to-end tests in `crates/victory-shader/src/emit/stride_tests.rs` covering a 3-way flat immediate sampler phi and a nested immediate sampler phi exercising both regular and comparison sampling. ## Verification - `cargo test -p victory-shader --locked -- sampler --test-threads=1` (RTX 5090 hardware + WARP): 11 passed, 0 failed. - `VICTORY_WARP=1 cargo test -p victory-shader --locked -- sampler --test-threads=1`: 11 passed, 0 failed. - `cargo test -p victory-shader --locked -- emit::lower::`: 33 passed, 0 failed. - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean. - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean. - `cargo test -p xtask --locked policy::tests::repository_passes_policy`: 1 passed, 0 failed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 08:46:36 +00:00
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 08:50 UTC · original · approved these changes

Verified on RTX 5090 & WARP against origin/main (63bcca4):

  • cargo test -p victory-shader --lib emit::stride_tests:: -- --test-threads=1:
    • All 3 sampler-phi tests (a_flat_sampler_phi_selects_among_three_static_samplers, a_nested_sampler_phi_selects_regular_and_comparison_samplers, a_sampler_chosen_by_a_uniform_branch_samples_as_chosen) passed on both RTX 5090 and WARP.
    • 10/10 passed under VICTORY_WARP=1; on RTX 5090, the only 2 failures (a_heap_buffer_read_by_element_takes_the_views_stride, a_heap_buffer_read_where_no_buffer_view_is_reads_zeros) reproduce identically on clean origin/main.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly generalizes immediate sampler phis to multi-way and nested phis across both regular and comparison samplers.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

**@⁠Dukestar69** on GitHub · 2026-11-26 08:50 UTC · [original](https://github.com/Marvisak/VIctory/pull/3117#pullrequestreview-6070973658) · **approved these changes** Verified on RTX 5090 & WARP against `origin/main` (`63bcca4`): - `cargo test -p victory-shader --lib emit::stride_tests:: -- --test-threads=1`: - All 3 sampler-phi tests (`a_flat_sampler_phi_selects_among_three_static_samplers`, `a_nested_sampler_phi_selects_regular_and_comparison_samplers`, `a_sampler_chosen_by_a_uniform_branch_samples_as_chosen`) passed on both RTX 5090 and WARP. - 10/10 passed under `VICTORY_WARP=1`; on RTX 5090, the only 2 failures (`a_heap_buffer_read_by_element_takes_the_views_stride`, `a_heap_buffer_read_where_no_buffer_view_is_reads_zeros`) reproduce identically on clean `origin/main`. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 191 files ok. Cleanly generalizes immediate sampler phis to multi-way and nested phis across both regular and comparison samplers. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
Author
Owner

@⁠Marvisak on GitHub · 2026-11-26 09:19 UTC · original

Automated triage for the maintainers.

Needs work. This generalises immediate sampler phis from the two-constant case to multi-way and nested phis. Lower::sampler_selector and immediate_sampler_phi build an i32 selector phi, Shader::sampler_choices now holds a list, and Module::select_indexed/Module::extract pick the result. The lowering reads correctly: it plans before emitting, collapses when only one sampler is distinct, and pairs args with preds in order. Three things are needed first:

  1. Evidence of need. Name the programs in the title that have a three-way or nested immediate sampler phi, for example a translate --list count of the "descriptor chosen by control flow" refusals this removes.
  2. An unneeded guard. resource::Source is an owned tree, so a Source::Phi cannot contain itself. The active: HashSet<*const Source> cycle guard covers a case that cannot happen. Please drop it.
  3. Test size. stride_tests.rs adds a separate unsafe D3D12 host of about 400 lines (mod comparison) just for comparison sampling. Please extend the existing test host in emit/host.rs with an R32_FLOAT view instead, or test the comparison case at the lowering level.

CI: check passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-26 09:19 UTC · [original](https://github.com/Marvisak/VIctory/pull/3117#issuecomment-7187774902) <!-- victory-triage v1 head=aa2f2b214ac08c3179967a46df10016b130993bb verdict=needs-work at=2026-11-26T09:19:00Z --> Automated triage for the maintainers. **Needs work.** This generalises immediate sampler phis from the two-constant case to multi-way and nested phis. `Lower::sampler_selector` and `immediate_sampler_phi` build an i32 selector phi, `Shader::sampler_choices` now holds a list, and `Module::select_indexed`/`Module::extract` pick the result. The lowering reads correctly: it plans before emitting, collapses when only one sampler is distinct, and pairs args with `preds` in order. Three things are needed first: 1. **Evidence of need.** Name the programs in the title that have a three-way or nested immediate sampler phi, for example a `translate --list` count of the "descriptor chosen by control flow" refusals this removes. 2. **An unneeded guard.** `resource::Source` is an owned tree, so a `Source::Phi` cannot contain itself. The `active: HashSet<*const Source>` cycle guard covers a case that cannot happen. Please drop it. 3. **Test size.** `stride_tests.rs` adds a separate unsafe D3D12 host of about 400 lines (`mod comparison`) just for comparison sampling. Please extend the existing test host in `emit/host.rs` with an R32_FLOAT view instead, or test the comparison case at the lowering level. CI: `check` passing. --- _Generated by [Claude Code](https://claude.ai/code)_
Drop the unreachable active-pointer cycle set in Lower::sampler_selector (resource::Source is an owned tree).

Extend emit::host::View with an R32_FLOAT texture SRV (View::FloatTexture) and remove the standalone comparison D3D12 dispatch harness from stride_tests.rs so regular and comparison sampler-phi tests share Host::dispatch.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 16:41 UTC · original

Updated in 042b2906 to address points 2 and 3 from triage:

  • Removed the unreachable active: HashSet<*const Source> cycle guard in Lower::sampler_selector (resource::Source is an owned tree; emit/lower.rs is now 522,690 B).
  • Removed the standalone mod comparison D3D12 harness from emit/stride_tests.rs (-233 lines) and added a small View::FloatTexture (DXGI_FORMAT_R32_FLOAT) variant to emit/host.rs so both regular and comparison sampler-phi tests share Host::dispatch (11/11 sampler-phi tests passing on both RTX 5090 and WARP with dxil.dll).
**@⁠fuzeofficlal** on GitHub · 2026-11-26 16:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/3117#issuecomment-7197966276) Updated in `042b2906` to address points 2 and 3 from triage: - Removed the unreachable `active: HashSet<*const Source>` cycle guard in `Lower::sampler_selector` (`resource::Source` is an owned tree; `emit/lower.rs` is now `522,690` B). - Removed the standalone `mod comparison` D3D12 harness from `emit/stride_tests.rs` (-233 lines) and added a small `View::FloatTexture` (`DXGI_FORMAT_R32_FLOAT`) variant to `emit/host.rs` so both regular and comparison sampler-phi tests share `Host::dispatch` (11/11 sampler-phi tests passing on both RTX 5090 and WARP with `dxil.dll`).
This pull request can be merged automatically.
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/3117/head:github-bot/gh-3117'
git switch 'github-bot/gh-3117'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-3117'
git switch 'github-bot/gh-3117'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-3117'
git switch 'github-bot/gh-3117'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-3117'
git switch 'main'
git merge --squash 'github-bot/gh-3117'
git switch 'main'
git merge --ff-only 'github-bot/gh-3117'
git switch 'main'
git merge 'github-bot/gh-3117'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!3117
No description provided.