Shaders: pass signed flag to wavePrefixOp.f32 and use integer NaN check in v_cvt_{u16,i16}_f16 #355

Open
github-bot wants to merge 1 commit from github-bot/gh-355 into main AGit
Owner

@⁠AscilCH on GitHub · 2026-11-24 23:50 UTC · original
AscilCH:fix/shader-wave-prefix-float-and-f16-nan → main · +139 −9 · 2 files · 1 commits · open

Problem

Two small DXIL correctness bugs in crates/victory-shader/src/emit/lower.rs:

  1. dx.op.wavePrefixOp.f32 passed unsigned = 1: In Lower::wave_reduce, (Op::AddU | Op::AddF, Some(inclusive)) hardcoded k1 = self.s.m.i8(1) (unsigned) even for Op::AddF, unlike waveActiveOp ((0, 0)) and the wave64 prefix exchange (u8::from(!float)). DXIL validation rejects unsigned = 1 on floating-point wavePrefixOp.f32.
  2. v_cvt_u16_f16 / v_cvt_i16_f16 used fcmp uno for NaN detection: This was the last remaining pred::UNO NaN check in lower.rs instead of self.is_nan_f32(a) (integer exponent/mantissa check that host fast-math drivers such as NVIDIA cannot fold away).

Fix

  • Pass self.s.m.i8(u8::from(!float)) to dx.op.wavePrefixOp.{i32,f32}.
  • Replace self.s.m.cmp(c, pred::UNO, a, a) with self.is_nan_f32(a) in v_cvt_{u16,i16}_f16.
  • Add emit::valu_tests::wave_prefix_f32_uses_signed_flag_and_validates and extend cvt_16bit_int_from_f16_saturates_and_honors_modifiers with -qNaN and +sNaN inputs.

Verification

  • cargo test -p victory-shader --locked wave_prefix_f32: passed (dxil.dll + hardware D3D12)
  • cargo test -p victory-shader --locked cvt_16bit_int_from_f16: passed (hardware D3D12 + WARP + dxil.dll)
  • cargo xtask policy: 169 files ok
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings: clean
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings: clean

(AI-assisted; synthetic tests only, no game data.)

**@⁠AscilCH** on GitHub · 2026-11-24 23:50 UTC · [original](https://github.com/fxceless/victory-fork/pull/355) `AscilCH:fix/shader-wave-prefix-float-and-f16-nan` → `main` · +139 −9 · 2 files · 1 commits · open ## Problem Two small DXIL correctness bugs in `crates/victory-shader/src/emit/lower.rs`: 1. **`dx.op.wavePrefixOp.f32` passed `unsigned = 1`**: In `Lower::wave_reduce`, `(Op::AddU | Op::AddF, Some(inclusive))` hardcoded `k1 = self.s.m.i8(1)` (unsigned) even for `Op::AddF`, unlike `waveActiveOp` (`(0, 0)`) and the wave64 prefix exchange (`u8::from(!float)`). DXIL validation rejects `unsigned = 1` on floating-point `wavePrefixOp.f32`. 2. **`v_cvt_u16_f16` / `v_cvt_i16_f16` used `fcmp uno` for NaN detection**: This was the last remaining `pred::UNO` NaN check in `lower.rs` instead of `self.is_nan_f32(a)` (integer exponent/mantissa check that host fast-math drivers such as NVIDIA cannot fold away). ## Fix - Pass `self.s.m.i8(u8::from(!float))` to `dx.op.wavePrefixOp.{i32,f32}`. - Replace `self.s.m.cmp(c, pred::UNO, a, a)` with `self.is_nan_f32(a)` in `v_cvt_{u16,i16}_f16`. - Add `emit::valu_tests::wave_prefix_f32_uses_signed_flag_and_validates` and extend `cvt_16bit_int_from_f16_saturates_and_honors_modifiers` with `-qNaN` and `+sNaN` inputs. ## Verification - `cargo test -p victory-shader --locked wave_prefix_f32`: passed (`dxil.dll` + hardware D3D12) - `cargo test -p victory-shader --locked cvt_16bit_int_from_f16`: passed (hardware D3D12 + WARP + `dxil.dll`) - `cargo xtask policy`: 169 files ok - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings`: clean - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings`: clean *(AI-assisted; synthetic tests only, no game data.)*
Fix two DXIL lowering bugs in `crates/victory-shader/src/emit/lower.rs`:

1. `Lower::wave_reduce` passed `k1 = 1` (`unsigned = 1`) for both
   `Op::AddU` and `Op::AddF` when emitting `dx.op.wavePrefixOp.{i32,f32}`
   (whereas `waveActiveOp` and the wave64 half-exchange path already used
   `unsigned = 0` for `f32`). Pass `u8::from(!float)` so `wavePrefixOp.f32`
   validates under `dxil.dll`.
2. `v_cvt_u16_f16` and `v_cvt_i16_f16` used `fcmp pred::UNO` for their
   `NaN -> 0` guard instead of `Lower::is_nan_f32`, which tests NaN in
   integer arithmetic so fast-math drivers (such as NVIDIA) do not fold
   the NaN check away.

Add `wave_prefix_f32_uses_signed_flag_and_validates` and extend
`cvt_16bit_int_from_f16_saturates_and_honors_modifiers` with `-qNaN` and
`+sNaN` cases.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:41:32 +00:00
Author
Owner

@⁠BTekV4 on GitHub · 2026-11-25 00:48 UTC · original

Tested this PR on top of 31714de (i.e. after yesterday's 3bff182 and 31714de merges), with #376 for the per-pipeline diagnostics. Hardware: RTX 5070 Ti, Windows 11, direct D3D12. Same automated run for every build: the prologue, with A pressed by a script so the world actually loads (~5000 draws/frame, 150 s).

Result: no measurable change on this title. missing-shader 10, pipeline-refused 7, mesh-pipeline-refused 1 — identical to the same build without this PR.

  • baseline (main + #376): a8826150ef94847a
  • this PR (main + #376 + PR): 86b3ffd870f3675c

The class this PR targets no longer shows up in the run. After the two commits merged yesterday, the a whole-wave section step the simulation does not follow (15 occurrences) and a lane mask exchanged where not every lane runs (15) failures are gone. What remains is:

  • 7× a descriptor read only as data (pixel)
  • 1× a descriptor's address or format read as data
  • 1× a lane mask exchanged where not every lane runs
  • 1× a lane mask holding lanes elsewhere read as data
  • 7× pipeline-refused, all E_INVALIDARG (0x80070057) on compute pipelines

So this may be superseded — worth checking before merging, unless it covers forms this scene does not exercise (the test cases suggest it covers more than the prologue does).

Two practical notes:

  1. Against 31714de this PR conflicts only in crates/victory-shader/src/emit/valu_tests.rs (a test file); the functional code applies cleanly, so a rebase is trivial.
  2. Same-run context and the full shader-diag.jsonl (34k records, 11.8 MB) are in #394.
**@⁠BTekV4** on GitHub · 2026-11-25 00:48 UTC · [original](https://github.com/fxceless/victory-fork/pull/355#issuecomment-7148902886) Tested this PR on top of `31714de` (i.e. after yesterday's `3bff182` and `31714de` merges), with #376 for the per-pipeline diagnostics. Hardware: RTX 5070 Ti, Windows 11, direct D3D12. Same automated run for every build: the prologue, with `A` pressed by a script so the world actually loads (~5000 draws/frame, 150 s). **Result: no measurable change on this title.** `missing-shader` 10, `pipeline-refused` 7, `mesh-pipeline-refused` 1 — identical to the same build without this PR. - baseline (`main` + #376): `a8826150ef94847a` - this PR (`main` + #376 + PR): `86b3ffd870f3675c` The class this PR targets no longer shows up in the run. After the two commits merged yesterday, the `a whole-wave section step the simulation does not follow` (15 occurrences) and `a lane mask exchanged where not every lane runs` (15) failures are gone. What remains is: - 7× `a descriptor read only as data` (pixel) - 1× `a descriptor's address or format read as data` - 1× `a lane mask exchanged where not every lane runs` - 1× `a lane mask holding lanes elsewhere read as data` - 7× `pipeline-refused`, all `E_INVALIDARG (0x80070057)` on compute pipelines So this may be **superseded** — worth checking before merging, unless it covers forms this scene does not exercise (the test cases suggest it covers more than the prologue does). Two practical notes: 1. Against `31714de` this PR conflicts **only** in `crates/victory-shader/src/emit/valu_tests.rs` (a test file); the functional code applies cleanly, so a rebase is trivial. 2. Same-run context and the full `shader-diag.jsonl` (34k records, 11.8 MB) are in #394.
This pull request has changes conflicting with the target branch.
  • crates/victory-shader/src/emit/valu_tests.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/355/head:github-bot/gh-355'
git switch 'github-bot/gh-355'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-355'
git switch 'github-bot/gh-355'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-355'
git switch 'github-bot/gh-355'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-355'
git switch 'main'
git merge --squash 'github-bot/gh-355'
git switch 'main'
git merge --ff-only 'github-bot/gh-355'
git switch 'main'
git merge 'github-bot/gh-355'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.