Repository navigation
feat(shader): compute f64 add, mul and f32 conversions with integers on devices without Float64 - #13341
Conversation
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
The source diff has no confirmed correctness blocker in this review, but the PR body omits required rows from the repository's pull request template.
What I ran
Reviewed head efedda8947ac8328dab359895c627421ae847f66 against base ee9a9a66cffb77ba42781b66d764e96d22843554; the merge preview was clean (tree e58571f38d0471aea0f358b981ffb97cbea9d934). Environment: Debian 12 x86-64, Python 3.11.2, Git 2.39.5. I did not configure, build, compile, or run C++/GPU tests.
python3 tools/pr_precheck.py --repo boykopovar/AnyPS5 --pr 13341
git diff --check ee9a9a66cffb77ba42781b66d764e96d22843554...efedda8947ac8328dab359895c627421ae847f66
python3 tools/check_conventions.py --base ee9a9a66cffb77ba42781b66d764e96d22843554 --head efedda8947ac8328dab359895c627421ae847f66 --title 'feat(shader): compute f64 add, mul and f32 conversions with integers on devices without Float64' --body /tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13341-efedda8947ac/pr-body.md
git merge-tree --write-tree ee9a9a66cffb77ba42781b66d764e96d22843554 efedda8947ac8328dab359895c627421ae847f66I inspected the integer arithmetic emitter, capability selection, added execution test and CMake's glob-based execution-test registration. I also checked that the author's stated test base 42d009f5f3 is an ancestor of this PR base and that the intervening commits do not change the shader backend or AGC execution-test sources.
Results
| Check | Result |
|---|---|
| Diff whitespace and conventions/template check | Passed. |
| No-build precheck | It completed relevant checks but returned a tooling error for the workspace-local ABI/test-quality scripts missing from its isolated worktree; I inspected test registration manually. |
| Current-base merge preview | Clean. |
| Test registration | Confirmed: CMake discovers tests/execution/*.cpp with file(GLOB ... CONFIGURE_DEPENDS) and registers each execution test. |
| Author-reported GPU tests | The PR reports Mac M5 Max/MoltenVK and RTX 4090 runs, including the new integer-path test, matched existing tests on main, and a Vulkan validation-layer run. I did not independently run these. |
| Hosted CI | All jobs were pending at final refresh. |
| Local C++/GPU tests | Not run; the reviewer instructions prohibit builds during initial review. |
Unedited local check output
Precheck helper errors:
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13341-efedda8947ac/head-efedda8947ac-f181cee7/tools/pr_abi_audit.py': [Errno 2] No such file or directory
/usr/bin/python3: can't open file '/tmp/anyps5-pr-precheck/boykopovar-AnyPS5-pr-13341-efedda8947ac/head-efedda8947ac-f181cee7/tools/pr_test_quality.py': [Errno 2] No such file or directory
Convention and merge-preview output:
All conventions checks passed.
e58571f38d0471aea0f358b981ffb97cbea9d934
Findings
Blocking
The PR body omits the template's Unblocks, GPUs tested, and checked AI-assisted rows. This PR changes the shader recompiler and reports tests on two GPUs, so the required GPU field applies. Please preserve the template lines, fill Unblocks with none if applicable, list the tested GPU/driver/OS details, and mark the AI-assisted checkbox. This is the only reason for this request.
Non-blocking
None found in the inspected source. The PR reports broad exact-result coverage and device testing; I did not independently reproduce those runs.
Sources
- Required PR-template fields at the reviewed base.
- Integer f64 implementation and dispatch at the reviewed head and capability selection.
- Execution-test registration at the reviewed head.
Not verified
I did not independently compile the shader backend, run either GPU's tests, reproduce the validation-layer check, or verify console behavior. The PR's full GPU results are author-reported. The hosted checks had not completed.
To get this to a good state
Please restore the missing template rows and complete them. I will re-check the same head and test evidence after the PR body is updated.
|
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.
|
…on devices without Float64 A shader whose only f64 instructions are v_add_f64, v_mul_f64, v_cvt_f64_f32 and v_cvt_f32_f64 no longer needs shaderFloat64: the SPIR-V backend emits them as exact IEEE binary64 operations on 64-bit integers (round to nearest even, denormals kept), with the same NaN rules as the native path. Any other f64 instruction still needs the device's Float64 capability.
…sions Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
efedda8 to
30e8559
Compare
|
An AMD RDNA 4 run on Windows of Windows 11 Pro 10.0.22631, AMD Radeon RX 9070 XT (
AI-assisted: yes (Claude Code) |
|
Checked the integer add/mul/convert code (round to nearest even, denormals, overflow, exact cancellation, sticky bit, NaN routing through |
What
On a device without
shaderFloat64, every shader with a 64-bit float instruction fails to prepare with64-bit float instructions need the Float64 capability, which the device lacks. Apple GPUs through MoltenVK are such devices. This PR computes the four most common of these instructions with 64-bit integers instead:v_add_f64,v_mul_f64,v_cvt_f64_f32andv_cvt_f32_f64.Float64and a shader's only f64 opcodes areFPAdd64,FPMul64,ConvertF64F32andConvertF32F64,DefineModulesetsintegerFloat64and declaresInt64(part of the driver's required device baseline) instead ofFloat64. A device withFloat64keeps the native path, unchanged.f64_add_integer,f64_mul_integer,f64_from_f32_integer,f32_from_f64_integer), each emitted once per module when used. They are straight-line integer code: no branches or loops. Values areuint64;f32_from_f64_integerkeeps its exponent, shift and packing inuint32(see Tested for why). Results are exact IEEE binary64: round to nearest even, denormals kept, overflow to infinity. Add and subtract align with ten guard bits and a sticky bit; multiply builds the 106-bit product from 32-bit halves.NanResultBits, split out ofNanResult): a NaN input comes out quieted, the first input first, and an invalid result is0xfff8000000000000. The translation's existing denormal flushing around these instructions is untouched.Float64, with the same error as before (SpirvRequirements::float64NeedsDevice). In integer mode,TypeF64fails the emission if anything reaches it.Title: Gran Turismo 7 (PPSA01317) on an Apple M5 Max dispatches compute shader
0x8258dc9a00about two minutes after boot. Its f64 work is exactly these instructions: 6v_cvt_f64_f32, 6v_mul_f64, 2v_add_f64and 6v_cvt_f32_f64. Onmainthe title stops there every time (2 of 2 runs, 133 and 135 s). With this PR the shader prepares and runs. I checked the final code from an empty shader cache: the compute pipeline the title creates for this shader declaresInt64and noFloat64, and holds the four functions with 32 calls (eachv_mul_f64also gets the translation's two denormal-flush multiplies). The title keeps running to the end of the 300 s run with no further stop. Three other compute shaders of the title use more f64 instructions and still refuse at registration, as they do onmain; the title has not dispatched them in my runs.Tested
macOS 27.0.1 on an Apple M5 Max (40-core GPU), MoltenVK 1.4.2 from the LunarG SDK 1.4.363.0, x86-64 build under Rosetta 2, Apple clang 21.0.0, Release with
BUILD_TESTING=ON. The device has noshaderFloat64.maindoes not build on macOS by itself, so these runs usemain102b7a5 with the open macOS host PRs #7631, #7804, #10552, #11447 and #11554 merged, plus this change. The f64 code is the same as on this branch, which is rebased onto currentmain42d009f without conflicts. All runs below are from the final code.agc_driver_f64_add_mul_denormal_modesno longer skips on a device withoutFloat64. All 9 float modes × 16 pairs × 2 instructions pass, with 0 device-dependent results skipped.agc_driver_f32_convert_denormal_modesnow runs itsv_cvt_f64_f32pass on a device withoutFloat64. All 32 vectors pass in the flushed, input-flushed, kept and output-flushed modes, with IEEE on and off.agc_driver_f64_integer_arithmetic. It removesFloat64from the target's capability list, so it runs the integer path on any GPU. It checks the four instructions bit for bit against the host's IEEE results: all 1,296 pairs of 36 edge values (zeros, denormals, the normal boundary, ties, the largest finite values, infinities, quiet and signaling NaNs), then random pairs. The random pairs are biased towards denormals, overflow, the f32 range, cancellation (xand-x ± 2 ulp) and exponent gaps of up to 53. That is 65,536 results per run. A one-off run with 2,048 batches and another seed (2,097,152 results) gave 0 differences. The random test caught one bug during development: an exact cancellation of two normal numbers has to give +0.agc_driver_nan_quietingandrequest_serializerpass.agc_driver_f64_arithmeticandagc_driver_f64_conversionsstill skip, because they use fma, min/max and integer conversions.Windows 11 on an RTX 4090 (driver 616.92, Vulkan 1.4.341), winlibs GCC 15.2.0, Release with
BUILD_TESTING=ON, this branch. The device hasFloat64, so the existing tests keep the native path and only the new test runs the integer path.mainthat use an f64 instruction orFloat64, plusagc_driver_f64_integer_arithmetic, pass 3 times in a row. They pass once more underVK_LAYER_KHRONOS_validationwithANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1(ctest -V), with noVUID-lines; the loader log shows the layer inserted.main42d009f the same 25 tests pass the same way, also with noVUID-lines.mainplus only the new test fails with64-bit float instructions need the Float64 capability, which the device lacks.f32_from_f64_integerdid its exponent arithmetic inuint64, and the 4090 returned infinity for most finite inputs. I made the function return each intermediate value in turn: all of them matched the host except the upper word of the 64-bit packed result (((exponent - 1) << 23) + rounded), which came back as0xff800000instead of 0 in some lanes. Which lanes were hit depended on the other operand in the batch, which this function never reads. The exponent, shift and packing now useuint32, which is all an f32 result needs. Add, multiply andv_cvt_f64_f32were bit-exact on the 4090 from the start, so I left them inuint64.tools/check_conventions.py --base origin/mainandtools/check_test_registration.pypass.tools/pr_overlap.py --branch feat/f64-integer-emulationfound no conflicting pull requests after I movedIsIntegerFloat64Opcodeto the end ofSpirvAnalysis.cpp, where it no longer meets #11510. It could not compare 19 open pull requests that conflict withmainthemselves; they share onlySpirvEmitterState.hpp,SpirvEmitterHelpers.hpp,SpirvModuleEmitter.cpporSpirvModuleSetup.cppwith this branch, where it adds a few lines next to existing members and calls.Overlap
DenormPreservedeclaration inSpirvModuleSetup.cpp. The integer path does not declareFloat64modes, so the two do not interact.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)0x8258dc9a00on Apple GPUs