Skip to content

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

Open
bihanikeshav wants to merge 1 commit into
fxceless:mainfrom
bihanikeshav:legacy-mad-test-either-rounding
Open

bihanikeshav wants to merge 1 commit into
fxceless:mainfrom
bihanikeshav:legacy-mad-test-either-rounding

Conversation

@bihanikeshav

@bihanikeshav bihanikeshav commented Nov 26, 2026 •

Copy link
Copy Markdown

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

…unding

`legacy_mad_fuses_its_product_and_flushes_its_sources` asserted a single
rounding on every hardware adapter. The instruction is lowered to DXIL
`FMad`, whose fusing is the driver's choice: NVIDIA's Ada driver fuses it
(pull request fxceless#961), but an RTX 5060 Laptop (Blackwell, driver 610.62)
rounds the product first, as WARP does, and the test failed there
(case 0: got 0x00000000, want 0xa8800000), turning `cargo test --workspace`
red on that card.

Case 0 now takes either correct answer (fused, or product rounded first)
on every device and says which it got; any other value still fails. The
flushing and zero-factor cases stay exact everywhere. The doc of
`legacy_fmad` says the fusing is asked for, not promised.

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.

1 participant