shader: bound storage buffers by their exact descriptor range #1603
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1603
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1603/head"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
@Nawid3333 on GitHub · 2026-10-17 15:53 UTC · original
Nawid3333:shader/exact-buffer-ranges→main· +101 −34 · 8 files · 2 commits · closed without mergingFixes #1595 (option 1 there).
PrepareStorageBufferResourceAccessbounded every storage-buffer access byOpArrayLength. 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:
RebindBufferswrites each storage buffer's descriptor range in bytes (theVkDescriptorBufferInforange) 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 valueOpArrayLengthshould return, so hosts where it is right see the same bounds. The onlyOpArrayLengthleft 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::PushDataStartForapplies 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
6aa3846f: 38 compute-suite entries go from fail to pass (the 36 multi-laneBufferStoreFormatD16HiX*/BufferStoreFormatD16Xyzw*cases,BufferUshortHostOffsetFirst,IndirectBufferStore); the other 686 entries and the 30 graphics cases keep their status. The named cases give no validation-layer messages. WithOpArrayLengthrestored (a local mutant), all five named cases fail again in every configuration.RebindBuffersand requires the shader data to haveShaderDataDwords()dwords;IndirectBufferStoreforbidsOpArrayLength; the RenderExecutor halfword-tail check also checks the range dword (14).shader_cfg_tests(not run by CI): four checks usedOpArrayLengthas the bound; they now look for the range load that feeds theOpULessThan(SpirvBufferRangeBoundPosition), with the same ordering checks. It passes.BoundedRecordBufferAccess32andGpuSelectedRecordBufferAccess32, also go from fail to pass on both GPUs (they write two words past the end on main, as NeySlim saw on RADV).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, andshader_cfg_testspasses.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
@coderabbitai[bot] on GitHub · 2026-10-17 16:02 UTC · original · edited 2026-10-18 04:15 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
0064a7db-221e-4b80-85ab-ddab79300eef📥 Commits
Reviewing files that changed from the base of the PR and between
3b4a6b8deband1bfcb063b7.📒 Files selected for processing: 5
src/graphics/host_gpu/renderer/pipeline/pipelineCache.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/ir/ShaderIR.htests/ShaderRecompilerComputeTests.cppIncluded 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:
nmzikPriority: ⬆️ High
Change: Bug fix · Severity of issue fixed: Medium
Merge Risk: ⚪ Minimal · up to
1bfcbNo confirmed issue remains that needs to be fixed before merge; proceed with normal checks.
Pre-merge checks:
4 ·
1
#1595requires exact storage-buffer bounds in shader code. The current head writes each descriptor range to shader data after the packed offsets.PrepareStorageBufferResourceAccessuses that r…#1595. Descriptor rebinding supplies the exact range. Shader layout, pipeline permutation selection, and lane-indexed placement support delivery of that range. The comput…Full details: Linked Issues check
Explanation
Issue
#1595requires exact storage-buffer bounds in shader code. The current head writes each descriptor range to shader data after the packed offsets.PrepareStorageBufferResourceAccessuses 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 usesOpArrayLengthfor 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 ofOpArrayLengthinIndirectBufferStore.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.
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 helpto get the list of available commands.@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:BufferUshortHostOffsetFirstreads back0x0000faceand the 36 multi-lane D16 store cases write the last record. With this PR those pass, and so doBoundedRecordBufferAccess32,GpuSelectedRecordBufferAccess32andGpuSelectedFormattedRgba16Store, which also fail on main on RADV (two words past the end each); the rest of the suite is unchanged exceptIndirectBufferStore.IndirectBufferStorestill 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 theindex < 2guard never reaches EXEC (v_cmp_gt_u32_e32 vcc_lo, 2, v3followed bys_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.@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.
IndirectBufferStorenow 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,BoundedRecordBufferAccess32andGpuSelectedRecordBufferAccess32fail on main on both GPUs and pass with this PR.Could you rerun
IndirectBufferStoreand 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.
@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, butIndirectBufferStorestill 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-lanebuffer_load_b32 ... offeninstead ofv_readfirstlane+s_load_b32. What is left is theindex < 2guard that never reaches EXEC (v_cmp_gt_u32_e32 vcc_lo, 2, v3followed bys_bitset0_b32 exec_lo, 4, same on main), so lanes with no matching key (slot -1) still enter the waterfall and load a descriptor atset + 0xfffffff0.@Nawid3333 on GitHub · 2026-10-18 13:19 UTC · original
Thanks, that ISA was the key. The lost
index < 2guard is a compiler bug in Mesa 26.2, and your main ISA shows it as well.if (selected < 2)(dumped from the test, spirv-val clean).AMDGPU_GPU_ID=strix1, alsonavi31,gfx1201and the RDNA2raphael_mendocino; the shim has no Strix Halo entry). Mesa 26.0.8 sets EXEC withs_and_b32 exec_lo, vcc_lo, 0xffffffef, which keeps both guards. Mesa 26.2.4 emitss_bitset0_b32 exec_lo, 4there, the instruction from your ISA: it clears lane 4 in the old EXEC and dropsvcc_lo(selected < 2). So lanes with no matching key stay active and load the descriptor atset - 16.vcc_lo = s_bitset0_b32 4, vcc_lofollowed byexec_lo = s_mov_b32 vcc_lo, which is correct. Thentry_optimize_branching_sequencein aco_optimizer_postRA.cpp makes thes_bitset0write exec directly.s_bitset0changes its destination in place, so this dropsvcc_lo. With Mesa commit 984aa6e0855 ("aco/ra: create s_bitset", in 26.2 but not in 26.0) reverted, 26.2.4 emits thes_and_b32again, and skipping instructions with tied definitions in that pass also gives correct code.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
IndirectBufferStoreon 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.
@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, 0xffffffefwith the revert and on 26.0.8,s_bitset0_b32 exec_lo, 4on 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.@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.
@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.
@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'souts[2]lands on the keys descriptor, so you getkeys[lane] = laneon 9 lanes. 26.0.8 and 26.2.4 with 984aa6e0855 reverted emits_and_b32 exec_lo, vcc_lo, 0xffffffefand pass. Same on 4 runs each, nothing in dmesg, validation layers clean. Build withgcc -o r1_run r1_run.c -lvulkan && ./r1_run r1_nonuniform.spv.r1_run.c
@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 becomesvcc_lo = s_bitset0_b32 4, vcc_lofollowed byexec_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-28 19:01 UTC · original
Closing this: main does it since
ba7f9969("shader: bound storage buffers by pushed binding sizes instead of OpArrayLength") anddc3bd68d("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 ofOpArrayLength, 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