Shaders: pack half FMA NaNs directly #2943
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!2943
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2943"
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?
@Ingenioeren on GitHub · 2026-11-26 01:01 UTC · original
Ingenioeren:perf/f16-fma-nan-payload→main· +87 −9 · 3 files · 3 commits · openThe software nearest-even lowering of
v_fma_f16used the full f32-to-f16 rounding sequence as its NaN fallback. The fallback is selected only for NaNs, so it can pack the quiet bit and upper payload bits directly. The fused operation reuses the sign it already computed and shares the NaN packing code with the general conversion.v_fma_f16with runtime operandsThe count includes the shader's input and output instructions and uses the bitcode writer's live instruction layout. The regression fails at 118 with the old fallback and passes with a budget of 78 after the change. The test-only
Module::written_instructions()counter is the same helper as in open PR #2893, and whichever PR lands second will drop its copy on rebase. The open PR search for"fma_f16" "payload"found no duplicate of this change.Validation
cargo test --locked --offline -p victory-shaderon63bcca4gave 300 passed, 2 failed, 3 ignored. After the change it gave 302 passed, 2 failed, 3 ignored. Both runs had the same localdxil.dllpipeline-state validation failures inrectangles_get_their_fourth_cornerandelements_sharing_a_row_keep_their_order.cargo test --locked --offline -p victory-shader f16_fma_packs_nan_without_a_second_rounding_pathfailed at 118 instructions with the old fallback. The regression passed in the full run with the new lowering.cargo test --locked --offline -p victory-shader v_fma_f16 -- --nocapturepassed both GPU tests. The existing test covered rounding and preservation of the other half on the Radeon RX 6750 XT. The NaN test asserts the exact 32-bit results, in case order,0x00007E35,0x0000FE42,0x0000FE00,0x0000FE35, and0xABCD7E35. Theorigin/mainlowering and this branch produced identical results on the Radeon RX 6750 XT and WARP, including the negative signaling NaN and the preserved upper destination half.cargo test --locked --offline -p victory-shader --test resource_trackinggave 3 passed and 1 ignored.cargo test --locked --offline -p victory-shader --doccompleted with zero doc tests.cargo clippy --locked --offline -p victory-shader --all-targetspassed.cargo run --locked --offline -p xtask -- policy --stagedpassed for all three files in the original commit and for the staged test update in this revision.No game run or game shaders were used. GPU execution time was not measured.
AI assistance: prepared with OpenAI Codex under Claude Code's direction, reviewed by Ingenioeren.
@fuzeofficlal on GitHub · 2026-11-26 01:21 UTC · original
Code review and RTX 5090 + WARP + DXIL verification at head
83ff480c0448merged cleanly ontomain(63bcca43c6a0;emit/lower.rs=521,381B,2,907B under the 512 KiB cap):lower.rs:2290-2306, 2380-2384):narrow16_nan(magnitude)and using it directly infma_f16avoids emitting a second fullnarrow16normalization/rounding/overflow path while preserving exact behavioral parity withmain.emit::lower::tests(34/34, includingf16_fma_packs_nan_without_a_second_rounding_path) andemit::semantics_tests(34/34 on both RTX 5090 and WARP) pass, as doclippyandcargo xtask policy(191 files ok).emit::valu_tests::v_fma_f16_quiets_nans,valu_tests.rs:444-463):hardwarecase 0:[0x7c35, 0x3c00, 0, 0],sNaN * 1.0 + 0.0), the new test panics atvalu_tests.rs:458:9:actual = 0x00007fff,expected = 0x00007e35fma_f16widens inputs vialegacyF16ToF32and runs f32FMul/FAddbefore extracting the payload, NVIDIA's D3D12/SASS pipeline canonicalizes f32 NaN results to0x7FFF_FFFF, whichnarrow16_nanpacks to0x7FFFrather than preserving the input payload0x35.narrow16_nan; relaxing the GPU assertion inv_fma_f16_quiets_nansto check for a quiet f16 NaN (e.g.(actual & 0x7E00) == 0x7E00and upper half preserved) — or checking exact payload only where deterministic — will make the test portable across NVIDIA hardware too.@Ingenioeren on GitHub · 2026-11-26 02:41 UTC · original
Thanks, @fuzeofficlal and @Dukestar69, for testing this on the RTX 5090 and reporting the NaN mismatch.
In
b628ad9bce082e08185676040e4506f773fbdceb, the f16 FMA NaN test still checks the exact result on WARP. The hardware check accepts any quiet f16 NaN (any sign, any payload) and checks the upper 16 bits exactly.The NaN test passed on the AMD Radeon RX 6750 XT and WARP. All 36 targeted shader tests passed, along with Clippy and the asset policy check. We did not test on NVIDIA.
@Marvisak on GitHub · 2026-11-26 04:28 UTC · original
Automated triage for the maintainers.
Merge candidate. The full
narrow16(sum)fallback infma_f16(emit/lower.rs) becomes anarrow16_nan(magnitude)helper thatnarrow16also uses. The output is unchanged: the old fallback only mattered for NaN sums, andnarrow16on a NaN givessign | 0x7E00 | payload>>13, exactly the new form; the DXIL drops from 118 to 78 instructions. The exact 0xFE00 for infinity times zero inv_fma_f16_quiets_nansis WARP's default NaN, not confirmed console behaviour, so it should not be read as a spec. The test-onlyModule::written_instructionsduplicates the one in #2893; whichever lands second should drop its copy.CI: passing.
Generated by Claude Code
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.