fix(shader): scope descriptor length reuse to SPIR-V labels #7747

Merged
MarcZX10 merged 3 commits from upstream-pr/7747 into main 2026-10-23 11:43:05 +00:00
MarcZX10 commented 2026-10-19 05:55:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T05:55:01Z.


What

Reuses a storage-buffer runtime length query only when the cached definition and the next access are in the same SPIR-V label. This prevents an OpArrayLength emitted in a conditional path from being reused after its merge, where it may not dominate the access. Reads across generated labels emit separate queries. No runtime speedup is expected or claimed; this change constrains the structural reuse reported in #7138 to cases where the SPIR-V definition is valid.

Tested

Linux x86_64; agc_formatted_buffer_once passes with ANYPS5_ENABLE_SPIRV_TOOLS=OFF (structural counts) and ON (each generated shader is validated before optimization). With the original cache, the new atomic-then-read case fails SPIRV-Tools validation because an ID defined in block 274 does not dominate its use in block 405; the label-scoped cache passes. I also built and attempted agc_driver_buffer_load_store and agc_driver_stream_copy with lavapipe and Vulkan validation enabled; both abort before Vulkan initialization because this host's Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA. No game or homebrew run. GPUs tested: n/a (compile and SPIR-V validation only).

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: n/a (compile and structural test only)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4916536041 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T05:55:01Z. --- ### What Reuses a storage-buffer runtime length query only when the cached definition and the next access are in the same SPIR-V label. This prevents an OpArrayLength emitted in a conditional path from being reused after its merge, where it may not dominate the access. Reads across generated labels emit separate queries. No runtime speedup is expected or claimed; this change constrains the structural reuse reported in #7138 to cases where the SPIR-V definition is valid. ### Tested Linux x86_64; `agc_formatted_buffer_once` passes with `ANYPS5_ENABLE_SPIRV_TOOLS=OFF` (structural counts) and `ON` (each generated shader is validated before optimization). With the original cache, the new atomic-then-read case fails SPIRV-Tools validation because an ID defined in block 274 does not dominate its use in block 405; the label-scoped cache passes. I also built and attempted `agc_driver_buffer_load_store` and `agc_driver_stream_copy` with lavapipe and Vulkan validation enabled; both abort before Vulkan initialization because this host's Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA. No game or homebrew run. GPUs tested: n/a (compile and SPIR-V validation only). ### Checklist - [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: n/a (compile and structural test only) - [x] AI-assisted: yes
jotitadev commented 2026-10-19 08:12:35 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T08:12:35Z.

Review: COMMENTED


Device run of d1e172b9f, since the description has no GPU run. With this change the recompiler emits invalid SPIR-V for a set of buffer shaders, and 28 tests fail on NVIDIA (mostly segfaults) and 17 on lavapipe.

Machine: Ubuntu 26.04, i7-8700, GCC 15.2, Release, BUILD_TESTING=ON, every execution test built. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host. PR merged onto main 6b8228b2b (clean). ANYPS5_NO_SHADER_CACHE=1, -j1 --timeout 30, ^agc without display/flip/lds_atomics64 (763 tests).

RTX 3070 lavapipe
main 6b8228b2b 762/763 (agc_driver_bda_device, #7584) 763/763
this PR 734/763 746/763

agc_formatted_buffer_once passes. The new failures (largely the same set on both devices; lavapipe skips the mesh ones and adds agc_driver_oversized_dispatch) include agc_driver_buffer_load_store, agc_driver_buffer_format, agc_driver_stream_copy, agc_driver_dword_pattern_fill, agc_driver_constant_dword_fill, agc_driver_memory_value_fill, agc_driver_vertex_fetch, agc_driver_image_table, agc_driver_address_passes and the agc_driver_mesh* tests. On NVIDIA most are segfaults. On lavapipe they fail with vkCreateComputePipelines: Vulkan result -13 or abort.

The same head built with -DANYPS5_ENABLE_SPIRV_TOOLS=ON stops at the recompiler's validator in agc_driver_buffer_load_store and agc_driver_stream_copy on both devices:

SPIR-V validation before optimization failed:
ID '509[%509]' defined in block '506[%506]' does not dominate its use in block '609[%609]'

main passes both tests in that build. So a cached OpArrayLength gets reused from a SPIR-V block that doesn't dominate the later access. bufferLengths is cleared once per IR block in EmitControlFlow, but one IR block can turn into several SPIR-V blocks (the access paths branch), so the first OpArrayLength can sit in a branch that the second access doesn't pass through. The structural test only counts OpArrayLength, so it can't see this. Running the module through the validator in the test, or one of the failing execution tests above, would catch it.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5568645022 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#pullrequestreview-5568645022). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T08:12:35Z. **Review:** COMMENTED --- Device run of `d1e172b9f`, since the description has no GPU run. With this change the recompiler emits invalid SPIR-V for a set of buffer shaders, and 28 tests fail on NVIDIA (mostly segfaults) and 17 on lavapipe. **Machine:** Ubuntu 26.04, i7-8700, GCC 15.2, Release, `BUILD_TESTING=ON`, every execution test built. NVIDIA GeForce RTX 3070 (driver 595.99.02) and lavapipe (Mesa 26.0.3, LLVM 21.1.8) on the same host. PR merged onto `main` `6b8228b2b` (clean). `ANYPS5_NO_SHADER_CACHE=1`, `-j1 --timeout 30`, `^agc` without display/flip/`lds_atomics64` (763 tests). | | RTX 3070 | lavapipe | |---|---|---| | `main` `6b8228b2b` | 762/763 (`agc_driver_bda_device`, #7584) | 763/763 | | this PR | 734/763 | 746/763 | `agc_formatted_buffer_once` passes. The new failures (largely the same set on both devices; lavapipe skips the mesh ones and adds `agc_driver_oversized_dispatch`) include `agc_driver_buffer_load_store`, `agc_driver_buffer_format`, `agc_driver_stream_copy`, `agc_driver_dword_pattern_fill`, `agc_driver_constant_dword_fill`, `agc_driver_memory_value_fill`, `agc_driver_vertex_fetch`, `agc_driver_image_table`, `agc_driver_address_passes` and the `agc_driver_mesh*` tests. On NVIDIA most are segfaults. On lavapipe they fail with `vkCreateComputePipelines: Vulkan result -13` or abort. The same head built with `-DANYPS5_ENABLE_SPIRV_TOOLS=ON` stops at the recompiler's validator in `agc_driver_buffer_load_store` and `agc_driver_stream_copy` on both devices: ``` SPIR-V validation before optimization failed: ID '509[%509]' defined in block '506[%506]' does not dominate its use in block '609[%609]' ``` `main` passes both tests in that build. So a cached `OpArrayLength` gets reused from a SPIR-V block that doesn't dominate the later access. `bufferLengths` is cleared once per IR block in `EmitControlFlow`, but one IR block can turn into several SPIR-V blocks (the access paths branch), so the first `OpArrayLength` can sit in a branch that the second access doesn't pass through. The structural test only counts `OpArrayLength`, so it can't see this. Running the module through the validator in the test, or one of the failing execution tests above, would catch it. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
jotitadev commented 2026-10-19 09:00:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-19T09:00:42Z.

Review: COMMENTED


Follow-up to my NVIDIA/lavapipe run, with the Apple GPU / MoltenVK result for the same head. It breaks the same way on Metal: 15 ^agc tests start failing on both MoltenVK drivers, and in every one of them SPIRV-Cross refuses the module with SPIR-V to MSL conversion error: Cannot resolve expression type, followed by vkCreateComputePipelines / vkCreateGraphicsPipelines: Vulkan result -3. That fits the OpArrayLength that doesn't dominate its use: SPIRV-Cross can't resolve an ID used outside the block that defines it.

Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Drivers: MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0) and MoltenVK main + SPIRV-Cross #2704. Head d1e172b9f, PR diff applied cleanly, compared with the same build without it.

Tested: the tree is main a373e85e5 + mugurc's macOS series (ci/macos-series-2) + the PRs needed to build on macOS (#6667, #6668, #7524, #6969, and two files of #7332), not plain main (it doesn't build on macOS yet). Under this PR the build also had #7371, #7535, #7684, #7746, #7759 and a test-only patch that lets nine AGC fixtures load the Vulkan loader on macOS (branch jotitadev:fix/agc-tests-vulkan-loader-macos). The comparison is that same build with and without this PR.

  • agc_formatted_buffer_once passes.
  • New failures, the same 15 on both drivers: agc_driver_address_passes, agc_driver_address_passes_targets_split, agc_driver_buffer_format, agc_driver_buffer_load_store, agc_driver_buffer_resource_vcc, agc_driver_constant_dword_fill, agc_driver_depth_fast_clear_submit, agc_driver_dword_pattern_fill, agc_driver_format_d16, agc_driver_format_d16_store, agc_driver_memory_value_fill, agc_driver_pattern_buffer_fill, agc_driver_stream_copy, agc_driver_vertex_fetch, agc_driver_zero_position_vertex. The mesh tests that fail on NVIDIA don't run on Apple (no mesh shaders), and agc_driver_image_table already fails on MoltenVK for lack of descriptor indexing features.
  • No failure goes away with the PR.

GPUs tested: Apple M2 Max (MoltenVK 1.4.2; MoltenVK main + SPIRV-Cross #2704)

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5569157319 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#pullrequestreview-5569157319). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-19T09:00:42Z. **Review:** COMMENTED --- <!-- head: d1e172b9f --> Follow-up to my NVIDIA/lavapipe run, with the Apple GPU / MoltenVK result for the same head. It breaks the same way on Metal: 15 `^agc` tests start failing on both MoltenVK drivers, and in every one of them SPIRV-Cross refuses the module with `SPIR-V to MSL conversion error: Cannot resolve expression type`, followed by `vkCreateComputePipelines` / `vkCreateGraphicsPipelines: Vulkan result -3`. That fits the `OpArrayLength` that doesn't dominate its use: SPIRV-Cross can't resolve an ID used outside the block that defines it. Machine: Apple M2 Max, macOS 27.2, x86-64 build under Rosetta. Drivers: MoltenVK 1.4.2 (Vulkan SDK 1.4.363.0) and MoltenVK main + SPIRV-Cross #2704. Head d1e172b9f, PR diff applied cleanly, compared with the same build without it. **Tested:** the tree is `main` a373e85e5 + mugurc's macOS series (`ci/macos-series-2`) + the PRs needed to build on macOS (#6667, #6668, #7524, #6969, and two files of #7332), not plain `main` (it doesn't build on macOS yet). Under this PR the build also had #7371, #7535, #7684, #7746, #7759 and a test-only patch that lets nine AGC fixtures load the Vulkan loader on macOS (branch `jotitadev:fix/agc-tests-vulkan-loader-macos`). The comparison is that same build with and without this PR. - `agc_formatted_buffer_once` passes. - New failures, the same 15 on both drivers: `agc_driver_address_passes`, `agc_driver_address_passes_targets_split`, `agc_driver_buffer_format`, `agc_driver_buffer_load_store`, `agc_driver_buffer_resource_vcc`, `agc_driver_constant_dword_fill`, `agc_driver_depth_fast_clear_submit`, `agc_driver_dword_pattern_fill`, `agc_driver_format_d16`, `agc_driver_format_d16_store`, `agc_driver_memory_value_fill`, `agc_driver_pattern_buffer_fill`, `agc_driver_stream_copy`, `agc_driver_vertex_fetch`, `agc_driver_zero_position_vertex`. The mesh tests that fail on NVIDIA don't run on Apple (no mesh shaders), and `agc_driver_image_table` already fails on MoltenVK for lack of descriptor indexing features. - No failure goes away with the PR. GPUs tested: Apple M2 Max (MoltenVK 1.4.2; MoltenVK main + SPIRV-Cross #2704) Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
MarcZX10 commented 2026-10-19 16:09:11 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T16:09:11Z.


Thanks for the detailed NVIDIA, lavapipe, and MoltenVK runs. I confirmed the cache can reuse an OpArrayLength after control flow has changed blocks. The fix on current head 4792d104f6 scopes each cache lookup to its defining SPIR-V label while retaining per-IR-block lifetime. The existing agc_formatted_buffer_once_tests builds and passes on Linux (the CTest project has no registered tests, so I ran the executable directly). This environment has ANYPS5_ENABLE_SPIRV_TOOLS=OFF, so I could not run spirv-val here; hosted checks are queued.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6271656902 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#issuecomment-6271656902). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T16:09:11Z. --- Thanks for the detailed NVIDIA, lavapipe, and MoltenVK runs. I confirmed the cache can reuse an `OpArrayLength` after control flow has changed blocks. The fix on current head `4792d104f6` scopes each cache lookup to its defining SPIR-V label while retaining per-IR-block lifetime. The existing `agc_formatted_buffer_once_tests` builds and passes on Linux (the CTest project has no registered tests, so I ran the executable directly). This environment has `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`, so I could not run `spirv-val` here; hosted checks are queued.
adriadam10 commented 2026-10-19 17:23:49 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T17:23:49Z.

Review: CHANGES_REQUESTED


Thanks for the follow-up, but 4792d104f does not fix the problem jotitadev reported.

  • SpirvRuntimeBuffer.cpp:149: the added entry.length != 0u is always true (AllocateId() never returns 0), so the lookup is unchanged. The entry still has no SPIR-V label, and the if (access.length == 0u) fallback at :157 is dead code.
  • directAccess is called from inside conditional regions (e.g. :826, within EmitValueOrDefaultIfCondition) as well as outside them (:761), and one IR block spans several SPIR-V labels. An OpArrayLength emitted inside such a region is then reused after the merge, where it does not dominate its use. That is the invalid SPIR-V (Cannot resolve expression type in SPIRV-Cross, crashes on NVIDIA) from the earlier reports.
  • To fix it, store state.currentLabel in the entry and match on it, or drop entries whenever a label is emitted (a reuse is only valid if the defining label dominates the current one; same label is the simple safe case).
  • The test only covers straight-line scalar reads (one label). Please add a case where the first access is inside a conditional (formatted/atomic buffer op in a branch) and a second one follows after the merge, and run it with ANYPS5_ENABLE_SPIRV_TOOLS=ON so spirv-val checks the module.
  • Please state the speedup or say it is not expected: #7138 is about frame time, and the description only claims structure.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5575214885 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#pullrequestreview-5575214885). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-19T17:23:49Z. **Review:** CHANGES_REQUESTED --- Thanks for the follow-up, but 4792d104f does not fix the problem jotitadev reported. - `SpirvRuntimeBuffer.cpp:149`: the added `entry.length != 0u` is always true (`AllocateId()` never returns 0), so the lookup is unchanged. The entry still has no SPIR-V label, and the `if (access.length == 0u)` fallback at `:157` is dead code. - `directAccess` is called from inside conditional regions (e.g. `:826`, within `EmitValueOrDefaultIfCondition`) as well as outside them (`:761`), and one IR block spans several SPIR-V labels. An `OpArrayLength` emitted inside such a region is then reused after the merge, where it does not dominate its use. That is the invalid SPIR-V (`Cannot resolve expression type` in SPIRV-Cross, crashes on NVIDIA) from the earlier reports. - To fix it, store `state.currentLabel` in the entry and match on it, or drop entries whenever a label is emitted (a reuse is only valid if the defining label dominates the current one; same label is the simple safe case). - The test only covers straight-line scalar reads (one label). Please add a case where the first access is inside a conditional (formatted/atomic buffer op in a branch) and a second one follows after the merge, and run it with `ANYPS5_ENABLE_SPIRV_TOOLS=ON` so spirv-val checks the module. - Please state the speedup or say it is not expected: #7138 is about frame time, and the description only claims structure.
MarcZX10 commented 2026-10-19 18:01:38 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T18:01:38Z.


I tested the suggested strict state.currentLabel cache key locally. It avoids reusing a value across labels, but it makes the existing three-read scalar-buffer regression emit three OpArrayLength instructions instead of one, so the PR’s current reuse behavior disappears on this path. I reverted the experiment and have not pushed it. Would you prefer a correctness-only label-scoped change with the test and PR claim updated, or should I investigate a dominance-aware cache that preserves reuse when the definition dominates the later access?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6273806924 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#issuecomment-6273806924). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T18:01:38Z. --- I tested the suggested strict state.currentLabel cache key locally. It avoids reusing a value across labels, but it makes the existing three-read scalar-buffer regression emit three OpArrayLength instructions instead of one, so the PR’s current reuse behavior disappears on this path. I reverted the experiment and have not pushed it. Would you prefer a correctness-only label-scoped change with the test and PR claim updated, or should I investigate a dominance-aware cache that preserves reuse when the definition dominates the later access?
MarcZX10 commented 2026-10-19 18:20:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T18:20:22Z.


Implemented in two commits: 43ca2784 adds the regression and 87300c7 scopes cached lengths to their defining SPIR-V label.

With ANYPS5_ENABLE_SPIRV_TOOLS=ON, the atomic-then-read fixture fails on the original cache with the same dominance validation error reported above (an ID defined in block 274 does not dominate block 405), and passes with the fix. The focused CTest passes with SPIRV-Tools both ON and OFF. With Tools OFF, the structural assertions confirm that queries are not reused across generated labels. The PR title and description now state that no runtime speedup is expected.

python3 tools/check_conventions.py --base upstream/main passes. I did not run a game or GPU test.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274170452 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#issuecomment-6274170452). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T18:20:22Z. --- Implemented in two commits: `43ca2784` adds the regression and `87300c7` scopes cached lengths to their defining SPIR-V label. With `ANYPS5_ENABLE_SPIRV_TOOLS=ON`, the atomic-then-read fixture fails on the original cache with the same dominance validation error reported above (an ID defined in block 274 does not dominate block 405), and passes with the fix. The focused CTest passes with SPIRV-Tools both ON and OFF. With Tools OFF, the structural assertions confirm that queries are not reused across generated labels. The PR title and description now state that no runtime speedup is expected. `python3 tools/check_conventions.py --base upstream/main` passes. I did not run a game or GPU test.
MarcZX10 commented 2026-10-19 18:25:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T18:25:15Z.


I installed the Khronos validation layer and built the two runtime tests named in the review. I attempted both on lavapipe with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. Both abort before Vulkan initialization: this host's Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA, which the test harness requires to run the guest instructions. No Vulkan VUID comparison is possible here. I added this limitation to the PR description; the dedicated SPIRV-Tools regression still passes with validation enabled.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6274260815 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#issuecomment-6274260815). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T18:25:15Z. --- I installed the Khronos validation layer and built the two runtime tests named in the review. I attempted both on lavapipe with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`. Both abort before Vulkan initialization: this host's Xeon E5-1620 v2 lacks LZCNT, BMI1, BMI2, MOVBE, AVX2 and FMA, which the test harness requires to run the guest instructions. No Vulkan VUID comparison is possible here. I added this limitation to the PR description; the dedicated SPIRV-Tools regression still passes with validation enabled.
MarcZX10 commented 2026-10-19 20:24:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-19T20:24:05Z.


Thanks for the careful review. The current head 87300c7cb now stores state.currentLabel in each buffer-length cache entry and only reuses an OpArrayLength when the defining label matches the current label. This is the same-label safe case you suggested; it intentionally gives up reuse across generated labels while retaining reuse within one label. The regression added in 43ca2784b emits a buffer query in the 64-bit atomic path and reads the buffer after its merge. I reran agc_formatted_buffer_once locally with ANYPS5_ENABLE_SPIRV_TOOLS=ON; CTest passes (1/1), so the module is validated by SPIRV-Tools. The executable also reports the structural checks passing, and python3 tools/check_conventions.py --base upstream/main passes. I have not rerun the full GPU suite on this host.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6276530833 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#issuecomment-6276530833). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-19T20:24:05Z. --- Thanks for the careful review. The current head `87300c7cb` now stores `state.currentLabel` in each buffer-length cache entry and only reuses an `OpArrayLength` when the defining label matches the current label. This is the same-label safe case you suggested; it intentionally gives up reuse across generated labels while retaining reuse within one label. The regression added in `43ca2784b` emits a buffer query in the 64-bit atomic path and reads the buffer after its merge. I reran `agc_formatted_buffer_once` locally with `ANYPS5_ENABLE_SPIRV_TOOLS=ON`; CTest passes (1/1), so the module is validated by SPIRV-Tools. The executable also reports the structural checks passing, and `python3 tools/check_conventions.py --base upstream/main` passes. I have not rerun the full GPU suite on this host.
MarcZX10 commented 2026-10-20 07:56:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T07:56:58Z.


The current head 87300c7cb259bfa69d36ad768ee5394b55e776da addresses the label/dominance concern: the cache key now includes state.currentLabel, so an OpArrayLength is reused only within the label where it was defined. The added FormattedBufferOnce regression compiles a 64-bit buffer atomic followed by a buffer read, asserts the post-merge read emits a new array-length query, and passes the focused CTest with ANYPS5_ENABLE_SPIRV_TOOLS=ON; the validator checks the generated module for dominance errors. The correctness-only behavior and no-speedup claim are stated in the PR description.

The NVIDIA, lavapipe and MoltenVK failures in the earlier reports were against d1e172b9f or 4792d104f, before this fix. My Xeon host cannot run the AGC execution tests past its CPU feature guard, so I cannot provide the requested current-head driver matrix. Could you rerun the affected buffer tests against 87300c7cb and current main and reassess the change request?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6286235400 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#issuecomment-6286235400). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T07:56:58Z. --- The current head `87300c7cb259bfa69d36ad768ee5394b55e776da` addresses the label/dominance concern: the cache key now includes `state.currentLabel`, so an `OpArrayLength` is reused only within the label where it was defined. The added `FormattedBufferOnce` regression compiles a 64-bit buffer atomic followed by a buffer read, asserts the post-merge read emits a new array-length query, and passes the focused CTest with `ANYPS5_ENABLE_SPIRV_TOOLS=ON`; the validator checks the generated module for dominance errors. The correctness-only behavior and no-speedup claim are stated in the PR description. The NVIDIA, lavapipe and MoltenVK failures in the earlier reports were against `d1e172b9f` or `4792d104f`, before this fix. My Xeon host cannot run the AGC execution tests past its CPU feature guard, so I cannot provide the requested current-head driver matrix. Could you rerun the affected buffer tests against `87300c7cb` and current `main` and reassess the change request?
MarcZX10 commented 2026-10-20 09:03:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T09:03:42Z.


Current-head verification for 87300c7cb259bfa69d36ad768ee5394b55e776da: ANYPS5_ENABLE_SPIRV_TOOLS=ON is set in the build configuration, ninja -C build-scalar agc_formatted_buffer_once_tests reports no work to do, and ctest --test-dir build-scalar -R '^agc_formatted_buffer_once$' --output-on-failure passes 1/1 (2.66 s). This is the focused dominance regression and SPIRV-Tools validates the generated module. The unrelated runtime Vulkan tests remain unrun here because the host CPU guard stops before Vulkan initialization.

The current PR description now states that reuse is label-scoped and no runtime speedup is expected. Could you re-review this exact head and update the review state if the requested correctness and test changes address your findings?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6287420570 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#issuecomment-6287420570). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T09:03:42Z. --- Current-head verification for `87300c7cb259bfa69d36ad768ee5394b55e776da`: `ANYPS5_ENABLE_SPIRV_TOOLS=ON` is set in the build configuration, `ninja -C build-scalar agc_formatted_buffer_once_tests` reports no work to do, and `ctest --test-dir build-scalar -R '^agc_formatted_buffer_once$' --output-on-failure` passes 1/1 (2.66 s). This is the focused dominance regression and SPIRV-Tools validates the generated module. The unrelated runtime Vulkan tests remain unrun here because the host CPU guard stops before Vulkan initialization. The current PR description now states that reuse is label-scoped and no runtime speedup is expected. Could you re-review this exact head and update the review state if the requested correctness and test changes address your findings?
MarcZX10 commented 2026-10-20 10:31:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-20T10:31:05Z.


I reran the focused dominance regression on the exact PR head 87300c7cb259bfa69d36ad768ee5394b55e776da. The existing Release build has ANYPS5_ENABLE_SPIRV_TOOLS=ON; ninja -C build-scalar agc_formatted_buffer_once_tests reports no work, and ctest --test-dir build-scalar -R "^agc_formatted_buffer_once$" --output-on-failure passes 1/1 (2.64 s). This validates the generated SPIR-V in the atomic-then-read case; it is not a Vulkan driver-suite run. The earlier GPU failures were reported on pre-fix heads. @adriadam10, could you reassess the label-dominance finding against this exact-head regression?

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6288898348 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#issuecomment-6288898348). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-20T10:31:05Z. --- I reran the focused dominance regression on the exact PR head `87300c7cb259bfa69d36ad768ee5394b55e776da`. The existing Release build has `ANYPS5_ENABLE_SPIRV_TOOLS=ON`; `ninja -C build-scalar agc_formatted_buffer_once_tests` reports no work, and `ctest --test-dir build-scalar -R "^agc_formatted_buffer_once$" --output-on-failure` passes 1/1 (2.64 s). This validates the generated SPIR-V in the atomic-then-read case; it is not a Vulkan driver-suite run. The earlier GPU failures were reported on pre-fix heads. @adriadam10, could you reassess the label-dominance finding against this exact-head regression?
jotitadev commented 2026-10-22 01:30:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by jotitadev on 2026-10-22T01:30:48Z.

Review: COMMENTED


Re-ran this after the rework to label-scoped reuse (head 87300c7cb). The ^agc suite regression I reported on d1e172b9f (28 failures on NVIDIA, 17 on lavapipe, and the MoltenVK Cannot resolve expression type from the OpArrayLength that didn't dominate its use) is gone: the guarded suite is back to main on both devices.

Tested

Ubuntu 26.04, GCC 15.2.0, Release, BUILD_TESTING=ON, ANYPS5_NO_SHADER_CACHE=1 and ANYPS5_REQUIRE_VULKAN=1, device selected with VK_ICD_FILENAMES, ctest -R "^agc" without display/flip/lds_atomics64, -j1 --timeout 30, on main a6dcea927 (this PR applies cleanly on it; head 87300c7cb). Build has ANYPS5_ENABLE_SPIRV_TOOLS=OFF, so agc_formatted_buffer_once runs its structural-count branch.

NVIDIA RTX 3070 (595.99.02) lavapipe (Mesa 26.0.3, LLVM 21.1.8)
main a6dcea927 858/861 860/861
this PR 87300c7cb 858/861 860/861

Same counts on both: the only failures left are the ones main already has here (sample_order family on NVIDIA, multisample_retirement on lavapipe), none of them this PR's. No segfaults, no pipeline-creation failures. agc_formatted_buffer_once passes on both.

One note on the structural test: with the three SPIR-V backend files reverted to current main and the new test kept, agc_formatted_buffer_once still passes, so against today's main it does not reproduce the earlier counting difference the way it did against the older base — the headline for me here is the suite being clean again rather than a red→green of that test.

GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04.

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

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5608236623 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#pullrequestreview-5608236623). Originally posted by [jotitadev](https://github.com/jotitadev) on 2026-10-22T01:30:48Z. **Review:** COMMENTED --- Re-ran this after the rework to `label`-scoped reuse (head `87300c7cb`). The `^agc` suite regression I reported on `d1e172b9f` (28 failures on NVIDIA, 17 on lavapipe, and the MoltenVK `Cannot resolve expression type` from the `OpArrayLength` that didn't dominate its use) is **gone**: the guarded suite is back to `main` on both devices. ### Tested Ubuntu 26.04, GCC 15.2.0, Release, `BUILD_TESTING=ON`, `ANYPS5_NO_SHADER_CACHE=1` and `ANYPS5_REQUIRE_VULKAN=1`, device selected with `VK_ICD_FILENAMES`, `ctest -R "^agc"` without display/flip/`lds_atomics64`, `-j1 --timeout 30`, on `main` `a6dcea927` (this PR applies cleanly on it; head `87300c7cb`). Build has `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`, so `agc_formatted_buffer_once` runs its structural-count branch. | | NVIDIA RTX 3070 (595.99.02) | lavapipe (Mesa 26.0.3, LLVM 21.1.8) | |---|---|---| | `main` `a6dcea927` | 858/861 | 860/861 | | this PR `87300c7cb` | 858/861 | 860/861 | Same counts on both: the only failures left are the ones `main` already has here (`sample_order` family on NVIDIA, `multisample_retirement` on lavapipe), none of them this PR's. No segfaults, no pipeline-creation failures. `agc_formatted_buffer_once` passes on both. One note on the structural test: with the three SPIR-V backend files reverted to current `main` and the new test kept, `agc_formatted_buffer_once` still passes, so against today's `main` it does not reproduce the earlier counting difference the way it did against the older base — the headline for me here is the suite being clean again rather than a red→green of that test. GPUs tested: NVIDIA GeForce RTX 3070 (595.99.02, Linux) and lavapipe (Mesa 26.0.3, LLVM 21.1.8), Ubuntu 26.04. Written with AI assistance (Claude Code). I ran the builds and tests above on my machine.
Dextroid17 commented 2026-10-22 02:14:02 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-22T02:14:02Z.


Device run of 87300c7cb on lavapipe, since the rerun against 87300c7cb and current main that @MarcZX10 asked for on 10-20 had not happened yet (the 10-19 device failures were all against d1e172b9f).

Setup: main at a6dcea927 + this PR (merge 6bb3e5c6e); CI's Linux configure line (-DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON, gcc 16.2.1, no ccache); i9-11900K, llvmpipe from Mesa 26.2.4 (LLVM 23.1.1, 256 bits) via VK_ICD_FILENAMES; scrubbed env (env -i) with ANYPS5_NO_SHADER_CACHE=1; @jotitadev's 10-19 filter: ctest -R '^agc' -E 'display|flip|lds_atomics64' -j1 --timeout 30 → 869 tests.

Results (same 869 tests, same host, both arms):

  • PR head: 810 passed, 2 failed, 57 skipped.
  • Control (the three SpirvBackend files reset to a6dcea927, PR test and CMake kept, rebuilt): 809 passed, 3 failed, 57 skipped. Identical skip set.
  • Every test jotitadev listed on 10-19 passes on both arms: agc_driver_buffer_load_store, agc_driver_buffer_format, agc_driver_stream_copy, agc_driver_dword_pattern_fill, agc_driver_constant_dword_fill, agc_driver_memory_value_fill, agc_driver_vertex_fetch, agc_driver_image_table, agc_driver_address_passes, agc_driver_oversized_dispatch, and the MoltenVK set (agc_driver_address_passes_targets_split, agc_driver_buffer_resource_vcc, agc_driver_depth_fast_clear_submit, agc_driver_format_d16, agc_driver_format_d16_store, agc_driver_pattern_buffer_fill, agc_driver_zero_position_vertex). The agc_driver_mesh* tests are skipped on lavapipe here, as in jotitadev's run.
  • The 2 failures common to both arms are agc_driver_multisample_retirement ("MSAA storage promotion did not retain its source image") and agc_compute_pipeline_replay ("replay did not export a pipeline cache header"). Both fail with the same message on both arms, so they are not from this PR. I have not checked them on another driver or host.
  • The one extra failure in the control arm, agc_driver_sgpr_pattern_fill_keys ("the dispatch completed 17 times without a pending write over the keys"), is a timing flake on this host, not an arm difference: rerun alone 10× per arm it passed 5/10 on the PR build and 6/10 on the control build. Its code path does not touch the buffer-length emitter.
  • No does not dominate or any other spirv-val message appears in either ctest log (SPIRV-Tools validation was on for every generated shader).

One note on the regression test. agc_formatted_buffer_once passes with the three source files at a6dcea927 too (3/3 with ANYPS5_ENABLE_SPIRV_TOOLS=ON and 3/3 with it OFF), because main at a6dcea927 has no bufferLengths cache at all: each access emits its own OpArrayLength (core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:146 on main). The "fails on the original cache" result in the description is against this PR's earlier revision, not against main, so the new atomic-then-read case guards the label-scoped cache this PR adds rather than catching a bug main has today. That matches what the PR now claims (correctness-only, label-scoped reuse); noting it so the test is not read as a main repro.

Logs: ctest-head.log, ctest-main.log (869 tests each) and the 20 sgpr rerun logs attached on request.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6331042334 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/7747#issuecomment-6331042334). Originally posted by [Dextroid17](https://github.com/Dextroid17) on 2026-10-22T02:14:02Z. --- Device run of `87300c7cb` on lavapipe, since the rerun against `87300c7cb` and current `main` that @MarcZX10 asked for on 10-20 had not happened yet (the 10-19 device failures were all against `d1e172b9f`). **Setup:** `main` at `a6dcea927` + this PR (merge `6bb3e5c6e`); CI's Linux configure line (`-DCMAKE_BUILD_TYPE=Release -DBUILD_TESTING=ON -DANYPS5_ENABLE_SPIRV_TOOLS=ON`, gcc 16.2.1, no ccache); i9-11900K, llvmpipe from Mesa 26.2.4 (LLVM 23.1.1, 256 bits) via `VK_ICD_FILENAMES`; scrubbed env (`env -i`) with `ANYPS5_NO_SHADER_CACHE=1`; @jotitadev's 10-19 filter: `ctest -R '^agc' -E 'display|flip|lds_atomics64' -j1 --timeout 30` → 869 tests. **Results (same 869 tests, same host, both arms):** - PR head: 810 passed, 2 failed, 57 skipped. - Control (the three `SpirvBackend` files reset to `a6dcea927`, PR test and CMake kept, rebuilt): 809 passed, 3 failed, 57 skipped. Identical skip set. - Every test jotitadev listed on 10-19 passes on both arms: `agc_driver_buffer_load_store`, `agc_driver_buffer_format`, `agc_driver_stream_copy`, `agc_driver_dword_pattern_fill`, `agc_driver_constant_dword_fill`, `agc_driver_memory_value_fill`, `agc_driver_vertex_fetch`, `agc_driver_image_table`, `agc_driver_address_passes`, `agc_driver_oversized_dispatch`, and the MoltenVK set (`agc_driver_address_passes_targets_split`, `agc_driver_buffer_resource_vcc`, `agc_driver_depth_fast_clear_submit`, `agc_driver_format_d16`, `agc_driver_format_d16_store`, `agc_driver_pattern_buffer_fill`, `agc_driver_zero_position_vertex`). The `agc_driver_mesh*` tests are skipped on lavapipe here, as in jotitadev's run. - The 2 failures common to both arms are `agc_driver_multisample_retirement` ("MSAA storage promotion did not retain its source image") and `agc_compute_pipeline_replay` ("replay did not export a pipeline cache header"). Both fail with the same message on both arms, so they are not from this PR. I have not checked them on another driver or host. - The one extra failure in the control arm, `agc_driver_sgpr_pattern_fill_keys` ("the dispatch completed 17 times without a pending write over the keys"), is a timing flake on this host, not an arm difference: rerun alone 10× per arm it passed 5/10 on the PR build and 6/10 on the control build. Its code path does not touch the buffer-length emitter. - No `does not dominate` or any other spirv-val message appears in either ctest log (SPIRV-Tools validation was on for every generated shader). **One note on the regression test.** `agc_formatted_buffer_once` passes with the three source files at `a6dcea927` too (3/3 with `ANYPS5_ENABLE_SPIRV_TOOLS=ON` and 3/3 with it `OFF`), because `main` at `a6dcea927` has no `bufferLengths` cache at all: each access emits its own `OpArrayLength` (`core/shader/recompiler/SpirvBackend/src/SpirvRuntimeBuffer.cpp:146` on `main`). The "fails on the original cache" result in the description is against this PR's earlier revision, not against `main`, so the new atomic-then-read case guards the label-scoped cache this PR adds rather than catching a bug `main` has today. That matches what the PR now claims (correctness-only, label-scoped reuse); noting it so the test is not read as a `main` repro. Logs: `ctest-head.log`, `ctest-main.log` (869 tests each) and the 20 `sgpr` rerun logs attached on request. AI-assisted: yes
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!7747
No description provided.