shader: size per-thread LDS emulation by the guest LDS allocation #1737

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

@⁠0xcrstn on GitHub · 2026-10-19 22:25 UTC · original
0xcrstn:fix/ufc6-ps-lds-size → main · +141 −3 · 4 files · 1 commits · closed without merging

Game and problem

EA SPORTS UFC 6 (PPSA23566, 01.004.000) on Windows 11, RTX 5090 (driver 617.42) stops 2-6 minutes in, during the intro/menus, with:

Not implemented (result != vk::Result::eSuccess) in src/graphics/host_gpu/renderer/masterSemaphore.cpp:56

Related reports: #1555 (consolidated UFC 6 report), #1458, #831.

Cause

Nsight Aftermath caught the crash 5 times out of 5. Every dump is the same GPU page fault: a write to an unmapped address (Error_DMA_PageFault) from fragment shader offset 0x660. That offset is in the prologue of the translated guest PS 0x9090c99f3d9c75b2, before any SPIR-V store. This is not a hang.

VK_KHR_pipeline_executable_properties statistics for all 830 pipeline stages compiled before the fault show what triggers it. The last pipeline created before the fault has a fragment shader, guest PS 0x7defe0f5a1a5356a, that needs 32,816 bytes of local memory per thread. The next largest of the 830 stages needs 1,280. The cause is in the recompiler. Non-compute stages that use LDS get a Function-scope uint[8192] array per invocation, because LdsDwordCount() falls back to a hard-coded 8192 dwords when the stage has no workgroup. On NVIDIA that array becomes local memory for every resident thread.

To confirm the trigger, I ran a build with a temporary diagnostic switch that skipped only that shader's draws. The fault went away: no fault in 12+ minutes, the faulting shader drew 41,468 times instead of ~1,080, and the tutorial fight was playable.

Change

The per-invocation LDS array is now sized from the guest's own LDS allocation. The unit is 128 dwords (512 bytes), as Mesa decodes it for GFX10.3 (src/amd/common/ac_binary.c ps_lds_granularity, ac_shader_encode_lds_size):

  • pixel: SPI_SHADER_PGM_RSRC2_PS.EXTRA_LDS_SIZE
  • local and hull: SPI_SHADER_PGM_RSRC2_HS.LDS_SIZE
  • vertex and domain: SPI_SHADER_PGM_RSRC2_GS.LDS_SIZE

The size is capped at the previous 8192 dwords, and an allocation of 0 keeps 8192, so no stage gets a larger array than before. It is added to the pixel and vertex stage cache keys. Accesses past the array still go through the existing bounds check. Compute and mesh (Workgroup storage) are unchanged.

For UFC 6, EXTRA_LDS_SIZE is 2, which gives 256 dwords instead of 8192. All 9 LDS accesses in that shader use lane + {0, 64, 128} dwords (at most 191), so every access takes the same path as before. It is the only one of the 798 shaders UFC 6 compiles in that run that uses function-scope LDS.

Testing

  • New CheckFunctionLdsAllocation in ShaderRecompilerComputeTests.cpp. It compiles a pixel and a vertex shader that use DS ops with guest allocations 256, 0, 8192 and 32640 dwords, reads the declared Function array length from the SPIR-V, and checks the local, hull and domain size policy and that compute is unchanged. It fails on main and on an unclamped variant, and passes with this change.
  • shader_recompiler_compute_tests: all cases pass (Windows, clang-cl, RTX 5090).
  • UFC 6: without this change, 5 of 5 runs page-faulted. With it, runs reach past the old fault point (VS 183 / PS 186 / CS 429 shaders vs ~139 / 151 / 243) with no GPU fault and no Aftermath dump. Those runs later stop on a separate CPU-side crash that also happens on main: PthreadGetprio on an exited thread, similar to #1279. I'll send that as its own PR.

clang-format: the changed lines follow the surrounding struct layout. clang-format reports 2 alignment warnings on the new ShaderVertexInputInfo field; that block already has warnings on main.

AI use

I used AI tools (Claude Code) for the crash investigation (Aftermath dump decoding, pipeline statistics, SPIR-V analysis) and to write the change and the test. I reviewed the diff, checked the register units against Mesa, and ran the tests and the game runs above myself.

**@⁠0xcrstn** on GitHub · 2026-10-19 22:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1737) `0xcrstn:fix/ufc6-ps-lds-size` → `main` · +141 −3 · 4 files · 1 commits · closed without merging ## Game and problem EA SPORTS UFC 6 (PPSA23566, 01.004.000) on Windows 11, RTX 5090 (driver 617.42) stops 2-6 minutes in, during the intro/menus, with: ``` Not implemented (result != vk::Result::eSuccess) in src/graphics/host_gpu/renderer/masterSemaphore.cpp:56 ``` Related reports: #1555 (consolidated UFC 6 report), #1458, #831. ## Cause Nsight Aftermath caught the crash 5 times out of 5. Every dump is the same GPU page fault: a write to an unmapped address (`Error_DMA_PageFault`) from fragment shader offset 0x660. That offset is in the prologue of the translated guest PS `0x9090c99f3d9c75b2`, before any SPIR-V store. This is not a hang. `VK_KHR_pipeline_executable_properties` statistics for all 830 pipeline stages compiled before the fault show what triggers it. The last pipeline created before the fault has a fragment shader, guest PS `0x7defe0f5a1a5356a`, that needs **32,816 bytes of local memory per thread**. The next largest of the 830 stages needs 1,280. The cause is in the recompiler. Non-compute stages that use LDS get a Function-scope `uint[8192]` array per invocation, because `LdsDwordCount()` falls back to a hard-coded 8192 dwords when the stage has no workgroup. On NVIDIA that array becomes local memory for every resident thread. To confirm the trigger, I ran a build with a temporary diagnostic switch that skipped only that shader's draws. The fault went away: no fault in 12+ minutes, the faulting shader drew 41,468 times instead of ~1,080, and the tutorial fight was playable. ## Change The per-invocation LDS array is now sized from the guest's own LDS allocation. The unit is 128 dwords (512 bytes), as Mesa decodes it for GFX10.3 (`src/amd/common/ac_binary.c` `ps_lds_granularity`, `ac_shader_encode_lds_size`): - pixel: `SPI_SHADER_PGM_RSRC2_PS.EXTRA_LDS_SIZE` - local and hull: `SPI_SHADER_PGM_RSRC2_HS.LDS_SIZE` - vertex and domain: `SPI_SHADER_PGM_RSRC2_GS.LDS_SIZE` The size is capped at the previous 8192 dwords, and an allocation of 0 keeps 8192, so no stage gets a larger array than before. It is added to the pixel and vertex stage cache keys. Accesses past the array still go through the existing bounds check. Compute and mesh (Workgroup storage) are unchanged. For UFC 6, `EXTRA_LDS_SIZE` is 2, which gives 256 dwords instead of 8192. All 9 LDS accesses in that shader use `lane + {0, 64, 128}` dwords (at most 191), so every access takes the same path as before. It is the only one of the 798 shaders UFC 6 compiles in that run that uses function-scope LDS. ## Testing - New `CheckFunctionLdsAllocation` in `ShaderRecompilerComputeTests.cpp`. It compiles a pixel and a vertex shader that use DS ops with guest allocations 256, 0, 8192 and 32640 dwords, reads the declared Function array length from the SPIR-V, and checks the local, hull and domain size policy and that compute is unchanged. It fails on `main` and on an unclamped variant, and passes with this change. - `shader_recompiler_compute_tests`: all cases pass (Windows, clang-cl, RTX 5090). - UFC 6: without this change, 5 of 5 runs page-faulted. With it, runs reach past the old fault point (VS 183 / PS 186 / CS 429 shaders vs ~139 / 151 / 243) with no GPU fault and no Aftermath dump. Those runs later stop on a separate CPU-side crash that also happens on `main`: `PthreadGetprio` on an exited thread, similar to #1279. I'll send that as its own PR. clang-format: the changed lines follow the surrounding struct layout. clang-format reports 2 alignment warnings on the new `ShaderVertexInputInfo` field; that block already has warnings on `main`. ## AI use I used AI tools (Claude Code) for the crash investigation (Aftermath dump decoding, pipeline statistics, SPIR-V analysis) and to write the change and the test. I reviewed the diff, checked the register units against Mesa, and ran the tests and the game runs above myself.
Pixel, vertex, local, hull and domain shaders that use LDS were given a
fixed 8192-dword (32 KiB) Function-scope array per invocation. On NVIDIA
this becomes local memory for every resident thread: EA SPORTS UFC 6
(PPSA23566) pixel shader 0x7defe0f5a1a5356a needed 32,816 bytes of local
memory per thread, and right after its pipeline was created an RTX 5090
hit a GPU page fault (write to an unmapped address) in another spilling
fragment shader, ending in masterSemaphore.cpp (5 of 5 Aftermath dumps).
Skipping only that shader's draws removed the fault.

The array is now sized from the guest's own allocation in 128-dword
(512-byte) units, as Mesa decodes it for GFX10.3
(src/amd/common/ac_binary.c ps_lds_granularity,
ac_shader_encode_lds_size):
- pixel: SPI_SHADER_PGM_RSRC2_PS.EXTRA_LDS_SIZE
- local and hull: SPI_SHADER_PGM_RSRC2_HS.LDS_SIZE
- vertex and domain: SPI_SHADER_PGM_RSRC2_GS.LDS_SIZE
The size is capped at the previous 8192 dwords, and an allocation of 0
keeps 8192, so no stage gets a larger array than before. Accesses past
the array take the existing bounds-checked path. The size is part of
each stage's cache key. UFC 6 sets EXTRA_LDS_SIZE=2 for that shader
(256 dwords); its highest access is dword 191, and it is the only one
of the 798 shaders UFC 6 compiles that uses function-scope LDS.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:04:01 +00:00
github-bot closed this pull request 2026-11-26 10:04:01 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-19 22:28 UTC · original

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: 0b589cf8-9ea6-4c48-8a59-44897b5275cd
📥 Commits

Reviewing files that changed from the base of the PR and between 0cad4672e9 and 12a7265da4.

📒 Files selected for processing: 4
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp
  • src/graphics/shader/shader.cpp
  • src/graphics/shader/shader.h
  • tests/ShaderRecompilerComputeTests.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

Shader input metadata now records LDS sizes for pixel, vertex, geometry, and tessellation stages. Stage sizing applies an 8192-dword limit, while compute and mesh stages use workgroup LDS values. The SPIR-V memory helper uses the stage-derived count. New tests inspect function-scope LDS allocations across shader stages.

Suggested reviewers: nmzik

Priority: ⬆️ High

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 12a72

The change sizes per-invocation LDS arrays by the guest allocation, capped at 8192 dwords, and falls back to the previous size when the allocation is zero. The supplied context shows no concrete merge-blocking risk, and tests cover the new sizing.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive 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 11 functions across 3 files. (1 skipped: 1… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly summarizes the main change: sizing per-thread LDS emulation from the guest LDS allocation.
Description check Passed The description is directly related to the changes and explains the cause, implementation, and validation in sufficient detail.
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.
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. Analyzed 11 functions across 3 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · 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-19 22:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1737#issuecomment-6278772438) <!-- 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/1737?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary><strong>ℹ️ Recent review info</strong></summary> <dl> <dd> <details> <summary><strong>⚙️ Run configuration</strong></summary> <dl> <dd> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `0b589cf8-9ea6-4c48-8a59-44897b5275cd` </dd> </dl> </details> <details> <summary><strong>📥 Commits</strong></summary> <dl> <dd> Reviewing files that changed from the base of the PR and between 0cad4672e948b92b92e1aaf6e9bb5b144d8075ac and 12a7265da4a05d2843f0e1daf09079458e817074. </dd> </dl> </details> <details> <summary><strong>📒 Files selected for processing: 4</strong></summary> <dl> <dd> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cpp` * `src/graphics/shader/shader.cpp` * `src/graphics/shader/shader.h` * `tests/ShaderRecompilerComputeTests.cpp` </dd> </dl> </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. </dd> </dl> </details> <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> Shader input metadata now records LDS sizes for pixel, vertex, geometry, and tessellation stages. Stage sizing applies an 8192-dword limit, while compute and mesh stages use workgroup LDS values. The SPIR-V memory helper uses the stage-derived count. New tests inspect function-scope LDS allocations across shader stages. **Suggested reviewers:** `nmzik` </dd> </dl> </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ⬆️ High <!-- change_assessment_commit:"12a7265da4a05d2843f0e1daf09079458e817074" --> **Change:** Bug fix <!-- change_assessment_end --> <details> <summary><strong>Merge Risk:</strong> <strong>⚪ Minimal</strong> · up to <code>12a72</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **⚪ Minimal** · up to `12a72` --> <!-- final_review_risk_coverage:{"sourceCommitId":"12a7265da4a05d2843f0e1daf09079458e817074","coveredCommitId":"12a7265da4a05d2843f0e1daf09079458e817074","kind":"reviewed"} --> The change sizes per-invocation LDS arrays by the guest allocation, capped at 8192 dwords, and falls back to the previous size when the allocation is zero. The supplied context shows no concrete merge-blocking risk, and tests cover the new sizing. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | 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 11 functions across 3 files. (1 skipped: 1… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :------------------------------------------------------------------------------------------------------------------------------ | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly summarizes the main change: sizing per-thread LDS emulation from the guest LDS allocation. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The description is directly related to the changes and explains the cause, implementation, and validation in sufficient detail. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **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. Analyzed 11 functions across 3 files. (1 skipped: 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </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">Autofix</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=1737)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [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) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠theantipopau on GitHub · 2026-10-20 00:49 UTC · original · approved these changes

Verified the safety invariants: guest allocation is capped at the previous 8192 (min), 0 keeps 8192, workgroup stages are untouched, and pixel + vertex static keys now include lds_size_dwords. The 128-dword unit matches Mesa's GFX10.3 LDS granularity, and past-array accesses still go through the existing bounds check. Test fails on main and passes here, plus 5/5 Aftermath-confirmed game runs past the fault point. One question (non-blocking): do the tessellation control/evaluation static keys also capture lds_size_dwords, or could two draws with the same shader hash but different HS/GS LDS allocations collide in the pipeline cache?

**@⁠theantipopau** on GitHub · 2026-10-20 00:49 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1737#pullrequestreview-5579502593) · **approved these changes** Verified the safety invariants: guest allocation is capped at the previous 8192 (min), 0 keeps 8192, workgroup stages are untouched, and pixel + vertex static keys now include lds_size_dwords. The 128-dword unit matches Mesa's GFX10.3 LDS granularity, and past-array accesses still go through the existing bounds check. Test fails on main and passes here, plus 5/5 Aftermath-confirmed game runs past the fault point. One question (non-blocking): do the tessellation control/evaluation static keys also capture lds_size_dwords, or could two draws with the same shader hash but different HS/GS LDS allocations collide in the pipeline cache?
Author
Owner

@⁠Nmzik on GitHub · 2026-10-20 00:57 UTC · original

@⁠0xcrstn Fixed thanks fa8216c4d9

**@⁠Nmzik** on GitHub · 2026-10-20 00:57 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1737#issuecomment-6280794016) @⁠0xcrstn Fixed thanks fa8216c4d95bee2dacbc6b2b7c09c3ba49fd1aac

Pull request closed

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