Skip to content

feat(shader): compute f64 add, mul and f32 conversions with integers on devices without Float64 - #13341

Merged
adriadam10 merged 2 commits into
boykopovar:mainfrom
frankea:feat/f64-integer-emulation
Oct 31, 2026
Merged

adriadam10 merged 2 commits into
boykopovar:mainfrom
frankea:feat/f64-integer-emulation

Conversation

@frankea

@frankea frankea commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

What

On a device without shaderFloat64, every shader with a 64-bit float instruction fails to prepare with 64-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_f32 and v_cvt_f32_f64.

  • When. The IR already carries f64 values as 64-bit bit patterns, and only the SPIR-V emitter turns them into doubles. When the device lacks Float64 and a shader's only f64 opcodes are FPAdd64, FPMul64, ConvertF64F32 and ConvertF32F64, DefineModule sets integerFloat64 and declares Int64 (part of the driver's required device baseline) instead of Float64. A device with Float64 keeps the native path, unchanged.
  • How. Four SPIR-V functions (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 are uint64; f32_from_f64_integer keeps its exponent, shift and packing in uint32 (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.
  • What stays the same. NaN results go through the same rules as the native path (NanResultBits, split out of NanResult): a NaN input comes out quieted, the first input first, and an invalid result is 0xfff8000000000000. The translation's existing denormal flushing around these instructions is untouched.
  • What still throws. Any other f64 instruction (fma, min/max, rounding, rcp/rsq/sqrt, integer conversions and so on) still needs the device's Float64, with the same error as before (SpirvRequirements::float64NeedsDevice). In integer mode, TypeF64 fails the emission if anything reaches it.

Title: Gran Turismo 7 (PPSA01317) on an Apple M5 Max dispatches compute shader 0x8258dc9a00 about two minutes after boot. Its f64 work is exactly these instructions: 6 v_cvt_f64_f32, 6 v_mul_f64, 2 v_add_f64 and 6 v_cvt_f32_f64. On main the 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 declares Int64 and no Float64, and holds the four functions with 32 calls (each v_mul_f64 also 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 on main; 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 no shaderFloat64. main does not build on macOS by itself, so these runs use main 102b7a5 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 current main 42d009f without conflicts. All runs below are from the final code.

  • agc_driver_f64_add_mul_denormal_modes no longer skips on a device without Float64. All 9 float modes × 16 pairs × 2 instructions pass, with 0 device-dependent results skipped.
  • agc_driver_f32_convert_denormal_modes now runs its v_cvt_f64_f32 pass on a device without Float64. All 32 vectors pass in the flushed, input-flushed, kept and output-flushed modes, with IEEE on and off.
  • New agc_driver_f64_integer_arithmetic. It removes Float64 from 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 (x and -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_quieting and request_serializer pass. agc_driver_f64_arithmetic and agc_driver_f64_conversions still 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 has Float64, so the existing tests keep the native path and only the new test runs the integer path.

  • The 25 execution tests on main that use an f64 instruction or Float64, plus agc_driver_f64_integer_arithmetic, pass 3 times in a row. They pass once more under VK_LAYER_KHRONOS_validation with ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1 (ctest -V), with no VUID- lines; the loader log shows the layer inserted.
  • On main 42d009f the same 25 tests pass the same way, also with no VUID- lines. main plus only the new test fails with 64-bit float instructions need the Float64 capability, which the device lacks.
  • The 2,097,152-result run with another seed gives 0 differences on the 4090 too.
  • The 4090 caught a problem the Mac did not. In my first version, f32_from_f64_integer did its exponent arithmetic in uint64, 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 as 0xff800000 instead 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 use uint32, which is all an f32 result needs. Add, multiply and v_cvt_f64_f32 were bit-exact on the 4090 from the start, so I left them in uint64.

tools/check_conventions.py --base origin/main and tools/check_test_registration.py pass. tools/pr_overlap.py --branch feat/f64-integer-emulation found no conflicting pull requests after I moved IsIntegerFloat64Opcode to the end of SpirvAnalysis.cpp, where it no longer meets #11510. It could not compare 19 open pull requests that conflict with main themselves; they share only SpirvEmitterState.hpp, SpirvEmitterHelpers.hpp, SpirvModuleEmitter.cpp or SpirvModuleSetup.cpp with this branch, where it adds a few lines next to existing members and calls.

Overlap

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: PPSA01317 Gran Turismo 7 (PPSA01317) #4697 (Gran Turismo 7), compute shader 0x8258dc9a00 on Apple GPUs
  • GPUs tested: Apple M5 Max (macOS 27.0.1, MoltenVK 1.4.2); NVIDIA RTX 4090 (Windows 11, driver 616.92, Vulkan 1.4.341)
  • AI-assisted: yes (Claude Code)

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 efedda8947ac8328dab359895c627421ae847f66

I 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

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.

@github-actions

github-actions Bot commented Oct 30, 2026 •

Copy link
Copy Markdown

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.

Pull request Shared files not compared
PR 5021 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
docs/dev/debt/shader.md
PR 5371 docs/dev/debt/shader.md
PR 6235 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
docs/dev/debt/shader.md
PR 6280 docs/dev/debt/shader.md
PR 6412 docs/dev/debt/shader.md
PR 6416 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
PR 6488 docs/dev/debt/shader.md
PR 6751 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
PR 6924 docs/dev/debt/shader.md
PR 7392 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
docs/dev/debt/shader.md
PR 7684 docs/dev/debt/shader.md
PR 7922 docs/dev/debt/shader.md
PR 8004 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
docs/dev/debt/shader.md
PR 9183 docs/dev/debt/shader.md
PR 9356 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 9387 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvMemory/SpirvModuleSetup.cpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
docs/dev/debt/shader.md
PR 9748 core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
docs/dev/debt/shader.md
PR 10193 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterHelpers.hpp
core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
core/shader/recompiler/SpirvBackend/src/SpirvModuleEmitter.cpp
PR 10233 docs/dev/debt/shader.md
PR 10652 core/shader/recompiler/SpirvBackend/include/SpirvBackend/SpirvEmitterState.hpp
docs/dev/debt/shader.md
PR 10941 docs/dev/debt/shader.md
PR 12548 docs/dev/debt/shader.md

@adriadam10 adriadam10 self-assigned this Oct 30, 2026
@github-actions github-actions Bot added the unblocks title Names a title ID on the Unblocks line label Oct 30, 2026
@frankea

frankea commented Oct 30, 2026

Copy link
Copy Markdown
Contributor Author

@MarcZX10 The three template rows are in the description now: adriadam10 added Unblocks and GPUs tested, and I moved AI-assisted into the checklist and named GT7's bring-up discussion (#4697) in Unblocks. The head is unchanged (efedda8947).

frankea and others added 2 commits October 30, 2026 19:15
…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>
@adriadam10
adriadam10 force-pushed the feat/f64-integer-emulation branch from efedda8 to 30e8559 Compare October 30, 2026 18:25
@bunbeans2-arch

Copy link
Copy Markdown
Contributor

An AMD RDNA 4 run on Windows of 30e8559f63, since the GPUs tested are Apple (MoltenVK) and NVIDIA.

Windows 11 Pro 10.0.22631, AMD Radeon RX 9070 XT (1002:7550, driver 32.0.32015.7029, amdvlk64), MSYS2 UCRT64 g++ 16.1.0, Release. ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation; with VK_LOADER_DEBUG=layer the loader logs Insert instance layer "VK_LAYER_KHRONOS_validation" in every run of every test below that creates a Vulkan instance. This head merged onto main f7f03daf52, 3 runs per side:

  • This head: agc_driver_f64_integer_arithmetic, which this PR adds, passes 3 of 3 with f64 integer arithmetic tests passed, 65536 results checked. The test removes Float64 from the target's capabilities, so the integer path is what ran here.
  • This head: agc_driver_f32_convert_denormal_modes and agc_driver_f64_add_mul_denormal_modes pass 3 of 3.
  • main f7f03daf52: those two pass 3 of 3.
  • No VUID- line on either side.

AI-assisted: yes (Claude Code)

@adriadam10
adriadam10 merged commit ab1c3b8 into boykopovar:main Oct 31, 2026
14 checks passed
@adriadam10

Copy link
Copy Markdown
Collaborator

Checked the integer add/mul/convert code (round to nearest even, denormals, overflow, exact cancellation, sticky bit, NaN routing through NanResultBits), and that agc_driver_f64_integer_arithmetic strips Float64 from the target and compares bit for bit with the host. Everything else in f64 still throws as before. Our docs/dev/debt/shader.md line for the integer path is on the branch (not measured on the PS5's gfx1013). The AMD RDNA 4 run by @bunbeans2-arch also passes with no VUID- lines; merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants