flush subnormal factors to +0 in legacy float multiply #616

Open
RileyW wants to merge 1 commit from RileyW/Darner:pr/legacy-subnormals into Main
First-time contributor

Not yet run in-game on this Darner branch (synthetic DXIL/census unit tests run on this revision; previously verified on RTX 3080 SM86 in a downstream fork).

What it changes

The problem on main: read from code (crates/darner-shader/src/emit/lower.rs:4785, Lower::legacy_mul).
RDNA2 default FP32 mode flushes subnormals below f32::MIN_POSITIVE to zero before evaluating legacy float products (v_mul_legacy_f32, v_mac_legacy_f32, v_mad_legacy_f32), so subnormal times inf and subnormal times NaN yield +0.0.
On DXIL hosts that preserve FP32 denormals (such as NVIDIA), comparing with pred::OEQ against 0.0 misses subnormal factors. Under rdna::LEGACY, not_zero also skipped the guard for subnormal constants.

  1. Guards the default path in Lower::legacy_mul using pred::OLT on fabs(a) and fabs(b) against f32::MIN_POSITIVE.
  2. Tightens not_zero under rdna::LEGACY to require finite constants with magnitude at least f32::MIN_POSITIVE.
  3. Under rdna::LEGACY, uses pred::OLT against f32::MIN_POSITIVE when DARNER_LEGACY_MIN is off, and keeps min(fabs(a), fabs(b)) == 0.0 (pred::OEQ) when DARNER_LEGACY_MIN=1 for Mesa NIR folding.
  4. Adds legacy_mul_flushes_subnormal_factors_to_positive_zero in crates/darner-shader/src/emit/valu_tests.rs.

How it was tested

  • Tested revision: bfb6055 (based on c8258f9)
  • Commands and results: legacy_mul_flushes_subnormal_factors_to_positive_zero (1 passed, dxil.dll + census), emit::cost::tests (5 passed), emit::lower::tests (30 passed, 1 ignored), both workspace clippy -- -D warnings gates (0 warnings), cargo xtask policy (ok).
  • Changes a default: yes, for all hosts (default Lower::legacy_mul treats FP32 subnormals as zero).
  • A/B result: correctness fix (prevents subnormal times inf/NaN artifacts on denorm-preserving hosts); not a speed claim.
  • Gates run on that revision: both workspace clippy gates, cargo xtask policy, and targeted darner-shader tests.
  • Gameplay: not yet re-run in-game on this Darner branch (previously verified on RTX 3080 SM86 in a downstream fork).
  • Hardware dependence: affects hosts that preserve FP32 subnormals in DXIL (e.g. NVIDIA); neutral on RDNA with default FTZ.
  • Coverage gaps: Windows 10 22H2 test binaries without Agility SDK exports see SM 0x65 / WARP SM 0x62, so GPU/WARP dispatch skipped while lowering, census assertions, and dxil.dll validation ran.

Checklist

  • I ran this change in the game, or say below why it cannot be (unit/DXIL tests run; in-game Darner run pending).
  • This PR contains one change based on main.
  • The diff follows docs/asset-policy.md.
  • I recorded this PR dependencies below.
    • Depends on: none

Checked for overlap

  • I searched the open pull requests for the same issue and for the files this touches.
  • Related PRs: #594 (touches crates/darner-shader/src/emit/lower.rs for unrelated binding/barrier fixes).
  • Replaces or overlaps: none found.
Not yet run in-game on this Darner branch (synthetic DXIL/census unit tests run on this revision; previously verified on RTX 3080 SM86 in a downstream fork). ## What it changes The problem on main: read from code (crates/darner-shader/src/emit/lower.rs:4785, Lower::legacy_mul). RDNA2 default FP32 mode flushes subnormals below f32::MIN_POSITIVE to zero before evaluating legacy float products (v_mul_legacy_f32, v_mac_legacy_f32, v_mad_legacy_f32), so subnormal times inf and subnormal times NaN yield +0.0. On DXIL hosts that preserve FP32 denormals (such as NVIDIA), comparing with pred::OEQ against 0.0 misses subnormal factors. Under rdna::LEGACY, not_zero also skipped the guard for subnormal constants. 1. Guards the default path in Lower::legacy_mul using pred::OLT on fabs(a) and fabs(b) against f32::MIN_POSITIVE. 2. Tightens not_zero under rdna::LEGACY to require finite constants with magnitude at least f32::MIN_POSITIVE. 3. Under rdna::LEGACY, uses pred::OLT against f32::MIN_POSITIVE when DARNER_LEGACY_MIN is off, and keeps min(fabs(a), fabs(b)) == 0.0 (pred::OEQ) when DARNER_LEGACY_MIN=1 for Mesa NIR folding. 4. Adds legacy_mul_flushes_subnormal_factors_to_positive_zero in crates/darner-shader/src/emit/valu_tests.rs. ## How it was tested - Tested revision: bfb6055 (based on c8258f9) - Commands and results: legacy_mul_flushes_subnormal_factors_to_positive_zero (1 passed, dxil.dll + census), emit::cost::tests (5 passed), emit::lower::tests (30 passed, 1 ignored), both workspace clippy -- -D warnings gates (0 warnings), cargo xtask policy (ok). - Changes a default: yes, for all hosts (default Lower::legacy_mul treats FP32 subnormals as zero). - A/B result: correctness fix (prevents subnormal times inf/NaN artifacts on denorm-preserving hosts); not a speed claim. - Gates run on that revision: both workspace clippy gates, cargo xtask policy, and targeted darner-shader tests. - Gameplay: not yet re-run in-game on this Darner branch (previously verified on RTX 3080 SM86 in a downstream fork). - Hardware dependence: affects hosts that preserve FP32 subnormals in DXIL (e.g. NVIDIA); neutral on RDNA with default FTZ. - Coverage gaps: Windows 10 22H2 test binaries without Agility SDK exports see SM 0x65 / WARP SM 0x62, so GPU/WARP dispatch skipped while lowering, census assertions, and dxil.dll validation ran. ## Checklist - [x] I ran this change in the game, or say below why it cannot be (unit/DXIL tests run; in-game Darner run pending). - [x] This PR contains one change based on main. - [x] The diff follows docs/asset-policy.md. - [x] I recorded this PR dependencies below. - Depends on: none ## Checked for overlap - [x] I searched the open pull requests for the same issue and for the files this touches. - Related PRs: #594 (touches crates/darner-shader/src/emit/lower.rs for unrelated binding/barrier fixes). - Replaces or overlaps: none found.
TrustNo1 changed title from [pr-fix][shaders] flush subnormal factors to +0 in legacy float multiply to flush subnormal factors to +0 in legacy float multiply 2026-12-06 03:26:12 +00:00
Owner

Test needed — commit bfb60559; what to check:

The problem on main: read from code (crates/darner-shader/src/emit/lower.rs:4785, Lower::legacy_mul).
RDNA2 default FP32 mode flushes subnormals below f32::MIN_POSITIVE to zero before evaluating legacy float products (v_mul_legacy_f32, v_mac_legacy_f32, v_mad_legacy_f32), so subnormal times inf and subnormal times NaN yield +0.0.
On DXIL hosts that preserve FP32 denormals (such as NVIDIA), comparing with pred::OEQ against 0.0 misses subnormal factors. Under rdna::LEGACY, not_zero also skipped the guard for subnormal constants.

  1. Guards the default path in Lower::legacy_mul using pred::OLT on fabs(a) and fabs(b) against f32::MIN_POSITIVE.
  2. Tightens not_zero under rdna::LEGACY to require finite constants with magnitude at least f32::MIN_POSITIVE.
  3. Under rdna::LEGACY, uses pred::OLT against f32::MIN_POSITIVE when DARNER_LEGACY_MIN is off, and keeps min(fabs(a), fabs(b)) == 0.0 (pred::OEQ) when DARNER_LEGACY_MIN=1 for Mesa NIR folding.
  4. Adds legacy_mul_flushes_subnormal_factors_to_positive_zero in crates/darner-shader/src/emit/valu_tests.rs.

Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture.

Reply testing to take this run; it's free again after 24 h with no results.

**Test needed** — commit `bfb60559`; what to check: The problem on main: read from code (crates/darner-shader/src/emit/lower.rs:4785, Lower::legacy_mul). RDNA2 default FP32 mode flushes subnormals below f32::MIN_POSITIVE to zero before evaluating legacy float products (v_mul_legacy_f32, v_mac_legacy_f32, v_mad_legacy_f32), so subnormal times inf and subnormal times NaN yield +0.0. On DXIL hosts that preserve FP32 denormals (such as NVIDIA), comparing with pred::OEQ against 0.0 misses subnormal factors. Under rdna::LEGACY, not_zero also skipped the guard for subnormal constants. 1. Guards the default path in Lower::legacy_mul using pred::OLT on fabs(a) and fabs(b) against f32::MIN_POSITIVE. 2. Tightens not_zero under rdna::LEGACY to require finite constants with magnitude at least f32::MIN_POSITIVE. 3. Under rdna::LEGACY, uses pred::OLT against f32::MIN_POSITIVE when DARNER_LEGACY_MIN is off, and keeps min(fabs(a), fabs(b)) == 0.0 (pred::OEQ) when DARNER_LEGACY_MIN=1 for Mesa NIR folding. 4. Adds legacy_mul_flushes_subnormal_factors_to_positive_zero in crates/darner-shader/src/emit/valu_tests.rs. Evidence to post: card + driver, settings, commit tested, before/after (switch off vs on, two runs each), fps median and p99, and one line saying you looked at the picture. Reply `testing` to take this run; it's free again after 24 h with no results.
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 'pr/legacy-subnormals:RileyW-pr/legacy-subnormals'
git switch 'RileyW-pr/legacy-subnormals'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'Main'
git merge --no-ff 'RileyW-pr/legacy-subnormals'
git switch 'RileyW-pr/legacy-subnormals'
git rebase 'Main'
git switch 'Main'
git merge --ff-only 'RileyW-pr/legacy-subnormals'
git switch 'RileyW-pr/legacy-subnormals'
git rebase 'Main'
git switch 'Main'
git merge --no-ff 'RileyW-pr/legacy-subnormals'
git switch 'Main'
git merge --squash 'RileyW-pr/legacy-subnormals'
git switch 'Main'
git merge --ff-only 'RileyW-pr/legacy-subnormals'
git switch 'Main'
git merge 'RileyW-pr/legacy-subnormals'
git push origin 'Main'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
2 participants
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
TrustNo1/Darner!616
No description provided.