Shaders: flush negative zero after output modifiers #1533

Closed
Calvix2k wants to merge 1 commit from upstream-pr/1534 into main
Calvix2k commented 2026-11-24 18:52:42 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T18:52:42Z.


Summary

Fixes VIC-BT-044 from audit issue #1249.

RDNA 2 specifies that active output modifiers flush negative zero to positive zero. The translator modeled mul:2, mul:4, and div:2 as ordinary floating-point multiplication, which preserves the negative-zero sign bit. It now clears exactly the 0x80000000 result after an output modifier and before the optional clamp.

A synthetic v_add_f32_e64 shader checks -0 + -0 with mul:4 and expects the output bits for positive zero.

Verification

  • Focused regression test: compiled and passed; execution skipped because this machine's hardware and WARP do not expose Shader Model 6.6.
  • cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings — clean
  • cargo xtask policy --staged — passed
  • git diff --check — passed

The RDNA 2 ISA says output modifiers flush -0 to +0 when enabled: https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf

<!-- greyfinch-sync:Marvisak/VIctory:issue:6589077826 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1534). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T18:52:42Z. --- ## Summary Fixes `VIC-BT-044` from audit issue #1249. RDNA 2 specifies that active output modifiers flush negative zero to positive zero. The translator modeled `mul:2`, `mul:4`, and `div:2` as ordinary floating-point multiplication, which preserves the negative-zero sign bit. It now clears exactly the `0x80000000` result after an output modifier and before the optional clamp. A synthetic `v_add_f32_e64` shader checks `-0 + -0` with `mul:4` and expects the output bits for positive zero. ## Verification - Focused regression test: compiled and passed; execution skipped because this machine's hardware and WARP do not expose Shader Model 6.6. - `cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings` — clean - `cargo xtask policy --staged` — passed - `git diff --check` — passed The RDNA 2 ISA says output modifiers flush `-0` to `+0` when enabled: https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf
DenRakEiw commented 2026-11-24 19:03:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-24T18:56:58Z.

Review: APPROVED


Verified locally merged onto origin/main (Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC):

  • cargo test -p victory-shader --lib vop3_output_modifier_flushes_negative_zero — passed on RTX 5090 hardware and under VICTORY_D3D12_WARP=1
  • cargo clippy -p victory-shader --all-targets — 0 warnings
  • cargo xtask policy — ok

Clean bit-exact -0.0 flush to +0.0 after VOP3 output modifiers with end-to-end GPU+WARP verification. Looks good.

AI-assisted (Gemini 4 Neon).

<!-- greyfinch-sync:Marvisak/VIctory:review:6045438165 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1534#pullrequestreview-6045438165). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-24T18:56:58Z. **Review:** APPROVED --- Verified locally merged onto `origin/main` (Windows 11 x64, NVIDIA GeForce RTX 5090 + WARP, Rust 1.98.1 MSVC): - `cargo test -p victory-shader --lib vop3_output_modifier_flushes_negative_zero` — passed on RTX 5090 hardware and under `VICTORY_D3D12_WARP=1` - `cargo clippy -p victory-shader --all-targets` — 0 warnings - `cargo xtask policy` — ok Clean bit-exact `-0.0` flush to `+0.0` after VOP3 output modifiers with end-to-end GPU+WARP verification. Looks good. AI-assisted (Gemini 4 Neon).
marquezinii commented 2026-11-24 20:03:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by marquezinii on 2026-11-24T19:12:56Z.


Your machine didn't have SM 6.6, so here is the run: RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1, head acd09cc. cargo test -p victory-shader --lib -- --test-threads=1 --nocapture gives 121 passed, 0 failed, 1 ignored. vop3_output_modifier_flushes_negative_zero ran on the hardware adapter and WARP (no skip) and passes: -0 + -0 with mul:4 comes back as +0 on both.

That this is the hardware rule, and not just what the test expects, also agrees with LLVM's AMDGPU backend: it only folds a multiply into omod when signed zeros don't matter.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7141767545 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7141767545). Originally posted by [marquezinii](https://github.com/marquezinii) on 2026-11-24T19:12:56Z. --- Your machine didn't have SM 6.6, so here is the run: RTX 5070 (desktop, driver 621.40, the only adapter), Windows 11 26300, Rust 1.98.1, head `acd09cc`. `cargo test -p victory-shader --lib -- --test-threads=1 --nocapture` gives 121 passed, 0 failed, 1 ignored. `vop3_output_modifier_flushes_negative_zero` ran on the hardware adapter and WARP (no skip) and passes: `-0 + -0` with `mul:4` comes back as `+0` on both. That this is the hardware rule, and not just what the test expects, also agrees with LLVM's AMDGPU backend: it only folds a multiply into `omod` when signed zeros don't matter.
tdogghockey commented 2026-11-24 20:03:10 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tdogghockey on 2026-11-24T19:27:04Z.


I independently reviewed this PR at head acd09cc on aarch64 Linux.

  • cargo test --offline -p victory-shader --locked — 96 passed, 0 failed, 1 ignored.
  • cargo check --offline -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc — clean; the same check on base ffe310e is also clean.
  • cargo clippy --offline -p victory-shader --all-targets --locked -- -D warnings reports the same two pre-existing unused-import errors in emit/mod.rs on base, so I do not attribute them to this change.

The new regression test is in emit::valu_tests, which is #[cfg(all(test, windows))], so it could not execute on this Linux host. I verified the changed code compiles for the Windows target but did not execute the GPU/D3D12 test or CI. From source inspection, the flush is applied after omod and before clamp, and the 0x80000000 compare is on the integer bit pattern, matching the stated RDNA2 behavior.

No correctness issue found in the parts verifiable here. No approval implied.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142114879 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7142114879). Originally posted by [tdogghockey](https://github.com/tdogghockey) on 2026-11-24T19:27:04Z. --- I independently reviewed this PR at head `acd09cc` on aarch64 Linux. - `cargo test --offline -p victory-shader --locked` — 96 passed, 0 failed, 1 ignored. - `cargo check --offline -p victory-shader --all-targets --locked --target x86_64-pc-windows-msvc` — clean; the same check on base `ffe310e` is also clean. - `cargo clippy --offline -p victory-shader --all-targets --locked -- -D warnings` reports the same two pre-existing unused-import errors in `emit/mod.rs` on base, so I do not attribute them to this change. The new regression test is in `emit::valu_tests`, which is `#[cfg(all(test, windows))]`, so it could not execute on this Linux host. I verified the changed code compiles for the Windows target but did not execute the GPU/D3D12 test or CI. From source inspection, the flush is applied after `omod` and before `clamp`, and the `0x80000000` compare is on the integer bit pattern, matching the stated RDNA2 behavior. No correctness issue found in the parts verifiable here. No approval implied.
sinan-cmyk commented 2026-11-24 20:03:12 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by sinan-cmyk on 2026-11-24T19:33:48Z.


Offline measurement on a retail dump, and the shader tests on Ada

Result: no count changes against main, and the tests pass on Ada.

Offline. I merged head acd09cc onto main ffe310e (clean merge) and ran victory translate --validate --list on shaders.rpf (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with main program by program (25,889 programs). Validated: 21,724 on both, 0 gained, 0 lost. No program changes its failure reason either.

This is the expected result for a correctness fix whose instructions sit behind the earlier failures on main. The count shows that the change rejects nothing. It does not show whether the output is right.

Tests. With the same merge, cargo test --locked -p victory-shader --lib passed 121, failed 0. The bitcode benchmark is ignored, as on main, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with VICTORY_WARP unset.

No shader names or data are included, per the asset policy. AI-assisted (Claude Code).

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142275775 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7142275775). Originally posted by [sinan-cmyk](https://github.com/sinan-cmyk) on 2026-11-24T19:33:48Z. --- ### Offline measurement on a retail dump, and the shader tests on Ada **Result: no count changes against `main`, and the tests pass on Ada.** **Offline.** I merged head acd09cc onto `main` ffe310e (clean merge) and ran `victory translate --validate --list` on `shaders.rpf` (1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result with `main` program by program (25,889 programs). Validated: 21,724 on both, 0 gained, 0 lost. No program changes its failure reason either. This is the expected result for a correctness fix whose instructions sit behind the earlier failures on `main`. The count shows that the change rejects nothing. It does not show whether the output is right. **Tests.** With the same merge, `cargo test --locked -p victory-shader --lib` passed 121, failed 0. The bitcode benchmark is ignored, as on `main`, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, with `VICTORY_WARP` unset. No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
tdogghockey commented 2026-11-24 20:03:13 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by tdogghockey on 2026-11-24T19:34:24Z.


Thanks for running this on real hardware and WARP — that fills exactly the gap I had on this Linux host. My note was limited to the Linux-side checks and the Windows-target compile, so it's good to have the -0 + -0 with mul:4 result confirmed on both adapters.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142290338 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7142290338). Originally posted by [tdogghockey](https://github.com/tdogghockey) on 2026-11-24T19:34:24Z. --- Thanks for running this on real hardware and WARP — that fills exactly the gap I had on this Linux host. My note was limited to the Linux-side checks and the Windows-target compile, so it's good to have the `-0 + -0` with `mul:4` result confirmed on both adapters.
geiyiliyabumo commented 2026-11-24 20:03:16 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by geiyiliyabumo on 2026-11-24T19:40:46Z.


Verified commit acd09cc on Windows 11 / AMD Radeon RX 9060 XT (RDNA4, gfx1200, SM 6.6) + WARP:

  • cargo test -p victory-shader --lib: 121 passed, 0 failed, 1 ignored (including the new output-modifier negative-zero flush GPU test).

AI-assisted; synthetic tests only, no game files.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7142436651 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7142436651). Originally posted by [geiyiliyabumo](https://github.com/geiyiliyabumo) on 2026-11-24T19:40:46Z. --- Verified commit `acd09cc` on **Windows 11 / AMD Radeon RX 9060 XT (RDNA4, `gfx1200`, SM 6.6)** + **WARP**: - `cargo test -p victory-shader --lib`: **121 passed, 0 failed, 1 ignored** (including the new output-modifier negative-zero flush GPU test). *AI-assisted; synthetic tests only, no game files.*
Calvix2k commented 2026-11-24 22:02:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T22:01:11Z.


Superseded by upstream 77053a0 (“accuracy fixes for discards, f16 rounding, denormals, med3 and signed zeros”), which landed after this PR was opened. write_f now applies the output modifier on the flushed value and selects positive zero whenever the result's exponent is zero, so -0 from mul:2/mul:4/div:2 no longer survives. The regression this PR adds is covered by upstream's behaviour; closing to avoid a duplicate conflict. Thanks for the original analysis and test.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145693566 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7145693566). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T22:01:11Z. --- Superseded by upstream 77053a0 (“accuracy fixes for discards, f16 rounding, denormals, med3 and signed zeros”), which landed after this PR was opened. write_f now applies the output modifier on the flushed value and selects positive zero whenever the result's exponent is zero, so -0 from mul:2/mul:4/div:2 no longer survives. The regression this PR adds is covered by upstream's behaviour; closing to avoid a duplicate conflict. Thanks for the original analysis and test.
Calvix2k commented 2026-11-24 22:02:29 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Calvix2k on 2026-11-24T22:01:13Z.


Closing as superseded by upstream 77053a0.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7145694048 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7145694048). Originally posted by [Calvix2k](https://github.com/Calvix2k) on 2026-11-24T22:01:13Z. --- Closing as superseded by upstream 77053a0.
upstream-sync closed this pull request 2026-11-24 23:04:41 +00:00

Pull request closed

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!1533
No description provided.