gpu: avoid spec-constant vector selects in tiler shaders #1152
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!1152
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1152"
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?
@NeySlim on GitHub · 2026-10-07 17:25 UTC · original
NeySlim:fix/tiler-spec-vector-select→main· +18 −12 · 3 files · 1 commits · openProblem
GpuTilerCpuParityfails on RADV (Mesa 26.2.3, Radeon 8060S):With the comparison made non-fatal, every case of three families differs from the CPU reference, for 1, 2, 4 and 8 bytes per element (25 to 50 % of the bytes):
Standard64KB3D,Prt64KBandPrt64KB3D. The 16-byte case and all other families match. The format/mode pairs that go through these layouts differ too.Those three shaders are the only ones that pick their swizzle shifts with a chained ternary on the
ELEMENT_BYTESspecialization constant:glslang turns this into
OpSpecConstantOp %v4uint Select %bool %v4uint %v4uint(a scalar condition selecting vectors). On RADV the resulting addresses are wrong. The 16-byte case only takes the last arm, which is why it still matches. The other tiler shaders useifchains or aswitchon the same constant and are correct.In God of War Ragnarök (PPSA08332), PRT textures detiled this way render as large saturated blocks.
Change
The three selections become an
if/else ifchain onELEMENT_BYTES, likestandard64_3d_extent()next to them. The values are unchanged, and the specialization still folds the branches away.I have not checked whether the bug is in Mesa's handling of this
OpSpecConstantOpor elsewhere. Either way, the branch form avoids it.Validation
Linux, AMD Radeon 8060S (RDNA 3.5), Mesa RADV 26.2.3.
GpuTilerCpuParitypasses:ok (350 cases, 256 format/mode pairs).shader_recompiler_compute_testsin its own process, with and without the change:GpuTilerCpuParityis the only difference.Not tested on Windows. The change is GLSL only, the selected values are identical, and drivers that already handled the ternary see equivalent code.
AI use
I used Claude Code (AI agent) to investigate the failure, write the change and run the tests above on my machine. I reviewed the diff and the results before opening this PR.
@coderabbitai[bot] on GitHub · 2026-10-07 17:28 UTC · original
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
d5140707-ea37-4e65-9a07-3ec3d09e1d18📥 Commits
Reviewing files that changed from the base of the PR and between
d2413fc2ebandc2041567bb.📒 Files selected for processing (3)
src/graphics/host_gpu/shaders/gpu_tiler_prt.compsrc/graphics/host_gpu/shaders/gpu_tiler_prt_3d.compsrc/graphics/host_gpu/shaders/gpu_tiler_standard64_3d.incIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
📝 Walkthrough
Walkthrough
Three GPU tiler shader routines now use explicit branches instead of nested conditional expressions to select vectors based on
ELEMENT_BYTES. The selections for values 1, 2, 4, and 8 and the fallback vectors remain unchanged. One routine includes a comment about driver miscompilation of vector selects on specialization constants.Priority: ➖ Normal
Change: Bug fix
Merge Risk: ⚪ Minimal · up to
c2041The shader changes preserve the existing vector selections while avoiding the reported specialization-constant vector-select issue. No actionable merge risk was identified.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
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.@Nawid3333 on GitHub · 2026-10-18 04:11 UTC · original
This should also fix a crash with AMD's Windows driver on RDNA2 GPUs: #821 (Demon's Souls, RX 6700 XT and RX 6600 XT) and #1428 (UFC 5, RX 6700 XT), probably also the log in #1059 (RX 5700 XT). There, AMD's other shader compiler (the one that isn't LLPC) crashes inside
vkCreateComputePipelineson the sameOpSpecConstantOp %v4uint Select: an access violation (a read of address 0 or 1) atamdvlk64.dll+0x22241FCon 26.8.1 (+0x22240FCon 26.9.1), the instruction in all those logs, with the same driver frames. Because Kyty creates the tiler pipelines lazily, the crash comes when a game first detiles such a texture, which fits the reports that precompiling all of the game's pipelines never crashed.My Ryzen 7600X iGPU uses that compiler. There,
GpuTilerCpuParitycrashes when it creates the 64 KiB 3D tiler, and a standalone program that only creates that pipeline crashes too, for every element size. So does a one-line shader with a single vectorOpSpecConstantOp Select, while the same select on scalars works. The RX 9070 XT (LLPC) builds all of them.With your change, all 30 tiler pipelines (3 shaders x 5 element sizes x tile/detile) build on the iGPU, and
GpuTilerCpuParitypasses on the iGPU and the RX 9070 XT, natively and with 32-wide subgroups. I applied your commit on top of763d3be3; compared with that, nothing else changes in the rest of the compute suite (807 entries) or in the 30 graphics cases on either GPU. SPIRV-Tools'--fold-spec-const-op-compositealso turns this select into an invalid module (an undefined id), so the branch form is the safer choice for other drivers too. I'm reporting the driver crash to AMD.Written with Claude Code (AI): it found the crash, built the reproducer and ran your change on my PC; I read this comment before posting it.
@Nawid3333 on GitHub · 2026-10-18 21:02 UTC · original
Confirmed with the game: volan3 ran Demon's Souls on an RX 6700 XT (#821). With the official builds, it crashed in
amdvlk64.dll("Unhandled host exception") after about 20 compute shaders, when KytyPS5 first created a tiler pipeline. With this PR, none of four runs crashed there: this PR's CI build reachedCS 118,099de8dplus this commit reachedCS 111, and with #1630 as well it reachedCS 136(language selection) and, in a second run, gameplay after the intro (VS 51 | PS 98 | CS 234). TheCS 118andCS 111runs stopped for other, already known reasons (the depth feedback check in the 7 October code, the error #1630 fixes), theCS 136run kept running, and the gameplay run crashed later in the game's own code.Written with Claude Code (AI): it compared the logs; I read this before posting.
@dcwxd on GitHub · 2026-10-30 22:31 UTC · original
Tested this on Windows with RX 5700 XT AMD drivers 26.10.1, seems to fix early crashes in:
@virgil48YT on GitHub · 2026-11-16 22:36 UTC · original
Bit late but yeah this seems to fix Minecraft and RE2, although this is kinda old build and the fixes arent here for re2 so there are artifacts. Running a RX 6700XT + 5700X on latest AMD driver 26.11.1
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.