mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 21:45:54 +01:00
[PR #1027] [CLOSED] rdna2spirv: float min and max order -0 below +0 on the GPU too (SHADER-MINMAX-SIGNED-ZERO) #1064
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#1064
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/1027
Author: @oscarlosu-lab
Created: 11/24/2026
Status: ❌ Closed
Base:
main← Head:pr/minmax-signed-zero📝 Commits (1)
9bc384brdna2spirv: float min and max order -0 below +0 on the GPU too (SHADER-MINMAX-SIGNED-ZERO)📊 Changes
7 files changed (+118 additions, -15 deletions)
View changed files
📝
docs/design.md(+1 -1)📝
runtime/test/shaders/check.py(+4 -0)➕
runtime/test/shaders/ps_fminmax_signed_zero.asm(+20 -0)📝
scripts/run_gpu_tests.py(+4 -0)➕
tests/semantic/fixtures/disasm/ps_fminmax_signed_zero.s(+11 -0)📝
tests/semantic/test_float_nan_fract.py(+19 -0)📝
tools/rdna2spirv.py(+59 -14)📄 Description
Claimed in the coordination issue as: SHADER-MINMAX-SIGNED-ZERO
Draft: the fix is not demonstrated on the GPU I have. On an NVIDIA RTX 3060 (Windows 11, driver 621.35) the new fixture passes both before and after the change, native and with
LEONIDA_W64_EMULATE=1: that driver already returns +0 forNMax(-0, +0). I'm asking for a run on AMD (RADV and the proprietary driver) and Intel before this leaves draft; if none of them returns the first zero either, this can be closed and only the fixture kept.Why
tools/rdna2spirv.pylowersv_max_f32/v_min_f32and their f16, packed, three-operand and med3 forms to GLSL.std.450NMax/NMin. GLSL.std.450 defines those as "y if x < y, otherwise x" (the other operand for a NaN). -0 and +0 compare equal, so on a driver that follows that literally, with two zeros of opposite sign the result is the first operand:max(-0, +0)is -0 andmin(+0, -0)is +0. The modules declareSignedZeroInfNanPreserve 32, so the sign is meant to survive. RDNA2 gives +0 for max and -0 for min in either order (docs/design.md, Float min/max row: "-0 < +0", measured on gfx1030). A -0 that should be +0 turns, for example, a followingv_rsq's +inf into -inf.The CPU interpreter in
tests/semanticalready orders -0 below +0 forNMax/NMin, so no CPU test could see the difference. Marvisak/VIctory (GPL-3.0) commitbf84134b2found and fixed the same thing in its DXIL lowering (DXIL's FMax/FMin are a compare and select there).Change
Gen.glsl_minmaxemitsNMax/NMinand, when both operands are zeros (magnitude bits 0), takes the result from their sign bits: AND for max, OR for min. Every f32, f16, packed, min3/max3 and med3 lowering goes through it. med3 skips it when at most one operand can be a zero (a constant that is not one), so an all-constant med3 still emits no select (test_v_med3_f32_all_constants_needs_no_select). NaN handling is unchanged. Cost: 8 instructions per min/max.runtime/test/shaders/ps_fminmax_signed_zero.asm: max and min of -0 and +0 in both orders, read from memory; incheck.pyandscripts/run_gpu_tests.py, with its translator fixture.tests/semantic/test_float_nan_fract.py: the expected words, and the sign-bit select after each min/max.docs/design.md: the Float min/max row says how the order is kept.Tested
scripts/run_semantic_tests.py tests/semantic: passes excepttest_image_cube_store_glc, which cannot startllvm-mcon this host (the Windows path splitting claimed as TEST-CUBE-WINPATH), unrelated.regen_fixtures.py --check,check_no_game_data.py,tests/test_docs_links.py: pass.run_gpu_tests.py --filter ps_fminmax_signed_zeropasses before and after (see above).AI-assisted (Claude Code). No game files.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.