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

Open
fuzeofficlal wants to merge 2 commits from upstream-pr/3117 into main
fuzeofficlal commented 2026-11-26 08:43:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T08:43:04Z.


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.
<!-- greyfinch-sync:Marvisak/VIctory:issue:6622826761 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3117). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T08:43:04Z. --- ## 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.
Dukestar69 commented 2026-11-26 08:50:05 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T08:50:05Z.

Review: APPROVED


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).

<!-- greyfinch-sync:Marvisak/VIctory:review:6070973658 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3117#pullrequestreview-6070973658). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T08:50:05Z. **Review:** APPROVED --- 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).
Marvisak commented 2026-11-26 10:05:04 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-26T09:19:03Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7187774902 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3117#issuecomment-7187774902). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-26T09:19:03Z. --- <!-- 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)_
fuzeofficlal commented 2026-11-26 16:41:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-26T16:41:12Z.


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).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7197966276 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3117#issuecomment-7197966276). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-26T16:41:12Z. --- 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 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/3117:upstream-pr/3117'
git switch 'upstream-pr/3117'

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