Shaders: lower binary64 fractional parts #2728

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

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 19:01 UTC · original
andrewpozdnakov7-jpg:codex2/fract-f64 → main · +305 −0 · 3 files · 2 commits · open

Summary

Lower RDNA 2 V_FRACT_F64 in VOP1 and VOP3. The lowering uses two 32-bit words, rounds ties to even and keeps finite results below one. It writes both destination words under the lane guard and requires neither host doubles nor int64. VOP3 source abs and neg are supported.

The RDNA 2 ISA defines the operation as x minus floor(x). RDNA 2 and RDNA 4 measurements confirm that tiny negative inputs return the largest binary64 value below one.

Verification

  • On base 13f91ca, both synthetic tests fail during shader translation with Unsupported v_fract_f64.
  • With the patch, the tests check results for 32 inputs through VGPR and SGPR pairs, including a rounding carry between words, signed zeros, subnormals and nonfinite inputs. VOP3 literals exercise abs and neg separately and verify that the optional double and int64 DXIL feature flags are clear.
  • All 32 project VALU tests pass on app-local D3D12 WARP. Strict shader Clippy and the 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. The regression uses synthetic inputs.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 19:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/2728) `andrewpozdnakov7-jpg:codex2/fract-f64` → `main` · +305 −0 · 3 files · 2 commits · open ## Summary Lower RDNA 2 V_FRACT_F64 in VOP1 and VOP3. The lowering uses two 32-bit words, rounds ties to even and keeps finite results below one. It writes both destination words under the lane guard and requires neither host doubles nor int64. VOP3 source abs and neg are supported. The [RDNA 2 ISA](https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf) defines the operation as x minus floor(x). [RDNA 2 and RDNA 4 measurements](https://github.com/KytyPS5/KytyPS5/issues/1209#issuecomment-6215026480) confirm that tiny negative inputs return the largest binary64 value below one. ## Verification - On base 13f91ca, both synthetic tests fail during shader translation with Unsupported v_fract_f64. - With the patch, the tests check results for 32 inputs through VGPR and SGPR pairs, including a rounding carry between words, signed zeros, subnormals and nonfinite inputs. VOP3 literals exercise abs and neg separately and verify that the optional double and int64 DXIL feature flags are clear. - All 32 project VALU tests pass on app-local D3D12 WARP. Strict shader Clippy and the 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. The regression uses synthetic inputs.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 05:12:53 +00:00
Author
Owner

@⁠kotekompotek on GitHub · 2026-11-25 19:04 UTC · original

Impressive lowering. Verified the hard parts:

  • shift_fraction_words correctly avoids any IR shift count reaching 32 (carry_shift masked to 31, needs_carry guards offset==0) - no poison.
  • The guard/sticky/parity combine implements round-to-even on the 53-bit significand before the 1-|x| complement for negatives - this is what produces the 'largest f64 below 1' for tiny negatives (KytyPS5-measured behavior), and the empty/limit select handles it explicitly.
  • Operand details all match the ISA: f64 literal = high word + zero low (the test's 0x402a8000 -> 13.25 confirms), const 248 uses the true f64 1/(2pi) not the f32 widening, inline float consts convert f32->f64, int consts sign-extend, and clamp/omod/sdwa/dpp reject to skip rather than mis-emit.
  • Positive |x|<1 shortcut (incl. subnormals), exponent>=1075 -> +0, nonfinite -> quiet NaN all correct.

Test matrix is genuinely exhaustive. LGTM.

**@⁠kotekompotek** on GitHub · 2026-11-25 19:04 UTC · [original](https://github.com/Marvisak/VIctory/pull/2728#issuecomment-7171790891) Impressive lowering. Verified the hard parts: - shift_fraction_words correctly avoids any IR shift count reaching 32 (carry_shift masked to 31, needs_carry guards offset==0) - no poison. - The guard/sticky/parity combine implements round-to-even on the 53-bit significand before the 1-|x| complement for negatives - this is what produces the 'largest f64 below 1' for tiny negatives (KytyPS5-measured behavior), and the empty/limit select handles it explicitly. - Operand details all match the ISA: f64 literal = high word + zero low (the test's 0x402a8000 -> 13.25 confirms), const 248 uses the true f64 1/(2pi) not the f32 widening, inline float consts convert f32->f64, int consts sign-extend, and clamp/omod/sdwa/dpp reject to skip rather than mis-emit. - Positive |x|<1 shortcut (incl. subnormals), exponent>=1075 -> +0, nonfinite -> quiet NaN all correct. Test matrix is genuinely exhaustive. LGTM.
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-25 19:34 UTC · original

Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + dxil.dll verification and IEEE-754 review of 325fda6 (on 13f91ca):

Verification (rustc 1.98.1 MSVC, Windows SDK 10.0.26100.0 dxil.dll)

  • cargo xtask policy: 184 files ok.
  • cargo clippy --locked -p victory-shader --all-targets -- -D warnings and --features host: 0 warnings.
  • cargo test --locked -p victory-shader --lib -- fract_f64 emit::tests emit::lower emit::valu_tests (skipping the 4 long exhaustive 16-bit/3-op tests; RTX 5090 hardware + WARP + dxil.dll active): 72 passed, 0 failed.
  • Combined merge test with #2713 (0af08f5): clean zero-conflict merge; all 4 binary64 tests pass together on RTX 5090 + WARP + dxil.dll.

Review Notes

  • Pure 32-bit integer lowering + firstbitLo/firstbitHi + safe shift_fraction_words avoids SFI0 DOUBLE/INT64 flags and shift UB, while accurately implementing RDNA2 [0.0, 1.0) semantics: fract(-0.0) = +0.0, exact integers and |x| >= 2^52 -> +0.0, positive subnormals preserved without FTZ, negative small/subnormal inputs (-2^-54, -3*2^-54, -2^-1074) rounded-to-nearest-even and clamped to next_down(1.0), and ±Inf/sNaN/qNaN quietened via | 0x0008_0000.
  • Clean and ready to merge (minor follow-up: share the ~40-line f64 source decode helper with #2713 if both land).
**@⁠fuzeofficlal** on GitHub · 2026-11-25 19:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2728#issuecomment-7172488356) Independent Windows 11 + NVIDIA GeForce RTX 5090 + WARP + `dxil.dll` verification and IEEE-754 review of `325fda6` (on `13f91ca`): ### Verification (`rustc 1.98.1` MSVC, Windows SDK `10.0.26100.0` `dxil.dll`) - `cargo xtask policy`: **184 files ok**. - `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` and `--features host`: **0 warnings**. - `cargo test --locked -p victory-shader --lib -- fract_f64 emit::tests emit::lower emit::valu_tests` (skipping the 4 long exhaustive 16-bit/3-op tests; RTX 5090 hardware + WARP + `dxil.dll` active): **72 passed, 0 failed**. - **Combined merge test with #2713 (`0af08f5`):** clean zero-conflict merge; all 4 binary64 tests pass together on RTX 5090 + WARP + `dxil.dll`. ### Review Notes - Pure 32-bit integer lowering + `firstbitLo`/`firstbitHi` + safe `shift_fraction_words` avoids `SFI0` `DOUBLE`/`INT64` flags and shift UB, while accurately implementing RDNA2 `[0.0, 1.0)` semantics: `fract(-0.0) = +0.0`, exact integers and `|x| >= 2^52 -> +0.0`, positive subnormals preserved without FTZ, negative small/subnormal inputs (`-2^-54`, `-3*2^-54`, `-2^-1074`) rounded-to-nearest-even and clamped to `next_down(1.0)`, and `±Inf`/`sNaN`/`qNaN` quietened via `| 0x0008_0000`. - Clean and ready to merge (minor follow-up: share the ~40-line `f64` source decode helper with #2713 if both land).
Author
Owner

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

Automated triage for the maintainers.

This adds a lowering for v_fract_f64 (VOP1 and VOP3) in the new crates/victory-shader/src/emit/lower/fract.rs, dispatched from Lower in lower.rs. It works on two 32-bit words, so it needs no double or int64 DXIL flags.

What I checked:

  • operand decoding: the f64 literal as the high word, the 1/(2π) constant and sign-extended integer constants;
  • that the shift helper keeps every shift count below 32;
  • the round-to-even path for small negative inputs, which gives the largest value below one;
  • the NaN, infinity and exact-integer cases.

The behaviour cites the public RDNA2 ISA document and published hardware measurements. The tests cover 32 inputs through VGPR and SGPR pairs, plus abs and neg. CI: check passes. This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/2728#issuecomment-7177349363) <!-- victory-triage v1 head=7b0550cd4bf4cf35a4dcb6f735e695ffb048e9e8 verdict=merge-candidate at=2026-11-25T23:22:00Z --> Automated triage for the maintainers. This adds a lowering for `v_fract_f64` (VOP1 and VOP3) in the new `crates/victory-shader/src/emit/lower/fract.rs`, dispatched from `Lower` in `lower.rs`. It works on two 32-bit words, so it needs no double or int64 DXIL flags. What I checked: - operand decoding: the f64 literal as the high word, the 1/(2π) constant and sign-extended integer constants; - that the shift helper keeps every shift count below 32; - the round-to-even path for small negative inputs, which gives the largest value below one; - the NaN, infinity and exact-integer cases. The behaviour cites the public RDNA2 ISA document and published hardware measurements. The tests cover 32 inputs through VGPR and SGPR pairs, plus abs and neg. CI: `check` passes. 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 7b0550c: 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: 303 passed, 1 failed. Both new tests pass on the card: fract_f64_vop1_returns_both_words_below_one and fract_f64_vop3_literals_obey_abs_and_neg.
  • 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 fract 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/2728#issuecomment-7177548408) First Radeon run of `7b0550c`: 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`: 303 passed, 1 failed. Both new tests pass on the card: `fract_f64_vop1_returns_both_words_below_one` and `fract_f64_vop3_literals_obey_abs_and_neg`. - 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 fract 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/2728/head:github-bot/gh-2728'
git switch 'github-bot/gh-2728'

Merge

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