feat(shader): implement 64-bit image_atomic_inc and image_atomic_dec #16952

Merged
r614 merged 3 commits from upstream-pr/16952 into main 2026-11-21 10:59:32 +00:00
r614 commented 2026-11-08 01:07:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by r614 on 2026-11-08T01:07:17Z.


What

64-bit image_atomic_inc and image_atomic_dec (MIMG opcodes 0x1b and 0x1c with a two-dword data mask) threw 64-bit ImageAtomicInc32 is not implemented. They now translate to new ImageAtomicInc64 / ImageAtomicDec64 IR opcodes. Those run as a 64-bit compare-and-swap loop through the existing AtomicUpdateTyped on the R64_UINT texel pointer that the other 64-bit image atomics use.

Semantics, from the RDNA 2 ISA descriptions of IMAGE_ATOMIC_INC and IMAGE_ATOMIC_DEC (unsigned compares, old value returned):

  • inc: mem = mem >= data ? 0 : mem + 1
  • dec: mem = (mem == 0 || mem > data) ? data : mem - 1

These are the rules the repo already applies to the 64-bit buffer, global and LDS forms (BufferAtomicInc64, SharedAtomicInc64 and their Dec pairs). The new opcodes sit inside the ImageAtomicSwap64..ImageAtomicCmpSwap64 range, so IsImageAtomic64Opcode, the Int64ImageEXT capability and the storage-view selection apply unchanged.

The debt entry in docs/dev/debt/shader.md is cut so it no longer lists 64-bit inc/dec as throwing. The 64-bit float atomics and other accesses to the same image still throw.

Tested

NVIDIA GeForce RTX 5090, driver 610.88 (32.0.16.1088), Windows 11 Pro 26200. Built with WinLibs GCC 15.2.0, Release, on main 0f147e329f.

  • agc_driver_image_atomics64 gains image_atomic_inc and image_atomic_dec blocks in its hand-assembled shader (rows 11 and 12; 0xf06c2308 and 0xf0702308). They check the returned and stored value for the 12 edge pairs and the random inputs on 32_32 UINT, SINT and FLOAT.
  • The test fails if inc compares with > instead of >=, and if dec wraps to 0 instead of data.
  • On both main and this branch, ctest --test-dir build -R ^agc_driver_image_atomics -V ran with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1 (Vulkan SDK 1.4.363.1):
    • 4/4 passed on each.
    • Neither log contains was not found but was requested by env var VK_INSTANCE_LAYERS.
    • VK_LOADER_DEBUG=layer shows the validation layer inserted.
    • Both logs have 0 VUID- lines, so the change adds no validation errors.
  • Also passed: agc_driver_image_atomics, _bitwise, _float, shader_ir_use_rewrite, shader_memory_decoder_tolerance, agc_ir_reclaim, ir_dump_memory, shader_scan, progress_report and progress_report_inputs.
  • python3 tools/check_conventions.py --base origin/main passes.
  • tools/pr_overlap.py finds no open PR with the same exports or new files. It could not compare 29 PRs that conflict with main. I checked their diffs by hand: none adds 64-bit image inc/dec.
  • No title is known to use these forms.

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: none
  • GPUs tested: NVIDIA GeForce RTX 5090, driver 610.88, Windows 11 Pro 26200
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5207454504 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16952). Originally posted by [r614](https://github.com/r614) on 2026-11-08T01:07:17Z. --- ### What 64-bit `image_atomic_inc` and `image_atomic_dec` (MIMG opcodes 0x1b and 0x1c with a two-dword data mask) threw `64-bit ImageAtomicInc32 is not implemented`. They now translate to new `ImageAtomicInc64` / `ImageAtomicDec64` IR opcodes. Those run as a 64-bit compare-and-swap loop through the existing `AtomicUpdateTyped` on the R64_UINT texel pointer that the other 64-bit image atomics use. Semantics, from the RDNA 2 ISA descriptions of `IMAGE_ATOMIC_INC` and `IMAGE_ATOMIC_DEC` (unsigned compares, old value returned): - inc: `mem = mem >= data ? 0 : mem + 1` - dec: `mem = (mem == 0 || mem > data) ? data : mem - 1` These are the rules the repo already applies to the 64-bit buffer, global and LDS forms (`BufferAtomicInc64`, `SharedAtomicInc64` and their `Dec` pairs). The new opcodes sit inside the `ImageAtomicSwap64`..`ImageAtomicCmpSwap64` range, so `IsImageAtomic64Opcode`, the Int64ImageEXT capability and the storage-view selection apply unchanged. The debt entry in `docs/dev/debt/shader.md` is cut so it no longer lists 64-bit inc/dec as throwing. The 64-bit float atomics and other accesses to the same image still throw. ### Tested NVIDIA GeForce RTX 5090, driver 610.88 (32.0.16.1088), Windows 11 Pro 26200. Built with WinLibs GCC 15.2.0, Release, on `main` 0f147e329f. - `agc_driver_image_atomics64` gains `image_atomic_inc` and `image_atomic_dec` blocks in its hand-assembled shader (rows 11 and 12; `0xf06c2308` and `0xf0702308`). They check the returned and stored value for the 12 edge pairs and the random inputs on 32_32 UINT, SINT and FLOAT. - The test fails if inc compares with `>` instead of `>=`, and if dec wraps to 0 instead of `data`. - On both `main` and this branch, `ctest --test-dir build -R ^agc_driver_image_atomics -V` ran with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1` (Vulkan SDK 1.4.363.1): - 4/4 passed on each. - Neither log contains `was not found but was requested by env var VK_INSTANCE_LAYERS`. - `VK_LOADER_DEBUG=layer` shows the validation layer inserted. - Both logs have 0 `VUID-` lines, so the change adds no validation errors. - Also passed: `agc_driver_image_atomics`, `_bitwise`, `_float`, `shader_ir_use_rewrite`, `shader_memory_decoder_tolerance`, `agc_ir_reclaim`, `ir_dump_memory`, `shader_scan`, `progress_report` and `progress_report_inputs`. - `python3 tools/check_conventions.py --base origin/main` passes. - `tools/pr_overlap.py` finds no open PR with the same exports or new files. It could not compare 29 PRs that conflict with `main`. I checked their diffs by hand: none adds 64-bit image inc/dec. - No title is known to use these forms. ### 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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 5090, driver 610.88, Windows 11 Pro 26200 - [x] AI-assisted: yes
MarcZX10 commented 2026-11-18 21:14:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T21:14:21Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and test additions inspected support merging.

What I ran

Reviewed head 9f494d21fc2d9d7688c6fc3b8bcf2e82403b9282 using the prepared diff and the pinned repository reader. No tests were run.

Results

Check Result Note
Diff and changed-file review passed Eight changed files read
Tests not run Author-reported runs were not repeated

Findings

Blocking

None.

Non-blocking

None.

Not verified

I read every changed file listed in the manifest. files.json was unavailable through the reader, so excluded-file details could not be confirmed. I did not run tests or independently verify the author-reported hardware and CI results.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5965277405 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16952#pullrequestreview-5965277405). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T21:14:21Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and test additions inspected support merging. ## What I ran Reviewed head `9f494d21fc2d9d7688c6fc3b8bcf2e82403b9282` using the prepared diff and the pinned repository reader. No tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed-file review | passed | Eight changed files read | | Tests | not run | Author-reported runs were not repeated | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I read every changed file listed in the manifest. `files.json` was unavailable through the reader, so excluded-file details could not be confirmed. I did not run tests or independently verify the author-reported hardware and CI results. ## To get this to a good state Nothing is required.
MarcZX10 commented 2026-11-19 03:27:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T03:27:52Z.

Review: APPROVED


Reviewed — looks good

Nothing blocks this change; the implementation and added edge case coverage look sound based on the source reviewed.

What I ran

Reviewed head 52b292d27312f29fe487bbf87859eac0bedbe0b7 using the prepared diff and pinned repository reader. No tests or builds were run.

Results

Check Result Note
Source review passed All eight changed files read
Tests and build not run Author-reported results not independently verified

Findings

Blocking

None.

Non-blocking

None.

Not verified

Did not run the tests, build, GPU validation, or convention checks reported in the PR description. No changed files were excluded: all eight changed files listed in the manifest were included and read. The separately requested files.json was not available through the reader; the reader listing confirmed the eight changed files and their inclusion.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5968893211 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16952#pullrequestreview-5968893211). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-19T03:27:52Z. **Review:** APPROVED --- # Reviewed — looks good Nothing blocks this change; the implementation and added edge case coverage look sound based on the source reviewed. ## What I ran Reviewed head `52b292d27312f29fe487bbf87859eac0bedbe0b7` using the prepared diff and pinned repository reader. No tests or builds were run. ## Results | Check | Result | Note | |---|---|---| | Source review | passed | All eight changed files read | | Tests and build | not run | Author-reported results not independently verified | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified Did not run the tests, build, GPU validation, or convention checks reported in the PR description. No changed files were excluded: all eight changed files listed in the manifest were included and read. The separately requested `files.json` was not available through the reader; the reader listing confirmed the eight changed files and their inclusion. ## To get this to a good state Nothing is required.
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!16952
No description provided.