Repository navigation
fix(shader): flush v_rcp_f32 denormal results to a signed zero - #22309
oneandonlydean merged 2 commits into
Conversation
RDNA2 returns a zero of the result's sign from v_rcp_f32 and v_rcp_iflag_f32 whenever the reciprocal is below 2^-126, in every FLOAT_MODE f32 denormal mode and IEEE mode. The recompiler kept the driver's denormal 1/x, so inputs above 2^126 in magnitude gave a denormal where the hardware gives zero. Measured on gfx1036 with the hardware oracle; the new execution test pins those rows for FLOAT_MODE 0xc0 and 0xf0. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The default v_rcp_f32 lowering is the driver's 1/x, which Vulkan allows 2.5 ulp of error. A result other than the RDNA 2 value now passes when it is a normal value within that bound of the exact reciprocal, or a signed zero when the bound reaches below 2^-126; a denormal result still fails. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Ran the new test and the existing Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor
No new AI-assisted: yes (Claude Code) |
|
Head No new failures and no new validation messages on either GPU.
Layer runs used AI-assisted: yes |
|
AMD driver data for this, on RDNA4 with AMD's Windows driver: the new test passes with and without the fix here, so this driver already returns the RDNA 2 values. Setup: Windows 10 22H2, AMD Radeon RX 9070 XT (RDNA4,
AI-assisted: yes (Claude Code) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
The reciprocal result flush and its execution coverage are consistent with the reported RDNA2 behavior; no blocking defect was verified in the changed code.
What I ran
Reviewed head a1efda1d9f0f1f9f1fba176718b7024e47dbeb63. No build or tests were run. I read description.md, commits.md, manifest.json, diff.patch, the full text of all three changed files, and targeted surrounding code in FloatInstructions.cpp. All files marked reviewed in the manifest were read; there were no excluded changed files.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed files | passed | All three changed files read |
| Targeted caller context | passed | Unary lowering path checked |
| Tests | not run | No commands executed |
| PS5 hardware behavior | not run | Description says gfx1013 was not measured |
Findings
Blocking
None.
Non-blocking
None.
Not verified
Build/test execution and behavior on PS5 gfx1013 were not verified. The hardware measurements and test runs in the description are author-reported, not runs performed in this review.
To get this to a good state
Nothing is required.
|
Tested on Intel Arc B390 (Mesa 26.2.7 ANV, Linux 7.2.10), PR head
AI-assisted: yes (Claude Code) |
What
On RDNA2,
v_rcp_f32andv_rcp_iflag_f32return a zero of the result's sign whenever the reciprocal is below 2^-126, that is for every input above 2^126 in magnitude. This holds in both f32 denormal modes ofFLOAT_MODE(flushed, 0xc0, and kept, 0xf0), at IEEE=0 and IEEE=1, and also through a negated VOP3 source. The recompiler kept the driver's denormal1/x, so on lavapipe (and on any driver that keeps f32 denormals)v_rcp_f32(0x7f7fffff)gave0x00200000where the hardware gives0x00000000.unaryFloatSpecialsalready treats a denormal input of these ops as zero. This adds the matching result flush forFPRecip32andFPRecipIFlag32: a result below 2^-126 in magnitude becomes the zero of its sign. It covers the default path and theAPS5_EXACT_RCPpath, which passes non-normal results to the driver's1/x.v_rcp_f16already matches the hardware in both f16 denormal modes, and the extra check cannot fire for it: its f32 intermediate is never denormal. The pixel shader's position W reciprocal does not go throughunaryFloatSpecialsand is unchanged.Measurement: hardware oracle on an AMD Radeon Graphics iGPU (Ryzen 7 9700X, gfx1036), AMD Windows driver 32.0.21042.62, HIP runtime. The same body and rows run through
agc_oracle_runner(lavapipe) showed the difference. The PS5's gfx1013 is not measured.v_rcp_f320x7e800000(2^126)0x008000000x008000000x008000000x7e8000010x000000000x007fffff0x000000000x7f0000000x000000000x004000000x000000000x7f7fffff0x000000000x002000000x000000000xff7fffff0x800000000x802000000x80000000Before the fix the oracle shows the difference in all four combinations of f32 denormal field (0 and 3) and IEEE mode, so titles on the default flushed mode are affected too. The hardware flushes the result before the output modifier and clamp: with the fix,
mul:2,mul:4,div:2,clampand|x|forms over 32 inputs between 2^124 and 2^128 match the hardware in every mode, except the documented 1-ULP approximation rows and one case this change does not touch. With f32 denormals kept and IEEE mode off, gfx1036 applies the output modifier tov_rcp_f32where the translation ignores it, before and after this change.The new execution test
RcpDenormalResultpins 32 measured rows forv_rcp_f32,v_rcp_iflag_f32andv_rcp_f32_e64with a negated source, under FLOAT_MODE 0xc0 and 0xf0. The rows are the denormal range plus the normal boundary (0x7e800000,0x7e7fffff,0x7e000001), zeros, infinities and denormal inputs. The default lowering is the driver's 1/x, which Vulkan allows 2.5 ulp of error. A result other than the RDNA 2 value is therefore accepted if it has the sign of 1/x and is either:A denormal result always fails. I checked the rule on the host against the table:
±0x7e800001, whose exact reciprocal is a fraction of an ulp below 2^-126.I assembled the kernel words with AMD's comgr for gfx1036.
The debt fragment adds the measured behaviour. It also records that
v_rcp_f64still keeps a denormal result with f64 denormals flushed, where the same GPU returns a signed zero. That case is left for a separate change.Tested
Linux (WSL2 Ubuntu 24.04), GCC, Release, lavapipe. Rebased on
main9b7afdd507, where the fullctest -j 14gives 5997 of 6002. The failures are the same five tests as below;guest_audio_in_status_reroute_shared_boundspasses 3 of 3 runs on its own. Before the rebase, onmaine51ae59fb4:agc_driver_rcp_denormal_resultwithout the fix:v_rcp_f32 of 0x7e800001 with FLOAT_MODE 0x000000f0 is 0x007fffff, expected the RDNA 2 value 0x00000000. With the fix: passes.APS5_EXACT_RCP=1and withAPS5_SPIRV_OPT=fullandnone.agc_driver_rcp_hardware_exactpasses before and after.ctest -j 14: 5985 of 5991 pass. The 6 failures are the same with the fix reverted on the same base, in 3 runs each:agc_driver_image_table_packed_guardsfails onmain(test(agc): keep the packed image table guard programs at different addresses #21255).agc_hook_clear_access,agc_hook_clear_access_offandagc_driver_recorderfail onmainon lavapipe (agc_hook_clear_access fails on Linux when host imports are compared: a pending image's results are dropped #21627).guest_kernel_pipe_boundshits SIGPIPE in this environment.guest_audio_in_status_reroute_shared_boundsfailed once under the parallel run and passes on its own.python3 tools/pr_overlap.py --branch fix/shader-rcp-f32-denormal-result: the only shared file whose comparison could not finish isFloatInstructions.cppwith perf(shader): keep the device's f32 NaN result behind an operand guard when a startup probe matches #20187. That PR changes the f32 NaN results of binary ops, notv_rcp.python3 tools/check_conventions.py --base origin/main: passed.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code