Shaders: simplify f32 min and max with literal operands #3744

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

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


Resolve a known f32 operand's denormal handling during emission for min/max. A literal or a raw i32-to-f32 bitcast can supply its exact bits. A subnormal literal becomes a zero of the same sign. When a normalized literal has nonzero magnitude, the two operands cannot both be zero, so the result can use the ordinary DXIL min/max directly. The signed-zero rule still applies when both values can be zero. DXIL FMax and FMin semantics.

Generated compute shader DXIL instructions, main → change DXIL bytes, main → change
Max with a normal bound 58 → 43 2,516 → 2,452
Min with a negative-zero bound 58 → 51 2,508 → 2,492
Min with a subnormal bound 58 → 51 2,508 → 2,488
Max with two dynamic inputs 60 → 60 2,516 → 2,516

On Microsoft WARP 1.0.22 with Agility 1.620.2, both builds matched all 47,790 generated output words, including both argument orders, signed zeros, subnormals, infinities and NaNs. The existing min/max model and 13 bitcode tests passed, with the existing benchmark ignored. The new bitcode regression checks that numeric conversions and raw integer values are excluded from the literal lookup. Strict all-feature shader Clippy and the asset policy passed.

#3733 covers repeated flushing across three-way f32 selections. This change covers literal operands. Counts describe generated DXIL. Game performance was unmeasured.

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:5541016036 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3744). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T14:14:01Z. --- Resolve a known f32 operand's denormal handling during emission for min/max. A literal or a raw i32-to-f32 bitcast can supply its exact bits. A subnormal literal becomes a zero of the same sign. When a normalized literal has nonzero magnitude, the two operands cannot both be zero, so the result can use the ordinary DXIL min/max directly. The signed-zero rule still applies when both values can be zero. [DXIL FMax and FMin semantics](https://github.com/microsoft/DirectXShaderCompiler/blob/main/docs/DXIL.rst#fmax). | Generated compute shader | DXIL instructions, main → change | DXIL bytes, main → change | |---|---:|---:| | Max with a normal bound | 58 → 43 | 2,516 → 2,452 | | Min with a negative-zero bound | 58 → 51 | 2,508 → 2,492 | | Min with a subnormal bound | 58 → 51 | 2,508 → 2,488 | | Max with two dynamic inputs | 60 → 60 | 2,516 → 2,516 | On Microsoft WARP 1.0.22 with Agility 1.620.2, both builds matched all 47,790 generated output words, including both argument orders, signed zeros, subnormals, infinities and NaNs. The existing min/max model and 13 bitcode tests passed, with the existing benchmark ignored. The new bitcode regression checks that numeric conversions and raw integer values are excluded from the literal lookup. Strict all-feature shader Clippy and the asset policy passed. #3733 covers repeated flushing across three-way f32 selections. This change covers literal operands. Counts describe generated DXIL. Game performance was unmeasured. 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:18:13 +00:00 (Migrated from github.com)

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


Windows CI passed on 6f3fa6d, including both Clippy configurations and the workspace tests. The two-operand min/max comparison on WARP with Agility 1.620.2 matched all 47,790 output words with main, including literal NaNs, signed zeros, subnormals, infinities, both operand orders and a dynamic control. The ordinary literal max went from 58 to 43 DXIL instructions (2,516 to 2,452 bytes), and the negative-zero literal min went from 58 to 51 (2,508 to 2,492 bytes). The dynamic control stayed at 60 instructions and 2,516 bytes. The committed bitcode test verifies the literal representations used by the optimization.

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:7240568624 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3744#issuecomment-7240568624). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-28T14:18:13Z. --- [Windows CI](https://github.com/Marvisak/VIctory/actions/runs/46153598192/job/141005304275) passed on `6f3fa6d`, including both Clippy configurations and the workspace tests. The two-operand min/max comparison on WARP with Agility 1.620.2 matched all 47,790 output words with `main`, including literal NaNs, signed zeros, subnormals, infinities, both operand orders and a dynamic control. The ordinary literal max went from 58 to 43 DXIL instructions (2,516 to 2,452 bytes), and the negative-zero literal min went from 58 to 51 (2,508 to 2,492 bytes). The dynamic control stayed at 60 instructions and 2,516 bytes. The committed bitcode test verifies the literal representations used by the optimization. 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:21:42 +00:00 (Migrated from github.com)

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


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

  • PR #3744 at head 6f3fa6d3130fd08186761fb38fa4bd013a00048d, base/parent 63bcca43c6a00a758510398fa43096ce7e4f7df0.
  • cargo test --locked -p victory-shader --lib -- emit::bitcode::tests::f32_literal_bits_require_a_float_or_i32_bitcast --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 (2 files, +51/-1).
  • 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 test). No game data, assets, extracted shaders, DRM or decrypt involved.

AI-assisted (Hy4 flash).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7240611157 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/3744#issuecomment-7240611157). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-28T14:21:42Z. --- Independent local verification (Windows, Rust 1.100.0/MSVC, no game data): - PR #3744 at head `6f3fa6d3130fd08186761fb38fa4bd013a00048d`, base/parent `63bcca43c6a00a758510398fa43096ce7e4f7df0`. - `cargo test --locked -p victory-shader --lib -- emit::bitcode::tests::f32_literal_bits_require_a_float_or_i32_bitcast --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 (2 files, +51/-1). - 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 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/3744:upstream-pr/3744'
git switch 'upstream-pr/3744'

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