shader: treat an image format that names nothing as no descriptor instead of aborting #1019

Open
github-bot wants to merge 3 commits from github-bot/gh-1019 into main AGit
Owner

@⁠tvhdev on GitHub · 2026-10-03 20:26 UTC · original
tvhdev:fix/undefined-image-format → main · +38 −0 · 3 files · 3 commits · open

Symptom

Demon's Souls (PPSA01341 1.07) aborts at a fixed spot in the first area with

shader resource specialization failed: sampled image descriptor 20 uses unsupported format 139
--- Fatal Error ---
Error: condition (!ShaderRecompiler::IR::MaterializeResources(...)) is true in .../pipelineCache.cpp

The same line appears in #697, #63 and #316 (Demon's Souls) and in #485, #938 and #541 for other titles.

Cause

ValidImageDescriptor accepts every format value up to kBc7Srgb. Format 139 lies in a gap of the
encoding (between k4_4_4_4UNorm = 136 and kFmask8_S2_F1 = 156), so the descriptor passes the
check, SampledTextureNumericClass then returns Unsupported, and specialization fails hard.

The descriptor itself is garbage by design, not by accident: the shader indexes a texture table slot
that the guest never filled. On the console that slot is never sampled from, so the game does not care
what it holds.

Fix

  • Prospero::IsDefinedBufferFormat(format) in gpu_format.{h,cpp}: true when FindFormatInfo knows
    the format.
  • ValidImageDescriptor rejects a descriptor whose format is not defined. Both the direct and the
    indirect-table path then treat it like a null descriptor and bind the null texture, which is what the
    zeroing path already did for other invalid descriptors.
  • One rate-limited log line per shader and slot (all-zero descriptors excluded, at most 64 lines), so the
    case stays visible instead of silently becoming a null texture.

Verification

  • Demon's Souls PPSA01341 1.07: the spot that aborted on every run now passes; several hours of play
    across runs since, no recurrence of this message as a fatal.
  • resource_materialization_tests, resource_tracking_tests, shader_recompiler_compute_tests unchanged.

Two commits, 30 added lines, no behaviour change for defined formats.

**@⁠tvhdev** on GitHub · 2026-10-03 20:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1019) `tvhdev:fix/undefined-image-format` → `main` · +38 −0 · 3 files · 3 commits · open ## Symptom Demon's Souls (PPSA01341 1.07) aborts at a fixed spot in the first area with shader resource specialization failed: sampled image descriptor 20 uses unsupported format 139 --- Fatal Error --- Error: condition (!ShaderRecompiler::IR::MaterializeResources(...)) is true in .../pipelineCache.cpp The same line appears in #697, #63 and #316 (Demon's Souls) and in #485, #938 and #541 for other titles. ## Cause `ValidImageDescriptor` accepts every format value up to `kBc7Srgb`. Format 139 lies in a gap of the encoding (between `k4_4_4_4UNorm` = 136 and `kFmask8_S2_F1` = 156), so the descriptor passes the check, `SampledTextureNumericClass` then returns `Unsupported`, and specialization fails hard. The descriptor itself is garbage by design, not by accident: the shader indexes a texture table slot that the guest never filled. On the console that slot is never sampled from, so the game does not care what it holds. ## Fix - `Prospero::IsDefinedBufferFormat(format)` in `gpu_format.{h,cpp}`: true when `FindFormatInfo` knows the format. - `ValidImageDescriptor` rejects a descriptor whose format is not defined. Both the direct and the indirect-table path then treat it like a null descriptor and bind the null texture, which is what the zeroing path already did for other invalid descriptors. - One rate-limited log line per shader and slot (all-zero descriptors excluded, at most 64 lines), so the case stays visible instead of silently becoming a null texture. ## Verification - Demon's Souls PPSA01341 1.07: the spot that aborted on every run now passes; several hours of play across runs since, no recurrence of this message as a fatal. - `resource_materialization_tests`, `resource_tracking_tests`, `shader_recompiler_compute_tests` unchanged. Two commits, 30 added lines, no behaviour change for defined formats.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:40:29 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-03 20:35 UTC · original · edited 2026-10-03 22:08 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: 9703dd27-4b42-41f5-bcdf-426265fab85e
📥 Commits

Reviewing files that changed from the base of the PR and between e3f0a07ac1 and 0e73f15ca4.

📒 Files selected for processing (3)
  • src/graphics/guest_gpu/gpu_format.cpp
  • src/graphics/guest_gpu/gpu_format.h
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
🚧 Files skipped from review as they are similar to previous changes (3)
  • src/graphics/guest_gpu/gpu_format.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • src/graphics/guest_gpu/gpu_format.h

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 IsDefinedBufferFormat to check whether a buffer format has metadata. Image descriptor validation now rejects undefined formats, including encodings within the accepted numeric range. Materialization logs invalid, non-null image descriptors once per shader hash and slot, up to 64 pairs. Invalid descriptors continue to be replaced with null descriptors. All-zero unbound descriptors are not logged.

Priority: ➖ Normal

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 0e73f

This change stops an abort on image descriptors whose format is undefined by treating them as null descriptors. Defined formats behave as before. No merge-blocking risk was identified.

Security Architecture Review

Security architecture risk: 🔵 Low · up to e3f0a

The fix strengthens validation and reuses an existing null-resource fallback. Current execution paths serialize the new bounded diagnostic state, and no material security regression was identified in those paths. Safe concurrent use outside that execution model was not fully established.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — In the inspected production paths, guest-controlled descriptors affect local rendering and bounded diagnostic output. Rejected descriptor addresses are discarded rather than becoming host-resource selections; no expanded authority was identified along this traced path.

Trust Boundaries and Controls

  • observed — Validation occurs after descriptor evaluation. The existing scalar-table read path retains address masking, overflow checks, and the specialization-memory callback; the added format check does not introduce another read or relax those controls.

Resilience and Maintainability Implications

  • inferred — The reporting set lacks an internal lock, but observed production draw and compute calls execute under the shared renderer context mutex, with one active window context. This counters a reachable production race in those paths without establishing a general thread-safety guarantee for the materialization API.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. 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 describes the main change: treating descriptors with undefined image formats as absent instead of aborting.
Description check ✅ Passed The description explains the failure, its cause, the fix, and reported verification. It directly relates to the changeset.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

**@⁠coderabbitai[bot]** on GitHub · 2026-10-03 20:35 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1019#issuecomment-5973245770) · edited 2026-10-03 22:08 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/1019?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**: `9703dd27-4b42-41f5-bcdf-426265fab85e` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between e3f0a07ac1ce491058e70f49ce376f422203fcfb and 0e73f15ca4c29805884f410504b8cc9d70550fa2. </details> <details> <summary>📒 Files selected for processing (3)</summary> * `src/graphics/guest_gpu/gpu_format.cpp` * `src/graphics/guest_gpu/gpu_format.h` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` </details> <details> <summary>🚧 Files skipped from review as they are similar to previous changes (3)</summary> * src/graphics/guest_gpu/gpu_format.cpp * src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp * src/graphics/guest_gpu/gpu_format.h </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 `IsDefinedBufferFormat` to check whether a buffer format has metadata. Image descriptor validation now rejects undefined formats, including encodings within the accepted numeric range. Materialization logs invalid, non-null image descriptors once per shader hash and slot, up to 64 pairs. Invalid descriptors continue to be replaced with null descriptors. All-zero unbound descriptors are not logged. </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"0e73f15ca4c29805884f410504b8cc9d70550fa2" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _⚪ Minimal_ · up to `0e73f` <!-- final_review_risk_coverage:{"sourceCommitId":"0e73f15ca4c29805884f410504b8cc9d70550fa2","coveredCommitId":"0e73f15ca4c29805884f410504b8cc9d70550fa2","kind":"reviewed"} --> This change stops an abort on image descriptors whose format is undefined by treating them as null descriptors. Defined formats behave as before. No merge-blocking risk was identified. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `e3f0a` The fix strengthens validation and reuses an existing null-resource fallback. Current execution paths serialize the new bounded diagnostic state, and no material security regression was identified in those paths. Safe concurrent use outside that execution model was not fully established. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — In the inspected production paths, guest-controlled descriptors affect local rendering and bounded diagnostic output. Rejected descriptor addresses are discarded rather than becoming host-resource selections; no expanded authority was identified along this traced path. **Trust Boundaries and Controls** - _observed_ — Validation occurs after descriptor evaluation. The existing scalar-table read path retains address masking, overflow checks, and the specialization-memory callback; the added format check does not introduce another read or relax those controls. **Resilience and Maintainability Implications** - _inferred_ — The reporting set lacks an internal lock, but observed production draw and compute calls execute under the shared renderer context mutex, with one active window context. This counters a reachable production race in those paths without establishing a general thread-safety guarantee for the materialization API. </details> <!-- architecture_review_end --> <!-- pre_merge_checks_walkthrough_start --> <details> <summary>🚥 Pre-merge checks | ✅ 4 | ❌ 1</summary> ### ❌ Failed checks (1 warning) | Check name | Status | Explanation | Resolution | | :----------------: | :--------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------- | | Docstring Coverage | ⚠️ Warning | Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 8 functions across 3 files. | 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 describes the main change: treating descriptors with undefined image formats as absent instead of aborting. | | Description check | ✅ Passed | The description explains the failure, its cause, the fix, and reported verification. It directly relates to the changeset. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> </details> <!-- pre_merge_checks_walkthrough_end --> <!-- autopilot:start --> - [ ] <!-- {"checkboxId":"2708ad07-9f24-4260-9c11-7dc76a49f2e3"} --> <strong title="Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts">Autopilot</strong> · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts <!-- autopilot:end --> <!-- tips_start --> --- Thanks for using [CodeRabbit](https://coderabbit.ai?utm_source=oss&utm_medium=github&utm_campaign=KytyPS5/KytyPS5&utm_content=1019)! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. <details> <summary>❤️ Share</summary> - [X](https://twitter.com/intent/tweet?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A&url=https%3A//coderabbit.ai) - [Mastodon](https://mastodon.social/share?text=I%20just%20used%20%40coderabbitai%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20the%20proprietary%20code.%20Check%20it%20out%3A%20https%3A%2F%2Fcoderabbit.ai) - [Reddit](https://www.reddit.com/submit?title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&text=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code.%20Check%20it%20out%3A%20https%3A//coderabbit.ai) - [LinkedIn](https://www.linkedin.com/sharing/share-offsite/?url=https%3A%2F%2Fcoderabbit.ai&mini=true&title=Great%20tool%20for%20code%20review%20-%20CodeRabbit&summary=I%20just%20used%20CodeRabbit%20for%20my%20code%20review%2C%20and%20it%27s%20fantastic%21%20It%27s%20free%20for%20OSS%20and%20offers%20a%20free%20trial%20for%20proprietary%20code) </details> <sub>Comment `@coderabbitai help` to get the list of available commands.</sub> <!-- tips_end -->
Author
Owner

@⁠AdelRdp2024 on GitHub · 2026-10-10 13:53 UTC · original

I’m testing Demon’s Souls Remake (PPSA01341) on a recent KytyPS5 build. The game reaches the main menu, but the emulator crashes after selecting New Game and Offline with this error:

failed to create image: extent=4096x4096x1 format=43 layers=5 levels=1

The error points to src/graphics/host_gpu/renderer/image/image.cpp:727.

Could this be related to the image-format issue addressed by this PR, or is it a separate problem? Thanks!

**@⁠AdelRdp2024** on GitHub · 2026-10-10 13:53 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1019#issuecomment-6098197445) I’m testing Demon’s Souls Remake (PPSA01341) on a recent KytyPS5 build. The game reaches the main menu, but the emulator crashes after selecting New Game and Offline with this error: `failed to create image: extent=4096x4096x1 format=43 layers=5 levels=1` The error points to `src/graphics/host_gpu/renderer/image/image.cpp:727`. Could this be related to the image-format issue addressed by this PR, or is it a separate problem? Thanks!
Author
Owner

@⁠tvhdev on GitHub · 2026-10-11 19:55 UTC · original

@⁠AdelRdp2024 i had this error too with two different images, the reason was that the graphics card's VRAM was exhausted. you could start the emulator with --printf-direction File --printf-output-file kyty_log.txt to see if there's a VMA heap info right before the crash.

**@⁠tvhdev** on GitHub · 2026-10-11 19:55 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1019#issuecomment-6113086513) @⁠AdelRdp2024 i had this error too with two different images, the reason was that the graphics card's VRAM was exhausted. you could start the emulator with --printf-direction File --printf-output-file kyty_log.txt to see if there's a VMA heap info right before the crash.
Author
Owner

@⁠AdelRdp2024 on GitHub · 2026-10-11 22:43 UTC · original

@⁠tvhdev Thanks, that was it. The log shows VMA heap 0: usage=4133105664, budget=3213950157, so VRAM is exhausted (GTX 980, 4GB). Not related to the PR then. Thanks for the tip!

**@⁠AdelRdp2024** on GitHub · 2026-10-11 22:43 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/1019#issuecomment-6114724376) @⁠tvhdev Thanks, that was it. The log shows VMA heap 0: usage=4133105664, budget=3213950157, so VRAM is exhausted (GTX 980, 4GB). Not related to the PR then. Thanks for the tip!
This pull request has changes conflicting with the target branch.
  • src/graphics/guest_gpu/gpu_format.cpp
  • src/graphics/guest_gpu/gpu_format.h
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

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

Merge

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