Shaders: decode f16 inline float constants in whole-wave v_add_f16 simulation #2493

Manually merged
github merged 1 commit from gh-pr/2493/head into gh-pr/2493/base 2026-11-26 05:07:26 +00:00
Owner

@⁠reeledMarek on GitHub · 2026-11-25 14:48 UTC · original
reeledMarek:fix/shader-wave-f16-inline-constants → main · +47 −0 · 1 files · 1 commits · merged 2026-11-25 21:57 UTC

Problem

In crates/victory-shader/src/emit/wave.rs, simulate() decoded all Operand::Const(c) operands through crate::resource::inline(c) (f32 bit patterns) even when simulating v_add_f16.

On GFX10, v_add_f16 encodes inline float constants (240..=248: 0.5, -0.5, 1.0, -1.0, 2.0, -2.0, 4.0, -4.0, 1/(2*pi)) as 16-bit f16 bit patterns in the low half (0x3800, 0xB800, 0x3C00, ...), not f32. Because the f32 bit patterns for 240..=247 (e.g. 0x3F80_0000 for 1.0) have zero in their low 15 bits, Op::AddH.identity(k) (k & 0x7FFF == 0) erroneously returned true and silently dropped non-zero v_add_f16 constant additions as additive identities (+ 0.0).

Fix

  • Decode Operand::Const(240..=248) as GFX10 f16 bit patterns when simulating v_add_f16 (matching Lower::f16_operand).
  • Added synthetic regression test emit::wave::tests::v_add_f16_inline_float_constants_are_not_zero_identity verifying 0 (code 128) still reduces to Shape::Half while all inline float constants 240..=248 invalidate the reduction.

Verification

  • cargo test -p victory-shader --locked (145 passed, 0 failed)
  • cargo test -p xtask --locked (repository_passes_policy passed)
  • cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings (0 warnings)
**@⁠reeledMarek** on GitHub · 2026-11-25 14:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2493) `reeledMarek:fix/shader-wave-f16-inline-constants` → `main` · +47 −0 · 1 files · 1 commits · merged 2026-11-25 21:57 UTC ### Problem In `crates/victory-shader/src/emit/wave.rs`, `simulate()` decoded all `Operand::Const(c)` operands through `crate::resource::inline(c)` (f32 bit patterns) even when simulating `v_add_f16`. On GFX10, `v_add_f16` encodes inline float constants (`240..=248`: `0.5`, `-0.5`, `1.0`, `-1.0`, `2.0`, `-2.0`, `4.0`, `-4.0`, `1/(2*pi)`) as 16-bit f16 bit patterns in the low half (`0x3800`, `0xB800`, `0x3C00`, ...), not f32. Because the f32 bit patterns for `240..=247` (e.g. `0x3F80_0000` for `1.0`) have zero in their low 15 bits, `Op::AddH.identity(k)` (`k & 0x7FFF == 0`) erroneously returned `true` and silently dropped non-zero `v_add_f16` constant additions as additive identities (`+ 0.0`). ### Fix - Decode `Operand::Const(240..=248)` as GFX10 f16 bit patterns when simulating `v_add_f16` (matching `Lower::f16_operand`). - Added synthetic regression test `emit::wave::tests::v_add_f16_inline_float_constants_are_not_zero_identity` verifying `0` (code 128) still reduces to `Shape::Half` while all inline float constants `240..=248` invalidate the reduction. ### Verification - `cargo test -p victory-shader --locked` (145 passed, 0 failed) - `cargo test -p xtask --locked` (`repository_passes_policy` passed) - `cargo clippy -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings` (0 warnings)
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:07:23 +00:00
github manually merged commit 6cd2489d55 into gh-pr/2493/base 2026-11-26 05:07:26 +00:00
Author
Owner

@⁠cloph-dsp on GitHub · 2026-11-25 15:41 UTC · original

Independent local validation (Windows, Rust 1.100.0/MSVC, head 6cd2489, no game data): cargo test --locked -p victory-shader --lib -> 248 passed, 0 failed, 3 ignored, exit 0; git diff --check clean. CPU-only regression run; the synthetic f16 inline-constant scenario was not replayed. AI-assisted (Hy4 flash). GPU/driver: N/A for CPU tests.

**@⁠cloph-dsp** on GitHub · 2026-11-25 15:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2493#issuecomment-7167239400) Independent local validation (Windows, Rust 1.100.0/MSVC, head 6cd2489, no game data): `cargo test --locked -p victory-shader --lib` -> 248 passed, 0 failed, 3 ignored, exit 0; `git diff --check` clean. CPU-only regression run; the synthetic f16 inline-constant scenario was not replayed. AI-assisted (Hy4 flash). GPU/driver: N/A for CPU tests.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 15:53 UTC · original

Automated triage for the maintainers. Recommended for a look (not an approval).

In crates/victory-shader/src/emit/wave.rs, simulate() fed inline float constants 240..=247 to half(Op::AddH, ...) as f32 bit patterns, whose low 15 bits are zero, so Op::identity treated e.g. v_add_f16 v1, 1.0, v1 as +0 and the reduction match could fire wrongly. The PR decodes them as f16 for v_add_f16, using the same table as Lower::f16_operand in emit/lower.rs, and adds a regression test that checks 0 still reduces while 240..=248 do not. CI (check) is passing.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 15:53 UTC · [original](https://github.com/Marvisak/VIctory/pull/2493#issuecomment-7167401515) <!-- victory-triage v1 head=6cd2489d552c765f7fd4b327f5bf78493f090589 verdict=merge-candidate at=2026-11-25T15:52:23Z --> Automated triage for the maintainers. Recommended for a look (not an approval). In `crates/victory-shader/src/emit/wave.rs`, `simulate()` fed inline float constants 240..=247 to `half(Op::AddH, ...)` as f32 bit patterns, whose low 15 bits are zero, so `Op::identity` treated e.g. `v_add_f16 v1, 1.0, v1` as `+0` and the reduction match could fire wrongly. The PR decodes them as f16 for `v_add_f16`, using the same table as `Lower::f16_operand` in `emit/lower.rs`, and adds a regression test that checks 0 still reduces while 240..=248 do not. CI (`check`) is passing. --- _Generated by [Claude Code](https://claude.ai/code)_
This discussion has been locked. Commenting is limited to contributors.
No reviewers
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.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2493
No description provided.