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

Open
github-bot wants to merge 1 commit from github-bot/gh-1587 into main AGit
Owner

@⁠exoticLgk on GitHub · 2026-11-25 05:15 UTC · original
exoticLgk:fix-exp-f32-denorm → main · +53 −2 · 7 files · 1 commits · open

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** on GitHub · 2026-11-25 05:15 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1587) `exoticLgk:fix-exp-f32-denorm` → `main` · +53 −2 · 7 files · 1 commits · open ## 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 - [x] Based on current main. - [x] One topic per PR. - [x] No game data, keys or protection workarounds. - [x] Synthetic regression tests included. - [x] Translator contract table updated in `docs/design.md`. - [x] Testing and known limitations documented.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:57:21 +00:00
Author
Owner

@⁠GeorgiyDemo on GitHub · 2026-11-25 05:20 UTC · original

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.

**@⁠GeorgiyDemo** on GitHub · 2026-11-25 05:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1587#issuecomment-7153671008) 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.
Author
Owner

@⁠ecox982745 on GitHub · 2026-11-25 05:50 UTC · original

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.

**@⁠ecox982745** on GitHub · 2026-11-25 05:50 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1587#issuecomment-7154183028) 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.
Author
Owner

@⁠adrianmjim on GitHub · 2026-11-25 07:54 UTC · original

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.

  • New fixtures: ps_exp_f32_denorm (4096/4096 exact) and ps_exp_f32_denorm_rt (exact across the 64 run-time inputs) both pass, natively and with LEONIDA_W64_EMULATE=1.
  • Whole GPU suite: 246/265 passed, 18 skipped, 1 failed. main gives 244/263 here, so the only difference is the two new passes. The one failure is cs_imgatomic_ext on both, the fixture problem #1518 fixes.

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.

**@⁠adrianmjim** on GitHub · 2026-11-25 07:54 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1587#issuecomment-7156380960) 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. - **New fixtures:** `ps_exp_f32_denorm` (4096/4096 exact) and `ps_exp_f32_denorm_rt` (exact across the 64 run-time inputs) both pass, natively and with `LEONIDA_W64_EMULATE=1`. - **Whole GPU suite:** 246/265 passed, 18 skipped, 1 failed. `main` gives 244/263 here, so the only difference is the two new passes. The one failure is `cs_imgatomic_ext` on both, the fixture problem #1518 fixes. **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.
Author
Owner

@⁠CodingRule on GitHub · 2026-11-25 12:20 UTC · original

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

**@⁠CodingRule** on GitHub · 2026-11-25 12:20 UTC · [original](https://github.com/ubiquitarianism/leonida/pull/1587#issuecomment-7162240904) 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).
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1587/head:github-bot/gh-1587'
git switch 'github-bot/gh-1587'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1587'
git switch 'github-bot/gh-1587'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1587'
git switch 'github-bot/gh-1587'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1587'
git switch 'main'
git merge --squash 'github-bot/gh-1587'
git switch 'main'
git merge --ff-only 'github-bot/gh-1587'
git switch 'main'
git merge 'github-bot/gh-1587'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.