graphics: avoid uvec4 specialization-constant selects in the GPU tiler shaders #795

Closed
github-bot wants to merge 1 commit from gh-pr/795/head into gh-pr/795/base
Owner

@⁠DenizSAHIN570 on GitHub · 2026-09-23 20:26 UTC · original
DenizSAHIN570:fix/gpu-tiler-vec-spec-selects → main · +30 −12 · 3 files · 1 commits · closed without merging

Summary

  • gpu_tiler_standard64_3d.inc, gpu_tiler_prt.comp and gpu_tiler_prt_3d.comp choose their per-element-size bit positions with a ternary chain between uvec4 constants on the ELEMENT_BYTES specialization constant
  • return those constants from early-return helpers instead, the same pattern standard64_3d_extent() already uses in that file
  • the values are unchanged

Problem

GpuTilerCpuParity fails on my machine (Radeon RX 9070 XT, RADV / Mesa 26.2.2, GFX1201):

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

The shader's address math is identical to the CPU reference (Gen5Standard64KBVolumeOffsetInBlock, SOURCES row {4,4,4,5} for 1-byte elements), so it is not a formula disagreement. What I found:

  • 549070 of the 2097152 bytes differ, but only 2127 are still the 0xab fill: the GPU copied real data from the wrong source offsets.
  • The test fills the tiled input with a known hash of the byte index, so I could invert it. For output byte x=8 the reference reads tiled offset 512 (0x200); the GPU read offset 33280 (0x8200). That is an extra flipped bit 15, which is what (x >> 3) & 1 would give, as if the fourth shift constant were 3 instead of 5. This matches the pattern of bad bytes exactly (x 8..15 wrong, 16..23 correct, 24..39 wrong).
  • glslang (-V --target-env vulkan1.3 -Os) compiles the ternary chain to OpSpecConstantOp Select with a scalar bool condition and uvec4 operands (legal in SPIR-V 1.4+). The constants in the module are correct.

I could not identify where the wrong value is produced (constant folding in the driver's SPIR-V front end, the shader compiler, or something else), and I did not find a matching report in Mesa's tracker, so I am not claiming it is a Mesa bug. The construct is easy to avoid, and that is what this PR does.

Change

Each vector ternary chain becomes a small helper (standard64_3d_shifts(), prt_shifts(), prt_3d_shifts()) with early returns, plus a short comment. 3 files, +30/-12. Values are the same as before.

Validation

  • Linux release build (clang); kyty_emulator and shader_recompiler_compute_tests both build against current main (569ec04)
  • SPIR-V compiled with the repo's flags: vector-typed OpSpecConstantOp Select count goes from 4 / 4 / 8 (standard64_3d / prt / prt_3d) to 0 / 0 / 0
  • GpuTilerCpuParity on unmodified main: fails as above (and at family 5 once only the 3D shader is fixed). With this change: ok (330 cases, 236 format/mode pairs).
  • The suite then stops at an unrelated check that also fails on unmodified main: image format does not support required usage: format=129, because this GPU does not support D24_UNORM_S8_UINT. So the full compute suite still cannot complete here, and validation for this change is the tiler test plus the SPIR-V check above. ShaderRecompilerComputeTests.cpp is the only test source that exercises the tiler.
  • The pinned clang-format is clean on the changed lines of the .inc file.

Limits and what would help

  • I only observed this on RADV / Mesa 26.2.2 / RX 9070 XT. I have not run it on Windows or on other vendors, where the original code presumably works.
  • I have not observed the effect in a game. The expectation, not a measurement, is that GPU tiling and detiling of 64 KB 3D and PRT textures would produce wrong data on affected drivers.
  • Runs on other GPUs or Mesa versions would be useful, both to confirm nothing changes elsewhere and to see how widespread the misbehaviour is.

AI assistance

An AI coding assistant was used for this change: to help analyse the failing test, to draft the change, and to draft this description. I ran the builds and test runs above in my own environment and checked their output, and I reviewed the complete diff. All communication on this PR comes from me.

**@⁠DenizSAHIN570** on GitHub · 2026-09-23 20:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/795) `DenizSAHIN570:fix/gpu-tiler-vec-spec-selects` → `main` · +30 −12 · 3 files · 1 commits · closed without merging ## Summary - `gpu_tiler_standard64_3d.inc`, `gpu_tiler_prt.comp` and `gpu_tiler_prt_3d.comp` choose their per-element-size bit positions with a ternary chain between `uvec4` constants on the `ELEMENT_BYTES` specialization constant - return those constants from early-return helpers instead, the same pattern `standard64_3d_extent()` already uses in that file - the values are unchanged ## Problem `GpuTilerCpuParity` fails on my machine (Radeon RX 9070 XT, RADV / Mesa 26.2.2, GFX1201): ``` GpuTilerCpuParity failed at detile bytes family=4 bpe=1: first mismatch at 8 of 2097152 ``` The shader's address math is identical to the CPU reference (`Gen5Standard64KBVolumeOffsetInBlock`, SOURCES row `{4,4,4,5}` for 1-byte elements), so it is not a formula disagreement. What I found: - 549070 of the 2097152 bytes differ, but only 2127 are still the 0xab fill: the GPU copied real data from the wrong source offsets. - The test fills the tiled input with a known hash of the byte index, so I could invert it. For output byte x=8 the reference reads tiled offset 512 (0x200); the GPU read offset 33280 (0x8200). That is an extra flipped bit 15, which is what `(x >> 3) & 1` would give, as if the fourth shift constant were 3 instead of 5. This matches the pattern of bad bytes exactly (x 8..15 wrong, 16..23 correct, 24..39 wrong). - glslang (`-V --target-env vulkan1.3 -Os`) compiles the ternary chain to `OpSpecConstantOp Select` with a scalar bool condition and `uvec4` operands (legal in SPIR-V 1.4+). The constants in the module are correct. I could not identify where the wrong value is produced (constant folding in the driver's SPIR-V front end, the shader compiler, or something else), and I did not find a matching report in Mesa's tracker, so I am not claiming it is a Mesa bug. The construct is easy to avoid, and that is what this PR does. ## Change Each vector ternary chain becomes a small helper (`standard64_3d_shifts()`, `prt_shifts()`, `prt_3d_shifts()`) with early returns, plus a short comment. 3 files, +30/-12. Values are the same as before. ## Validation - Linux release build (clang); `kyty_emulator` and `shader_recompiler_compute_tests` both build against current main (569ec04) - SPIR-V compiled with the repo's flags: vector-typed `OpSpecConstantOp Select` count goes from 4 / 4 / 8 (standard64_3d / prt / prt_3d) to 0 / 0 / 0 - `GpuTilerCpuParity` on unmodified main: fails as above (and at family 5 once only the 3D shader is fixed). With this change: `ok (330 cases, 236 format/mode pairs)`. - The suite then stops at an unrelated check that also fails on unmodified main: `image format does not support required usage: format=129`, because this GPU does not support D24_UNORM_S8_UINT. So the full compute suite still cannot complete here, and validation for this change is the tiler test plus the SPIR-V check above. `ShaderRecompilerComputeTests.cpp` is the only test source that exercises the tiler. - The pinned clang-format is clean on the changed lines of the `.inc` file. ## Limits and what would help - I only observed this on RADV / Mesa 26.2.2 / RX 9070 XT. I have not run it on Windows or on other vendors, where the original code presumably works. - I have not observed the effect in a game. The expectation, not a measurement, is that GPU tiling and detiling of 64 KB 3D and PRT textures would produce wrong data on affected drivers. - Runs on other GPUs or Mesa versions would be useful, both to confirm nothing changes elsewhere and to see how widespread the misbehaviour is. ## AI assistance An AI coding assistant was used for this change: to help analyse the failing test, to draft the change, and to draft this description. I ran the builds and test runs above in my own environment and checked their output, and I reviewed the complete diff. All communication on this PR comes from me.
standard64_3d, prt and prt_3d pick their per-element-size bit positions
with a ternary chain between uvec4 constants on the ELEMENT_BYTES
specialization constant. glslang compiles that to OpSpecConstantOp Select
with a scalar condition and uvec4 operands.

On RADV (Mesa 26.2.2, RX 9070 XT) the fourth component comes out wrong for
1-byte elements, so 64 KB 3D and PRT tiling reads and writes the wrong
bytes. GpuTilerCpuParity fails there ("detile bytes family=4 bpe=1: first
mismatch at 8"), while the shader's address math matches the CPU reference
exactly.

Return the shift constants from early-return helpers instead, the same
pattern standard64_3d_extent() already uses. The values are unchanged. The
compiled SPIR-V no longer contains a vector-typed OpSpecConstantOp Select.

GpuTilerCpuParity passes with this change on the same GPU (330 cases, 236
format/mode pairs).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:32:42 +00:00
github-bot closed this pull request 2026-11-26 09:32:42 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-23 20:28 UTC · original

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

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: 02dc6d58-49a5-4b95-9ea9-371a993fe48d

📥 Commits

Reviewing files that changed from the base of the PR and between 569ec04d1a and e73ebd60f4.

📒 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: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The PRT, PRT 3D, and standard64 3D shader paths now use helper functions to select shift vectors for ELEMENT_BYTES values 1, 2, 4, and 8, with the existing fallback for other values. The offset calculations remain unchanged. Comments document a reported specialization-constant select miscompilation.

Merge Risk: ⚪ Minimal · up to e73eb

No merge-blocking issue is evident in the shader change; it is ready for normal checks.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: replacing problematic uvec4 specialization-constant selects in the GPU tiler shaders.
Description check ✅ Passed The description directly explains the affected shaders, the reported RADV/Mesa issue, the early-return change, unchanged values, and validation results.
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.

Comment @coderabbitai help to get the list of available commands.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-23 20:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/795#issuecomment-5802402339) <!-- 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/795"><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> Navigate logical layers of code changes, visualize relationships, and explore their blast radius. <!-- 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**: `02dc6d58-49a5-4b95-9ea9-371a993fe48d` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 569ec04d1a77127c601eed522ad5bba187173f9d and e73ebd60f40bdf0d890d06c74af9d06e2f422a89. </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:** Your plan provides up to 10 included reviews per hour; 8 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough The PRT, PRT 3D, and standard64 3D shader paths now use helper functions to select shift vectors for `ELEMENT_BYTES` values 1, 2, 4, and 8, with the existing fallback for other values. The offset calculations remain unchanged. Comments document a reported specialization-constant select miscompilation. </details> <!-- walkthrough_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `e73eb` <!-- final_review_risk_coverage:{"sourceCommitId":"e73ebd60f40bdf0d890d06c74af9d06e2f422a89","coveredCommitId":"e73ebd60f40bdf0d890d06c74af9d06e2f422a89","kind":"reviewed"} --> No merge-blocking issue is evident in the shader change; it is ready for normal checks. <!-- 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 and concisely describes the main change: replacing problematic uvec4 specialization-constant selects in the GPU tiler shaders. | | Description check | ✅ Passed | The description directly explains the affected shaders, the reported RADV/Mesa issue, the early-return change, unchanged values, and validation results. | | 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 --> <!-- tips_start --> --- <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠MuteRex on GitHub · 2026-10-21 13:42 UTC · original

Retested on current main (4644c52, 2026-10-21) on a second RDNA4 card, and this is still needed. I'm asking for it to be reopened.

Hardware: RX 9060 XT (RADV GFX1200), Mesa 26.0.8, Ubuntu 26.04, kernel 7.0.0-38. That's a different chip and an older Mesa than the 9070 XT / GFX1201 / Mesa 26.2.2 in the PR description.

gpu_tiler fails on main with exactly the error from the PR description:

GpuTilerCpuParity failed at detile bytes family=4 bpe=1: first mismatch at 8 of 2097152
Build gpu_tiler
main 4644c52 fails (mismatch above)
main 4644c52 + #930 still fails
main 4644c52 + #930 + this PR passes

The diff still applies cleanly to current main. Nothing else regressed: the full suite went from 6 failures to 5, and the remaining ones are unrelated (shader_recompiler_compute / BoundedRecordBufferAccess32, plus 4 emulator CLI tests that only show "Not Run" because I built kyty_tests without the emulator).

I also ran a source build with this PR applied in Resident Evil 2 (PPSA04288) for a while and saw no tiler-related problems. That game's main issue on AMD is a separate GPU hang (#1396).

Logs for all three runs are attached.

AI assistance (Claude) was used to run the suites and summarise the logs. I ran the tests on my own hardware and reviewed the results.

kytyps5-rdna4-pr-tests.zip

**@⁠MuteRex** on GitHub · 2026-10-21 13:42 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/795#issuecomment-6317574008) Retested on current main (4644c52, 2026-10-21) on a second RDNA4 card, and this is still needed. I'm asking for it to be reopened. **Hardware:** RX 9060 XT (RADV GFX1200), Mesa 26.0.8, Ubuntu 26.04, kernel 7.0.0-38. That's a different chip and an older Mesa than the 9070 XT / GFX1201 / Mesa 26.2.2 in the PR description. `gpu_tiler` fails on main with exactly the error from the PR description: ``` GpuTilerCpuParity failed at detile bytes family=4 bpe=1: first mismatch at 8 of 2097152 ``` | Build | `gpu_tiler` | |---|---| | main 4644c52 | fails (mismatch above) | | main 4644c52 + #930 | still fails | | main 4644c52 + #930 + this PR | **passes** | The diff still applies cleanly to current main. Nothing else regressed: the full suite went from 6 failures to 5, and the remaining ones are unrelated (`shader_recompiler_compute` / `BoundedRecordBufferAccess32`, plus 4 emulator CLI tests that only show "Not Run" because I built `kyty_tests` without the emulator). I also ran a source build with this PR applied in Resident Evil 2 (PPSA04288) for a while and saw no tiler-related problems. That game's main issue on AMD is a separate GPU hang (#1396). Logs for all three runs are attached. *AI assistance (Claude) was used to run the suites and summarise the logs. I ran the tests on my own hardware and reviewed the results.* [kytyps5-rdna4-pr-tests.zip](https://github.com/user-attachments/files/33771517/kytyps5-rdna4-pr-tests.zip)

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.