Shaders: flush negative zero after output modifiers #1534
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!1534
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1534/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@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 mergingSummary
Fixes
VIC-BT-044from audit issue #1249.RDNA 2 specifies that active output modifiers flush negative zero to positive zero. The translator modeled
mul:2,mul:4, anddiv:2as ordinary floating-point multiplication, which preserves the negative-zero sign bit. It now clears exactly the0x80000000result after an output modifier and before the optional clamp.A synthetic
v_add_f32_e64shader checks-0 + -0withmul:4and expects the output bits for positive zero.Verification
cargo clippy -p victory-shader --all-targets --all-features --locked -- -D warnings— cleancargo xtask policy --staged— passedgit diff --check— passedThe RDNA 2 ISA says output modifiers flush
-0to+0when enabled: https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf@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 --nocapturegives 121 passed, 0 failed, 1 ignored.vop3_output_modifier_flushes_negative_zeroran on the hardware adapter and WARP (no skip) and passes:-0 + -0withmul:4comes back as+0on 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
omodwhen signed zeros don't matter.@tdogghockey on GitHub · 2026-11-24 19:27 UTC · original
I independently reviewed this PR at head
acd09ccon 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 baseffe310eis also clean.cargo clippy --offline -p victory-shader --all-targets --locked -- -D warningsreports the same two pre-existing unused-import errors inemit/mod.rson 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 afteromodand beforeclamp, and the0x80000000compare 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 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
acd09ccontomainffe310e(clean merge) and ranvictory translate --validate --listonshaders.rpf(1.0.2.1), with dxil.dll 1.8.2502.11. I compared the result withmainprogram 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 --libpassed 121, failed 0. The bitcode benchmark is ignored, as onmain, where 120 pass. The run was on an RTX 4070 SUPER (Ada, 32-lane waves, driver 32.0.16.1088), the default adapter, withVICTORY_WARPunset.No shader names or data are included, per the asset policy. AI-assisted (Claude Code).
@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 + -0withmul:4result confirmed on both adapters.@geiyiliyabumo on GitHub · 2026-11-24 19:40 UTC · original
Verified commit
acd09ccon 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 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
Closing as superseded by upstream
77053a0.Pull request closed