fix(shader): keep spanned waves past an OpUnreachable under APS5_SPANNED_UNREACHABLE_STAYS #26716
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26716"
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 muhmuhkuh on 2026-11-24T17:00:32Z.
What
The spanned-wave uniformity check (
SpirvSpannedUniformity.cpp) countsOpUnreachableas an invocation leaving the program, likeOpReturnorOpKill. No invocation executes anOpUnreachable, so it is not an exit.Since #6416, a faulting BDA read no longer stops its invocation; later guest writes run under
if (!faulted). When such a write is a runtime image write, the mode switch of that write puts anOpUnreachabledefault (SpirvImageEmitter.cpp) inside the per-invocation guard. The check then treats everything after the guard as divergent: a Private word stored afterwards (for example the ballot parity of the spanned ballot) becomes non-uniform, the loops on it become non-uniform, and the next workgroup barrier is refused, so the program falls back to two lanes per invocation although every invocation reaches the barrier.The only
OpUnreachablethe emitter writes is the default of a switch on the image-mode specialization constant, andResourceMaterializer::RuntimeImageModeonly returns the index of an emitted mode or throws, so that default is never taken.Behind
APS5_SPANNED_UNREACHABLE_STAYS(off by default, read by the device likeAPS5_NO_SPANNED_SHUFFLE_EXCHANGE, in the shader disk cache key throughSpirvTarget), the check no longer countsOpUnreachableas an exit.OpReturn,OpReturnValue,OpKillandOpTerminateInvocationstill count. Each program kept spanned this way prints one[spanned-wave] ... keeps spanned waves past an OpUnreachableline with the reason the old rule would have given.APS5_VERIFY_SPANNED_UNREACHABLE_STAYSturns the switch on and checks, for every program it keeps spanned, that eachOpUnreachableof the module is reached only as the default of a switch on a specialization constant (no other branch or case targets it); otherwise the recompile stops and names the block.The #6416 masking is unchanged: faulted invocations still skip their later writes.
This is a correctness fix of the uniformity check and makes no speed claim. On
mainonly single-wave (64-thread) wave64 compute programs are spanned, so a 256-thread program is not affected: for the captured PPSA02015 compute program0xc280575600(16x16 threads)agc_shader_replaygives the same SPIR-V with the switch unset and set (1234866 words, no fallback line). Together with #23244, which runs each wave of a multi-wave workgroup as its own host workgroup, the same program keeps its split form (4 host workgroups per guest workgroup) instead of falling back to two lanes; that is shown offline in a downstream tree, the game measurement follows.Tested
Windows 11 Pro 10.0.26200, NVIDIA GeForce RTX 3080 Ti, driver 610.88.
ctest --test-dir build -R "^(spanned_uniformity|agc_driver_faulting_wave_invocation|agc_shader_disk_cache.*|agc_shader_memory.*)$" -VwithANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, same machine and GPU:main9/9 passed, this PR 9/9 passed, this PR with both switches set 9/9 passed. Each log showsInsert instance layer "VK_LAYER_KHRONOS_validation", none containswas not found but was requested by env var VK_INSTANCE_LAYERS, and none contains aVUID-line, so the PR adds no validation error.spanned_uniformity: a new case builds a per-invocation guard holding a specialization-constant switch with anOpUnreachabledefault, then a Private store and a loop with a barrier. It is refused whenOpUnreachablecounts as an exit (the behaviour without this change) and accepted with the switch; a per-invocationOpReturnis still refused with the switch. The verify check accepts a specialization-constant default and rejects a constant-switch default and a block that is also a case target.spanned_uniformityred: the change applied without the switch;OpUnreachablecounted as an exit again.0xc280575600request recompiles to the split form (4 groups, 760442 words) with the switch, against the two-lane fallback without it; the verify check passes; a GPU replay of the program through the driver writes the same 1048576 guest bytes in the split form and in the two-lane fallback.tools/pr_overlap.py --branchreports conflicts with #14218, #15548, #17611, #22432 and #25660, each on lines both sides extend: theSpannedBarrierInDivergentFlowdeclaration (#14218), the lastCacheKey.hpptarget fields (#15548, #17611), theexpecthelper ofSpannedUniformityTests.cpp(#22432) and the lastSpirvEmitter.hpptarget options (#25660). None of them changes howOpUnreachablecounts. The 92 pull requests it could not compare (they conflict withmainthemselves) were checked by diff: none touchesSpirvSpannedUniformity, and none adds or removes a line withOpUnreachable,SpannedBarrierInDivergentFloworExits(.Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T07:02:31Z.
Review: COMMENTED
Reviewed — comments
Comments are limited to unverified runtime behavior and one verifier edge case; no blocking defect was confirmed in the reviewed code.
What I ran
Read the prepared diff and targeted source context at head
436d4ec95bd924e22339b1912cabe8c551f4d65cusingrepo_read.py. No build or tests were run.Results
Findings
Blocking
None.
Non-blocking
core/shader/recompiler/SpirvBackend/src/SpirvSpannedUniformity.cpp:572: the verifier classifies a switch as specialization-driven when the selector itself is anOpSpecConstant. SPIR-V also permits derived selector expressions based on specialization constants; those valid switches will be rejected by verification even when their defaultOpUnreachablecannot be selected at runtime. Consider recognizing spec-constant operations or documenting this narrower verifier rule.Not verified
VulkanDevice.cppis excluded from the review folder due to size; only the changed diff lines were inspected. Its surrounding function and callers were not read.ShaderDiskCache.cpp,CacheKey.hpp,Recompiler.cpp,Recompiler.hpp,SpirvEmitter.hpp,SpirvSpannedUniformity.hpp,SpirvEmitter.cpp,SpirvSpannedUniformity.cpp,SpannedUniformityTests.cpp, andENVIRONMENT.md.VulkanDevice.cppfull text was excluded by size; no other changed file was excluded.To get this to a good state
Nothing is required. Optionally broaden verifier handling or clarify that only direct specialization-constant selectors are accepted.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-26T07:24:07Z.
Review: COMMENTED
Reviewed — no blocking findings
The reviewed implementation and its targeted tests support the stated opt-in behavior; the full Vulkan device file was not available in the review folder, so its surrounding context was not verified.
What I ran
Reviewed head
f946bf453799a05e08d808ba82f842223cf4cb6busing the prepared diff andrepo_read.pyfor changed-file context. No commands or tests were run.Results
Findings
Blocking
None.
Non-blocking
None.
Not verified
core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cppwas excluded because it was too large for the review folder; only the changed lines shown in the diff were available. Runtime behavior and the author-reported test results were not independently verified. The other changed files listed inmanifest.jsonwere included and inspected in relevant portions.To get this to a good state
Nothing is required.