feat(shader): split unused-result 64-bit bitwise buffer atomics without shaderBufferInt64Atomics #11510

Merged
morten-holm merged 5 commits from upstream-pr/11510 into main 2026-11-02 10:28:54 +00:00
morten-holm commented 2026-10-26 17:40:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by morten-holm on 2026-10-26T17:40:13Z.


What

A 64-bit buffer_atomic_or, and or xor compiles on a device without shaderBufferInt64Atomics when the instruction result is not used.

The recompiler now emits two 32-bit atomics on the low and high dwords of the 64-bit address. The 64-bit alignment and bounds checks stay. Each dword is atomic. The pair is not atomic as one 64-bit operation.

Other 64-bit buffer atomics, and any atomic whose result is read, still fail with "64-bit buffer atomics need shaderBufferInt64Atomics". The limit is listed in docs/dev/debt/shader.md.

MoltenVK and KosmicKrisp do not expose shaderBufferInt64Atomics.

Tested

  • macOS 27.0.1, Apple M2, x86-64 build under Rosetta 2.
  • agc_shader_memory_tests passes. New cases: OR, AND and XOR compile without the capability and do not declare Int64Atomics. They declare it when the device has it. An OR with a stored result and an ADD still fail.
  • Same test on main and on this change with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (validation layer 1.4.363, x86-64): both exit 0. Neither log has "was not found but was requested". Neither has a VUID- line. This test creates no Vulkan device, so the layer was not exercised. These runs used an older main base than this branch.
  • ASTRO BOT (PPSA21567), MoltenVK, 75 s run: 8 of the 12 shaders that failed with the 64-bit atomics error now compile. 4 still fail with the same error because they use other opcodes. The run had no crash. I did not check the rendered output.
  • Not tested: the split form on other GPUs, and the result of the split on real data.

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: PPSA21567 (ASTRO BOT) and in part PPSA02100 (Stray); no Game bring-up discussion number known
  • GPUs tested: Apple M2, MoltenVK, macOS 27.0.1 (AGC shader recompiler); the validation run is CPU-side
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5021963690 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11510). Originally posted by [morten-holm](https://github.com/morten-holm) on 2026-10-26T17:40:13Z. --- ### What A 64-bit `buffer_atomic_or`, `and` or `xor` compiles on a device without `shaderBufferInt64Atomics` when the instruction result is not used. The recompiler now emits two 32-bit atomics on the low and high dwords of the 64-bit address. The 64-bit alignment and bounds checks stay. Each dword is atomic. The pair is not atomic as one 64-bit operation. Other 64-bit buffer atomics, and any atomic whose result is read, still fail with "64-bit buffer atomics need shaderBufferInt64Atomics". The limit is listed in `docs/dev/debt/shader.md`. MoltenVK and KosmicKrisp do not expose `shaderBufferInt64Atomics`. ### Tested - macOS 27.0.1, Apple M2, x86-64 build under Rosetta 2. - `agc_shader_memory_tests` passes. New cases: OR, AND and XOR compile without the capability and do not declare Int64Atomics. They declare it when the device has it. An OR with a stored result and an ADD still fail. - Same test on `main` and on this change with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (validation layer 1.4.363, x86-64): both exit 0. Neither log has "was not found but was requested". Neither has a `VUID-` line. This test creates no Vulkan device, so the layer was not exercised. These runs used an older `main` base than this branch. - ASTRO BOT (PPSA21567), MoltenVK, 75 s run: 8 of the 12 shaders that failed with the 64-bit atomics error now compile. 4 still fail with the same error because they use other opcodes. The run had no crash. I did not check the rendered output. - Not tested: the split form on other GPUs, and the result of the split on real data. ### 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: PPSA21567 (ASTRO BOT) and in part PPSA02100 (Stray); no Game bring-up discussion number known - [x] GPUs tested: Apple M2, MoltenVK, macOS 27.0.1 (AGC shader recompiler); the validation run is CPU-side - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-26 17:44:21 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-26T17:44:21Z.

Review: CHANGES_REQUESTED


Two validation gaps remain before this shader change is ready to merge:

  1. The new compile assertions only check that the module is nonempty and does not declare Int64Atomics. They would still pass if the emitter accidentally dropped the atomic. Please inspect the emitted SPIR-V and assert that each OR/AND/XOR case contains the expected two 32-bit atomic operations, including the low/high dword addresses.
  2. CONTRIBUTING.md requires the same focused AGC test on current main and the change, on the same machine and GPU, with the requested Vulkan environment and validation comparison. The description says the main run used an older base than this branch. Please rerun both at current base 88795ed44801fa719eb2df990cbe1f11a1f9bd81 and this head, then record the exact commits, GPU vendor/model, driver and OS, missing-layer check, and any VUID- differences. The hosted product and relinker jobs are currently skipped, so they do not supply this comparison.

Local tools/check_conventions.py and git show --check pass. I have not run the focused AGC test locally; the current-main build for the separate #11481 reproduction is still compiling. Changes requested for the test assertion and required current-base validation, not for a demonstrated runtime defect.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5656472288 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11510#pullrequestreview-5656472288). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-26T17:44:21Z. **Review:** CHANGES_REQUESTED --- Two validation gaps remain before this shader change is ready to merge: 1. The new compile assertions only check that the module is nonempty and does not declare `Int64Atomics`. They would still pass if the emitter accidentally dropped the atomic. Please inspect the emitted SPIR-V and assert that each OR/AND/XOR case contains the expected two 32-bit atomic operations, including the low/high dword addresses. 2. `CONTRIBUTING.md` requires the same focused AGC test on current `main` and the change, on the same machine and GPU, with the requested Vulkan environment and validation comparison. The description says the `main` run used an older base than this branch. Please rerun both at current base `88795ed44801fa719eb2df990cbe1f11a1f9bd81` and this head, then record the exact commits, GPU vendor/model, driver and OS, missing-layer check, and any `VUID-` differences. The hosted product and relinker jobs are currently skipped, so they do not supply this comparison. Local `tools/check_conventions.py` and `git show --check` pass. I have not run the focused AGC test locally; the current-main build for the separate #11481 reproduction is still compiling. Changes requested for the test assertion and required current-base validation, not for a demonstrated runtime defect.
jotitadev commented 2026-10-27 10:17:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-27T10:17:33Z.

Review: COMMENTED


Clean main vs this head on Linux, since macOS can't build main.

Linux run: Ubuntu 26.04, GCC 15.2, Release. RTX 3070 (NVIDIA 595.99.02) and lavapipe (Mesa 26.0.3), one at a time via VK_DRIVER_FILES. Khronos validation layer 1.4.341 with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1; VK_LOADER_DEBUG=layer shows the layer inserted, no "was not found but was requested", 0 VUID- lines.

Base main 808a557ac (newer than 88795ed448; the merge of 9ebcc241f is clean).

  • main + only this PR's tests/ShaderMemory.cpp: agc_shader_memory fails with 64-bit buffer atomics need shaderBufferInt64Atomics. So the new cases do catch the missing split.
  • main alone: agc_shader_memory passes.
  • main + this PR (merge --no-commit): agc_shader_memory passes 3/3. agc_driver_buffer_atomics*, agc_driver_global_atomics64 and agc_driver_image_atomics64 pass 3/3 on both devices (7/7 per run).
  • As you said, agc_shader_memory creates no Vulkan device, so the layer only covers the execution tests. Both devices here expose shaderBufferInt64Atomics, so the split itself doesn't run on GPU here. These runs show the native path doesn't change.
  • ^agc suite (no flip/display/lds64, -j1): 3070 1052/1052, lavapipe 1051/1052. The one failure is agc_driver_multisample_retirement, which also fails on main.
  • Builds on Linux/GCC; public_headers passes.

GPUs tested: NVIDIA RTX 3070 (Linux), lavapipe.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5665454454 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11510#pullrequestreview-5665454454). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-27T10:17:33Z. **Review:** COMMENTED --- Clean `main` vs this head on Linux, since macOS can't build `main`. Linux run: Ubuntu 26.04, GCC 15.2, Release. RTX 3070 (NVIDIA 595.99.02) and lavapipe (Mesa 26.0.3), one at a time via `VK_DRIVER_FILES`. Khronos validation layer 1.4.341 with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`; `VK_LOADER_DEBUG=layer` shows the layer inserted, no "was not found but was requested", 0 `VUID-` lines. Base `main` `808a557ac` (newer than `88795ed448`; the merge of `9ebcc241f` is clean). - `main` + only this PR's `tests/ShaderMemory.cpp`: `agc_shader_memory` fails with `64-bit buffer atomics need shaderBufferInt64Atomics`. So the new cases do catch the missing split. - `main` alone: `agc_shader_memory` passes. - `main` + this PR (`merge --no-commit`): `agc_shader_memory` passes 3/3. `agc_driver_buffer_atomics*`, `agc_driver_global_atomics64` and `agc_driver_image_atomics64` pass 3/3 on both devices (7/7 per run). - As you said, `agc_shader_memory` creates no Vulkan device, so the layer only covers the execution tests. Both devices here expose `shaderBufferInt64Atomics`, so the split itself doesn't run on GPU here. These runs show the native path doesn't change. - `^agc` suite (no flip/display/lds64, `-j1`): 3070 1052/1052, lavapipe 1051/1052. The one failure is `agc_driver_multisample_retirement`, which also fails on `main`. - Builds on Linux/GCC; `public_headers` passes. GPUs tested: NVIDIA RTX 3070 (Linux), lavapipe. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-28 22:06:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-28T22:06:02Z.

Review: CHANGES_REQUESTED


Reviewing exact head 990a69fa06c1a229d56cdb7aa6ffe44952e2d83d.

What I ran

  • Inspected the four-commit diff, current test and CI reports, and the review discussion.
  • Verified the PR's hosted relinker platform matrix, ASan, Windows, conventions, eligibility, labels, and report checks pass. Linux full-build, register-context, and write-watch jobs are skipped.
  • Compared the PR base 88795ed448 with current main 319621ba2e: current main has since changed core/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cpp, core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp, and related AGC shader tests.
  • I did not run a local build or tests.

Results

Check Result Evidence
Patch and same-opcode split logic Reviewed Exact current four-commit diff
Hosted relinker platform matrix, ASan, Windows Pass GitHub Actions
Hosted conventions, eligibility, labels, report Pass GitHub Actions
Linux full-build and specialized hosted jobs Skipped GitHub Actions
Matched current-main shader validation Not yet verified Existing reported comparison uses older main 808a557; current main changed AGC shader-memory implementation and tests
Local build and CTest Not run This review

Findings

Blocking

  • The repository's AGENTS.md requires the same focused test on current main and the PR for shader-recompiler changes, using ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, and the Khronos validation layer, with logs compared for missing-layer warnings and new VUIDs. The posted comparison used main 808a557, while this PR is still based on 88795ed and current main is 319621ba; current main has changed the AGC shader-memory implementation and test sources since then. Please rebase or otherwise test the PR against current main and post the matched focused results before approval.

Non-blocking

  • The split is restricted to unused-result OR/AND/XOR operations, and the latest change rejects mixed-opcode programs. The added tests cover compilation and capability declaration. An independent report also describes successful builds and broad AGC execution tests on RTX 3070 and lavapipe. Those devices expose the native 64-bit atomic feature, so they do not execute the split path; the reported MoltenVK title runs show shader compilation progress but do not check rendered output. This leaves a useful follow-up validation gap, but I have not identified a specific incorrect result in the current diff.
  • The reported validation-layer run notes that agc_shader_memory creates no Vulkan device. Ensure the matched comparison includes a Vulkan-using focused test so the layer is actually inserted and can check for VUIDs.

Sources

Not verified

  • I did not locally build the shader recompiler, run CTest, run a GPU test, or inspect title output.
  • Platform test runs and title behavior mentioned above are reported by PR participants.

To get this to a good state

Rebase or test against current main, post the same focused checks on both trees with the required layer active, and include a Vulkan-using test in the validation comparison; then request a re-review.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5690318145 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11510#pullrequestreview-5690318145). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-28T22:06:02Z. **Review:** CHANGES_REQUESTED --- Reviewing exact head `990a69fa06c1a229d56cdb7aa6ffe44952e2d83d`. ## What I ran - Inspected the four-commit diff, current test and CI reports, and the review discussion. - Verified the PR's hosted relinker platform matrix, ASan, Windows, conventions, eligibility, labels, and report checks pass. Linux full-build, register-context, and write-watch jobs are skipped. - Compared the PR base `88795ed448` with current `main` `319621ba2e`: current main has since changed `core/libs/prx/libSceAgcDriver/Execution/src/ShaderMemory.cpp`, `core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp`, and related AGC shader tests. - I did not run a local build or tests. ## Results | Check | Result | Evidence | |---|---|---| | Patch and same-opcode split logic | Reviewed | Exact current four-commit diff | | Hosted relinker platform matrix, ASan, Windows | Pass | GitHub Actions | | Hosted conventions, eligibility, labels, report | Pass | GitHub Actions | | Linux full-build and specialized hosted jobs | Skipped | GitHub Actions | | Matched current-main shader validation | Not yet verified | Existing reported comparison uses older main `808a557`; current main changed AGC shader-memory implementation and tests | | Local build and CTest | Not run | This review | ## Findings ### Blocking - The repository's AGENTS.md requires the same focused test on current `main` and the PR for shader-recompiler changes, using `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, and the Khronos validation layer, with logs compared for missing-layer warnings and new VUIDs. The posted comparison used main `808a557`, while this PR is still based on `88795ed` and current main is `319621ba`; current main has changed the AGC shader-memory implementation and test sources since then. Please rebase or otherwise test the PR against current main and post the matched focused results before approval. ### Non-blocking - The split is restricted to unused-result OR/AND/XOR operations, and the latest change rejects mixed-opcode programs. The added tests cover compilation and capability declaration. An independent report also describes successful builds and broad AGC execution tests on RTX 3070 and lavapipe. Those devices expose the native 64-bit atomic feature, so they do not execute the split path; the reported MoltenVK title runs show shader compilation progress but do not check rendered output. This leaves a useful follow-up validation gap, but I have not identified a specific incorrect result in the current diff. - The reported validation-layer run notes that `agc_shader_memory` creates no Vulkan device. Ensure the matched comparison includes a Vulkan-using focused test so the layer is actually inserted and can check for VUIDs. ## Sources - [Repository shader validation rules](https://github.com/boykopovar/AnyPS5/blob/main/AGENTS.md) - [Current pull request and validation reports](https://github.com/boykopovar/AnyPS5/pull/11510) ## Not verified - I did not locally build the shader recompiler, run CTest, run a GPU test, or inspect title output. - Platform test runs and title behavior mentioned above are reported by PR participants. ## To get this to a good state Rebase or test against current main, post the same focused checks on both trees with the required layer active, and include a Vulkan-using test in the validation comparison; then request a re-review.
jotitadev commented 2026-10-30 17:08:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T17:08:27Z.

Review: COMMENTED


Matched current-main run of head 990a69fa0, plus the cause of the NVIDIA CI failure on this head.

Linux: Ubuntu 26.04, GCC 15.2, Release. RTX 3070 (NVIDIA 595.99.02) and lavapipe (Mesa 26.0.3), one at a time via VK_DRIVER_FILES. Khronos validation layer 1.4.341, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1. Base main f91137142; the head merges onto it cleanly.

RTX 3070 lavapipe
main + this PR's ShaderMemory.cpp only agc_shader_memory fails: 64-bit buffer atomics need shaderBufferInt64Atomics same
merged, agc_shader_memory + buffer_atomics* + global_atomics64 + image_atomics64 7/7, 3 of 3 runs, 0 VUID- 7/7, 3 of 3 runs, 0 VUID-
^agc suite (no display/flip/lds64), -j1 --timeout 30 1127/1128 1128/1128

The one RTX 3070 failure is agc_driver_graphics_maps_fallback timing out at 30 s, which also times out on main here under load. public_headers passes. The layer was inserted in the 6 device tests; agc_shader_memory creates no device, as noted before.

The NVIDIA CI failure is not NVIDIA-specific; it comes from ANYPS5_ENABLE_SPIRV_TOOLS=ON. The CI builds with it; the build above does not. I rebuilt agc_shader_memory_tests from the same merge with -DANYPS5_ENABLE_SPIRV_TOOLS=ON and it fails without any GPU, with the CI's message: an unused-result bitwise buffer atomic was not emitted as two 32-bit atomics.

With the option on, Recompile runs ValidateAndOptimizeSpirv, and verifySplit sees the optimized module. I dumped the module the OR case compiles to. The entry function has no atomic left: it computes the buffer address and bounds compares, then returns. The only atomics left are in the helper function (one 32-bit OpAtomicOr with a constant 1, a compare-exchange and an atomic store). The native compile of the same program (CapabilityInt64Atomics) loses its 64-bit atomic the same way. So the optimizer drops the test program's buffer atomic in both modes, and verifySplit finds 0 halves. That is a test problem, not a sign that the split emits the wrong thing.

Possible fixes: skip verifySplit under #if ANYPS5_ENABLE_SPIRV_TOOLS, or give the test program an atomic that the optimizer keeps. The declares(...) checks still pass with the option on, because the capability stays declared after the instruction is removed.

GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux); lavapipe (Mesa 26.0.3). As before, neither device runs the split at execution time, because both have shaderBufferInt64Atomics.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5715886299 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11510#pullrequestreview-5715886299). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-30T17:08:27Z. **Review:** COMMENTED --- Matched current-`main` run of head `990a69fa0`, plus the cause of the NVIDIA CI failure on this head. Linux: Ubuntu 26.04, GCC 15.2, Release. RTX 3070 (NVIDIA 595.99.02) and lavapipe (Mesa 26.0.3), one at a time via `VK_DRIVER_FILES`. Khronos validation layer 1.4.341, `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`. Base `main` `f91137142`; the head merges onto it cleanly. | | RTX 3070 | lavapipe | |---|---|---| | `main` + this PR's `ShaderMemory.cpp` only | `agc_shader_memory` fails: `64-bit buffer atomics need shaderBufferInt64Atomics` | same | | merged, `agc_shader_memory` + `buffer_atomics*` + `global_atomics64` + `image_atomics64` | 7/7, 3 of 3 runs, 0 `VUID-` | 7/7, 3 of 3 runs, 0 `VUID-` | | `^agc` suite (no display/flip/lds64), `-j1 --timeout 30` | 1127/1128 | 1128/1128 | The one RTX 3070 failure is `agc_driver_graphics_maps_fallback` timing out at 30 s, which also times out on `main` here under load. `public_headers` passes. The layer was inserted in the 6 device tests; `agc_shader_memory` creates no device, as noted before. **The NVIDIA CI failure is not NVIDIA-specific; it comes from `ANYPS5_ENABLE_SPIRV_TOOLS=ON`.** The CI builds with it; the build above does not. I rebuilt `agc_shader_memory_tests` from the same merge with `-DANYPS5_ENABLE_SPIRV_TOOLS=ON` and it fails without any GPU, with the CI's message: `an unused-result bitwise buffer atomic was not emitted as two 32-bit atomics`. With the option on, `Recompile` runs `ValidateAndOptimizeSpirv`, and `verifySplit` sees the optimized module. I dumped the module the OR case compiles to. The entry function has no atomic left: it computes the buffer address and bounds compares, then returns. The only atomics left are in the helper function (one 32-bit `OpAtomicOr` with a constant 1, a compare-exchange and an atomic store). The native compile of the same program (`CapabilityInt64Atomics`) loses its 64-bit atomic the same way. So the optimizer drops the test program's buffer atomic in both modes, and `verifySplit` finds 0 halves. That is a test problem, not a sign that the split emits the wrong thing. Possible fixes: skip `verifySplit` under `#if ANYPS5_ENABLE_SPIRV_TOOLS`, or give the test program an atomic that the optimizer keeps. The `declares(...)` checks still pass with the option on, because the capability stays declared after the instruction is removed. GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux); lavapipe (Mesa 26.0.3). As before, neither device runs the split at execution time, because both have `shaderBufferInt64Atomics`. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
jotitadev commented 2026-10-30 18:13:06 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T18:13:06Z.

Review: COMMENTED


Follow-up to my earlier note on the NVIDIA CI failure (ANYPS5_ENABLE_SPIRV_TOOLS=ON): I traced why the optimizer drops the atomic. It is the test's buffer descriptor, not the split and not the optimizer.

Head 990a69fa0 merged onto main f91137142, Linux, GCC 15.2, Release, SPIRV-Tools from the submodule. No GPU is involved; agc_shader_memory never creates a device.

What removes it. I dumped the module before optimization (APS5_SPIRV_OPT=none) and ran AnyPS5's default pass list one prefix at a time. All 5 atomics survive until dead-branch-elim right after ccp, which removes the two split OpAtomicOrs. Without ccp they stay. There is no OpUndef in the module, so this is not undefined-value folding.

Why. The recompiler already emits the bounds check as a constant false: %155 = OpLogicalAnd %bool %153 %false. The test's V# is 256u, 0x01016facu with stride 0 (word 1 bits 16-29). 0x01016fac has OOB_SELECT (bits 28-29) = 0, the structured mode, and byteAddress checks index < num_records && offset < stride there. With stride 0 every access is out of bounds, so the atomic is dead code, and dropping it is correct. The native 64-bit compile ends up with no atomic for the same reason. Without SPIRV-Tools nothing folds the branch, so verifySplit sees the atomics in the dead block.

Production impact: none that I can see. A real out-of-range buffer atomic is dropped the same way, and the 0-halves result comes from the test's descriptor.

Fix (test only), verified:

-        static_cast<std::uint32_t>(bufferAddress), static_cast<std::uint32_t>((bufferAddress >> 32u) & 0xffffu), 256u, 0x01016facu,
+        static_cast<std::uint32_t>(bufferAddress), static_cast<std::uint32_t>((bufferAddress >> 32u) & 0xffffu), 256u, 0x31016facu,
...
-    const std::vector<std::uint32_t> bufferOr{0xe1685000u, 0x80012803u, 0xbf810000u};
-    const std::vector<std::uint32_t> bufferAnd{0xe1645000u, 0x80012803u, 0xbf810000u};
-    const std::vector<std::uint32_t> bufferXor{0xe16c5000u, 0x80012803u, 0xbf810000u};
+    const std::vector<std::uint32_t> bufferOr{0xe1685000u, 0x80010003u, 0xbf810000u};
+    const std::vector<std::uint32_t> bufferAnd{0xe1645000u, 0x80010003u, 0xbf810000u};
+    const std::vector<std::uint32_t> bufferXor{0xe16c5000u, 0x80010003u, 0xbf810000u};
  • 0x31016facu sets OOB_SELECT = 3 (raw), so the access at offset 0 of the 256-byte buffer is in bounds.
  • vdata v0 instead of v40. The atomic needs both changes to pass. With only the first, the atomic survives, but v40/v41 are never written, so the data is the constant 0. ccp then folds both OpUConvert halves to %uint_0, and the last verifySplit check fails ("do not take the low and high dwords of the operand"). v0 is the invocation id and stays variable.
build agc_shader_memory
SPIRV-Tools ON, head as is fails: "...was not emitted as two 32-bit atomics"
SPIRV-Tools ON, with the diff passes, 3 of 3
SPIRV-Tools OFF, with the diff passes, 3 of 3

The red should be unchanged: on main, the first OR compile without shaderBufferInt64Atomics throws before verifySplit runs, whatever the V# and vdata are. I did not rerun that part.

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5716687180 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11510#pullrequestreview-5716687180). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-30T18:13:06Z. **Review:** COMMENTED --- Follow-up to my earlier note on the NVIDIA CI failure (`ANYPS5_ENABLE_SPIRV_TOOLS=ON`): I traced why the optimizer drops the atomic. It is the test's buffer descriptor, not the split and not the optimizer. Head `990a69fa0` merged onto `main` `f91137142`, Linux, GCC 15.2, Release, SPIRV-Tools from the submodule. No GPU is involved; `agc_shader_memory` never creates a device. **What removes it.** I dumped the module before optimization (`APS5_SPIRV_OPT=none`) and ran AnyPS5's default pass list one prefix at a time. All 5 atomics survive until `dead-branch-elim` right after `ccp`, which removes the two split `OpAtomicOr`s. Without `ccp` they stay. There is no `OpUndef` in the module, so this is not undefined-value folding. **Why.** The recompiler already emits the bounds check as a constant false: `%155 = OpLogicalAnd %bool %153 %false`. The test's V# is `256u, 0x01016facu` with stride 0 (word 1 bits 16-29). `0x01016fac` has OOB_SELECT (bits 28-29) = 0, the structured mode, and `byteAddress` checks `index < num_records && offset < stride` there. With stride 0 every access is out of bounds, so the atomic is dead code, and dropping it is correct. The native 64-bit compile ends up with no atomic for the same reason. Without SPIRV-Tools nothing folds the branch, so `verifySplit` sees the atomics in the dead block. **Production impact:** none that I can see. A real out-of-range buffer atomic is dropped the same way, and the 0-halves result comes from the test's descriptor. **Fix (test only), verified:** ```diff - static_cast<std::uint32_t>(bufferAddress), static_cast<std::uint32_t>((bufferAddress >> 32u) & 0xffffu), 256u, 0x01016facu, + static_cast<std::uint32_t>(bufferAddress), static_cast<std::uint32_t>((bufferAddress >> 32u) & 0xffffu), 256u, 0x31016facu, ... - const std::vector<std::uint32_t> bufferOr{0xe1685000u, 0x80012803u, 0xbf810000u}; - const std::vector<std::uint32_t> bufferAnd{0xe1645000u, 0x80012803u, 0xbf810000u}; - const std::vector<std::uint32_t> bufferXor{0xe16c5000u, 0x80012803u, 0xbf810000u}; + const std::vector<std::uint32_t> bufferOr{0xe1685000u, 0x80010003u, 0xbf810000u}; + const std::vector<std::uint32_t> bufferAnd{0xe1645000u, 0x80010003u, 0xbf810000u}; + const std::vector<std::uint32_t> bufferXor{0xe16c5000u, 0x80010003u, 0xbf810000u}; ``` - `0x31016facu` sets OOB_SELECT = 3 (raw), so the access at offset 0 of the 256-byte buffer is in bounds. - vdata `v0` instead of `v40`. The atomic needs both changes to pass. With only the first, the atomic survives, but `v40`/`v41` are never written, so the data is the constant 0. `ccp` then folds both `OpUConvert` halves to `%uint_0`, and the last `verifySplit` check fails ("do not take the low and high dwords of the operand"). `v0` is the invocation id and stays variable. | build | `agc_shader_memory` | |---|---| | SPIRV-Tools ON, head as is | fails: "...was not emitted as two 32-bit atomics" | | SPIRV-Tools ON, with the diff | passes, 3 of 3 | | SPIRV-Tools OFF, with the diff | passes, 3 of 3 | The red should be unchanged: on `main`, the first OR compile without `shaderBufferInt64Atomics` throws before `verifySplit` runs, whatever the V# and vdata are. I did not rerun that part. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
jotitadev commented 2026-10-30 23:09:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-30T23:09:33Z.

Review: COMMENTED


Re-run of head c12f979291 for the matched-run request. The SPIRV-Tools ON failure is fixed.

Linux (Ubuntu 26.04, GCC 15.2, Release), merged onto current main 7fcab08f71, and the same tests on that main alone. lavapipe (Mesa 26.0.3), ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, Khronos validation layer 1.4.341.

build main 7fcab08f71 main + c12f979291
SPIRV-Tools OFF: agc_shader_memory, the 4 agc_driver_buffer_atomics*, global_atomics64, image_atomics64 7/7, 0 VUID- 7/7 in 3 of 3 runs, 0 VUID-
SPIRV-Tools ON: agc_shader_memory passes passes, 3 of 3
SPIRV-Tools ON, c12f979291 reverted (old test) n/a fails: an unused-result bitwise buffer atomic was not emitted as two 32-bit atomics

The last row is the NVIDIA CI failure, reproduced without a GPU. The fixed test also covers the OR-with-OR and OR-with-AND programs, with v2 as the second vdata.

The NVIDIA CI has not reported on this head yet. I did not rerun the 3070, since the failure did not depend on the GPU.

GPUs tested: lavapipe (Mesa 26.0.3), Ubuntu 26.04

Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5719644620 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/11510#pullrequestreview-5719644620). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-30T23:09:33Z. **Review:** COMMENTED --- Re-run of head `c12f979291` for the matched-run request. The SPIRV-Tools ON failure is fixed. Linux (Ubuntu 26.04, GCC 15.2, Release), merged onto current `main` `7fcab08f71`, and the same tests on that `main` alone. lavapipe (Mesa 26.0.3), `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`, Khronos validation layer 1.4.341. | build | `main` `7fcab08f71` | `main` + `c12f979291` | |---|---|---| | SPIRV-Tools OFF: `agc_shader_memory`, the 4 `agc_driver_buffer_atomics*`, `global_atomics64`, `image_atomics64` | 7/7, 0 `VUID-` | 7/7 in 3 of 3 runs, 0 `VUID-` | | SPIRV-Tools ON: `agc_shader_memory` | passes | passes, 3 of 3 | | SPIRV-Tools ON, `c12f979291` reverted (old test) | n/a | fails: `an unused-result bitwise buffer atomic was not emitted as two 32-bit atomics` | The last row is the NVIDIA CI failure, reproduced without a GPU. The fixed test also covers the OR-with-OR and OR-with-AND programs, with `v2` as the second vdata. The NVIDIA CI has not reported on this head yet. I did not rerun the 3070, since the failure did not depend on the GPU. GPUs tested: lavapipe (Mesa 26.0.3), Ubuntu 26.04 Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
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!11510
No description provided.