Shader: relax the console float rules the host can take as they are (VICTORY_RELAX_FLOAT, exact by default) #37
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/37"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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::Relaxleaves each kind to the host. The default isexact: every console rule is kept.VICTORY_RELAX_FLOAT=safeopts 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, orall.What
safechanges (docs/metal-backend.md, linked from docs/native-host.md): withdenormals, the flush beforev_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. Withsigned_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 whysafeis opt-in. Translating a 19,105-shader capture through the native host's path, theexactdefault gives DXIL byte-identical to main for every shader;safechanges 14,423, and none switches between translating and refused.Tests:
exact_float_rules_order_minus_zero_below_plus_zero_in_min_and_maxchecks 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_zerochecks 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-librarytag(). victory-shader 220 passed, victory-gpu 146 passed; Windows clippy andxtask policyclean.Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by LakshanSivakumar on 2026-11-26T11:01:05Z.
Review: CHANGES_REQUESTED
Thanks for the measurements. Blocking:
This no longer compiles against main.
gfx_refusal_tests.rs:156, aParts {}literal added on main by #29, lacksrelax, socargo testand clippy--all-targetsfail with E0063. Please rebase.safecan't be the default. It isn't limited to zero-versus-denormal results:denormalsalso removes the flush beforev_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_zeroschanges the sign of a zero, which divide and copysign can see.Please make the default
exact, withVICTORY_RELAX_FLOAT=safeopt-in, until there is native evidence and a numeric test (the current test compares instruction counts, not values).Smaller. Please add relax to the pipeline-library
tag()(as #35 does), and correct the "safe" wording indocs/metal-backend.md.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:
exactand keepsafeopt-in.tag().docs/metal-backend.md.Also, please remove the AI
Co-Authored-Bytrailer 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.
Imported from LakshanSivakumar/Native-Victory-macOS. Originally posted by 64bitMango on 2026-11-26T11:53:36Z.
Thanks. Merged main with the
relaxfix. The default is nowexact;VICTORY_RELAX_FLOAT=safeis opt-in. The docs (including metal-backend.md) now list whatsafechanges: 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.relaxnow feeds the pipeline-librarytag(). I added a GPU value test:exactfloors a negative denormal to 0 throughv_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.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.
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
+0and-0in 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 callssafethe default) and link the corrected float-mode notes fromdocs/native-host.md.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_maxf32 and f16 of (+0,-0), (-0,+0), (-0,-0) and (+0,+0), checked on the result bits on Metal. Expected bits followmax_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: withsigned_zerosit 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 (exactis the default). Squashed to one commit.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.
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.rstag(). After it merges, please rebase and hash bothtranslation_settings()andrelaxthere; I'll merge once CI is green.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.
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!
Pull request closed