Shader tests: the legacy multiply-add's rounding case takes either rounding #1332

Open
bihanikeshav wants to merge 1 commit from upstream-pr/1335 into main
bihanikeshav commented 2026-11-26 15:56:52 +00:00 (Migrated from github.com)

Imported from fxceless/victory-fork. Originally posted by bihanikeshav on 2026-11-26T15:56:52Z.


Problem

legacy_mad_fuses_its_product_and_flushes_its_sources fails on my RTX 5060 Laptop (Blackwell, driver 610.62):

hardware: case 0
  left: 0
 right: 2826960896

Case 0 checks that v_mad_legacy_f32 rounds once. We lower it to DXIL FMad, and DXIL leaves fusing that op up to the driver. NVIDIA's Ada driver fuses it (#961 ran into that from the other side). This card's driver doesn't, so the product gets rounded to 1.0 before the add and the result is +0 instead of -2^-46. WARP does the same thing, which is why the test already skipped case 0 there. #1026 was only run on WARP, so the hardware branch of that assertion never saw a card like this one.

Every other case passed here. Flushing subnormal sources and the zero-factor rule both work, and those are the parts that fixed the water reflections.

Change

  • Case 0 now takes either correct answer on any device: fused (0xa8800000) or product rounded first (0x00000000). It prints which one it got. Any other value still fails.
  • The other three cases are unchanged and stay exact on hardware and WARP.
  • The doc comment on legacy_fmad in lower.rs now says the fusing is asked for, not promised.

No change to the translator's output.

I didn't try to force a single rounding (doing the add in f64 with round-to-odd would work). It costs several double ops per instruction, doubles are slow on consumer NVIDIA cards, and I haven't seen this last-bit difference cause anything visible. Happy to look at it if someone has a case where it matters.

Tests

On the RTX 5060 Laptop, Windows 11:

  • cargo test -p victory-shader --locked: 222 passed, 0 failed, 4 ignored. Before this change: 221 passed, 1 failed.
  • The test with --nocapture prints hardware: FMad not fused by this host (product rounded first) and the same for warp.
  • cargo clippy -p victory-shader --all-targets --locked -- -D warnings and the --all-features run are both clean.

🤖 Generated with Claude Code

<!-- greyfinch-sync:fxceless/victory-fork:issue:6630409464 --> Imported from [fxceless/victory-fork](https://github.com/fxceless/victory-fork/pull/1335). Originally posted by [bihanikeshav](https://github.com/bihanikeshav) on 2026-11-26T15:56:52Z. --- ## Problem `legacy_mad_fuses_its_product_and_flushes_its_sources` fails on my RTX 5060 Laptop (Blackwell, driver 610.62): ``` hardware: case 0 left: 0 right: 2826960896 ``` Case 0 checks that `v_mad_legacy_f32` rounds once. We lower it to DXIL `FMad`, and DXIL leaves fusing that op up to the driver. NVIDIA's Ada driver fuses it (#961 ran into that from the other side). This card's driver doesn't, so the product gets rounded to 1.0 before the add and the result is +0 instead of -2^-46. WARP does the same thing, which is why the test already skipped case 0 there. #1026 was only run on WARP, so the hardware branch of that assertion never saw a card like this one. Every other case passed here. Flushing subnormal sources and the zero-factor rule both work, and those are the parts that fixed the water reflections. ## Change - Case 0 now takes either correct answer on any device: fused (`0xa8800000`) or product rounded first (`0x00000000`). It prints which one it got. Any other value still fails. - The other three cases are unchanged and stay exact on hardware and WARP. - The doc comment on `legacy_fmad` in `lower.rs` now says the fusing is asked for, not promised. No change to the translator's output. I didn't try to force a single rounding (doing the add in f64 with round-to-odd would work). It costs several double ops per instruction, doubles are slow on consumer NVIDIA cards, and I haven't seen this last-bit difference cause anything visible. Happy to look at it if someone has a case where it matters. ## Tests On the RTX 5060 Laptop, Windows 11: - `cargo test -p victory-shader --locked`: 222 passed, 0 failed, 4 ignored. Before this change: 221 passed, 1 failed. - The test with `--nocapture` prints `hardware: FMad not fused by this host (product rounded first)` and the same for warp. - `cargo clippy -p victory-shader --all-targets --locked -- -D warnings` and the `--all-features` run are both clean. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1335:upstream-pr/1335'
git switch 'upstream-pr/1335'

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 'upstream-pr/1335'
git switch 'upstream-pr/1335'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1335'
git switch 'upstream-pr/1335'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1335'
git switch 'main'
git merge --squash 'upstream-pr/1335'
git switch 'main'
git merge --ff-only 'upstream-pr/1335'
git switch 'main'
git merge 'upstream-pr/1335'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
No milestone
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.

Reference
fxceless/victory-fork!1332
No description provided.