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

Merged
reeledMarek merged 1 commit from upstream-pr/2493 into main 2026-11-25 21:57:42 +00:00
reeledMarek commented 2026-11-25 14:48:23 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by reeledMarek on 2026-11-25T14:48:23Z.


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)
<!-- greyfinch-sync:Marvisak/VIctory:issue:6607169709 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2493). Originally posted by [reeledMarek](https://github.com/reeledMarek) on 2026-11-25T14:48:23Z. --- ### 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)
DenRakEiw commented 2026-11-25 15:04:06 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T14:57:58Z.

Review: APPROVED


Verified against origin/main (940d32f) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP:

  • Decoding f16 inline float constants properly in whole-wave v_add_f16 simulation prevents misclassifying them as zero identity.
  • cargo test -p victory-shader emit::wave: 7/7 passed on RTX 5090, 7/7 passed on WARP.
  • cargo clippy -p victory-shader --all-targets -- -D warnings: 0 warnings.
  • cargo xtask policy: 183 files ok.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6060002533 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2493#pullrequestreview-6060002533). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T14:57:58Z. **Review:** APPROVED --- Verified against `origin/main` (`940d32f`) on Windows 11 + NVIDIA GeForce RTX 5090 and WARP: - Decoding f16 inline float constants properly in whole-wave `v_add_f16` simulation prevents misclassifying them as zero identity. - `cargo test -p victory-shader emit::wave`: 7/7 passed on RTX 5090, 7/7 passed on WARP. - `cargo clippy -p victory-shader --all-targets -- -D warnings`: 0 warnings. - `cargo xtask policy`: 183 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
cloph-dsp commented 2026-11-25 16:09:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by cloph-dsp on 2026-11-25T15:41:47Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167239400 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2493#issuecomment-7167239400). Originally posted by [cloph-dsp](https://github.com/cloph-dsp) on 2026-11-25T15:41:47Z. --- 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.
Marvisak commented 2026-11-25 16:09:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T15:53:18Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7167401515 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2493#issuecomment-7167401515). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T15:53:18Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-25 22:03:46 +00:00
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!2491
No description provided.