Shaders: omit DXIL selects with identical values #3796

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3796 into main
andrewpozdnakov7-jpg commented 2026-11-28 21:32:03 +00:00 (Migrated from github.com)

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


Return the shared value directly when the two arms of a DXIL select are the same IR value. The existing liveness pass can then drop calculations used only by that condition. The bitcode regression checks that a discarded 64-bit comparison stops contributing the integer-width flag. A select between distinct values keeps the comparison live.

A generated compute shader selected the same register on both sides of a dynamic comparison. Its DXIL size fell from 2,052 to 1,984 bytes. The distinct-register control remained at 2,052 bytes. Both versions returned the expected words for all 32 WARP readbacks per build, including inputs yielding both comparison results. Both shaders passed Microsoft's signed DXIL validator. The two existing select semantics tests also passed on app-local WARP 1.0.22 with Agility 1.620.2.

The focused bitcode tests, both strict shader Clippy configurations 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:5544768725 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3796). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T21:32:03Z. --- Return the shared value directly when the two arms of a DXIL select are the same IR value. The existing liveness pass can then drop calculations used only by that condition. The bitcode regression checks that a discarded 64-bit comparison stops contributing the integer-width flag. A select between distinct values keeps the comparison live. A generated compute shader selected the same register on both sides of a dynamic comparison. Its DXIL size fell from 2,052 to 1,984 bytes. The distinct-register control remained at 2,052 bytes. Both versions returned the expected words for all 32 WARP readbacks per build, including inputs yielding both comparison results. Both shaders passed Microsoft's signed DXIL validator. The two existing select semantics tests also passed on app-local WARP 1.0.22 with Agility 1.620.2. The focused bitcode tests, both strict shader Clippy configurations 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 21:34:51 +00:00 (Migrated from github.com)

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


Windows CI passed on d8dba2c, including both Clippy configurations and the workspace tests. The new bitcode regression checks that the comparison stays live with two distinct values and becomes dead with the same value. The signed WARP fixture returned all 32 expected words per build. The matching-value shader became 68 bytes smaller. The distinct-value control stayed at 2,052 bytes.

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:7246121646 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3796#issuecomment-7246121646). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T21:34:51Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46192075136/job/141124926635) passed on d8dba2c, including both Clippy configurations and the workspace tests. The new bitcode regression checks that the comparison stays live with two distinct values and becomes dead with the same value. The signed WARP fixture returned all 32 expected words per build. The matching-value shader became 68 bytes smaller. The distinct-value control stayed at 2,052 bytes. 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.
andrewpozdnakov7-jpg commented 2026-11-28 21:42:42 +00:00 (Migrated from github.com)

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


I tested #3796 together with #3791 and #3792. 9e9ea39 resolves the overlapping bitcode tests and retains the identical-select and live-i64 regressions. Both exercise the shared plan_with_uses entry point.

I built main 63bcca4, exact #3796 head d8dba2c, and the combined branch on Windows. In each build the two generated shaders produced all 32 expected readbacks on WARP 1.0.22 with Agility 1.620.2. Both containers on the combined branch are byte-identical to #3796 and pass Microsoft's DXIL validator 1.9.2609.5. The identical-select container is 1,984 bytes versus 2,052 on main. The distinct-select control is 2,052 bytes and byte-identical across all three builds.

All 15 active bitcode tests and all three select tests passed on the combined branch. Strict Clippy passed with default features and all features, as did the asset policy check.

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

AI-assisted with OpenAI Codex.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7246215757 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3796#issuecomment-7246215757). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T21:42:42Z. --- I tested #3796 together with #3791 and #3792. [`9e9ea39`](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/9e9ea39aca7f8740939feef18a1222d324499f58) resolves the overlapping bitcode tests and retains the identical-select and live-i64 regressions. Both exercise the shared `plan_with_uses` entry point. I built main `63bcca4`, exact #3796 head `d8dba2c`, and the combined branch on Windows. In each build the two generated shaders produced all 32 expected readbacks on WARP 1.0.22 with Agility 1.620.2. Both containers on the combined branch are byte-identical to #3796 and pass Microsoft's DXIL validator 1.9.2609.5. The identical-select container is 1,984 bytes versus 2,052 on main. The distinct-select control is 2,052 bytes and byte-identical across all three builds. All 15 active bitcode tests and all three select tests passed on the combined branch. Strict Clippy passed with default features and all features, as did the asset policy check. [Integration branch](https://github.com/andrewpozdnakov7-jpg/VIctory/tree/review/3791-3792-3796-dxil-plan). Please retain the Git authors on cherry-pick or rebase, or add `Co-authored-by: andrewpozdnakov7-jpg <[email protected]>` if folding these changes into another commit. AI-assisted with OpenAI Codex.
cloph-dsp commented 2026-11-28 22:58:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-28T22:58:35Z.


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

  • PR #3796 at head d8dba2ceded4705925b92563dec4053503cd0198, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::bitcode::tests::same_select_operands_do_not_keep_the_condition_live --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 HEAD^ HEAD clean (1 file, +24/-0).
  • 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 shader bitcode test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247111724 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3796#issuecomment-7247111724). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T22:58:35Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3796 at head `d8dba2ceded4705925b92563dec4053503cd0198`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-shader --lib -- emit::bitcode::tests::same_select_operands_do_not_keep_the_condition_live --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 HEAD^ HEAD` clean (1 file, +24/-0). - 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 shader bitcode test). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
ColorMeBoom commented 2026-11-28 23:38:00 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by ColorMeBoom on 2026-11-28T23:38:00Z.


Full victory-shader --lib --features host on AMD hardware: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head d8dba2ced on 63bcca4: 303 passed; 0 failed; 3 ignored. That suite includes the GPU semantics tests, which run on the hardware adapter and WARP in turn. I didn't check which of them reach the changed code. The new same_select_operands_do_not_keep_the_condition_live passes; it runs on the CPU.

AI use: Claude Code (Claude Opus 5.5).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7247560630 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3796#issuecomment-7247560630). Originally posted by [ColorMeBoom](https://github.com/ColorMeBoom) on 2026-11-28T23:38:00Z. --- Full `victory-shader --lib --features host` on AMD hardware: RX 5700 XT (Navi 10, RDNA1, driver 32.0.21045.29003, Windows 11 26200), head `d8dba2ced` on `63bcca4`: 303 passed; 0 failed; 3 ignored. That suite includes the GPU semantics tests, which run on the hardware adapter and WARP in turn. I didn't check which of them reach the changed code. The new `same_select_operands_do_not_keep_the_condition_live` passes; it runs on the CPU. AI use: Claude Code (Claude Opus 5.5).
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/3796:upstream-pr/3796'
git switch 'upstream-pr/3796'

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