shader: bound storage buffers by their exact descriptor range #1603

Closed
github-bot wants to merge 2 commits from gh-pr/1603/head into gh-pr/1603/base
Owner

@⁠Nawid3333 on GitHub · 2026-10-17 15:53 UTC · original
Nawid3333:shader/exact-buffer-ranges → main · +101 −34 · 8 files · 2 commits · closed without merging

Fixes #1595 (option 1 there).

PrepareStorageBufferResourceAccess bounded every storage-buffer access by OpArrayLength. On my RX 9070 XT (LLPC) and Ryzen 7600X iGPU (AMD's other compiler), that length is wrong in two ways, shown in #1595: it counts the descriptor range rounded up to a multiple of 4 bytes, and with a non-uniform descriptor index every lane gets the first active lane's length.

Change: RebindBuffers writes each storage buffer's descriptor range in bytes (the VkDescriptorBufferInfo range) into the shader data after the packed byte offsets (Bindings::MemoryRangeDword()). The shader loads it at entry next to the byte offset for static slots, or per access with the same non-uniform index as the byte offset, and shifts it to the view's element size. That is the value OpArrayLength should return, so hosts where it is right see the same bounds. The only OpArrayLength left is the GDS one (an emulator-owned binding that is never indexed non-uniformly). Null descriptors keep their 16-byte range.

Cost: one more shader-data dword per storage buffer. A stage whose shader data no longer fits in the 128-byte push block uses the existing shader-data buffer.

Second commit (after NeySlim's RADV report below): for a GPU-selected buffer whose candidates share one descriptor array, the slot's byte offset (on main already) and now its range are read with a per-lane index. Vulkan requires push-constant arrays to be indexed with dynamically uniform indices (Push Constant Interface, VUID-RuntimeSpirv-None-04745), and RADV up to Mesa 26.2 reads them once per wave, from the first active lane; with a first lane that has no match, that read went far outside the push constants (GPU fault). Such shaders now keep their shader data in the shader-data storage buffer, where a per-lane index is allowed. Bindings::PushDataStartFor applies the same placement in the emitter and when the pipeline cache looks for a compiled permutation, and the emitter exits if a per-lane slot read would still use push constants.

Tests

  • On both GPUs, in both subgroup modes (native and the harness forced to 32-wide, a local switch), compared with 6aa3846f: 38 compute-suite entries go from fail to pass (the 36 multi-lane BufferStoreFormatD16HiX* / BufferStoreFormatD16Xyzw* cases, BufferUshortHostOffsetFirst, IndirectBufferStore); the other 686 entries and the 30 graphics cases keep their status. The named cases give no validation-layer messages. With OpArrayLength restored (a local mutant), all five named cases fail again in every configuration.
  • The test harness writes the ranges like RebindBuffers and requires the shader data to have ShaderDataDwords() dwords; IndirectBufferStore forbids OpArrayLength; the RenderExecutor halfword-tail check also checks the range dword (14).
  • shader_cfg_tests (not run by CI): four checks used OpArrayLength as the bound; they now look for the range load that feeds the OpULessThan (SpirvBufferRangeBoundPosition), with the same ordering checks. It passes.
  • Two standalone checks of the full run, BoundedRecordBufferAccess32 and GpuSelectedRecordBufferAccess32, also go from fail to pass on both GPUs (they write two words past the end on main, as NeySlim saw on RADV).
  • Second commit: on both GPUs and both modes, compared with the first commit, the 807 compute-suite entries (now including every standalone check of the full run) and the 30 graphics cases keep their status, except IndirectBufferStore, which now also requires the shader data in the storage buffer for the shared layouts and in push constants for the others (it fails without the commit). The named cases give no validation-layer messages, and shader_cfg_tests passes.
  • CI (build and tests on Windows, Linux and macOS) passes on 1bfcb063, this PR's head; CodeRabbit has no comments on the second commit.

If you'd like this done differently, tell me and I'll change it.

Written with Claude Code (AI): it wrote the change and ran the tests and measurements on my PC (driver 26.8.1, Windows 11).

🤖 Generated with Claude Code

**@⁠Nawid3333** on GitHub · 2026-10-17 15:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603) `Nawid3333:shader/exact-buffer-ranges` → `main` · +101 −34 · 8 files · 2 commits · closed without merging Fixes #1595 (option 1 there). `PrepareStorageBufferResourceAccess` bounded every storage-buffer access by `OpArrayLength`. On my RX 9070 XT (LLPC) and Ryzen 7600X iGPU (AMD's other compiler), that length is wrong in two ways, shown in #1595: it counts the descriptor range rounded up to a multiple of 4 bytes, and with a non-uniform descriptor index every lane gets the first active lane's length. **Change:** `RebindBuffers` writes each storage buffer's descriptor range in bytes (the `VkDescriptorBufferInfo` range) into the shader data after the packed byte offsets (`Bindings::MemoryRangeDword()`). The shader loads it at entry next to the byte offset for static slots, or per access with the same non-uniform index as the byte offset, and shifts it to the view's element size. That is the value `OpArrayLength` should return, so hosts where it is right see the same bounds. The only `OpArrayLength` left is the GDS one (an emulator-owned binding that is never indexed non-uniformly). Null descriptors keep their 16-byte range. Cost: one more shader-data dword per storage buffer. A stage whose shader data no longer fits in the 128-byte push block uses the existing shader-data buffer. **Second commit (after NeySlim's RADV report below):** for a GPU-selected buffer whose candidates share one descriptor array, the slot's byte offset (on main already) and now its range are read with a per-lane index. Vulkan requires push-constant arrays to be indexed with dynamically uniform indices (Push Constant Interface, VUID-RuntimeSpirv-None-04745), and RADV up to Mesa 26.2 reads them once per wave, from the first active lane; with a first lane that has no match, that read went far outside the push constants (GPU fault). Such shaders now keep their shader data in the shader-data storage buffer, where a per-lane index is allowed. `Bindings::PushDataStartFor` applies the same placement in the emitter and when the pipeline cache looks for a compiled permutation, and the emitter exits if a per-lane slot read would still use push constants. **Tests** - On both GPUs, in both subgroup modes (native and the harness forced to 32-wide, a local switch), compared with 6aa3846f: 38 compute-suite entries go from fail to pass (the 36 multi-lane `BufferStoreFormatD16HiX*` / `BufferStoreFormatD16Xyzw*` cases, `BufferUshortHostOffsetFirst`, `IndirectBufferStore`); the other 686 entries and the 30 graphics cases keep their status. The named cases give no validation-layer messages. With `OpArrayLength` restored (a local mutant), all five named cases fail again in every configuration. - The test harness writes the ranges like `RebindBuffers` and requires the shader data to have `ShaderDataDwords()` dwords; `IndirectBufferStore` forbids `OpArrayLength`; the RenderExecutor halfword-tail check also checks the range dword (14). - `shader_cfg_tests` (not run by CI): four checks used `OpArrayLength` as the bound; they now look for the range load that feeds the `OpULessThan` (`SpirvBufferRangeBoundPosition`), with the same ordering checks. It passes. - Two standalone checks of the full run, `BoundedRecordBufferAccess32` and `GpuSelectedRecordBufferAccess32`, also go from fail to pass on both GPUs (they write two words past the end on main, as NeySlim saw on RADV). - Second commit: on both GPUs and both modes, compared with the first commit, the 807 compute-suite entries (now including every standalone check of the full run) and the 30 graphics cases keep their status, except `IndirectBufferStore`, which now also requires the shader data in the storage buffer for the shared layouts and in push constants for the others (it fails without the commit). The named cases give no validation-layer messages, and `shader_cfg_tests` passes. - CI (build and tests on Windows, Linux and macOS) passes on 1bfcb063, this PR's head; CodeRabbit has no comments on the second commit. If you'd like this done differently, tell me and I'll change it. Written with Claude Code (AI): it wrote the change and ran the tests and measurements on my PC (driver 26.8.1, Windows 11). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
OpArrayLength rounds the descriptor range up to 4 bytes on AMD, and for a
NonUniform descriptor index it gives every lane the first active lane's
length. Store each storage buffer's range in the shader data after the
packed byte offsets and bound accesses by it.

Fixes #1595.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A GPU-selected storage buffer whose candidates share one descriptor array reads the selected
slot's byte offset and range from the shader data with a per-lane index. Vulkan requires
push-constant arrays to be indexed with dynamically uniform indices, and RADV (Mesa 26.2)
reads every lane's value from the first active lane. Such shaders now keep their shader
data in the storage buffer, and the pipeline cache applies the same placement when it looks
for a compiled permutation.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:01:30 +00:00
github-bot closed this pull request 2026-11-26 10:01:33 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-17 16:02 UTC · original · edited 2026-10-18 04:15 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0064a7db-221e-4b80-85ab-ddab79300eef
📥 Commits

Reviewing files that changed from the base of the PR and between 3b4a6b8deb and 1bfcb063b7.

📒 Files selected for processing: 5
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

📝 Walkthrough

The change adds a per-buffer descriptor range to shader data. SPIR-V generation uses the range to bound storage-buffer accesses instead of using OpArrayLength. Shader-data layout and push-data placement account for lane-indexed data. Tests cover range packing, shader-data sizing, generated bounds checks, and indirect-store pointer handling.

Suggested reviewers: nmzik

Priority: ⬆️ High

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 1bfcb

No confirmed issue remains that needs to be fixed before merge; proceed with normal checks.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Linked Issues check Passed Issue #1595 requires exact storage-buffer bounds in shader code. The current head writes each descriptor range to shader data after the packed offsets. PrepareStorageBufferResourceAccess uses that r…
Out of Scope Changes check Passed The changes stay within issue #1595. Descriptor rebinding supplies the exact range. Shader layout, pipeline permutation selection, and lane-indexed placement support delivery of that range. The comput…
Title check Passed The title clearly and concisely describes the main change: storage buffers are bounded by their exact descriptor range.
Description check Passed The description directly explains the descriptor-range bounds change, the handling of non-uniform indices, shader-data placement, tests, and related issue context.
Full details: Linked Issues check

Explanation

Issue #1595 requires exact storage-buffer bounds in shader code. The current head writes each descriptor range to shader data after the packed offsets. PrepareStorageBufferResourceAccess uses that range for uniform access and loads the range with the same non-uniform index as the byte offset. It shifts the byte range to the view element size and no longer uses OpArrayLength for storage buffers. Lane-indexed data avoids push constants and uses the existing shader-data buffer path. The updated tests check shader-data size, range values, range-based guards, and the absence of OpArrayLength in IndirectBufferStore.

Full details: Out of Scope Changes check

Explanation

The changes stay within issue #1595. Descriptor rebinding supplies the exact range. Shader layout, pipeline permutation selection, and lane-indexed placement support delivery of that range. The compute and shader-configuration test changes verify the new bounds and layout. No unrelated change is demonstrated.

Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-17 16:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#issuecomment-6236273904) · edited 2026-10-18 04:15 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1603?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `0064a7db-221e-4b80-85ab-ddab79300eef` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 3b4a6b8debdb316164a24c57d5bc84e9ca0381c6 and 1bfcb063b7ded91a6c352149fa082eb974c84b91. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 5</strong></summary> <dl> <dd> * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp` * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The change adds a per-buffer descriptor range to shader data. SPIR-V generation uses the range to bound storage-buffer accesses instead of using `OpArrayLength`. Shader-data layout and push-data placement account for lane-indexed data. Tests cover range packing, shader-data sizing, generated bounds checks, and indirect-store pointer handling. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬆️ High <!-- change_assessment_commit:"1bfcb063b7ded91a6c352149fa082eb974c84b91" --> **Change:** Bug fix · **Severity of issue fixed:** Medium <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>1bfcb</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `1bfcb` --> <!-- final_review_risk_coverage:{"sourceCommitId":"1bfcb063b7ded91a6c352149fa082eb974c84b91","coveredCommitId":"1bfcb063b7ded91a6c352149fa082eb974c84b91","kind":"reviewed"} --> No confirmed issue remains that needs to be fixed before merge; proceed with normal checks. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. (1 skipped: 1 … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Issue `#1595` requires exact storage-buffer bounds in shader code. The current head writes each descriptor range to shader data after the packed offsets. `PrepareStorageBufferResourceAccess` uses that r… | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The changes stay within issue `#1595`. Descriptor rebinding supplies the exact range. Shader layout, pipeline permutation selection, and lane-indexed placement support delivery of that range. The comput… | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: storage buffers are bounded by their exact descriptor range. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description directly explains the descriptor-range bounds change, the handling of non-uniform indices, shader-data placement, tests, and related issue context. | <details> <summary><strong>Full details: Linked Issues check</strong></summary> <dl> <dd> **Explanation** Issue `#1595` requires exact storage-buffer bounds in shader code. The current head writes each descriptor range to shader data after the packed offsets. `PrepareStorageBufferResourceAccess` uses that range for uniform access and loads the range with the same non-uniform index as the byte offset. It shifts the byte range to the view element size and no longer uses `OpArrayLength` for storage buffers. Lane-indexed data avoids push constants and uses the existing shader-data buffer path. The updated tests check shader-data size, range values, range-based guards, and the absence of `OpArrayLength` in `IndirectBufferStore`. </dd> </dl> </details> <details> <summary><strong>Full details: Out of Scope Changes check</strong></summary> <dl> <dd> **Explanation** The changes stay within issue `#1595`. Descriptor rebinding supplies the exact range. Shader layout, pipeline permutation selection, and lane-indexed placement support delivery of that range. The compute and shader-configuration test changes verify the new bounds and layout. No unrelated change is demonstrated. </dd> </dl> </details> </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 6 files. (1 skipped: 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autofix</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1603)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠NeySlim on GitHub · 2026-10-17 23:09 UTC · original

RADV data point: Radeon 8060S (RDNA 3.5), Mesa 26.2.4, against 763d3be3. Main shows the same rounding here: BufferUshortHostOffsetFirst reads back 0x0000face and the 36 multi-lane D16 store cases write the last record. With this PR those pass, and so do BoundedRecordBufferAccess32, GpuSelectedRecordBufferAccess32 and GpuSelectedFormattedRgba16Store, which also fail on main on RADV (two words past the end each); the rest of the suite is unchanged except IndirectBufferStore.

IndirectBufferStore still fails with the PR (the four Shared stores are missing) and the process then hits a GPUVM fault (SQC data) and a ring reset; on main it only mismatches. In the ISA, ACO scalarizes the per-lane push-constant reads (v_readfirstlane + s_load_b32, the byte offset on main and now the range too), and the index < 2 guard never reaches EXEC (v_cmp_gt_u32_e32 vcc_lo, 2, v3 followed by s_bitset0_b32 exec_lo, 4, on main as well). So on RADV the range comes from the first active lane, and lanes whose key has no match are no longer filtered by a per-lane length before the waterfall.

**@⁠NeySlim** on GitHub · 2026-10-17 23:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#issuecomment-6242862372) RADV data point: Radeon 8060S (RDNA 3.5), Mesa 26.2.4, against 763d3be3. Main shows the same rounding here: `BufferUshortHostOffsetFirst` reads back `0x0000face` and the 36 multi-lane D16 store cases write the last record. With this PR those pass, and so do `BoundedRecordBufferAccess32`, `GpuSelectedRecordBufferAccess32` and `GpuSelectedFormattedRgba16Store`, which also fail on main on RADV (two words past the end each); the rest of the suite is unchanged except `IndirectBufferStore`. `IndirectBufferStore` still fails with the PR (the four Shared stores are missing) and the process then hits a GPUVM fault (SQC data) and a ring reset; on main it only mismatches. In the ISA, ACO scalarizes the per-lane push-constant reads (`v_readfirstlane` + `s_load_b32`, the byte offset on main and now the range too), and the `index < 2` guard never reaches EXEC (`v_cmp_gt_u32_e32 vcc_lo, 2, v3` followed by `s_bitset0_b32 exec_lo, 4`, on main as well). So on RADV the range comes from the first active lane, and lanes whose key has no match are no longer filtered by a per-lane length before the waterfall.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-18 04:15 UTC · original

Thanks for the ISA readout, it pointed straight at the cause, and the bug is in Kyty. For a buffer whose candidates share one descriptor array, Kyty reads the selected slot's byte offset (on main) and, with this PR, also its range from the push constants, using an index that differs per lane. Vulkan only allows dynamically uniform indices into push-constant arrays (Push Constant Interface, VUID-RuntimeSpirv-None-04745), and Mesa up to 26.2 turns every push-constant load into one scalar load per wave (Mesa issue #16130, changed in 26.3). So every lane got the first lane's byte offset, and with this PR a first lane without a match (slot 0xFFFFFFFF) made that scalar load read far outside the push constants, which shows up as the SQC fault.

I pushed a second commit: shaders that pick a buffer slot per lane now keep their shader data in the storage buffer, where a per-lane index is allowed, and the pipeline cache applies the same rule when it reuses a compiled shader. IndirectBufferStore now also checks where the shader data goes. The drivers on my RX 9070 XT and Ryzen 7600X iGPU already returned per-lane values, so nothing changes there: the whole suite gives the same results with and without the commit. As on RADV, BoundedRecordBufferAccess32 and GpuSelectedRecordBufferAccess32 fail on main on both GPUs and pass with this PR.

Could you rerun IndirectBufferStore and the rest of the suite on RADV with the new head?

Written with Claude Code (AI): it traced the cause, wrote the fix and ran the tests on my PC; I read this comment before posting it.

**@⁠Nawid3333** on GitHub · 2026-10-18 04:15 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#issuecomment-6245555060) Thanks for the ISA readout, it pointed straight at the cause, and the bug is in Kyty. For a buffer whose candidates share one descriptor array, Kyty reads the selected slot's byte offset (on main) and, with this PR, also its range from the push constants, using an index that differs per lane. Vulkan only allows dynamically uniform indices into push-constant arrays (Push Constant Interface, VUID-RuntimeSpirv-None-04745), and Mesa up to 26.2 turns every push-constant load into one scalar load per wave (Mesa issue #16130, changed in 26.3). So every lane got the first lane's byte offset, and with this PR a first lane without a match (slot 0xFFFFFFFF) made that scalar load read far outside the push constants, which shows up as the SQC fault. I pushed a second commit: shaders that pick a buffer slot per lane now keep their shader data in the storage buffer, where a per-lane index is allowed, and the pipeline cache applies the same rule when it reuses a compiled shader. `IndirectBufferStore` now also checks where the shader data goes. The drivers on my RX 9070 XT and Ryzen 7600X iGPU already returned per-lane values, so nothing changes there: the whole suite gives the same results with and without the commit. As on RADV, `BoundedRecordBufferAccess32` and `GpuSelectedRecordBufferAccess32` fail on main on both GPUs and pass with this PR. Could you rerun `IndirectBufferStore` and the rest of the suite on RADV with the new head? Written with Claude Code (AI): it traced the cause, wrote the fix and ran the tests on my PC; I read this comment before posting it.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-18 10:53 UTC · original

Reran on RADV (Radeon 8060S, Mesa 26.2.4) with the new head merged on 37df7f32, one case per process. The same 40 cases go from failing to passing and nothing else in the suite changes, but IndirectBufferStore still fails (the four Shared stores are missing) and still ends in a GPUVM fault (SQC data, same address) and a gfx ring reset. The second commit does what it says: the slot offset and range are now per-lane buffer_load_b32 ... offen instead of v_readfirstlane + s_load_b32. What is left is the index < 2 guard that never reaches EXEC (v_cmp_gt_u32_e32 vcc_lo, 2, v3 followed by s_bitset0_b32 exec_lo, 4, same on main), so lanes with no matching key (slot -1) still enter the waterfall and load a descriptor at set + 0xfffffff0.

**@⁠NeySlim** on GitHub · 2026-10-18 10:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#issuecomment-6248972373) Reran on RADV (Radeon 8060S, Mesa 26.2.4) with the new head merged on 37df7f32, one case per process. The same 40 cases go from failing to passing and nothing else in the suite changes, but `IndirectBufferStore` still fails (the four Shared stores are missing) and still ends in a GPUVM fault (SQC data, same address) and a gfx ring reset. The second commit does what it says: the slot offset and range are now per-lane `buffer_load_b32 ... offen` instead of `v_readfirstlane` + `s_load_b32`. What is left is the `index < 2` guard that never reaches EXEC (`v_cmp_gt_u32_e32 vcc_lo, 2, v3` followed by `s_bitset0_b32 exec_lo, 4`, same on main), so lanes with no matching key (slot -1) still enter the waterfall and load a descriptor at `set + 0xfffffff0`.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-18 13:19 UTC · original

Thanks, that ISA was the key. The lost index < 2 guard is a compiler bug in Mesa 26.2, and your main ISA shows it as well.

  • The test's Shared-layout SPIR-V keeps the NonUniform access chain, the slot data loads and the store inside if (selected < 2) (dumped from the test, spirv-val clean).
  • I compiled that SPIR-V with RADV through Mesa's AMDGPU drm-shim, so without the hardware (AMDGPU_GPU_ID=strix1, also navi31, gfx1201 and the RDNA2 raphael_mendocino; the shim has no Strix Halo entry). Mesa 26.0.8 sets EXEC with s_and_b32 exec_lo, vcc_lo, 0xffffffef, which keeps both guards. Mesa 26.2.4 emits s_bitset0_b32 exec_lo, 4 there, the instruction from your ISA: it clears lane 4 in the old EXEC and drops vcc_lo (selected < 2). So lanes with no matching key stay active and load the descriptor at set - 16.
  • In 26.2.4, register allocation produces vcc_lo = s_bitset0_b32 4, vcc_lo followed by exec_lo = s_mov_b32 vcc_lo, which is correct. Then try_optimize_branching_sequence in aco_optimizer_postRA.cpp makes the s_bitset0 write exec directly. s_bitset0 changes its destination in place, so this drops vcc_lo. With Mesa commit 984aa6e0855 ("aco/ra: create s_bitset", in 26.2 but not in 26.0) reverted, 26.2.4 emits the s_and_b32 again, and skipping instructions with tied definitions in that pass also gives correct code.
  • A small GLSL shader (two nested ifs and a NonUniform store) shows the same.

I'll report it to Mesa (https://gitlab.freedesktop.org/mesa/mesa/-/issues) and link the issue here. This is from compiler output only, and you can show the fault on hardware, so it would help a lot if you added your result to that issue. If you have time, a run of IndirectBufferStore on Mesa 26.0, or on 26.2 with 984aa6e0855 reverted, would also confirm it.

Written with Claude Code (AI): it dumped the SPIR-V, built Mesa 26.2.4 with the drm-shim and compared the compiler output; I read this before posting.

**@⁠Nawid3333** on GitHub · 2026-10-18 13:19 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#issuecomment-6250398992) Thanks, that ISA was the key. The lost `index < 2` guard is a compiler bug in Mesa 26.2, and your main ISA shows it as well. - The test's Shared-layout SPIR-V keeps the NonUniform access chain, the slot data loads and the store inside `if (selected < 2)` (dumped from the test, spirv-val clean). - I compiled that SPIR-V with RADV through Mesa's AMDGPU drm-shim, so without the hardware (`AMDGPU_GPU_ID=strix1`, also `navi31`, `gfx1201` and the RDNA2 `raphael_mendocino`; the shim has no Strix Halo entry). Mesa 26.0.8 sets EXEC with `s_and_b32 exec_lo, vcc_lo, 0xffffffef`, which keeps both guards. Mesa 26.2.4 emits `s_bitset0_b32 exec_lo, 4` there, the instruction from your ISA: it clears lane 4 in the old EXEC and drops `vcc_lo` (`selected < 2`). So lanes with no matching key stay active and load the descriptor at `set - 16`. - In 26.2.4, register allocation produces `vcc_lo = s_bitset0_b32 4, vcc_lo` followed by `exec_lo = s_mov_b32 vcc_lo`, which is correct. Then `try_optimize_branching_sequence` in aco_optimizer_postRA.cpp makes the `s_bitset0` write exec directly. `s_bitset0` changes its destination in place, so this drops `vcc_lo`. With Mesa commit 984aa6e0855 ("aco/ra: create s_bitset", in 26.2 but not in 26.0) reverted, 26.2.4 emits the `s_and_b32` again, and skipping instructions with tied definitions in that pass also gives correct code. - A small GLSL shader (two nested ifs and a NonUniform store) shows the same. I'll report it to Mesa (https://gitlab.freedesktop.org/mesa/mesa/-/issues) and link the issue here. This is from compiler output only, and you can show the fault on hardware, so it would help a lot if you added your result to that issue. If you have time, a run of `IndirectBufferStore` on Mesa 26.0, or on 26.2 with 984aa6e0855 reverted, would also confirm it. Written with Claude Code (AI): it dumped the SPIR-V, built Mesa 26.2.4 with the drm-shim and compared the compiler output; I read this before posting.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-18 14:06 UTC · original

Confirmed on hardware (Radeon 8060S, gfx1151). IndirectBufferStore passes on Mesa 26.0.8 and on 26.2.4 with 984aa6e0855 reverted, and still fails on stock 26.2.4 with the same GPUVM fault. The ISA matches your drm-shim output: s_and_b32 exec_lo, vcc_lo, 0xffffffef with the revert and on 26.0.8, s_bitset0_b32 exec_lo, 4 on stock 26.2.4. With the revert, the full GPU suite shows only the 40 expected fixes from this PR and no regressions, and IndirectBufferStore passes on main too, so its failure on main on RADV is the same Mesa bug.

**@⁠NeySlim** on GitHub · 2026-10-18 14:06 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#issuecomment-6250859454) Confirmed on hardware (Radeon 8060S, gfx1151). IndirectBufferStore passes on Mesa 26.0.8 and on 26.2.4 with 984aa6e0855 reverted, and still fails on stock 26.2.4 with the same GPUVM fault. The ISA matches your drm-shim output: `s_and_b32 exec_lo, vcc_lo, 0xffffffef` with the revert and on 26.0.8, `s_bitset0_b32 exec_lo, 4` on stock 26.2.4. With the revert, the full GPU suite shows only the 40 expected fixes from this PR and no regressions, and IndirectBufferStore passes on main too, so its failure on main on RADV is the same Mesa bug.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-18 15:17 UTC · original

Reported to Mesa: https://gitlab.freedesktop.org/mesa/mesa/-/work_items/16618 (your hardware result is linked). If you can, adding your Radeon 8060S result there directly would help.

Written with Claude Code (AI); I read this before posting.

**@⁠Nawid3333** on GitHub · 2026-10-18 15:17 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#issuecomment-6251575669) Reported to Mesa: https://gitlab.freedesktop.org/mesa/mesa/-/work_items/16618 (your hardware result is linked). If you can, adding your Radeon 8060S result there directly would help. Written with Claude Code (AI); I read this before posting.
Author
Owner

@⁠theantipopau on GitHub · 2026-10-19 03:08 UTC · original · approved these changes

Reviewed the full diff. This implements option 1 from #1595 exactly: exact descriptor ranges flow through shader data (static slots loaded at entry, non-uniform slots loaded per-access with the same per-lane index as the byte offset), eliminating both the 4-byte round-up and the first-lane-broadcast hazards of OpArrayLength. The push-data exclusion is well-reasoned (Vulkan dynamic-uniformity requirement + RADV wave-read behavior), the pipeline-cache/emitter placement agreement via PushDataStartFor plus the loud EXIT on mismatch is the right fail-safe, and the tests genuinely verify the new behavior (OpArrayLength forbidden, range-bound checks required, shader-data/packed-user-data agreement). CI green on all three platforms. LGTM.

**@⁠theantipopau** on GitHub · 2026-10-19 03:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#pullrequestreview-5566508519) · **approved these changes** Reviewed the full diff. This implements option 1 from #1595 exactly: exact descriptor ranges flow through shader data (static slots loaded at entry, non-uniform slots loaded per-access with the same per-lane index as the byte offset), eliminating both the 4-byte round-up and the first-lane-broadcast hazards of OpArrayLength. The push-data exclusion is well-reasoned (Vulkan dynamic-uniformity requirement + RADV wave-read behavior), the pipeline-cache/emitter placement agreement via PushDataStartFor plus the loud EXIT on mismatch is the right fail-safe, and the tests genuinely verify the new behavior (OpArrayLength forbidden, range-bound checks required, shader-data/packed-user-data agreement). CI green on all three platforms. LGTM.
Author
Owner

@⁠NeySlim on GitHub · 2026-10-19 06:26 UTC · original

I can't comment on the Mesa tracker yet (account confirmation is stuck). Could you add this to 16618?

Standalone run on a Radeon 8060S (gfx1151): the exact shader from the issue, one workgroup of 32 with key[lane] = lane % 3, makes the key-2 lanes store on stock 26.2.4 (s_bitset0_b32 exec_lo, 4), with no GPU fault since RADV's outs[2] lands on the keys descriptor, so you get keys[lane] = lane on 9 lanes. 26.0.8 and 26.2.4 with 984aa6e0855 reverted emit s_and_b32 exec_lo, vcc_lo, 0xffffffef and pass. Same on 4 runs each, nothing in dmesg, validation layers clean. Build with gcc -o r1_run r1_run.c -lvulkan && ./r1_run r1_nonuniform.spv.

r1_run.c
// Runs r1_nonuniform.spv once (one workgroup of 32) and checks the results.
// set 0: binding 0 = outs[2], binding 53 = keys. key[lane] = lane % 3, so lanes with key 2 must not
// store anything (index < 2 is false). Lane 4 has key 1 and must not store either (lane != 4).
// Usage: r1_run <r1_nonuniform.spv>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vulkan/vulkan.h>

#define CHECK(call)                                                       \
	do {                                                                  \
		VkResult r_ = (call);                                             \
		if (r_ != VK_SUCCESS) {                                           \
			fprintf(stderr, "%s failed: %d\n", #call, (int)r_);           \
			exit(1);                                                      \
		}                                                                 \
	} while (0)

#define N 32
#define POISON 0xdeadbeefu

static VkDevice device;
static VkPhysicalDevice physical;

static VkBuffer make_buffer(VkDeviceMemory* memory, uint32_t** map) {
	VkBufferCreateInfo info = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO};
	info.size = N * sizeof(uint32_t);
	info.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT;
	VkBuffer buffer;
	CHECK(vkCreateBuffer(device, &info, NULL, &buffer));
	VkMemoryRequirements req;
	vkGetBufferMemoryRequirements(device, buffer, &req);
	VkPhysicalDeviceMemoryProperties props;
	vkGetPhysicalDeviceMemoryProperties(physical, &props);
	VkMemoryPropertyFlags want = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
	uint32_t type = UINT32_MAX;
	for (uint32_t i = 0; i < props.memoryTypeCount; ++i)
		if ((req.memoryTypeBits & (1u << i)) && (props.memoryTypes[i].propertyFlags & want) == want) {
			type = i;
			break;
		}
	if (type == UINT32_MAX) exit(6);
	VkMemoryAllocateInfo alloc = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO};
	alloc.allocationSize = req.size;
	alloc.memoryTypeIndex = type;
	CHECK(vkAllocateMemory(device, &alloc, NULL, memory));
	CHECK(vkBindBufferMemory(device, buffer, *memory, 0));
	CHECK(vkMapMemory(device, *memory, 0, VK_WHOLE_SIZE, 0, (void**)map));
	return buffer;
}

int main(int argc, char** argv) {
	if (argc < 2) return 2;
	FILE* file = fopen(argv[1], "rb");
	if (!file) return 3;
	fseek(file, 0, SEEK_END);
	long size = ftell(file);
	fseek(file, 0, SEEK_SET);
	uint32_t* code = malloc(size);
	if (fread(code, 1, size, file) != (size_t)size) return 4;
	fclose(file);

	VkApplicationInfo app = {VK_STRUCTURE_TYPE_APPLICATION_INFO};
	app.apiVersion = VK_API_VERSION_1_3;
	VkInstanceCreateInfo instance_info = {VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO};
	instance_info.pApplicationInfo = &app;
	VkInstance instance;
	CHECK(vkCreateInstance(&instance_info, NULL, &instance));
	uint32_t count = 8;
	VkPhysicalDevice devices[8];
	CHECK(vkEnumeratePhysicalDevices(instance, &count, devices));
	physical = VK_NULL_HANDLE;
	for (uint32_t i = 0; i < count; ++i) {
		VkPhysicalDeviceDriverProperties driver = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES};
		VkPhysicalDeviceProperties2 props = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &driver};
		vkGetPhysicalDeviceProperties2(devices[i], &props);
		if (driver.driverID == VK_DRIVER_ID_MESA_RADV && physical == VK_NULL_HANDLE) {
			physical = devices[i];
			printf("device: %s (%s %s)\n", props.properties.deviceName, driver.driverName, driver.driverInfo);
		}
	}
	if (physical == VK_NULL_HANDLE) {
		fprintf(stderr, "no RADV device\n");
		return 5;
	}

	VkPhysicalDeviceVulkan12Features features12 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES};
	features12.descriptorIndexing = VK_TRUE;
	features12.shaderStorageBufferArrayNonUniformIndexing = VK_TRUE;
	VkPhysicalDeviceFeatures2 features = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &features12};
	float priority = 1.0f;
	VkDeviceQueueCreateInfo queue_info = {VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO};
	queue_info.queueCount = 1;
	queue_info.pQueuePriorities = &priority;
	VkDeviceCreateInfo device_info = {VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, &features};
	device_info.queueCreateInfoCount = 1;
	device_info.pQueueCreateInfos = &queue_info;
	CHECK(vkCreateDevice(physical, &device_info, NULL, &device));
	VkQueue queue;
	vkGetDeviceQueue(device, 0, 0, &queue);

	VkDeviceMemory memory[3];
	uint32_t* map[3];
	VkBuffer buffers[3];
	for (int i = 0; i < 3; ++i) buffers[i] = make_buffer(&memory[i], &map[i]);
	uint32_t *out0 = map[0], *out1 = map[1], *keys = map[2];
	for (uint32_t l = 0; l < N; ++l) {
		out0[l] = out1[l] = POISON;
		keys[l] = l % 3;
	}

	VkDescriptorSetLayoutBinding bindings[2] = {
	    {0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2, VK_SHADER_STAGE_COMPUTE_BIT, NULL},
	    {53, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, NULL}};
	VkDescriptorSetLayoutCreateInfo set_info = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO};
	set_info.bindingCount = 2;
	set_info.pBindings = bindings;
	VkDescriptorSetLayout set_layout;
	CHECK(vkCreateDescriptorSetLayout(device, &set_info, NULL, &set_layout));
	VkPipelineLayoutCreateInfo layout_info = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO};
	layout_info.setLayoutCount = 1;
	layout_info.pSetLayouts = &set_layout;
	VkPipelineLayout layout;
	CHECK(vkCreatePipelineLayout(device, &layout_info, NULL, &layout));

	VkDescriptorPoolSize pool_size = {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 3};
	VkDescriptorPoolCreateInfo pool_info = {VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
	pool_info.maxSets = 1;
	pool_info.poolSizeCount = 1;
	pool_info.pPoolSizes = &pool_size;
	VkDescriptorPool pool;
	CHECK(vkCreateDescriptorPool(device, &pool_info, NULL, &pool));
	VkDescriptorSetAllocateInfo set_alloc = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO};
	set_alloc.descriptorPool = pool;
	set_alloc.descriptorSetCount = 1;
	set_alloc.pSetLayouts = &set_layout;
	VkDescriptorSet set;
	CHECK(vkAllocateDescriptorSets(device, &set_alloc, &set));
	VkDescriptorBufferInfo infos[3];
	for (int i = 0; i < 3; ++i) infos[i] = (VkDescriptorBufferInfo){buffers[i], 0, VK_WHOLE_SIZE};
	VkWriteDescriptorSet writes[2] = {{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET},
	                                  {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}};
	writes[0].dstSet = set;
	writes[0].dstBinding = 0;
	writes[0].descriptorCount = 2;
	writes[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
	writes[0].pBufferInfo = &infos[0];
	writes[1].dstSet = set;
	writes[1].dstBinding = 53;
	writes[1].descriptorCount = 1;
	writes[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER;
	writes[1].pBufferInfo = &infos[2];
	vkUpdateDescriptorSets(device, 2, writes, 0, NULL);

	VkShaderModuleCreateInfo module_info = {VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO};
	module_info.codeSize = (size_t)size;
	module_info.pCode = code;
	VkShaderModule module;
	CHECK(vkCreateShaderModule(device, &module_info, NULL, &module));
	VkComputePipelineCreateInfo pipeline_info = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO};
	pipeline_info.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
	pipeline_info.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT;
	pipeline_info.stage.module = module;
	pipeline_info.stage.pName = "main";
	pipeline_info.layout = layout;
	VkPipeline pipeline;
	CHECK(vkCreateComputePipelines(device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &pipeline));

	VkCommandPoolCreateInfo cmd_pool_info = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO};
	VkCommandPool cmd_pool;
	CHECK(vkCreateCommandPool(device, &cmd_pool_info, NULL, &cmd_pool));
	VkCommandBufferAllocateInfo cmd_alloc = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO};
	cmd_alloc.commandPool = cmd_pool;
	cmd_alloc.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
	cmd_alloc.commandBufferCount = 1;
	VkCommandBuffer cmd;
	CHECK(vkAllocateCommandBuffers(device, &cmd_alloc, &cmd));
	VkCommandBufferBeginInfo begin = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO};
	CHECK(vkBeginCommandBuffer(cmd, &begin));
	vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline);
	vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, layout, 0, 1, &set, 0, NULL);
	vkCmdDispatch(cmd, 1, 1, 1);
	VkMemoryBarrier barrier = {VK_STRUCTURE_TYPE_MEMORY_BARRIER};
	barrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT;
	barrier.dstAccessMask = VK_ACCESS_HOST_READ_BIT;
	vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 1, &barrier, 0,
	                     NULL, 0, NULL);
	CHECK(vkEndCommandBuffer(cmd));
	VkSubmitInfo submit = {VK_STRUCTURE_TYPE_SUBMIT_INFO};
	submit.commandBufferCount = 1;
	submit.pCommandBuffers = &cmd;
	CHECK(vkQueueSubmit(queue, 1, &submit, VK_NULL_HANDLE));
	CHECK(vkQueueWaitIdle(queue));

	int errors = 0;
	for (uint32_t l = 0; l < N; ++l) {
		uint32_t key = l % 3;
		int stores = l != 4 && key < 2;
		uint32_t want0 = stores && key == 0 ? l : POISON;
		uint32_t want1 = stores && key == 1 ? l : POISON;
		if (out0[l] != want0 || out1[l] != want1 || keys[l] != key) {
			printf("lane %2u key %u: outs[0]=0x%08x outs[1]=0x%08x keys=0x%08x (want 0x%08x 0x%08x %u)\n", l, key,
			       out0[l], out1[l], keys[l], want0, want1, key);
			++errors;
		}
	}
	printf("%s: %d wrong lanes\n", errors ? "FAIL" : "PASS", errors);

	vkDestroyCommandPool(device, cmd_pool, NULL);
	vkDestroyPipeline(device, pipeline, NULL);
	vkDestroyShaderModule(device, module, NULL);
	vkDestroyDescriptorPool(device, pool, NULL);
	vkDestroyPipelineLayout(device, layout, NULL);
	vkDestroyDescriptorSetLayout(device, set_layout, NULL);
	for (int i = 0; i < 3; ++i) {
		vkDestroyBuffer(device, buffers[i], NULL);
		vkFreeMemory(device, memory[i], NULL);
	}
	vkDestroyDevice(device, NULL);
	vkDestroyInstance(instance, NULL);
	free(code);
	return errors ? 1 : 0;
}
**@⁠NeySlim** on GitHub · 2026-10-19 06:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#issuecomment-6261096993) I can't comment on the Mesa tracker yet (account confirmation is stuck). Could you add this to 16618? Standalone run on a Radeon 8060S (gfx1151): the exact shader from the issue, one workgroup of 32 with `key[lane] = lane % 3`, makes the key-2 lanes store on stock 26.2.4 (`s_bitset0_b32 exec_lo, 4`), with no GPU fault since RADV's `outs[2]` lands on the keys descriptor, so you get `keys[lane] = lane` on 9 lanes. 26.0.8 and 26.2.4 with 984aa6e0855 reverted emit `s_and_b32 exec_lo, vcc_lo, 0xffffffef` and pass. Same on 4 runs each, nothing in dmesg, validation layers clean. Build with `gcc -o r1_run r1_run.c -lvulkan && ./r1_run r1_nonuniform.spv`. <details><summary>r1_run.c</summary> ```c // Runs r1_nonuniform.spv once (one workgroup of 32) and checks the results. // set 0: binding 0 = outs[2], binding 53 = keys. key[lane] = lane % 3, so lanes with key 2 must not // store anything (index < 2 is false). Lane 4 has key 1 and must not store either (lane != 4). // Usage: r1_run <r1_nonuniform.spv> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <vulkan/vulkan.h> #define CHECK(call) \ do { \ VkResult r_ = (call); \ if (r_ != VK_SUCCESS) { \ fprintf(stderr, "%s failed: %d\n", #call, (int)r_); \ exit(1); \ } \ } while (0) #define N 32 #define POISON 0xdeadbeefu static VkDevice device; static VkPhysicalDevice physical; static VkBuffer make_buffer(VkDeviceMemory* memory, uint32_t** map) { VkBufferCreateInfo info = {VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO}; info.size = N * sizeof(uint32_t); info.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT; VkBuffer buffer; CHECK(vkCreateBuffer(device, &info, NULL, &buffer)); VkMemoryRequirements req; vkGetBufferMemoryRequirements(device, buffer, &req); VkPhysicalDeviceMemoryProperties props; vkGetPhysicalDeviceMemoryProperties(physical, &props); VkMemoryPropertyFlags want = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; uint32_t type = UINT32_MAX; for (uint32_t i = 0; i < props.memoryTypeCount; ++i) if ((req.memoryTypeBits & (1u << i)) && (props.memoryTypes[i].propertyFlags & want) == want) { type = i; break; } if (type == UINT32_MAX) exit(6); VkMemoryAllocateInfo alloc = {VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO}; alloc.allocationSize = req.size; alloc.memoryTypeIndex = type; CHECK(vkAllocateMemory(device, &alloc, NULL, memory)); CHECK(vkBindBufferMemory(device, buffer, *memory, 0)); CHECK(vkMapMemory(device, *memory, 0, VK_WHOLE_SIZE, 0, (void**)map)); return buffer; } int main(int argc, char** argv) { if (argc < 2) return 2; FILE* file = fopen(argv[1], "rb"); if (!file) return 3; fseek(file, 0, SEEK_END); long size = ftell(file); fseek(file, 0, SEEK_SET); uint32_t* code = malloc(size); if (fread(code, 1, size, file) != (size_t)size) return 4; fclose(file); VkApplicationInfo app = {VK_STRUCTURE_TYPE_APPLICATION_INFO}; app.apiVersion = VK_API_VERSION_1_3; VkInstanceCreateInfo instance_info = {VK_STRUCTURE_TYPE_INSTANCE_CREATE_INFO}; instance_info.pApplicationInfo = &app; VkInstance instance; CHECK(vkCreateInstance(&instance_info, NULL, &instance)); uint32_t count = 8; VkPhysicalDevice devices[8]; CHECK(vkEnumeratePhysicalDevices(instance, &count, devices)); physical = VK_NULL_HANDLE; for (uint32_t i = 0; i < count; ++i) { VkPhysicalDeviceDriverProperties driver = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DRIVER_PROPERTIES}; VkPhysicalDeviceProperties2 props = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PROPERTIES_2, &driver}; vkGetPhysicalDeviceProperties2(devices[i], &props); if (driver.driverID == VK_DRIVER_ID_MESA_RADV && physical == VK_NULL_HANDLE) { physical = devices[i]; printf("device: %s (%s %s)\n", props.properties.deviceName, driver.driverName, driver.driverInfo); } } if (physical == VK_NULL_HANDLE) { fprintf(stderr, "no RADV device\n"); return 5; } VkPhysicalDeviceVulkan12Features features12 = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_VULKAN_1_2_FEATURES}; features12.descriptorIndexing = VK_TRUE; features12.shaderStorageBufferArrayNonUniformIndexing = VK_TRUE; VkPhysicalDeviceFeatures2 features = {VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_FEATURES_2, &features12}; float priority = 1.0f; VkDeviceQueueCreateInfo queue_info = {VK_STRUCTURE_TYPE_DEVICE_QUEUE_CREATE_INFO}; queue_info.queueCount = 1; queue_info.pQueuePriorities = &priority; VkDeviceCreateInfo device_info = {VK_STRUCTURE_TYPE_DEVICE_CREATE_INFO, &features}; device_info.queueCreateInfoCount = 1; device_info.pQueueCreateInfos = &queue_info; CHECK(vkCreateDevice(physical, &device_info, NULL, &device)); VkQueue queue; vkGetDeviceQueue(device, 0, 0, &queue); VkDeviceMemory memory[3]; uint32_t* map[3]; VkBuffer buffers[3]; for (int i = 0; i < 3; ++i) buffers[i] = make_buffer(&memory[i], &map[i]); uint32_t *out0 = map[0], *out1 = map[1], *keys = map[2]; for (uint32_t l = 0; l < N; ++l) { out0[l] = out1[l] = POISON; keys[l] = l % 3; } VkDescriptorSetLayoutBinding bindings[2] = { {0, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 2, VK_SHADER_STAGE_COMPUTE_BIT, NULL}, {53, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 1, VK_SHADER_STAGE_COMPUTE_BIT, NULL}}; VkDescriptorSetLayoutCreateInfo set_info = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_LAYOUT_CREATE_INFO}; set_info.bindingCount = 2; set_info.pBindings = bindings; VkDescriptorSetLayout set_layout; CHECK(vkCreateDescriptorSetLayout(device, &set_info, NULL, &set_layout)); VkPipelineLayoutCreateInfo layout_info = {VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO}; layout_info.setLayoutCount = 1; layout_info.pSetLayouts = &set_layout; VkPipelineLayout layout; CHECK(vkCreatePipelineLayout(device, &layout_info, NULL, &layout)); VkDescriptorPoolSize pool_size = {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 3}; VkDescriptorPoolCreateInfo pool_info = {VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; pool_info.maxSets = 1; pool_info.poolSizeCount = 1; pool_info.pPoolSizes = &pool_size; VkDescriptorPool pool; CHECK(vkCreateDescriptorPool(device, &pool_info, NULL, &pool)); VkDescriptorSetAllocateInfo set_alloc = {VK_STRUCTURE_TYPE_DESCRIPTOR_SET_ALLOCATE_INFO}; set_alloc.descriptorPool = pool; set_alloc.descriptorSetCount = 1; set_alloc.pSetLayouts = &set_layout; VkDescriptorSet set; CHECK(vkAllocateDescriptorSets(device, &set_alloc, &set)); VkDescriptorBufferInfo infos[3]; for (int i = 0; i < 3; ++i) infos[i] = (VkDescriptorBufferInfo){buffers[i], 0, VK_WHOLE_SIZE}; VkWriteDescriptorSet writes[2] = {{VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}, {VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET}}; writes[0].dstSet = set; writes[0].dstBinding = 0; writes[0].descriptorCount = 2; writes[0].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; writes[0].pBufferInfo = &infos[0]; writes[1].dstSet = set; writes[1].dstBinding = 53; writes[1].descriptorCount = 1; writes[1].descriptorType = VK_DESCRIPTOR_TYPE_STORAGE_BUFFER; writes[1].pBufferInfo = &infos[2]; vkUpdateDescriptorSets(device, 2, writes, 0, NULL); VkShaderModuleCreateInfo module_info = {VK_STRUCTURE_TYPE_SHADER_MODULE_CREATE_INFO}; module_info.codeSize = (size_t)size; module_info.pCode = code; VkShaderModule module; CHECK(vkCreateShaderModule(device, &module_info, NULL, &module)); VkComputePipelineCreateInfo pipeline_info = {VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO}; pipeline_info.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO; pipeline_info.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT; pipeline_info.stage.module = module; pipeline_info.stage.pName = "main"; pipeline_info.layout = layout; VkPipeline pipeline; CHECK(vkCreateComputePipelines(device, VK_NULL_HANDLE, 1, &pipeline_info, NULL, &pipeline)); VkCommandPoolCreateInfo cmd_pool_info = {VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO}; VkCommandPool cmd_pool; CHECK(vkCreateCommandPool(device, &cmd_pool_info, NULL, &cmd_pool)); VkCommandBufferAllocateInfo cmd_alloc = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO}; cmd_alloc.commandPool = cmd_pool; cmd_alloc.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; cmd_alloc.commandBufferCount = 1; VkCommandBuffer cmd; CHECK(vkAllocateCommandBuffers(device, &cmd_alloc, &cmd)); VkCommandBufferBeginInfo begin = {VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO}; CHECK(vkBeginCommandBuffer(cmd, &begin)); vkCmdBindPipeline(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, pipeline); vkCmdBindDescriptorSets(cmd, VK_PIPELINE_BIND_POINT_COMPUTE, layout, 0, 1, &set, 0, NULL); vkCmdDispatch(cmd, 1, 1, 1); VkMemoryBarrier barrier = {VK_STRUCTURE_TYPE_MEMORY_BARRIER}; barrier.srcAccessMask = VK_ACCESS_SHADER_WRITE_BIT; barrier.dstAccessMask = VK_ACCESS_HOST_READ_BIT; vkCmdPipelineBarrier(cmd, VK_PIPELINE_STAGE_COMPUTE_SHADER_BIT, VK_PIPELINE_STAGE_HOST_BIT, 0, 1, &barrier, 0, NULL, 0, NULL); CHECK(vkEndCommandBuffer(cmd)); VkSubmitInfo submit = {VK_STRUCTURE_TYPE_SUBMIT_INFO}; submit.commandBufferCount = 1; submit.pCommandBuffers = &cmd; CHECK(vkQueueSubmit(queue, 1, &submit, VK_NULL_HANDLE)); CHECK(vkQueueWaitIdle(queue)); int errors = 0; for (uint32_t l = 0; l < N; ++l) { uint32_t key = l % 3; int stores = l != 4 && key < 2; uint32_t want0 = stores && key == 0 ? l : POISON; uint32_t want1 = stores && key == 1 ? l : POISON; if (out0[l] != want0 || out1[l] != want1 || keys[l] != key) { printf("lane %2u key %u: outs[0]=0x%08x outs[1]=0x%08x keys=0x%08x (want 0x%08x 0x%08x %u)\n", l, key, out0[l], out1[l], keys[l], want0, want1, key); ++errors; } } printf("%s: %d wrong lanes\n", errors ? "FAIL" : "PASS", errors); vkDestroyCommandPool(device, cmd_pool, NULL); vkDestroyPipeline(device, pipeline, NULL); vkDestroyShaderModule(device, module, NULL); vkDestroyDescriptorPool(device, pool, NULL); vkDestroyPipelineLayout(device, layout, NULL); vkDestroyDescriptorSetLayout(device, set_layout, NULL); for (int i = 0; i < 3; ++i) { vkDestroyBuffer(device, buffers[i], NULL); vkFreeMemory(device, memory[i], NULL); } vkDestroyDevice(device, NULL); vkDestroyInstance(instance, NULL); free(code); return errors ? 1 : 0; } ``` </details>
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-21 17:03 UTC · original

@⁠NeySlim Update on the Mesa side (issue 16618): Rhys Perry's MR !45419 fixes it (aco/opt_postRA: check for tied defs in try_optimize_branching_sequence). It is reviewed but not merged yet.

Here I could only check it without AMD Linux hardware: compiled with RADV on drm-shim for RDNA2, RDNA3, RDNA3.5 and RDNA4, stock 26.2.4 emits s_bitset0_b32 exec_lo, 4, and with the MR it becomes vcc_lo = s_bitset0_b32 4, vcc_lo followed by exec_lo = s_mov_b32 vcc_lo. The MR's own ACO unit tests fail on stock and pass with it.

A run on your 8060S would be the real hardware check: your standalone shader and IndirectBufferStore on 26.2.4 with the MR applied. If you post the result here, I'll add it to the Mesa issue.

**@⁠Nawid3333** on GitHub · 2026-10-21 17:03 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#issuecomment-6321785863) @⁠NeySlim Update on the Mesa side (issue 16618): Rhys Perry's MR [!45419](https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/45419) fixes it (`aco/opt_postRA: check for tied defs in try_optimize_branching_sequence`). It is reviewed but not merged yet. Here I could only check it without AMD Linux hardware: compiled with RADV on drm-shim for RDNA2, RDNA3, RDNA3.5 and RDNA4, stock 26.2.4 emits `s_bitset0_b32 exec_lo, 4`, and with the MR it becomes `vcc_lo = s_bitset0_b32 4, vcc_lo` followed by `exec_lo = s_mov_b32 vcc_lo`. The MR's own ACO unit tests fail on stock and pass with it. A run on your 8060S would be the real hardware check: your standalone shader and IndirectBufferStore on 26.2.4 with the MR applied. If you post the result here, I'll add it to the Mesa issue.
Author
Owner

@⁠Nawid3333 on GitHub · 2026-10-28 19:01 UTC · original

Closing this: main does it since ba7f9969 ("shader: bound storage buffers by pushed binding sizes instead of OpArrayLength") and dc3bd68d ("gpu: bound null storage bindings to zero bytes"). Each storage buffer's bound size now goes into the shader data and bounds the accesses instead of OpArrayLength, which is what this PR did. One difference: null bindings get 0 bytes on main, where this PR kept 16.

Thanks @⁠theantipopau for the review.

**@⁠Nawid3333** on GitHub · 2026-10-28 19:01 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1603#issuecomment-6477974404) Closing this: main does it since ba7f9969 ("shader: bound storage buffers by pushed binding sizes instead of OpArrayLength") and dc3bd68d ("gpu: bound null storage bindings to zero bytes"). Each storage buffer's bound size now goes into the shader data and bounds the accesses instead of `OpArrayLength`, which is what this PR did. One difference: null bindings get 0 bytes on main, where this PR kept 16. Thanks @⁠theantipopau for the review.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.