shader: keep a wave32 guest inside its 32-lane half of a 64-lane subgroup #2134
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!2134
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2134/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 06:22 UTC · original
theantipopau:fix/lds-append-wave32→main· +30 −12 · 2 files · 2 commits · closed without mergingA 32-lane guest wave runs in one half of a 64-lane host subgroup on AMD, and the upper wave's
threads see subgroup lanes 32-63. Three emitters treated that native lane as if it were the
guest lane:
BufferLanemasks it with 63, so ADD_TID buffer addressing in the upper wave used lanes32..63 instead of restarting at 0.
BufferStoreFormatXAddTidUsesLaneIndexreads back thewrong rows because of this.
V_MBCNT_U32_B32applied its "lane >= 32" adjustment to every wave, so wave32 ranked theupper half as 32..63 instead of 0..31.
DS_APPENDelected the leader and broadcast the allocation through native lanes, so twowave32 waves shared a single allocation and the upper half collided on one id:
DsAppendAllocatesAcrossWaves32reported 256 allocations for 512 appends.Each site now keeps a wave32 guest inside its 32-lane half (
subgroup_lane & 31) and leaveswave64 unchanged, where the guest wave really does own the whole subgroup.
Testing on an RX 9070 XT (RADV, subgroup size 64),
shader_recompiler_compute:DsAppendAllocatesAcrossWaves32counter 256 with colliding ids, suite exits 127DsAppendAllocatesAcrossWaves32 ok,DsAppendAllocatesAcrossWaves64 ok,BufferStoreFormatXAddTidUsesLaneIndex ok, 995/995 cases,ctest82/82The bug only appears when the host subgroup is 64 lanes; on a 32-lane subgroup all three sites
were already correct. I could not test NVIDIA or Intel hardware here.
@coderabbitai[bot] on GitHub · 2026-11-06 06:27 UTC · original
Walkthrough
Lane selection in SPIR-V memory emission and integer translation now accounts for guest wave size. Wave32 lane masks use the low five lane bits. For append/consume operations on a 64-lane host subgroup, the selected active lane stays within the current 32-lane half.
Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Moderate · up to
1fc03Wave32 append operations can allocate incorrectly on partial dispatches. Use each guest wave’s own EXEC mask before merging.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.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 3 functions across 2 files.
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
@ -1548,0 +1557,4 @@Binary(state, spv::OpBitwiseAnd, TypeU32(state), first,ConstantU32(state, 31)));}const auto is_first = Binary(state, spv::OpIEqual, TypeBool(state), native_lane, source_lane);@coderabbitai[bot] on GitHub · 2026-11-06 06:27 UTC · original
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6841
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11880
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 25187
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19355
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 21752
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 10472
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 17569
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11329
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4593
Use each wave32 half’s EXEC mask for allocation
On a 64-lane host, a partial dispatch can leave the upper guest wave inactive while the lower wave is active.
EmitAppendConsumeuses the lower half’s EXEC word for both halves, so it can elect lane 32 and issue an extra atomic allocation. Use the corresponding guest wave’s EXEC mask for both election and count.@coderabbitai[bot] on GitHub · 2026-11-06 06:27 UTC · original · reviewed
Actionable comments posted: 1
d000c3f0-1235-4433-af6c-0c1ab34131f7Reviewing files that changed from the base of the PR and between
9912f1af23and1fc03424aa.src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppsrc/graphics/shader/recompiler/frontend/translate/Integer.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@Nawid3333 on GitHub · 2026-11-09 19:35 UTC · original
I ran this together with #2136 on an RX 9070 XT (host subgroup 64) with a partial wave32 dispatch: 48 threads, so the upper guest wave has only 16 live lanes (host lanes 32-47). The test is a local copy of
DsAppendAllocatesAcrossWaveswith 48 threads, and every thread appends twice, so the counter has to end at 96.6fd43ac65Three runs each, same result every time.
This is the case CodeRabbit describes in its comment on
EmitAppendConsume: the guest EXEC word of a wave32 program is word 0 of a 64-lane ballot, so the upper wave counts and elects from the lower wave's 32 lanes.DsAppendAllocatesAcrossWaves32passes because both of its halves are full, so the two words happen to have the same bit count.The change that gives 96 makes
EmitBallotreturn the caller's half word (HalfBallotWordfrom #2136) for a wave32 program on a 64-lane host, so EXEC, VCC and the append count all come from the caller's own wave:DefineInputsthen also has to declareSubgroupLocalInvocationIdwhenWideWave32(state) && state.program.info.subgroup_ballot; without that a compute case aborts with "SubgroupLocalInvocationId was not declared before SPIR-V function emission".A pixel shader does not get its initial EXEC through
EmitBallot:Translate.cppemitsLiveMaskfor the pixel stage, andEmitLiveMaskballots!helperover the native subgroup, so an upper-half pixel wave still starts with the lower half's live word. It needs the same half word. I found that one by reading the code; my test is compute only, so it does not cover it. (readfirstlanein the upper half has the same word-0 problem at this commit; #2135 already fixes it.)Where this matters outside the harness: #2136 gives every stage without a workgroup
host_subgroup_size = 64(SpirvEmitter.cpp), so a wave32 pixel shader takes the wide path, and its halves are often only partly covered. Compute is different: on mainGetComputeProgrampasses 64 wheneverSupportsComputeWave64()(pipelineCache.cpp:874), butCreatePipelineInternalpins the pipeline torequiredSubgroupSize = wave_size(shaders.cpp:375), so a wave32 compute shader runs in a 32-lane subgroup while the emitter assumes 64. With #2136 that means every wave32 compute reduction becomes the five-step shuffle butterfly on hardware where the native reduction is already exact. Passing the pinned size (the guest wave size whencompute_subgroup_size_control_enabledand it is in range) ashost_subgroup_sizefor compute would keep the native ops there.Full
shader_recompiler_compute_testswith keep-going on #2134 + #2136 + this change: no failed check that main6fd43ac65does not also fail on this GPU, andDsAppendAllocatesAcrossWaves32andBufferStoreFormatXAddTidUsesLaneIndexpass (both fail on main). One f64 case was left out in both runs because the AMD driver's compiler crashes on it, on main too.Pull request closed