tests: run the add_tid case in one wave instead of two #934

Closed
github-bot wants to merge 1 commit from gh-pr/934/head into gh-pr/934/base
Owner

@⁠theantipopau on GitHub · 2026-09-29 23:05 UTC · original
theantipopau:subgroup-lane-width → main · +7 −1 · 1 files · 1 commits · closed without merging

What

BufferStoreFormatXAddTidUsesLaneIndex dispatches a 64-thread workgroup with wave_size = 32 and
expects only dwords 0–31 to be written, on the theory that MUBUF add_tid addresses by the
subgroup lane. That expectation is only meaningful if the host subgroup is 32 wide — which nothing
in the pipeline guarantees.

On my machine (AMD, subgroup_size == 64) the case fails:

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

All 64 slots are written, i.e. SubgroupLocalInvocationId is coming back as the flat thread id.
Dropping the workgroup to a single 32-lane wave makes it pass, which is what this change does.
The required_spirv / forbidden_spirv assertions still pin the addressing choice — the
recompiled module is still required to use SubgroupLocalInvocationId and must not use
LocalInvocationId or a reconstructed ballot — so nothing about what the case actually checks is
lost. Only the runtime pattern that was device-dependent is gone.

The underlying issue is bigger than this test

I do not think this should be closed as "just a test fix". What I found while isolating it:

state.lane_count is derived from the host subgroup size, but nothing ever declares
VK_SUBGROUP_SIZE_CONTROL. OpExecutionMode never carries SubgroupSizeControl, and
spirvEmitterModule.cpp only emits ExecutionModeLocalSize. The device already has
VkPhysicalDeviceVulkan13Features::subgroupSizeControl enabled at creation
(vulkanWindow.cpp:587), so the driver is free to pick any subgroup width it likes for a
32-lane guest wave — and on my GPU it picks 64.

Wherever the recompiler assumes SubgroupLocalInvocationId is the wave lane, that assumption
breaks together:

  • BufferLane (spirvEmitterMemory.cpp:76) masks with & 63 unconditionally, so for a wave32
    shader on a 64-wide subgroup it yields the flat thread id — this is what the failing case saw.
  • ValueEmitContext::Ballot (spirvEmitterProgram.cpp) uses ScopeSubgroup, which ballots across
    the full 64 lanes rather than the guest's 32.

DsAppendAllocatesAcrossWaves32 fails on the same machine and I believe it is the same root
cause: 256 threads with wave_size = 32 expects 8 waves, and the final LDS append counter does
come out right, but the per-lane allocation histogram collapses — bins 0–31 each get one hit,
bin 32 gets 32, everything after gets none. That is four 64-lane appends instead of eight 32-lane
ones. I have not touched that case, because confirming it needs hardware-truth I do not have
here.

A proper fix looks like emitting SubgroupSizeControl = RequireSize 32 for wave32 compute and
64 for wave64, gated on the device actually supporting VK_EXT_subgroup_size_control (the
test harness does not enable that feature today, so it would need that too). I have deliberately
not attempted it here — it touches device-capability plumbing and shader validity, and I cannot
validate it against a real game from this machine.

Testing

shader_recompiler_compute_tests with #930 and #933 merged in so the suite runs to completion
here. Failures on this machine go 5 → 4.

**@⁠theantipopau** on GitHub · 2026-09-29 23:05 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/934) `theantipopau:subgroup-lane-width` → `main` · +7 −1 · 1 files · 1 commits · closed without merging ## What `BufferStoreFormatXAddTidUsesLaneIndex` dispatches a 64-thread workgroup with `wave_size = 32` and expects only dwords 0–31 to be written, on the theory that `MUBUF` `add_tid` addresses by the subgroup lane. That expectation is only meaningful if the host subgroup is 32 wide — which nothing in the pipeline guarantees. On my machine (AMD, `subgroup_size == 64`) the case fails: ``` expected [... 0x12345678 x32, 0 x32] actual [... 0x12345678 x64] ``` All 64 slots are written, i.e. `SubgroupLocalInvocationId` is coming back as the flat thread id. Dropping the workgroup to a single 32-lane wave makes it pass, which is what this change does. The `required_spirv` / `forbidden_spirv` assertions still pin the addressing choice — the recompiled module is still required to use `SubgroupLocalInvocationId` and must not use `LocalInvocationId` or a reconstructed ballot — so nothing about what the case actually checks is lost. Only the runtime pattern that was device-dependent is gone. ## The underlying issue is bigger than this test I do not think this should be closed as "just a test fix". What I found while isolating it: `state.lane_count` is derived from the *host* subgroup size, but nothing ever declares `VK_SUBGROUP_SIZE_CONTROL`. `OpExecutionMode` never carries `SubgroupSizeControl`, and `spirvEmitterModule.cpp` only emits `ExecutionModeLocalSize`. The device already has `VkPhysicalDeviceVulkan13Features::subgroupSizeControl` enabled at creation (`vulkanWindow.cpp:587`), so the driver is free to pick any subgroup width it likes for a 32-lane guest wave — and on my GPU it picks 64. Wherever the recompiler assumes `SubgroupLocalInvocationId` is the wave lane, that assumption breaks together: - `BufferLane` (`spirvEmitterMemory.cpp:76`) masks with `& 63` unconditionally, so for a wave32 shader on a 64-wide subgroup it yields the flat thread id — this is what the failing case saw. - `ValueEmitContext::Ballot` (`spirvEmitterProgram.cpp`) uses `ScopeSubgroup`, which ballots across the full 64 lanes rather than the guest's 32. `DsAppendAllocatesAcrossWaves32` fails on the same machine and I believe it is the same root cause: 256 threads with `wave_size = 32` expects 8 waves, and the final LDS append counter does come out right, but the per-lane allocation histogram collapses — bins 0–31 each get one hit, bin 32 gets 32, everything after gets none. That is four 64-lane appends instead of eight 32-lane ones. I have not touched that case, because confirming it needs hardware-truth I do not have here. A proper fix looks like emitting `SubgroupSizeControl = RequireSize 32` for wave32 compute and `64` for wave64, gated on the device actually supporting `VK_EXT_subgroup_size_control` (the test harness does not enable that feature today, so it would need that too). I have deliberately not attempted it here — it touches device-capability plumbing and shader validity, and I cannot validate it against a real game from this machine. ## Testing `shader_recompiler_compute_tests` with #930 and #933 merged in so the suite runs to completion here. Failures on this machine go 5 → 4.
A 64-thread workgroup is legal, but a driver may run it as a single 64-wide
subgroup, which makes SubgroupLocalInvocationId the flat thread id, so both
waves write lanes 0..31 and the readback cannot distinguish that from lane
indexing. The SPIR-V assertions are what pin the addressing, not the pattern.

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

@⁠theantipopau on GitHub · 2026-09-29 23:11 UTC · original

Superseded by #935, which fixes the underlying BufferLane wave-size mask.

**@⁠theantipopau** on GitHub · 2026-09-29 23:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/934#issuecomment-5900837196) Superseded by #935, which fixes the underlying BufferLane wave-size mask.
Author
Owner

@⁠theantipopau on GitHub · 2026-09-29 23:12 UTC · original

Closing in favour of #935, which fixes the actual cause instead of working around it.

I had assumed here that the recompiler's choice of SubgroupLocalInvocationId was right and the test's 64-thread workgroup was the problem. That was wrong. BufferLane masks the lane id with a hardcoded 63 regardless of the guest wave size, so a wave32 shader running in a 64-wide subgroup gets the flat thread id and every per-lane buffer address is wrong.

#935 masks by state.program.wave_size instead, and with it BufferStoreFormatXAddTidUsesLaneIndex passes unchanged — the stricter 64-thread version this PR was relaxing. That is strictly better than what I proposed here: same coverage, one real defect fixed instead of one device dependency papered over.

The underlying VK_SUBGROUP_SIZE_CONTROL gap is documented in #935. The ballot half of it is still open, and DsAppendAllocatesAcrossWaves32 still fails for that reason.

**@⁠theantipopau** on GitHub · 2026-09-29 23:12 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/934#issuecomment-5900840384) Closing in favour of #935, which fixes the actual cause instead of working around it. I had assumed here that the recompiler's choice of `SubgroupLocalInvocationId` was right and the *test's* 64-thread workgroup was the problem. That was wrong. `BufferLane` masks the lane id with a hardcoded `63` regardless of the guest wave size, so a wave32 shader running in a 64-wide subgroup gets the flat thread id and every per-lane buffer address is wrong. #935 masks by `state.program.wave_size` instead, and with it `BufferStoreFormatXAddTidUsesLaneIndex` passes **unchanged** — the stricter 64-thread version this PR was relaxing. That is strictly better than what I proposed here: same coverage, one real defect fixed instead of one device dependency papered over. The underlying `VK_SUBGROUP_SIZE_CONTROL` gap is documented in #935. The ballot half of it is still open, and `DsAppendAllocatesAcrossWaves32` still fails for that reason.

Pull request closed

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