shader: size per-thread LDS emulation by the guest LDS allocation #1737
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!1737
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1737/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?
@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 mergingGame 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:
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 PS0x9090c99f3d9c75b2, before any SPIR-V store. This is not a hang.VK_KHR_pipeline_executable_propertiesstatistics 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 PS0x7defe0f5a1a5356a, 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-scopeuint[8192]array per invocation, becauseLdsDwordCount()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.cps_lds_granularity,ac_shader_encode_lds_size):SPI_SHADER_PGM_RSRC2_PS.EXTRA_LDS_SIZESPI_SHADER_PGM_RSRC2_HS.LDS_SIZESPI_SHADER_PGM_RSRC2_GS.LDS_SIZEThe 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_SIZEis 2, which gives 256 dwords instead of 8192. All 9 LDS accesses in that shader uselane + {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
CheckFunctionLdsAllocationinShaderRecompilerComputeTests.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 onmainand on an unclamped variant, and passes with this change.shader_recompiler_compute_tests: all cases pass (Windows, clang-cl, RTX 5090).main:PthreadGetprioon 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
ShaderVertexInputInfofield; that block already has warnings onmain.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.
@coderabbitai[bot] on GitHub · 2026-10-19 22:28 UTC · original
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
0b589cf8-9ea6-4c48-8a59-44897b5275cd📥 Commits
Reviewing files that changed from the base of the PR and between
0cad4672e9and12a7265da4.📒 Files selected for processing: 4
src/graphics/shader/recompiler/backend/spirv/spirvEmitterMemoryHelpers.cppsrc/graphics/shader/shader.cppsrc/graphics/shader/shader.htests/ShaderRecompilerComputeTests.cppIncluded 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:
nmzikPriority: ⬆️ High
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
12a72The 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:
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. Analyzed 11 functions across 3 files. (1 skipped: 1 too large.)
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
Comment
@coderabbitai helpto get the list of available commands.@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?
@Nmzik on GitHub · 2026-10-20 00:57 UTC · original
@0xcrstn Fixed thanks
fa8216c4d9Pull request closed