recompiler: mask the buffer lane by the guest wave size #935
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!935
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/935/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-09-29 23:11 UTC · original
theantipopau:buffer-lane-wave-mask→main· +6 −1 · 1 files · 3 commits · closed without mergingWhat
BufferLanemasksSubgroupLocalInvocationIdwith a hardcoded63:It is used for
MUBUFadd_tidand for the packed per-lane stride path, both of which address bythe guest wave lane. Masking with 63 is only right if the host subgroup is 64 lanes wide —
and for a wave32 shader it is usually not the right width at all.
Why the host subgroup can be wider than the guest wave
Nothing in the pipeline declares
VK_SUBGROUP_SIZE_CONTROL.OpExecutionModenever carriesSubgroupSizeControl;spirvEmitterModule.cppemitsExecutionModeLocalSizeonly. MeanwhilevulkanWindow.cpp:587already enablesVkPhysicalDeviceVulkan13Features::subgroupSizeControlatdevice creation, so the driver is free to choose whatever subgroup width it likes for a 32-lane
guest wave.
On my AMD GPU (
subgroup_size == 64) that choice is a single 64-wide subgroup, soSubgroupLocalInvocationIdcomes back as the flat thread id and& 63is a no-op. The existingBufferStoreFormatXAddTidUsesLaneIndexcase shows it exactly — a 64-thread workgroup withwave_size = 32storesMUBUF ... add_tid0x12345678, and should only fill dwords 0–31:Every lane addressed by the flat thread id instead of the wave lane. With this change the case
passes unchanged — I did not weaken the test to accommodate the bug.
The fix
Mask by the wave size the shader was compiled for:
On a device whose subgroup already matches the guest wave this is a no-op — a 32-wide subgroup
under
& 31, a 64-wide one under& 63. It only changes behaviour where the previous mask wasdemonstrably wrong.
For wave64 on a 32-wide host subgroup,
EmitSubgroupLocalInvocationIdadds 32 for the upper halfbefore this mask is applied, so
& 63still yields 0–63 as before.Scope
This is deliberately the narrow part.
ValueEmitContext::BallotusesScopeSubgroup, whichballots across the host subgroup rather than the guest wave, and
DsAppendAllocatesAcrossWaves32fails on the same machine for that reason (256 threads at
wave_size = 32expects 8 waves andgets 4). Masking a lane id cannot fix a ballot that spans the wrong number of lanes.
The complete fix is to declare
SubgroupSizeControl = RequireSizefor compute — 32 for wave32,64 for wave64 — gated on
VK_EXT_subgroup_size_controlactually being available. I have leftthat out here because it touches device-capability plumbing and shader validity (the test harness
does not enable that feature today either), and I cannot validate it against a real game from
this machine.
Testing
shader_recompiler_compute_testswith #930 merged in so the suite runs to completion on my GPU.BufferStoreFormatXAddTidUsesLaneIndexgoes from failing to passing with no change to the case.@coderabbitai[bot] on GitHub · 2026-09-29 23:18 UTC · original · edited 2026-10-06 04:54 UTC
📝 Walkthrough
Walkthrough
BufferLanenow selects its invocation ID mask based on the guest wave size. It uses mask 63 when the wave size is at least 64, and mask 31 otherwise.Suggested reviewers:
nmzikPriority: ⬇️ Low
Change: Bug fix
Merge Risk: 🟡 Moderate · up to
6de93Some valid wave32 compute workloads can address the wrong buffer element on devices using wider host subgroups, producing incorrect shader results. Resolve the lane source 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.@theantipopau on GitHub · 2026-09-29 23:30 UTC · original
A note on CI, since it has now bitten three of my PRs on the same job:
Both are the macOS runner failing to reserve the large fixed guest-memory mappings, in tests that
touch neither area of the change. Both pass on a re-run. I have hit this on unrelated branches and
it seems to be fairly frequent — worth a look at whether the macOS job needs a larger runner or a
retry, because as it stands a correct PR can go red for a reason unrelated to its diff, and a
reviewer has no way to tell that from a real failure without pulling the log.
Not a blocker for this PR; flagging it because it will keep happening.
@coderabbitai[bot] on GitHub · 2026-10-06 04:51 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
d955d3ab-8a2d-4467-ad95-49a561aed0cd📥 Commits
Reviewing files that changed from the base of the PR and between
81ebf3a5b6and6de936ff94.📒 Files selected for processing (1)
src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
@ -80,2 +84,3 @@const auto mask = state.program.wave_size >= 64u ? 63u : 31u;return Binary(state, spv::OpBitwiseAnd, TypeU32(state), EmitSubgroupLocalInvocationId(state),ConstantU32(state, 63));ConstantU32(state, mask));@coderabbitai[bot] on GitHub · 2026-10-06 04:51 UTC · original
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 1936
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6052
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8362
Use
LocalInvocationIndexfor compute buffer lanes.BufferLaneusesSubgroupLocalInvocationId, which can select a different element from the guest wave lane for partial compute subgroups. UseEmitLocalInvocationIndex(state)for compute shaders.Keep the existing
lane_count == 2behavior. Extend that condition instead of adding a secondadd_builtincall.add_builtindeduplicates byStageInputKind, but one binding request is clearer and guarantees one generated SPIR-V input variable.Suggested fix
📝 Committable suggestion
Pull request closed