fix(agc): refuse 64-bit buffer atomics on devices without shaderBufferInt64Atomics #1213

Merged
kr4y4 merged 1 commit from upstream-pr/1213 into main 2026-10-08 08:56:36 +00:00
kr4y4 commented 2026-10-07 17:52:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-07T17:52:44Z.


What

When a program uses a 64-bit buffer or global atomic, the recompiler emits Int64 and Int64Atomics with 64-bit OpAtomic* on storage buffers and physical storage buffer pointers (SpirvModuleSetup.cpp). Nothing checks that the device supports them. VulkanDevice enables shaderBufferInt64Atomics when it is present, but never adds Int64Atomics to the target's capabilities. On a device without the feature the module is invalid (VUID-VkShaderModuleCreateInfo-pCode-08740), so what the driver does with it is undefined. The 64-bit image atomics path a few lines below already fails emission in the same situation.

The device now adds Int64Atomics to the target capabilities when it enables shaderBufferInt64Atomics. Emission fails with 64-bit buffer atomics need shaderBufferInt64Atomics when a program needs them on a device without it. The execution tests that use 64-bit buffer, global or image atomics skip on such devices, as ImageSampleLodClamp does for shaderResourceMinLod.

Intel Raptor Lake-S Mobile Graphics (driver 32.0.101.6790) reports shaderBufferInt64Atomics, shaderSharedInt64Atomics and shaderImageInt64Atomics all 0. On it the dispatch writes nothing, including its 32-bit stores:

Test main this change
agc_driver_buffer_atomics lane 0 buffer_atomic_inc is 0xdeadbeef, expected 0x00000000 skipped
agc_driver_buffer_atomics_float lane 0 fcmpswap_ret0 is 0xdeadbeef, expected 0x00000000 skipped
agc_driver_buffer_atomics_inc_dec64 lane 0 inc_x2_ret0 is 0xdeadbeef, expected 0x00000000 skipped
agc_driver_buffer_atomics_or_swap64 lane 0 buffer_atomic_or_x2 returned lo is 0xdeadbeef, expected 0x6a6ae768 skipped
agc_driver_look_back_scan look-back from block 0: the counter is 0 (buffer_atomic_swap_x2 publish) skipped
agc_driver_global_atomics64, agc_driver_global_atomics_float, agc_driver_global_atomics_lanes pass, from modules that declare Int64Atomics without the feature skipped
agc_driver_image_atomics64 64-bit image atomics need VK_EXT_shader_image_atomic_int64 skipped

Before the skips were added, global_atomics_float, global_atomics_lanes and look_back_scan failed with SPIR-V module emission failed: 64-bit buffer atomics need shaderBufferInt64Atomics.

A plain Vulkan compute shader (GLSL, no AnyPS5 code) on the same device shows the same result:

  • A dispatch with one atomicAdd on a uint64_t SSBO member lands none of its 32 plain stores.
  • The store-only control lands 32/32.
  • The same atomic in a branch that's never taken lands 32/32.
  • Running the variants in one process, the next vkQueueSubmit returns VK_ERROR_DEVICE_LOST.

Tested

Windows 11 (26200), WinLibs GCC 15.2.0 r7, CI configure flags, main at cea1ef13, ctest --output-on-failure --timeout 120 --repeat until-fail:3:

  • NVIDIA RTX 4070 Laptop GPU (driver 32.0.15.9597, has the feature): 395/395 passed, none skipped.
  • Intel Raptor Lake-S, ANYPS5_GPU=Intel: the nine tests above skip. The 24 remaining failures also fail on main and have other causes on this device:
    • no shaderFloat64;
    • the compute subgroup width, see #1185;
    • f16 denormals flushed in compares;
    • V_FRACT_F32 rounding;
    • a driver error in OpSMulExtended by some constants.

Notes:

  • supportedCapabilities is part of the shader cache key, so cached shaders on devices with the feature are recompiled once.
  • buffer_atomics also covers 32-bit inc/dec. On devices without the feature those cases are skipped together with the 64-bit ones.
  • #1074 makes graphics validation accept Int64Atomics when the device enables it. This change makes emission refuse it when the device does not. The two are independent, and the branches merge without conflicts (git merge-tree, checked against the 22 open PRs that touch these files).

Checklist

  • Based on current main; no other open PR implements the same thing
  • One topic per PR
  • No comments in code except technical debt
  • Unimplemented paths throw; no silent stubs added
  • No notes, investigation files or images added to the repository
  • No new third-party code
  • Generic, not specific to one title
  • Depends on: none
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4776407662 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1213). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-07T17:52:44Z. --- ### What When a program uses a 64-bit buffer or global atomic, the recompiler emits `Int64` and `Int64Atomics` with 64-bit `OpAtomic*` on storage buffers and physical storage buffer pointers (`SpirvModuleSetup.cpp`). Nothing checks that the device supports them. `VulkanDevice` enables `shaderBufferInt64Atomics` when it is present, but never adds `Int64Atomics` to the target's capabilities. On a device without the feature the module is invalid (VUID-VkShaderModuleCreateInfo-pCode-08740), so what the driver does with it is undefined. The 64-bit image atomics path a few lines below already fails emission in the same situation. The device now adds `Int64Atomics` to the target capabilities when it enables `shaderBufferInt64Atomics`. Emission fails with `64-bit buffer atomics need shaderBufferInt64Atomics` when a program needs them on a device without it. The execution tests that use 64-bit buffer, global or image atomics skip on such devices, as `ImageSampleLodClamp` does for `shaderResourceMinLod`. Intel Raptor Lake-S Mobile Graphics (driver 32.0.101.6790) reports `shaderBufferInt64Atomics`, `shaderSharedInt64Atomics` and `shaderImageInt64Atomics` all 0. On it the dispatch writes nothing, including its 32-bit stores: | Test | main | this change | |---|---|---| | `agc_driver_buffer_atomics` | `lane 0 buffer_atomic_inc is 0xdeadbeef, expected 0x00000000` | skipped | | `agc_driver_buffer_atomics_float` | `lane 0 fcmpswap_ret0 is 0xdeadbeef, expected 0x00000000` | skipped | | `agc_driver_buffer_atomics_inc_dec64` | `lane 0 inc_x2_ret0 is 0xdeadbeef, expected 0x00000000` | skipped | | `agc_driver_buffer_atomics_or_swap64` | `lane 0 buffer_atomic_or_x2 returned lo is 0xdeadbeef, expected 0x6a6ae768` | skipped | | `agc_driver_look_back_scan` | `look-back from block 0: the counter is 0` (`buffer_atomic_swap_x2` publish) | skipped | | `agc_driver_global_atomics64`, `agc_driver_global_atomics_float`, `agc_driver_global_atomics_lanes` | pass, from modules that declare `Int64Atomics` without the feature | skipped | | `agc_driver_image_atomics64` | `64-bit image atomics need VK_EXT_shader_image_atomic_int64` | skipped | Before the skips were added, `global_atomics_float`, `global_atomics_lanes` and `look_back_scan` failed with `SPIR-V module emission failed: 64-bit buffer atomics need shaderBufferInt64Atomics`. A plain Vulkan compute shader (GLSL, no AnyPS5 code) on the same device shows the same result: - A dispatch with one `atomicAdd` on a `uint64_t` SSBO member lands none of its 32 plain stores. - The store-only control lands 32/32. - The same atomic in a branch that's never taken lands 32/32. - Running the variants in one process, the next `vkQueueSubmit` returns `VK_ERROR_DEVICE_LOST`. ### Tested Windows 11 (26200), WinLibs GCC 15.2.0 r7, CI configure flags, main at cea1ef13, `ctest --output-on-failure --timeout 120 --repeat until-fail:3`: - NVIDIA RTX 4070 Laptop GPU (driver 32.0.15.9597, has the feature): 395/395 passed, none skipped. - Intel Raptor Lake-S, `ANYPS5_GPU=Intel`: the nine tests above skip. The 24 remaining failures also fail on main and have other causes on this device: - no `shaderFloat64`; - the compute subgroup width, see #1185; - f16 denormals flushed in compares; - `V_FRACT_F32` rounding; - a driver error in `OpSMulExtended` by some constants. Notes: - `supportedCapabilities` is part of the shader cache key, so cached shaders on devices with the feature are recompiled once. - `buffer_atomics` also covers 32-bit inc/dec. On devices without the feature those cases are skipped together with the 64-bit ones. - #1074 makes graphics validation accept `Int64Atomics` when the device enables it. This change makes emission refuse it when the device does not. The two are independent, and the branches merge without conflicts (`git merge-tree`, checked against the 22 open PRs that touch these files). ### Checklist - [x] Based on current `main`; no other open PR implements the same thing - [x] One topic per PR - [x] No comments in code except technical debt - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation files or images added to the repository - [x] No new third-party code - [x] Generic, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
adriadam10 commented 2026-10-08 08:56:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-08T08:56:32Z.


Checked on the PR merged onto current main: build + ctest 428/428 green, and the nine tests pass on a device that has the feature. With the Int64Atomics push in VulkanDevice.cpp removed, the buffer/global/look-back tests report Skipped, so the skip path works. Linux, Windows and conventions CI are green; merging.

Nothing blocking, for a later PR: nothing pins the new FailEmit in SpirvModuleSetup.cpp (the image-atomics one next to it has no test either), and the 12/5016 capability constants are repeated in each test.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6056368565 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1213#issuecomment-6056368565). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-08T08:56:32Z. --- Checked on the PR merged onto current main: build + ctest 428/428 green, and the nine tests pass on a device that has the feature. With the `Int64Atomics` push in `VulkanDevice.cpp` removed, the buffer/global/look-back tests report Skipped, so the skip path works. Linux, Windows and conventions CI are green; merging. Nothing blocking, for a later PR: nothing pins the new `FailEmit` in `SpirvModuleSetup.cpp` (the image-atomics one next to it has no test either), and the `12`/`5016` capability constants are repeated in each test.
kr4y4 commented 2026-10-08 12:43:55 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-08T12:43:55Z.


Both follow-ups from your review are up: #1563 pins the 64-bit buffer and image atomics FailEmit messages, and #1558 replaces the repeated capability constants with spv::Capability names through a shared helper.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6060133734 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/1213#issuecomment-6060133734). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-08T12:43:55Z. --- Both follow-ups from your review are up: #1563 pins the 64-bit buffer and image atomics `FailEmit` messages, and #1558 replaces the repeated capability constants with `spv::Capability` names through a shared helper.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!1213
No description provided.