Skip to content

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

Open
andrewpozdnakov7-jpg wants to merge 1 commit into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/literal-minmax-f32
Open

andrewpozdnakov7-jpg wants to merge 1 commit into
Marvisak:mainfrom
andrewpozdnakov7-jpg:codex2/literal-minmax-f32

Conversation

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor

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 <andrewpozdnakov7-jpg@users.noreply.github.com> if folding the change into another commit.

AI-assisted with OpenAI Codex.

@andrewpozdnakov7-jpg

Copy link
Copy Markdown
Contributor Author

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 <andrewpozdnakov7-jpg@users.noreply.github.com> if folding the change into another commit.

AI-assisted with OpenAI Codex.

@cloph-dsp

Copy link
Copy Markdown

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

  • PR Shaders: simplify f32 min and max with literal operands #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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants