Shaders: flush negative zero after output modifiers #1534

Closed
github-bot wants to merge 1 commit from gh-pr/1534/head into gh-pr/1534/base
Owner

@⁠Calvix2k on GitHub · 2026-11-24 18:52 UTC · original
Calvix2k:codex/shader-omod-positive-zero-044 → main · +31 −0 · 2 files · 1 commits · closed without merging

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

**@⁠Calvix2k** on GitHub · 2026-11-24 18:52 UTC · [original](https://github.com/Marvisak/VIctory/pull/1534) `Calvix2k:codex/shader-omod-positive-zero-044` → `main` · +31 −0 · 2 files · 1 commits · closed without merging ## 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
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:35:24 +00:00
github-bot closed this pull request 2026-11-26 04:35:24 +00:00
Author
Owner

@⁠marquezinii on GitHub · 2026-11-24 19:12 UTC · original

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.

**@⁠marquezinii** on GitHub · 2026-11-24 19:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7141767545) 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.
Author
Owner

@⁠tdogghockey on GitHub · 2026-11-24 19:27 UTC · original

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.

**@⁠tdogghockey** on GitHub · 2026-11-24 19:27 UTC · [original](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7142114879) 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.
Author
Owner

@⁠sinan-cmyk on GitHub · 2026-11-24 19:33 UTC · original

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).

**@⁠sinan-cmyk** on GitHub · 2026-11-24 19:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7142275775) ### 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).
Author
Owner

@⁠tdogghockey on GitHub · 2026-11-24 19:34 UTC · original

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.

**@⁠tdogghockey** on GitHub · 2026-11-24 19:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7142290338) 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.
Author
Owner

@⁠geiyiliyabumo on GitHub · 2026-11-24 19:40 UTC · original

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.

**@⁠geiyiliyabumo** on GitHub · 2026-11-24 19:40 UTC · [original](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7142436651) 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.*
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-24 22:01 UTC · original

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** on GitHub · 2026-11-24 22:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7145693566) 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.
Author
Owner

@⁠Calvix2k on GitHub · 2026-11-24 22:01 UTC · original

Closing as superseded by upstream 77053a0.

**@⁠Calvix2k** on GitHub · 2026-11-24 22:01 UTC · [original](https://github.com/Marvisak/VIctory/pull/1534#issuecomment-7145694048) Closing as superseded by upstream 77053a0.

Pull request closed

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