Shaders: lower binary64 scaling with floating-point modes #2743

Open
github-bot wants to merge 2 commits from github-bot/gh-2743 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 19:27 UTC · original
andrewpozdnakov7-jpg:codex2/ldexp-f64 → main · +397 −49 · 3 files · 2 commits · open

Summary

Lower RDNA 2 V_LDEXP_F64 by adjusting and rounding its binary64 significand and exponent in two 32-bit words. Both register pairs and signed 32-bit scale operands use their normal routes. The translation requires neither host doubles nor int64.

The existing MODE analysis now also tracks the FP16/FP64 denormal field. Scaling handles all four rounding and denormal modes when they are known at translation time. The shader entry uses nearest-even rounding and preserves binary64 subnormals, matching the documented AMDHSA defaults. RDNA 2 ISA · AMDGPU kernel descriptor defaults

Verification

  • On 13f91ca, each of the three synthetic shaders fails translation with Unsupported v_ldexp_f64.
  • With the change, the same tests verify both result words on app-local D3D12 WARP. Cases cover normals, subnormals, signed zeros, overflow, underflow, NaN/Inf, cross-word carry, and explicit S_ROUND_MODE, S_DENORM_MODE and S_SETREG writes.
  • All 33 project VALU tests pass. The existing FP16 mode test also passes on the base and patched builds. Strict shader Clippy and staged asset policy pass.

Coordination claim

Please retain the Git author if cherry-picking or rebasing this commit. If folding it into another commit, add Co-authored-by: andrewpozdnakov7-jpg [email protected].

AI-assisted. Verification used synthetic shaders.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 19:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/2743) `andrewpozdnakov7-jpg:codex2/ldexp-f64` → `main` · +397 −49 · 3 files · 2 commits · open ## Summary Lower RDNA 2 V_LDEXP_F64 by adjusting and rounding its binary64 significand and exponent in two 32-bit words. Both register pairs and signed 32-bit scale operands use their normal routes. The translation requires neither host doubles nor int64. The existing MODE analysis now also tracks the FP16/FP64 denormal field. Scaling handles all four rounding and denormal modes when they are known at translation time. The shader entry uses nearest-even rounding and preserves binary64 subnormals, matching the documented AMDHSA defaults. [RDNA 2 ISA](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) · [AMDGPU kernel descriptor defaults](https://llvm.org/docs/AMDGPUUsage.html#amdhsa-kernel-directives-table) ## Verification - On 13f91ca, each of the three synthetic shaders fails translation with Unsupported v_ldexp_f64. - With the change, the same tests verify both result words on app-local D3D12 WARP. Cases cover normals, subnormals, signed zeros, overflow, underflow, NaN/Inf, cross-word carry, and explicit S_ROUND_MODE, S_DENORM_MODE and S_SETREG writes. - All 33 project VALU tests pass. The existing FP16 mode test also passes on the base and patched builds. Strict shader Clippy and staged asset policy pass. [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) Please retain the Git author if cherry-picking or rebasing this commit. If folding it into another commit, add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>. AI-assisted. Verification used synthetic shaders.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:13:14 +00:00
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 20:10 UTC · original

Reviewed and verified 99161fd6 on Windows 11 (RTX 5090 + WARP + Windows SDK 10.0.26100.0 dxil.dll) against main (13f91ca).

Code review

  • Pure 32-bit integer lowering of v_ldexp_f64 (no DOUBLE / INT64 shader capability required).
  • scale_source_words applies abs then neg on the high word, rejects src1 modifiers and clamp/omod/sdwa/dpp, places Literal in the high word, sign-extends inline negative integers, promotes inline floats (with 248 = 0x3fc4_5f30_6dc9_c882), preserves ±0.0/±Inf, and quietens sNaN while retaining payload.
  • Clamping power to [-4096, 4096] avoids signed overflow with i32::MIN/i32::MAX. FpMode16 tracks both MODE[3:2] rounding and MODE[7:6] FP16/FP64 denorm modes cleanly and explicitly refuses unknown/conflicting modes at CFG joins; subnormal input flush vs. FirstbitHi normalization, cross-word FirstbitLo sticky rounding in round_scaled_subnormal, carry-out from max subnormal to min normal before output flush, and overflow rounding (±Inf vs. ±f64::MAX) all check out.

Verification (Windows 11, RTX 5090 + WARP + dxil.dll)

  • cargo test --locked -p victory-shader --lib --features host emit::tests: 17/17 passed; emit::lower::tests: 27/27 passed; emit::valu_tests (excluding slow exhaustive tests): 29/29 passed (all 3 ldexp_f64_* tests pass on both RTX 5090 and WARP).
  • VICTORY_WARP=1 cargo test --locked -p victory-shader --lib --features host ldexp: 3/3 passed.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default & --features host): 0 warnings; cargo xtask policy: 185 files ok.
  • Clean git merge-tree against 13f91ca, #2713, and #2728.
**@⁠fuzeofficlal** on GitHub · 2026-11-25 20:10 UTC · [original](https://github.com/Marvisak/VIctory/pull/2743#issuecomment-7173296012) Reviewed and verified `99161fd6` on Windows 11 (RTX 5090 + WARP + Windows SDK `10.0.26100.0` `dxil.dll`) against `main` (`13f91ca`). ### Code review - Pure 32-bit integer lowering of `v_ldexp_f64` (no `DOUBLE` / `INT64` shader capability required). - `scale_source_words` applies `abs` then `neg` on the high word, rejects `src1` modifiers and `clamp`/`omod`/`sdwa`/`dpp`, places `Literal` in the high word, sign-extends inline negative integers, promotes inline floats (with `248` = `0x3fc4_5f30_6dc9_c882`), preserves `±0.0`/`±Inf`, and quietens `sNaN` while retaining payload. - Clamping `power` to `[-4096, 4096]` avoids signed overflow with `i32::MIN`/`i32::MAX`. `FpMode16` tracks both `MODE[3:2]` rounding and `MODE[7:6]` FP16/FP64 denorm modes cleanly and explicitly refuses unknown/conflicting modes at CFG joins; subnormal input flush vs. `FirstbitHi` normalization, cross-word `FirstbitLo` sticky rounding in `round_scaled_subnormal`, carry-out from max subnormal to min normal before output flush, and overflow rounding (`±Inf` vs. `±f64::MAX`) all check out. ### Verification (Windows 11, RTX 5090 + WARP + `dxil.dll`) - `cargo test --locked -p victory-shader --lib --features host emit::tests`: **17/17 passed**; `emit::lower::tests`: **27/27 passed**; `emit::valu_tests` (excluding slow exhaustive tests): **29/29 passed** (all 3 `ldexp_f64_*` tests pass on both RTX 5090 and WARP). - `VICTORY_WARP=1 cargo test --locked -p victory-shader --lib --features host ldexp`: **3/3 passed**. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default & `--features host`): **0 warnings**; `cargo xtask policy`: **185 files ok**. - Clean `git merge-tree` against `13f91ca`, `#2713`, and `#2728`.
Author
Owner

@⁠oni-swr on GitHub · 2026-11-25 20:15 UTC · original

Independent WARP/CPU verification for head 99161fd6fe against origin/main 13f91caee2. State check at start and again before posting: open, non-draft, mergeable, head unchanged; no prior oni-swr comment.

Environment: Windows 11 x64, Rust 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1, Windows SDK dxil.dll 10.0.26100.0 (file version 1.8.2502.11). VICTORY_WARP=1 and VICTORY_D3D12_WARP=1 set (WARP only, no physical GPU); no game files. CARGO_TARGET_DIR=D:\victory-warp-2741-target. Tested commit: the PR head itself, which is exactly one commit on top of origin/main (merge-base = origin/main, so no temporary merge was needed). In victory-shader's host tests VICTORY_WARP=1 makes both the "hardware" and "warp" labels run on WARP (Host::new), so no physical GPU was used.

Commands/results:

  • Baseline (origin/main): cargo test --locked -p victory-shader — 267 passed, 3 failed, 3 ignored. Pre-existing failures on main: emit::synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number, gathers_at_a_level_match_the_hardware, permutes_read_the_lane_named_and_zero_from_lanes_left_out. cargo clippy --locked -p victory-shader --all-targets -- -D warnings — pass.
  • PR: cargo test --locked -p victory-shader --lib ldexp_f64 — 3/3 passed. cargo test --locked -p victory-shader — 270 passed (+3), the same 3 failed (identical names to baseline, so no new failure), 3 ignored. cargo clippy --locked -p victory-shader --all-targets -- -D warnings — pass.
  • Negative controls (tests kept, each change restored afterwards, tree clean): "v_ldexp_f64" arm removed -> all 3 new tests FAILED. Round-up direction inverted (1 => negative) -> ldexp_f64_uses_the_round_mode_for_underflow_and_overflow FAILED, the other two passed. Subnormal-result flush disabled (if false) -> ldexp_f64_uses_the_denormal_mode_for_both_operands_and_results FAILED, the other two passed. So each of the three tests pins a different part of the lowering.

Review: no correctness blocker found in the inspected paths. The MODE tracker now follows bits 3:2 and 7:6 independently, joins disagreeing paths to unknown, and v_ldexp_f64 refuses (Err) when either mode is unknown instead of guessing; the test also asserts the SFI0 doubles/int64 feature bits are clear, which is a good guard for the no-native-double goal. Subnormal rounding (sticky across the dword boundary, carry into the minimum normal, flush only if the result is still subnormal), overflow by round mode, NaN quieting and power clamping are all covered by cases. Scope notes: clamp, omod, SDWA, DPP and abs/neg on the exponent operand are rejected as unsupported (explicit errors, not silent); the lowering is only checked against hand-written expected bit patterns, not against a hardware reference, and the new files are not rustfmt-formatted (neither is most of main, so not counted against it).

Not tested: physical GPU, retail title/game behavior, release build (debug profile only).

AI disclosure: Claude Code (Claude Sonnet 5.5).

**@⁠oni-swr** on GitHub · 2026-11-25 20:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/2743#issuecomment-7173410008) Independent WARP/CPU verification for head 99161fd6fe5ce773cb2e0e5a3458d8492643784d against origin/main 13f91caee25f2fdf2c062be5f7a27f058e51cbca. State check at start and again before posting: open, non-draft, mergeable, head unchanged; no prior oni-swr comment. Environment: Windows 11 x64, Rust 1.98.1 (48a229cea 2026-09-01), cargo 1.98.1, Windows SDK dxil.dll 10.0.26100.0 (file version 1.8.2502.11). `VICTORY_WARP=1` and `VICTORY_D3D12_WARP=1` set (WARP only, no physical GPU); no game files. `CARGO_TARGET_DIR=D:\victory-warp-2741-target`. Tested commit: the PR head itself, which is exactly one commit on top of `origin/main` (merge-base = `origin/main`, so no temporary merge was needed). In victory-shader's host tests `VICTORY_WARP=1` makes both the "hardware" and "warp" labels run on WARP (`Host::new`), so no physical GPU was used. Commands/results: - Baseline (origin/main): `cargo test --locked -p victory-shader` — 267 passed, **3 failed**, 3 ignored. Pre-existing failures on main: `emit::synthetic_tests::a_mask_joined_with_data_at_a_uniform_loop_is_its_number`, `gathers_at_a_level_match_the_hardware`, `permutes_read_the_lane_named_and_zero_from_lanes_left_out`. `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` — pass. - PR: `cargo test --locked -p victory-shader --lib ldexp_f64` — 3/3 passed. `cargo test --locked -p victory-shader` — 270 passed (+3), the same 3 failed (identical names to baseline, so no new failure), 3 ignored. `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` — pass. - Negative controls (tests kept, each change restored afterwards, tree clean): `"v_ldexp_f64"` arm removed -> all 3 new tests FAILED. Round-up direction inverted (`1 => negative`) -> `ldexp_f64_uses_the_round_mode_for_underflow_and_overflow` FAILED, the other two passed. Subnormal-result flush disabled (`if false`) -> `ldexp_f64_uses_the_denormal_mode_for_both_operands_and_results` FAILED, the other two passed. So each of the three tests pins a different part of the lowering. Review: no correctness blocker found in the inspected paths. The MODE tracker now follows bits 3:2 and 7:6 independently, joins disagreeing paths to unknown, and `v_ldexp_f64` refuses (`Err`) when either mode is unknown instead of guessing; the test also asserts the SFI0 doubles/int64 feature bits are clear, which is a good guard for the no-native-double goal. Subnormal rounding (sticky across the dword boundary, carry into the minimum normal, flush only if the result is still subnormal), overflow by round mode, NaN quieting and power clamping are all covered by cases. Scope notes: `clamp`, `omod`, SDWA, DPP and abs/neg on the exponent operand are rejected as unsupported (explicit errors, not silent); the lowering is only checked against hand-written expected bit patterns, not against a hardware reference, and the new files are not rustfmt-formatted (neither is most of main, so not counted against it). Not tested: physical GPU, retail title/game behavior, release build (debug profile only). AI disclosure: Claude Code (Claude Sonnet 5.5).
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 20:39 UTC · original

The FpMode16 refactor is the right shape: INITIAL matches the shader-entry convention (nearest-even, preserve subnormals both ways), the s_setreg field overlap check (offset<=start && end>=start+2) handles partial-field writes correctly, and tracking round/denorm independently unblocks ldexp's denorm handling. ldexp_f64 normalizes subnormal inputs by scaling before exponent adjust - the standard approach. Heads up on merge order: #2782's s_getreg reads self.mode16 as Option; whichever lands second needs mode16.round.

**@⁠kotekompotek** on GitHub · 2026-11-25 20:39 UTC · [original](https://github.com/Marvisak/VIctory/pull/2743#issuecomment-7173997865) The FpMode16 refactor is the right shape: INITIAL matches the shader-entry convention (nearest-even, preserve subnormals both ways), the s_setreg field overlap check (offset<=start && end>=start+2) handles partial-field writes correctly, and tracking round/denorm independently unblocks ldexp's denorm handling. ldexp_f64 normalizes subnormal inputs by scaling before exponent adjust - the standard approach. Heads up on merge order: #2782's s_getreg reads self.mode16 as Option<u8>; whichever lands second needs mode16.round.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 23:24 UTC · original

Automated triage for the maintainers. This adds a lowering for v_ldexp_f64 in crates/victory-shader/src/emit/lower/ldexp.rs using only 32-bit integer ops, and replaces round16 in emit/lower.rs with FpMode16, which tracks MODE bits 3:2 (round) and 7:6 (FP16/64 denorm) on their own. I checked the subnormal normalization (FirstbitHi counted from the MSB), the right shift into subnormal units with sticky bits across the dword boundary, the directed and nearest-even rounding, the flush rules for the RDNA2 denorm field (bit 0 input, bit 1 output), overflow to Inf or max-finite by round mode, NaN quieting, and the 64-bit literal and inline-constant handling. Things to note: the entry assumption that subnormals are preserved comes from the AMDHSA defaults, not from the title's own shader float mode, and #2782 reads mode16 as Option<u8>, so whichever lands second needs mode16.round. CI: check passing. This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:24 UTC · [original](https://github.com/Marvisak/VIctory/pull/2743#issuecomment-7177522047) <!-- victory-triage v1 head=177f0e52bf457774caebce2299c617499efaed1a verdict=merge-candidate at=2026-11-25T23:24:32Z --> Automated triage for the maintainers. This adds a lowering for `v_ldexp_f64` in `crates/victory-shader/src/emit/lower/ldexp.rs` using only 32-bit integer ops, and replaces `round16` in `emit/lower.rs` with `FpMode16`, which tracks MODE bits 3:2 (round) and 7:6 (FP16/64 denorm) on their own. I checked the subnormal normalization (FirstbitHi counted from the MSB), the right shift into subnormal units with sticky bits across the dword boundary, the directed and nearest-even rounding, the flush rules for the RDNA2 denorm field (bit 0 input, bit 1 output), overflow to Inf or max-finite by round mode, NaN quieting, and the 64-bit literal and inline-constant handling. Things to note: the entry assumption that subnormals are preserved comes from the AMDHSA defaults, not from the title's own shader float mode, and #2782 reads `mode16` as `Option<u8>`, so whichever lands second needs `mode16.round`. CI: `check` passing. This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠HAL9000RELOADED on GitHub · 2026-11-25 23:25 UTC · original

First Radeon run of 177f0e5: RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2 (19045), Agility SDK 1.620 in the shader test binaries through #486. Base: 481d699 (main 842b0cb + #486).

  • victory-shader: 304 passed, 1 failed. The three new tests pass on the card: ldexp_f64_scales_normal_and_subnormal_values, ldexp_f64_uses_the_denormal_mode_for_both_operands_and_results and ldexp_f64_uses_the_round_mode_for_underflow_and_overflow.
  • The one failure is pops_wait_loop_exits_immediately_for_inactive_lanes, which wants an SM 6.6 WARP device (this Windows 10 WARP reports SM 6.2). It fails the same way on the base without this PR.

So the lowered binary64 scaling, denormal and round modes included, matches on RDNA3 hardware as well as on the RTX 5090 and WARP.

**@⁠HAL9000RELOADED** on GitHub · 2026-11-25 23:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/2743#issuecomment-7177547749) First Radeon run of `177f0e5`: RX 7900 XTX (RDNA3), driver 32.0.32015.7029, Windows 10 22H2 (19045), Agility SDK 1.620 in the shader test binaries through #486. Base: `481d699` (main `842b0cb` + #486). - `victory-shader`: 304 passed, 1 failed. The three new tests pass on the card: `ldexp_f64_scales_normal_and_subnormal_values`, `ldexp_f64_uses_the_denormal_mode_for_both_operands_and_results` and `ldexp_f64_uses_the_round_mode_for_underflow_and_overflow`. - The one failure is `pops_wait_loop_exits_immediately_for_inactive_lanes`, which wants an SM 6.6 WARP device (this Windows 10 WARP reports SM 6.2). It fails the same way on the base without this PR. So the lowered binary64 scaling, denormal and round modes included, matches on RDNA3 hardware as well as on the RTX 5090 and WARP.
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

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

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2743'
git switch 'github-bot/gh-2743'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2743'
git switch 'github-bot/gh-2743'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2743'
git switch 'main'
git merge --squash 'github-bot/gh-2743'
git switch 'main'
git merge --ff-only 'github-bot/gh-2743'
git switch 'main'
git merge 'github-bot/gh-2743'
git push origin 'main'
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!2743
No description provided.