shader: dispatch indirect image gathers and queries per candidate #1320
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!1320
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1320/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?
@NeySlim on GitHub · 2026-10-09 17:55 UTC · original
NeySlim:fix/indirect-image-queries→main· +374 −67 · 4 files · 7 commits · closed without mergingProblem
An image whose T# is chosen at run time from a descriptor table (indirect image table) is specialized into one root plus one child image per distinct candidate. Since
71c72617,ImageSampleRawandImageReadselect the candidate throughEmitImageAccess.ImageGatherRaw(IMAGE_GATHER4*),ImageQueryDimensions(IMAGE_GET_RESINFO) andImageQueryLod(IMAGE_GET_LOD) still use the root resource only, i.e. the first candidate.Resource tracking accepts these tables for any image opcode. In the full pipeline a gather or query through such a table then stops at
EXIT_IF(image.indirect_root == memory.resource && inst.GetOpcode() != ValueOpcode::ImageSampleRaw && inst.GetOpcode() != ValueOpcode::ImageRead)inApplyResourceSpecialization, with no hint of the cause. The emitter on its own reads the root image for every lane. A store or atomic through such a table hits the sameEXIT_IF.Change
spirvEmitterImage.cpp: gathers (2D/2D-array/cube, the 1D LZ path and dynamic-mip gathers), dimension queries and LOD queries go throughEmitImageAccess, like samples and loads. Each candidate uses its own dimension, cube flag and mip count for coordinates, offsets and the mip switch; the image operand already getsNonUniformfromLoadImageDescriptor.BuildResourceSpecializationfails withindirect storage image table at pc 0x... is unsupported, and the emitter refuses such an access instead of using the root image.CoordF32gets the samesuppliedargument as in #1255, so both PRs apply one rule.EXIT_IFinApplyResourceSpecializationnow states that invariant: only sampled-class operations reach an indirect root.Related: #852 made loads and dimension queries use indirect candidates on top of #811, which was closed; it conflicts with current main and also accepts mixed 2D/3D candidates, which this change does not.
Test
IndirectImageOperations(GPU,shader_recompiler_compute_tests, also under--indirect-image-only): a 2D-array load (slice 1, LOD 0), a gather and a size query through an indirect table with a native array run of three 2D candidates and a separate 2-layer 2D-array candidate whose slice 1 holds a distinct value. Each lane selects a candidate and stores the three results. Wave32 and wave64. It checks that both a native array run and a candidate switch are emitted and that the fetched image carriesNonUniform. On main the loads are right, the gathers return the root texel and the queries the root width for every lane.indirect image table operations(resource_tracking_tests): a load, a gather and a size query through a tracked image table materialize and specialize with all candidates (on main the gather and the query stop at theEXIT_IF); a store through the same table is rejected byMaterializeResources(on main it was accepted, then aborted inApplyResourceSpecialization).IndirectImageOperationsalso loads LOD 1 with a 2D instruction through the same table: the 2D-array candidate must return layer 0 of mip 1 (on main it returned layer 1).Validation
ctest -R "resource_|shader_cfg"passes.shader_recompiler_compute_testsrun one case per process: same results as main.AI use
The investigation, code and tests were produced with Claude Code (Anthropic) and reviewed by a second, independent Claude Code agent. I checked the change and the test results; I have not run a game that hits this path.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-09 18:01 UTC · original · edited 2026-10-09 19:05 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
f3b650e7-218f-40a5-954d-457e51a1bbf2📥 Commits
Reviewing files that changed from the base of the PR and between
6e607830f8and6b28b3fdf9.📒 Files selected for processing (1)
tests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 0 remain after this review.
📝 Walkthrough
Walkthrough
Image queries, reads, and gathers now use selected indirect image resources and array indices. Coordinate helpers limit coordinates to those supplied by the instruction. Indirect image roots must use sampled resources, and indirect storage-image access is rejected. Resource-tracking and compute tests cover supported operations, write rejection, candidate selection, and wave32 and wave64 results.
Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
6b28bThe prior wave64 coverage concern is resolved, and no remaining merge risk is established by the supplied review context.
Pre-merge checks |
4 |
1
❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 15 functions across 3 files. (1 skipped: 1 too large.)
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.@coderabbitai[bot] on GitHub · 2026-10-09 18:01 UTC · original · reviewed
🧹 Nitpick comments (1)
ℹ️ Review info
⚙️ Run configuration
1b98c3fa-8e4c-4ada-819e-ef2e1a6c4582📥 Commits
Reviewing files that changed from the base of the PR and between
c1926f915dandc99b0c31ed.📒 Files selected for processing (4)
src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpptests/ResourceTrackingTests.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@NeySlim on GitHub · 2026-10-09 18:10 UTC · original
Addressed the CodeRabbit nitpick on the 8-entry ordinal table in
cd48599d: the map now has 60 entries (an 11-entry pattern), so lanes 32-63 of the wave64 dispatch also select every candidate, and lanes 60-63 still fall past the map and select the root. The test still fails with the shader commit reverted; the GPU suite run one case per process matches main. The Linux CI failure is main's ResourceMaterializationTests.cpp:246 (see #1277).@coderabbitai[bot] on GitHub · 2026-10-09 18:15 UTC · original · reviewed
🧹 Nitpick comments (1)
ℹ️ Review info
⚙️ Run configuration
e7855de5-dd82-48c9-b8ec-c215d1bc870a📥 Commits
Reviewing files that changed from the base of the PR and between
c99b0c31edandcd48599dfe.📒 Files selected for processing (1)
tests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.
@NeySlim on GitHub · 2026-10-09 18:21 UTC · original
On the root-image nitpick: in this table the root is candidate 0 (
indirect_resources[0]is the root resource itself), so lanes past the map and lanes mapped to ordinal 0 read the same image by construction; there is no separate root fixture to tell apart. A wrap or clamp of out-of-range keys would already fail, since lanes 61-63 would then select other candidates. What the fixture did miss is a null or out-of-bounds read, which also returns 0.a87175c0gives every candidate a nonzero value (the root is now 1.0), so such a read no longer matches the root. The test still fails with the shader commit reverted; the GPU suite run one case per process matches main.@coderabbitai[bot] on GitHub · 2026-10-09 18:35 UTC · original · reviewed
🧹 Nitpick comments (1)
ℹ️ Review info
⚙️ Run configuration
f36579ec-1039-4384-80f7-dd9bb7b93aa3📥 Commits
Reviewing files that changed from the base of the PR and between
cd48599dfeanda87175c075.📒 Files selected for processing (1)
tests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@NeySlim on GitHub · 2026-10-09 18:44 UTC · original
Fixed the mixed 2D/2D-array address layout in
eb1690a0(test in6e607830): loads and gathers through a candidate now read coordinates, LOD and sample index in the instruction's own layout. A component the instruction does not supply reads 0 and an extra one is dropped, the same rule (and the sameCoordF32change) as #1255 for samples. The new test loads LOD 1 with a 2D instruction through a table that holds a 2D-array candidate; it returned layer 1 before the fix and returns layer 0 of mip 1 now. The test fails with the shader commit reverted; the GPU suite run one case per process matches main. The PR description is updated.@ -35396,0 +35530,4 @@std::fill(pixels.begin() + width * 4u, pixels.end(), std::bit_cast<u32>(30.0f));textures.push_back(vulkan.CreateImageMips(name, width, 1, vk::Format::eR32G32B32A32Sfloat, vk::ImageUsageFlagBits::eSampled,{pixels, mip}, 4u, vk::ImageLayout::eShaderReadOnlyOptimal, vk::ImageType::e2D,@coderabbitai[bot] on GitHub · 2026-10-09 18:50 UTC · original · edited 2026-10-09 19:00 UTC
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Give candidate 0 a valid two-level mip chain.
Candidate 0 has width 1 and height 1, but
{pixels, mip}makesCreateImageMipsrequest two mip levels. Vulkan allows only one mip level for a 1×1 image, so image creation fails before this test checks any indirect operation. Start candidate widths at 2 and update the size-query expectations to match. (docs.vulkan.org)✅ Confirmed as addressed by @NeySlim
@coderabbitai[bot] on GitHub · 2026-10-09 18:50 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
220715a3-6d8e-4a39-9c16-e841013ef66c📥 Commits
Reviewing files that changed from the base of the PR and between
a87175c075and6e607830f8.📒 Files selected for processing (2)
src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 1 remain after this review.
@ -35396,0 +35530,4 @@std::fill(pixels.begin() + width * 4u, pixels.end(), std::bit_cast<u32>(30.0f));textures.push_back(vulkan.CreateImageMips(name, width, 1, vk::Format::eR32G32B32A32Sfloat, vk::ImageUsageFlagBits::eSampled,{pixels, mip}, 4u, vk::ImageLayout::eShaderReadOnlyOptimal, vk::ImageType::e2D,@NeySlim on GitHub · 2026-10-09 18:59 UTC · original
Right, a 1x1 image cannot have a second level. Fixed in
6b28b3fd: candidate widths now start at 2 (2, 3, 4, 5 x 1), so every candidate has a valid two-level chain, and the size-query expectations follow. The LOD-1 load still tells the two layouts apart: the 2D-array candidate's mip 1 holds 200 in layer 0 and 300 in layer 1, and the test fails with the layout commit reverted (and with both shader commits reverted). wave32 and wave64 pass; the GPU suite run one case per process matches main.@ -35396,0 +35530,4 @@std::fill(pixels.begin() + width * 4u, pixels.end(), std::bit_cast<u32>(30.0f));textures.push_back(vulkan.CreateImageMips(name, width, 1, vk::Format::eR32G32B32A32Sfloat, vk::ImageUsageFlagBits::eSampled,{pixels, mip}, 4u, vk::ImageLayout::eShaderReadOnlyOptimal, vk::ImageType::e2D,@coderabbitai[bot] on GitHub · 2026-10-09 19:00 UTC · original
@NeySlim, thanks for the fix. Widths 2–5 give every candidate a valid two-level mip chain. The distinct values of 200 and 300 still let the LOD-1 test detect an incorrect array-layer selection.If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!
✅ Review thread resolved.
You are interacting with an AI system.
Pull request closed