[PR #1587] rdna2spirv: flush v_exp_f32 denormal results (SHADER-EXP-F32-DENORM) #1607

Open
opened 2026-11-26 20:21:50 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1587
Author: @exoticLgk
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix-exp-f32-denorm


📝 Commits (1)

  • eb39d27 rdna2spirv: flush v_exp_f32 denormal results

📊 Changes

7 files changed (+53 additions, -2 deletions)

View changed files

📝 docs/design.md (+1 -1)
📝 runtime/test/shaders/check.py (+17 -0)
➕ runtime/test/shaders/ps_exp_f32_denorm.asm (+12 -0)
➕ runtime/test/shaders/ps_exp_f32_denorm_rt.asm (+10 -0)
📝 scripts/run_gpu_tests.py (+5 -1)
📝 tests/semantic/test_alu_exp_f32.py (+6 -0)
📝 tools/rdna2spirv.py (+2 -0)

📄 Description

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.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1587 **Author:** [@exoticLgk](https://github.com/exoticLgk) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix-exp-f32-denorm` --- ### 📝 Commits (1) - [`eb39d27`](https://github.com/ubiquitarianism/leonida/commit/eb39d2765eae88793b5caf9523f5d95a1effeb44) rdna2spirv: flush v_exp_f32 denormal results ### 📊 Changes **7 files changed** (+53 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `docs/design.md` (+1 -1) 📝 `runtime/test/shaders/check.py` (+17 -0) ➕ `runtime/test/shaders/ps_exp_f32_denorm.asm` (+12 -0) ➕ `runtime/test/shaders/ps_exp_f32_denorm_rt.asm` (+10 -0) 📝 `scripts/run_gpu_tests.py` (+5 -1) 📝 `tests/semantic/test_alu_exp_f32.py` (+6 -0) 📝 `tools/rdna2spirv.py` (+2 -0) </details> ### 📄 Description ## 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. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
starred/leonida#1607
No description provided.