Skip to content

rdna2spirv: flush v_exp_f32 denormal results (SHADER-EXP-F32-DENORM) - #1587

Merged
DadaCap merged 1 commit into
ProjectLeonida:mainfrom
exoticLgk:fix-exp-f32-denorm
Nov 28, 2026
Merged

DadaCap merged 1 commit into
ProjectLeonida:mainfrom
exoticLgk:fix-exp-f32-denorm

Conversation

@exoticLgk

Copy link
Copy Markdown
Contributor

Coordination

Claimed in the coordination issue as: SHADER-EXP-F32-DENORM

The 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:

claiming: SHADER-EXP-F32-DENORM — Fix denormal result flushing in v_exp_f32 to match documented RDNA2 hardware behaviour.

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.md establish that v_exp_f32 flushes denormal results, including when MODE requests denormal preservation.

The translator previously emitted GLSL Exp2 without explicitly modelling this behaviour.

This PR:

  • Reuses Gen.flush_f32 to flush the raw v_exp_f32 result before output modifiers.
  • Adds semantic regression coverage around the minimum normal f32 value.
  • Adds two synthetic GPU fixtures, including runtime-dependent inputs.
  • Updates both GPU test runners and the translator contract table.

The semantic regression reproduces the following differences:

Input Before After
-127 0x00400000 0x00000000
-128 0x00200000 0x00000000
-149 0x00000001 0x00000000

Normal results at -125 and -126 remain unchanged.

Tested

  • Semantic suite: 487 files, 6,280 tests, zero failed files.
  • Runtime rebuilt successfully after rebasing onto c7e82e26e.
  • Both new GPU fixtures pass translation, SPIR-V validation and exact readback.
  • Static fixture: 4,096/4,096 pixels exact.
  • Runtime-dependent fixture: 4,096/4,096 pixels exact across 64 distinct inputs.

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:

  • Native: 274/274 translated and validated; 210 passed, 53 skipped, 1 failed.
  • Wave64 emulation: 274/274 translated and validated; 244 passed, 19 skipped, 1 failed.

The existing cs_imgatomic_ext failure 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:

Input Modifier Translated result
-127 mul:2 0x00000000
-128 mul:4 0x00000000
-126 div:2 0x00400000
-127 clamp 0x00000000
2 clamp 0x3f800000
1 mul:2 0x40800000
1 mul:4 0x41000000
1 div:2 0x3f800000

All 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_f32 boundary behaviour has not been independently established on native RDNA2.

The existing f32_fuzz.py reference 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:

  • Translator code merged automatically.
  • Documentation conflicts were resolved locally.
  • Semantic suite: 487 files, 6,281 tests, zero failed files.
  • GPU translation and SPIR-V validation: 275/275.
  • Native GPU tests: 211 passed, 53 skipped, 1 existing failure.
  • Wave64 emulation: 245 passed, 19 skipped, 1 existing failure.
  • Both new GPU fixtures remained exact.

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

  • NVIDIA GeForce RTX 4070 SUPER
  • Windows 11
  • NVIDIA driver 591.86
  • Native subgroup size: 32
  • Native and Wave64-emulated execution

Limitations

  • No new native RDNA2 measurements were performed.
  • No new game shader corpus scan was performed.
  • The correction models the raw exponential result, not denormal handling after output scaling.
  • Compatibility with every other pending PR and GPU configuration has not been established.
  • Official CI validation is pending.

AI-assisted

ChatGPT assisted with investigation, implementation, regression tests, documentation and compatibility analysis. The reported local tests were executed on my machine.

Checklist

  • Based on current main.
  • One topic per PR.
  • No game data, keys or protection workarounds.
  • Synthetic regression tests included.
  • Translator contract table updated in docs/design.md.
  • Testing and known limitations documented.

@exoticLgk exoticLgk closed this Nov 25, 2026
@exoticLgk exoticLgk reopened this Nov 25, 2026
@GeorgiyDemo

Copy link
Copy Markdown
Contributor

Tested eb39d2765 on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), against main c7e82e26e (translator + new GPU fixtures; binaries from the build at 66d4f5aa3, which these fixtures do not need rebuilt):

  • python3 -m unittest test_alu_exp_f32 (from tests/semantic): OK at this head; the same file on main fails 3 times — the denormal-flush expectation is new.
  • The two new GPU fixtures, --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_denorm 4096/4096 pixels exact, ps_exp_f32_denorm_rt 4096 pixels exact across 64 runtime-dependent inputs.
  • The fixtures do not exist on main, so the semantic failures are the before/after evidence for the translator change.

AI-assisted; synthetic fixtures only, no game data.

@ecox982745

Copy link
Copy Markdown

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_ext failure 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, 0x0badf00d instead of 0x00000101. The cs_imgatomic and cs_imgatomic3d controls passed in both modes. I then replaced only runtime/test/shaders/cs_imgatomic_ext.asm with 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-pass runs on that combination:

Mode Shaders translated and SPIR-V validated Cases passed Skipped Failed
Native 275/275 212 53 0
LEONIDA_W64_EMULATE=1 275/275 246 19 0

Both 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.

@adrianmjim

Copy link
Copy Markdown

Tested eb39d2765 applied onto main 42537e7b6 on 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 a main 42537e7b6 build. No game files.

Does AMD's driver need the flush? As on NVIDIA, no. I read v_exp_f32 back for one lane with an opaque operand, through tools/vk_fuzz_run.run_programs (v_mov_b32 v1, <bits> then v_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.

wave32 wave64
main 42537e7b6 12/12 flushed, 0 denormals 12/12, 0 denormals
this PR 12/12, 0 denormals 12/12, 0 denormals

So on this card main already 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.py gets a ps_exp_f32_denorm_rt branch in pixel_test (around line 2169), but that name is not in PIXEL_TESTS (line 922), so check.py never runs it. Only scripts/run_gpu_tests.py does, because it discovers every .asm. Adding the name to PIXEL_TESTS would make the branch live.

@CodingRule

Copy link
Copy Markdown
Contributor

GPU test on an NVIDIA Ada card, for the record: this passes on an RTX 4090.

  • Tested: this branch's head eb39d276 merged onto main 0d80bc5d (clean merge), test programs built from that main with scripts\build_runtime.ps1.
  • Command: python -I scripts/run_gpu_tests.py --build runtime/build --filter ps_exp_f32_denorm, once native and once with LEONIDA_W64_EMULATE=1.
  • Result: 2/2 translated and spirv-val clean, 2/2 passed in both modes, with the expected words/pixels from the fixture header. Nothing skipped.
  • Device: NVIDIA GeForce RTX 4090 (Ada / AD102), driver 591.86, Vulkan 1.4.325, subgroup 32..32, Windows 11 Pro build 26200. llvm-mc 21.1.8 (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 main is in #1777. Synthetic fixtures only, no game files. AI-assisted (Claude Code ran the tests and wrote this comment).

@MoonEyes

Copy link
Copy Markdown
Collaborator

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 ID SHADER-EXP-F32-DENORM appears in the pull request, but there is no claiming: 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).

@sodove

sodove commented Nov 28, 2026

Copy link
Copy Markdown
Contributor

#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 trees

The 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 3bd936ecd98995bca3e1da83d5e28d2343001aef was 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.

@DadaCap
DadaCap merged commit 87f12b9 into ProjectLeonida:main Nov 28, 2026
@DadaCap

DadaCap commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

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.

Tauwni added a commit to Tauwni/leonida that referenced this pull request Nov 28, 2026
…irtual runner (CI-MACOS-EXP-DENORM)

The fixture from ProjectLeonida#1587 reads 16777214 instead of 16777216 at pixel 0 on the
runner's Apple Paravirtual device (MoltenVK 1.4.2), on main's last two macOS runs
(46142035955, 46144804679) and on ProjectLeonida#1774's. On an Apple M3 with MoltenVK 1.4.2 it passes, 3 of 3 runs, so the
translator is not at fault: list it with ps_ssharp. ci_expected_failures.py
still prints a notice if it starts to pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Tauwni added a commit to Tauwni/leonida that referenced this pull request Nov 28, 2026
…irtual runner (CI-MACOS-EXP-DENORM)

The fixture from ProjectLeonida#1587 reads 16777214 instead of 16777216 at pixel 0 on the
runner's Apple Paravirtual device (MoltenVK 1.4.2), on main's last two macOS runs
(46142035955, 46144804679) and on ProjectLeonida#1774's. On an Apple M3 with MoltenVK 1.4.2 it passes, 3 of 3 runs, so the
translator is not at fault: list it with ps_ssharp. ci_expected_failures.py
still prints a notice if it starts to pass.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants