graphics: apply configured SPIR-V shader optimization #1015

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

@⁠nicolasabosch on GitHub · 2026-10-03 18:02 UTC · original
nicolasabosch:perf/shader-optimization → main · +514 −147 · 8 files · 1 commits · closed without merging

The existing None, Size, and Performance shader optimization setting does not reach guest shader compilation. This change passes the configured mode into the recompiler and applies a conservative SPIRV-Tools pipeline after SPIR-V emission.

None preserves the emitted binary. The other modes remove redundant instructions and dead code while preserving descriptor bindings, specialization constants, and stage outputs. The pipeline avoids inlining, loop unrolling, and fast-math changes. Input and output are validated for Vulkan 1.3; optimization failures retain the original module and log diagnostics. Optimization runs during shader compilation, with word counts and elapsed time logged.

Validation

  • Windows Release command-line emulator and relevant test executables built with Clang 21.1.8. The Qt launcher was not built.
  • Repository clang-format 22.1.3 pre-commit hook and git diff --check passed. The hook also reformatted existing code in the touched source files.
  • CTest: 3/3 passed (shader_optimizer, shader_cfg, shader_optimization_gpu).
  • On an NVIDIA GeForce RTX 4070 Laptop GPU, 33 compute and 9 fragment output comparisons passed across None, Size, and Performance. Cases include wave32/wave64 masks, FP64 comparisons, FP16 NaN/signed-zero behavior, memory publication, 64-bit atomic contention, BVH intersections, and fragment interpolation.
  • Across 11 compute fixtures, Size reduced total SPIR-V words from 112,402 to 107,684 (4.20%), and Performance reduced them to 101,722 (9.50%).

These measurements establish shader binary-size reduction and correctness for the selected cases. FPS and driver compilation-time improvements have not been measured. No game benchmark or Linux/macOS build was run; mesh and tessellation stages were not exercised by the new GPU selector.

After configuring a Windows Release build with testing enabled:

cmake --build <build-dir> --target kyty_emulator shader_optimizer_tests shader_cfg_tests shader_recompiler_compute_tests
ctest --test-dir <build-dir> --output-on-failure -R "^(shader_optimizer|shader_cfg|shader_optimization_gpu)$"

The GPU test requires the capabilities checked by the existing Vulkan harness.

AI involvement and review status

Codex researched the change, generated and reviewed the implementation and tests, prepared this description, and executed the build and automated tests above. The contributor explicitly requested this PR, approved reporting the measured results, and confirmed human review of the code. The build and automated tests were executed by Codex; no independent manual testing or game-performance measurements are claimed.

**@⁠nicolasabosch** on GitHub · 2026-10-03 18:02 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1015) `nicolasabosch:perf/shader-optimization` → `main` · +514 −147 · 8 files · 1 commits · closed without merging The existing `None`, `Size`, and `Performance` shader optimization setting does not reach guest shader compilation. This change passes the configured mode into the recompiler and applies a conservative SPIRV-Tools pipeline after SPIR-V emission. `None` preserves the emitted binary. The other modes remove redundant instructions and dead code while preserving descriptor bindings, specialization constants, and stage outputs. The pipeline avoids inlining, loop unrolling, and fast-math changes. Input and output are validated for Vulkan 1.3; optimization failures retain the original module and log diagnostics. Optimization runs during shader compilation, with word counts and elapsed time logged. ## Validation - Windows Release command-line emulator and relevant test executables built with Clang 21.1.8. The Qt launcher was not built. - Repository clang-format 22.1.3 pre-commit hook and `git diff --check` passed. The hook also reformatted existing code in the touched source files. - CTest: **3/3 passed** (`shader_optimizer`, `shader_cfg`, `shader_optimization_gpu`). - On an NVIDIA GeForce RTX 4070 Laptop GPU, **33 compute and 9 fragment output comparisons passed** across None, Size, and Performance. Cases include wave32/wave64 masks, FP64 comparisons, FP16 NaN/signed-zero behavior, memory publication, 64-bit atomic contention, BVH intersections, and fragment interpolation. - Across 11 compute fixtures, Size reduced total SPIR-V words from 112,402 to 107,684 (**4.20%**), and Performance reduced them to 101,722 (**9.50%**). These measurements establish shader binary-size reduction and correctness for the selected cases. FPS and driver compilation-time improvements have not been measured. No game benchmark or Linux/macOS build was run; mesh and tessellation stages were not exercised by the new GPU selector. After configuring a Windows Release build with testing enabled: ```text cmake --build <build-dir> --target kyty_emulator shader_optimizer_tests shader_cfg_tests shader_recompiler_compute_tests ctest --test-dir <build-dir> --output-on-failure -R "^(shader_optimizer|shader_cfg|shader_optimization_gpu)$" ``` The GPU test requires the capabilities checked by the existing Vulkan harness. ## AI involvement and review status Codex researched the change, generated and reviewed the implementation and tests, prepared this description, and executed the build and automated tests above. The contributor explicitly requested this PR, approved reporting the measured results, and confirmed human review of the code. The build and automated tests were executed by Codex; no independent manual testing or game-performance measurements are claimed.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:40:27 +00:00
github-bot closed this pull request 2026-11-26 09:40:27 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-03 18:12 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: 21eadac9-9c4b-473c-a0ae-174d0ec092b6
📥 Commits

Reviewing files that changed from the base of the PR and between e7f6327068 and 71bf7e06a4.

📒 Files selected for processing (8)
  • CMakeLists.txt
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
  • src/graphics/shader/recompiler/ShaderRecompiler.cpp
  • src/graphics/shader/recompiler/ShaderRecompiler.h
  • src/graphics/shader/recompiler/backend/spirv/SpirvOptimizer.cpp
  • src/graphics/shader/recompiler/backend/spirv/SpirvOptimizer.h
  • tests/ShaderOptimizerTests.cpp
  • tests/ShaderRecompilerComputeTests.cpp

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

The change adds None, Size, and Performance SPIR-V optimization modes to shader compilation. The optimizer validates optimized modules before replacing the original and reports diagnostics on failure. Compilation obtains the selected mode from configuration and retains the original shader if optimization fails. New unit and GPU tests cover optimizer behavior and selected compute and graphics cases.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 71bf7

No actionable issue remains in the supplied review evidence. The PR is mergeable after normal checks.

Security Architecture Review

Security architecture risk: 🔵 Low · up to 71bf7

The change adds processing of game-provided shader data without an observed increase in privileges. Optimized results are validated before use, and ordinary failures retain the original shader. Abnormal-failure behavior and changing settings during execution remain incompletely established; no introduced vulnerability was demonstrated.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Guest shader content can influence the new native optimizer through recompiler-generated SPIR-V. The inspected exposure remains within the existing emulator process and host GPU compilation path; no additional identity, privilege, or cross-service authority transition was observed.

Trust Boundaries and Controls

  • observed — The host configuration selects optimization policy, while guest data supplies shader content through the existing compilation path. Optimization occurs after host resource materialization and binding allocation; it does not add a guest-memory callback or transfer descriptor ownership to the optimizer.

Resilience and Maintainability Implications

  • inferred — Local candidate ownership and validation-before-replacement contain ordinary optimizer failures without introducing a partially transformed module into the cache. These controls do not establish containment of native-library crashes, resource exhaustion, or interruption; no such exploitable failure was demonstrated.
🚥 Pre-merge checks | ✅ 4 | ❓ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ❓ Inconclusive Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 6 files. (2 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: applying the configured SPIR-V shader optimization during graphics compilation.
Description check ✅ Passed The description explains how the configured optimization mode reaches shader compilation, describes the optimization and fallback behavior, and reports validation and test results relevant to the chan…
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.
Full details: Docstring Coverage

Explanation

Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 6 files. (2 skipped: 1 unsupported, 1 too large.)

  • 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-03 18:12 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1015#issuecomment-5972034983) <!-- 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/1015?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> 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**: `21eadac9-9c4b-473c-a0ae-174d0ec092b6` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e7f6327068ff565d42b55641a11c30a6be5a01f6 and 71bf7e06a45b454abb865d985585b263acc3922c. </details> <details> <summary>📒 Files selected for processing (8)</summary> * `CMakeLists.txt` * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` * `src/graphics/shader/recompiler/ShaderRecompiler.cpp` * `src/graphics/shader/recompiler/ShaderRecompiler.h` * `src/graphics/shader/recompiler/backend/spirv/SpirvOptimizer.cpp` * `src/graphics/shader/recompiler/backend/spirv/SpirvOptimizer.h` * `tests/ShaderOptimizerTests.cpp` * `tests/ShaderRecompilerComputeTests.cpp` </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 The change adds `None`, `Size`, and `Performance` SPIR-V optimization modes to shader compilation. The optimizer validates optimized modules before replacing the original and reports diagnostics on failure. Compilation obtains the selected mode from configuration and retains the original shader if optimization fails. New unit and GPU tests cover optimizer behavior and selected compute and graphics cases. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"71bf7e06a45b454abb865d985585b263acc3922c" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `71bf7` <!-- final_review_risk_coverage:{"sourceCommitId":"71bf7e06a45b454abb865d985585b263acc3922c","coveredCommitId":"71bf7e06a45b454abb865d985585b263acc3922c","kind":"reviewed"} --> No actionable issue remains in the supplied review evidence. The PR is mergeable after normal checks. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `71bf7` The change adds processing of game-provided shader data without an observed increase in privileges. Optimized results are validated before use, and ordinary failures retain the original shader. Abnormal-failure behavior and changing settings during execution remain incompletely established; no introduced vulnerability was demonstrated. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — Guest shader content can influence the new native optimizer through recompiler-generated SPIR-V. The inspected exposure remains within the existing emulator process and host GPU compilation path; no additional identity, privilege, or cross-service authority transition was observed. **Trust Boundaries and Controls** - _observed_ — The host configuration selects optimization policy, while guest data supplies shader content through the existing compilation path. Optimization occurs after host resource materialization and binding allocation; it does not add a guest-memory callback or transfer descriptor ownership to the optimizer. **Resilience and Maintainability Implications** - _inferred_ — Local candidate ownership and validation-before-replacement contain ordinary optimizer failures without introducing a partially transformed module into the cache. These controls do not establish containment of native-library crashes, resource exhaustion, or interruption; no such exploitable failure was demonstrated. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❓ 1</summary> ### ❌ Failed checks (1 inconclusive) | Check name | Status | Explanation | Resolution | | :----------------: | :------------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ❓ Inconclusive | Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 6 files. (2 skipped: … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly summarizes the main change: applying the configured SPIR-V shader optimization during graphics compilation. | | Description check | ✅ Passed | The description explains how the configured optimization mode reaches shader compilation, describes the optimization and fallback behavior, and reports validation and test results relevant to the chan… | | 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> <summary>Full details: Docstring Coverage</summary> **Explanation** Docstring coverage is 12.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 24 functions across 6 files. (2 skipped: 1 unsupported, 1 too large.) </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=1015)! 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 -->

Pull request closed

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