gpu: avoid spec-constant vector selects in tiler shaders #1152

Open
github-bot wants to merge 1 commit from github-bot/gh-1152 into main AGit
Owner

@⁠NeySlim on GitHub · 2026-10-07 17:25 UTC · original
NeySlim:fix/tiler-spec-vector-select → main · +18 −12 · 3 files · 1 commits · open

Problem

GpuTilerCpuParity fails on RADV (Mesa 26.2.3, Radeon 8060S):

GpuTilerCpuParity failed at detile bytes family=4 bpe=1: first mismatch at 8 of 2097152

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, Prt64KB and Prt64KB3D. 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_BYTES specialization constant:

uvec4 s = ELEMENT_BYTES == 1 ? uvec4(...) :
          ELEMENT_BYTES == 2 ? uvec4(...) : ... : uvec4(...);

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 use if chains or a switch on 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 if chain on ELEMENT_BYTES, like standard64_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 OpSpecConstantOp or elsewhere. Either way, the branch form avoids it.

Validation

Linux, AMD Radeon 8060S (RDNA 3.5), Mesa RADV 26.2.3.

  • GpuTilerCpuParity passes: ok (350 cases, 256 format/mode pairs).
  • I ran each of the 543 cases of shader_recompiler_compute_tests in its own process, with and without the change: GpuTilerCpuParity is the only difference.
  • God of War Ragnarök: the saturated block patterns are gone. Other rendering problems remain.

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.

**@⁠NeySlim** on GitHub · 2026-10-07 17:25 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1152) `NeySlim:fix/tiler-spec-vector-select` → `main` · +18 −12 · 3 files · 1 commits · open ## Problem `GpuTilerCpuParity` fails on RADV (Mesa 26.2.3, Radeon 8060S): ``` GpuTilerCpuParity failed at detile bytes family=4 bpe=1: first mismatch at 8 of 2097152 ``` 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`, `Prt64KB` and `Prt64KB3D`. 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_BYTES` specialization constant: ```glsl uvec4 s = ELEMENT_BYTES == 1 ? uvec4(...) : ELEMENT_BYTES == 2 ? uvec4(...) : ... : uvec4(...); ``` 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 use `if` chains or a `switch` on 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 if` chain on `ELEMENT_BYTES`, like `standard64_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 `OpSpecConstantOp` or elsewhere. Either way, the branch form avoids it. ## Validation Linux, AMD Radeon 8060S (RDNA 3.5), Mesa RADV 26.2.3. - `GpuTilerCpuParity` passes: `ok (350 cases, 256 format/mode pairs)`. - I ran each of the 543 cases of `shader_recompiler_compute_tests` in its own process, with and without the change: `GpuTilerCpuParity` is the only difference. - God of War Ragnarök: the saturated block patterns are gone. Other rendering problems remain. 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:45:15 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-07 17:28 UTC · original

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: d5140707-ea37-4e65-9a07-3ec3d09e1d18
📥 Commits

Reviewing files that changed from the base of the PR and between d2413fc2eb and c2041567bb.

📒 Files selected for processing (3)
  • src/graphics/host_gpu/shaders/gpu_tiler_prt.comp
  • src/graphics/host_gpu/shaders/gpu_tiler_prt_3d.comp
  • src/graphics/host_gpu/shaders/gpu_tiler_standard64_3d.inc

Included 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 c2041

The 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)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the main change: replacing specialization-constant vector selects in tiler shaders. It is concise and specific.
Description check ✅ Passed The description directly explains the RADV failure, the shader changes, preserved behavior, and validation results. It is relevant to the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0…
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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 help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-07 17:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1152#issuecomment-6043208060) <!-- This is an auto-generated comment: summarize by coderabbit.ai --> <!-- review_stack_entry_start --> <a href="https://app.coderabbit.ai/change-stack/KytyPS5/KytyPS5/pull/1152?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=2" alt="Review in Change Stack →" width="220" height="32"></a> <!-- review_stack_entry_end --> <!-- recent_review_start --> No actionable comments were generated in the recent review. 🎉 <details> <summary>ℹ️ Recent review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `d5140707-ea37-4e65-9a07-3ec3d09e1d18` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between d2413fc2ebd91d1b7234197c2dd5bd48e1cb6a51 and c2041567bb66232e5dc55debb003209dd4859006. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/graphics/host_gpu/shaders/gpu_tiler_prt.comp` * `src/graphics/host_gpu/shaders/gpu_tiler_prt_3d.comp` * `src/graphics/host_gpu/shaders/gpu_tiler_standard64_3d.inc` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## 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. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"c2041567bb66232e5dc55debb003209dd4859006" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `c2041` <!-- final_review_risk_coverage:{"sourceCommitId":"c2041567bb66232e5dc55debb003209dd4859006","coveredCommitId":"c2041567bb66232e5dc55debb003209dd4859006","kind":"reviewed"} --> The shader changes preserve the existing vector selections while avoiding the reported specialization-constant vector-select issue. No actionable merge risk was identified. <!-- final_review_risk_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 5</summary> <details> <summary>✅ Passed checks (5 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly identifies the main change: replacing specialization-constant vector selects in tiler shaders. It is concise and specific. | | Description check | ✅ Passed | The description directly explains the RADV failure, the shader changes, preserved behavior, and validation results. It is relevant to the changeset. | | Docstring Coverage | ✅ Passed | No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff. Analyzed 0 functions across 0… | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1152)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠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 vkCreateComputePipelines on the same OpSpecConstantOp %v4uint Select: an access violation (a read of address 0 or 1) at amdvlk64.dll+0x22241FC on 26.8.1 (+0x22240FC on 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, GpuTilerCpuParity crashes 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 vector OpSpecConstantOp 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 GpuTilerCpuParity passes on the iGPU and the RX 9070 XT, natively and with 32-wide subgroups. I applied your commit on top of 763d3be3; 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-composite also 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 04:11 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1152#issuecomment-6245525149) 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 `vkCreateComputePipelines` on the same `OpSpecConstantOp %v4uint Select`: an access violation (a read of address 0 or 1) at `amdvlk64.dll+0x22241FC` on 26.8.1 (`+0x22240FC` on 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, `GpuTilerCpuParity` crashes 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 vector `OpSpecConstantOp 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 `GpuTilerCpuParity` passes on the iGPU and the RX 9070 XT, natively and with 32-wide subgroups. I applied your commit on top of 763d3be3; 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-composite` also 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.
Author
Owner

@⁠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 reached CS 118, 099de8d plus this commit reached CS 111, and with #1630 as well it reached CS 136 (language selection) and, in a second run, gameplay after the intro (VS 51 | PS 98 | CS 234). The CS 118 and CS 111 runs stopped for other, already known reasons (the depth feedback check in the 7 October code, the error #1630 fixes), the CS 136 run 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.

**@⁠Nawid3333** on GitHub · 2026-10-18 21:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1152#issuecomment-6255103298) 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 reached `CS 118`, 099de8d plus this commit reached `CS 111`, and with #1630 as well it reached `CS 136` (language selection) and, in a second run, gameplay after the intro (`VS 51 | PS 98 | CS 234`). The `CS 118` and `CS 111` runs stopped for other, already known reasons (the depth feedback check in the 7 October code, the error #1630 fixes), the `CS 136` run 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.
Author
Owner

@⁠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:

  • Minecraft, instead of crashing while loading to main menu, I'm able to launch the game. Crashes in game, after 1 to 30 seconds.
  • Hades, instead of crashing while loading to game. Game is playable for few minutes without crash.
**@⁠dcwxd** on GitHub · 2026-10-30 22:31 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1152#issuecomment-6534876107) Tested this on Windows with RX 5700 XT AMD drivers 26.10.1, seems to fix early crashes in: - Minecraft, instead of crashing while loading to main menu, I'm able to launch the game. Crashes in game, after 1 to 30 seconds. - Hades, instead of crashing while loading to game. Game is playable for few minutes without crash.
Author
Owner

@⁠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

**@⁠virgil48YT** on GitHub · 2026-11-16 22:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1152#issuecomment-6931471968) 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
This pull request can be merged automatically.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/1152/head:github-bot/gh-1152'
git switch 'github-bot/gh-1152'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-1152'
git switch 'github-bot/gh-1152'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-1152'
git switch 'github-bot/gh-1152'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-1152'
git switch 'main'
git merge --squash 'github-bot/gh-1152'
git switch 'main'
git merge --ff-only 'github-bot/gh-1152'
git switch 'main'
git merge 'github-bot/gh-1152'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.