Shaders: lower binary64 fractional parts #2726

Open
andrewpozdnakov7-jpg wants to merge 2 commits from upstream-pr/2728 into main
andrewpozdnakov7-jpg commented 2026-11-25 19:01:35 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by andrewpozdnakov7-jpg on 2026-11-25T19:01:35Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:5497379928 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2728). Originally posted by [andrewpozdnakov7-jpg](https://github.com/andrewpozdnakov7-jpg) on 2026-11-25T19:01:35Z. --- ## 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://github.com/Marvisak/VIctory/issues/1633#issuecomment-7171515454) 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.
kotekompotek commented 2026-11-25 19:06:44 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by kotekompotek on 2026-11-25T19:04:46Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7171790891 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2728#issuecomment-7171790891). Originally posted by [kotekompotek](https://github.com/kotekompotek) on 2026-11-25T19:04:46Z. --- 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.
fuzeofficlal commented 2026-11-25 20:06:18 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-25T19:34:38Z.


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).
<!-- greyfinch-sync:Marvisak/VIctory:comment:7172488356 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2728#issuecomment-7172488356). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-25T19:34:38Z. --- 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).
Marvisak commented 2026-11-26 00:03:22 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T23:16:40Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177349363 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2728#issuecomment-7177349363). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T23:16:40Z. --- <!-- 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)_
HAL9000RELOADED commented 2026-11-26 00:03:30 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by HAL9000RELOADED on 2026-11-25T23:25:48Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7177548408 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2728#issuecomment-7177548408). Originally posted by [HAL9000RELOADED](https://github.com/HAL9000RELOADED) on 2026-11-25T23:25:48Z. --- 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.
Dukestar69 commented 2026-11-26 04:19:52 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dukestar69 on 2026-11-26T04:19:52Z.

Review: APPROVED


Tested merged onto origin/main (63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, dxil.dll validator active):

  • cargo test -p victory-shader --lib emit::valu_tests::fract_f64: 2 passed, 0 failed (fract_f64_vop1_returns_both_words_below_one and fract_f64_vop3_literals_obey_abs_and_neg pass on both RTX 5090 hardware and WARP).
  • cargo clippy -p victory-shader --all-targets -- -D warnings: clean.
  • cargo xtask policy: 192 files ok.

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

<!-- greyfinch-sync:Marvisak/VIctory:review:6068499661 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2728#pullrequestreview-6068499661). Originally posted by [Dukestar69](https://github.com/Dukestar69) on 2026-11-26T04:19:52Z. **Review:** APPROVED --- Tested merged onto `origin/main` (`63bcca4`) on Windows 11 x64 (NVIDIA GeForce RTX 5090 + WARP, `dxil.dll` validator active): - `cargo test -p victory-shader --lib emit::valu_tests::fract_f64`: **2 passed, 0 failed** (`fract_f64_vop1_returns_both_words_below_one` and `fract_f64_vop3_literals_obey_abs_and_neg` pass on both RTX 5090 hardware and WARP). - `cargo clippy -p victory-shader --all-targets -- -D warnings`: clean. - `cargo xtask policy`: 192 files ok. Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
fuzeofficlal commented 2026-11-27 01:31:59 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by fuzeofficlal on 2026-11-27T01:31:59Z.

Review: APPROVED


Looks good — verified locally at 7b0550cd:

  • cargo xtask policy (192 files ok) and cargo clippy --all-targets --all-features pass with 0 warnings.
  • Zero new rustfmt --edition 2024 diffs (crates/victory-shader/src/emit/lower/fract.rs is clean; remaining diffs in lower.rs and valu_tests.rs are pre-existing).
  • emit::valu_tests::fract passes 2/2 on both RTX 5090 (VICTORY_WARP=0) and WARP (VICTORY_WARP=1), verifying SFI0 & 0x8001 == 0, < 1.0 clamping (0x3FEF_FFFF_FFFF_FFFF), abs/neg modifiers, literals, and SGPR/VGPR sources.
  • Exact-rational checks across 1,112,745 cases confirm the integer bit arithmetic under RTE + denorm-preserve semantics.

(Non-blocking note: fract_f64 currently assumes default RTE + preserved denormals rather than tracking mode16 round/denorm changes, and rejects clamp/omod; those can be extended later if needed.)

<!-- greyfinch-sync:Marvisak/VIctory:review:6082296025 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2728#pullrequestreview-6082296025). Originally posted by [fuzeofficlal](https://github.com/fuzeofficlal) on 2026-11-27T01:31:59Z. **Review:** APPROVED --- Looks good — verified locally at `7b0550cd`: - `cargo xtask policy` (`192 files ok`) and `cargo clippy --all-targets --all-features` pass with 0 warnings. - Zero new `rustfmt --edition 2024` diffs (`crates/victory-shader/src/emit/lower/fract.rs` is clean; remaining diffs in `lower.rs` and `valu_tests.rs` are pre-existing). - `emit::valu_tests::fract` passes **2/2** on both RTX 5090 (`VICTORY_WARP=0`) and WARP (`VICTORY_WARP=1`), verifying `SFI0 & 0x8001 == 0`, `< 1.0` clamping (`0x3FEF_FFFF_FFFF_FFFF`), `abs`/`neg` modifiers, literals, and SGPR/VGPR sources. - Exact-rational checks across 1,112,745 cases confirm the integer bit arithmetic under RTE + denorm-preserve semantics. *(Non-blocking note: `fract_f64` currently assumes default RTE + preserved denormals rather than tracking `mode16` round/denorm changes, and rejects `clamp`/`omod`; those can be extended later if needed.)*
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2728:upstream-pr/2728'
git switch 'upstream-pr/2728'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2728'
git switch 'upstream-pr/2728'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2728'
git switch 'upstream-pr/2728'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2728'
git switch 'main'
git merge --squash 'upstream-pr/2728'
git switch 'main'
git merge --ff-only 'upstream-pr/2728'
git switch 'main'
git merge 'upstream-pr/2728'
git push origin 'main'
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!2726
No description provided.