Keep wave32 votes and reductions inside the caller's half #2136
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!2136
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2136/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 09:31 UTC · original
theantipopau:fix/wave32-vote-reduce→main· +165 −19 · 7 files · 2 commits · closed without mergingSummary
A wave32 guest wave occupies one half of a 64-lane native subgroup, but its votes and reductions were subgroup-wide, so the wave sharing that subgroup contributed its own EXEC and values.
s_cbranch_execz/vccz/sccz/nz) now compare the caller's ballot word;Alltests that word against its own active lanes.OpGroupNonUniformUMin/UMax/BitwiseOrlower to a five-stepOpGroupNonUniformShuffleXorbutterfly over the five lane bits of the caller's half instead of a subgroup-wide reduction, so the wave never reads the other half.Tests
shader_recompiler_compute_tests: 997/997, including the newVectorBranchVoteStaysInsideWave32(wave0 takes the branch, wave1 does not) and the updatedScalarBranchRestoresInactiveWave32, which now requires the ballot-word vote and forbidsOpGroupNonUniformAny.shader_cfg_tests: newTestSpirvWave32HalfReductionsrequires 15OpGroupNonUniformShuffleXorand no subgroup-wide arithmetic on a 64-lane host, and keeps one native op per reduction on a 32-lane host.ctestin_Build/windows: 82/82.kyty_emulatorbuilds.@coderabbitai[bot] on GitHub · 2026-11-06 09:41 UTC · original · edited 2026-11-06 22:05 UTC
Walkthrough
The SPIR-V emitter now distinguishes wave32 execution on a host subgroup of a different size. In that configuration, it limits vote evaluation and subgroup reductions to the caller’s half. Other configurations retain their existing paths. Tests check generated SPIR-V expectations for wide-host and native subgroup handling.
Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Moderate · up to
4120fWave32 reductions on 64-lane hosts may produce undefined results when the host subgroup is only partly populated. Resolve or explicitly accept that risk before merging. The new tests also do not check ballot-word selection or shuffle masks, so they would miss some future regressions.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 50.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 6 functions across 5 files. (2 skipped: 2 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
@ -822,0 +829,4 @@}const auto active = ctx.HalfBallotWord(ctx.Ballot(IR::Value(true)));const auto yes = EmitBinaryU32(ctx.state, spv::OpBitwiseAnd, word, active);return EmitNative<spv::OpIEqual, IR::Type::U1>(ctx.state, yes, active);@coderabbitai[bot] on GitHub · 2026-11-06 09:41 UTC · original
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 21840
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9793
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 29273
Web query:
Vulkan specification compute shader SubgroupLocalInvocationId LocalInvocationIndex mapping implementation dependent subgroup invocation order guaranteeResult:
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7686
Keep the vote within the guest wave.
On a 64-lane subgroup, Vulkan can assign local invocation indices to subgroup lanes in a different order. In that case, the selected ballot word can contain lanes from different guest waves and omit lanes from the caller’s wave. The vote can then produce an incorrect branch decision.
@ -857,0 +874,4 @@state, scope, value, ConstantU32(state, mask));value = Combine(state, value, shuffled);}return value;@coderabbitai[bot] on GitHub · 2026-11-06 09:41 UTC · original
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 185
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19527
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 43229
Web query:
SPIR-V specification OpGroupNonUniformShuffleXor inactive invocation result undefined OpGroupNonUniformUMin active invocationsResult:
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 37601
Handle inactive host invocations in wave32 reductions.
A partial host subgroup can make the butterfly read an inactive invocation and produce an undefined reduction result. Full guest EXEC does not guarantee that all 32 host invocations exist.
Reduce all active invocations in the caller’s half. Masking guest EXEC-disabled inputs alone does not fix shuffles from missing host invocations.
@coderabbitai[bot] on GitHub · 2026-11-06 09:41 UTC · original
On
tests/ShaderRecompilerComputeTests.cppline 29855 (outdated):Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6061
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 35309
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 36163
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7407
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3661
Make wave32 instruction checks depend on the host subgroup size.
On a 32-lane host, the emitter uses
OpGroupNonUniformAnyfor these nonzero branches, but the wave32 checks forbid it. The tests can fail before comparing shader output. Apply the ballot-specific checks only when wave32 shares a wider host subgroup.@coderabbitai[bot] on GitHub · 2026-11-06 09:41 UTC · original · reviewed
Actionable comments posted: 3
6965f39d-267c-431c-b0f5-46d024e3d321Reviewing files that changed from the base of the PR and between
b6cc1fff27and fc907239637c09f791939334e065d008fe05b964.src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.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.
@coderabbitai[bot] on GitHub · 2026-11-06 22:05 UTC · original · reviewed
6861293a-d256-4482-aca2-a5e640882ba6Reviewing files that changed from the base of the PR and between fc907239637c09f791939334e065d008fe05b964 and
4120ffc001.tests/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.
Pull request closed