shader: vote EXEC/VCC branches across the native wave #1143

Closed
github-bot wants to merge 2 commits from gh-pr/1143/head into gh-pr/1143/base
Owner

@⁠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 merging

Problem

On a native 64-wide subgroup (no emulated halves), EmitConditionRef returned the per-invocation condition for S_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, then ErrorDeviceLost). The hung pipeline uses pixel shader 0xfb162b166301cb2d, which has several loops of this form:

s_ff1_i32_b32   s46, s45
s_cmp_eq_u32    -1, s46
s_cselect_b64   s[2:3], exec, 0
s_cmp_ge_u32    s46, s97
s_cselect_b64   vcc, exec, 0
s_or_b64        vcc, vcc, s[2:3]
s_cbranch_vccnz exit
...
s_bitset0_b32   s45, s46
s_branch        loop

Earlier, the shader discards pixels (s_andn2_b64 s4, s4, vcc + s_cbranch_scc0) and goes back to s_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-invocation vccnz never leaves the loop.

Change

In native mode, EXEC/VCC branch conditions are reduced with OpGroupNonUniformBallot:

  • NonZero kinds: taken when any invocation has the predicate.
  • Zero kinds: taken when no invocation has the negated predicate, so a partially populated subgroup still means "all lanes".

SCC and scalar-instruction conditions are unchanged, and so is the two-half path. AnalyzeProgramRequirements requests 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: BranchVccnzUsesWaveMask and BranchVccnzUsesCarryProducedWaveMask fail 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).
  • God of War Ragnarök: the GPU hang is gone. With my other pending fixes (#1118 and #1144), the game reaches its first setup screen.

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.

**@⁠NeySlim** on GitHub · 2026-10-07 14:44 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1143) `NeySlim:fix/native-wave-branch-vote` → `main` · +51 −1 · 2 files · 2 commits · closed without merging ## Problem On a native 64-wide subgroup (no emulated halves), `EmitConditionRef` returned the per-invocation condition for `S_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`, then `ErrorDeviceLost`). The hung pipeline uses pixel shader `0xfb162b166301cb2d`, which has several loops of this form: ``` s_ff1_i32_b32 s46, s45 s_cmp_eq_u32 -1, s46 s_cselect_b64 s[2:3], exec, 0 s_cmp_ge_u32 s46, s97 s_cselect_b64 vcc, exec, 0 s_or_b64 vcc, vcc, s[2:3] s_cbranch_vccnz exit ... s_bitset0_b32 s45, s46 s_branch loop ``` Earlier, the shader discards pixels (`s_andn2_b64 s4, s4, vcc` + `s_cbranch_scc0`) and goes back to `s_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-invocation `vccnz` never leaves the loop. ## Change In native mode, EXEC/VCC branch conditions are reduced with `OpGroupNonUniformBallot`: - NonZero kinds: taken when any invocation has the predicate. - Zero kinds: taken when no invocation has the negated predicate, so a partially populated subgroup still means "all lanes". SCC and scalar-instruction conditions are unchanged, and so is the two-half path. `AnalyzeProgramRequirements` requests 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`: `BranchVccnzUsesWaveMask` and `BranchVccnzUsesCarryProducedWaveMask` fail 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). - God of War Ragnarök: the GPU hang is gone. With my other pending fixes (#1118 and #1144), the game reaches its first setup screen. 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:44:49 +00:00
github-bot closed this pull request 2026-11-26 09:44:49 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-07 14:50 UTC · original · edited 2026-10-07 16:08 UTC

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0d3bcd35-4e4b-41b5-964d-4345f2a2e7d4
📥 Commits

Reviewing files that changed from the base of the PR and between 9730a812bd and c3b133d92c.

📒 Files selected for processing (2)
  • src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp
  • src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp

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 c3b13

On 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)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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 3 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely describes the main change: applying wave-wide voting to EXEC and VCC branch conditions on native waves.
Description check ✅ Passed The description directly explains the native wave64 branch-condition bug, the ballot-based fix, affected conditions, validation results, and known test limitations.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-07 14:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1143#issuecomment-6040536391) · edited 2026-10-07 16:08 UTC <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1143?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `0d3bcd35-4e4b-41b5-964d-4345f2a2e7d4` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 9730a812bd5b3476cb038a27ae4779cd5decc5b2 and c3b133d92ca7a74572e9a44fbbc2b6d2740bce51. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (2)</summary> * src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp * src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## 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. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬆️ High <!-- change_assessment_commit:"c3b133d92ca7a74572e9a44fbbc2b6d2740bce51" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🟡 Moderate_ · up to `c3b13` <!-- final_review_risk_coverage:{"sourceCommitId":"c3b133d92ca7a74572e9a44fbbc2b6d2740bce51","coveredCommitId":"c3b133d92ca7a74572e9a44fbbc2b6d2740bce51","kind":"reviewed"} --> On devices without ballot support in an affected graphics stage, shader pipeline creation may fail. Check stage-specific support before merging. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | 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 3 functions across 2 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Title check | ✅ Passed | The title clearly and concisely describes the main change: applying wave-wide voting to EXEC and VCC branch conditions on native waves. | | Description check | ✅ Passed | The description directly explains the native wave64 branch-condition bug, the ballot-based fix, affected conditions, validation results, and known test limitations. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1143)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -284,0 +287,4 @@
kind == CFG::BranchCondition::VccZero ||
kind == CFG::BranchCondition::ExecNonZero ||
kind == CFG::BranchCondition::VccNonZero) {
requirements.subgroup_ballot = true;
Author
Owner

@⁠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:

#!/bin/bash
# Inspect device admission and pipeline-stage checks for subgroup ballot support.
rg -n -C 4 'supportedStages|subgroupSupportedStages|supportedOperations|subgroupSupportedOperations|SUBGROUP_FEATURE_BALLOT|SupportsComputeWave64' src/graphics

Repository: KytyPS5/KytyPS5

Length of output: 3085


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- reviewed diff ---'
git diff --no-ext-diff --unified=40 bb98f26433fa9e711c219aac1711fe8ecba5bf3a 9730a812bd5b3476cb038a27ae4779cd5decc5b2 -- src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp
printf '%s\n' '--- subgroup ballot references ---'
rg -n -C 5 -F -- 'subgroup_ballot' src || test "$?" -eq 1
printf '%s\n' '--- subgroup Vulkan feature references ---'
rg -n -C 5 'subgroup.*(ballot|supported|feature)|Subgroup.*(Ballot|Supported|Feature)|VK_SUBGROUP_FEATURE_BALLOT_BIT|shaderSubgroupExtendedTypes|subgroupSupportedStages|supportedStages|supportedOperations' src || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 21740


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- all subgroup references in graphics ---'
rg -n -C 3 -i 'subgroup|groupnonuniform|group_non_uniform|ballot' src/graphics || test "$?" -eq 1
printf '%s\n' '--- Vulkan feature/property setup ---'
rg -n -C 4 'PhysicalDevice.*(Properties|Features)|getPhysicalDevice.*(Properties|Features)|DeviceCreateInfo|ShaderStageFlags|shader.*stage|feature.*(subgroup|group)' src/graphics || test "$?" -eq 1
printf '%s\n' '--- requirement and shader capability consumers ---'
rg -n -C 5 'SpirvRequirements|AnalyzeProgramRequirements|RequireCapability|requirements\.' src/graphics/shader src/graphics/host_gpu || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 42453


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- Vulkan initialization and feature chain ---'
sed -n '430,660p' src/graphics/presentation/window/vulkanWindow.cpp
printf '%s\n' '--- subgroup and requirement source excerpts ---'
sed -n '193,305p' src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp
sed -n '700,740p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp
sed -n '475,505p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp
printf '%s\n' '--- shader pipeline creation references ---'
rg -n -C 5 'CreateShaderModule|createShaderModule|ShaderModule|ShaderStageCreateInfo|ShaderStageFlagBits|Compile|Spirv' src/graphics/host_gpu src/graphics/shader src/graphics/presentation || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 40400


🏁 Script executed:

#!/bin/bash
set -u
printf '%s\n' '--- physical-device selection ---'
rg -n -C 8 'VulkanFindPhysicalDevice|FindPhysicalDevice|RequiredVulkan11Features|RequiredVulkan12Features|RequiredVulkan13Features' src
printf '%s\n' '--- Vulkan subgroup API identifiers across repository ---'
rg -n -C 4 -i 'subgroup.*(feature|operation|stage)|supported.*(operation|stage)|group.*non.*uniform|PhysicalDeviceSubgroupProperties|SubgroupFeature|subgroupSupported' . --glob '!build/**' --glob '!dist/**' --glob '!node_modules/**' || test "$?" -eq 1

Repository: KytyPS5/KytyPS5

Length of output: 42039


Check subgroup ballot support for each emitted shader stage.

Emitter::AnalyzeProgramRequirements sets subgroup_ballot without checking program.stage. The SPIR-V emitter then requires CapabilityGroupNonUniformBallot, and the ballot path emits OpGroupNonUniformBallot. Vulkan reports subgroup operation support and supported shader stages separately. The device setup checks subgroup-size control, but it does not check subgroupSupportedStages and subgroupSupportedOperations. 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 for VK_SUBGROUP_FEATURE_BALLOT_BIT and the stage mask before emitting or using this path.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-07 14:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1143#discussion_r4208402326) · edited 2026-10-07 15:59 UTC **🩺 Stability & Availability** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash # Inspect device admission and pipeline-stage checks for subgroup ballot support. rg -n -C 4 'supportedStages|subgroupSupportedStages|supportedOperations|subgroupSupportedOperations|SUBGROUP_FEATURE_BALLOT|SupportsComputeWave64' src/graphics ``` Repository: KytyPS5/KytyPS5 Length of output: 3085 --- 🏁 Script executed: ```bash #!/bin/bash set -u printf '%s\n' '--- reviewed diff ---' git diff --no-ext-diff --unified=40 bb98f26433fa9e711c219aac1711fe8ecba5bf3a 9730a812bd5b3476cb038a27ae4779cd5decc5b2 -- src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp printf '%s\n' '--- subgroup ballot references ---' rg -n -C 5 -F -- 'subgroup_ballot' src || test "$?" -eq 1 printf '%s\n' '--- subgroup Vulkan feature references ---' rg -n -C 5 'subgroup.*(ballot|supported|feature)|Subgroup.*(Ballot|Supported|Feature)|VK_SUBGROUP_FEATURE_BALLOT_BIT|shaderSubgroupExtendedTypes|subgroupSupportedStages|supportedStages|supportedOperations' src || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 21740 --- 🏁 Script executed: ```bash #!/bin/bash set -u printf '%s\n' '--- all subgroup references in graphics ---' rg -n -C 3 -i 'subgroup|groupnonuniform|group_non_uniform|ballot' src/graphics || test "$?" -eq 1 printf '%s\n' '--- Vulkan feature/property setup ---' rg -n -C 4 'PhysicalDevice.*(Properties|Features)|getPhysicalDevice.*(Properties|Features)|DeviceCreateInfo|ShaderStageFlags|shader.*stage|feature.*(subgroup|group)' src/graphics || test "$?" -eq 1 printf '%s\n' '--- requirement and shader capability consumers ---' rg -n -C 5 'SpirvRequirements|AnalyzeProgramRequirements|RequireCapability|requirements\.' src/graphics/shader src/graphics/host_gpu || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 42453 --- 🏁 Script executed: ```bash #!/bin/bash set -u printf '%s\n' '--- Vulkan initialization and feature chain ---' sed -n '430,660p' src/graphics/presentation/window/vulkanWindow.cpp printf '%s\n' '--- subgroup and requirement source excerpts ---' sed -n '193,305p' src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp sed -n '700,740p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp sed -n '475,505p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterProgram.cpp printf '%s\n' '--- shader pipeline creation references ---' rg -n -C 5 'CreateShaderModule|createShaderModule|ShaderModule|ShaderStageCreateInfo|ShaderStageFlagBits|Compile|Spirv' src/graphics/host_gpu src/graphics/shader src/graphics/presentation || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 40400 --- 🏁 Script executed: ```bash #!/bin/bash set -u printf '%s\n' '--- physical-device selection ---' rg -n -C 8 'VulkanFindPhysicalDevice|FindPhysicalDevice|RequiredVulkan11Features|RequiredVulkan12Features|RequiredVulkan13Features' src printf '%s\n' '--- Vulkan subgroup API identifiers across repository ---' rg -n -C 4 -i 'subgroup.*(feature|operation|stage)|supported.*(operation|stage)|group.*non.*uniform|PhysicalDeviceSubgroupProperties|SubgroupFeature|subgroupSupported' . --glob '!build/**' --glob '!dist/**' --glob '!node_modules/**' || test "$?" -eq 1 ``` Repository: KytyPS5/KytyPS5 Length of output: 42039 --- </details> **Check subgroup ballot support for each emitted shader stage.** `Emitter::AnalyzeProgramRequirements` sets `subgroup_ballot` without checking `program.stage`. The SPIR-V emitter then requires `CapabilityGroupNonUniformBallot`, and the ballot path emits `OpGroupNonUniformBallot`. Vulkan reports subgroup operation support and supported shader stages separately. The device setup checks subgroup-size control, but it does not check `subgroupSupportedStages` and `subgroupSupportedOperations`. 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 for `VK_SUBGROUP_FEATURE_BALLOT_BIT` and the stage mask before emitting or using this path. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:95deef63345d8df1cff88926 --> <!-- This is an auto-generated reply by CodeRabbit -->
@ -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);
Author
Owner

@⁠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:

#!/bin/bash
# Trace the selected and effective subgroup sizes through compute pipeline creation.
rg -n -C 5 'CreatePipelineInternal|SupportsComputeWave64|requiredSubgroupSize|host_subgroup_size|wave_size' src/graphics/host_gpu src/graphics/shader

Repository: KytyPS5/KytyPS5

Length of output: 41916


🏁 Script executed:

set -eu
printf '%s\n' '--- pipeline cache compute setup ---'
sed -n '640,710p' src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
printf '%s\n' '--- subgroup capability contract ---'
rg -n -C 8 'SupportsComputeWave64|subgroup_size|compute_subgroup_size_control_enabled|min_subgroup_size|max_subgroup_size' src/graphics/host_gpu
printf '%s\n' '--- compute pipeline creation ---'
sed -n '559,580p' src/graphics/host_gpu/renderer/pipeline/shaders.cpp
printf '%s\n' '--- emitter lane-count and condition lowering ---'
rg -n -C 12 'lane_count|OpGroupNonUniformBallot|EmitConditionRef' src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp

Repository: KytyPS5/KytyPS5

Length of output: 28591


Keep each ballot within one guest wave.

When program.wave_size is 32 and host_subgroup_size is 64, this ScopeSubgroup ballot includes two guest waves. A predicate bit in one guest wave can change the EXEC/VCC branch result in the other guest wave.

GetComputeProgram selects host subgroup64 when SupportsComputeWave64() returns true. That function returns true when the device subgroup size is 64, even when subgroup-size control is disabled. CreatePipelineInternal then 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](https://github.com/KytyPS5/KytyPS5/pull/1143#discussion_r4208402349) · edited 2026-10-07 16:07 UTC **🎯 Functional Correctness** | **🟠 Major** | **🏗️ Heavy lift** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash # Trace the selected and effective subgroup sizes through compute pipeline creation. rg -n -C 5 'CreatePipelineInternal|SupportsComputeWave64|requiredSubgroupSize|host_subgroup_size|wave_size' src/graphics/host_gpu src/graphics/shader ``` Repository: KytyPS5/KytyPS5 Length of output: 41916 --- 🏁 Script executed: ```bash set -eu printf '%s\n' '--- pipeline cache compute setup ---' sed -n '640,710p' src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp printf '%s\n' '--- subgroup capability contract ---' rg -n -C 8 'SupportsComputeWave64|subgroup_size|compute_subgroup_size_control_enabled|min_subgroup_size|max_subgroup_size' src/graphics/host_gpu printf '%s\n' '--- compute pipeline creation ---' sed -n '559,580p' src/graphics/host_gpu/renderer/pipeline/shaders.cpp printf '%s\n' '--- emitter lane-count and condition lowering ---' rg -n -C 12 'lane_count|OpGroupNonUniformBallot|EmitConditionRef' src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 28591 --- </details> **Keep each ballot within one guest wave.** When `program.wave_size` is 32 and `host_subgroup_size` is 64, this `ScopeSubgroup` ballot includes two guest waves. A predicate bit in one guest wave can change the EXEC/VCC branch result in the other guest wave. `GetComputeProgram` selects host subgroup64 when `SupportsComputeWave64()` returns true. That function returns true when the device subgroup size is 64, even when subgroup-size control is disabled. `CreatePipelineInternal` then 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. <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:9a29bf8afeff030f90b338a3 --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit c3b133d
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-07 14:50 UTC · original · reviewed

Actionable comments posted: 2


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: f367f554-1d26-4e1b-9547-79a8838ac214
📥 Commits

Reviewing files that changed from the base of the PR and between d2413fc2eb and 9730a812bd.

📒 Files selected for processing (2)
  • src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-07 14:50 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1143#pullrequestreview-5444136260) · **reviewed** **Actionable comments posted: 2** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `f367f554-1d26-4e1b-9547-79a8838ac214` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between d2413fc2ebd91d1b7234197c2dd5bd48e1cb6a51 and 9730a812bd5b3476cb038a27ae4779cd5decc5b2. </details> <details> <summary>📒 Files selected for processing (2)</summary> * `src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=d758806c-2cea-401b-87b8-10592143e2af attempt=ae8f2b0d-cea3-4af9-83a5-b68086038bd4 batch=1/1 -->
@ -284,0 +287,4 @@
kind == CFG::BranchCondition::VccZero ||
kind == CFG::BranchCondition::ExecNonZero ||
kind == CFG::BranchCondition::VccNonZero) {
requirements.subgroup_ballot = true;
Author
Owner

@⁠NeySlim on GitHub · 2026-10-07 15:59 UTC · original

The emitter already requires GroupNonUniformBallot through the same subgroup_ballot flag 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 on subgroupSupportedStages and subgroupSupportedOperations would cover all of these uses, so it belongs in a separate change.

**@⁠NeySlim** on GitHub · 2026-10-07 15:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1143#discussion_r4209065897) The emitter already requires `GroupNonUniformBallot` through the same `subgroup_ballot` flag 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 on `subgroupSupportedStages` and `subgroupSupportedOperations` would 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);
Author
Owner

@⁠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 >= 32 selects 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.

**@⁠NeySlim** on GitHub · 2026-10-07 15:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1143#discussion_r4209066222) Fixed in c3b133d. For a wave32 program, the vote now uses only the ballot word of the invocation's own guest wave: `SubgroupLocalInvocationId >= 32` selects 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;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-07 15:59 UTC · original

@NeySlim, agreed. The existing operations use the same subgroup_ballot requirement. 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
Learnt from: NeySlim
Repo: KytyPS5/KytyPS5 PR: 1143
File: src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp:286-290
Timestamp: 2026-10-07T15:59:32.375Z
Learning: In KytyPS5/KytyPS5, the C++ SPIR-V backend's Emitter::AnalyzeProgramRequirements in src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp already sets subgroup_ballot for Ballot, ReadFirstLane, ReadLane, and DppMoveU32 without a per-stage check. Vulkan admission checks for subgroupSupportedStages and subgroupSupportedOperations should cover all subgroup ballot users as a shared backend change, rather than be treated as a requirement specific to EXEC/VCC ConditionRef emission.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.

✅ Review thread resolved.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-07 15:59 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1143#discussion_r4209070629) `@NeySlim`, agreed. The existing operations use the same `subgroup_ballot` requirement. 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? --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: NeySlim Repo: KytyPS5/KytyPS5 PR: 1143 File: src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp:286-290 Timestamp: 2026-10-07T15:59:32.375Z Learning: In KytyPS5/KytyPS5, the C++ SPIR-V backend's Emitter::AnalyzeProgramRequirements in src/graphics/shader/recompiler/backend/spirv/SpirvEmitter.cpp already sets subgroup_ballot for Ballot, ReadFirstLane, ReadLane, and DppMoveU32 without a per-stage check. Vulkan admission checks for subgroupSupportedStages and subgroupSupportedOperations should cover all subgroup ballot users as a shared backend change, rather than be treated as a requirement specific to EXEC/VCC ConditionRef emission. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
@ -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);
Author
Owner

@⁠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
Learnt from: NeySlim
Repo: KytyPS5/KytyPS5 PR: 1143
File: src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp:723-724
Timestamp: 2026-10-07T16:07:34.608Z
Learning: In KytyPS5/KytyPS5, compute pipeline creation in src/graphics/host_gpu/renderer/pipeline/shaders.cpp requests subgroup size 32 for guest wave32 programs when subgroup-size control is available. Guest wave32 programs can share a native subgroup64 when subgroup-size control is unavailable, so subgroup votes must isolate each guest wave.

Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure review instructions. You can manage existing learnings in the app.


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-10-07 16:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1143#discussion_r4209152537) `@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. --- <details> <summary>✏️ Learnings added</summary> ``` Learnt from: NeySlim Repo: KytyPS5/KytyPS5 PR: 1143 File: src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp:723-724 Timestamp: 2026-10-07T16:07:34.608Z Learning: In KytyPS5/KytyPS5, compute pipeline creation in src/graphics/host_gpu/renderer/pipeline/shaders.cpp requests subgroup size 32 for guest wave32 programs when subgroup-size control is available. Guest wave32 programs can share a native subgroup64 when subgroup-size control is unavailable, so subgroup votes must isolate each guest wave. ``` > Note: Learnings are effective only in the context of similar code segments. To apply general coding guidelines, please configure [review instructions](https://docs.coderabbit.ai/guides/review-instructions). You can manage existing learnings in the [app](https://app.coderabbit.ai/learnings). </details> --- <!-- This is an auto-generated comment: tweet message by coderabbit.ai --> If you found this review helpful, would you consider giving us a shout-out on [X](https://twitter.com/intent/tweet?related=CodeRabbitAI&text=Keep%20GPU%20ballots%20within%20each%20guest%20wave%3A%20wave32%20programs%20on%20host%20subgroup64%20must%20use%20their%20own%20ballot%20word%20to%20prevent%20cross-wave%20EXEC%2FVCC%20bugs.%20%40coderabbitai%20catches%20subtle%20issues%E2%80%94try%20it!%20%F0%9F%90%87&url=https%3A%2F%2Fgithub.com%2FKytyPS5%2FKytyPS5%2Fpull%2F1143%23discussion_r4208402349)? Thank you for using CodeRabbit! <!-- end of auto-generated comment: tweet message by coderabbit.ai --> ✅ Review thread resolved. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠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. BranchVccnzUsesWaveMask and BranchVccnzUsesCarryProducedWaveMask, which this PR was fixing, pass on current main without it, and God of War Ragnarök no longer hangs there.

**@⁠NeySlim** on GitHub · 2026-10-08 20:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1143#issuecomment-6068410837) Closing: a8beac19 ("shader: evaluate scalar branch decisions across the complete guest wave") now makes the same whole-wave decision on main. `BranchVccnzUsesWaveMask` and `BranchVccnzUsesCarryProducedWaveMask`, which this PR was fixing, pass on current main without it, and God of War Ragnarök no longer hangs there.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.