Repository navigation
fix(shader): keep v_exp_f32 within RDNA precision on M1 - #24714
Romannachwievor wants to merge 4 commits into
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — comments
The patch is narrowly scoped and adds fractional exp2 coverage, but the generated Ldexp path is not confirmed against the test or an available check in this review.
What I ran
Reviewed head de334c9f3ab20a18cfe2e12791a967dfbcb5aae3 using the prepared diff and repo_read.py. No commands or tests were run.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed files | passed | Both changed files read |
| Tests | not run | Author-reported results only |
| Source behavior | not run | No build or GPU execution here |
Findings
Blocking
None.
Non-blocking
- The added
v_exp_f32expected-value checks permit a one-bit difference for every0x25case, not only the fractional cases motivating the fix (SdwaExpLogF32.cpp:219). This also weakens the existing exact checks for 0, 1, and 2. Consider restricting the tolerance to the cases that need it, or state why all exp2 cases should permit one ULP.
Not verified
- No tests were run. The Apple M1 / MoltenVK results and the separate Metal probe are author-reported.
- Did not read the entire test file or emitter file; inspected only relevant ranges and helpers. No files were excluded from the prepared changed-file manifest.
To get this to a good state
Nothing is required. Optional: narrow or explain the broadened exp2 tolerance.
Jazeupoi
left a comment
There was a problem hiding this comment.
Tested on an Apple M4 (MacBook Air, macOS 27.0.1, MoltenVK 1.4.2 from Vulkan SDK 1.4.363.1, x86-64 Release under Rosetta 2), a different Apple GPU generation from the M1 in the description. Base: main 0a025bd3c6 with #17425 and #11049 (needed for the macOS build). I applied this PR's diff (head de334c9f3a) on top; it applies cleanly. Each test ran 3 times with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and the Khronos validation layer loaded (VK_LOADER_DEBUG=layer):
agc_driver_sdwa_exp_log_f32 |
_wave64 |
|
|---|---|---|
| base | 3/3 pass | 3/3 pass |
| base + only this PR's strengthened test | 3/3 pass | 3/3 pass |
| this PR | 3/3 pass | 3/3 pass |
No VUID- messages. On the M4, Exp2 already meets the RDNA ULP bound for the new negative inputs without the change, so the imprecision looks specific to the M1.
SuperTuxKart (PPSA69421) is slower with this PR on the M4. The scene is a race on Subsea, seconds 40 to 60, with the same scripted input and a warm shader cache, in alternated runs. Frame p50 was 99.2 and 99.8 ms on the base, and 110.5 and 112.8 ms with this PR; two separate runs with this PR gave 112.7 (cold cache) and 112.4 ms. GPU busy per present goes from about 21 ms to 23 to 26 ms. The race draws correctly with this PR. Since the new path applies on every GPU and is not needed here, it may be worth limiting it to the devices that show the error.
AI-assisted: yes (Claude Code)
|
I ran this on AMD under RADV and on llvmpipe. The AMD parts show no change, but on llvmpipe the new Builds: merge-base
On every arm and GPU, the 11 tests in the set I didn't build are
For the positive fractional input the new path is just |
de334c9 to
6795f31
Compare
|
Fixed in head I rebuilt the focused test and AI-assisted: yes (Claude Code) |
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 6795f318f958552568bc50f521783864947bd9f6. No commands or tests were run. Read review/description.md, review/commits.md, review/manifest.json, review/diff.patch, SpirvAluEmitterMath.cpp around EmitFPExp2, and the changed test declarations and assertions in SdwaExpLogF32.cpp. Both files listed for review were read at the relevant changed sections; no files were excluded by manifest.json.
Results
| Check | Result | Note |
|---|---|---|
| Diff and changed paths | passed | Both changed files inspected |
| Tests | not run | Results in the PR description are author-reported |
Findings
Blocking
None.
Non-blocking
None.
Not verified
The author-reported M1 test runs and Metal probe were not independently reproduced. I did not inspect unrelated portions of either changed file or run builds, tests, or a negative control.
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) |
|
GPU run on RDNA4 (gfx1201) with the AMD Windows driver and the validation layer. The tests pass 3 of 3 runs, and a mutation of the new path fails them. But the change is not neutral on AMD. On 8191 inputs, What this run adds.
Code.
Overlap.
Evidence.
Negative control.
GPU. Head
Validation.
Host:
AI-assisted: yes |
|
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.
|
|
@Helldiverr thanks for the hardware sweep. Both points are addressed in
On M1 the probe logs Not run here: an RDNA device. If you can, a run of the two SDWA tests on gfx1201 should log AI-assisted: yes (Claude Code) |
|
@Romannachwievor On gfx1201 the new probe picks the host form, and Every GPU test logs this line: The first run logged 12 ms and 20 ms once each. Every other run logged 1 ms. Code (at
Sweep. I used the 8191 inputs from the earlier review: the test's 8 inputs plus a jittered grid over [-126, 128). I ran them through the recompiler with the earlier probe test (
Mutation. I inverted the decision at
Checks on the merge. GPU.
Validation.
Host:
AI-assisted: yes |
|
@Helldiverr thanks for the gfx1201 sweep and the mutation. On M1 (on
On integer inputs only: yes, the probe decides only from n in [-126, 127]. Those are the inputs with a known exact result. For fractional x, The AI-assisted: yes (Claude Code) |
|
On gfx1201 the new check does what it should. At The new check (
Mutations, all run on this GPU:
On integer inputs only: agreed. Without an RDNA table there is no exact reference for fractional inputs, and a device that falls back to the host form gets f16 part on the R9700: it runs and does not skip. Every passing log has Runs
Host:
AI-assisted: yes |
|
NVIDIA run at the current head: no regression, and the new probe keeps the host Setup: NVIDIA GeForce RTX 3070 (Ampere), driver 616.56, Windows 11 Pro 10.0.26100, WinLibs GCC 15.2.0 r7, Release, Vulkan validation layer 1.4.363. Base Tests run:
AI-assisted (Claude Code). |
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — no blocking findings
Nothing blocks this change; the inspected code supports the device-specific exp2 selection and range-reduced fallback.
What I ran
Reviewed head c74b1673fb4453a4456a315f3b0f6903355732f4 using repo_read.py. No commands or tests were run; the PR description reports test runs, which I did not independently reproduce.
Results
| Check | Result | Note |
|---|---|---|
| Code review | passed | Inspected changed exp2 logic and probe |
| Tests | not run | Results in the description are author reported |
Findings
Blocking
None.
Non-blocking
None.
Not verified
No tests were run. VulkanDevice.cpp was excluded from the prepared files because it was too large; I read the changed probe setup and target assignment there through the reader. The other 14 changed files listed as included in the manifest were not all read in full, so this review does not verify their entire contents. The claimed AMD gfx1201 result and physical device behavior were not independently verified.
To get this to a good state
Nothing is required.
ligmaSec
left a comment
There was a problem hiding this comment.
Float32Exp2Probe can set request.target.float32HostExp2 to true, but RequestSerializer has no field for it. A .req dumped from a device that selected the host lowering therefore replays with the range-reduced lowering by default. The --f32-host-exp2 override can recover the host path only when the person replaying the request already knows the startup probe result. This matters when comparing the emitted instructions or investigating a precision difference. Could the format save the flag with a versioned default for older requests, and test that a round trip preserves the host lowering?
I traced this on c74b1673fb. The branch currently conflicts with main in VulkanDevice.cpp, so this is a source review.
AI-assisted: yes.
What
GLSLstd450Exp2returns a result two ULP low forv_exp_f32 -1.0and-1.25on Apple M1. RDNA 2 and 3 specify one ULP accuracy for this instruction. For finite inputs with normal F32 results, the range-reduced form calculatesExp2on the fractional part and scales by a power of two. Special values and underflow or overflow inputs keep plainExp2. The SDWA test now checks positive and negative fractional values within one ULP.On RDNA4, plain
Exp2matches the native instruction bit for bit (review comment by Helldiverr), so the range-reduced form is now chosen per device. A startup probe,ProbeFloat32HostExp2, runs plainExp2for every integer n in [-126, 127]. If every result is exactly 2^n,SpirvTarget::float32HostExp2is set andv_exp_f32lowers to plainExp2as onmain. Otherwise it uses the range-reduced form. The flag is part of the shader cache key.APS5_NO_HOST_F32_EXP2skips the probe, andagc_shader_replay --f32-host-exp2selects the host form. In the range-reduced form,Exp2(x)is now emitted only in the else branch, so each path runs oneExp2.agc_driver_float16_nan_proberuns the probe with the range-reduced form on every device, before its f16 capability skip, and requires all 254 results to be exact. It then runs the probe with the host form and requiresfloat32HostExp2on the device target to match that result, unlessAPS5_NO_HOST_F32_EXP2is set.The branch overlap check could not merge #12324 automatically. Its changes in
SpirvAluEmitterMath.cppare in lane-analysis helpers around lines 311–691; this change is confined toEmitFPExp2around line 1496.Tested
Apple M1, macOS 26.5, x86_64 Release under Rosetta 2, MoltenVK from Vulkan SDK 1.4.363.0. Rebuilt
agc_driver_sdwa_exp_log_f32_testsandlibs. Onmainf7590cfb35plus macOS build helpers,agc_driver_sdwa_exp_log_f32and_wave64both failed; with this patch both passed. Both arms usedANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layerand verbose CTest. The layer loaded in every run; noVUID-errors appeared. Subsequent upstream commits before the branch baseda685dc528changed no AGC or shader recompiler file.Head
aee281b495(mergesmain, then adds the probe): Apple M1, macOS 26.5, same Vulkan SDK and environment variables, onmain6555c1425aplus #17425 and #11049 (needed to build on macOS) plus this branch. The mergedmaina05250bf50changes no AGC or shader recompiler file after6555c1425a, and the 15 changed files are byte-identical to the tested tree.agc_driver_sdwa_exp_log_f32and_wave64both fail on the base (v_exp_f32 -1.0gives0x3efffffe) and pass with this branch.agc_driver_float16_nan_probe_spirvpasses.agc_driver_float16_nan_proberuns the exp2 check, then skips its f16 part as before (M1 has no native f16). Every run logs[float-controls] f32 exp2: range-reduced (125 of 254 probe results not exact), so M1 keeps the range-reduced form. The layer was inserted in every run, with noVUID-errors. Negative control: with the test's probe switched to the host form,agc_driver_float16_nan_probefails withf32 exp2 probe: range-reduced path changed an integer result. Not tested here: an AMD or other device where the probe should select the host form. Helldiverr ran it on gfx1201 (comment 7110091901): the probe picks the host form andv_exp_f32matches the native instruction on 8191 of 8191 inputs, as onmain.Head
c74b1673fbadds the target check suggested in that review. On M1, all four tests pass with and withoutAPS5_NO_HOST_F32_EXP2=1, with the layer inserted and noVUID-errors. With the decision inVulkanDevice.cppinverted, the log showsf32 exp2: host (125 of 254 probe results not exact)andagc_driver_float16_nan_probefails withf32 exp2 probe: the device target does not follow the host probe.A separate Apple M1 Metal probe sampled 65,536 fractional inputs in
[0,1): 58,454 exact, 6,960 one ULP low, 122 one ULP high, none farther away.python3 tools/check_conventions.py --base origin/mainpassed.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)