Shaders: fold selects with constant conditions #3747

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3747 into main
andrewpozdnakov7-jpg commented 2026-11-28 14:38:01 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T14:38:01Z.


When a DXIL select already has a known Boolean condition, use the chosen operand directly. This uses the same integer-constant interpretation as the control-flow builder. The existing liveness pass can then omit computations reachable only through the unused operand. Dynamic and undefined conditions still emit a select.

On Windows WARP with Agility 1.620.2, all 29,736 output words matched main and the expected values. The seven generated cases cover both constant conditions, source sign modifiers, an arithmetic input used only by the unchosen arm, a chain of 12 selects, and a dynamic condition.

DXIL probe Instructions on main This PR Module bytes
One constant-false select 37 34 2,320 to 2,308
Arithmetic used only by the unused arm 43 34 2,344 to 2,308
12 constant selects 50 34 2,392 to 2,316
Dynamic select 40 40 2,332 in both

The committed bitcode test covers true, false, and an undefined condition. The bitcode, lowerer and VALU tests, both select semantic tests, strict shader Clippy and the asset policy passed.

Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5541226170 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3747). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T14:38:01Z. --- When a DXIL select already has a known Boolean condition, use the chosen operand directly. This uses the same integer-constant interpretation as the control-flow builder. The existing liveness pass can then omit computations reachable only through the unused operand. Dynamic and undefined conditions still emit a select. On Windows WARP with Agility 1.620.2, all 29,736 output words matched main and the expected values. The seven generated cases cover both constant conditions, source sign modifiers, an arithmetic input used only by the unchosen arm, a chain of 12 selects, and a dynamic condition. | DXIL probe | Instructions on main | This PR | Module bytes | |---|---:|---:|---:| | One constant-false select | 37 | 34 | 2,320 to 2,308 | | Arithmetic used only by the unused arm | 43 | 34 | 2,344 to 2,308 | | 12 constant selects | 50 | 34 | 2,392 to 2,316 | | Dynamic select | 40 | 40 | 2,332 in both | The committed bitcode test covers true, false, and an undefined condition. The bitcode, lowerer and VALU tests, both select semantic tests, strict shader Clippy and the asset policy passed. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
andrewpozdnakov7-jpg commented 2026-11-28 14:41:40 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T14:41:40Z.


Windows CI passed on 981f8b2, including both Clippy configurations and the workspace tests. All 29,736 generated output words matched on Windows WARP. The 12-select probe went from 50 to 34 DXIL instructions, and the dynamic probe stayed at 40. The committed unit test verifies both constant choices and that an undefined condition still emits a select.

The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the change into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7240860806 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3747#issuecomment-7240860806). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T14:41:40Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46155670598/job/141011659098) passed on `981f8b2`, including both Clippy configurations and the workspace tests. All 29,736 generated output words matched on Windows WARP. The 12-select probe went from 50 to 34 DXIL instructions, and the dynamic probe stayed at 40. The committed unit test verifies both constant choices and that an undefined condition still emits a select. The next step is maintainer review. Please retain the Git author on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding the change into another commit. AI-assisted with OpenAI Codex.
cloph-dsp commented 2026-11-28 14:50:31 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-28T14:50:31Z.


Independent local verification (Windows, Rust 1.100.0/MSVC, no game data):

  • PR #3747 at head 981f8b277c79a0aa1731f97b06d01b299b5aaab1, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::bitcode::tests::a_constant_select_uses_only_the_chosen_value --exact --test-threads=1 --quiet → 1 passed, 0 failed, 305 filtered, exit 0.
  • git grep -F for the test name on the base returned no match (test is new on this PR); git diff --check 63bcca4 HEAD clean (1 file, +24).
  • Used a per-worktree CARGO_TARGET_DIR (never shared) with CARGO_BUILD_JOBS=2.
  • Only the named synthetic test was replayed; full workspace suite and clippy were not run locally.
  • GPU/driver: N/A (CPU-only bitcode IR test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7240975317 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3747#issuecomment-7240975317). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T14:50:31Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3747 at head `981f8b277c79a0aa1731f97b06d01b299b5aaab1`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-shader --lib -- emit::bitcode::tests::a_constant_select_uses_only_the_chosen_value --exact --test-threads=1 --quiet` → 1 passed, 0 failed, 305 filtered, exit 0. - `git grep -F` for the test name on the base returned no match (test is new on this PR); `git diff --check 63bcca4 HEAD` clean (1 file, +24). - Used a per-worktree `CARGO_TARGET_DIR` (never shared) with `CARGO_BUILD_JOBS=2`. - Only the named synthetic test was replayed; full workspace suite and clippy were not run locally. - GPU/driver: N/A (CPU-only bitcode IR test). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
andrewpozdnakov7-jpg commented 2026-11-28 21:36:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T21:36:12Z.


Combined 07afa54 keeps this PR at 981f8b2 and #3796 at d8dba2c as direct parents. It applies both folds in one place and associates the constant-branch test's documentation with that test.

The constant-condition and identical-value regressions both passed. The distinct-value dynamic control still emitted 2,052 bytes. The identical-value shader emitted 1,984 bytes. Across both fixtures, all 32 WARP readbacks matched the expected values. The two established select semantics tests also passed with signed app-local WARP and SDK DXIL validation. All 14 active bitcode tests, both strict shader Clippy configurations and the asset policy passed.

The combined branch is available for maintainer review. Please retain the Git authors on cherry-pick or rebase, or include Co-authored-by: andrewpozdnakov7-jpg [email protected] if folding the changes into another commit.

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7246138006 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3747#issuecomment-7246138006). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T21:36:12Z. --- [Combined 07afa54](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/07afa54df12dfaeb30193bd7489ce25497d6010f) keeps this PR at 981f8b2 and #3796 at d8dba2c as direct parents. It applies both folds in one place and associates the constant-branch test's documentation with that test. The constant-condition and identical-value regressions both passed. The distinct-value dynamic control still emitted 2,052 bytes. The identical-value shader emitted 1,984 bytes. Across both fixtures, all 32 WARP readbacks matched the expected values. The two established select semantics tests also passed with signed app-local WARP and SDK DXIL validation. All 14 active bitcode tests, both strict shader Clippy configurations and the asset policy passed. The combined branch is available for maintainer review. Please retain the Git authors on cherry-pick or rebase, or include Co-authored-by: andrewpozdnakov7-jpg <[email protected]> if folding the changes into another commit. AI-assisted with OpenAI Codex.
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/3747:upstream-pr/3747'
git switch 'upstream-pr/3747'

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