Shaders: lower binary64 truncation #2600

Open
github-bot wants to merge 3 commits from github-bot/gh-2600 into main AGit
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 16:34 UTC · original
andrewpozdnakov7-jpg:codex2/shader-trunc-f64 → main · +147 −0 · 3 files · 3 commits · open

v_trunc_f64 (RDNA 2 VOP1 opcode 0x017) is decoded but rejected by host shader lowering. Emit round-toward-zero by clearing the fractional bits in the two binary64 words. This preserves signed zeros and leaves integral values unchanged. The emitted shader uses 32-bit integer operations. AMD RDNA 2 ISA, VOP1

The same two synthetic shaders are rejected as Unsupported on 67e8ae1 and execute successfully on the patch. The tests check 15 input values through both vector and scalar register pairs, both output dwords, and a negated VOP3 literal. Cases cover the 31/32/33-bit mask boundary, negative fractions, subnormals, signed zero, and large integral values. The VOP3 fixture also checks the DXIL feature bits.

Windows app-local WARP 1.0.22 and Agility 1.620.2 with Microsoft DXIL validation. All 32 project VALU tests pass, plus a temporary test confirming the loaded runtime modules and validator. Strict shader Clippy and the staged asset policy pass. The lowering explicitly reports unsupported output clamp/omod.

Coordination claim

If you cherry-pick or rebase this commit, please retain its Git author. If you fold the change into another commit, please add Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.

AI-assisted. Verification used synthetic shaders.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 16:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2600) `andrewpozdnakov7-jpg:codex2/shader-trunc-f64` → `main` · +147 −0 · 3 files · 3 commits · open `v_trunc_f64` (RDNA 2 VOP1 opcode `0x017`) is decoded but rejected by host shader lowering. Emit round-toward-zero by clearing the fractional bits in the two binary64 words. This preserves signed zeros and leaves integral values unchanged. The emitted shader uses 32-bit integer operations. [AMD RDNA 2 ISA, VOP1](https://docs.amd.com/api/khub/documents/Et~wpu9g~Ffl7d9q0QZ~Og/content) The same two synthetic shaders are rejected as `Unsupported` on `67e8ae1` and execute successfully on the patch. The tests check 15 input values through both vector and scalar register pairs, both output dwords, and a negated VOP3 literal. Cases cover the 31/32/33-bit mask boundary, negative fractions, subnormals, signed zero, and large integral values. The VOP3 fixture also checks the DXIL feature bits. Windows app-local WARP 1.0.22 and Agility 1.620.2 with Microsoft DXIL validation. All 32 project VALU tests pass, plus a temporary test confirming the loaded runtime modules and validator. Strict shader Clippy and the staged asset policy pass. The lowering explicitly reports unsupported output `clamp`/`omod`. [Coordination claim](https://git.gtahub.st/github/Marvisak--VIctory/issues/1633) If you cherry-pick or rebase this commit, please retain its Git author. If you fold the change into another commit, please 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:10:05 +00:00
Author
Owner

@⁠Mericas77 on GitHub · 2026-11-25 17:33 UTC · original

Tested on NVIDIA: RTX 4070, driver 621.01, Windows 11, rustc 1.100.0. Head 04c2d2b against main 67e8ae1.

  • v_trunc_f64_rounds_toward_zero_in_both_words and v_trunc_f64_rounds_a_negated_vop3_literal: pass. Both go through run_cases, which prints no SM 6.6 … skipped when a host is missing; nothing was printed, so they ran on the NVIDIA hardware adapter as well as WARP.
  • cargo test -p victory-shader --lib --locked (with --skip heap_direct_texture_reads_mark_their_heap_index, which crashes the process on main here too, #2571): main 266 passed / 3 failed / 3 ignored, this PR 268 / 3 / 3. The 3 failures are the known NVIDIA ones on main and are the same.

So the integer-only lowering gives the same bits on NVIDIA hardware, no regression. No game data; the title was not run.

AI-assisted.

**@⁠Mericas77** on GitHub · 2026-11-25 17:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/2600#issuecomment-7169683494) Tested on NVIDIA: RTX 4070, driver 621.01, Windows 11, rustc 1.100.0. Head `04c2d2b` against `main` `67e8ae1`. - `v_trunc_f64_rounds_toward_zero_in_both_words` and `v_trunc_f64_rounds_a_negated_vop3_literal`: **pass**. Both go through `run_cases`, which prints `no SM 6.6 … skipped` when a host is missing; nothing was printed, so they ran on the NVIDIA hardware adapter as well as WARP. - `cargo test -p victory-shader --lib --locked` (with `--skip heap_direct_texture_reads_mark_their_heap_index`, which crashes the process on `main` here too, #2571): `main` 266 passed / 3 failed / 3 ignored, this PR 268 / 3 / 3. The 3 failures are the known NVIDIA ones on `main` and are the same. So the integer-only lowering gives the same bits on NVIDIA hardware, no regression. No game data; the title was not run. AI-assisted.
Author
Owner

@⁠andrewpozdnakov7-jpg on GitHub · 2026-11-25 21:56 UTC · original

I resolved the merge conflicts in 32f9d85, keeping the original truncation commit and the upstream 64-bit integer compare helper and legacy multiply test.

On merged main 129a9ba, both V_TRUNC_F64 WARP fixtures pass, including the SGPR/VGPR inputs and the negated VOP3 literal. All 38 VALU checks pass including the temporary app-local WARP identity check, with DXIL validation enabled. Strict shader Clippy in both configurations and staged policy pass. git merge-tree is clean with 4989260.

Please retain the Git author if moving the original change, or keep this trailer if it is folded into another commit.

Co-authored-by: andrewpozdnakov7-jpg [email protected]

AI-assisted with Codex.

**@⁠andrewpozdnakov7-jpg** on GitHub · 2026-11-25 21:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2600#issuecomment-7175733150) I resolved the merge conflicts in [32f9d85](https://github.com/andrewpozdnakov7-jpg/VIctory/commit/32f9d85798c7a168eac2ad38c2e03eeafbcf0656), keeping the original truncation commit and the upstream 64-bit integer compare helper and legacy multiply test. On merged main `129a9ba`, both `V_TRUNC_F64` WARP fixtures pass, including the SGPR/VGPR inputs and the negated VOP3 literal. All 38 VALU checks pass including the temporary app-local WARP identity check, with DXIL validation enabled. Strict shader Clippy in both configurations and staged policy pass. `git merge-tree` is clean with `4989260`. Please retain the Git author if moving the original change, or keep this trailer if it is folded into another commit. Co-authored-by: andrewpozdnakov7-jpg <[email protected]> AI-assisted with Codex.
Author
Owner

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

Automated triage for the maintainers.

This adds lowering for v_trunc_f64 (VOP1 0x17 / VOP3 0x197; it was decoded but rejected before) in the new crates/victory-shader/src/emit/lower/trunc.rs (Lower::trunc_f64), with the RDNA 2 ISA cited as the reference. It truncates by masking the fraction bits with 32-bit integer operations. I checked the mask boundaries: exponents below 1023 give a signed zero, 1023-1042 mask the high word and zero the low word, 1043-1074 mask the low word, and 1075 or more pass through unchanged. That covers inf/NaN; NaNs are passed through bit-for-bit, not quieted. The operand handling also looks right: a literal is the high dword, float inline constants are widened to f64, and integer inline constants are sign-extended. The tests in valu_tests.rs compare against f64::trunc across the word boundaries, signed zero, subnormals and a negated VOP3 literal. CI: passing (check). This is a recommendation for a maintainer to look, not an approval.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 23:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/2600#issuecomment-7177388664) <!-- victory-triage v1 head=dd01a41c622e8a437b02b9b688036592ff971b1d verdict=merge-candidate at=2026-11-25T23:18:22Z --> Automated triage for the maintainers. This adds lowering for `v_trunc_f64` (VOP1 0x17 / VOP3 0x197; it was decoded but rejected before) in the new `crates/victory-shader/src/emit/lower/trunc.rs` (`Lower::trunc_f64`), with the RDNA 2 ISA cited as the reference. It truncates by masking the fraction bits with 32-bit integer operations. I checked the mask boundaries: exponents below 1023 give a signed zero, 1023-1042 mask the high word and zero the low word, 1043-1074 mask the low word, and 1075 or more pass through unchanged. That covers inf/NaN; NaNs are passed through bit-for-bit, not quieted. The operand handling also looks right: a literal is the high dword, float inline constants are widened to f64, and integer inline constants are sign-extended. The tests in `valu_tests.rs` compare against `f64::trunc` across the word boundaries, signed zero, subnormals and a negated VOP3 literal. CI: passing (check). This is a recommendation for a maintainer to look, not an approval. --- _Generated by [Claude Code](https://claude.ai/code)_
Author
Owner

@⁠fuzeofficlal on GitHub · 2026-11-26 18:02 UTC · original · approved these changes

Looks good. Verified merged onto main (63bcca43) on an RTX 5090, Microsoft WARP, and Windows SDK dxil.dll:

  • The 32-bit integer bit-masking lowering in crates/victory-shader/src/emit/lower/trunc.rs handles every exponent band (< 1023, 1023..1043, 1043, 1044..1075, >= 1075) cleanly, masks shift counts with & 31 (trunc.rs:70) to avoid shift-width UB, preserves signed zeros, and avoids setting DOUBLES or INT64 shader feature bits (SFI0 & 0x8021 == 0).
  • cargo xtask policy (192 files ok; crates/victory-shader/src/emit/lower.rs = 520,632 B < 524,288 B) and cargo clippy --locked -p victory-shader --all-targets -- -D warnings (default and --all-features) pass.
  • Both PR tests (v_trunc_f64_rounds_toward_zero_in_both_words and v_trunc_f64_rounds_a_negated_vop3_literal) pass on RTX 5090 and WARP with dxil.dll validation.
  • Additional probes verified 70 exponent/bit-boundary inputs across disjoint VGPR, SGPR pair, in-place (v[1:2] -> v[1:2]), and overlapping (v[1:2] -> v[2:3]) register pairs, 15 VOP3 source/modifier cases (abs, neg, high-word literal, inline floats 240..=248, inline ints, NULL), and rejection of clamp and omod = 1/2/3 on both RTX 5090 and WARP.

(Non-blocking note: signaling NaNs pass through with their raw bit pattern unchanged rather than setting the quiet bit 0x0008_0000 in the high word.)

**@⁠fuzeofficlal** on GitHub · 2026-11-26 18:02 UTC · [original](https://github.com/Marvisak/VIctory/pull/2600#pullrequestreview-6078732601) · **approved these changes** Looks good. Verified merged onto `main` (`63bcca43`) on an RTX 5090, Microsoft WARP, and Windows SDK `dxil.dll`: - The 32-bit integer bit-masking lowering in `crates/victory-shader/src/emit/lower/trunc.rs` handles every exponent band (`< 1023`, `1023..1043`, `1043`, `1044..1075`, `>= 1075`) cleanly, masks shift counts with `& 31` (`trunc.rs:70`) to avoid shift-width UB, preserves signed zeros, and avoids setting `DOUBLES` or `INT64` shader feature bits (`SFI0 & 0x8021 == 0`). - `cargo xtask policy` (`192 files ok`; `crates/victory-shader/src/emit/lower.rs` = 520,632 B < 524,288 B) and `cargo clippy --locked -p victory-shader --all-targets -- -D warnings` (default and `--all-features`) pass. - Both PR tests (`v_trunc_f64_rounds_toward_zero_in_both_words` and `v_trunc_f64_rounds_a_negated_vop3_literal`) pass on RTX 5090 and WARP with `dxil.dll` validation. - Additional probes verified 70 exponent/bit-boundary inputs across disjoint VGPR, SGPR pair, in-place (`v[1:2] -> v[1:2]`), and overlapping (`v[1:2] -> v[2:3]`) register pairs, 15 VOP3 source/modifier cases (`abs`, `neg`, high-word literal, inline floats `240..=248`, inline ints, `NULL`), and rejection of `clamp` and `omod = 1/2/3` on both RTX 5090 and WARP. (Non-blocking note: signaling NaNs pass through with their raw bit pattern unchanged rather than setting the quiet bit `0x0008_0000` in the high word.)
Author
Owner

@⁠Dukestar69 on GitHub · 2026-11-26 18:31 UTC · original · approved these changes

LGTM — verified on RTX 5090 and VICTORY_WARP=1 (Windows / D3D12) against origin/main (63bcca4).

  • Lowering v_trunc_f64 using pure 32-bit bit manipulation keeps SFI0 double/int64 feature bits clear while accurately rounding toward zero across subnormals, 31/32/33-bit fractional tails, negated VOP3 literals, and infinities.
  • cargo test -p victory-shader --lib emit::valu_tests::v_trunc_f64 -- --test-threads=1: 2 passed, 0 failed on RTX 5090 and 2 passed, 0 failed on VICTORY_WARP=1.
  • 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).

**@⁠Dukestar69** on GitHub · 2026-11-26 18:31 UTC · [original](https://github.com/Marvisak/VIctory/pull/2600#pullrequestreview-6079012617) · **approved these changes** LGTM — verified on RTX 5090 and `VICTORY_WARP=1` (Windows / D3D12) against `origin/main` (`63bcca4`). - Lowering `v_trunc_f64` using pure 32-bit bit manipulation keeps `SFI0` double/int64 feature bits clear while accurately rounding toward zero across subnormals, 31/32/33-bit fractional tails, negated VOP3 literals, and infinities. - `cargo test -p victory-shader --lib emit::valu_tests::v_trunc_f64 -- --test-threads=1`: 2 passed, 0 failed on RTX 5090 and 2 passed, 0 failed on `VICTORY_WARP=1`. - `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).
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/2600/head:github-bot/gh-2600'
git switch 'github-bot/gh-2600'

Merge

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