rdna2spirv: flush v_exp_f32 denormal results (SHADER-EXP-F32-DENORM) #1587
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1587"
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 ubiquitarianism/leonida. Originally posted by exoticLgk on 2026-11-25T05:15:44Z.
Coordination
Claimed in the coordination issue as:
SHADER-EXP-F32-DENORMThe claim could not be posted because coordination issue #14 reached GitHub's 2,500-comment limit and no successor was found. Following the precedent in #1544, the claim is recorded here:
Searched existing claims and open PRs before implementation. No directly overlapping contribution was identified.
What and why
The RDNA2 hardware measurements documented in
docs/design.mdestablish thatv_exp_f32flushes denormal results, including when MODE requests denormal preservation.The translator previously emitted GLSL
Exp2without explicitly modelling this behaviour.This PR:
Gen.flush_f32to flush the rawv_exp_f32result before output modifiers.The semantic regression reproduces the following differences:
0x004000000x000000000x002000000x000000000x000000010x00000000Normal results at -125 and -126 remain unchanged.
Tested
c7e82e26e.Both GPU fixtures also pass without the translator change on the tested NVIDIA device. They establish GPU compatibility rather than a hardware-visible regression on this device. The semantic regression distinguishes the corrected implementation from the previous one.
Full GPU runs before the final rebase and addition of the second fixture:
The existing
cs_imgatomic_extfailure was reproduced without this patch on the earlier base and persisted after rebuilding on the updated base. PR #1518 appears relevant to that failure but was not tested here.Output modifier checks
Eight additional semantic probes were performed:
0x000000000x000000000x004000000x000000000x3f8000000x408000000x410000000x3f800000All eight match the intended implementation.
The existing hardware measurements in
docs/design.md, particularly the VOP3 modifier validation, support flushing denormal intermediate results before output modifiers.Post-scaling underflow remains outside this PR's scope because the exact
v_exp_f32boundary behaviour has not been independently established on native RDNA2.The existing
f32_fuzz.pyreference deliberately declines denormal exponential results. Its behaviour is left unchanged.Compatibility with #1231
PR #1231 addresses special results for other f32 transcendental instructions and explicitly leaves denormal handling unchanged.
A temporary local merge was tested:
No additional regression was detected in the combined configuration.
The temporary merge was aborted after testing. No changes from #1231 are included in this PR.
The final branch was checked against upstream main immediately before submission: zero commits behind, one commit ahead, clean working tree and clean
git diff --check.GPUs tested
Limitations
AI-assisted
ChatGPT assisted with investigation, implementation, regression tests, documentation and compatibility analysis. The reported local tests were executed on my machine.
Checklist
docs/design.md.Imported from ubiquitarianism/leonida. Originally posted by GeorgiyDemo on 2026-11-25T05:20:05Z.
Tested
eb39d2765on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), againstmainc7e82e26e(translator + new GPU fixtures; binaries from the build at66d4f5aa3, which these fixtures do not need rebuilt):python3 -m unittest test_alu_exp_f32(fromtests/semantic): OK at this head; the same file onmainfails 3 times — the denormal-flush expectation is new.--filter ps_exp_f32_denorm: 2/2 PASS on MoltenVK 1.4.2 and 2/2 PASS on KosmicKrisp (Mesa 26.3.1) —ps_exp_f32_denorm4096/4096 pixels exact,ps_exp_f32_denorm_rt4096 pixels exact across 64 runtime-dependent inputs.main, so the semantic failures are the before/after evidence for the translator change.AI-assisted; synthetic fixtures only, no game data.
Imported from ubiquitarianism/leonida. Originally posted by ecox982745 on 2026-11-25T05:50:05Z.
I checked the open question about #1518 on Windows with an RTX 4090 (NVIDIA 616.64). The two descriptor-word changes in that PR resolve the
cs_imgatomic_extfailure reported here.I built the test executables from this PR's
eb39d2765. With its original fixture, the native and wave64-emulated runs both reproduced six wrong signed image words. The first was word 32,0x0badf00dinstead of0x00000101. Thecs_imgatomicandcs_imgatomic3dcontrols passed in both modes. I then replaced onlyruntime/test/shaders/cs_imgatomic_ext.asmwith the fixture from #1518 (1bbf8a9b7), keeping the translator, binaries and driver fixed. All three image-atomic fixtures passed in both modes.Full
scripts/run_gpu_tests.py --require-passruns on that combination:LEONIDA_W64_EMULATE=1Both of this PR's exponential fixtures also matched all 4,096 pixels per draw in each run. These are local synthetic GPU results. AI-assisted verification.
Imported from ubiquitarianism/leonida. Originally posted by adrianmjim on 2026-11-25T07:54:12Z.
Tested
eb39d2765applied ontomain42537e7b6on AMD: Radeon RX 7900 XT (RDNA3, gfx1100), AMD driver 32.0.32029.2010 (26.11.2), Windows 11 build 26300, Vulkan SDK 1.4.363.0, llvm-mc 23.1.5, test programs from amain42537e7b6build. No game files.ps_exp_f32_denorm(4096/4096 exact) andps_exp_f32_denorm_rt(exact across the 64 run-time inputs) both pass, natively and withLEONIDA_W64_EMULATE=1.maingives 244/263 here, so the only difference is the two new passes. The one failure iscs_imgatomic_exton both, the fixture problem #1518 fixes.Does AMD's driver need the flush? As on NVIDIA, no. I read
v_exp_f32back for one lane with an opaque operand, throughtools/vk_fuzz_run.run_programs(v_mov_b32 v1, <bits>thenv_exp_f32 v8, v1,words=1). There are 12 inputs from -120 to -160, including -126.5, -127, -128, -130, -140, -149 and -149.5, whose exact results are denormal.main42537e7b6So on this card
mainalready returns +0 wherever RDNA2 flushes, and keeps -125 and -126 exact (0x01000000, 0x00800000). The PR makes no visible difference here and causes no regression. It still makes the translated SPIR-V say what the hardware does, instead of relying on the driver's denormal mode.One small thing in the harness:
runtime/test/shaders/check.pygets aps_exp_f32_denorm_rtbranch inpixel_test(around line 2169), but that name is not inPIXEL_TESTS(line 922), socheck.pynever runs it. Onlyscripts/run_gpu_tests.pydoes, because it discovers every.asm. Adding the name toPIXEL_TESTSwould make the branch live.Imported from ubiquitarianism/leonida. Originally posted by CodingRule on 2026-11-25T12:20:25Z.
GPU test on an NVIDIA Ada card, for the record: this passes on an RTX 4090.
eb39d276merged ontomain0d80bc5d(clean merge), test programs built from thatmainwithscripts\build_runtime.ps1.python -I scripts/run_gpu_tests.py --build runtime/build --filter ps_exp_f32_denorm, once native and once withLEONIDA_W64_EMULATE=1.spirv-valclean, 2/2 passed in both modes, with the expected words/pixels from the fixture header. Nothing skipped.scripts\build_llvm_mc.ps1), SPIRV-Tools v2026.4, MSVC 14.44.35207.Only the filtered fixture(s) were run for this PR, not the full suite or ctest; the full-suite baseline for this card on
mainis in #1777. Synthetic fixtures only, no game files. AI-assisted (Claude Code ran the tests and wrote this comment).Imported from ubiquitarianism/leonida. Originally posted by MoonEyes on 2026-11-28T03:01:32Z.
Hi @exoticLgk, thanks for this pull request.
CONTRIBUTING.md asks contributors to claim their work in the coordination issue ("Coordinating who works on what", currently #1608) before opening a pull request: post
claiming: <ID>there, or a one-line description if the item is not listed yet, and put the ID in the pull request. I could not find a claim from you for this one (the IDSHADER-EXP-F32-DENORMappears in the pull request, but there is noclaiming:line for it).The claim matters because "it is claimed in the coordination issue by the pull request's author" is the first item on the maintainers' checklist for a mergeable pull request, and because it lets others see that the work is taken before they write it a second time.
Could you post the claim in #1608 and add the ID to the pull request description? If you already claimed it in another form, a link to your comment is enough.
AI-assisted (Claude Code, Claude Opus 5.5).
Imported from ubiquitarianism/leonida. Originally posted by sodove on 2026-11-28T10:44:40Z.
#1587 | head
eb39d2765eae88793b5caf9523f5d95a1effeb44|python3 -m unittest discover -s tests/semantic -p test_alu_exp_f32.py -v| red: 7 run, 3 failures | green: 7 passed | Red → green. Semantic red → green, Vulkan passed on both treesThe semantic file reproduced the v_exp_f32 denormal regression. On the two available drivers the hardware readbacks already matched the expected words on the baseline.
Captured 62 distinct complete SPIR-V module(s) emitted while rerunning test_alu_exp_f32.py on the merged tree. All assembled and passed spirv-val for Vulkan 1.2 with --allow-offset-texture-operand.
On each adapter I ran both changed fixtures with the default wave setting and with LEONIDA_W64_EMULATE=1. Both trees matched all 4096 pixels per draw, including 64 runtime-dependent inputs in the second fixture.
Windows Vulkan adapters: AMD Radeon(TM) Graphics (26.11.2) and NVIDIA GeForce RTX 5070 Ti (610.74).
Additional commands
python scripts/run_gpu_tests.py --filter ps_exp_f32_denorm --require-pass --assembler spirv-as --build <build> --work <work>Base
3bd936ecd98995bca3e1da83d5e28d2343001aefwas merged into the recorded PR head for the second run. Ubuntu 26.04.1 (WSL2), Python 3.14.4. Native runs used Windows 11, Python 3.12.10. Counts include unittest subtest events where applicable. AI-assisted with OpenAI Codex. Batch claim.Imported from ubiquitarianism/leonida. Originally posted by DadaCap on 2026-11-28T11:53:02Z.
Merged, thank you @exoticLgk! This translator PR (rdna2spirv: flush v_exp_f32 denormal results (SHADER-EXP-F32-DENORM)) passed its own tests with main merged in during sodove's verification of this batch, so it went in with the batch.
AI-assisted (Claude Code, Claude Opus 5.5), posted for the maintainers.