shader: share indirect image query bodies inside the caller's wave #2142
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!2142
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2142/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?
@theantipopau on GitHub · 2026-11-06 23:00 UTC · original
theantipopau:fix/indirect-image-query-wave→main· +431 −29 · 13 files · 7 commits · closed without mergingThis is stacked on #2136 (fix/wave32-vote-reduce): the first two commits belong to that PR and drop out of this diff once it lands. The three new commits are the indirect-image work, its wave-local vote fix, and the test-contract update.
Upstream already supports dynamic indirect image tables and per-candidate query selection. What is still missing is the long-table path: a materialized image array can hold hundreds of candidates, and one static query body per candidate grows the module with the array.
Local checks on this AMD machine: the filtered indirect-image compute group passes and shader_cfg_tests exits 0. The full compute suite stops earlier in GpuSelectedFormattedRgba16Store, a pre-existing failure of this branch's base on this driver.
@coderabbitai[bot] on GitHub · 2026-11-06 23:08 UTC · original · edited 2026-11-08 22:15 UTC
Walkthrough
The SPIR-V emitter now tracks host subgroup size. For wave32 guest execution on a wider host subgroup, it uses ballot-based condition votes and XOR shuffle reductions. Large indirect image-dimension queries use shared loops over compatible candidate groups, while smaller lists use an index switch. Tests cover wide-host and matching-size subgroup cases, query instruction counts, and emitted SPIR-V.
Suggested reviewers:
nmzikChange: Refactor
Merge Risk:
Moderate · previous review
6b923After switching to a GPU with a different subgroup size, stale cached shaders can produce wrong results for wave32 votes or reductions. Include the subgroup size in the shader-store header before merging.
Pre-merge checks:
4 ·
1
Full details: Title check
Explanation
The title names the main change: indirect image query bodies are shared in a wave-uniform loop. The changeset adds EmitSharedIndirectImageQuery, which groups consecutive descriptor slots into shared loops, and the wave-local ballot handling matches the 'inside the caller's wave' part. It is specific and single-sentence, though it uses internal jargon. This is a PASS.
Full details: Description check
Explanation
The description states the purpose of the change: a long-table path for indirect image queries, where consecutive descriptor slots share a wave-uniform loop. It also explains the wave32 ballot-word vote fix, the test updates, and the local test results. It relates directly to the changeset, so this is a PASS.
Full details: Docstring Coverage
Explanation
Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 12 functions across 10 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
@ -466,0 +466,4 @@// A 32-lane guest wave that shares its native subgroup with a second guest wave.bool WideWave32(const EmitterState& state) {return state.program.wave_size == 32u && state.host_subgroup_size != 32u;}@coderabbitai[bot] on GitHub · 2026-11-06 23:08 UTC · original · edited 2026-11-07 04:25 UTC
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 10079
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 27054
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 29963
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 10812
Web query:
Vulkan SPIR-V SubgroupLocalInvocationId fragment helper invocations ballot helper invocations undefined OpGroupNonUniformShuffleXor inactive invocationResult:
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 24586
Web query:
Vulkan SPIR-V OpGroupNonUniformShuffleXor resulting value undefined inactive invocation mask subgroup current invocation specificationResult:
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 13869
Use the host subgroup size for non-workgroup stages.
On a 32-lane host, a wave32 pixel shader still takes the wide-wave reduction path. If an invocation is inactive, the shuffle reduction can produce an undefined result. Pass the host subgroup size to these stages so they use the native reduction on 32-lane hosts.
✅ Addressed in commit 9fe7cc0
@coderabbitai[bot] on GitHub · 2026-11-06 23:08 UTC · original · reviewed
Actionable comments posted: 1
2df24dc6-7819-40b8-be78-fabec9b71ef5Reviewing files that changed from the base of the PR and between
182161eb3eand c01de550add44cf736725b4398bd7de183b8f689.src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpptests/ShaderRecompilerComputeTests.cpptests/shaderCfgTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -466,0 +466,4 @@// A 32-lane guest wave that shares its native subgroup with a second guest wave.bool WideWave32(const EmitterState& state) {return state.program.wave_size == 32u && state.host_subgroup_size != 32u;}@theantipopau on GitHub · 2026-11-07 04:24 UTC · original
Fixed in 9fe7cc04: the pipeline cache now passes the device subgroup size for non-workgroup stages, so wave32 pixel shaders use native subgroup reductions on 32-lane hosts. Added a pixel-stage regression test that fails without the emitter change.
@ -466,0 +466,4 @@// A 32-lane guest wave that shares its native subgroup with a second guest wave.bool WideWave32(const EmitterState& state) {return state.program.wave_size == 32u && state.host_subgroup_size != 32u;}@coderabbitai[bot] on GitHub · 2026-11-07 04:24 UTC · original
@theantipopau Thanks for fixing this and adding the pixel-stage regression test.
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.
@coderabbitai[bot] on GitHub · 2026-11-07 11:57 UTC · original · reviewed
089fe69a-2df6-4627-aa68-675b61590881Reviewing files that changed from the base of the PR and between 9fe7cc040dda2d3a60e5ad8dd41e7da18697a662 and 8cf6a47642f1f59ebc2f89b82438123fcbc70263.
tests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -390,1 +390,4 @@}if (ShaderWorkgroupInput(options.stage, options.input_info) == nullptr) {// Graphics stages have no workgroup metadata; their native subgroups are the device's.options.host_subgroup_size = m_graphics.subgroup_size;@coderabbitai[bot] on GitHub · 2026-11-07 20:11 UTC · original · edited 2026-11-07 21:24 UTC
Include the subgroup size in shader-store invalidation.
If a user switches GPUs with different subgroup sizes but matching shader-store headers,
WarmUpreloads graphics SPIR-V compiled for the old size. The graphics stage keys also omit this value, soGetProgramcan reuse that module and produce incorrect wave32 votes or reductions. Includem_graphics.subgroup_sizein the shader-store header so incompatible records are discarded before warm-up. (raw.githubusercontent.com)✅ Addressed in commits e3c2f9f to 444395a
@coderabbitai[bot] on GitHub · 2026-11-07 20:11 UTC · original · reviewed
Actionable comments posted: 1
a5639657-8abd-4917-92c5-81c5306d033cReviewing files that changed from the base of the PR and between bd6391f45405caabb956a740074dd506d5983ae9 and 6b923372ae53dff81b70d9c64461d0f2b62611da.
src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpptests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
@ -390,1 +390,4 @@}if (ShaderWorkgroupInput(options.stage, options.input_info) == nullptr) {// Graphics stages have no workgroup metadata; their native subgroups are the device's.options.host_subgroup_size = m_graphics.subgroup_size;@theantipopau on GitHub · 2026-11-07 21:23 UTC · original
Fixed in 444395a: the shader store header now records the host subgroup size and the compute subgroup-control flag, so records compiled for different wave behaviour are discarded before WarmUp.
@ -390,1 +390,4 @@}if (ShaderWorkgroupInput(options.stage, options.input_info) == nullptr) {// Graphics stages have no workgroup metadata; their native subgroups are the device's.options.host_subgroup_size = m_graphics.subgroup_size;@coderabbitai[bot] on GitHub · 2026-11-07 21:25 UTC · original
Analysis chain
Script executed:
Length of output: 22271
Script executed:
Length of output: 12598
@theantipopauVerified in444395a:StoreHeaderincludes both values, andWarmUploads records only when the header matches. I did not run tests.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.
@Nawid3333 on GitHub · 2026-11-10 00:36 UTC · original
@theantipopau I ran
d992f09f8against its base9ffbe8550on an RX 9070 XT (Windows). The run wasshader_recompiler_compute_testswith the graphics cases enabled, using our lab overlays: keep-going, andVectorMinMaxF64CapturedAndEdgesskipped because it crashes this driver. I also ranshader_cfg_tests.shader_cfg_testsexits 0 on both.IndirectImageQueryDimensionsfails on the base and on upstream main (6fd43ac65) and passes with this PR. On the base, lane 1 gets{1,1,0,2}instead of{2,1,0,3}. That is the driver behaviour reported in #1624: on this GPU aNonUniformimage size/levels query takes the descriptor of the subgroup's first lane, while the Ryzen 7600X iGPU passes the same standalone repro. So the static per-candidate bodies are what make this query correct on the RX 9070 XT. The shared loop also uses a wave-uniform slot index, which should avoid this descriptor-selection bug, but these runs do not execute that path.Two points:
wantedcomes from a ballot orOpGroupNonUniformAny, and Vulkan allows helper invocations to be inactive for those. A candidate that only a helper lane selects can then be skipped, and that lane keeps the carried value. Live fragments are affected when that result feeds derivatives or quad operations. Running the body unconditionally in pixel shaders, or always using the per-candidate switch in pixel shaders whatever the candidate count, would avoid it.Pull request closed