feat(recompiler): implement 64-bit image atomics #896

Merged
alfalfa-star merged 2 commits from upstream-pr/896 into main 2026-10-07 08:54:10 +00:00
alfalfa-star commented 2026-10-06 14:02:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-06T14:02:37Z.


What

Implement 64-bit integer image atomics. image_atomic_* with a two-dword data mask (0x3, or 0xf for cmpswap) is the 64-bit form of an integer image atomic, and the decoder rejected it with invalid MIMG data mask.

PPSA14632 (LEGO Horizon Adventures, Unreal Engine) updates a 32_32 surface with six 64-bit image_atomic_umax in a compute shader during its first frames, and stops there on main.

  • Decoder: swap, add, sub, smin, umin, smax, umax, and, or, xor and cmpswap with the 64-bit data mask decode with dataBits = 64.
  • IR: new ImageAtomic*64 opcodes take and return U64, read from and written to register pairs as the 64-bit buffer atomics are.
  • Resources and bindings: an image updated by them is marked atomic64 and gets its own descriptor binding range (five bindings after the 32-bit atomic ones), declared as an R64ui image of 64-bit integers. The descriptor must be 32_32 UINT, SINT or FLOAT. The flag reaches the driver as DescriptorBinding::imageAtomic64 and is stored in the shader disk cache.
  • SPIR-V: OpImageTexelPointer to a 64-bit texel and the 64-bit atomic opcodes, with Int64, Int64Atomics, Int64ImageEXT and SPV_EXT_shader_image_int64. When the target does not list Int64ImageEXT, recompiling throws 64-bit image atomics need VK_EXT_shader_image_atomic_int64.
  • Driver: VulkanDevice enables shaderImageInt64Atomics when the device offers it and advertises Int64ImageEXT. StorageTexture::Atomic64View binds an R64_UINT view of the surface; storage images are already created with MUTABLE_FORMAT and EXTENDED_USAGE, and R64_UINT is in the 64-bit compatibility class of R32G32_*.

Not covered, and listed in TechnicalDebt: 64-bit image_atomic_inc/dec and the float atomics still throw, as does any other access in the same shader to an image it updates with 64-bit atomics.

Tested

  • Arch Linux, GCC 16.2, Release, RX 9070 XT (RADV GFX1201, shaderImageInt64Atomics = true).
  • New agc_driver_image_atomics64: each of the 11 operations on 32_32 UINT, SINT and FLOAT surfaces, checking the returned and stored values for every thread against edge cases across the dword boundary (carry, borrow, sign bit, high word deciding min/max). Turning 64-bit umax into umin in the emitter makes it fail. Full ctest: 360/360.
  • PPSA14632: the shader recompiles to 36653 words with six OpAtomicUMax %ulong on an R64ui image, spirv-val accepts it, and the title runs on to an unrelated sceAgcCbBranch: null or misaligned address 0x0.
  • Windows not built or tested.

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 in TechnicalDebt
  • 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
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4759848897 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/896). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-06T14:02:37Z. --- ### What Implement 64-bit integer image atomics. `image_atomic_*` with a two-dword data mask (`0x3`, or `0xf` for cmpswap) is the 64-bit form of an integer image atomic, and the decoder rejected it with `invalid MIMG data mask`. PPSA14632 (LEGO Horizon Adventures, Unreal Engine) updates a 32_32 surface with six 64-bit `image_atomic_umax` in a compute shader during its first frames, and stops there on `main`. - **Decoder**: swap, add, sub, smin, umin, smax, umax, and, or, xor and cmpswap with the 64-bit data mask decode with `dataBits = 64`. - **IR**: new `ImageAtomic*64` opcodes take and return `U64`, read from and written to register pairs as the 64-bit buffer atomics are. - **Resources and bindings**: an image updated by them is marked `atomic64` and gets its own descriptor binding range (five bindings after the 32-bit atomic ones), declared as an `R64ui` image of 64-bit integers. The descriptor must be 32_32 UINT, SINT or FLOAT. The flag reaches the driver as `DescriptorBinding::imageAtomic64` and is stored in the shader disk cache. - **SPIR-V**: `OpImageTexelPointer` to a 64-bit texel and the 64-bit atomic opcodes, with `Int64`, `Int64Atomics`, `Int64ImageEXT` and `SPV_EXT_shader_image_int64`. When the target does not list `Int64ImageEXT`, recompiling throws `64-bit image atomics need VK_EXT_shader_image_atomic_int64`. - **Driver**: `VulkanDevice` enables `shaderImageInt64Atomics` when the device offers it and advertises `Int64ImageEXT`. `StorageTexture::Atomic64View` binds an `R64_UINT` view of the surface; storage images are already created with `MUTABLE_FORMAT` and `EXTENDED_USAGE`, and `R64_UINT` is in the 64-bit compatibility class of `R32G32_*`. Not covered, and listed in TechnicalDebt: 64-bit `image_atomic_inc`/`dec` and the float atomics still throw, as does any other access in the same shader to an image it updates with 64-bit atomics. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. --> - Arch Linux, GCC 16.2, Release, RX 9070 XT (RADV GFX1201, `shaderImageInt64Atomics = true`). - New `agc_driver_image_atomics64`: each of the 11 operations on 32_32 UINT, SINT and FLOAT surfaces, checking the returned and stored values for every thread against edge cases across the dword boundary (carry, borrow, sign bit, high word deciding min/max). Turning 64-bit umax into umin in the emitter makes it fail. Full ctest: 360/360. - PPSA14632: the shader recompiles to 36653 words with six `OpAtomicUMax %ulong` on an `R64ui` image, `spirv-val` accepts it, and the title runs on to an unrelated `sceAgcCbBranch: null or misaligned address 0x0`. - Windows not built or tested. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
alfalfa-star commented 2026-10-06 14:25:43 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-06T14:25:43Z.


A note on overlaps with open pull requests, for whichever lands second:

  • #757 turns the "atomic image descriptor uses an unsupported format" throw in decodeImageDescriptor into rejectImage(PoisonReason::InvalidFormat, ...). This PR adds the 64-bit counterpart right before it ("64-bit atomic image descriptor uses an unsupported format"), which should then go through rejectImage the same way. #757 also pushes imageAtomic(false) for table images; ShaderResources here bounds-checks imageAtomic64, so a table image without an entry is treated as not 64-bit.
  • #799, #815 and #822 add per-binding vectors to DescriptorBinding as well, so static_assert(sizeof(DescriptorBinding) == ...) in ShaderDiskCache.cpp needs the combined size after both land (this PR adds one std::vector<bool>, 40 bytes).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6018411771 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/896#issuecomment-6018411771). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-06T14:25:43Z. --- A note on overlaps with open pull requests, for whichever lands second: - #757 turns the "atomic image descriptor uses an unsupported format" throw in `decodeImageDescriptor` into `rejectImage(PoisonReason::InvalidFormat, ...)`. This PR adds the 64-bit counterpart right before it ("64-bit atomic image descriptor uses an unsupported format"), which should then go through `rejectImage` the same way. #757 also pushes `imageAtomic(false)` for table images; `ShaderResources` here bounds-checks `imageAtomic64`, so a table image without an entry is treated as not 64-bit. - #799, #815 and #822 add per-binding vectors to `DescriptorBinding` as well, so `static_assert(sizeof(DescriptorBinding) == ...)` in `ShaderDiskCache.cpp` needs the combined size after both land (this PR adds one `std::vector<bool>`, 40 bytes).
adriadam10 commented 2026-10-07 08:25:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T08:25:34Z.


Measured all 11 operations (cmpswap with equal and different comparator) on 32_32 UINT/SINT/FLOAT surfaces on RDNA2 hardware (gfx1035) with carry/sign edge rows plus random rows: returned and stored values match this PR's model bit for bit (5760 cells, 0 mismatches). The test passes on RADV and on CI's lavapipe, and fails without the change. Rebased on main (only conflict: the DescriptorBinding size assert, now 448, and the new imageUnnormalized/imageSamplers lines next to imageAtomic64); full ctest green after the rebase. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6034022613 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/896#issuecomment-6034022613). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T08:25:34Z. --- Measured all 11 operations (cmpswap with equal and different comparator) on 32_32 UINT/SINT/FLOAT surfaces on RDNA2 hardware (gfx1035) with carry/sign edge rows plus random rows: returned and stored values match this PR's model bit for bit (5760 cells, 0 mismatches). The test passes on RADV and on CI's lavapipe, and fails without the change. Rebased on main (only conflict: the `DescriptorBinding` size assert, now 448, and the new `imageUnnormalized`/`imageSamplers` lines next to `imageAtomic64`); full ctest green after the rebase. Merging once CI is green.
github-actions[bot] commented 2026-10-07 08:38:39 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-07T08:38:39Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#944 core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp L1071
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6034229976 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/896#issuecomment-6034229976). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-07T08:38:39Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #944 | `core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp` [L1071](https://github.com/boykopovar/AnyPS5/blob/219a1cf8d246f491dd93e81307496173e568f412/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L1071) | | |
alfalfa-star commented 2026-10-07 08:38:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by alfalfa-star on 2026-10-07T08:38:48Z.


A second commit makes draws work too. In PPSA14632, a pixel shader with a 64-bit image atomic was rejected by graphics shader validation (SPIR-V requires unsupported device capability 5016); compute dispatches are not validated this way. The device now records imageInt64Atomics, and ValidateShaders accepts Int64Atomics, Int64ImageEXT and SPV_EXT_shader_image_int64 when it is set. A test in agc_driver_graphics covers both capabilities. ctest: 387 of 387 pass.

#1074 does the same for 64-bit buffer atomics (bufferInt64Atomics) and touches the same ValidateShaders signature; whichever lands second needs a small rebase.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6034232215 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/896#issuecomment-6034232215). Originally posted by [alfalfa-star](https://github.com/alfalfa-star) on 2026-10-07T08:38:48Z. --- A second commit makes draws work too. In PPSA14632, a pixel shader with a 64-bit image atomic was rejected by graphics shader validation (`SPIR-V requires unsupported device capability 5016`); compute dispatches are not validated this way. The device now records `imageInt64Atomics`, and `ValidateShaders` accepts `Int64Atomics`, `Int64ImageEXT` and `SPV_EXT_shader_image_int64` when it is set. A test in `agc_driver_graphics` covers both capabilities. `ctest`: 387 of 387 pass. #1074 does the same for 64-bit buffer atomics (`bufferInt64Atomics`) and touches the same `ValidateShaders` signature; whichever lands second needs a small rebase.
adriadam10 commented 2026-10-07 08:54:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-07T08:54:06Z.


Re-checked the second commit: graphics validation now accepts Int64Atomics, Int64ImageEXT and SPV_EXT_shader_image_int64 only when the device enabled shaderImageInt64Atomics, and the new agc_driver_graphics case fails if that acceptance is removed. Full ctest green (387/387) merged onto main. #1074 changes the same ValidateShaders signature, so whichever lands second needs a small rebase. Merging once CI is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6034472843 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/896#issuecomment-6034472843). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-07T08:54:06Z. --- Re-checked the second commit: graphics validation now accepts `Int64Atomics`, `Int64ImageEXT` and `SPV_EXT_shader_image_int64` only when the device enabled `shaderImageInt64Atomics`, and the new `agc_driver_graphics` case fails if that acceptance is removed. Full ctest green (387/387) merged onto main. #1074 changes the same `ValidateShaders` signature, so whichever lands second needs a small rebase. Merging once CI is green.
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!896
No description provided.