feat(shader): support 32-bit image atomics through keyed image tables #8792

Merged
SuarezPM merged 2 commits from upstream-pr/8792 into main 2026-10-23 22:00:04 +00:00
SuarezPM commented 2026-10-21 00:42:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SuarezPM on 2026-10-21T00:42:59Z.


What

32-bit image atomics through keyed image tables no longer fault. A T# keyed at runtime feeding image_atomic_*32 now lowers to OpAtomic* on the table's AtomicView instead of unsupported operation, so compute using bindless UAVs stops dying on the first atomic dispatch. Follows up the stores support from #6402, which left atomics faulting ("Atomic, packed, BY2/BY4 and dynamic-mip table stores still fault").

  • ResourceTracker::AssignTables keeps tableOperation supported for 32-bit atomics; 64-bit atomics, packed and BY formats still mark Unsupported.
  • Table elements carry the atomic flag through dedup into the descriptor binding (DescriptorBindingBuilder, ShaderResources), and the table write path binds AtomicView exactly like the direct path.
  • docs/dev/debt/shader.md rewrites the image-table entry: 32-bit atomics supported (Device scope, relaxed, AcquireRelease/UniformMemory barrier as the direct path); faulting remainder is image_store_mip/image_store_pck, PCK2/PCK4, MIMG BY2/BY4 and 64-bit atomics.

Tested

$ cmake -S . -B build-full -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON
$ cmake --build build-full
[4052/4052] built, exit 0

$ ctest --test-dir build-full --output-on-failure -E "trace_|progress"
100% tests passed out of 1732

$ ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ./build-full/tests/agc_driver_image_table_tests
image table tests passed (incl. new RunAtomicTests: add/swap/cmpswap on R32_UINT by runtime key, float-record add, null-entry no-reach)

$ ./build-full/tests/agc_shader_memory_tests
Shader memory capture, strict validation and deterministic replay passed

$ python3 tools/check_conventions.py --base origin/main
All conventions checks passed.

$ python3 tools/pr_overlap.py --branch ai/image-atomics-keyed-tables
Line-level contact only with #7803 (MSAA sample-0) and #8429 (FMASK width): neighbouring debt entries, no same-function overlap (reviewed manually).

Host: Linux x86-64 (CachyOS), Ryzen 5 3600, RTX 2060 SUPER (NVIDIA 615.78.08). No validation layer installed on this host, so no VUIDs could be produced here; full builds run on merge.

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 RTX 2060 SUPER, driver 615.78.08, CachyOS Linux (execution tests with validation layers requested; no VUIDs observed — validation layer not installed on host)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4944583249 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8792). Originally posted by [SuarezPM](https://github.com/SuarezPM) on 2026-10-21T00:42:59Z. --- ### What 32-bit image atomics through keyed image tables no longer fault. A T# keyed at runtime feeding `image_atomic_*32` now lowers to `OpAtomic*` on the table's `AtomicView` instead of `unsupported operation`, so compute using bindless UAVs stops dying on the first atomic dispatch. Follows up the stores support from #6402, which left atomics faulting ("Atomic, packed, BY2/BY4 and dynamic-mip table stores still fault"). - `ResourceTracker::AssignTables` keeps `tableOperation` supported for 32-bit atomics; 64-bit atomics, packed and BY formats still mark `Unsupported`. - Table elements carry the atomic flag through dedup into the descriptor binding (`DescriptorBindingBuilder`, `ShaderResources`), and the table write path binds `AtomicView` exactly like the direct path. - `docs/dev/debt/shader.md` rewrites the image-table entry: 32-bit atomics supported (`Device` scope, relaxed, `AcquireRelease`/`UniformMemory` barrier as the direct path); faulting remainder is `image_store_mip`/`image_store_pck`, PCK2/PCK4, MIMG BY2/BY4 and 64-bit atomics. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> ``` $ cmake -S . -B build-full -G Ninja -DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON $ cmake --build build-full [4052/4052] built, exit 0 $ ctest --test-dir build-full --output-on-failure -E "trace_|progress" 100% tests passed out of 1732 $ ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation ./build-full/tests/agc_driver_image_table_tests image table tests passed (incl. new RunAtomicTests: add/swap/cmpswap on R32_UINT by runtime key, float-record add, null-entry no-reach) $ ./build-full/tests/agc_shader_memory_tests Shader memory capture, strict validation and deterministic replay passed $ python3 tools/check_conventions.py --base origin/main All conventions checks passed. $ python3 tools/pr_overlap.py --branch ai/image-atomics-keyed-tables Line-level contact only with #7803 (MSAA sample-0) and #8429 (FMASK width): neighbouring debt entries, no same-function overlap (reviewed manually). ``` Host: Linux x86-64 (CachyOS), Ryzen 5 3600, RTX 2060 SUPER (NVIDIA 615.78.08). No validation layer installed on this host, so no VUIDs could be produced here; full builds run on merge. ### 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 RTX 2060 SUPER, driver 615.78.08, CachyOS Linux (execution tests with validation layers requested; no VUIDs observed — validation layer not installed on host) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-21 00:50:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T00:50:12Z.

Review: CHANGES_REQUESTED


I found a remaining StorageView in the recorded image-table descriptor update path. In ShaderResources::buildComplete(), the binding.flags != 0 branch around line 2349 constructs VkDescriptorImageInfo with storageTextures[index]->StorageView(...) unconditionally. The compact-binding path below it (around line 2394) now selects AtomicView when storageAtomic[index] is set, but table descriptors use the recorded branch. Since this PR marks table elements atomic in resolveImageTables(), the table can still be written with the non-atomic view and the new execution tests may fail or trigger Vulkan validation there. Please make the recorded table write use the same storageAtomic64 / storageAtomic view selection as the compact path, then run the image-table tests with validation when available. Hosted GPU/build jobs are skipped on the current PR head, so they do not verify this branch.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5593614354 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8792#pullrequestreview-5593614354). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T00:50:12Z. **Review:** CHANGES_REQUESTED --- I found a remaining `StorageView` in the recorded image-table descriptor update path. In `ShaderResources::buildComplete()`, the `binding.flags != 0` branch around line 2349 constructs `VkDescriptorImageInfo` with `storageTextures[index]->StorageView(...)` unconditionally. The compact-binding path below it (around line 2394) now selects `AtomicView` when `storageAtomic[index]` is set, but table descriptors use the recorded branch. Since this PR marks table elements atomic in `resolveImageTables()`, the table can still be written with the non-atomic view and the new execution tests may fail or trigger Vulkan validation there. Please make the recorded table write use the same `storageAtomic64` / `storageAtomic` view selection as the compact path, then run the image-table tests with validation when available. Hosted GPU/build jobs are skipped on the current PR head, so they do not verify this branch.
MarcZX10 commented 2026-10-21 01:05:10 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-21T01:05:10Z.

Review: APPROVED


Correction to my earlier review: I misread the recorded table descriptor branch. It already selects AtomicView for atomic entries (and Atomic64View for 64-bit entries in the compact branch); the table image-info construction shown here is correct. I withdraw my request for changes. The PR checks currently pass for eligibility, conventions, intake, labels, and report; build/runtime jobs are skipped, so I have not independently verified the GPU execution claim.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5593714929 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8792#pullrequestreview-5593714929). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-21T01:05:10Z. **Review:** APPROVED --- Correction to my earlier review: I misread the recorded table descriptor branch. It already selects AtomicView for atomic entries (and Atomic64View for 64-bit entries in the compact branch); the table image-info construction shown here is correct. I withdraw my request for changes. The PR checks currently pass for eligibility, conventions, intake, labels, and report; build/runtime jobs are skipped, so I have not independently verified the GPU execution claim.
SuarezPM commented 2026-10-21 02:38:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SuarezPM on 2026-10-21T02:38:35Z.


Thanks for the careful review and the correction, MarcZX10 — glad the recorded table branch reads correctly on re-read. GPU execution evidence is in the PR body (RTX 2060 SUPER runs); happy to add any extra run you want. Leaving it in the maintainers' queue.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6306624746 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8792#issuecomment-6306624746). Originally posted by [SuarezPM](https://github.com/SuarezPM) on 2026-10-21T02:38:35Z. --- Thanks for the careful review and the correction, MarcZX10 — glad the recorded table branch reads correctly on re-read. GPU execution evidence is in the PR body (RTX 2060 SUPER runs); happy to add any extra run you want. Leaving it in the maintainers' queue.
xXPBSXx commented 2026-10-21 03:53:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by xXPBSXx on 2026-10-21T03:53:27Z.


Windows data point for a55b76e09 merged onto main a683688fe (clean, git merge-tree rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. ctest -N -R '^agc_shader_memory$' lists exactly that one test; ctest --no-tests=error -R '^agc_shader_memory$' was run three times per tree.

  • With the PR: passes 3 of 3 (0.9-1.1 s).
  • Same tree with the non-test files of the PR (ShaderResources.cpp, ResourceMaterializer.hpp/.cpp, DescriptorBindingBuilder.cpp, ResourceTracker.cpp) restored to main (the new test cases kept): fails 3 of 3 (ordinary test failure, not a crash).
    Not tested: the new execution/ImageTable.cpp cases (a GPU test, not run), other platforms, a title run.
    AI-assisted (Claude Code).
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307618580 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8792#issuecomment-6307618580). Originally posted by [xXPBSXx](https://github.com/xXPBSXx) on 2026-10-21T03:53:27Z. --- Windows data point for `a55b76e09` merged onto `main` `a683688fe` (clean, `git merge-tree` rc 0): Windows 10.0.19045, MinGW-w64 GCC 15.2.0, Release. `ctest -N -R '^agc_shader_memory$'` lists exactly that one test; `ctest --no-tests=error -R '^agc_shader_memory$'` was run three times per tree. - With the PR: passes 3 of 3 (0.9-1.1 s). - Same tree with the non-test files of the PR (`ShaderResources.cpp`, `ResourceMaterializer.hpp/.cpp`, `DescriptorBindingBuilder.cpp`, `ResourceTracker.cpp`) restored to `main` (the new test cases kept): fails 3 of 3 (ordinary test failure, not a crash). Not tested: the new `execution/ImageTable.cpp` cases (a GPU test, not run), other platforms, a title run. AI-assisted (Claude Code).
thuanquang commented 2026-10-21 06:33:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-21T06:33:50Z.


An AMD proprietary-driver run: RX 6700 XT (gfx1031), AMD Windows driver 32.0.21045.5002, Windows 11 26200, MinGW GCC 15.2.0, Release, ANYPS5_REQUIRE_VULKAN=1.

  • main 338f22e49 with only this PR's ImageTable.cpp and ShaderMemory.cpp: agc_driver_image_table fails with image table registration: a table T# feeding image_atomic_add was not a supported table operation, and agc_shader_memory fails too. agc_driver_image_atomics and agc_driver_image_atomics_float pass.
  • main 338f22e49 merged with this head a55b76e09 (clean merge): all four pass 3 of 3.
  • Khronos validation layer, ctest -V on the same four: main a07e985c8 and a07e985c8 + this head both pass 4 of 4. There are 0 VUID- lines on either side, and the layer was inserted in each GPU test process.

On the float-record case: integer image_atomic_add on a 32_FLOAT texel adds the raw bits on RDNA 2, as the test expects. I measured this earlier on the same card through the HIP oracle for #7939: the stored value matched the raw-integer model on all 121 rows, in wave32 and wave64.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6309692937 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8792#issuecomment-6309692937). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-21T06:33:50Z. --- An AMD proprietary-driver run: RX 6700 XT (gfx1031), AMD Windows driver 32.0.21045.5002, Windows 11 26200, MinGW GCC 15.2.0, Release, `ANYPS5_REQUIRE_VULKAN=1`. - **`main` `338f22e49` with only this PR's `ImageTable.cpp` and `ShaderMemory.cpp`:** `agc_driver_image_table` fails with `image table registration: a table T# feeding image_atomic_add was not a supported table operation`, and `agc_shader_memory` fails too. `agc_driver_image_atomics` and `agc_driver_image_atomics_float` pass. - **`main` `338f22e49` merged with this head `a55b76e09` (clean merge):** all four pass 3 of 3. - **Khronos validation layer, `ctest -V` on the same four:** `main` `a07e985c8` and `a07e985c8` + this head both pass 4 of 4. There are 0 `VUID-` lines on either side, and the layer was inserted in each GPU test process. On the float-record case: integer `image_atomic_add` on a 32_FLOAT texel adds the raw bits on RDNA 2, as the test expects. I measured this earlier on the same card through the HIP oracle for #7939: the stored value matched the raw-integer model on all 121 rows, in wave32 and wave64.
SuarezPM commented 2026-10-21 21:23:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SuarezPM on 2026-10-21T21:23:21Z.


Thanks xXPBSXx and thuanquang — the reverted-to-main control failing 3/3 and the AMD + validation 0-VUID runs are exactly the evidence this PR needed, including the float-record confirmation against your HIP oracle rows. Much appreciated.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6326864451 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8792#issuecomment-6326864451). Originally posted by [SuarezPM](https://github.com/SuarezPM) on 2026-10-21T21:23:21Z. --- Thanks xXPBSXx and thuanquang — the reverted-to-main control failing 3/3 and the AMD + validation 0-VUID runs are exactly the evidence this PR needed, including the float-record confirmation against your HIP oracle rows. Much appreciated.
oneandonlydean commented 2026-10-22 03:14:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-22T03:14:21Z.


@SuarezPM thanks for the update. The full CI run on a55b76e092 (merged into current main) fails three tests on Linux, and the cause is in this PR:

  • agc_shader_bindless, agc_shader_memory and agc_driver_image_table all stop with SPIR-V validation before optimization failed: OpPhi's result type <id> '1[%1]' does not match incoming value ..., e.g. %246 = OpPhi %uint %263 %254 %272 %267 %273 %248.
  • Main passes all three in the same lane at the same base, and the commits between bases don't touch the shader recompiler.

Why it shows up only there: only the Linux CI lane configures with -DANYPS5_ENABLE_SPIRV_TOOLS=ON (build.yml:511). The option defaults to OFF, so Windows CI and a default local build skip validation, and GPU drivers accept the module. That is why the execution runs on real hardware passed.

Cause: before this PR, 32-bit image atomics never reached the keyed-table path, so the table merge in SpirvImageEmitter.cpp could assume a 4 x u32 result. With atomics now in the table path, the result is a scalar %uint, but the poisoned-element branch still feeds the merge Phi a vector zero:

// SpirvImageEmitter.cpp:1971
if (returnsValue) incoming.insert(incoming.end(), {ConstantU32CompositeZero(state, 4u), invalid});

The sampler-guard Phi at :1988 has the same constant. ZeroResult(ctx, inst) in the same file already returns the right zero for U32, U64 and U32x4, so using it at both places should fix it. To reproduce locally, configure with -DANYPS5_ENABLE_SPIRV_TOOLS=ON and run agc_shader_bindless.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331782070 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8792#issuecomment-6331782070). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-22T03:14:21Z. --- @SuarezPM thanks for the update. The full CI run on a55b76e092 (merged into current main) fails three tests on Linux, and the cause is in this PR: - agc_shader_bindless, agc_shader_memory and agc_driver_image_table all stop with `SPIR-V validation before optimization failed: OpPhi's result type <id> '1[%1]' does not match incoming value ...`, e.g. `%246 = OpPhi %uint %263 %254 %272 %267 %273 %248`. - Main passes all three in the same lane at the same base, and the commits between bases don't touch the shader recompiler. Why it shows up only there: only the Linux CI lane configures with `-DANYPS5_ENABLE_SPIRV_TOOLS=ON` (build.yml:511). The option defaults to OFF, so Windows CI and a default local build skip validation, and GPU drivers accept the module. That is why the execution runs on real hardware passed. Cause: before this PR, 32-bit image atomics never reached the keyed-table path, so the table merge in `SpirvImageEmitter.cpp` could assume a 4 x u32 result. With atomics now in the table path, the result is a scalar `%uint`, but the poisoned-element branch still feeds the merge Phi a vector zero: ```cpp // SpirvImageEmitter.cpp:1971 if (returnsValue) incoming.insert(incoming.end(), {ConstantU32CompositeZero(state, 4u), invalid}); ``` The sampler-guard Phi at :1988 has the same constant. `ZeroResult(ctx, inst)` in the same file already returns the right zero for U32, U64 and U32x4, so using it at both places should fix it. To reproduce locally, configure with `-DANYPS5_ENABLE_SPIRV_TOOLS=ON` and run `agc_shader_bindless`.
SuarezPM commented 2026-10-22 10:38:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SuarezPM on 2026-10-22T10:38:38Z.


Fixed as suggested: both merge sites now use ZeroResult(ctx, inst) (commit on top of current main, rebased cleanly). Reproduced your lane locally with ANYPS5_ENABLE_SPIRV_TOOLS=ON: agc_shader_bindless, agc_shader_memory and agc_driver_image_table all pass, plus the Turing execution runs. The missing submodule for the new main (3rdparty/vgmstream) was the only rebase friction; no code conflicts.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6338730213 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8792#issuecomment-6338730213). Originally posted by [SuarezPM](https://github.com/SuarezPM) on 2026-10-22T10:38:38Z. --- Fixed as suggested: both merge sites now use `ZeroResult(ctx, inst)` (commit on top of current main, rebased cleanly). Reproduced your lane locally with `ANYPS5_ENABLE_SPIRV_TOOLS=ON`: `agc_shader_bindless`, `agc_shader_memory` and `agc_driver_image_table` all pass, plus the Turing execution runs. The missing submodule for the new main (`3rdparty/vgmstream`) was the only rebase friction; no code conflicts.
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!8792
No description provided.