fix: HLSL f32 operations folded at compile time (x + 0, 0 - x, x - x, 0 × x) #220
No reviewers
Labels
No labels
accessibility
bloqué : binaire console
bug
chargeur
console-dll
cpu
documentation
duplicate
enhancement
good first issue
gpu
help wanted
invalid
performance
question
runtime-gdk
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/LooperSalty--AnyXboxX!220
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/220/head"
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?
@IxMxAMAR on GitHub · 2026-11-25 16:22 UTC · original
IxMxAMAR:fix/hlsl-f32-zero→main· +50 −5 · 3 files · 2 commits · merged 2026-11-25 18:28 UTCChange
Replaces #169, which was closed during the 25 November triage. It is rebased on
main(ab55a2a), and it fixes the cases of #166 (closed in the same triage; they still fail onmain, see below).The f32 templates
v_add,v_sub,v_subrevandv_mul_f32go through threeprecisefunctions,F32Add,F32SubandF32Mul, now inemu/rdna2_hlsl_helpers.pywheremainmoved the HLSL helpers. dxc no longer removes these operations, and the DXIL marks them!dx.precise.What changed in the rebase: the FMA family (
v_fma,v_fmac,v_fmamk,v_fmaak,v_macandv_mad_f32) keepsmain's templates.main'sFmaF32works on the bits with no float arithmetic, so the sign of zero is right by construction. This PR's formerF32Fmais dropped, and the test'sfma(x, 1, 0)andv_fmaccases pass withFmaF32.Drivers still fold some operations despite
precise(measured: AMDfadd x, 0.0andfsub x, x; Intelfsub 0.0, x; RDNA 2 also0 - xandinf - inf). Two cases are therefore computed in integer:x - xwith identical operands gives +0, the default NaN 0xFFC00000 for ±infinity (as the interpreter does), or the NaN itself, made quiet.Cost: a few integer operations per addition and subtraction.
Out of scope: the sign of a subtracted NaN (
0 - NaN) differs between the interpreter (x86 rules) and Intel and AMD hardware, even without folding. As in the test of #138, the new test avoids NaNs whose pattern depends on the GPU.Linked issue: Refs #166
Verification
main'srdna2_hlsl_ops.pyandrdna2_hlsl_helpers.py, this PR's test),test_constant_zero_folds_match_on_gpufails on all three: byte 0x20003 is 0x80 instead of 0x00, the sign of zero.main's new rounding test (test_rounding_and_fract_match_on_gpu) passes alongside it.runtime/(ANYXBOXX_RUNTIME).f5cdd8e; the f32 templates and helpers have not changed since. The Intel and WARP runs are onab55a2a.1100+.Earlier revisions were also checked by others:
Oracle and test data
test_constant_zero_folds_match_on_gpu(tests/test_rdna2_exec_specials.py) compares the whole memory, byte for byte, with the reference interpreter.0 + xandx + 0,0 - x(v_subandv_subrev),x - x,0 × x,fma(x, 1, 0)andv_fmac.0 × x).Checklist
test_readme_sync.pychecks it).Made with AI assistance.