fix(recompiler): size per-invocation LDS arrays to the addresses they reach #586
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/586"
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?
Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-04T23:55:28Z.
What
Stages without workgroup memory (vertex, pixel, ...) keep LDS in a per-invocation
Functionarray of 8192 dwords (FunctionLdsDwordsin SpirvBufferAccess.cpp). Most shaders that use it touch a few lane-strided slots. On NVIDIA, the whole array goes to local memory per thread.PPSA21564 creates a pixel shader that writes
lane * 4at LDS byte offsets 0, 256 and 512, so the highest byte it can reach is 767. Its pipeline gets 32,864 bytes of local memory per thread (pipeline executable statistics, NVIDIA 610.57). About 15 s after that pipeline is created, the GPU hangs:VK_ERROR_DEVICE_LOST;VK_EXT_device_faulton, Xid 31 (FAULT_PDE VIRT_WRITE) at an address no Vulkan object ever held.With the array cut to 256 dwords, the same runs stopped hanging.
This PR sizes the array to what the shader can reach:
FunctionLdsDwords(program)in SpirvAnalysis bounds each LDS access's address. It handles lane ids, constants,IAdd32,IMul32, shifts, ands, ors, xors,UMin32/UMax32,SelectU32,BitFieldUExtractand phis of those, in unsigned 64-bit arithmetic.LoadShared,StoreShared,DataAppend,DataConsume, and any opcode added later).LdsDwordCountuses the new size for stages without workgroup memory. Compute and mesh stages are unchanged.This is exact: no access can reach past the smaller array, so the existing bounds checks and every result are the same as with 8192 dwords. Shaders whose addresses can't be bounded produce the same module as before.
Tested
BUILD_TESTING=ON;ctestpasses (213/213).verifyFunctionLdsBoundinagc_shader_memory_tests:AnalyzeProgramRequirements;select(c, (lane & 7) * 16, 0x100): 128 dwords;LoadSharedwithout a width: 8192;Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt.mdfiles or images added to the repository (attach them to this PR)Note for #573: its 64-bit shared atomics touch 2 dwords. This PR doesn't list them, so a shader that uses them keeps the full array until they're added to the width table.
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-05T07:30:30Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/shader/recompiler/SpirvBackend/src/SpirvAnalysis.cppL1