Repository navigation
fix(recompiler): size per-invocation LDS arrays to the addresses they reach - #586
Merged
oneandonlydean merged 1 commit intoOct 5, 2026
Conversation
This was referenced Oct 5, 2026
oneandonlydean
force-pushed
the
fix/recompiler-lds-array-bound
branch
from
October 5, 2026 00:34
05c293b to
3abf107
Compare
9 tasks done
This was referenced Oct 5, 2026
… reach Stages without workgroup memory (vertex, pixel, ...) keep LDS in a per-invocation Function array of 8192 dwords. PPSA21564 creates a pixel shader that keeps three lane-strided slots there (lane * 4 at byte offsets 0, 256 and 512). On NVIDIA (driver 610.57) the array becomes 32864 bytes of local memory per thread, and about 15 s after the pipeline is created the GPU hangs: Xid 109 (CTX SWITCH TIMEOUT), or Xid 31 (FAULT_PDE VIRT_WRITE) with VK_EXT_device_fault enabled, at an address no Vulkan object ever held. The analysis now bounds each LDS access's address over lane ids, constants, adds, multiplies, shifts, ands, ors, xors, min/max, selects, bitfield extracts and phis of those. A loop-carried or otherwise unknown address, an add that could wrap with the instruction offset, or a shared access whose width is not listed has no bound. The array becomes the dwords the accesses can reach, rounded up to 64, and stays at 8192 when any access is unbounded. No access can reach past the smaller array, so the bounds checks and results are unchanged. The pixel shader above now takes 192 dwords.
oneandonlydean
force-pushed
the
fix/recompiler-lds-array-bound
branch
from
October 5, 2026 07:29
3abf107 to
bdf3984
Compare
oneandonlydean
added a commit
to oneandonlydean/AnyPS5
that referenced
this pull request
Oct 5, 2026
…lots Stages without workgroup memory keep LDS in a per-invocation Function array. With the array sized to the addresses it reaches (boykopovar#586), PPSA21564's intro pixel shader still takes 864 bytes of local memory per thread on NVIDIA: its accesses are lane * 4 + {0, 256, 512}, so the index stays dynamic and the 192-dword array lives in local memory. When every LDS access's address is lane * stride + constant (lane id, constants, adds, multiplies and left shifts), with one stride, a whole number of dwords, for all of them and no wrap (the bound analysis already proves that), the emitter now addresses each access by its constant plus its instruction offset. The lane id is the same for every access of an invocation, so taking lane * stride out maps the addresses one to one, keeps which accesses alias and keeps every access in bounds; the array sees only constant indices and the driver keeps it in registers. Shaders with any other address form are emitted as before.
|
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.
|
9 tasks done
oneandonlydean
added a commit
to oneandonlydean/AnyPS5
that referenced
this pull request
Oct 5, 2026
Takes upstream's merged versions of our boykopovar#586 boykopovar#611 boykopovar#612 boykopovar#505 boykopovar#490 boykopovar#619 boykopovar#503 boykopovar#627 boykopovar#628 boykopovar#618 and drops astrobot's local copies, plus gate-batch-3 (boykopovar#469 boykopovar#500 boykopovar#504 boykopovar#509 boykopovar#510 boykopovar#514 boykopovar#525 boykopovar#526 boykopovar#528), round o/p (boykopovar#617 boykopovar#620 boykopovar#621 boykopovar#622 boykopovar#623 boykopovar#624 boykopovar#501 boykopovar#508 boykopovar#629 boykopovar#630 boykopovar#631). Conflicts: - SpirvAnalysis.hpp/.cpp, SpirvBufferAccess.cpp: upstream's boykopovar#586/boykopovar#612. The 64-bit LDS atomics keep the full array (f27d6e5 no longer needed). - SpirvMemoryInstructions.cpp: upstream's constant slot plus offset; astrobot's split-wave append/consume kept. - GuestTextureResource.cpp, TextureTiling.cpp and their tests: upstream's boykopovar#490/boykopovar#503 (astrobot had no other change there). - MaskedSelect.cpp test, ShaderMemory.cpp LDS test: upstream's. - State.cpp: upstream's boykopovar#505 export count and boykopovar#469 null pixel program; astrobot's depth export rejection and depth target model kept. - Pipeline.cpp: upstream's pipeline key; astrobot's depth attachment and blend check (a trailing unused attachment stays valid, as colorGapPipelineTests expects). - Draw.cpp, Recorder.cpp, ShaderResources.cpp: astrobot's (renderPassKey with depth, moved sample functions, residency maintenance), which already hold the merged boykopovar#505/boykopovar#628/boykopovar#490 changes. - ShaderInputState.cpp: both register sets. - State.hpp: the duplicate exportIndex member from the auto-merge removed. - CMakeLists.txt: astrobot's test list (a superset of upstream's). - tests/Graphics.cpp: upstream's CompactedExportTests replaces astrobot's inline copy; tests/Recorder.cpp: upstream's viewPastLastMipTests added.
12 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.