Collected sampler/graphics fixes for Neptunia ReVerse (PPSA02721) #857

Closed
github-bot wants to merge 9 commits from gh-pr/857/head into gh-pr/857/base
Owner

@⁠EmK530 on GitHub · 2026-09-26 21:58 UTC · original
EmK530:shader/neptunia-fixes → main · +274 −22 · 18 files · 9 commits · closed without merging

Notice

Every change targeting a fix for the game is isolated into its own commit, this PR description will go over every change made and why it was made. I've categorized each commit into two sections: one section is critical for getting the game to function, the other section is for extra fixes that get the game to pass Vulkan validation.
The commits to pass validation are not mandatory to include but are a part of this PR in case they may be of value, leave them out of cherry-picking if they are wrong or not desired.

Critical commits

  • a6e271b: Fix blending on reordered-channel render targets.
    • This commit fixes the game's glitchy blue look. Neptunia's bloom target uses a reversed channel order which Kyty stores correctly, but Vulkan's SRC_ALPHA blend would incorrectly read a large red channel and treat it as an abnormally high alpha value.
    • This commit changes afflicted shaders by writing their alpha to a second output and makes the blend use that. This imposes no new hardware requirement as Kyty already enables the requirement for dualSrcBlend.
    • Only the first color target is covered because the fix uses dual-source blending, which Vulkan usually limits to a single attachment. It also needs MRT1 free for the second output.
    • On reordered-channel targets, blends that this fix can't handle are disabled with a one-time console warning. This can be changed for an EXIT call if preferred.
  • d699613 + 156e6ba: Clear stale buffer GPU-dirty records when a render target overwrites them.
    • This commit (d699613) fixes random black frames in the game. During gameplay Neptunia clears the display buffer with a compute fill, which marks that memory region as GPU-modified in the buffer cache. When a render target later draws into the same region, the flag is never reset and the region is still deemed GPU-modified. This caused SafeToDownload to fail, so the GC freed the image without saving it. At the next flip no image was found for the display buffer so a new one was created from empty data and black was presented.
    • The second commit addresses an error in ShaderRecompilerComputeTests.cpp which had a check to ensure DiscardGpuDirtyBytes was absent, which it no longer is. The test case has been updated to account for this. The discard was removed by the perf refactor (b877b4b).
  • bdc9668: Dodge unknown anisotropy ratio crashes and default to 16x.
    • This is a relatively simple commit: Neptunia experiences crashes from anisotropy ratios like 5 and 7 which are defaulted to 16x rather than hard-crashing, may need more investigation.

Validation fixes

These commits cover crashes only present with Vulkan validation, may be useful regardless so they are documented and included in this PR.
Tests were performed on a RTX 5070, validation errors may not show on all system configurations.

  • 5222898: Emulate unnormalized sampler coordinates in the shader.
    • Vulkan's unnormalized-coordinate samplers forbid several things Neptunia does (differing min/mag filters, implicit LOD, depth comparison, multi-level views), which stops the game on validation. The Vulkan sampler now stays normal, and the shader converts texel coordinates by dividing by the image size and sampling level 0.
    • Not covered: gather instructions and cube maps with such samplers.
    • The description of this change was AI-written. The commit is confirmed to clear the validation error in Neptunia ReVerse, but sampled output is not compared against hardware.
  • b23d7cd: Change 5:6:5 targets to R5G6B5 and apply a red/blue swap.
    • Vulkan threw an error since B5G6R5 isn't a usable color target. This commit changes the formats of these targets to R5G6B5 and applies a red/blue color channel swap to preserve proper coloring.
    • Without validation, targets affected by this issue are rendered blank which may affect rendered output.
  • f2faaa6: Clamp mipLodBias to not be greater than maxSamplerLodBias.
    • Simple clamp edit to mipLodBias to avoid a Vulkan error encountered where the game asked for a mipLodBias of about 31.67, whereas the limit on my device was 15.
  • ffa9c62: Clamp min_lod to not be greater than max_lod.
    • Dodges a validation error where the game set an inverted LOD range which Vulkan would reject, the minimum gets lowered to the maximum in these cases.

Testing

Broad tests have not been performed on these commits, a quick verification on ASTRO BOT was made to ensure nothing regressed before this PR was submitted, suggested to scrutinize each commit before cherry-picking.
Test files were modified by commits: b23d7cd, 156e6ba and have been ran to ensure all pass which they do.

AI usage

AI was involved in the process of investigating issues and was responsible for implementing most changes. I have studied the changes in post and written the PR and change descriptions myself unless explicitly stated (5222898).

**@⁠EmK530** on GitHub · 2026-09-26 21:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/857) `EmK530:shader/neptunia-fixes` → `main` · +274 −22 · 18 files · 9 commits · closed without merging # Notice Every change targeting a fix for the game is isolated into its own commit, this PR description will go over every change made and why it was made. I've categorized each commit into two sections: one section is critical for getting the game to function, the other section is for extra fixes that get the game to pass Vulkan validation. The commits to pass validation are not mandatory to include but are a part of this PR in case they may be of value, leave them out of cherry-picking if they are wrong or not desired. ## Critical commits - a6e271b: **Fix blending on reordered-channel render targets.** - This commit fixes the game's glitchy blue look. Neptunia's bloom target uses a reversed channel order which Kyty stores correctly, but Vulkan's `SRC_ALPHA` blend would incorrectly read a large red channel and treat it as an abnormally high alpha value. - This commit changes afflicted shaders by writing their alpha to a second output and makes the blend use that. This imposes no new hardware requirement as Kyty already enables the requirement for `dualSrcBlend`. - **Only the first color target is covered** because the fix uses dual-source blending, which Vulkan usually limits to a single attachment. It also needs MRT1 free for the second output. - **On reordered-channel targets, blends that this fix can't handle are disabled** with a one-time console warning. This can be changed for an `EXIT` call if preferred. - ~~d699613 + 156e6ba: **Clear stale buffer GPU-dirty records when a render target overwrites them.**~~ - This commit (d699613) fixes random black frames in the game. During gameplay Neptunia clears the display buffer with a compute fill, which marks that memory region as GPU-modified in the buffer cache. When a render target later draws into the same region, the flag is never reset and the region is still deemed GPU-modified. This caused `SafeToDownload` to fail, so the GC freed the image without saving it. At the next flip no image was found for the display buffer so a new one was created from empty data and black was presented. - The second commit addresses an error in ShaderRecompilerComputeTests.cpp which had a check to ensure DiscardGpuDirtyBytes was absent, which it no longer is. The test case has been updated to account for this. The discard was removed by the perf refactor (b877b4b). - ~~bdc9668: **Dodge unknown anisotropy ratio crashes and default to 16x.**~~ - This is a relatively simple commit: Neptunia experiences crashes from anisotropy ratios like 5 and 7 which are defaulted to 16x rather than hard-crashing, may need more investigation. ## Validation fixes These commits cover crashes only present with Vulkan validation, may be useful regardless so they are documented and included in this PR. **Tests were performed on a RTX 5070, validation errors may not show on all system configurations.** - 5222898: **Emulate unnormalized sampler coordinates in the shader.** - Vulkan's unnormalized-coordinate samplers forbid several things Neptunia does (differing min/mag filters, implicit LOD, depth comparison, multi-level views), which stops the game on validation. The Vulkan sampler now stays normal, and the shader converts texel coordinates by dividing by the image size and sampling level 0. - Not covered: gather instructions and cube maps with such samplers. - *The description of this change was AI-written. The commit is confirmed to clear the validation error in Neptunia ReVerse, but sampled output is not compared against hardware.* - b23d7cd: **Change 5:6:5 targets to R5G6B5 and apply a red/blue swap.** - Vulkan threw an error since B5G6R5 isn't a usable color target. This commit changes the formats of these targets to R5G6B5 and applies a red/blue color channel swap to preserve proper coloring. - Without validation, targets affected by this issue are rendered blank which may affect rendered output. - f2faaa6: **Clamp `mipLodBias` to not be greater than `maxSamplerLodBias`.** - Simple clamp edit to mipLodBias to avoid a Vulkan error encountered where the game asked for a mipLodBias of about `31.67`, whereas the limit on my device was `15`. - ffa9c62: **Clamp `min_lod` to not be greater than `max_lod`.** - Dodges a validation error where the game set an inverted LOD range which Vulkan would reject, the minimum gets lowered to the maximum in these cases. ## Testing Broad tests have not been performed on these commits, a quick verification on ASTRO BOT was made to ensure nothing regressed before this PR was submitted, suggested to scrutinize each commit before cherry-picking. Test files were modified by commits: b23d7cd, 156e6ba and have been ran to ensure all pass which they do. ## AI usage AI was involved in the process of investigating issues and was responsible for implementing most changes. I have studied the changes in post and written the PR and change descriptions myself unless explicitly stated (5222898).
Render targets with a non-identity export mapping (e.g. ABGR RGBA16F) were
blended with the physical alpha channel, because the shader swizzles its
output before Vulkan's fixed-function blend runs. Hardware blends on
logical components, so SRC_ALPHA/ONE_MINUS_SRC_ALPHA picked up an unrelated
channel (values up to ~1000 in Neptunia ReVerse's bloom pass), producing
static and a blue cast.

For target 0 blending only with source-alpha factors, output the logical
alpha as a second source (MRT1) and map the factors to SRC1_COLOR /
ONE_MINUS_SRC1_COLOR. Cases that cannot be expressed (destination alpha,
differing alpha equation, guest dual-source, slot != 0) disable blending
with a one-time warning instead of blending with the wrong channel.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Anisotropy ratio encodings 5-7 are reserved. Neptunia ReVerse binds
descriptors with such a value in slots the shader never samples, and the
EXIT("unknown ratio") stopped the emulator. Use the maximum ratio and log
the descriptor once instead.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
A compute buffer fill marks its range GPU-dirty in the buffer cache. When a
render target later draws into the same memory, CommitGpuWrite cleared the
image's buffer-modified flag but left the buffer cache's dirty bytes, so
SafeToDownload kept failing for that image. The texture GC then freed the
GPU-modified display image without saving it, the next flip found no image
and presented black (Neptunia ReVerse). The stale dirty pages were also
read-protected, so a guest read would have flushed the old fill bytes over
the real contents.

Add BufferCache::DiscardGpuDirtyBytes and call it from CommitGpuWrite for
the image's range. Tracker pages are only released when no dirty bytes
remain in them, keeping the tracker and byte ranges consistent.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
Guest samplers can address texels directly (bit 15 of the first sampler
dword). Vulkan's unnormalized samplers are far more restricted: min and mag
filter must match, and implicit LOD, depth comparison and multi-level views
are forbidden. Neptunia ReVerse breaks all three, and validation stops at
the first one.

Keep the Vulkan sampler normalized. Carry the flag from the sampler
descriptor through resource specialization to the shader, which divides the
spatial coordinates by the image size (OpImageQuerySizeLod) and samples
level zero explicitly. Depth comparison and the requested filters are
preserved.

Gather instructions and cube maps are not handled for such samplers.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
d699613 restores DiscardGpuDirtyBytes (removed in b877b4b) so a render
target write clears stale buffer GPU-dirty bytes. Drop the static_assert
that pinned its absence.

Co-Authored-By: Claude Sonnet 5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:35:14 +00:00
github-bot closed this pull request 2026-11-26 09:35:14 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-26 22:09 UTC · original · edited 2026-09-28 18:38 UTC

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: 3c8d8daf-30d8-4827-83ba-86f89a0abdf6

📥 Commits

Reviewing files that changed from the base of the PR and between 156e6ba7ea and c9fb9fe494.

📒 Files selected for processing (7)
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/samplerCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.h
  • tests/ShaderRecompilerComputeTests.cpp
  • tests/shaderCfgTests.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 changes add GPU-dirty byte tracking updates after image writes, sampler-state specialization and shader-side emulation for unnormalized coordinates, and blend handling for mapped color outputs. They also add RGB565 format resolution and update related tests.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🟡 Moderate · up to c9fb9

Some mapped blends and texture gathers can render incorrectly, and a sparse multi-target shader can terminate. Resolve or explicitly accept these risks before merging.

Security Architecture Review

Security architecture risk: 🟡 Moderate · up to c9fb9

The memory-ownership change may allow a guest-memory read before updated image contents are available in backing memory. No new privilege or cross-tenant exposure has been established, but the synchronization path needs confirmation.

Retained concerns

  • Medium · reliability · inferred: Removing buffer dirty tracking at image-write commit may release guest-memory read protection before the image has been synchronized back to CPU-visible memory. The inspected CPU fault path downloads only through the buffer cache; an image-owned readback at that transition is not established.
Security review details

Security Blast Radius

  • inferred — The identified uncertainty affects GPU-written guest-memory ranges shared by buffer and image caches. Available evidence does not establish exposure beyond that renderer memory path.

Trust Boundaries and Controls

  • observed — Host Vulkan sampler creation no longer requests unnormalized coordinates. The inspected shader path instead enforces level-zero sampling and coordinate conversion for regular non-cube samples; equivalent behavior for other sampling operations remains unverified.

Resilience and Maintainability Implications

  • inferred — The memory-ownership handoff lacks an established CPU-read synchronization path in the inspected sources. This is a data-consistency and failure-containment uncertainty, not a verified confidentiality or privilege-escalation finding.

Hardening Proposals

  • proposed — Establish an explicit owner-and-completion invariant for CPU reads after buffer dirty bytes are discarded in favor of an image, including partial writes and interrupted GPU work.
🚥 Pre-merge checks | ✅ 4 | ❓ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ❓ Inconclusive Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 16 files. (2 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
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.
Title check ✅ Passed The title clearly identifies a collection of sampler and graphics fixes for Neptunia ReVerse and matches the main changes in the pull request.
Description check ✅ Passed The description directly explains the graphics, sampler, validation, testing, and game-specific fixes included in the pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 16 files. (2 skipped: 2 too large.)


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-09-26 22:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/857#issuecomment-5850331622) · edited 2026-09-28 18:38 UTC <!-- 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/857"><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**: `3c8d8daf-30d8-4827-83ba-86f89a0abdf6` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 156e6ba7ea8504c8267a9fb70b7ca2365b5db00f and c9fb9fe494fa19c9eb68633cdde7fcfc0866ce7f. </details> <details> <summary>📒 Files selected for processing (7)</summary> * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/cache/samplerCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.h` * `tests/ShaderRecompilerComputeTests.cpp` * `tests/shaderCfgTests.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 changes add GPU-dirty byte tracking updates after image writes, sampler-state specialization and shader-side emulation for unnormalized coordinates, and blend handling for mapped color outputs. They also add RGB565 format resolution and update related tests. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"c9fb9fe494fa19c9eb68633cdde7fcfc0866ce7f" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🟡 Moderate_ · up to `c9fb9` <!-- final_review_risk_coverage:{"sourceCommitId":"c9fb9fe494fa19c9eb68633cdde7fcfc0866ce7f","coveredCommitId":"c9fb9fe494fa19c9eb68633cdde7fcfc0866ce7f","kind":"reviewed"} --> Some mapped blends and texture gathers can render incorrectly, and a sparse multi-target shader can terminate. Resolve or explicitly accept these risks before merging. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🟡 Moderate_ · up to `c9fb9` The memory-ownership change may allow a guest-memory read before updated image contents are available in backing memory. No new privilege or cross-tenant exposure has been established, but the synchronization path needs confirmation. **Retained concerns** - **Medium · reliability · inferred:** Removing buffer dirty tracking at image-write commit may release guest-memory read protection before the image has been synchronized back to CPU-visible memory. The inspected CPU fault path downloads only through the buffer cache; an image-owned readback at that transition is not established. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — The identified uncertainty affects GPU-written guest-memory ranges shared by buffer and image caches. Available evidence does not establish exposure beyond that renderer memory path. **Trust Boundaries and Controls** - _observed_ — Host Vulkan sampler creation no longer requests unnormalized coordinates. The inspected shader path instead enforces level-zero sampling and coordinate conversion for regular non-cube samples; equivalent behavior for other sampling operations remains unverified. **Resilience and Maintainability Implications** - _inferred_ — The memory-ownership handoff lacks an established CPU-read synchronization path in the inspected sources. This is a data-consistency and failure-containment uncertainty, not a verified confidentiality or privilege-escalation finding. **Hardening Proposals** - _proposed_ — Establish an explicit owner-and-completion invariant for CPU reads after buffer dirty bytes are discarded in favor of an image, including partial writes and interrupted GPU work. </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 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 16 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 | | :------------------------: | :------- | :--------------------------------------------------------------------------------------------------------------------------------------------- | | 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. | | Title check | ✅ Passed | The title clearly identifies a collection of sampler and graphics fixes for Neptunia ReVerse and matches the main changes in the pull request. | | Description check | ✅ Passed | The description directly explains the graphics, sampler, validation, testing, and game-specific fixes included in the pull request. | </details> <details> <summary>Full details: Docstring Coverage</summary> **Explanation** Docstring coverage is 15.38% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 26 functions across 16 files. (2 skipped: 2 too large.) </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=857)! 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 -->
@ -178,0 +217,4 @@
BlendMappingSupport ClassifyBlendMapping(const HW::BlendControl& blend,
const Prospero::ColorComponentMapping& mapping) {
if (mapping.IsIdentity() || mapping.Map(3) == 3u) {
return BlendMappingSupport::Direct;
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-26 22:09 UTC · original

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not classify permuted constant-color blending as direct.

A mapping such as ColorMappingBgra keeps alpha in physical A, so this branch returns Direct. If a blend factor is kConstantColor or kOneMinusConstantColor and the R and B blend constants differ, the shader swaps the exported channels but the Vulkan blend constants remain in physical channel order. The resulting blend differs from the guest blend. The later !uses_alpha return has the same problem when a mapping moves alpha. Reject these factor-and-mapping combinations, or permute the blend constants consistently. (docs.vulkan.org)

**@⁠coderabbitai[bot]** on GitHub · 2026-09-26 22:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/857#discussion_r4112976659) _🎯 Functional Correctness_ | _🟠 Major_ | _⚡ Quick win_ **Do not classify permuted constant-color blending as direct.** A mapping such as `ColorMappingBgra` keeps alpha in physical A, so this branch returns `Direct`. If a blend factor is `kConstantColor` or `kOneMinusConstantColor` and the R and B blend constants differ, the shader swaps the exported channels but the Vulkan blend constants remain in physical channel order. The resulting blend differs from the guest blend. The later `!uses_alpha` return has the same problem when a mapping moves alpha. Reject these factor-and-mapping combinations, or permute the blend constants consistently. ([docs.vulkan.org](https://docs.vulkan.org/spec/latest/chapters/framebuffer.html)) <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:570c0efe5a82884fac60458a --> <!-- This is an auto-generated comment by CodeRabbit -->
@ -622,1 +687,4 @@
pixel_info.target_export_mapping[1] = pixel_info.target_export_mapping[0];
} else if (blend.enable && !context.GetRenderTarget(0).info.blend_bypass &&
pixel_info.target_output_mode[0] != 0 && pixel_info.target_output_mode[1] == 0 &&
ClassifyBlendMapping(blend, pixel_info.target_export_mapping[0]) ==
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-26 22:09 UTC · original

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Keep the remap path off shaders with other MRT outputs.

If MRT1 is disabled but a pixel shader exports MRT2, this condition enables dual_source_blending. DefineOutputs in src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp then calls EXIT_NOT_IMPLEMENTED for the MRT2 binding because its index exceeds 1. The new path turns a sparse multi-target draw into a termination. Check all other MRT outputs before selecting the remap path, and use the unsupported-blend fallback when they are present. Dual-source attachment capacity is also device-dependent. (docs.vulkan.org)

**@⁠coderabbitai[bot]** on GitHub · 2026-09-26 22:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/857#discussion_r4112976662) _🩺 Stability & Availability_ | _🟠 Major_ | _⚡ Quick win_ **Keep the remap path off shaders with other MRT outputs.** If MRT1 is disabled but a pixel shader exports MRT2, this condition enables `dual_source_blending`. `DefineOutputs` in `src/graphics/shader/recompiler/backend/spirv/spirvEmitterModule.cpp` then calls `EXIT_NOT_IMPLEMENTED` for the MRT2 binding because its index exceeds 1. The new path turns a sparse multi-target draw into a termination. Check all other MRT outputs before selecting the remap path, and use the unsupported-blend fallback when they are present. Dual-source attachment capacity is also device-dependent. ([docs.vulkan.org](https://docs.vulkan.org/spec/latest/chapters/framebuffer.html)) <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:3b2df493dfa7291ec23bbb7d --> <!-- This is an auto-generated comment by CodeRabbit -->
@ -476,0 +491,4 @@
const uint32_t components = info.coordinate_components;
std::vector<uint32_t> words {spv::OpCompositeConstruct, TypeF32Vector(state, components),
state.builder.AllocateId()};
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-26 22:09 UTC · original

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

#!/bin/bash
# Inspect the type helper without building or running repository code.
ast-grep outline src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h \
  --match TypeF32Vector --view expanded
rg -n -C 6 --glob '*.{h,cpp}' 'TypeF32Vector\s*\(' src/graphics/shader/recompiler/backend/spirv

Repository: KytyPS5/KytyPS5

Length of output: 40575


🏁 Script executed:

#!/bin/bash
sed -n '460,525p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
rg -n -C 8 'coordinate_components|ImageDimensionInfoFor|struct ImageDimension|class ImageDimension' src/graphics/shader/recompiler/backend/spirv src/graphics/shader/recompiler

Repository: KytyPS5/KytyPS5

Length of output: 41993


Use a scalar type for one-dimensional coordinates.

Dim1D sets coordinate_components to one. TypeF32Vector always requests OpTypeVector, so the scalar early return occurs after an invalid one-component vector type is created.

🐛 Suggested fix
-	std::vector<uint32_t> words {spv::OpCompositeConstruct, TypeF32Vector(state, components),
+	const auto type = components == 1u ? TypeF32(state) : TypeF32Vector(state, components);
+	std::vector<uint32_t> words {spv::OpCompositeConstruct, type,
 	                             state.builder.AllocateId()};
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

	const auto type = components == 1u ? TypeF32(state) : TypeF32Vector(state, components);
	std::vector<uint32_t> words {spv::OpCompositeConstruct, type,
	                             state.builder.AllocateId()};
**@⁠coderabbitai[bot]** on GitHub · 2026-09-26 22:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/857#discussion_r4112976664) _🩺 Stability & Availability_ | _🟡 Minor_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash #!/bin/bash # Inspect the type helper without building or running repository code. ast-grep outline src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h \ --match TypeF32Vector --view expanded rg -n -C 6 --glob '*.{h,cpp}' 'TypeF32Vector\s*\(' src/graphics/shader/recompiler/backend/spirv ``` Repository: KytyPS5/KytyPS5 Length of output: 40575 --- 🏁 Script executed: ```bash #!/bin/bash sed -n '460,525p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp rg -n -C 8 'coordinate_components|ImageDimensionInfoFor|struct ImageDimension|class ImageDimension' src/graphics/shader/recompiler/backend/spirv src/graphics/shader/recompiler ``` Repository: KytyPS5/KytyPS5 Length of output: 41993 --- </details> **Use a scalar type for one-dimensional coordinates.** `Dim1D` sets `coordinate_components` to one. `TypeF32Vector` always requests `OpTypeVector`, so the scalar early return occurs after an invalid one-component vector type is created. <details> <summary>🐛 Suggested fix</summary> ```diff - std::vector<uint32_t> words {spv::OpCompositeConstruct, TypeF32Vector(state, components), + const auto type = components == 1u ? TypeF32(state) : TypeF32Vector(state, components); + std::vector<uint32_t> words {spv::OpCompositeConstruct, type, state.builder.AllocateId()}; ``` </details> <!-- suggestion_start --> <details> <summary>📝 Committable suggestion</summary> > ‼️ **IMPORTANT** > Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements. ```suggestion const auto type = components == 1u ? TypeF32(state) : TypeF32Vector(state, components); std::vector<uint32_t> words {spv::OpCompositeConstruct, type, state.builder.AllocateId()}; ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:de07b78cd183d56cd6c5b11b --> <!-- This is an auto-generated comment by CodeRabbit -->
@ -717,0 +761,4 @@
// Unnormalized samplers have no mip selection, so they sample level zero explicitly.
const bool unnormalized = mem.sampler < state.program.info.samplers.size() &&
state.program.info.samplers[mem.sampler].unnormalized;
const bool explicit_lod = unnormalized || HasFlag(mem, Decoder::ImageSampleFlagDerivative) ||
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-26 22:09 UTC · original

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

Handle unnormalized coordinates in the gather branch.

ImageGatherRaw returns before this flag is read. For a 2D gather with a force-unnormalized sampler, the gather branch passes texel coordinates directly to the normalized Vulkan sampler. Coordinates such as (4, 4) then address the wrong texels. Read the flag before the gather branch and convert gather coordinates using the image extent. The 1D gather helper also needs its coordinate input checked. (registry.khronos.org)

**@⁠coderabbitai[bot]** on GitHub · 2026-09-26 22:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/857#discussion_r4112976670) _🎯 Functional Correctness_ | _🟠 Major_ | _🏗️ Heavy lift_ **Handle unnormalized coordinates in the gather branch.** `ImageGatherRaw` returns before this flag is read. For a 2D gather with a force-unnormalized sampler, the gather branch passes texel coordinates directly to the normalized Vulkan sampler. Coordinates such as `(4, 4)` then address the wrong texels. Read the flag before the gather branch and convert gather coordinates using the image extent. The 1D gather helper also needs its coordinate input checked. ([registry.khronos.org](https://registry.khronos.org/vulkan/specs/latest/man/html/VkSamplerCreateInfo.html?utm_source=openai)) <!-- fingerprinting:phantom:poseidon:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:066379a19aea0b9100b34a3e --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-26 22:09 UTC · original · reviewed

Actionable comments posted: 4


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml

Review profile: CHILL

Plan: Advanced

Run ID: f322eda5-d834-41ee-9907-1d11e35bfccd

📥 Commits

Reviewing files that changed from the base of the PR and between a22a9d9348 and 156e6ba7ea.

📒 Files selected for processing (18)
  • src/graphics/host_gpu/renderer/cache/bufferCache.cpp
  • src/graphics/host_gpu/renderer/cache/bufferCache.h
  • src/graphics/host_gpu/renderer/cache/samplerCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/image/textureCommon.cpp
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.h
  • src/graphics/host_gpu/renderer/pipeline/shaders.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.h
  • src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpp
  • src/graphics/shader/shader.cpp
  • src/graphics/shader/shader.h
  • tests/ShaderRecompilerComputeTests.cpp
  • tests/shaderCfgTests.cpp

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-26 22:09 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/857#pullrequestreview-5327669138) · **reviewed** **Actionable comments posted: 4** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `f322eda5-d834-41ee-9907-1d11e35bfccd` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between a22a9d9348bb079c6b97c7f14ffb47d9b754fa44 and 156e6ba7ea8504c8267a9fb70b7ca2365b5db00f. </details> <details> <summary>📒 Files selected for processing (18)</summary> * `src/graphics/host_gpu/renderer/cache/bufferCache.cpp` * `src/graphics/host_gpu/renderer/cache/bufferCache.h` * `src/graphics/host_gpu/renderer/cache/samplerCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/image/textureCommon.cpp` * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.h` * `src/graphics/host_gpu/renderer/pipeline/shaders.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterFlow.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp` * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.h` * `src/graphics/shader/recompiler/ir/passes/ShaderInfoCollection.cpp` * `src/graphics/shader/shader.cpp` * `src/graphics/shader/shader.h` * `tests/ShaderRecompilerComputeTests.cpp` * `tests/shaderCfgTests.cpp` </details> **Included review availability:** This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
Author
Owner

@⁠EmK530 on GitHub · 2026-09-27 13:28 UTC · original

Resolved conflict from 9229c04, commit bdc9668 no longer applies 🎉

**@⁠EmK530** on GitHub · 2026-09-27 13:28 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/857#issuecomment-5856278182) Resolved conflict from 9229c04, commit bdc9668 no longer applies 🎉
Author
Owner

@⁠EmK530 on GitHub · 2026-09-28 18:36 UTC · original

Verified recent changes, this PR's commit d699613 is now obsolete as it was resolved by 6ee1bf9 🎉

**@⁠EmK530** on GitHub · 2026-09-28 18:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/857#issuecomment-5876197463) Verified recent changes, this PR's commit d699613 is now obsolete as it was resolved by 6ee1bf9 🎉
Author
Owner

@⁠Nmzik on GitHub · 2026-09-29 16:08 UTC · original · edited 2026-09-29 16:11 UTC

@⁠EmK530 Thanks for detailed PR. I loved it. sorry for waiting. Everything cherry picked. I checked Vulkan validation too. Will leave them for now except one

**@⁠Nmzik** on GitHub · 2026-09-29 16:08 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/857#issuecomment-5894016874) · edited 2026-09-29 16:11 UTC @⁠EmK530 Thanks for detailed PR. I loved it. sorry for waiting. Everything cherry picked. I checked Vulkan validation too. Will leave them for now except one

Pull request closed

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