graphics: read depth images through integer T# with a shader-side conversion (CP2077 now can reach the main menu) #1799

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

@⁠ArtyomZabroda on GitHub · 2026-10-21 18:58 UTC · original
ArtyomZabroda:pr/depth_as_uint → main · +1696 −1112 · 14 files · 2 commits · closed without merging

Sorry about the AI generated description, most of the code was written by myself, I don't have time today to write the description myself. Feel free to ask questions about the code in comments.
This pr combined with #1765 should make cp2077 reach the main menu.

Fixes #182

Before: a shader can read a depth target through an integer T#: k16UInt over a D16 target, or k32UInt over a D32 target. The texture cache keeps the depth VkImage at that address, and Vulkan allows only a depth view on it.

For k16UInt, ValidateSampledDepthBinding exits with unsupported sampled depth image.
For k32UInt, FindView silently swaps the R32Uint view for the D32 view, while the shader still declares a uint image. This violates VUID-vkCmdDraw-format-07753.
Float reads (k16UNorm/k32Float) of a depth image ask for a color view (R16Unorm/R32Sfloat) and depend on the same silent swap in FindView.
After: an integer read of an existing depth image with the same element size selects a shader permutation. That permutation samples the depth view as float and converts the result in the shader:

k16UInt → uint(roundEven(x * 65535));
k32UInt → bitcast.
Float reads of a depth image request D16_UNORM/D32_SFLOAT explicitly. IsFormatDepthCompatible accepts only depth formats.

Relation to Cyberpunk 2077 (PPSA04029 v2.120)
Cyberpunk crashed right after the intro video, before the main menu:

unsupported sampled depth image: resource=1 encoding=1 view=0 class=1 numeric=2 dimension=3 mip_mode=0
read=1 written=0 atomic=0 compare=0 guest_format=11 swizzle=0x204 image_format=124 view_format=74
image_layers=1 descriptor_type=13 base_array=0 depth=0 descriptor_pitch=2048 target_pitch=2048
addr=0x0000001cd3e30000 size=0x0000000000800000
dwords=1cd3e300,c0b00000,01ffc1ff,d1800204,00000000,00700000,00280000,001cd463
in src/graphics/host_gpu/renderer/pipeline/descriptors.cpp:209
What the values mean:

The T# is k16UInt (guest_format=11). It is a 2048×2048 kColor2DArray (descriptor_type=13) with tile mode kDepth ((dword3 >> 20) & 0x1f = 0x18) and swizzle 0x204 = (R, 0, 0, 1).
The shader declares a uint image (numeric=2). It reads the raw 16-bit depth values of a depth buffer the game rendered earlier.
The texture cache already holds a D16_UNORM depth image (image_format=124) at that address. The renderer requested an R16_UINT view (view_format=74).
IsFormatDepthCompatible did not list R16Uint, so the view check failed (view=0) and the emulator exited.
The existing raw_d16_texture path (22bdafec, PPSA04264) recreates a D16 image as a color R16Uint copy. It did not match this binding, so the depth image stayed bound.
Adding R16Uint to IsFormatDepthCompatible only hides the error. FindView would then bind the D16 view, and the shader would read normalized floats in [0, 1] as uint bits. The pass would get wrong values (the menu then showed rendering artifacts), and the spec violation above would remain.

With this change, the permutation for that draw is specialized with DepthReadConversion::DepthAsUInt16:

the renderer binds the existing D16 image through a D16 view;
the shader samples it as float and recovers the exact 16-bit value with roundEven(x * 65535);
the swizzle (R, 0, 0, 1) is applied in the shader after the conversion, so the constant 1 stays an integer 1.
The game no longer stops at this error and reaches new-game creation. That run also had an unrelated local kernel fix needed to boot the game. A later crash during new-game creation, shader image has an invalid descriptor type or mip count for an MSAA storage image (spirvEmitterModule.cpp:223), is unrelated and not addressed here.

k32UInt over D32 is the same problem without a crash. It worked only because FindView silently swapped the view format. This PR handles it with the same mechanism.

How
IR. ShaderIR.h adds DepthReadConversion { None, DepthAsUInt16, DepthAsUInt32 } to ImageResource. ResourceMaterialization.h adds it to ResourceSpecialization::Image, so it becomes part of the permutation key.
Materialization. MaterializeResources takes HostResourceQueries. For a sampled read without depth compare, not 3D, with a k16UInt/k32UInt T#, it asks the texture cache whether a depth image with the same bytes per element starts at the T# address.
If yes, the image is declared Float, the T# swizzle moves into the shader, and paired samplers are forced to point filtering.
The decision uses the cache, not the tile mode: color render targets can also use kDepth tiling, and data that only the CPU or compute wrote lives in a color image, where a native uint read is already correct.
SPIR-V. UnpackImageTexel and UnpackImageGather convert D16 with FMul 65535 → RoundEven → ConvertFToU and D32 with OpBitcast, then apply the swizzle. The result is returned as uint.
Pipeline cache. PipelineCache receives the TextureCache and answers the query through the new TextureCache::DepthImageBytesPerBlock.
Renderer (ResolveTexture).
A conversion requests D16/D32.
A k16UNorm/k32Float read over an existing depth image of the same size also requests D16/D32. Without the cache check, a color texture with the same guest format would be recreated as depth.
The view swizzle is identity when the shader converts.
After FindImage, the renderer exits if the bound image is not a depth image of the expected size. The permutation is chosen before the draw's targets are resolved, so this catches a mismatch.
Views. IsFormatDepthCompatible accepts only D16_UNORM and D32_SFLOAT.
Not covered
FindView still replaces the view format with the image format. This is still needed for Z16 stored as D16S8, D24S8, D32S8 or D32.
Depth reads through a different-size or different format still exit: k8_8UNorm over Z16, k32SInt, k16SInt.
If the permutation is chosen before the depth image exists in the cache, the read stays uint. raw_d16_texture remains the fallback for k16UInt.
Testing
resource_materialization_tests. A new TestDepthReadConversionSpecialization covers:
k16UInt/Z16 → DepthAsUInt16 and k32UInt/Z32 → DepthAsUInt32;
no conversion when there is no depth image, the size differs, the T# is float, the read is 3D, or no host query is given;
the swizzle, point filtering, the binding kind, and a distinct permutation key.
shader_recompiler_compute_tests.
Updated cases that expected color views on depth images.
New R32 float depth-backed view.
New depth-tiled color sampled as color: a k32Float read of a color target with kDepth tiling stays color.
New color view on depth target.
Cyberpunk 2077 PPSA04029. The game passes the crash above.
Not tested: the bitcast and RoundEven values on a GPU. No dispatch test reads back converted values.

Before:
Снимок экрана 2026-10-20 192913
After:
Снимок экрана 2026-10-21 203104

**@⁠ArtyomZabroda** on GitHub · 2026-10-21 18:58 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1799) `ArtyomZabroda:pr/depth_as_uint` → `main` · +1696 −1112 · 14 files · 2 commits · closed without merging Sorry about the AI generated description, most of the code was written by myself, I don't have time today to write the description myself. Feel free to ask questions about the code in comments. This pr combined with #1765 should make cp2077 reach the main menu. Fixes #182 Before: a shader can read a depth target through an integer T#: k16UInt over a D16 target, or k32UInt over a D32 target. The texture cache keeps the depth VkImage at that address, and Vulkan allows only a depth view on it. For k16UInt, ValidateSampledDepthBinding exits with unsupported sampled depth image. For k32UInt, FindView silently swaps the R32Uint view for the D32 view, while the shader still declares a uint image. This violates VUID-vkCmdDraw-format-07753. Float reads (k16UNorm/k32Float) of a depth image ask for a color view (R16Unorm/R32Sfloat) and depend on the same silent swap in FindView. After: an integer read of an existing depth image with the same element size selects a shader permutation. That permutation samples the depth view as float and converts the result in the shader: k16UInt → uint(roundEven(x * 65535)); k32UInt → bitcast. Float reads of a depth image request D16_UNORM/D32_SFLOAT explicitly. IsFormatDepthCompatible accepts only depth formats. Relation to Cyberpunk 2077 (PPSA04029 v2.120) Cyberpunk crashed right after the intro video, before the main menu: unsupported sampled depth image: resource=1 encoding=1 view=0 class=1 numeric=2 dimension=3 mip_mode=0 read=1 written=0 atomic=0 compare=0 guest_format=11 swizzle=0x204 image_format=124 view_format=74 image_layers=1 descriptor_type=13 base_array=0 depth=0 descriptor_pitch=2048 target_pitch=2048 addr=0x0000001cd3e30000 size=0x0000000000800000 dwords=1cd3e300,c0b00000,01ffc1ff,d1800204,00000000,00700000,00280000,001cd463 in src/graphics/host_gpu/renderer/pipeline/descriptors.cpp:209 What the values mean: The T# is k16UInt (guest_format=11). It is a 2048×2048 kColor2DArray (descriptor_type=13) with tile mode kDepth ((dword3 >> 20) & 0x1f = 0x18) and swizzle 0x204 = (R, 0, 0, 1). The shader declares a uint image (numeric=2). It reads the raw 16-bit depth values of a depth buffer the game rendered earlier. The texture cache already holds a D16_UNORM depth image (image_format=124) at that address. The renderer requested an R16_UINT view (view_format=74). IsFormatDepthCompatible did not list R16Uint, so the view check failed (view=0) and the emulator exited. The existing raw_d16_texture path (22bdafec, PPSA04264) recreates a D16 image as a color R16Uint copy. It did not match this binding, so the depth image stayed bound. Adding R16Uint to IsFormatDepthCompatible only hides the error. FindView would then bind the D16 view, and the shader would read normalized floats in [0, 1] as uint bits. The pass would get wrong values (the menu then showed rendering artifacts), and the spec violation above would remain. With this change, the permutation for that draw is specialized with DepthReadConversion::DepthAsUInt16: the renderer binds the existing D16 image through a D16 view; the shader samples it as float and recovers the exact 16-bit value with roundEven(x * 65535); the swizzle (R, 0, 0, 1) is applied in the shader after the conversion, so the constant 1 stays an integer 1. The game no longer stops at this error and reaches new-game creation. That run also had an unrelated local kernel fix needed to boot the game. A later crash during new-game creation, shader image has an invalid descriptor type or mip count for an MSAA storage image (spirvEmitterModule.cpp:223), is unrelated and not addressed here. k32UInt over D32 is the same problem without a crash. It worked only because FindView silently swapped the view format. This PR handles it with the same mechanism. How IR. ShaderIR.h adds DepthReadConversion { None, DepthAsUInt16, DepthAsUInt32 } to ImageResource. ResourceMaterialization.h adds it to ResourceSpecialization::Image, so it becomes part of the permutation key. Materialization. MaterializeResources takes HostResourceQueries. For a sampled read without depth compare, not 3D, with a k16UInt/k32UInt T#, it asks the texture cache whether a depth image with the same bytes per element starts at the T# address. If yes, the image is declared Float, the T# swizzle moves into the shader, and paired samplers are forced to point filtering. The decision uses the cache, not the tile mode: color render targets can also use kDepth tiling, and data that only the CPU or compute wrote lives in a color image, where a native uint read is already correct. SPIR-V. UnpackImageTexel and UnpackImageGather convert D16 with FMul 65535 → RoundEven → ConvertFToU and D32 with OpBitcast, then apply the swizzle. The result is returned as uint. Pipeline cache. PipelineCache receives the TextureCache and answers the query through the new TextureCache::DepthImageBytesPerBlock. Renderer (ResolveTexture). A conversion requests D16/D32. A k16UNorm/k32Float read over an existing depth image of the same size also requests D16/D32. Without the cache check, a color texture with the same guest format would be recreated as depth. The view swizzle is identity when the shader converts. After FindImage, the renderer exits if the bound image is not a depth image of the expected size. The permutation is chosen before the draw's targets are resolved, so this catches a mismatch. Views. IsFormatDepthCompatible accepts only D16_UNORM and D32_SFLOAT. Not covered FindView still replaces the view format with the image format. This is still needed for Z16 stored as D16S8, D24S8, D32S8 or D32. Depth reads through a different-size or different format still exit: k8_8UNorm over Z16, k32SInt, k16SInt. If the permutation is chosen before the depth image exists in the cache, the read stays uint. raw_d16_texture remains the fallback for k16UInt. Testing resource_materialization_tests. A new TestDepthReadConversionSpecialization covers: k16UInt/Z16 → DepthAsUInt16 and k32UInt/Z32 → DepthAsUInt32; no conversion when there is no depth image, the size differs, the T# is float, the read is 3D, or no host query is given; the swizzle, point filtering, the binding kind, and a distinct permutation key. shader_recompiler_compute_tests. Updated cases that expected color views on depth images. New R32 float depth-backed view. New depth-tiled color sampled as color: a k32Float read of a color target with kDepth tiling stays color. New color view on depth target. Cyberpunk 2077 PPSA04029. The game passes the crash above. Not tested: the bitcast and RoundEven values on a GPU. No dispatch test reads back converted values. Before: <img width="1109" height="617" alt="Снимок экрана 2026-10-20 192913" src="https://github.com/user-attachments/assets/0a41a545-7c57-49cd-b43c-121f09eeea2e" /> After: <img width="1283" height="755" alt="Снимок экрана 2026-10-21 203104" src="https://github.com/user-attachments/assets/bcc0a51f-5c29-4ec0-916b-cb39415d1676" />
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 10:06:03 +00:00
github-bot closed this pull request 2026-11-26 10:06:03 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 19:07 UTC · original · edited 2026-10-21 19:37 UTC

Review in Change Stack →

📝 Walkthrough

The change adds host depth-image metadata queries to resource specialization. Eligible sampled images can use D16 or D32 depth-read conversions, with corresponding descriptor view selection and unsigned shader-result conversion. Tests cover depth format resolution, conversion selection, filtering, and rejection cases.

Priority: ⬆️ High

Estimated code review effort:

Suggested reviewers: nmzik

Change: Bug fix

Merge Risk: 🔵 Low · up to 18f7d

Shaders that mix these image types in one indirect table may fail to compile or return an incorrect value. The risk is narrow, but the emission path should be corrected before relying on it.

Pre-merge checks: Passed 4 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Docstring Coverage Inconclusive Docstring coverage is 5.47% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 128 functions across 13 files. (1 skipped:… Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: reading depth images through integer T# resources with shader-side conversion. It also identifies the practical Cyberpunk 2077 outcome.
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.
Description check Passed The pull request description directly explains the depth-image integer-read changes, shader conversion behavior, renderer integration, testing, and Cyberpunk 2077 issue addressed by the changeset.
Full details: Docstring Coverage

Explanation

Docstring coverage is 5.47% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 128 functions across 13 files. (1 skipped: 1 too large.)

Resolution

Write docstrings for the functions missing them to satisfy the coverage threshold.

  • Autofix · 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-21 19:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1799#issuecomment-6324241910) · edited 2026-10-21 19:37 UTC <!-- coderabbit-ai-generated:v1 --> <!-- 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/1799?scope=ghh_OusAJGA4HG8ljoOV0wJvVx8NmnZIjc2DdjmxOu0xZWA&amp;cs_source=review_comment"><picture><source media="(prefers-color-scheme: dark)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui-dark.svg?v=3"><source media="(prefers-color-scheme: light)" srcset="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3"><img src="https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg?v=3" alt="Review in Change Stack →" height="32"></picture></a> <!-- review_stack_entry_end --> <!-- walkthrough_start --> <details> <summary><strong>📝 Walkthrough</strong></summary> <dl> <dd> The change adds host depth-image metadata queries to resource specialization. Eligible sampled images can use D16 or D32 depth-read conversions, with corresponding descriptor view selection and unsigned shader-result conversion. Tests cover depth format resolution, conversion selection, filtering, and rejection cases. <!-- change_assessment_start --> **Priority:** ⬆️ High **Estimated code review effort:** **Suggested reviewers:** `nmzik` <!-- change_assessment_commit:"18f7dd1d6f460af38d66e77e63f1729ea53b9225" --> **Change:** Bug fix <!-- change_assessment_end --> </dd> </dl> </details> <!-- walkthrough_end --> <details> <summary><strong>Merge Risk:</strong> <strong>🔵 Low</strong> · up to <code>18f7d</code></summary> <dl> <dd> <!-- final_review_risk_start --> <!-- final_review_risk_label **Merge Risk:** **🔵 Low** · up to `18f7d` --> <!-- final_review_risk_coverage:{"sourceCommitId":"18f7dd1d6f460af38d66e77e63f1729ea53b9225","coveredCommitId":"18f7dd1d6f460af38d66e77e63f1729ea53b9225","kind":"reviewed"} --> Shaders that mix these image types in one indirect table may fail to compile or return an incorrect value. The risk is narrow, but the emission path should be corrected before relying on it. <!-- final_review_risk_end --> </dd> </dl> </details> <!-- pre_merge_checks_walkthrough_start --> <details> <summary><strong>Pre-merge checks: <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> 4 · <sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-inconclusive-14-v2.svg" width="14" height="14" align="middle" alt="Inconclusive" title="Inconclusive"></picture></sup> 1</strong></summary> <dl> <dd> <strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-failed-14-v2.svg" width="14" height="14" align="middle" alt="Failed" title="Failed"></picture></sup> Failed checks: 1 inconclusive</strong> | Check name | Status | Explanation | Resolution | | :---------------- | :--------------------------------------------------------------------------------------------------------: | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ![Inconclusive](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-inconclusive.svg) | Docstring coverage is 5.47% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 128 functions across 13 files. (1 skipped:… | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary><strong><sup><picture><img src="https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-counter-passed-14-v2.svg" width="14" height="14" align="middle" alt="Passed" title="Passed"></picture></sup> Passed checks: 4 passed</strong></summary> <dl> <dd> | Check name | Status | Explanation | | :------------------------ | :--------------------------------------------------------------------------------------------: | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The title clearly and concisely describes the main change: reading depth images through integer T# resources with shader-side conversion. It also identifies the practical Cyberpunk 2077 outcome. | | Linked Issues check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | Check skipped because no linked issues were found for this pull request. | | Description check | ![Passed](https://storage.googleapis.com/coderabbit_public_assets/pre-merge-checks-passed.svg) | The pull request description directly explains the depth-image integer-read changes, shader conversion behavior, renderer integration, testing, and Cyberpunk 2077 issue addressed by the changeset. | </dd> </dl> </details> <details> <summary><strong>Full details: Docstring Coverage</strong></summary> <dl> <dd> **Explanation** Docstring coverage is 5.47% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 128 functions across 13 files. (1 skipped: 1 too large.) **Resolution** Write docstrings for the functions missing them to satisfy the coverage threshold. </dd> </dl> </details> </dd> </dl> </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">Autofix</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=1799)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary><strong>❤️ Share</strong></summary> <dl> <dd> - [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) </dd> </dl> </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
@ -760,0 +847,4 @@
: img.numeric_class;
};
const bool mixed = std::ranges::any_of(image.indirect_resources, [&](uint32_t resource) {
return result_class(resource) != result_class(mem.resource);
Author
Owner

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

🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

set -o pipefail
printf '%s\n' '--- diff ---'
git diff --no-ext-diff --unified=80 4644c5292773095b8ee30483aaf6e017bba3c713 18f7dd1d6f460af38d66e77e63f1729ea53b9225 -- src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
printf '%s\n' '--- target context ---'
nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp | sed -n '740,980p'
printf '%s\n' '--- relevant symbols ---'
rg -n -F --glob '*.cpp' --glob '*.h' -e 'EmitIndexSwitch' -e 'result_class' -e 'native_type' -e 'depth_read_conversion' -e 'indirect_resources' src/graphics/shader/recompiler

Repository: KytyPS5/KytyPS5

Length of output: 42433


🏁 Script executed:

set -o pipefail
printf '%s\n' '--- image emitter helper and caller ---'
nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h | sed -n '520,575p'
nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp | sed -n '755,880p'
printf '%s\n' '--- materialization compatibility ---'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1935,1980p'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '2085,2130p'
printf '%s\n' '--- image resource declarations ---'
nl -ba src/graphics/shader/recompiler/ir/ShaderIR.h | sed -n '155,188p'

Repository: KytyPS5/KytyPS5

Length of output: 16155


🏁 Script executed:

nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h | sed -n '520,575p'
nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp | sed -n '833,880p'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1935,1980p'
nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '2085,2130p'
nl -ba src/graphics/shader/recompiler/ir/ShaderIR.h | sed -n '155,188p'

Repository: KytyPS5/KytyPS5

Length of output: 11607


Include native image type and depth conversion in mixed.

When an indirect table contains a plain unsigned image and a depth-converted image in different binding groups, both resources have result class Uint, but their native result types differ. EmitIndexSwitch then creates an OpPhi with Float and Uint values, which violates SPIR-V type rules. The homogeneous path can also apply the root resource's conversion to a candidate with a different conversion mode.

🐛 Suggested fix
--- "a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp"
+++ "b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp"
@@ -846,9 +846,12 @@
 		           ? Prospero::TextureNumericClass::Uint
 		           : img.numeric_class;
 	};
-	const bool mixed       = std::ranges::any_of(image.indirect_resources, [&](uint32_t resource) {
-		return result_class(resource) != result_class(mem.resource);
-	});
+	const bool mixed = std::ranges::any_of(image.indirect_resources, [&](uint32_t resource) {
+		const auto& candidate = state.program.info.images[resource];
+		return result_class(resource) != result_class(mem.resource) ||
+		       candidate.numeric_class != image.numeric_class ||
+		       candidate.depth_read_conversion != image.depth_read_conversion;
+	});
 	const auto native_type = [&](uint32_t resource) {
 		return scalar ? TypeF32(state)
 		              : ImageVectorType(state,
📝 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 bool mixed = std::ranges::any_of(image.indirect_resources, [&](uint32_t resource) {
		const auto& candidate = state.program.info.images[resource];
		return result_class(resource) != result_class(mem.resource) ||
		       candidate.numeric_class != image.numeric_class ||
		       candidate.depth_read_conversion != image.depth_read_conversion;
**@⁠coderabbitai[bot]** on GitHub · 2026-10-21 19:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1799#discussion_r4340838179) <!-- coderabbit-ai-generated:v1 --> **🩺 Stability & Availability** | **🟡 Minor** | **⚡ Quick win** <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- diff ---' git diff --no-ext-diff --unified=80 4644c5292773095b8ee30483aaf6e017bba3c713 18f7dd1d6f460af38d66e77e63f1729ea53b9225 -- src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp printf '%s\n' '--- target context ---' nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp | sed -n '740,980p' printf '%s\n' '--- relevant symbols ---' rg -n -F --glob '*.cpp' --glob '*.h' -e 'EmitIndexSwitch' -e 'result_class' -e 'native_type' -e 'depth_read_conversion' -e 'indirect_resources' src/graphics/shader/recompiler ``` Repository: KytyPS5/KytyPS5 Length of output: 42433 --- 🏁 Script executed: ```bash set -o pipefail printf '%s\n' '--- image emitter helper and caller ---' nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h | sed -n '520,575p' nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp | sed -n '755,880p' printf '%s\n' '--- materialization compatibility ---' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1935,1980p' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '2085,2130p' printf '%s\n' '--- image resource declarations ---' nl -ba src/graphics/shader/recompiler/ir/ShaderIR.h | sed -n '155,188p' ``` Repository: KytyPS5/KytyPS5 Length of output: 16155 --- 🏁 Script executed: ```bash nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterInternal.h | sed -n '520,575p' nl -ba src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp | sed -n '833,880p' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '1935,1980p' nl -ba src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | sed -n '2085,2130p' nl -ba src/graphics/shader/recompiler/ir/ShaderIR.h | sed -n '155,188p' ``` Repository: KytyPS5/KytyPS5 Length of output: 11607 --- </details> **Include native image type and depth conversion in `mixed`.** When an indirect table contains a plain unsigned image and a depth-converted image in different binding groups, both resources have result class `Uint`, but their native result types differ. `EmitIndexSwitch` then creates an `OpPhi` with `Float` and `Uint` values, which violates SPIR-V type rules. The homogeneous path can also apply the root resource's conversion to a candidate with a different conversion mode. <details> <summary>🐛 Suggested fix</summary> ```diff --- "a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp" +++ "b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp" @@ -846,9 +846,12 @@ ? Prospero::TextureNumericClass::Uint : img.numeric_class; }; - const bool mixed = std::ranges::any_of(image.indirect_resources, [&](uint32_t resource) { - return result_class(resource) != result_class(mem.resource); - }); + const bool mixed = std::ranges::any_of(image.indirect_resources, [&](uint32_t resource) { + const auto& candidate = state.program.info.images[resource]; + return result_class(resource) != result_class(mem.resource) || + candidate.numeric_class != image.numeric_class || + candidate.depth_read_conversion != image.depth_read_conversion; + }); const auto native_type = [&](uint32_t resource) { return scalar ? TypeF32(state) : ImageVectorType(state, ``` </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 bool mixed = std::ranges::any_of(image.indirect_resources, [&](uint32_t resource) { const auto& candidate = state.program.info.images[resource]; return result_class(resource) != result_class(mem.resource) || candidate.numeric_class != image.numeric_class || candidate.depth_read_conversion != image.depth_read_conversion; ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:beignet55 --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:4ae9db100321ce62abe27f79 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-21 19:07 UTC · original · reviewed

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository: KytyPS5/KytyPS5/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: cf9df07b-95a9-4876-8893-bb29115cb678
📥 Commits

Reviewing files that changed from the base of the PR and between c07ad621f2 and 18f7dd1d6f.

📒 Files selected for processing: 14
  • src/graphics/host_gpu/renderer/cache/textureCache.cpp
  • src/graphics/host_gpu/renderer/cache/textureCache.h
  • src/graphics/host_gpu/renderer/image/imageView.h
  • src/graphics/host_gpu/renderer/pipeline/descriptors.cpp
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp
  • src/graphics/host_gpu/renderer/pipeline/pipelineCache.h
  • src/graphics/host_gpu/renderer/renderContext.cpp
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • src/graphics/shader/recompiler/ir/Value.h
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.h
  • tests/ResourceMaterializationTests.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.

**@⁠coderabbitai[bot]** on GitHub · 2026-10-21 19:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1799#pullrequestreview-5604833891) · **reviewed** <!-- coderabbit-ai-generated:v1 --> **Actionable comments posted: 1** --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> - **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml - **Review profile**: CHILL - **Plan**: Advanced - **Run ID**: `cf9df07b-95a9-4876-8893-bb29115cb678` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between c07ad621f2293a729342e0c316f2b3511e9a96e8 and 18f7dd1d6f460af38d66e77e63f1729ea53b9225. </details> <details> <summary>📒 Files selected for processing: 14</summary> * `src/graphics/host_gpu/renderer/cache/textureCache.cpp` * `src/graphics/host_gpu/renderer/cache/textureCache.h` * `src/graphics/host_gpu/renderer/image/imageView.h` * `src/graphics/host_gpu/renderer/pipeline/descriptors.cpp` * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.cpp` * `src/graphics/host_gpu/renderer/pipeline/pipelineCache.h` * `src/graphics/host_gpu/renderer/renderContext.cpp` * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp` * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `src/graphics/shader/recompiler/ir/Value.h` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.h` * `tests/ResourceMaterializationTests.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> <!-- This is an auto-generated comment by CodeRabbit for review status --> <!-- coderabbit-review-publication v1 publication=27e2168e-258f-4947-8ca7-9b9a94e341db attempt=3a3116a7-64db-46b7-94cf-2c67d7fcbaaf batch=1/1 -->
Author
Owner

@⁠Nmzik on GitHub · 2026-10-22 20:13 UTC · original

@⁠ArtyomZabroda Credited Thanks!

**@⁠Nmzik** on GitHub · 2026-10-22 20:13 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1799#issuecomment-6350295817) @⁠ArtyomZabroda Credited Thanks!

Pull request closed

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