feat(shader): implement global_atomic_csub #670

Merged
NahuelGenchi merged 1 commit from upstream-pr/670 into main 2026-10-05 18:54:05 +00:00
NahuelGenchi commented 2026-10-05 13:34:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by NahuelGenchi on 2026-10-05T13:34:13Z.


What

global_atomic_csub (GLOBAL opcode 0x34) threw FLAT opcode is not supported. It subtracts the data register from a global dword, clamps the result to zero and returns the previous value, so it's the same as buffer_atomic_csub from #594 but on a global address. It goes through flatAtomic with a new AddressAtomicUSubSat32, which the SPIR-V backend runs as a compare and swap loop like the other address atomics that have no native SPIR-V op.

RDNA 2 only has this opcode in the global segment, so the decoder throws for the flat segment (scratch atomics already throw). Without glc it throws in the translation, the same way buffer_atomic_csub does.

The clamped subtract that #594 wrote inline for the buffer form is now AtomicUSubSat, next to AtomicIncrement and AtomicDecrement, and both opcodes use it.

tools/progress.py: GLOBAL 57/57, shaders 1119/1166.

Tested

Ubuntu 26.04, GCC 15.2, AMD R9 380 with RADV and with lavapipe.

New agc_driver_global_atomic_csub, wave32 and wave64 with 64 threads. Each thread runs csub on its own dword with the same edge rows as the buffer test, then all threads hit two shared dwords, one that never reaches zero and one that runs out and clamps. The values returned from the shared dwords are checked as one ordered chain, and the whole guest block is compared byte by byte afterwards. The test also checks that the form without glc and the flat segment form are refused. With the clamp taken out of AtomicUSubSat, both this test and agc_driver_buffer_atomic_csub fail.

Full ctest on lavapipe with ANYPS5_REQUIRE_VULKAN=1: 287/287. On RADV the only failures are agc_driver_pixel_helper_lanes, agc_driver_pixel_lds and agc_driver_pixel_lds_lane_slots, and they fail the same way on main (wave64 pixel shaders on this GPU, see #487).

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
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4745717890 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/670). Originally posted by [NahuelGenchi](https://github.com/NahuelGenchi) on 2026-10-05T13:34:13Z. --- ### What `global_atomic_csub` (GLOBAL opcode 0x34) threw `FLAT opcode is not supported`. It subtracts the data register from a global dword, clamps the result to zero and returns the previous value, so it's the same as `buffer_atomic_csub` from #594 but on a global address. It goes through `flatAtomic` with a new `AddressAtomicUSubSat32`, which the SPIR-V backend runs as a compare and swap loop like the other address atomics that have no native SPIR-V op. RDNA 2 only has this opcode in the global segment, so the decoder throws for the flat segment (scratch atomics already throw). Without glc it throws in the translation, the same way `buffer_atomic_csub` does. The clamped subtract that #594 wrote inline for the buffer form is now `AtomicUSubSat`, next to `AtomicIncrement` and `AtomicDecrement`, and both opcodes use it. `tools/progress.py`: GLOBAL 57/57, shaders 1119/1166. ### Tested Ubuntu 26.04, GCC 15.2, AMD R9 380 with RADV and with lavapipe. New `agc_driver_global_atomic_csub`, wave32 and wave64 with 64 threads. Each thread runs csub on its own dword with the same edge rows as the buffer test, then all threads hit two shared dwords, one that never reaches zero and one that runs out and clamps. The values returned from the shared dwords are checked as one ordered chain, and the whole guest block is compared byte by byte afterwards. The test also checks that the form without glc and the flat segment form are refused. With the clamp taken out of `AtomicUSubSat`, both this test and `agc_driver_buffer_atomic_csub` fail. Full ctest on lavapipe with `ANYPS5_REQUIRE_VULKAN=1`: 287/287. On RADV the only failures are `agc_driver_pixel_helper_lanes`, `agc_driver_pixel_lds` and `agc_driver_pixel_lds_lane_slots`, and they fail the same way on main (wave64 pixel shaders on this GPU, see #487). ### 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
github-actions[bot] commented 2026-10-05 13:34:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T13:34:41Z.


Progress report (af92452 → a93faff)

📈 GPU shader instructions: 96.14% (+0.09%, +1 implemented instructions)

✅ 1 implemented
Encoding Name
GLOBAL GLOBAL_ATOMIC_CSUB
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:5995551798 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/670#issuecomment-5995551798). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-05T13:34:41Z. --- <!-- progress-report --> ### Progress report (af92452 → a93faff) 📈 **GPU shader instructions**: 96.14% (+0.09%, +1 implemented instructions) <details> <summary>✅ 1 implemented</summary> | Encoding | Name | | - | - | | GLOBAL | `GLOBAL_ATOMIC_CSUB` | </details>
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!670
No description provided.