shader: vote EXEC/VCC branches across the native wave #1143
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!1143
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1143/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-07 14:44 UTC · original
NeySlim:fix/native-wave-branch-vote→main· +51 −1 · 2 files · 2 commits · closed without mergingProblem
On a native 64-wide subgroup (no emulated halves),
EmitConditionRefreturned the per-invocation condition forS_CBRANCH_VCCZ/VCCNZ/EXECZ/EXECNZ. These branches test the whole wave mask, so invocations whose EXEC bit is clear could take a different path from the active lanes.God of War Ragnarök (PPSA08332, 05.005) hangs the GPU a few seconds into boot on RADV (
ring gfx timeout, thenErrorDeviceLost). The hung pipeline uses pixel shader0xfb162b166301cb2d, which has several loops of this form:Earlier, the shader discards pixels (
s_andn2_b64 s4, s4, vcc+s_cbranch_scc0) and goes back tos_wqm_b64 exec, s4. An invocation whose whole quad was discarded keeps running with EXEC clear. For that invocation VCC is always 0, so a per-invocationvccnznever leaves the loop.Change
In native mode, EXEC/VCC branch conditions are reduced with
OpGroupNonUniformBallot:SCC and scalar-instruction conditions are unchanged, and so is the two-half path.
AnalyzeProgramRequirementsrequests the ballot capability for these ConditionRefs.This follows the ISA (RDNA2 ISA reference, S_CBRANCH_VCCNZ: "if VCC != 0 then jump", VCC being the 64-bit wave mask) and the point made in #933.
Validation
Linux, AMD Radeon 8060S (RDNA 3.5), Mesa RADV 26.2.3, native wave64 subgroup.
shader_recompiler_compute_tests:BranchVccnzUsesWaveMaskandBranchVccnzUsesCarryProducedWaveMaskfail on main (actual [0x2a, 0x0b, 0x0b, 0x0b, 0x2a, 0x0b, 0x0b, 0x0b]) and pass with this change. I ran each of the 543 cases in its own process, with and without the change: these two cases are the only difference. On this setup, 10 cases fail on main with or without the change (GpuTilerCpuParity, NativeIndirectDispatch, UnifiedTextureCacheFlow, UnifiedImageViewCache, VectorFractF16CapturedAndEdges, VectorFractF64CapturedAndEdges, VectorF64ModesModifiersAndExec, BufferUshortHostOffsetFirst, BufferStoreFormatXAddTidUsesLaneIndex, DsAppendAllocatesAcrossWaves32).Not tested on NVIDIA: the two-half path is not touched.
Not tested on Windows. The change only affects the generated SPIR-V, with no platform-specific code: on AMD the native wave64 path is the same on both systems.
AI use
I used Claude Code (AI agent) to investigate the hang, write the change and run the tests above on my machine. I reviewed the diff and the results before opening this PR.
@coderabbitai[bot] on GitHub · 2026-10-07 14:50 UTC · original · edited 2026-10-07 16:08 UTC
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
0d3bcd35-4e4b-41b5-964d-4345f2a2e7d4📥 Commits
Reviewing files that changed from the base of the PR and between
9730a812bdandc3b133d92c.📒 Files selected for processing (2)
src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp🚧 Files skipped from review as they are similar to previous changes (2)
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
The SPIR-V backend now requires subgroup ballot support for EXEC and VCC zero or nonzero conditions. When no paired wave half is present, condition emission uses a subgroup ballot and tests the applicable ballot word or words. For wave32 on a 64-lane host, it selects the word for the current guest wave. Other condition kinds return the input predicate. The paired-half path remains unchanged.
Priority: ⬆️ High
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
c3b13On devices without ballot support in an affected graphics stage, shader pipeline creation may fail. Check stage-specific support before merging.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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.@ -284,0 +287,4 @@kind == CFG::BranchCondition::VccZero ||kind == CFG::BranchCondition::ExecNonZero ||kind == CFG::BranchCondition::VccNonZero) {requirements.subgroup_ballot = true;@coderabbitai[bot] on GitHub · 2026-10-07 14:50 UTC · original · edited 2026-10-07 15:59 UTC
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 3085
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 21740
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42453
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 40400
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42039
Check subgroup ballot support for each emitted shader stage.
Emitter::AnalyzeProgramRequirementssetssubgroup_ballotwithout checkingprogram.stage. The SPIR-V emitter then requiresCapabilityGroupNonUniformBallot, and the ballot path emitsOpGroupNonUniformBallot. Vulkan reports subgroup operation support and supported shader stages separately. The device setup checks subgroup-size control, but it does not checksubgroupSupportedStagesandsubgroupSupportedOperations. An affected pipeline can therefore fail shader or pipeline creation on a device without ballot support for that stage. Add a device or pipeline admission check forVK_SUBGROUP_FEATURE_BALLOT_BITand the stage mask before emitting or using this path.@ -703,0 +721,4 @@const auto combined = state.builder.AllocateId();const auto result = state.builder.AllocateId();state.builder.AddFunction(spv::OpGroupNonUniformBallot, TypeU32Vector(state, 4), ballot,ConstantU32(state, spv::ScopeSubgroup), predicate);@coderabbitai[bot] on GitHub · 2026-10-07 14:50 UTC · original · edited 2026-10-07 16:07 UTC
🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 41916
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 28591
Keep each ballot within one guest wave.
When
program.wave_sizeis 32 andhost_subgroup_sizeis 64, thisScopeSubgroupballot includes two guest waves. A predicate bit in one guest wave can change the EXEC/VCC branch result in the other guest wave.GetComputeProgramselects host subgroup64 whenSupportsComputeWave64()returns true. That function returns true when the device subgroup size is 64, even when subgroup-size control is disabled.CreatePipelineInternalthen does not request the program wave size. If this pairing is possible, select subgroup32 for guest wave32 or restrict the ballot to its guest wave.✅ Addressed in commit
c3b133d@coderabbitai[bot] on GitHub · 2026-10-07 14:50 UTC · original · reviewed
Actionable comments posted: 2
ℹ️ Review info
⚙️ Run configuration
f367f554-1d26-4e1b-9547-79a8838ac214📥 Commits
Reviewing files that changed from the base of the PR and between
d2413fc2eband9730a812bd.📒 Files selected for processing (2)
src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@ -284,0 +287,4 @@kind == CFG::BranchCondition::VccZero ||kind == CFG::BranchCondition::ExecNonZero ||kind == CFG::BranchCondition::VccNonZero) {requirements.subgroup_ballot = true;@NeySlim on GitHub · 2026-10-07 15:59 UTC · original
The emitter already requires
GroupNonUniformBallotthrough the samesubgroup_ballotflag for ReadFirstLane, ReadLane, DPP moves and the Ballot opcode, in every stage and with no per-stage check. This path adds no new device requirement. An admission check onsubgroupSupportedStagesandsubgroupSupportedOperationswould cover all of these uses, so it belongs in a separate change.@ -703,0 +721,4 @@const auto combined = state.builder.AllocateId();const auto result = state.builder.AllocateId();state.builder.AddFunction(spv::OpGroupNonUniformBallot, TypeU32Vector(state, 4), ballot,ConstantU32(state, spv::ScopeSubgroup), predicate);@NeySlim on GitHub · 2026-10-07 15:59 UTC · original
Fixed in
c3b133d. For a wave32 program, the vote now uses only the ballot word of the invocation's own guest wave:SubgroupLocalInvocationId >= 32selects the upper word. When subgroup size control is available, compute pipelines already request subgroup 32 for wave32, so this only matters on devices without it. I ran the 543 compute cases again one by one: the results are unchanged.@ -284,0 +287,4 @@kind == CFG::BranchCondition::VccZero ||kind == CFG::BranchCondition::ExecNonZero ||kind == CFG::BranchCondition::VccNonZero) {requirements.subgroup_ballot = true;@coderabbitai[bot] on GitHub · 2026-10-07 15:59 UTC · original
@NeySlim, agreed. The existing operations use the samesubgroup_ballotrequirement. The missing stage and operation admission checks are a shared backend concern, not specific to this change. I withdraw this finding from#1143.Thanks for the clarification. Would you like me to open a follow-up issue for the shared admission checks?
✏️ Learnings added
✅ Review thread resolved.
You are interacting with an AI system.
@ -703,0 +721,4 @@const auto combined = state.builder.AllocateId();const auto result = state.builder.AllocateId();state.builder.AddFunction(spv::OpGroupNonUniformBallot, TypeU32Vector(state, 4), ballot,ConstantU32(state, spv::ScopeSubgroup), predicate);@coderabbitai[bot] on GitHub · 2026-10-07 16:07 UTC · original
@NeySlim, thanks for the fix and the clarification. The supplied code selects only the ballot word for the invocation’s own guest wave32. This prevents one guest wave from changing the other guest wave’s EXEC/VCC branch result.Thanks for rerunning all 543 compute cases.
✏️ Learnings added
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.
@NeySlim on GitHub · 2026-10-08 20:25 UTC · original
Closing:
a8beac19("shader: evaluate scalar branch decisions across the complete guest wave") now makes the same whole-wave decision on main.BranchVccnzUsesWaveMaskandBranchVccnzUsesCarryProducedWaveMask, which this PR was fixing, pass on current main without it, and God of War Ragnarök no longer hangs there.Pull request closed