Shaders: fold inverse i32 and f32 bitcasts #3729

Open
andrewpozdnakov7-jpg wants to merge 1 commit from upstream-pr/3729 into main
andrewpozdnakov7-jpg commented 2026-11-28 12:22:51 +00:00 (Migrated from github.com)

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


When an i32/f32 bitcast immediately reverses a previous numeric bitcast, use the original value. If the intermediate value has no other readers, the existing liveness pass omits it. The regression covers both directions and an intermediate that still has a reader. LLVM bitcast semantics

On Windows WARP with Agility, three generated shaders matched their 256 expected output words each on both exact main and this change. The fixtures combine float additions with zero, one, or sixteen bitwise moves. DXC reports:

Fixture Instructions, main → proposed Bitcasts, main → proposed Bytes, main → proposed
16 consecutive float additions after initialization 72 → 52 22 → 2 2472 → 2384
One intervening bitwise move 44 → 37 9 → 2 2348 → 2320
16 intervening bitwise moves 104 → 52 54 → 2 2616 → 2384

These are emitted-code counts. Runtime GPU and title performance remain unmeasured. The bitcode suite passed 13 tests with one benchmark ignored. 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:5540078472 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3729). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T12:22:51Z. --- When an `i32`/`f32` bitcast immediately reverses a previous numeric bitcast, use the original value. If the intermediate value has no other readers, the existing liveness pass omits it. The regression covers both directions and an intermediate that still has a reader. [LLVM bitcast semantics](https://llvm.org/docs/LangRef.html#bitcast-to-instruction) On Windows WARP with Agility, three generated shaders matched their 256 expected output words each on both exact main and this change. The fixtures combine float additions with zero, one, or sixteen bitwise moves. DXC reports: | Fixture | Instructions, main → proposed | Bitcasts, main → proposed | Bytes, main → proposed | | --- | ---: | ---: | ---: | | 16 consecutive float additions after initialization | 72 → 52 | 22 → 2 | 2472 → 2384 | | One intervening bitwise move | 44 → 37 | 9 → 2 | 2348 → 2320 | | 16 intervening bitwise moves | 104 → 52 | 54 → 2 | 2616 → 2384 | These are emitted-code counts. Runtime GPU and title performance remain unmeasured. The bitcode suite passed 13 tests with one benchmark ignored. 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 12:26:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-28T12:26:52Z.


The exact 5f57f5e head passed Windows CI, including workspace tests and both Clippy configurations. The three generated programs matched all 768 expected output words on Windows WARP with Agility. The 16-move fixture emitted 52 instructions instead of 104, and its container shrank from 2,616 to 2,384 bytes.

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:7239233225 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3729#issuecomment-7239233225). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T12:26:52Z. --- The exact `5f57f5e` head passed [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46144371319/job/140977053242), including workspace tests and both Clippy configurations. The three generated programs matched all 768 expected output words on Windows WARP with Agility. The 16-move fixture emitted 52 instructions instead of 104, and its container shrank from 2,616 to 2,384 bytes. 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 12:37:07 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-28T12:37:07Z.


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

  • PR #3729 at head 5f57f5ebdf6423c99b3742dabdd0b33d10513883, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::bitcode::tests::inverse_i32_f32_bitcasts_reuse_the_original_values --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, +40/-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 IR/bitcode test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7239351221 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3729#issuecomment-7239351221). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T12:37:07Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3729 at head `5f57f5ebdf6423c99b3742dabdd0b33d10513883`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-shader --lib -- emit::bitcode::tests::inverse_i32_f32_bitcasts_reuse_the_original_values --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, +40/-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 IR/bitcode test). No game data, assets, extracted shaders, DRM or decrypt involved. AI-assisted (Hy4 flash).
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/3729:upstream-pr/3729'
git switch 'upstream-pr/3729'

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