shader: elect a non-helper lane for DS_APPEND and DS_CONSUME in pixel shaders #1881
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!1881
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/1881/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?
@Nawid3333 on GitHub · 2026-10-24 16:35 UTC · original
Nawid3333:fix/ds-append-helper→main· +147 −2 · 6 files · 2 commits · closed without mergingASTRO BOT (PPSA21564) loses the device while loading on NVIDIA (#1511):
CS 0x657ad04626bf9d55does not leave the loop that walks the per-pixel lists built byPS 0x4a55033774c8f01e. @ZrDaniel07 tested thesrc/change of this PR on an RTX 5090 (Windows 11, driver 617.42, no game patch; #1511). His control was an earlier diagnostic build of mine with all its switches off, so the two builds also differ by 20 upstream commits:babec5b=main79837b42+ #1365 (control)de0e387=main6aaa5332+ #1365 + this changeIn both
de0e387runs the builder,CS 0x657ad04626bf9d55andPS 0x5457609506174517were compiled, and the second run got as far as loading a level. With #838 and a local fix for the oversized mesh draw from #624 added as well, he got into gameplay in the Garden level (#1511).Rebased on
8291cfeb, the change kept the samegit patch-id; after that I removed alane_count == 2branch from it that cannot run in pixel shaders (see below). The exact head of this PR has not run in the game, and I have not run the game on8291cfeb, which also hasbdf48dcf(faulting SRT walker loads).What is wrong
Pixel shaders start with the guest EXEC = true (
Translate.cpp), so on a host that keeps helper invocations active in subgroup operations, the EXEC ballot contains the quad's helpers. Vulkan allows that withoutMaximallyReconvergesKHR, and it differs by driver (#1574).EmitAppendConsumelets the first lane of that ballot do the oneOpAtomicIAdd/OpAtomicISubfor the wave and broadcasts its result. If that lane is a helper, the atomic has no effect on the GDS buffer and its result is undefined (Vulkan: "Stores and atomics performed by helper invocations must not have any effect on memory except for the Function, Private and Output storage classes, and values returned by atomic instructions in helper invocations are undefined."). The counter is not advanced, and every lane of the wave gets the same undefined base.The builder takes its node indices from a
DS_APPENDon a GDS counter and adds each lane'sv_mbcntrank. My explanation of the hang is that waves then get overlapping node indices and a list ends up with a cycle; I have not dumped the lists to confirm the cycle. The evidence is the 2/2 → 0/2 above. The builder has no derivative or implicit-LOD sample. In the test below, a shader like that (it also reads an interpolant) gets no helpers in the ballot on the RX 9070 XT. On RADV, @NeySlim measured in #1574 that one interpolated input is enough to put the helpers in, and the builder reads interpolants; I have not tried RADV.What changes
In pixel shaders, the lane that performs the atomic is now the first lane of
ballot(EXEC) & ballot(!HelperInvocation).gl_HelperInvocationis declared only for pixel shaders that useDS_APPENDorDS_CONSUME. In pixel shaders the emitter has one guest lane per invocation (lane_countis 2 only for compute and mesh), so the host ballot already has the guest layout. If no live lane is in EXEC, the elected lane is 0, and the atomic still requires that lane's own EXEC bit, so nothing reaches memory, as onmain.The count added is unchanged: the bits in the EXEC ballot, because the guest ranks lanes with
v_mbcntover the same EXEC. So helper lanes in EXEC still take slots, as onmainwhenever it elected a live lane. Those slots are never written, so an append buffer can have holes, and on hosts that count helpers a quad with one covered pixel can use up to 4 slots; forDS_CONSUME, slots taken by helpers are consumed but not processed. Whether helpers are counted depends on the driver. The wider question in #1574 (helpers inside the guest EXEC) stays open; this change does not touch it.DS_ORDERED_COUNTalso elects the first lane of EXEC (Memory.cpp) and is not changed here.Prior work: #761 (@carbonimax) excludes fragment helpers from the guest ballots and from the internal lane-activity ballot, and has a GDS fragment test,
GraphicsDsAppendHelperQuad; the GDS binding for graphics cases here follows the same idea. DeathWhispers traced an ASTRO BOT device loss to helper lanes in EXEC (Death-Whispers-U/KytyPS5@646753963a, see #1574).Tests
GraphicsDsAppendSkipsHelperLanes(--ds-append-helper-only): a 2x1 target where only pixel 1 is covered, so the rest of its quad can run as helpers. It runsds_appendtwice on a GDS counter that starts at 10 (M0 = 0x100) and exports the first base andbase2 - base1 - s_bcnt1(exec). Expected (10.0, 0.0): the first append returns 10, and the second returns 10 + the lanes in EXEC, so the first add was applied with the EXEC count. This holds whether or not the host counts helpers in EXEC. Like the builder, the shader reads an interpolant. Graphics cases can now bind GDS for this (GraphicsCase::gds_initial), and the harness enablesfragmentStoresAndAtomicsfor graphics cases, as the emulator does.mainon both GPUs I have, an RX 9070 XT (driver 26.8.1, LLPC) and the Ryzen 7600X iGPU: on the RX 9070 XT the helpers stay out of the ballot unless the shader needs WQM (a derivative or an implicit-LOD sample), and the interpolant alone does not change that; the iGPU keeps them out even then. With anOpDPdxadded by hand to the dumped fragment SPIR-V (not part of this PR; its result goes into a select that is never true), the RX 9070 XT puts all four lanes of the quad into EXEC, andmainfails in two separate runs: pixel 1 gets (0.0, -4.0) instead of (10.0, 0.0), consistent with the elected helper's add being dropped and both appends returning 0. With this change the case passes with and without theOpDPdxon both GPUs. The harness skips rasterization cases on these drivers (noattachmentFeedbackLoopDynamicState), so I ran them with a local switch that makes it optional, asvulkanWindow.cppdoes.shader_cfg_testspasses.scalar_provenance,resource_materializationandresource_trackingwith a SegFault, the same three asmain8291cfeb(https://github.com/KytyPS5/KytyPS5/actions/runs/40076044366);6aaa5332still passed them.Not tested:
DS_CONSUME(no case; the builder usesDS_APPEND), the case on NVIDIA, the exact head of this PR in the game, and ASTRO BOT on AMD with this change without the lab loop cap. @ZrDaniel07, if you build this branch,shader_recompiler_compute_tests --ds-append-helper-onlyonmainand on this branch would show whether the RTX 5090 puts the helpers into the ballot here, and ASTRO BOT runs with this branch and withmain8291cfeb(+ #1365, if it still needs it) would test the exact head against a control on the same base.AI use: Claude Code wrote this change and the test with me and traced the ASTRO BOT shaders; I reviewed the diff and the test results.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-24 16:45 UTC · original · edited 2026-10-24 17:15 UTC
Walkthrough
Pixel shaders that use shared append or consume operations now collect helper-invocation metadata. The SPIR-V emitter uses that metadata to exclude helper lanes when selecting a lane for the atomic operation. The graphics test harness adds fragment-stage GDS support and append and consume test cases. Rasterization capability detection and device creation now account for
fragmentStoresAndAtomics.Suggested reviewers:
nmzikPriority:
Normal
Change: Bug fix
Merge Risk:
Low · up to
f3396The change remains mergeable, but the regression test should include derivative-backed coverage so helper-lane election failures cannot pass unnoticed on some hosts.
Pre-merge checks:
4 ·
1
Full details: Docstring Coverage
Explanation
Docstring coverage is 16.67% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 6 functions across 5 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.@ -21372,6 +21437,7 @@ private:available_features.drawIndirectFirstInstance &&available_features.multiDrawIndirect &&available_features.depthBounds &&available_features.fragmentStoresAndAtomics &&@coderabbitai[bot] on GitHub · 2026-10-24 16:45 UTC · original · edited 2026-10-24 16:56 UTC
Do not disable all graphics tests when fragment atomics are unavailable.
fragmentStoresAndAtomicsis the feature needed for fragment-stage storage-buffer writes and atomics. Making it a condition ofm_rasterization_supportedalso skips graphics cases that do not use GDS on a device without that feature. Track fragment-atomic support separately, and gate only cases that need it. (docs.vulkan.org)@coderabbitai[bot] on GitHub · 2026-10-24 16:45 UTC · original · reviewed
Actionable comments posted: 1
🧹 Nitpick comments: 1
4044cf99-1f58-4dc1-a6ed-d65a85bad2bbReviewing files that changed from the base of the PR and between
8291cfeb04andc076fa5872.src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.hsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterMemory.cppsrc/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cppsrc/graphics/shader/recompiler/ir/ShaderIR.hsrc/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpptests/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.
@ -21372,6 +21437,7 @@ private:available_features.drawIndirectFirstInstance &&available_features.multiDrawIndirect &&available_features.depthBounds &&available_features.fragmentStoresAndAtomics &&@Nawid3333 on GitHub · 2026-10-24 16:56 UTC · original
The emulator itself requires
fragmentStoresAndAtomics:vulkanWindow.cpprejects a device without it (check_feature(device_features2.features.fragmentStoresAndAtomics, ...)) and enables it. So a device that lacks it cannot run Kyty, andm_rasterization_supportedalready stands for the features the production renderer needs. Gating only the GDS case would add code for a device the emulator does not start on, so I'd keep it as it is.@Nawid3333 on GitHub · 2026-10-24 16:56 UTC · original
@coderabbitai On the nitpick about reading back the final GDS counter in
GraphicsDsAppendSkipsHelperLanes: the final value is 10 + 2 × the lanes in EXEC, and that lane count depends on the host (1 when the helpers stay out of the ballot, 4 when they are in), so a fixed expected value would fail on one of them. The case checks the add through the second append's return value instead (base2 - base1 - s_bcnt1(exec)= 0), and both appends go through the same lane election.@ -21372,6 +21437,7 @@ private:available_features.drawIndirectFirstInstance &&available_features.multiDrawIndirect &&available_features.depthBounds &&available_features.fragmentStoresAndAtomics &&@coderabbitai[bot] on GitHub · 2026-10-24 16:57 UTC · original
🧩 Analysis chain
🏁 Script executed:
Length of output: 6060
@Nawid3333You're right. I verified thatvulkanWindow.cppchecks and enablesfragmentStoresAndAtomics. The harness also labels this gateProductionRasterization.Keeping the feature in
m_rasterization_supportedmatches that production baseline. A separate gate for GDS cases is not needed here. I withdraw this finding.✏️ Learnings added
✅ Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-10-24 16:57 UTC · original
🧩 Analysis chain
🏁 Script executed:
Length of output: 7758
@Nawid3333I couldn't produce a complete response to this request. Please try again.You are interacting with an AI system.
@Nawid3333 on GitHub · 2026-10-24 17:14 UTC · original
Added
f3396e94: the same case forDS_CONSUME(GraphicsDsConsumeSkipsHelperLanes;--ds-append-helper-onlynow runs both). With the counter starting at 10 it exports the first value returned andbase1 - base2 - s_bcnt1(exec), expected (10.0, 0.0). The results match the append case: it passes onmainand with this PR on the RX 9070 XT and the 7600X iGPU, and with the hand-addedOpDPdxthe RX 9070 XT fails onmainwith (0.0, -4.0) and passes with this PR. With this PR the validation layer reports nothing for either case on either GPU.@coderabbitai[bot] on GitHub · 2026-10-24 17:15 UTC · original · reviewed
🧹 Nitpick comments: 1
016491ff-8667-4274-be4d-803fbec36b0cReviewing files that changed from the base of the PR and between
c076fa5872andf3396e9493.tests/ShaderRecompilerComputeTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@Nawid3333 on GitHub · 2026-10-24 17:34 UTC · original
@coderabbitai On the nitpick about a derivative-backed variant: the recompiler emits a derivative only for an implicit-LOD image sample (
OpImageSampleImplicitLodinspirvEmitterImage.cpp); no guest instruction becomesOpDPdxor a quad operation, and graphics cases cannot bind images yet. So theOpDPdxvariant was run by hand on the dumped fragment SPIR-V (results in the description and in the comment above), and a committed variant would need image binding in the fragment harness first, which I'd keep out of this PR.@coderabbitai[bot] on GitHub · 2026-10-24 17:35 UTC · original
🧩 Analysis chain
🏁 Script executed:
Length of output: 14451
@Nawid3333I couldn't produce a complete response to this request. Please try again.You are interacting with an AI system.
@ZrDaniel07 on GitHub · 2026-10-24 17:39 UTC · original
@Nawid3333 I ran both tests on the RTX 5090 (Windows 11, driver 617.42).
shader_recompiler_compute_tests --ds-append-helper-onlyf3396e94)GraphicsDsAppendSkipsHelperLanes ok,GraphicsDsConsumeSkipsHelperLanes okmain's shader code (git checkout 8291cfeb -- src)On
main's code, pixel 1 read back (4294967296.0, -3.0) in the first run and (4294967296.0, ≈-2.09e9) in the second, instead of (10.0, 0.0). The values change from run to run, which is what an atomic done by a helper lane would give. The run stops at that case, so the consume case didn't run onmain's code. So the NVIDIA driver puts helpers into the EXEC ballot for this shader without a derivative, and the case as committed catches the bug there without the hand-addedOpDPdx(re the derivative-variant nitpick).ASTRO BOT, same base (
8291cfeb)Same settings as my earlier runs: no game patch, no loop cap, guest log to a file. There is no #838 and no mesh patch, so only the loading hang is being tested.
main8291cfeb(control)masterSemaphore.cpp:56atVS 22 | PS 36 | CS 48andVS 18 | PS 28 | CS 47f3396e94LevelTask_ATQT(pc=0x900388230,rcx=0x9ca52db2). That is the same fault #838 fixes, and #838 is not in these builds.8291cfeb(SrtRuntime::read_memoryis gone), so the control is plainmain. Neither build needed it to boot, sobdf48dcfseems to cover that crash.Separate, probably not from this PR
In the PR build, the sand in the crash-site desert is flat bright yellow and the rocks are mostly dark. With
de0e387on6aaa5332the same area looked right. The control dies before the desert, so I can't tell from these runs whether it comes from the 9maincommits in6aaa5332..8291cfeb. Since this PR only touches theDS_APPEND/DS_CONSUMElane election, I suspect them. I haven't bisected it yet.AI use: Claude Code built the branches, ran the shader tests and compared the logs with me; I ran the game and checked the outputs myself.
@Nawid3333 on GitHub · 2026-10-24 17:47 UTC · original
@ZrDaniel07 Thank you, that settles two things the description lists as not tested: the case on NVIDIA (as committed it fails on
main's shader code on the RTX 5090 without theOpDPdxedit, and passes with this PR), and the exact head in the game (2 of 2 device losses on plainmain8291cfeb, 0 of 2 with this PR on the same base). Good to know that #1365 is no longer needed to boot on8291cfeb.I can't reach the desert here (our RX 9070 XT loses the device earlier in ASTRO BOT), so I can't check the sand myself. If you look into it, the
maincommits between6aaa5332and8291cfebare the 9 from07f64202to8291cfeb.@devklex on GitHub · 2026-10-25 01:38 UTC · original
I checked which shaders this has to cover, using a 4090 run that lost the device entering Sky Garden in the same
CS 0x657ad04626bf9d55dispatch (#1511). That run dumped all 551 shaders it compiled, and 15 of them are pixel shaders withDS_APPEND,4a55033774c8f01eamong them.V_MBCNTranks exactly the lanes that theDS_APPENDcounts, and none picks a lane itself (noV_READLANE,V_READFIRSTLANEorS_FF1). So the election in this PR should be enough for all of them.exec & s, then the append underS_AND_SAVEEXEC_B64withs, the EXEC saved before the entryS_WQM_B64. Unlike4a55, these 13 sample with implicit LOD, so going by #1574 the RX 9070 XT also puts their helpers into the ballot. Wherever helpers are in the ballot, they still take slots in these 13: the holes the description mentions.I haven't run this branch; this comes from the shader code.
AI use: Claude Code went through the shader dumps and drafted this comment.
@ZrDaniel07 on GitHub · 2026-10-26 20:35 UTC · original
@Nawid3333 FYI, on
mainf90a8b15(with #838, without this PR) ASTRO BOT no longer loses the device while loading on my RTX 5090. I did 1 run to the Garden plus 3 more with the mesh patch, with no DEVICE_LOST. That is presumably5429888d, which keeps helper lanes out of EXEC/VCC. I haven't re-run--ds-append-helper-onlyagainst it, so I can't say whether this PR still covers a casemainmisses.AI use: Claude Code compared the builds with me; I ran the game.
@Nawid3333 on GitHub · 2026-10-27 16:23 UTC · original
Closing:
mainhas this since5429888d("shader: keep pixel helper lanes out of the EXEC and VCC words"), which keeps the helper lanes out of the EXEC words that DS_APPEND and DS_CONSUME elect and count from, and addsGraphicsDsAppendSkipsHelperLaneswith consume and ordered-count cases. ZrDaniel07 reports no DEVICE_LOST in ASTRO BOT onf90a8b15with #838 and without this PR (#1881). Thanks for all the test runs, @ZrDaniel07, and to @devklex for checking which shaders it has to cover.Pull request closed