Shader: relax the console float rules the host can take as they are (VICTORY_RELAX_FLOAT, exact by default) #37

Closed
64bitMango wants to merge 1 commit from upstream-pr/37 into main
64bitMango commented 2026-11-26 10:46:54 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T10:46:54Z.


What. The translator reproduces console float rules on the bits: denormal operands of min/max/med3 read as zeros, -0 below +0, legacy multiplies, 16-bit rounding, NaN rules. emit::Relax leaves each kind to the host. The default is exact: every console rule is kept. VICTORY_RELAX_FLOAT=safe opts in to leaving denormals and signed zeros to the host; the riskier kinds (legacy_mul, legacy_mul_nan, half_rounding, nan) can be named too, or all.

What safe changes (docs/metal-backend.md, linked from docs/native-host.md): with denormals, the flush before v_cvt_flr_i32_f32, min, max, med3 and the x2/x4/÷2 output modifiers goes, so a negative denormal can floor to -1 instead of 0, and a surviving denormal can flip a compare or change an rcp. With signed_zeros, the sign of a zero can change, which divide and copysign can see; on the Apple GPU, min and max of +0/-0 return the second operand.

Measured on the Wine route only: −1 to −5 ms GPU on one recorded frame with safe, picture within noise. Per dispatch with all kinds relaxed: up to two thirds of a pass. The riskier kinds saved more (up to −13.5 ms) but change NaN/rounding behaviour that one frame can't prove harmless. Nothing is measured on the native host yet, which is why safe is opt-in. Translating a 19,105-shader capture through the native host's path, the exact default gives DXIL byte-identical to main for every shader; safe changes 14,423, and none switches between translating and refused.

Tests: exact_float_rules_order_minus_zero_below_plus_zero_in_min_and_max checks the result bits of v_min/v_max (f32 and f16) of ±0 in both orders on Metal; the modes give different bits there, so it catches a lost exact path. exact_float_rules_floor_a_negative_denormal_to_zero checks the floor (both modes give 0 on the Apple GPU, so it does not tell them apart). The relax setting is part of the shader cache key and the pipeline-library tag(). victory-shader 220 passed, victory-gpu 146 passed; Windows clippy and xtask policy clean.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:issue:6624954228 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T10:46:54Z. --- **What.** The translator reproduces console float rules on the bits: denormal operands of min/max/med3 read as zeros, -0 below +0, legacy multiplies, 16-bit rounding, NaN rules. `emit::Relax` leaves each kind to the host. **The default is `exact`: every console rule is kept.** `VICTORY_RELAX_FLOAT=safe` opts in to leaving denormals and signed zeros to the host; the riskier kinds (`legacy_mul`, `legacy_mul_nan`, `half_rounding`, `nan`) can be named too, or `all`. **What `safe` changes** (docs/metal-backend.md, linked from docs/native-host.md): with `denormals`, the flush before `v_cvt_flr_i32_f32`, min, max, med3 and the x2/x4/÷2 output modifiers goes, so a negative denormal can floor to -1 instead of 0, and a surviving denormal can flip a compare or change an rcp. With `signed_zeros`, the sign of a zero can change, which divide and copysign can see; on the Apple GPU, min and max of +0/-0 return the second operand. **Measured** on the Wine route only: −1 to −5 ms GPU on one recorded frame with `safe`, picture within noise. Per dispatch with all kinds relaxed: up to two thirds of a pass. The riskier kinds saved more (up to −13.5 ms) but change NaN/rounding behaviour that one frame can't prove harmless. Nothing is measured on the native host yet, which is why `safe` is opt-in. Translating a 19,105-shader capture through the native host's path, the `exact` default gives DXIL byte-identical to main for every shader; `safe` changes 14,423, and none switches between translating and refused. **Tests:** `exact_float_rules_order_minus_zero_below_plus_zero_in_min_and_max` checks the result bits of v_min/v_max (f32 and f16) of ±0 in both orders on Metal; the modes give different bits there, so it catches a lost exact path. `exact_float_rules_floor_a_negative_denormal_to_zero` checks the floor (both modes give 0 on the Apple GPU, so it does not tell them apart). The relax setting is part of the shader cache key and the pipeline-library `tag()`. victory-shader 220 passed, victory-gpu 146 passed; Windows clippy and `xtask policy` clean.
LakshanSivakumar commented 2026-11-26 11:01:05 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:01:05Z.

Review: CHANGES_REQUESTED


Thanks for the measurements. Blocking:

  1. This no longer compiles against main. gfx_refusal_tests.rs:156, a Parts {} literal added on main by #29, lacks relax, so cargo test and clippy --all-targets fail with E0063. Please rebase.

  2. safe can't be the default. It isn't limited to zero-versus-denormal results:

    • denormals also removes the flush before v_cvt_flr_i32_f32, min, max, med3 and the x2/x4/÷2 output modifiers. So a negative denormal floors to -1 instead of 0, and a surviving denormal can flip a compare or give a different rcp.
    • signed_zeros changes the sign of a zero, which divide and copysign can see.
    • The measurements are one recorded frame through D3DMetal, with nothing on the native host.

    Please make the default exact, with VICTORY_RELAX_FLOAT=safe opt-in, until there is native evidence and a numeric test (the current test compares instruction counts, not values).

  3. Smaller. Please add relax to the pipeline-library tag() (as #35 does), and correct the "safe" wording in docs/metal-backend.md.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6072962103 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37#pullrequestreview-6072962103). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:01:05Z. **Review:** CHANGES_REQUESTED --- Thanks for the measurements. Blocking: 1. **This no longer compiles against main.** `gfx_refusal_tests.rs:156`, a `Parts {}` literal added on main by #29, lacks `relax`, so `cargo test` and clippy `--all-targets` fail with E0063. Please rebase. 2. **`safe` can't be the default.** It isn't limited to zero-versus-denormal results: - `denormals` also removes the flush before `v_cvt_flr_i32_f32`, min, max, med3 and the x2/x4/÷2 output modifiers. So a negative denormal floors to -1 instead of 0, and a surviving denormal can flip a compare or give a different rcp. - `signed_zeros` changes the sign of a zero, which divide and copysign can see. - The measurements are one recorded frame through D3DMetal, with nothing on the native host. Please make the default `exact`, with `VICTORY_RELAX_FLOAT=safe` opt-in, until there is native evidence and a numeric test (the current test compares instruction counts, not values). 3. **Smaller.** Please add relax to the pipeline-library `tag()` (as #35 does), and correct the "safe" wording in `docs/metal-backend.md`.
LakshanSivakumar commented 2026-11-26 11:22:25 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:22:25Z.

Review: CHANGES_REQUESTED


Thanks for fixing the fixture. Still open:

  • Default both hosts to exact and keep safe opt-in.
  • Add numeric coverage for the negative-denormal floor and the signed-zero cases. The current test compares DXIL sizes only.
  • Include the effective relax settings in the pipeline-library tag().
  • Correct the "safe" wording in docs/metal-backend.md.

Also, please remove the AI Co-Authored-By trailer from 730455a. This repo doesn't take AI attribution lines.

Suggested landing order once the blockers are fixed, to keep conflicts down: #35 → #36 → #34 → #37 → #33.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073282966 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37#pullrequestreview-6073282966). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T11:22:25Z. **Review:** CHANGES_REQUESTED --- Thanks for fixing the fixture. Still open: - Default both hosts to `exact` and keep `safe` opt-in. - Add numeric coverage for the negative-denormal floor and the signed-zero cases. The current test compares DXIL sizes only. - Include the effective relax settings in the pipeline-library `tag()`. - Correct the "safe" wording in `docs/metal-backend.md`. Also, please remove the AI `Co-Authored-By` trailer from 730455a. This repo doesn't take AI attribution lines. Suggested landing order once the blockers are fixed, to keep conflicts down: #35 → #36 → #34 → #37 → #33.
64bitMango commented 2026-11-26 11:53:36 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T11:53:36Z.


Thanks. Merged main with the relax fix. The default is now exact; VICTORY_RELAX_FLOAT=safe is opt-in. The docs (including metal-backend.md) now list what safe changes: the floor, min/max/med3 and output-modifier flushes, and zero signs that divide and copysign can see. They also say the only evidence is one D3DMetal frame. relax now feeds the pipeline-library tag(). I added a GPU value test: exact floors a negative denormal to 0 through v_cvt_flr_i32_f32. On my Apple GPU the relaxed path also gives 0, so the test doesn't yet tell the two modes apart there.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7191299928 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37#issuecomment-7191299928). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T11:53:36Z. --- Thanks. Merged main with the `relax` fix. The default is now `exact`; `VICTORY_RELAX_FLOAT=safe` is opt-in. The docs (including metal-backend.md) now list what `safe` changes: the floor, min/max/med3 and output-modifier flushes, and zero signs that divide and copysign can see. They also say the only evidence is one D3DMetal frame. `relax` now feeds the pipeline-library `tag()`. I added a GPU value test: `exact` floors a negative denormal to 0 through `v_cvt_flr_i32_f32`. On my Apple GPU the relaxed path also gives 0, so the test doesn't yet tell the two modes apart there.
64bitMango commented 2026-11-26 11:56:50 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T11:56:50Z.


@LakshanSivakumar ready for another look when you have time. The review points are addressed above.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7191368893 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37#issuecomment-7191368893). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T11:56:50Z. --- @LakshanSivakumar ready for another look when you have time. The review points are addressed above.
LakshanSivakumar commented 2026-11-26 12:10:06 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:10:06Z.

Review: CHANGES_REQUESTED


Thanks for making exact mode the default on both hosts, fixing the fixture, and wiring relax into the cache keys. Please add bit-pattern tests for exact min/max of +0 and -0 in both operand orders. The floor test is worth keeping, but both modes returned zero on the tested GPU, so it can't catch a lost exact-mode flush. Please also update the PR body (it still calls safe the default) and link the corrected float-mode notes from docs/native-host.md.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6073893847 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37#pullrequestreview-6073893847). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:10:06Z. **Review:** CHANGES_REQUESTED --- Thanks for making exact mode the default on both hosts, fixing the fixture, and wiring relax into the cache keys. Please add bit-pattern tests for exact min/max of `+0` and `-0` in both operand orders. The floor test is worth keeping, but both modes returned zero on the tested GPU, so it can't catch a lost exact-mode flush. Please also update the PR body (it still calls `safe` the default) and link the corrected float-mode notes from `docs/native-host.md`.
64bitMango commented 2026-11-26 12:37:07 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:37:07Z.


Thanks. Added exact_float_rules_order_minus_zero_below_plus_zero_in_min_and_max: v_min/v_max f32 and f16 of (+0,-0), (-0,+0), (-0,-0) and (+0,+0), checked on the result bits on Metal. Expected bits follow max_min_flushed (min is -0 if either operand is; max is +0 unless both are). Unlike the floor case, the modes differ on the Apple GPU: with signed_zeros it returns the second operand (min and max of (+0,-0) are both -0), so the test catches a lost exact path. docs/native-host.md now links the float-rule notes in metal-backend.md, and the PR body is corrected (exact is the default). Squashed to one commit.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7192236262 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37#issuecomment-7192236262). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T12:37:07Z. --- Thanks. Added `exact_float_rules_order_minus_zero_below_plus_zero_in_min_and_max`: `v_min`/`v_max` f32 and f16 of (+0,-0), (-0,+0), (-0,-0) and (+0,+0), checked on the result bits on Metal. Expected bits follow `max_min_flushed` (min is -0 if either operand is; max is +0 unless both are). Unlike the floor case, the modes differ on the Apple GPU: with `signed_zeros` it returns the second operand (min and max of (+0,-0) are both -0), so the test catches a lost exact path. docs/native-host.md now links the float-rule notes in metal-backend.md, and the PR body is corrected (`exact` is the default). Squashed to one commit.
64bitMango commented 2026-11-26 12:38:51 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T12:38:51Z.


@LakshanSivakumar ready for another look when you have time. The review points are addressed in the comment above, and the branch is squashed to one commit.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7192275131 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37#issuecomment-7192275131). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T12:38:51Z. --- @LakshanSivakumar ready for another look when you have time. The review points are addressed in the comment above, and the branch is squashed to one commit.
LakshanSivakumar commented 2026-11-26 12:47:22 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T12:47:22Z.

Review: APPROVED


Thanks. The +0/-0 min/max bit-pattern tests (f32 and f16, both operand orders) fail with the fix-up forced off, exact is the default, the PR body is corrected and the float notes are linked. Approved. Heads-up: #35 lands first, and the two conflict in pipeline/library.rs tag(). After it merges, please rebase and hash both translation_settings() and relax there; I'll merge once CI is green.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:review:6074371863 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37#pullrequestreview-6074371863). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T12:47:22Z. **Review:** APPROVED --- Thanks. The +0/-0 min/max bit-pattern tests (f32 and f16, both operand orders) fail with the fix-up forced off, exact is the default, the PR body is corrected and the float notes are linked. Approved. Heads-up: #35 lands first, and the two conflict in `pipeline/library.rs` `tag()`. After it merges, please rebase and hash both `translation_settings()` and `relax` there; I'll merge once CI is green.
64bitMango commented 2026-11-26 13:17:31 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T13:17:31Z.


Closing this: I'm continuing this work on my fork, 64bitMango/Native-Victory-macOS, where it's merged with the other open PRs (#33–#37). Thanks for the thorough reviews; the fixes from your latest feedback are included there.

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7193138263 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37#issuecomment-7193138263). Originally posted by [64bitMango](https://github.com/64bitMango) on 2026-11-26T13:17:31Z. --- Closing this: I'm continuing this work on my fork, [64bitMango/Native-Victory-macOS](https://github.com/64bitMango/Native-Victory-macOS), where it's merged with the other open PRs (#33–#37). Thanks for the thorough reviews; the fixes from your latest feedback are included there.
LakshanSivakumar commented 2026-11-26 13:23:14 +00:00 (Migrated from github.com)

Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T13:23:14Z.


Thanks, do help to submit a PR if you have made progress!

<!-- greyfinch-sync:LakshanSivakumar/Native-Victory-macOS:comment:7193278698 --> Imported from [LakshanSivakumar/Native-Victory-macOS](https://github.com/LakshanSivakumar/Native-Victory-macOS/pull/37#issuecomment-7193278698). Originally posted by [LakshanSivakumar](https://github.com/LakshanSivakumar) on 2026-11-26T13:23:14Z. --- Thanks, do help to submit a PR if you have made progress!

Pull request closed

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
LakshanSivakumar/Native-Victory-macOS!37
No description provided.