shader: keep EXEC words to the lanes the host subgroup runs #1918
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!1918
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1918"
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?
@ew-sudo on GitHub · 2026-10-26 19:18 UTC · original
ew-sudo:pr-exec-words→main· +32 −9 · 2 files · 2 commits · openshader: keep EXEC words to the lanes the host subgroup runs
EXEC is kept as guest words (likely since
5429888), so a scalar write to EXEC stores the guest value as is. A guest that enables its whole wave (S_MOV_B64 EXEC, -1, orS_OR_SAVEEXEC_B64with -1) then holds bits for lanes the host never runs: lanes 32-63 of a wave64 on a 32-lane subgroup, and lanes past the end of a partial wave. Nothing ever clears those bits.A waterfall loop (
V_READFIRSTLANEuntil EXEC is empty) then spins forever. Gran Turismo 7's tessellation vertex shaders do exactly this, and the GPU hangs (device lost inwaitSemaphores) when a race starts.The fix masks written EXEC words with the present lanes: the subgroup's active invocations, or the live ones in a pixel shader, as for the initial words. The per-lane EXEC still takes the written value as is, so pixel helpers stay enabled.
Testing
f90a8b1(it runs on2864818); with the fix the race starts.ba86c7dfe244de9f) on2864818andf90a8b1: the loop exit went fromBallot(active && !done)to(exec_words & ~Ballot(done)) != 0withexec_words = 0xffffffff'ffffffff.@coderabbitai[bot] on GitHub · 2026-10-26 19:23 UTC · original · edited 2026-11-02 18:38 UTC
Findings
8cc111b2-328b-48d1-95f1-6169f6bfb822Reviewing files that changed from the base of the PR and between
2720c49946and4b98ab702d.src/graphics/shader/recompiler/frontend/translate/Translate.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
Walkthrough
Translator::PresentMaskreturns the live-lane mask for pixel shaders and a ballot mask for other shader stages. Wave32 uses zero for the high word. EXEC writes now mask stored words with this present-lane mask. Per-lane EXEC values continue to use the supplied values.Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Moderate · up to
4b98aThe change stops EXEC bits for absent lanes from being stored, which targets the Gran Turismo 7 hang. However, SCC after 64-bit EXEC writes is still computed from the unmasked value, so some shaders can branch or loop incorrectly. Fix this before merging.
Pre-merge checks:
5
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
@coderabbitai[bot] on GitHub · 2026-10-26 19:23 UTC · original · reviewed
eedbc9a9-fc4f-41b9-b4e1-918dbaef0c72Reviewing files that changed from the base of the PR and between
f90a8b1589and2720c49946.src/graphics/shader/recompiler/frontend/translate/Translate.cppsrc/graphics/shader/recompiler/frontend/translate/Translator.hIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ZrDaniel07 on GitHub · 2026-10-31 00:53 UTC · original
Data point from an RTX 5090 (driver 617.42), GT7 v01.680, with #1918, #1919 and #1920 stacked on
main4919fdb6, plus a local port of the call-target part of #1849 (needed to get pastShaderCFG.cpp:1751).masterSemaphore.cpp:56during the drive, but that also happens without these three PRs, so it has a different cause. Details are in #1451.Which mode did you use for the race start that hung? I can retest that path with and without the PRs.
AI use: Claude Code built the branches and compared the logs with me; I ran the game.
@ew-sudo on GitHub · 2026-10-31 07:07 UTC · original
Thanks for testing, and for the data point. I tested in the garage of Career mode and in a Career mode race with the offline save patch. I never tested in Music Rally, so that explains why you don't see tessellation shaders there (LS/HS/TES stay at 0): that mode doesn't exercise this path. Career mode does, so it should be the right place to retest with and without the PRs.
@ew-sudo on GitHub · 2026-10-31 07:22 UTC · original
I just tested the same drive (Music Rally, Alsace) on my side and it runs without a crash, so the device lost doesn't seem to come from these PRs. Could you send me your full log (from the start up to the device lost), plus the exact list of patches in your build, including your local port of #1849? That would help find what differs between our setups.
@Nawid3333 on GitHub · 2026-11-01 23:22 UTC · original
The new masking covers
WriteRawU32andWriteU32Pair, but two 64-bit paths still write the EXEC words throughWriteMask. Its EXEC arm storesmask[0]andmask[1]unchanged (Translate.cpp:727-732at2720c49).S_SAVEEXECwithwrite_64(Control.cpp:79):S_ORN2_SAVEEXEC_B64andS_ANDN1_SAVEEXEC_B64can set bits, becauses_orn2_saveexec_b64 s[0:1], 0gives EXEC | ~0, and ANDN1 uses ~EXEC. The decoder has noS_OR_SAVEEXEC; its 64-bit SAVEEXEC forms are AND, ANDN1 and ORN2.S_U64_MASKwith an EXEC destination (Integer.cpp:125): for examples_or_b64 exec, exec, -1,s_not_b64 exec, 0, or the XOR/NOR/XNOR forms.On a 32-lane host, these paths still put the bits of lanes the host never runs into EXEC, which is the case the new
PresentMaskcomment describes. Masking inWriteMask's EXEC arm, as the other two writers now do, would cover both paths in one place.@ -711,2 +733,2 @@ir.SetExecLo(mask[0]);ir.SetExecHi(mask[1]);ir.SetExecLo(ir.BitwiseAnd(mask[0], present[0]));ir.SetExecHi(ir.BitwiseAnd(mask[1], present[1]));@coderabbitai[bot] on GitHub · 2026-11-02 18:38 UTC · original
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11610
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 32343
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 11280
Calculate SCC from the masked EXEC result.
For
S_ORN2_SAVEEXEC_B64withEXEC = 0x00000000ffffffffand source0, the unmasked result is0xffffffff00000000. On a 32-lane host,WriteMaskstores zero, butS_SAVEEXECsets SCC to 1 from the unmasked result. A laterS_CBRANCH_SCC0orS_CBRANCH_SCC1can therefore take the wrong path.Apply
PresentMaskbefore calculating SCC for EXEC destinations inS_SAVEEXECandS_U64_MASK. This correction belongs in the callers, or in a shared helper that returns the masked words. ChangingWriteMaskalone is insufficient because both callers set SCC afterWriteMaskreturns.@coderabbitai[bot] on GitHub · 2026-11-02 18:38 UTC · original · reviewed
@ew-sudo on GitHub · 2026-11-02 19:24 UTC · original
Good catch, thanks. WriteMask's EXEC arm was the one writer I missed: S_SAVEEXEC (ORN2/ANDN1) and S_U64_MASK to EXEC both go through it, so
s_orn2_saveexec_b64 s[0:1], 0ors_or_b64 exec, exec, -1could still set bits for lanes the host never runs.Fixed in
4b98ab70: WriteMask now masks both EXEC words with PresentMask(), like WriteRawU32 and WriteU32Pair, so all EXEC writers behave the same. The per-lane EXEC still takes the value unmasked.Tested on an RTX 4070 Laptop (32-lane subgroups): builds and GT7 still runs fine with it.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.