Repository navigation
fix(shader): keep the f32 sign on native f16 results when the NaN probe matches - #18484
oneandonlydean merged 2 commits into
Conversation
|
Windows data point on a different AMD GPU: this card does not show the failure, so I can't confirm the fix here, only that the PR doesn't break these tests. Setup: Windows 11 Enterprise 22621, RX 6700 XT (RDNA 2), AMD driver 26.10.1, MinGW-w64 GCC 15.2 UCRT, Release,
The binaries matched the hashes recorded at preparation for both arms, and each receipt shows exit 0 and Games on this machine log AI-assisted: yes. |
|
Thanks for the RX 6700 XT run. A passing test does print its probe line with Look for On the 860M (driver 26.10.2) it says AI-assisted: yes (Claude Code) |
|
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
|
|
An RDNA 3.5 data point for "A conversion never changes the sign", measured with Setup:
Rows:
Forms:
The result sign is compared with the f32 value converted, or with the f16 source for
A second run printed exact bits in 8 modes: IEEE 0 and 1, f32 denormal field 0 and 3, and f16 denormal field 0 and 3, all with f16 round mode 0. In every one of them:
So on gfx1151 the f16 result of a conversion or an The oracle runs raw ISA through HIP, not the Vulkan driver's Not run: the recompiler side (no Windows build of the runner here), and the PR's tests. AI-assisted: yes (measurement scripted with Claude Code; rows and results checked by me). |
|
A second RDNA 3.5 data point, on an older driver than the 860M one. It has the same probe result and the same eight failures on main. All eight pass with this PR. Setup:
Command (separate ctest invocations, one at a time): Results:
The failures on main are all −0 returned as +0, for example:
On the open question of GPU generation vs driver: both RDNA 3.5 parts fail the same way, the 860M on Adrenalin 26.10.2 (.12012) and the 8060S on 32.0.22032. The RX 6700 XT on 26.10.1 passes. That points at the generation more than the driver, although the probe says Not run: RADV, Intel, NVIDIA. AI-assisted: yes (run scripted with Claude Code; results checked by me) |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed the f32 sign on native f16 narrowing — no blocking findings
The change keeps the f32 source sign on the native f16 narrowing path, and the code I read at head 7d9d84f9c7ba87d6726511fb74daefb1843c1762 matches the description.
What I ran
- Head
7d9d84f9c7ba87d6726511fb74daefb1843c1762, basemain. - Read the diff of both changed files and the emitter at head (
SpirvAluEmitterMath.cpplines 2005–2045), plus the three call sites ofEmitNativeF32ToF16BitsRte. - No build and no tests run here (no-build review). The author reports a run on AMD Radeon 860M (driver 26.10.2), which I did not perform.
Results
| Check | Result | Note |
|---|---|---|
| Diff read | passed | 2 of 2 files |
| Emitter read at head | passed | Lines 2005–2045 |
| Call sites | passed | 3 sites, all pass f32 values |
| Build and tests | not run | No-build review |
| Author's device run | not run | Reported by the author, not verified here |
Findings
Blocking
None.
Non-blocking
SpirvAluEmitterMath.cpp:2036: the narrowed path now returnssign | (bits & 0x7fff). The high half ofbitsis the constant zero fromOpCompositeConstruct(line 2032), so the mask keeps only the f16 result. Sign and magnitude are correct for finite values, and for NaN the sign comes from the source, as the non-narrow path already does (line 2042).SpirvAluEmitterMath.cpp:2035: thesignline moved above thenanPayloadUnusedreturn. ThenanPayloadUnusedpath (line 2038) does not usesign, and the final return (line 2042) still does, so that path behaves as before.- No test is added in this PR. Coverage depends on the existing
agc_driver_float16_*and related tests, which the author reports fail onmainon this device and pass with the change. A unit test that feeds a computed negative value through the narrowed path would cover the case the probe misses.
Sources
- Diff:
diff.patch,SpirvAluEmitterMath.cppanddocs/dev/ARCHITECTURE.md, head7d9d84f9c7ba87d6726511fb74daefb1843c1762.
Not verified
- Build and test results on any device; only the author's report exists.
- RADV, Intel and NVIDIA behaviour; the description says these are not tested.
- The probe's sign coverage: the probe converts buffer-loaded values, so a device can pass it and still return +0 for computed -0. The description and
ARCHITECTURE.mdstate this; I did not check the probe's inputs in full.
To get this to a good state
- Optional: add a test for a computed negative value through the narrowed path, or name the existing test that covers it.
- Rerun the eight listed
agc_drivertests on the new head if the head changes.
|
Thanks for the review. On the test: the eight
A device whose driver already keeps the sign passes them either way. So they guard this change only on drivers that drop the sign, such as AMD's Windows driver here. A host-side test could not see the bug, because it is in the driver's The head has not changed since my run, so the eight results in the description still apply. AI-assisted: yes (Claude Code) |
|
RADV data point, since the description lists RADV as not tested. On RADV the probe also picks the native path, but the eight tests pass on Setup: Ubuntu 26.04, Linux 7.0, AMD Radeon 780M (Ryzen 9 PRO 8945HS, RDNA 3,
Every run selected the 780M ( AI-assisted. |
…be matches Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
7d9d84f to
a82def3
Compare
|
RDNA 3 on AMD's Windows driver, on the current head Setup: Radeon 780M (
AI-assisted: yes (Claude Code) |
|
Ran the eight f16 tests from the description and the other Setup: Arch Linux (kernel 7.3.4), GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (vendor
On this driver the start-up probe does not select the native path, on either side, so the tests run the emulated conversion and the changed The probe's own native variant does go through the changed path: in all 25 runs per side, 156 fewer probe results differ on this PR, so the added sign changes some native results on this driver too. The remaining differences keep the probe on the emulated path. The three No new AI-assisted: yes (Claude Code) |
|
Confirmation on a second AMD device with AMD's Windows driver: 8 f16 tests fail on Setup: Windows 11 25H2 (build 26200), two GPUs in the same machine, each selected with
AI-assisted: yes (build and runs scripted with an AI assistant, on the hardware above). |
|
RDNA4 data point for this fix, on AMD's Windows driver. Windows 11 Pro 10.0.26100, AMD Radeon RX 9070 XT (0x1002:0x7550, RDNA4), AMD driver 32.0.32015.7029, MSYS2 UCRT64 GCC 16.2.0, Release, The eight tests listed in the description:
The probe line reads Not done: no Khronos validation layer is installed here, so there is no VUID comparison, and I ran only these eight tests on the change, not the rest of the suite. AI-assisted: yes |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — looks good
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head a82def3918e847b5cbc9b9fed4613b22f362c8fa. I read the prepared description, commits, manifest, diff, both changed files, and targeted emitter callers and conversion probe code. I did not run build or tests; the reported device test results are author supplied.
Results
| Check | Result | Note |
|---|---|---|
| Changed code review | passed | Sign extraction and native result mask inspected |
| Build and tests | not run | No local execution performed |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author-reported Windows 11 / AMD Radeon 860M results were not independently verified. I did not read other files in files.json beyond the two changed files and the targeted context ranges; no changed files were excluded from the prepared bundle.
To get this to a good state
Nothing is required.
|
Tested head Setup: Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
Whole batch: the full This is one combined tree, not a run of this PR alone. AI-assisted: yes (Claude Code) |
What
On AMD's Windows driver, eight f16 execution tests fail on
mainagain. Each one returns +0 where -0 is expected, the problem #2483 reported:agc_driver_f16_conversion_float_modeagc_driver_float16_miscagc_driver_float16_modifiersagc_driver_float16_roundingagc_driver_fp16_overflowagc_driver_ldexp_f16_inline_constantsagc_driver_sdwa_ldexp_f16agc_driver_vop2_modifier_formsFor example:
v_ldexp_f16 0x8000, 0.5 is 0x0000, expected 0x8000.Cause:
EmitNativeF32ToF16BitsRte.if (state.float16NarrowNans) return bits;above that fix. It returns the rawOpFConvertresult when the start-up probe finds that the device's f32 to f16 NaN results match RDNA.f32 to f16 NaN results: native (0 of 220032 probe results differ)), so the sign fix is skipped. The probe converts values loaded from a buffer and keeps the sign there; the failing tests convert the result of an f32 operation, and the driver returns +0.APS5_NO_NATIVE_F16_NANS=1, which skips the probe, all eight pass onmain.Change: the
float16NarrowNanspath still returns the native result, NaN payload included, but ORs in the f32 source's sign, as the other native path does. A conversion never changes the sign, so devices that already returned the right sign get the same bits. The cost is three integer instructions per conversion instead of the full NaN rebuild that #11351 removed.docs/dev/ARCHITECTURE.mdsays the emitter returns the native result when the probe matches. It now adds that a narrowed value takes its sign from the f32 source, and why.Tested
Windows 11, AMD Radeon 860M (RDNA 3.5), AMD proprietary driver 26.10.2, MinGW GCC 15.2 Release, on
mainf57c971559. Every run usedANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.mainmainwithAPS5_NO_NATIVE_F16_NANS=1Rest of the suite:
ctest -R '^(agc|shader|job)'gives 1627 of 1631. The four that don't pass:agc_driver_sample_order_grid_referencealso fails onmainhere (agc_driver_sample_order_grid_reference: exact 2x sample-order path leaves odd rows at pixel (0,0)'s locations on RX 6700 XT (Windows) #18229);agc_drivertimed out under-j 8and passes alone (34 s);shader_memory_decoder_toleranceandshader_operand_typeshave no executable in this configuration.tools/check_conventions.py --base origin/mainpasses.Overlap:
tools/pr_overlap.py --branchmerged 33 of 33 overlapping pull requests cleanly. Two conflict on the one-lineARCHITECTURE.mdparagraph:Whichever merges second rebases. It could not compare feat(aot): consolidate native ARM64 compiler, runtime and consumers #5021, perf(shader): run wave64 compute at one lane where no lane can tell #12324 and fix(shader): emit OpFmaKHR for f32 fma when VK_KHR_shader_fma is available #15343, which also touch
SpirvAluEmitterMath.cpp; none of them changesEmitNativeF32ToF16BitsRte.Not tested on RADV, Intel or NVIDIA. The probe also selects the native path on those devices when it matches, and there the added sign is the sign they already return.
Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)