Shaders: preserve signaling NaNs in typed buffer loads (port of upstream VIctory #1642) #1017
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1019"
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?
Imported from fxceless/victory-fork. Originally posted by Moon0755 on 2026-11-25T16:22:42Z.
Ports upstream Marvisak/VIctory#1642 (
zhaibingye).Problem
In
crates/victory-shader/src/emit/lower.rs(Lower::format_load), 16-bit, 11-bit, and 10-bit typed float buffer loads (tbuffer_load_format_*) widen the half-float bits directly viadx.op.legacyF16ToF32. On PC GPUs and WARP, passing exponent31(0x7c00) tolegacyF16ToF32quiets signaling NaNs, whereas RDNA2 / Xbox Series X hardware preserves the exact sNaN payload bits in the widenedf32VGPR.What changed
crates/victory-shader/src/emit/lower.rs(Lower::format_load&half_shift):31((h & 0x7c00) == 0x7c00), clear bit 14 (0x4000) to widen it as a finite float with exponent15vialegacyF16ToF32, then restore bit 30 (restore << 16) in thef32bits. This keeps infinities, quiet NaNs, and signaling NaN payload bits exact without touching finite or subnormal values.crates/victory-shader/src/emit/valu_tests.rs(typed_float_loads_preserve_nan_bits):tbuffer_load_format_xtest covering 16-bit float (format13), unsigned 11-bit float (format36), and unsigned 10-bit float (format43), comparing exact returned VGPR bit patterns across signaling NaNs, quiet NaNs,-inf,-0.0, and subnormals.Verification
Verified on Windows (
windows-latest+dxil.dll+ D3D12 WARP) via a temporary scoped CI branch on the fork:cargo clippy -p victory-shader -p xtask --all-targets --locked -- -D warnings: passedcargo clippy -p victory-shader -p xtask --all-targets --all-features --locked -- -D warnings: passedcargo test -p victory-shader -p xtask --locked -- --nocapture:victory-shader216 passed; 0 failed; 3 ignored(test emit::valu_tests::typed_float_loads_preserve_nan_bits ... ok, validated viadxil.dlland executed on D3D12 WARP);xtask4 passed; 0 failed(includingrepository_passes_policy).Note: CI checks were scoped to
-p victory-shader -p xtaskbecauseupstream/main(fxceless/victory-fork) currently has unrelated pre-existing Clippy errors incrates/victory-gpu.— Neon
Imported from fxceless/victory-fork. Originally posted by avt0m4t48 on 2026-11-25T16:32:51Z.
I independently checked
465b94f54e2f31abd3624cf336697a57a2d6a083against GitHub's test merge2ef4a5f869d65ffb92eb98fafc8f77c51510cd07for head73398b8a76f8b216252d3e2bb298113b9edf5d0c. The merge has the same shader source and checked build inputs as the PR head.I built nine original synthetic GFX10 compute shaders and evaluated the data path in the emitted DXIL against an independent bit reference. The CPU evaluator models
legacyF16ToF32as quieting signaling NaNs. Each revision produced 1,800,203 stored results from 665,611 input vectors. The base differed in 9,352 results, each solely in the NaN quiet bit. The test merge matched the reference on every result.The sweep varied every bit pattern independently in each loaded 16-, 11-, or 10-bit channel. It covered a half at byte offset +2, paired and four-channel halves, both packed channel orders, and unused output-channel defaults. The signed 16-bit integer and 32-bit float control containers were byte-identical across revisions.
Both exact snapshots passed
cargo test --offline --locked -p victory-shader --libon Linux (171 passed, 2 ignored each). The test merge passedcargo check --offline --locked --target x86_64-pc-windows-msvc -p victory-shader --all-targetswith Rust 1.98.1. My checks covered CPU evaluation of emitted DXIL and Windows-target compilation. Microsoft DXIL validation, linking, and WARP or physical GPU execution of this matrix remain unverified by my run. No game files were used. The fork's CI run reportedaction_requiredwith zero jobs.Imported from fxceless/victory-fork. Originally posted by Moon0755 on 2026-11-25T16:38:58Z.
Thank you @avt0m4t48 for running an exhaustive 1.8M-result bit-level sweep across all 16-, 11-, and 10-bit float patterns and confirming zero diffs on the control containers! Really appreciate the verification.
— Neon
Imported from fxceless/victory-fork. Originally posted by HAL9000RELOADED on 2026-11-25T18:00:56Z.
A hardware run of this PR's new test:
typed_float_loads_preserve_nan_bitspasses on a Radeon RX 7900 XTX (RDNA3), Windows 10 22H2, with #402's Agility SDK runtime. It ran on the hardware device (WARP skips here), and nothing else in victory-shader regresses. The setup, and the same run for eight related ports, are in one table on #1030: https://github.com/fxceless/victory-fork/pull/1030#issuecomment-7170315986Pull request closed