Shaders: the neg input modifier flips a NaN's sign too #2823
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!2823
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2823"
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?
@xKineticK on GitHub · 2026-11-25 21:31 UTC · original
xKineticK:fix/neg-modifier-flips-nan-sign→main· +43 −8 · 2 files · 1 commits · openThe
negsource modifier was lowered as-0.0 - x. IEEE 754 leaves the sign of a NaN produced by a subtraction to the host, and WARP keeps it, so a negated NaN reached the instruction with its original sign. On the console the modifier flips bit 31 alone, NaN or not (RDNA2 ISA).The floor conversions make it visible, because they saturate a NaN by its sign:
v_cvt_rpi_i32_f32 v5, -v1, v1 =0x7fc00000to_i32_floorof-NaN)0x800000000x800000000x7fffffffHow it was found
#1614's VALU fuzzer, merged onto
main(13f91ca), withVICTORY_FUZZ_MODS=1and 200 inputs per opcode on the RX 7900 XTX against WARP. Only two results were new beyond the 17 known disagreements, and neither appears without modifiers:v_cvt_rpi_i32_f32, neg src0: 20 of 200 inputs differ;v_cvt_flr_i32_f32, neg src0: 9 of 200 inputs differ.All of the differing inputs are NaNs. This is separate from the Intel UHD finding reported on #1614 (NaN gives 0 there, without modifiers).
Change
Lower::fnegnegates by XOR-ing the sign bit on the integer bits, which gives the same result on every host.neginput modifier was a subtraction:fsrc);v_fma_mix*sources;Related, no overlap: #2548 makes
v_mov_b32's modifiers bitwise on the integer path.Test
semantics_tests::source_modifiers_set_the_sign_of_a_nanruns both floor conversions withabs,negand-|x|onF32_EDGES. It compares against the existingto_i32_floormodel on the hardware adapter and on WARP.Checks
Windows 11, AMD Radeon RX 7900 XTX (driver 32.0.32029.2010), and WARP:
cargo test --workspace --locked: 780 passed, 0 failed.--all-targets, with and without--all-features,-D warnings): clean.cargo xtask policy: ok.cargo fmt --checkreports nothing in the two changed files.VICTORY_FUZZ_MODS=1, 400 inputs, onv_cvt_{flr,rpi}_i32_f32andv_cvt_{i32,u32}_f32: 0 differ.Not tested: NVIDIA and Intel adapters. I also did not rerun the full 23-minute fuzzer with the fix. Per the floor-conversion test's own note, the title uses neither conversion, so the gain is hosts agreeing, including CI's WARP, rather than a visible change in the game.
🤖 Generated with Claude Code
@cloph-dsp on GitHub · 2026-11-25 21:37 UTC · original
Local verification on Windows / rustc 1.100.0 / MSVC, synthetic inputs only, no game data; GPU tests allowed here (hardware + WARP), no clippy/rustup.
cargo test --locked -p victory-shader --lib source_modifiers_set_the_sign_of_a_nan --quiet-> 1 passed, 0 failed (273 filtered out), with CARGO_BUILD_JOBS=2. The test covers both the hardware adapter and WARP,abs/neg/-|x|on F32_EDGES and both floor conversions.git diff --check origin/main..HEADclean; diff is 2 files +43/-8 (emit/lower.rs,emit/semantics_tests.rs).source_modifiers_set_the_sign_of_a_nanis absent from origin/main, so the test is new here.Lower::fnegflips the sign bit on integer bits, replacing the subtraction that left a NaN sign host-dependent.AI-assisted (Hy4 flash).
@fuzeofficlal on GitHub · 2026-11-25 21:48 UTC · original
Verified
74b15542on Windows 11 (RTX 5090 + WARP + Windows SDK10.0.26100.0dxil.dll):cargo xtask policy: 184 files ok;cargo clippy --locked -p victory-shader --all-targets -- -D warnings(default &--features host): 0 warnings.dxil.dll:source_modifiers_set_the_sign_of_a_nan1/1 passed (0 hardware/WARP diff),floor_conversions_match_the_hardware1/1 passed,emit::lower::tests27/27 passed.Lower::fnegcovers all 4 float inputnegmodifier sites (fsrc,fma_mix,half_fsrc,packed16) withabsapplied beforefneg.git merge-treeagainstorigin/main, #1327, and #2081 (1-line adjacent context overlap with #2548 atlower.rs:2075-2085, zero semantic conflict).@Marvisak on GitHub · 2026-11-26 02:22 UTC · original
Automated triage for the maintainers.
The
negsource modifier was lowered as-0.0 - x, which leaves a NaN's sign to the host.Lower::fnegnow XORs bit 31 on the integer bits, as RDNA2's modifier does, at the f32,v_fma_mix, f16-as-f32 and packed sources. The evidence is a fuzzer disagreement onv_cvt_rpi/flr_i32_f32reproduced on an RX 7900 XTX against WARP, andsource_modifiers_set_the_sign_of_a_nanmodels it. The XOR also avoids any flushing a subtraction could do to a denormal input, which matches a pure sign modifier.CI: passing.
Generated by Claude Code
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 04:24 UTC · original
I checked whether this fix also covers
v_cvt_f32_f16when the widened result is stored as raw bits. The same synthetic test checks all 2,046 NaN encodings and 14 finite, zero and infinity controls in each of six instruction forms. It uses the project's IEEE-off model and the published RDNA2 widening measurements.main63bcca43gives 2,046 wrong results in each ofNEGand high-halfABS+NEG. For example,NEG(0x7c01)gives0x7fc02000, expected0xff802000. The four other forms pass.74b15542combined with63bcca43passes all 12,360 cases per test slot. Your original floor-conversion test passes too. Both slots used app-local D3D12 WARP (SM 6.6) with DXIL validation on this host.The optional test-only commit
df1d930adds that widening coverage. Its parent is a clean merge of your exact commit and currentmain. Please keep the Git author if you cherry-pick or rebase it. If you fold the test into a commit, please addCo-authored-by: andrewpozdnakov7-jpg <[email protected]>.View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.