Repository navigation
shader: preserve signed zero in floating-point min and max - #2044
Conversation
Ran it, broke the helper five ways — all caught — and checked the signed-zero table by bit patternRead on the merge base ( out/pe-env/Scripts/python.exe -B tests/shader_signed_zero_minmax_check.py
20 signed-zero lowering checks reject both helper mutations exit 0
The second one is the subtle one: The table, checked against the ISA order over the corner valuesI transcribed so Exactly-one-zero must not take the special path, and it does not: That last line is the interesting one: A mistake I made while checking this, recorded because it is instructiveMy first reference implementation used What I could not checkThe claim that keeping the selection in The Notes
|
|
Thanks @ChazY11. The five mutations and the bit-pattern table are a useful cross-check, and yes, the fixture has both On the one claim you couldn't check, I compiled the helper with DXC 1.9 (
So at the DXIL stage both keep the zero bits; DXC doesn't merge them in either form. The code comment overstates this, and the real reason is narrower. With the integer selection there's no float-typed choice between two zeros left for the driver's backend compiler, which may treat The cache revision only invalidates translations cached before this change; you're right that the fixture doesn't read it. Status: ready to merge from our side. CI is green at |
tedin7
left a comment
There was a problem hiding this comment.
Review of head c56a2485b10194903482017bafb75a4c13a88481.
Verdict: no blocking findings. P1=0, P2=0.
What I checked
- The helper
minmax_zero32(tools/shader_minmax.py) is integer-selected only when both operands are +/-0. Max uses AND of the sign bits, min uses OR. All other pairs, including NaN mixes, fall through to the oldmin/max, so behavior elsewhere is unchanged. - Both translators use the same helper through one shared module (
FLOAT_MINMAX): offline pixel (min, max, min3, max3, med3_32, packedminmax16_num) and startup (v_min_f32,v_max_f32, min3, max3, med3). - Packed f16 keeps the NaN-first selection and only defers to the zero rule for non-NaN pairs. This matches the PR text.
- The startup cache revision moves to
x2w-startup-shader-7insrc/startup_stubs/d3d12_draw.inl. It matches the revision the Python side hashes. - Clean-room: the title and body are neutral and the sources cited are the public ISA and DXIL docs. CMake registers the new Linux control plus warp and hardware draw tests, with SKIP_RETURN_CODE 77.
CI: the Windows build and test job, the Linux Python checks and the gfx1013 assemble and translate job are all green. The /O2 job and the coverage chart job were skipped.
Commands executed locally (Linux worktree)
python3 tests/shader_signed_zero_minmax_check.py->20 signed-zero lowering checks reject both helper mutations, rc 0python3 tests/pixel_aot_check.py-> rc 0python3 tests/docs_links_check.py->Checked 18 Markdown files and 388 links.python3 tests/bidi_controls_check.py-> no bidirectional controlsgit diff --check origin/main...HEAD-> clean
Mutations I tried (reverted afterwards)
- In
tools/startup/gfx2hlsl.py, I flipped the last polarity ofv_max3_f32fromtruetofalse. The new check failed with an AssertionError onmax3, so it was killed. - In
tools/shader_minmax.py, I changed the max zero case froma_bits & b_bitstoeither. The check failed with an AssertionError on the helper text, so it was killed.
Nits (non-blocking)
- Both mutations were killed by source-text assertions on Linux. The real GPU readback check (WARP and hardware draw tests) only runs on Windows. The Windows CI job is green. The PR's own table shows the WARP and GTX 1060 runs, but those were on Windows 10 22H2, not Win2025.
- I did not run a Win2025 WARP pass myself. The change is shader lowering, so a maintainer may want that pass before moving the PR to Ready, if that is the gate.
med3mixed-zero ordering is not defined by the ISA. The PR already says it applies the same ordering. This is a documented choice, not a defect.
AI-assisted; commands listed were executed locally.
|
Ran it on an RX 9070 XT (driver 32.0.32029.2010), because the signed-zero rule is exactly the kind of thing that only shows on a real card: Both compilers are covered (dxc I also went back to the ISA clauses the helper rests on, and they are stronger than the "orders -0 below +0" summary you wrote — worth having in the comment of so min returns Limits: AMD only, no NVIDIA card here; and a green draw says the words match your reference on this driver, not that another compiler could not reorder the two zeros again. AI-assisted. |
|
@thepatrickworld, thank you for the RX 9070 XT run (0/252 words differ, with both compilers) and for pulling out the exact clauses.
Agreed on your limit: the hardware evidence is the original GTX 1060 6GB + WARP runs plus your RX 9070 XT. An Intel or newer NVIDIA run would still be welcome. Status: ready to merge from our side once CI is green on |
tedin7
left a comment
There was a problem hiding this comment.
Re-review of head df0dd5fa89d169e2097b3905825c7a311e29ed28 (previous review was on c56a2485; the new commits are 2919a123 plus a main merge).
Summary: no blocking issues. One doc inconsistency (P2) and two nits.
Checked (all executed locally in a review worktree)
git diff --stat origin/main...HEAD: 11 files, +376/-27. Title is neutral. PR is MERGEABLE.git merge-treeagainst currentorigin/main(5 commits ahead) is clean.- CI on this head: Linux Python checks pass, gfx1013 fixtures pass, Windows build and test pass.
python3 -B tests/shader_signed_zero_minmax_check.py->20 signed-zero lowering checks reject both helper mutations.python3 -B tests/pixel_aot_check.py->Self-test passed.python3 tests/docs_links_check.py-> 18 files, 405 links OK.python3 tests/bidi_controls_check.py-> OK.git diff --check origin/main...HEAD-> clean.- The
binary llvm-mc-15mode could not run here (llvm-mc-15is not installed on this host). CI covers it. - Mutation 1: replaced the
v_max3_f32lowering intools/startup/gfx2hlsl.pywith plainmax(max()). The test fails with an AssertionError. Killed. - Mutation 2: replaced
maximum ? (a_bits & b_bits) : eitherwitheitherintools/shader_minmax.py. The test fails. Killed. Both mutations were reverted. - Win2025 run not repeated: the diff changes HLSL text and helper wiring only. The WARP and hardware draw tests are registered in CMake and the Windows CI job is green.
Logic review
minmax_zero32(tools/shader_minmax.py): for two zeros, min takes the OR of the bits and max takes the AND. This matches the ISA rule that min returns -0 if either operand is -0 and max returns +0 when the zeros differ. Equal zeros are unchanged. Non-zero and NaN inputs fall through to the native min/max. The zero test is on the masked bits, so denormals are not caught. Correct.min3/max3are nested in both translators.med3is rebuilt from the helper in both. NaN handling inmed3_32is kept. Packed binary16 goes throughminmax16_num, which keeps the NaN select. All consistent.FLOAT_MINMAXis emitted once per pixel source and once in the startupcommon(). Compute requests are still refused on main, so no compute preamble is missing the helper after the merge.- Startup cache revision is
x2w-startup-shader-9in bothd3d12_draw.inlandgfx2hlsl.pyand agrees withdocs/startup-runtime.md:192.
Findings
- P2
docs/experiments.md:6298says the cache revision advances tox2w-startup-shader-7. The code anddocs/startup-runtime.md:192say-9. Update the doc line to-9. - nit
tools/shader_minmax.py:9hasFLOAT_MINMAX =""". Add a space before=. - nit The Linux test pins emitted strings, so only the Windows WARP and hardware draw tests prove the value behavior. Keep those required before Ready.
P1=0 P2=1
AI-assisted; commands listed were executed locally.
|
Thanks. Both fixed in b0bab44:
The signed-zero check (20 checks, both mutations rejected), docs links and Status: ready to merge from our side once CI is green. |
tedin7
left a comment
There was a problem hiding this comment.
Re-review of head b0bab443dcefc694d4040f186e1626e893b333c5 (previous review was on df0dd5fa; the one new commit is b0bab443, docs and spacing only).
Summary: no blocking issues. The earlier P2 and the earlier nit are both resolved.
Previous findings
- P2 (
docs/experiments.mdsaidx2w-startup-shader-7): resolved. Line 6298 now saysx2w-startup-shader-9. It agrees withsrc/startup_stubs/d3d12_draw.inl:210,tools/startup/gfx2hlsl.py:2711anddocs/startup-runtime.md:192. - nit (
FLOAT_MINMAX ="""spacing intools/shader_minmax.py): resolved. - nit (Linux test pins emitted strings): still true and still fine. Keep the WARP and hardware draw tests required before Ready.
Checked (all executed locally in a review worktree)
git diff --stat df0dd5fa..HEAD: 2 files, +2/-2 (docs/experiments.md,tools/shader_minmax.py). No logic change.python3 -B tests/shader_signed_zero_minmax_check.py->20 signed-zero lowering checks reject both helper mutations.python3 -B tests/pixel_aot_check.py-> exit 0.python3 tests/docs_links_check.py-> 18 files, 405 links OK.python3 tests/bidi_controls_check.py-> OK.git diff --check origin/main...HEAD-> clean.- Mutation: replaced
maximum ? (a_bits & b_bits) : eitherwitheitherintools/shader_minmax.py. The check fails with an AssertionError. Killed. Reverted withgit checkout -- .. - CI on this head: Linux Python checks pass, gfx1013 fixtures pass, Windows build and test pass.
- Win2025 run not repeated: since the last reviewed head only a doc line and one space changed.
Findings
- P1: none.
- P2: none.
AI-assisted; commands listed were executed locally.
tedin7
left a comment
There was a problem hiding this comment.
Re-review at head 4beb58eb04dfd2b1d226cc0cceab6ea711ba4da2 (a merge of main into the branch; no change to the min/max logic since the previously reviewed head b0bab443).
Findings
- P1: none.
- P2: none.
- Nit: reverting
x2w-startup-shader-9to-8intools/startup/gfx2hlsl.pyalone is not caught byshader_signed_zero_minmax_check.pyorstartup_gfx2hlsl_mad_check.py. The Python key and thesrc/startup_stubs/d3d12_draw.inl:222constant could drift apart without a failing test. Consider a small check that both strings match. - Nit: the Linux-only mutation of the helper is rejected by the exact-source pin, not by behavior. Behavior is only exercised by the
warp/hardwaredraw tests, which need Windows.
Checked
tools/shader_minmax.py: the OR rule for min and the AND rule for max on two zeros match the signed-zero rule in the ISA text quoted in the file. A NaN operand skips the zero branch becauseeither & 0x7fffffff != 0, so NaN behavior is unchanged.pixel_aot.py(min, max, min3, max3, med3_32, packed f16minmax16_num) andgfx2hlsl.py(v_min/max_f32, min3/max3, med3) all route through the helper.FLOAT_MINMAXis emitted once per shader in both translators.- The cache revision is bumped in both places,
gfx2hlsl.pyandd3d12_draw.inl. - CMake and
windows.ymlregister the new test, including the warp and hardware draw variants. - The title is neutral. The PR is mergeable. The Linux CI job passes. The Windows jobs were still pending when I checked.
Commands run locally (all passed)
python3 tests/shader_signed_zero_minmax_check.py->20 signed-zero lowering checks reject both helper mutationspython3 tests/pixel_aot_check.py-> rc 0python3 tests/startup_gfx2hlsl_mad_check.py-> passpython3 tests/docs_links_check.py-> 412 links OKpython3 tests/bidi_controls_check.py-> OKgit diff --check origin/main...HEAD-> clean- Mutation 1: changed max's AND to OR in
shader_minmax.py. The test failed with an AssertionError, so it is killed. Reverted. - Mutation 2: reverted the cache revision to
-8. Not caught (see the nit). Reverted.
I did not run the Windows WARP draw tests for this head, because the only change since the last review is a merge of main. The Windows CI jobs should confirm the readback tests.
AI-assisted; commands listed were executed locally.
|
@Jess-Doit could you rebase this branch onto current GitHub reports head Files that conflict with current
Commands run locally: Once it is rebased and CI is green it will be re-checked right away. AI-assisted; commands listed were executed locally. |
4beb58e to
69c6db7
Compare
|
@tedin7 thanks. Rebased onto current What changed in the rebase:
Tests on Windows 10 build 19045,
Ready to merge from our side. |
# Conflicts: # AGENTS.md # docs/startup-runtime.md # src/startup_stubs/d3d12_draw.inl # tools/pixel_aot.py # tools/startup/gfx2hlsl.py
# Conflicts: # AGENTS.md # docs/experiments.md # docs/startup-runtime.md # tests/startup_gfx2hlsl_buffer_store_check.py # tools/startup/gfx2hlsl.py
69c6db7 to
706767a
Compare
|
Rebased onto current Revision: #2010 moved the startup shader cache revision to 16, so this change now advances it to 17.
Tests on Windows 10 19045, GTX 1060 + WARP,
Ready to merge from our side. |
|
Heads-up, because the numbers moved under this branch. #2095 merged at 21:48 as There is also a content conflict behind the number, in Two smaller ones. AI-assisted. |
706767a to
25e01dc
Compare
|
Rebased onto What changed since
Tests on Windows 10 19045, GTX 1060 6GB (driver 32.0.15.6094) + WARP,
Ready to merge from our side. |
Both translators resolve a pair of zeros from the sign bits (maximum ANDs the signs, minimum ORs them), following the RDNA 2 V_MIN/V_MAX clauses. The startup shader cache revisions advance from 14 to 15 and 15cs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Fixed the failed Cause: Fix: the two values are re-pinned for Checks:
Ready to merge from our side. |
25e01dc to
a9fc952
Compare
|
An AMD adapter line for the table: the reference you cite is RDNA 2 and the rows above are WARP and a GTX 1060. Head cmake --preset dev -DINTAKE_PYTHON=…\out\pe-env\Scripts\python.exe
cmake --build --preset dev
ctest --preset dev --no-tests=error -R "^shader_signed_zero_minmax"All three ran and passed; the capture holds no So, on this adapter, after the change: 0 / 252. Every one of the 252 words agrees with the reference — the same cell as WARP after and as both GTX 1060 cells in the adapter table above. I did not measure the before column on this adapter. The check is added by this PR ( Neighbouring selections, to show the change does not disturb what surrounds it — the filters the run used: and what they reported: Two of the four names in that second filter exist in the suite; The hardware run reports AI-assisted. |
|
Merged current The shader cache revision is still 18 here and 17 on Commands executed locally
AI-assisted; commands listed were executed locally. |
…n-max # Conflicts: # tools/startup/gfx2hlsl.py
|
Thanks @tedin7 for the merge and the Windows Server 2025 run, and @thepatrickworld for the RX 9070 XT result (0 / 252). That gives an RDNA cell next to WARP and the GTX 1060.
The conflict and two follow-ups:
Checks:
Ready to merge from our side. |
|
Win2025 WARP receipt for head c1689a5 after updating with main. Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
Selection used: AI-assisted; commands listed were executed locally. |
tedin7
left a comment
There was a problem hiding this comment.
Review at head c1689a59 (main merged into the branch since the previously reviewed head 4beb58eb; the min/max logic is unchanged).
Findings
- P1: none.
- P2: none.
Checked
- Since
4beb58ebthe only PR-specific change is the update of the four mutations intests/startup_gfx2hlsl_float_alu_check.py(v_min_f32,v_max_f32,v_min3_f32,v_max3_f32). They match theminmax_zero32text and flip the same operation as before, so each mutation still changes a draw set. - The cache revision is 18 in
tools/startup/gfx2hlsl.pyand insrc/startup_stubs/d3d12_draw.inl. Nox2w-startup-shader-17literal is left intools,srcortests. - The behavior is guarded by D3D12 WARP readback tests (
shader_signed_zero_minmax_warp,startup_gfx2hlsl_f32_med3_warp,startup_gfx2hlsl_float_alu_warp). The Win2025 receipt for this head is on the PR. - The earlier nit about
-9versus-8is no longer relevant: the revision is now 18 andstartup_shader_cache_key_check.pypins it.
Commands run locally (all passed)
python3 tests/shader_signed_zero_minmax_check.py->20 signed-zero lowering checks reject both helper mutationspython3 tests/startup_gfx2hlsl_float_alu_check.py,tests/pixel_aot_check.py,tests/startup_shader_cache_key_check.py-> rc 0python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py-> rc 0git diff --check origin/main...HEAD-> clean- Mutation: changed the NaN mask in
tools/shader_minmax.pyfrom0x7fffffffto0x7ffffffe. The signed-zero check failed, so it is killed. Reverted. - Win2025 WARP, dev and release:
ctestselection of 237 tests, 237 passed.
AI-assisted; commands listed were executed locally.
|
Independent AMD RDNA 4 result on Environment
Commandscmake --build --preset dev --target offscreen_check
ctest --preset dev --no-tests=error -R "^shader_signed_zero_minmax" # three consecutive runs
python -B tests/shader_signed_zero_minmax_check.py draw <dxc> <offscreen_check.exe> hardware <fxc>
python -B tests/shader_signed_zero_minmax_check.py plain <dxc> <offscreen_check.exe> hardware <fxc>
python -B tests/shader_signed_zero_minmax_check.py invert <dxc> <offscreen_check.exe> hardware <fxc>
python -B tests/shader_signed_zero_minmax_check.py plain <dxc> <offscreen_check.exe> warp <fxc>
python -B tests/shader_signed_zero_minmax_check.py draw <dxc> <offscreen_check.exe> warp <fxc>
ctest --preset dev --no-tests=error -R "transcendental" -V # twice
git diff --stat 7949526d HEAD -- tests/shader_signed_zero_minmax_check.py \
tests/startup_gfx2hlsl_float_transcendental_check.py tests/startup_gfx2hlsl_lane_alu.py # empty
ObservedThe other two runs differ only in durations ( The fixture's own summaries, one per mode. Its convention is worth stating because it reads backwards: it exits 1 when differences are found, 0 when it finds none, and only 252 words is 63 rows of four: 29 pixel rows at What the
|
Change
Resolve a pair of floating-point zeros by sign in the offline pixel and startup shader translators. Max uses the AND of the sign bits and min uses the OR. The same helper feeds min3, max3, med3 and the per-half binary16 packed min/max path. Other operand pairs still use the existing float operations. Packed NaN selection, output modifiers and integer min/max are unchanged. The startup cache revision advances to
x2w-startup-shader-9(main is at-8), so previously translated shaders are regenerated.RDNA 2 defines the two-input binary32 and binary16 ordering in §12.7 (pp. 132–133 and 136). Min3 and max3 compose those operations (§12.12, p. 170). The packed definitions specify per-half min/max (§12.10, p. 164). The median description has no separate mixed-zero rule, so the fixture applies the same ordering to the median. DXIL FMin and FMax permit either input when the operands compare equal. AMD RDNA 2 ISA, DXIL operation reference
Before and after
The baseline used the translators at
150c625ae9b0c0f48d50f44d77899cc18291d2ec. Each adapter produced 252 result words across the offline pixel (DXCps_6_2) and startup (DXCps_6_0and FXCps_5_1) paths. The table gives mismatches against the independent reference. Each offline draw also checks all 4,096 rendered pixels.Each cell below contains four hexadecimal words in readback order. The first two two-input lanes place
(-0, +0)and(+0, -0)in order, followed by two negative zeros and two positive zeros. The three-input mixed rows repeat the two mixed pairs with a trailing-1and then+2. The all-zero rows use(-0,-0,+0),(+0,+0,-0),(-0,+0,+0)and(+0,-0,-0). The packed rows swap both half-lane orders.00000000 80000000 80000000 0000000080000000 80000000 80000000 0000000000000000 80000000 80000000 0000000000000000 00000000 80000000 00000000bf800000 bf800000 00000000 80000000bf800000 bf800000 80000000 80000000bf800000 bf800000 80000000 00000000bf800000 bf800000 80000000 8000000000000000 80000000 40000000 4000000000000000 00000000 40000000 4000000080000000 00000000 40000000 4000000000000000 00000000 40000000 4000000000000000 80000000 00000000 8000000080000000 80000000 00000000 0000000000000000 80000000 00000000 80000000/80000000 00000000 80000000 0000000080000000 80000000 80000000 8000000000000000 80000000 00000000 80000000/80000000 00000000 80000000 0000000000000000 00000000 00000000 0000000000000000 80000000 00000000 8000000080000000 00000000 00000000 8000000080000000 00008000 80000000 0000800080008000 80008000 80000000 0000800080000000 00008000 80000000 0000800000000000 00000000 80000000 00008000Single quiet NaN rows matched before and after on both adapters. For median with
(-1, +2, qNaN), the pixel path returnedbf800000and the startup path returned40000000, preserving their existing policies.Limits
The fixture covers the float min/max encodings already lowered by these two translators. Plain scalar and three-input binary16 min/max and the startup SDWA variants remain unsupported. Median and packed zero ordering were tested on desktop adapters. Console hardware, signaling NaNs and NaN payload propagation were unmeasured.
Verification
Tested commit
e6560f186ee6228ba2f497d4d48468f43dcef944.Windows 10 22H2, build 19045.6456. NVIDIA GeForce GTX 1060 6GB, driver 32.0.15.6094. In-box Microsoft Basic Render Driver (WARP), driver 10.0.19041.5794. DXC 1.9.2602.17, FXC 10.0.26100.9457, LLVM 15.0.7. D3D12 debug layer enabled, with zero errors and warnings in the signed-zero draws.
dev)release)The Debug totals count each selected test once, incorporating focused reruns after updating the existing pixel assertions and the new fixture's readback extent check. Both shader controls ran with the Debug renderer. The first changed word on WARP with plain min/max was the first output of offline f32 min, which returned
00000000in place of80000000. The hardware GPU check has a capability skip (77) for systems without a D3D12-capable adapter.The CPU checks reject both mutations across all 20 translator/encoding combinations. The LLVM 15 check reassembles the recorded instruction words.
Set
VULKAN_SDKto the Vulkan SDK 1.4.363.0 installation and make the Windows SDK shader compilers available. Use a Python environment withrequirements-dev.txtinstalled.The focused Debug reruns used
^shader_signed_zero_minmax_|^pixel_aot_(three_way_)?(warp|hardware)$and then^shader_signed_zero_minmax_as the CTest filter.To measure the baseline, run the same fixture with
beforein place of$modeagainst the base translators.I reran the same
$testsselection on the same machine, ate6560f18: 65/65 in dev and 65/65 in release on the GTX 1060 and WARP, with the debug layer on and no skips.After merging main and moving the cache revision to 7 (head
c56a2485), the Debug selection^shader_signed_zero_minmax_|^startup_gfx2hlsl_|^pixel_aot_(three_way_)?(warp|hardware)$|^docs_links$passed 50/50. The cache-revision checksstartup_image_sample_a16_check.pyandstartup_image_load_mip_check.pypass too.AI-assisted (Codex, driven with Claude Code; Claude Code reviewed the change and reran the selection).