recompiler: mask the buffer lane by the guest wave size #935

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

@⁠theantipopau on GitHub · 2026-09-29 23:11 UTC · original
theantipopau:buffer-lane-wave-mask → main · +6 −1 · 1 files · 3 commits · closed without merging

What

BufferLane masks SubgroupLocalInvocationId with a hardcoded 63:

uint32_t BufferLane(EmitterState& state) {
  return Binary(state, spv::OpBitwiseAnd, TypeU32(state),
                EmitSubgroupLocalInvocationId(state), ConstantU32(state, 63));
}

It is used for MUBUF add_tid and for the packed per-lane stride path, both of which address by
the 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. OpExecutionMode never carries
SubgroupSizeControl; spirvEmitterModule.cpp emits ExecutionModeLocalSize only. Meanwhile
vulkanWindow.cpp:587 already enables VkPhysicalDeviceVulkan13Features::subgroupSizeControl at
device 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, so
SubgroupLocalInvocationId comes back as the flat thread id and & 63 is a no-op. The existing
BufferStoreFormatXAddTidUsesLaneIndex case shows it exactly — a 64-thread workgroup with
wave_size = 32 stores MUBUF ... add_tid 0x12345678, and should only fill dwords 0–31:

expected [... 0x12345678 x32, 0 x32]
actual   [... 0x12345678 x64]

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:

const auto mask = state.program.wave_size >= 64u ? 63u : 31u;

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 was
demonstrably wrong.

For wave64 on a 32-wide host subgroup, EmitSubgroupLocalInvocationId adds 32 for the upper half
before this mask is applied, so & 63 still yields 0–63 as before.

Scope

This is deliberately the narrow part. ValueEmitContext::Ballot uses ScopeSubgroup, which
ballots across the host subgroup rather than the guest wave, and DsAppendAllocatesAcrossWaves32
fails on the same machine for that reason (256 threads at wave_size = 32 expects 8 waves and
gets 4). Masking a lane id cannot fix a ballot that spans the wrong number of lanes.

The complete fix is to declare SubgroupSizeControl = RequireSize for compute — 32 for wave32,
64 for wave64 — gated on VK_EXT_subgroup_size_control actually being available. I have left
that 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_tests with #930 merged in so the suite runs to completion on my GPU.
BufferStoreFormatXAddTidUsesLaneIndex goes from failing to passing with no change to the case.

**@⁠theantipopau** on GitHub · 2026-09-29 23:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/935) `theantipopau:buffer-lane-wave-mask` → `main` · +6 −1 · 1 files · 3 commits · closed without merging ## What `BufferLane` masks `SubgroupLocalInvocationId` with a hardcoded `63`: ```cpp uint32_t BufferLane(EmitterState& state) { return Binary(state, spv::OpBitwiseAnd, TypeU32(state), EmitSubgroupLocalInvocationId(state), ConstantU32(state, 63)); } ``` It is used for `MUBUF` `add_tid` and for the packed per-lane stride path, both of which address by the **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`. `OpExecutionMode` never carries `SubgroupSizeControl`; `spirvEmitterModule.cpp` emits `ExecutionModeLocalSize` only. Meanwhile `vulkanWindow.cpp:587` already enables `VkPhysicalDeviceVulkan13Features::subgroupSizeControl` at device 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, so `SubgroupLocalInvocationId` comes back as the flat thread id and `& 63` is a no-op. The existing `BufferStoreFormatXAddTidUsesLaneIndex` case shows it exactly — a 64-thread workgroup with `wave_size = 32` stores `MUBUF ... add_tid` 0x12345678, and should only fill dwords 0–31: ``` expected [... 0x12345678 x32, 0 x32] actual [... 0x12345678 x64] ``` 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: ```cpp const auto mask = state.program.wave_size >= 64u ? 63u : 31u; ``` 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 was demonstrably wrong. For wave64 on a 32-wide host subgroup, `EmitSubgroupLocalInvocationId` adds 32 for the upper half before this mask is applied, so `& 63` still yields 0–63 as before. ## Scope This is deliberately the narrow part. `ValueEmitContext::Ballot` uses `ScopeSubgroup`, which ballots across the host subgroup rather than the guest wave, and `DsAppendAllocatesAcrossWaves32` fails on the same machine for that reason (256 threads at `wave_size = 32` expects 8 waves and gets 4). Masking a lane id cannot fix a ballot that spans the wrong number of lanes. The complete fix is to declare `SubgroupSizeControl = RequireSize` for compute — 32 for wave32, 64 for wave64 — gated on `VK_EXT_subgroup_size_control` actually being available. I have left that 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_tests` with #930 merged in so the suite runs to completion on my GPU. `BufferStoreFormatXAddTidUsesLaneIndex` goes from failing to passing with no change to the case.
MUBUF add_tid and the packed per-lane stride address by the wave lane, but
BufferLane masked SubgroupLocalInvocationId with 63 unconditionally. Nothing
declares VK_SUBGROUP_SIZE_CONTROL, so a wave32 shader can run in a 64-wide
subgroup where that built-in is the flat thread id, and every per-lane buffer
address came out wrong.

Co-Authored-By: Codebuff <[email protected]>
Co-Authored-By: Codebuff <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:37:29 +00:00
github-bot closed this pull request 2026-11-26 09:37:29 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-29 23:18 UTC · original · edited 2026-10-06 04:54 UTC

Review in Change Stack →

📝 Walkthrough

Walkthrough

BufferLane now 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: nmzik

Priority: ⬇️ Low

Change: Bug fix

Merge Risk: 🟡 Moderate · up to 6de93

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

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: masking the buffer lane according to the guest wave size.
Description check ✅ Passed The description explains the lane-masking issue, the proposed fix, its scope, and the reported test results. It is directly related to the changeset.
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.

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-09-29 23:18 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/935#issuecomment-5900917029) · edited 2026-10-06 04:54 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/935?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 --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough `BufferLane` now 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:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬇️ Low <!-- change_assessment_commit:"6de936ff94c7da30bd8efe41af7364399f382962" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🟡 Moderate_ · up to `6de93` <!-- final_review_risk_coverage:{"sourceCommitId":"6de936ff94c7da30bd8efe41af7364399f382962","coveredCommitId":"6de936ff94c7da30bd8efe41af7364399f382962","kind":"reviewed"} --> Some 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. <!-- 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 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 3 functions across 1 files. | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :---------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly and concisely describes the main change: masking the buffer lane according to the guest wave size. | | Description check | ✅ Passed | The description explains the lane-masking issue, the proposed fix, its scope, and the reported test results. It is directly related to the changeset. | | 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. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=935)! 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 -->
Author
Owner

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

#930  MemoryTrackerTests: failed: range invalidation allocation failed
#935  PageManagerTests:  failed: fixed low mach_vm_allocate failed

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.

**@⁠theantipopau** on GitHub · 2026-09-29 23:30 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/935#issuecomment-5901042112) A note on CI, since it has now bitten three of my PRs on the same job: ``` #930 MemoryTrackerTests: failed: range invalidation allocation failed #935 PageManagerTests: failed: fixed low mach_vm_allocate failed ``` 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.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 04:51 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d955d3ab-8a2d-4467-ad95-49a561aed0cd
📥 Commits

Reviewing files that changed from the base of the PR and between 81ebf3a5b6 and 6de936ff94.

📒 Files selected for processing (1)
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 04:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/935#pullrequestreview-5423914980) · **reviewed** **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `d955d3ab-8a2d-4467-ad95-49a561aed0cd` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 81ebf3a5b619a86d78c49e9711a286a21d2043dd and 6de936ff94c7da30bd8efe41af7364399f382962. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=aa0297d2-270e-40f8-ab2e-99cbc2a8bbf1 attempt=7e30647f-98b0-47c5-bbe1-5ce2be54d769 batch=1/1 -->
@ -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));
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-06 04:51 UTC · original

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

rg -n 'add_builtin|lane_count == 2|LocalInvocationIndex|EmitLocalInvocationIndex' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp src/graphics/shader/recompiler/backend/spirv/spirvEmitterHelpers.cpp

Repository: KytyPS5/KytyPS5

Length of output: 1936


🏁 Script executed:

sed -n '400,465p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp
sed -n '150,190p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterHelpers.cpp
rg -n -F -- 'InputVariableForKind' src/graphics/shader/recompiler/backend/spirv
rg -n -F -- 'stage_inputs' src/graphics/shader/recompiler/backend/spirv src/graphics/shader/recompiler

Repository: KytyPS5/KytyPS5

Length of output: 6052


🏁 Script executed:

sed -n '460,560p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp
sed -n '60,105p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp
sed -n '125,155p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterHelpers.cpp

Repository: KytyPS5/KytyPS5

Length of output: 8362


Use LocalInvocationIndex for compute buffer lanes.

BufferLane uses SubgroupLocalInvocationId, which can select a different element from the guest wave lane for partial compute subgroups. Use EmitLocalInvocationIndex(state) for compute shaders.

Keep the existing lane_count == 2 behavior. Extend that condition instead of adding a second add_builtin call. add_builtin deduplicates by StageInputKind, but one binding request is clearer and guarantees one generated SPIR-V input variable.

Suggested fix
diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp
@@
 	// flat thread id. Mask by the wave size instead of assuming 64 lanes.
 	const auto mask = state.program.wave_size >= 64u ? 63u : 31u;
-	return Binary(state, spv::OpBitwiseAnd, TypeU32(state), EmitSubgroupLocalInvocationId(state),
+	const auto lane = state.program.stage == ShaderType::Compute
+	                      ? EmitLocalInvocationIndex(state)
+	                      : EmitSubgroupLocalInvocationId(state);
+	return Binary(state, spv::OpBitwiseAnd, TypeU32(state), lane,
 	              ConstantU32(state, mask));
 }
diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp
@@
-	if (state.lane_count == 2) {
+	if (state.lane_count == 2 || state.program.stage == ShaderType::Compute) {
 		add_builtin(IR::StageInputKind::LocalInvocationIndex, 1, "gl_LocalInvocationIndex");
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

	// MUBUF add_tid and the packed per-lane stride address by the guest wave
	// lane. Nothing declares VK_SUBGROUP_SIZE_CONTROL, so the host subgroup may
	// be wider than the guest wave and SubgroupLocalInvocationId may already be a
	// flat thread id. Mask by the wave size instead of assuming 64 lanes.
	const auto mask = state.program.wave_size >= 64u ? 63u : 31u;
	const auto lane = state.program.stage == ShaderType::Compute
	                      ? EmitLocalInvocationIndex(state)
	                      : EmitSubgroupLocalInvocationId(state);
	return Binary(state, spv::OpBitwiseAnd, TypeU32(state), lane,
	              ConstantU32(state, mask));
**@⁠coderabbitai[bot]** on GitHub · 2026-10-06 04:51 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/935#discussion_r4191643080) **🎯 Functional Correctness** | **🟠 Major** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash rg -n 'add_builtin|lane_count == 2|LocalInvocationIndex|EmitLocalInvocationIndex' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp src/graphics/shader/recompiler/backend/spirv/spirvEmitterHelpers.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 1936 --- 🏁 Script executed: ```bash sed -n '400,465p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp sed -n '150,190p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterHelpers.cpp rg -n -F -- 'InputVariableForKind' src/graphics/shader/recompiler/backend/spirv rg -n -F -- 'stage_inputs' src/graphics/shader/recompiler/backend/spirv src/graphics/shader/recompiler ``` Repository: KytyPS5/KytyPS5 Length of output: 6052 --- 🏁 Script executed: ```bash sed -n '460,560p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp sed -n '60,105p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp sed -n '125,155p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterHelpers.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 8362 --- </details> **Use `LocalInvocationIndex` for compute buffer lanes.** `BufferLane` uses `SubgroupLocalInvocationId`, which can select a different element from the guest wave lane for partial compute subgroups. Use `EmitLocalInvocationIndex(state)` for compute shaders. Keep the existing `lane_count == 2` behavior. Extend that condition instead of adding a second `add_builtin` call. `add_builtin` deduplicates by `StageInputKind`, but one binding request is clearer and guarantees one generated SPIR-V input variable. <details> <summary>Suggested fix</summary> ```diff diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cpp @@ // flat thread id. Mask by the wave size instead of assuming 64 lanes. const auto mask = state.program.wave_size >= 64u ? 63u : 31u; - return Binary(state, spv::OpBitwiseAnd, TypeU32(state), EmitSubgroupLocalInvocationId(state), + const auto lane = state.program.stage == ShaderType::Compute + ? EmitLocalInvocationIndex(state) + : EmitSubgroupLocalInvocationId(state); + return Binary(state, spv::OpBitwiseAnd, TypeU32(state), lane, ConstantU32(state, mask)); } diff --git a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp @@ - if (state.lane_count == 2) { + if (state.lane_count == 2 || state.program.stage == ShaderType::Compute) { add_builtin(IR::StageInputKind::LocalInvocationIndex, 1, "gl_LocalInvocationIndex"); ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion // MUBUF add_tid and the packed per-lane stride address by the guest wave // lane. Nothing declares VK_SUBGROUP_SIZE_CONTROL, so the host subgroup may // be wider than the guest wave and SubgroupLocalInvocationId may already be a // flat thread id. Mask by the wave size instead of assuming 64 lanes. const auto mask = state.program.wave_size >= 64u ? 63u : 31u; const auto lane = state.program.stage == ShaderType::Compute ? EmitLocalInvocationIndex(state) : EmitSubgroupLocalInvocationId(state); return Binary(state, spv::OpBitwiseAnd, TypeU32(state), lane, ConstantU32(state, mask)); ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:serval --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:2dc50cff994a9cf6b2fe8d51 --> <!-- This is an auto-generated comment by CodeRabbit -->

Pull request closed

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