shader: emulate the sRGB decode of narrow sRGB sampled formats #706

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

@⁠YuhiAida on GitHub · 2026-09-18 20:27 UTC · original
YuhiAida:agents/update-main-check-pacman-cutscenes → main · +365 −15 · 6 files · 8 commits · closed without merging

Summary

The guest can sample 8-bit sRGB textures (k8Srgb / k8_8Srgb), but Vulkan only
guarantees sRGB sampling for RGBA8, so those formats are stored as the linear format of the
same width (R8_UNORM / R8G8_UNORM) and the sRGB decode the guest texture pipe expects is
emulated by the shader.

Related to #524 — the magenta/pink wash in the PAC-MAN WORLD 2 Re-PAC cutscenes. The
cutscene video planes are bound as narrow sRGB textures, so their BT.601-decoded samples were
returned linear and then re-encoded, saturating red and blue.

What changed

  • ShaderIR.h / ResourceMaterialization.{h,cpp}: new srgb_sample_decode specialization
    field, set when the image descriptor format is k8Srgb or k8_8Srgb (never for storage
    images). The field takes part in the specialization identity, so it is also part of the
    permutation/pipeline key.
  • spirvEmitterImage.cpp: when the sampled image requests it, the sampled value is decoded
    in the shader — x <= 0.04045 ? x / 12.92 : pow((x + 0.055) / 1.055, 2.4) per channel, via
    GLSLstd450FMax / GLSLstd450Pow (spv::OpFMax does not exist in the bundled
    SPIRV-Headers).

The wider formats k8_8_8_8Srgb and Bc*Srgb already map to real sRGB host formats, so the
hardware decodes them and no shader decode is emitted for them.

Why shader-side instead of an sRGB image view

Creating a linear/sRGB image view pair over the same image and binding the sRGB view for
sampled reads was implemented and measured first; it cannot work on this device because
VK_FORMAT_R8G8_SRGB reports optimal=0x0 linear=0x0 buffer=0x0, and VK_FORMAT_R8_SRGB
has the same restriction. The shared-decoder shader path is device-independent, so the change
was moved there (the descriptor-side experiment was reverted).

Evidence

Same run, same cutscene frame, before/after (frame mean RGB over the cutscene region):

before after
cutscene frame mean (199.7, 44.4, 242.2) (52, 54, 99)
constant 128/128 plane probe magenta flat neutral (130, 130, 130)

Gameplay is unchanged (it never samples these formats) and the run still presents at 60 fps.

Known approximation: the decode is applied after filtering, while hardware sRGB decoding
happens before it. This is exact for the ~1:1 luma plane and a small approximation for the
2x-upsampled chroma plane; it is unavoidable while sampling R8_UNORM/R8G8_UNORM.

Screenshot_20260905_000102 Screenshot_20260918_220858

Tests

  • tests/ResourceMaterializationTests.cpp: new TestNarrowSrgbDescriptorRequestsShaderDecode
    — k8Srgb and k8_8Srgb descriptors request the shader decode, k8UNorm does not.
  • resource_materialization_tests and resource_tracking_tests pass on the container
    toolchain; the emulator builds and runs with the change.

#167 ("Decode sRGB in the shader for formats the host image cannot carry") and #415
("shader: decode narrow sRGB textures when sampling", closed unmerged) target the same bug.
This PR is the minimal form of the same fix; if it is accepted, #167 can be superseded.

Draft for now: the mixed-narrow-sRGB indirect image table case makes the new field a
candidate-compatibility check, and that path has not been exercised on hardware yet.

**@⁠YuhiAida** on GitHub · 2026-09-18 20:27 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/706) `YuhiAida:agents/update-main-check-pacman-cutscenes` → `main` · +365 −15 · 6 files · 8 commits · closed without merging ## Summary The guest can sample 8-bit sRGB textures (`k8Srgb` / `k8_8Srgb`), but Vulkan only guarantees sRGB sampling for RGBA8, so those formats are stored as the linear format of the same width (`R8_UNORM` / `R8G8_UNORM`) and the sRGB decode the guest texture pipe expects is emulated by the shader. **Related to #524** — the magenta/pink wash in the PAC-MAN WORLD 2 Re-PAC cutscenes. The cutscene video planes are bound as narrow sRGB textures, so their BT.601-decoded samples were returned linear and then re-encoded, saturating red and blue. ## What changed - `ShaderIR.h` / `ResourceMaterialization.{h,cpp}`: new `srgb_sample_decode` specialization field, set when the image descriptor format is `k8Srgb` or `k8_8Srgb` (never for storage images). The field takes part in the specialization identity, so it is also part of the permutation/pipeline key. - `spirvEmitterImage.cpp`: when the sampled image requests it, the sampled value is decoded in the shader — `x <= 0.04045 ? x / 12.92 : pow((x + 0.055) / 1.055, 2.4)` per channel, via `GLSLstd450FMax` / `GLSLstd450Pow` (`spv::OpFMax` does not exist in the bundled SPIRV-Headers). The wider formats `k8_8_8_8Srgb` and `Bc*Srgb` already map to real sRGB host formats, so the hardware decodes them and no shader decode is emitted for them. ## Why shader-side instead of an sRGB image view Creating a linear/sRGB image view pair over the same image and binding the sRGB view for sampled reads was implemented and measured first; it cannot work on this device because `VK_FORMAT_R8G8_SRGB` reports `optimal=0x0 linear=0x0 buffer=0x0`, and `VK_FORMAT_R8_SRGB` has the same restriction. The shared-decoder shader path is device-independent, so the change was moved there (the descriptor-side experiment was reverted). ## Evidence Same run, same cutscene frame, before/after (frame mean RGB over the cutscene region): | | before | after | |---|---|---| | cutscene frame mean | `(199.7, 44.4, 242.2)` | `(52, 54, 99)` | | constant 128/128 plane probe | magenta | flat neutral `(130, 130, 130)` | Gameplay is unchanged (it never samples these formats) and the run still presents at 60 fps. Known approximation: the decode is applied after filtering, while hardware sRGB decoding happens before it. This is exact for the ~1:1 luma plane and a small approximation for the 2x-upsampled chroma plane; it is unavoidable while sampling `R8_UNORM`/`R8G8_UNORM`. <img width="1282" height="746" alt="Screenshot_20260905_000102" src="https://github.com/user-attachments/assets/948a7f6d-ad7b-4979-b4a1-6585c0183816" /> <img width="1272" height="753" alt="Screenshot_20260918_220858" src="https://github.com/user-attachments/assets/8f242c31-8b7d-4bae-a7f8-8aa09a071d35" /> ## Tests - `tests/ResourceMaterializationTests.cpp`: new `TestNarrowSrgbDescriptorRequestsShaderDecode` — `k8Srgb` and `k8_8Srgb` descriptors request the shader decode, `k8UNorm` does not. - `resource_materialization_tests` and `resource_tracking_tests` pass on the container toolchain; the emulator builds and runs with the change. ## Related work #167 ("Decode sRGB in the shader for formats the host image cannot carry") and #415 ("shader: decode narrow sRGB textures when sampling", closed unmerged) target the same bug. This PR is the minimal form of the same fix; if it is accepted, #167 can be superseded. Draft for now: the mixed-narrow-sRGB indirect image table case makes the new field a candidate-compatibility check, and that path has not been exercised on hardware yet.
Vulkan only guarantees sRGB sampling for RGBA8, so the 8-bit sRGB guest
formats (k8Srgb, k8_8Srgb) are stored in the linear format of the same width
and the sRGB -> linear decode the guest texture pipe performs for their
samples was lost.

The video planes of PAC-MAN WORLD 2 (PPSA18189) are bound that way, and its
video shader assumes linear samples (it encodes, applies the BT.601 matrix
and decodes again), so cutscenes rendered with a magenta wash while gameplay
stayed correct. Sampled values are now decoded in the shader whenever the
image's guest format is one of those, which keeps the result independent of
the device's sRGB sampling support.
Keep the narrow sRGB shader decode alongside main's reworked resource
materialization: srgb_sample_decode is now carried through the copied
image entries, the descriptor specialization, the indirect image table
validation and ApplyResourceSpecialization.

Conflict resolution:
- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp:
  took main's structure (MaterializedSnapshot, MaterializeIndirectImage,
  ReadScalarTable) and re-applied the sRGB decode hooks on it.
- tests/ShaderRecompilerComputeTests.cpp: kept both the
  --narrow-srgb-only and the --s-memrealtime-only selectors.
Main replaced the RequiresPointSampler overloads with ClassifySampler, so
the sRGB decode helper was kept next to the new sampler classification.

Conflict resolution:
- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp:
  kept NeedsSrgbSampleDecode, dropped the RequiresPointSampler block and
  took main's SamplerClass enum and ClassifySampler.
# Conflicts:
#	src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
#	tests/ResourceMaterializationTests.cpp
#	tests/ShaderRecompilerComputeTests.cpp
An indirect image table may mix narrow sRGB (k8Srgb/k8_8Srgb) and linear (k8UNorm) candidates. Both sample as floats with no conversion format, so they only differ in the shader-side sRGB decode, but the table-wide srgb_sample_decode comparison added with that decode rejected the mix and made MaterializeResources fail for the table.

Drop the comparison and decode each candidate in its own OpSwitch arm before the OpPhi merge. When every candidate shares the root's flag the merged result is decoded once instead, so a uniform table keeps a single decode sequence. Covered by a mixed-table materialization case and candidate-specific SPIR-V emitter cases.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 09:30:19 +00:00
github-bot closed this pull request 2026-11-26 09:30:19 +00:00
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-18 20:39 UTC · original · edited 2026-10-04 11:22 UTC

Review in Change Stack →

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

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

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: 2cefcc50-98ca-4b8a-8c54-8b4f22c649e9
📥 Commits

Reviewing files that changed from the base of the PR and between 0e8f2465de and cf3715e661.

📒 Files selected for processing (4)
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • 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; 6 remain after this review.


📝 Walkthrough

Walkthrough

Image materialization tracks whether sampled narrow sRGB images need shader-side decoding. It sets the flag for supported 8-bit sRGB formats on non-storage images and propagates it through specialization. The SPIR-V emitter decodes eligible sampled results, excluding integer samples and depth-reference results. For indirect images, it decodes mixed candidates in their switch arms and uniformly flagged candidates after the merge. Tests cover single-channel and two-channel sRGB images, linear-format preservation, and materialization behavior.

Suggested reviewers: nmzik

Priority: ➖ Normal

Change: Bug fix

Merge Risk: 🔵 Low · up to cf371

Mixed-format indirect tables no longer show the reported failure. Narrow-sRGB image loads can still return decoded rather than encoded values; this bounded issue needs owner awareness or a follow-up.

Security Architecture Review

Security architecture risk: 🔵 Low · up to cf371

The change affects texture color interpretation without demonstrated expansion of access or privileges. Risk is low rather than minimal because concurrent-use guarantees and runtime validation remain incomplete.

Retained concerns
No architecture-level concerns identified.

Security review details

Security Blast Radius

  • inferred — Guest descriptor formats can influence decode behavior and shader permutation selection. The inspected impact is confined to those shader results and existing bound resources; no additional resource set or privilege was identified.

Trust Boundaries and Controls

  • observed — The added decoder operates on values returned by the existing image-sampling path. It does not change descriptor loads, indirect mapping addresses, resource identifiers, or sampler selection; the base-to-head emitter comparison preserves those access paths.

Resilience and Maintainability Implications

  • observed — Materialization refreshes outputs in place, with an explicit contract forbidding use after failure. The inspected production caller terminates before permutation lookup or compilation when refresh fails. This containment behavior predates the PR; transactional recovery and concurrent publication guarantees were not established.
🚥 Pre-merge checks | ✅ 4 | ❓ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ❓ Inconclusive Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 5 files. (1 skipped: … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: shader-side sRGB decoding for narrow sampled formats.
Description check ✅ Passed The description explains the narrow sRGB sampling issue, the shader decode implementation, its known approximation, and the tests added.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 5 files. (1 skipped: 1 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-18 20:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/706#issuecomment-5735907359) · edited 2026-10-04 11:22 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/706?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 --> <!-- This is an auto-generated comment: review paused by coderabbit.ai --> > [!NOTE] > ## Reviews paused > > It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the `reviews.auto_review.auto_pause_after_reviewed_commits` setting. > > Use the following commands to manage reviews: > - `@coderabbitai resume` to resume automatic reviews. > - `@coderabbitai review` to trigger a single review. > > Use the checkboxes below for quick actions: > - [ ] <!-- {"checkboxId":"7f6cc2e2-2e4e-497a-8c31-c9e4573e93d1"} --> ▶️ Resume reviews > - [ ] <!-- {"checkboxId":"e9bb8d72-00e8-4f67-9cb2-caf3b22574fe"} --> 🔍 Trigger review <!-- end of auto-generated comment: review paused by coderabbit.ai --> <!-- 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**: `2cefcc50-98ca-4b8a-8c54-8b4f22c649e9` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 0e8f2465de1a535ff967a20ba5537d312b6b7f49 and cf3715e66161715b8ac2e281e55677a883beb2ed. </details> <details> <summary>📒 Files selected for processing (4)</summary> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `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; 6 remain after this review. </details> --- <!-- recent_review_end --> <!-- walkthrough_start --> <details> <summary>📝 Walkthrough</summary> ## Walkthrough Image materialization tracks whether sampled narrow sRGB images need shader-side decoding. It sets the flag for supported 8-bit sRGB formats on non-storage images and propagates it through specialization. The SPIR-V emitter decodes eligible sampled results, excluding integer samples and depth-reference results. For indirect images, it decodes mixed candidates in their switch arms and uniformly flagged candidates after the merge. Tests cover single-channel and two-channel sRGB images, linear-format preservation, and materialization behavior. **Suggested reviewers:** `nmzik` </details> <!-- walkthrough_end --> <!-- change_assessment_start --> **Priority:** ➖ Normal <!-- change_assessment_commit:"cf3715e66161715b8ac2e281e55677a883beb2ed" --> **Change:** Bug fix <!-- change_assessment_end --> <!-- final_review_risk_start --> **Merge Risk:** _🔵 Low_ · up to `cf371` <!-- final_review_risk_coverage:{"sourceCommitId":"cf3715e66161715b8ac2e281e55677a883beb2ed","coveredCommitId":"cf3715e66161715b8ac2e281e55677a883beb2ed","kind":"reviewed"} --> Mixed-format indirect tables no longer show the reported failure. Narrow-sRGB image loads can still return decoded rather than encoded values; this bounded issue needs owner awareness or a follow-up. <!-- final_review_risk_end --> <!-- architecture_review_start --> ### Security Architecture Review **Security architecture risk:** _🔵 Low_ · up to `cf371` The change affects texture color interpretation without demonstrated expansion of access or privileges. Risk is low rather than minimal because concurrent-use guarantees and runtime validation remain incomplete. **Retained concerns** No architecture-level concerns identified. <details> <summary>Security review details</summary> **Security Blast Radius** - _inferred_ — Guest descriptor formats can influence decode behavior and shader permutation selection. The inspected impact is confined to those shader results and existing bound resources; no additional resource set or privilege was identified. **Trust Boundaries and Controls** - _observed_ — The added decoder operates on values returned by the existing image-sampling path. It does not change descriptor loads, indirect mapping addresses, resource identifiers, or sampler selection; the base-to-head emitter comparison preserves those access paths. **Resilience and Maintainability Implications** - _observed_ — Materialization refreshes outputs in place, with an explicit contract forbidding use after failure. The inspected production caller terminates before permutation lookup or compilation when refresh fails. This containment behavior predates the PR; transactional recovery and concurrent publication guarantees were not established. </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 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 5 files. (1 skipped: … | Write docstrings for the functions missing them to satisfy the coverage threshold. | <details> <summary>✅ Passed checks (4 passed)</summary> | Check name | Status | Explanation | | :------------------------: | :------- | :--------------------------------------------------------------------------------------------------------------------------------------- | | Title check | ✅ Passed | The title clearly and concisely describes the main change: shader-side sRGB decoding for narrow sampled formats. | | Description check | ✅ Passed | The description explains the narrow sRGB sampling issue, the shader decode implementation, its known approximation, and the tests added. | | Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | | Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. | </details> <details> <summary>Full details: Docstring Coverage</summary> **Explanation** Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 21 functions across 5 files. (1 skipped: 1 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=706)! 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 -->
@ -228,3 +268,4 @@
}
if (mem.data_bits == 16u) {
uint32_t packed[4] = {ConstantU32(ctx.state, 0), ConstantU32(ctx.state, 0),
ConstantU32(ctx.state, 0), ConstantU32(ctx.state, 0)};
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-18 20:39 UTC · original · edited 2026-09-18 21:20 UTC

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🔎 Supported by static analysis

🏁 Script executed:

sed -n '130,215p' tests/ResourceMaterializationTests.cpp
rg -n 'ResultVector|SrgbDecoded|srgb_sample_decode|SPIR-V|Spirv|ImageSample|SampledImage' tests src/graphics/shader/recompiler/backend/spirv
rg -n 'spirvEmitterImage|SpirvEmitter|ShaderRecompiler' tests CMakeLists.txt

Repository: KytyPS5/KytyPS5

Length of output: 50372


🏁 Script executed:

#!/bin/bash
set -o pipefail
printf '%s\n' '--- sRGB references ---'
rg -n -C 4 'srgb_sample_decode|SrgbDecoded|ResultVector' tests src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
printf '%s\n' '--- focused image tests ---'
sed -n '25140,25330p' tests/ShaderRecompilerComputeTests.cpp
sed -n '25570,25705p' tests/ShaderRecompilerComputeTests.cpp
sed -n '25950,26045p' tests/ShaderRecompilerComputeTests.cpp
printf '%s\n' '--- registrations and resource-materialization test registration ---'
rg -n -C 3 'TestNarrowSrgbDescriptorRequestsShaderDecode|ImageSamplePackedUintConvertsSampleAndGather|ImageSampleAndGather|ImageLoadR32UintUsesIntegerSampledImage|ResourceMaterialization' tests CMakeLists.txt
printf '%s\n' '--- relevant diff summary ---'
git diff --stat -- src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp tests/ShaderRecompilerComputeTests.cpp tests/ResourceMaterializationTests.cpp
git diff --unified=12 -- src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp tests/ShaderRecompilerComputeTests.cpp tests/ResourceMaterializationTests.cpp

Repository: KytyPS5/KytyPS5

Length of output: 36841


Add SPIR-V coverage for ResultVector sRGB decoding. TestNarrowSrgbDescriptorRequestsShaderDecode only checks descriptor specialization. The reachable ResultVector branch applies SrgbDecodedVector, but no current SPIR-V test enables srgb_sample_decode or checks the emitted transfer instructions. Add a focused emitter test for enabled floating-point color sampling, plus disabled, integer, and depth-reference cases that must not emit the transfer sequence.

✅ Addressed in commit b1392f6

**@⁠coderabbitai[bot]** on GitHub · 2026-09-18 20:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/706#discussion_r4050523825) · edited 2026-09-18 21:20 UTC _🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '130,215p' tests/ResourceMaterializationTests.cpp rg -n 'ResultVector|SrgbDecoded|srgb_sample_decode|SPIR-V|Spirv|ImageSample|SampledImage' tests src/graphics/shader/recompiler/backend/spirv rg -n 'spirvEmitterImage|SpirvEmitter|ShaderRecompiler' tests CMakeLists.txt ``` Repository: KytyPS5/KytyPS5 Length of output: 50372 --- 🏁 Script executed: ```bash #!/bin/bash set -o pipefail printf '%s\n' '--- sRGB references ---' rg -n -C 4 'srgb_sample_decode|SrgbDecoded|ResultVector' tests src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp printf '%s\n' '--- focused image tests ---' sed -n '25140,25330p' tests/ShaderRecompilerComputeTests.cpp sed -n '25570,25705p' tests/ShaderRecompilerComputeTests.cpp sed -n '25950,26045p' tests/ShaderRecompilerComputeTests.cpp printf '%s\n' '--- registrations and resource-materialization test registration ---' rg -n -C 3 'TestNarrowSrgbDescriptorRequestsShaderDecode|ImageSamplePackedUintConvertsSampleAndGather|ImageSampleAndGather|ImageLoadR32UintUsesIntegerSampledImage|ResourceMaterialization' tests CMakeLists.txt printf '%s\n' '--- relevant diff summary ---' git diff --stat -- src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp tests/ShaderRecompilerComputeTests.cpp tests/ResourceMaterializationTests.cpp git diff --unified=12 -- src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp tests/ShaderRecompilerComputeTests.cpp tests/ResourceMaterializationTests.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 36841 --- </details> **Add SPIR-V coverage for `ResultVector` sRGB decoding.** `TestNarrowSrgbDescriptorRequestsShaderDecode` only checks descriptor specialization. The reachable `ResultVector` branch applies `SrgbDecodedVector`, but no current SPIR-V test enables `srgb_sample_decode` or checks the emitted transfer instructions. Add a focused emitter test for enabled floating-point color sampling, plus disabled, integer, and depth-reference cases that must not emit the transfer sequence. <!-- fingerprinting:phantom:medusa:tapir --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:d06e96652e798fe88aeda33e --> <!-- This is an auto-generated reply by CodeRabbit --> ✅ Addressed in commit b1392f6
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-18 20:39 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: 54f06b4e-6bda-4443-97bb-e6eac230a9f2

📥 Commits

Reviewing files that changed from the base of the PR and between 5b7d3343cf and 5f4bafecd4.

📒 Files selected for processing (5)
  • 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
  • tests/ResourceMaterializationTests.cpp

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

**@⁠coderabbitai[bot]** on GitHub · 2026-09-18 20:39 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/706#pullrequestreview-5252403965) · **reviewed** **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**: `54f06b4e-6bda-4443-97bb-e6eac230a9f2` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 5b7d3343cf1586e42068f0ce455ab0675ec43ada and 5f4bafecd44083e29b8ecfcace4f9995354ae56c. </details> <details> <summary>📒 Files selected for processing (5)</summary> * `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` * `tests/ResourceMaterializationTests.cpp` </details> **Included review availability:** 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 -->
@ -228,3 +268,4 @@
}
if (mem.data_bits == 16u) {
uint32_t packed[4] = {ConstantU32(ctx.state, 0), ConstantU32(ctx.state, 0),
ConstantU32(ctx.state, 0), ConstantU32(ctx.state, 0)};
Author
Owner

@⁠YuhiAida on GitHub · 2026-09-18 21:07 UTC · original

Addressed in b1392f6 (tests: cover the shader sRGB decode in the SPIR-V emitter), which extends tests/ShaderRecompilerComputeTests.cpp with three focused image-load cases plus a negative marker on the existing integer case:

  • ImageLoadDecodesNarrowSrgbTexel - float enabled, k8Srgb (eR8Unorm), low-branch texel 0x0a; asserts the exact decoded value 0x3b46eb61 and requires the transfer sequence (FMax, OpFOrdLessThanEqual %bool, Pow) in the disassembly.
  • ImageLoadDecodesNarrowSrgbChromaPair - float enabled, k8_8Srgb (eR8G8Unorm), dmask 0x3, two texels; asserts {0x3a9f22b4, 0x3b1f22b4} (bytes 4 and 8) and requires the same markers.
  • ImageLoadKeepsLinearTexelsLinear - float disabled, k8UNorm; asserts the pass-through value 0x3e808081 for texel 0x40 and forbids FMax/Pow.
  • ImageLoadR32UintUsesIntegerSampledImage - integer path; now also forbids FMax/Pow so a future change cannot start emitting the transfer sequence for integer sampled images.

All three new cases are registered with AddCase and can be run in isolation with a new --narrow-srgb-only flag; the full suite also passes (ShaderRecompilerComputeTests: all cases passed).

One honest caveat on guard coverage: srgb_sample_decode is only set for descriptor formats k8Srgb/k8_8Srgb, and those materialize as float sampled images, so the !integer and !dref conditions in the emitter guard are defensive rather than reachable today - no descriptor that sets the flag can also be an integer numeric class or a depth-compare sample. That is why there is no positive integer/dref decode case: such a case cannot be constructed against the current materializer (only the negative integer case above). I have kept the guards and covered them from the negative side; if you would prefer, I can instead add a checks-only test asserting the materializer never produces srgb_sample_decode together with a non-float numeric class or depth_compare.

**@⁠YuhiAida** on GitHub · 2026-09-18 21:07 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/706#discussion_r4050696440) Addressed in b1392f6 (`tests: cover the shader sRGB decode in the SPIR-V emitter`), which extends `tests/ShaderRecompilerComputeTests.cpp` with three focused image-load cases plus a negative marker on the existing integer case: - `ImageLoadDecodesNarrowSrgbTexel` - float enabled, `k8Srgb` (`eR8Unorm`), low-branch texel `0x0a`; asserts the exact decoded value `0x3b46eb61` and requires the transfer sequence (`FMax`, `OpFOrdLessThanEqual %bool`, `Pow`) in the disassembly. - `ImageLoadDecodesNarrowSrgbChromaPair` - float enabled, `k8_8Srgb` (`eR8G8Unorm`), dmask `0x3`, two texels; asserts `{0x3a9f22b4, 0x3b1f22b4}` (bytes 4 and 8) and requires the same markers. - `ImageLoadKeepsLinearTexelsLinear` - float disabled, `k8UNorm`; asserts the pass-through value `0x3e808081` for texel `0x40` and forbids `FMax`/`Pow`. - `ImageLoadR32UintUsesIntegerSampledImage` - integer path; now also forbids `FMax`/`Pow` so a future change cannot start emitting the transfer sequence for integer sampled images. All three new cases are registered with `AddCase` and can be run in isolation with a new `--narrow-srgb-only` flag; the full suite also passes (`ShaderRecompilerComputeTests: all cases passed`). One honest caveat on guard coverage: `srgb_sample_decode` is only set for descriptor formats `k8Srgb`/`k8_8Srgb`, and those materialize as float sampled images, so the `!integer` and `!dref` conditions in the emitter guard are defensive rather than reachable today - no descriptor that sets the flag can also be an integer numeric class or a depth-compare sample. That is why there is no positive integer/dref decode case: such a case cannot be constructed against the current materializer (only the negative integer case above). I have kept the guards and covered them from the negative side; if you would prefer, I can instead add a checks-only test asserting the materializer never produces `srgb_sample_decode` together with a non-float numeric class or `depth_compare`.
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-09-18 21:16 UTC · original · reviewed

Caution

Some comments are outside the diff and can’t be posted inline due to GitHub limitations.

⚠️ Outside diff range comments (1)

🟡 Minor · Exclude IMAGE_LOAD results from shader-side sRGB decoding. · spirvEmitterImage.cpp:216-226

src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp:216-226
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Exclude IMAGE_LOAD results from shader-side sRGB decoding.

IMAGE_LOAD translates to ImageRead, which emits OpImageFetch and then calls ResultVector. For reachable k8Srgb and k8_8Srgb images, ResultVector applies SrgbDecodedVector to this fetch result. A non-endpoint encoded component, such as approximately 0.5, therefore becomes approximately 0.214 instead of remaining encoded. Restrict the decode to ordinary sampling results, while preserving it for ordinary sampling operations.


ℹ️ Review info
⚙️ Run configuration

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

Review profile: CHILL

Plan: Advanced

Run ID: 6c1c0b9e-02ae-4f58-b86e-c56df1e29156

📥 Commits

Reviewing files that changed from the base of the PR and between 5f4bafecd4 and b1392f6a96.

📒 Files selected for processing (1)
  • tests/ShaderRecompilerComputeTests.cpp

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-18 21:16 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/706#pullrequestreview-5252687248) · **reviewed** > [!CAUTION] > Some comments are outside the diff and can’t be posted inline due to GitHub limitations. > > **⚠️ Outside diff range comments (1)** > > <details> > <summary><em>🟡 Minor</em> · Exclude <code>IMAGE_LOAD</code> results from shader-side sRGB decoding. · <code>spirvEmitterImage.cpp:216-226</code></summary><blockquote> > > `src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp:216-226` > _🎯 Functional Correctness_ | _🟡 Minor_ | _⚡ Quick win_ > > **Exclude `IMAGE_LOAD` results from shader-side sRGB decoding.** > > `IMAGE_LOAD` translates to `ImageRead`, which emits `OpImageFetch` and then calls `ResultVector`. For reachable `k8Srgb` and `k8_8Srgb` images, `ResultVector` applies `SrgbDecodedVector` to this fetch result. A non-endpoint encoded component, such as approximately `0.5`, therefore becomes approximately `0.214` instead of remaining encoded. Restrict the decode to ordinary sampling results, while preserving it for ordinary sampling operations. > > <!-- cr-comment:v1:d66862a62f0254016396a176 --> > > </blockquote></details> --- <details> <summary>ℹ️ Review info</summary> <details> <summary>⚙️ Run configuration</summary> **Configuration used**: Repository: KytyPS5/KytyPS5/.coderabbit.yaml **Review profile**: CHILL **Plan**: Advanced **Run ID**: `6c1c0b9e-02ae-4f58-b86e-c56df1e29156` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between 5f4bafecd44083e29b8ecfcace4f9995354ae56c and b1392f6a964c8b8268a015463ea8762032b10fe2. </details> <details> <summary>📒 Files selected for processing (1)</summary> * `tests/ShaderRecompilerComputeTests.cpp` </details> **Included review availability:** Your plan provides up to 10 included reviews per hour; 8 remain after this review. </details> <!-- This is an auto-generated comment by CodeRabbit for review status -->
@ -228,3 +268,4 @@
}
if (mem.data_bits == 16u) {
uint32_t packed[4] = {ConstantU32(ctx.state, 0), ConstantU32(ctx.state, 0),
ConstantU32(ctx.state, 0), ConstantU32(ctx.state, 0)};
Author
Owner

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

@YuhiAida, thanks for the detailed update. The added cases cover the reachable ResultVector sRGB decode behavior and the disabled paths.

The materializer invariant makes positive integer and depth-reference decode cases unreachable. The existing negative integer marker is sufficient for this emitter coverage. No additional checks-only test is required for this finding.

You are interacting with an AI system.

**@⁠coderabbitai[bot]** on GitHub · 2026-09-18 21:20 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/706#discussion_r4050776343) `@YuhiAida`, thanks for the detailed update. The added cases cover the reachable `ResultVector` sRGB decode behavior and the disabled paths. The materializer invariant makes positive integer and depth-reference decode cases unreachable. The existing negative integer marker is sufficient for this emitter coverage. No additional checks-only test is required for this finding. _You are interacting with an AI system._ <!-- This is an auto-generated reply by CodeRabbit -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-04 10:36 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: 7537e7f7-64c6-4e96-8336-f543643703d2
📥 Commits

Reviewing files that changed from the base of the PR and between b051a10072 and 0e8f2465de.

📒 Files selected for processing (5)
  • src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
  • src/graphics/shader/recompiler/ir/ShaderIR.h
  • src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
  • 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-04 10:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/706#pullrequestreview-5405539501) · **reviewed** **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**: `7537e7f7-64c6-4e96-8336-f543643703d2` </details> <details> <summary>📥 Commits</summary> Reviewing files that changed from the base of the PR and between b051a10072ed8ab8398dcc78e45106e9c118d6ed and 0e8f2465de1a535ff967a20ba5537d312b6b7f49. </details> <details> <summary>📒 Files selected for processing (5)</summary> * `src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp` * `src/graphics/shader/recompiler/ir/ShaderIR.h` * `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` * `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 -->
Author
Owner

@⁠coderabbitai[bot] on GitHub · 2026-10-04 10:36 UTC · original
On src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp line 564 (outdated):

@@ -552,6 +561,7 @@ static bool BuildResourceSpecialization(const ResourcePlan& program, ResourceSna
 			    (!same_coordinates && !(is_2d(image.dimension) && is_2d(image_class.dimension))) ||
 			    image.mip_count != image_class.mip_count ||
 			    image.conversion_format != image_class.conversion_format ||
+			    image.srgb_sample_decode != image_class.srgb_sample_decode ||

🎯 Functional Correctness | 🟠 Major | 🏗️ Heavy lift

🔎 Supported by static analysis

🏁 Script executed:

sed -n '450,590p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
sed -n '1020,1135p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
rg -n 'indirect_images|image_class|srgb_sample_decode' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp

Repository: KytyPS5/KytyPS5

Length of output: 14704


🏁 Script executed:

printf '%s\n' '--- emitter ---'
sed -n '190,315p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
printf '%s\n' '--- indirect and sampled image references ---'
rg -n -C 3 'indirect_resources|indirect_root|indirect_mapping_offset|indirect_search_iterations|OpSampledImage|SampledImage|ImageSample|SampledImage' src/graphics/shader/recompiler
printf '%s\n' '--- formats and conversion/swizzle helpers ---'
rg -n -C 4 'ImageConversionFormat|NeedsSrgbSampleDecode|k8Srgb|k8UNorm|shader_swizzle|SampledTextureNumericClass' src/graphics/shader/recompiler src/graphics/shader/decoder

Repository: KytyPS5/KytyPS5

Length of output: 42657


🏁 Script executed:

printf '%s\n' '--- image sample emitter ---'
sed -n '680,850p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
printf '%s\n' '--- conversion/decode and image helper ---'
sed -n '1,125p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
sed -n '400,490p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
printf '%s\n' '--- image descriptor creation ---'
sed -n '160,190p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterAnalysis.cpp
printf '%s\n' '--- format remapping definitions and exact mappings ---'
rg -n -C 5 'RemapTextureFormat|k8Srgb|k8_8Srgb|k8UNorm' src/graphics/shader/recompiler/BufferFormat.h src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/shader

Repository: KytyPS5/KytyPS5

Length of output: 29345


🏁 Script executed:

printf '%s\n' '--- indirect sample selection and result merge ---'
sed -n '810,945p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
printf '%s\n' '--- texture format remapping implementation ---'
rg -n -C 8 'RemapTextureFormat' src/graphics/guest_gpu/gpu_format.h src/graphics/guest_gpu src/graphics

Repository: KytyPS5/KytyPS5

Length of output: 18593


🏁 Script executed:

printf '%s\n' '--- PR change at the comparison ---'
git diff --unified=3 db1758527751125592f57bf02f29616fa0643159 0e8f2465de1a535ff967a20ba5537d312b6b7f49 -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | rg -n -C 5 'srgb_sample_decode|incompatible candidates'
printf '%s\n' '--- sampled format classification ---'
sed -n '180,237p' src/graphics/guest_gpu/gpu_format.cpp
rg -n -C 2 'k8Srgb|k8UNorm' src/graphics/guest_gpu
printf '%s\n' '--- specialization failures and call sites ---'
rg -n -C 4 'BuildResourceSpecialization|SpecializationFail|MaterializeResources\\(' src/graphics/shader/recompiler

Repository: KytyPS5/KytyPS5

Length of output: 8241


🏁 Script executed:

rg -n -F -C 6 'MaterializeResources(' src/graphics/shader/recompiler
rg -n -F -C 6 'BuildResourceSpecialization(' src/graphics/shader/recompiler
rg -n -F -C 4 'SpecializationFail(' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp

Repository: KytyPS5/KytyPS5

Length of output: 12615


Keep compatible mixed sRGB/UNorm indirect tables.

When k8Srgb and k8UNorm candidates meet the other table constraints, the new decode-flag comparison rejects them even though both sample as floats and use no conversion format. This makes MaterializeResources fail for the table. The emitter samples candidates in separate switch arms, merges their results with OpPhi, then applies ResultVector using only the root image’s decode flag. Decode each candidate in its switch arm before the merge, skip the root-level decode for that result, and remove the table-wide comparison. Add a regression test for materialization and candidate-specific decoding.

🐛 Suggested fix
--- a/src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
+++ b/src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp
@@
 			    image.mip_count != image_class.mip_count ||
 			    image.conversion_format != image_class.conversion_format ||
-			    image.srgb_sample_decode != image_class.srgb_sample_decode ||
 			    image.shader_swizzle != image_class.shader_swizzle) {

--- a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
+++ b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp
@@
 uint32_t ResultVector(ValueEmitContext& ctx, uint32_t value,
                       Prospero::TextureNumericClass numeric_class, bool dref,
-                      const IR::MemoryInfo& mem, bool gather = false) {
+                      const IR::MemoryInfo& mem, bool gather = false, bool decode_srgb = true) {
@@
-	if (!integer && !dref && ctx.state.program.info.images[mem.resource].srgb_sample_decode) {
+	if (decode_srgb && !integer && !dref &&
+	    ctx.state.program.info.images[mem.resource].srgb_sample_decode) {
 		value = SrgbDecodedVector(ctx.state, value);
 	}
@@
 		const auto EmitSample = [&](uint32_t resource) {
@@
 			state.builder.AddFunction(opcode, sample_operands);
 			return sample;
 		};
+		const auto EmitCandidateSample = [&](uint32_t resource) {
+			const auto sample = EmitSample(resource);
+			if (dref || !state.program.info.images[resource].srgb_sample_decode) {
+				return sample;
+			}
+			return SrgbDecodedVector(state, sample);
+		};
@@
-		phi_words.push_back(EmitSample(image.indirect_resources[0]));
+		phi_words.push_back(EmitCandidateSample(image.indirect_resources[0]));
@@
-			phi_words.push_back(EmitSample(image.indirect_resources[candidate]));
+			phi_words.push_back(EmitCandidateSample(image.indirect_resources[candidate]));
@@
-		ctx.Define(inst, ResultVector(ctx, result, numeric_class, dref, mem));
+		ctx.Define(inst, ResultVector(ctx, result, numeric_class, dref, mem, false, false));
📝 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.


**@⁠coderabbitai[bot]** on GitHub · 2026-10-04 10:36 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/706#discussion_r4177136298) On `src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp` line 564 (outdated): ```diff @@ -552,6 +561,7 @@ static bool BuildResourceSpecialization(const ResourcePlan& program, ResourceSna (!same_coordinates && !(is_2d(image.dimension) && is_2d(image_class.dimension))) || image.mip_count != image_class.mip_count || image.conversion_format != image_class.conversion_format || + image.srgb_sample_decode != image_class.srgb_sample_decode || ``` _🎯 Functional Correctness_ | _🟠 Major_ | _🏗️ Heavy lift_ <details> <summary>🔎 Supported by static analysis</summary> 🏁 Script executed: ```bash sed -n '450,590p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp sed -n '1020,1135p' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp rg -n 'indirect_images|image_class|srgb_sample_decode' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 14704 --- 🏁 Script executed: ```bash printf '%s\n' '--- emitter ---' sed -n '190,315p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp printf '%s\n' '--- indirect and sampled image references ---' rg -n -C 3 'indirect_resources|indirect_root|indirect_mapping_offset|indirect_search_iterations|OpSampledImage|SampledImage|ImageSample|SampledImage' src/graphics/shader/recompiler printf '%s\n' '--- formats and conversion/swizzle helpers ---' rg -n -C 4 'ImageConversionFormat|NeedsSrgbSampleDecode|k8Srgb|k8UNorm|shader_swizzle|SampledTextureNumericClass' src/graphics/shader/recompiler src/graphics/shader/decoder ``` Repository: KytyPS5/KytyPS5 Length of output: 42657 --- 🏁 Script executed: ```bash printf '%s\n' '--- image sample emitter ---' sed -n '680,850p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp printf '%s\n' '--- conversion/decode and image helper ---' sed -n '1,125p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp sed -n '400,490p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp printf '%s\n' '--- image descriptor creation ---' sed -n '160,190p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterAnalysis.cpp printf '%s\n' '--- format remapping definitions and exact mappings ---' rg -n -C 5 'RemapTextureFormat|k8Srgb|k8_8Srgb|k8UNorm' src/graphics/shader/recompiler/BufferFormat.h src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp src/graphics/shader ``` Repository: KytyPS5/KytyPS5 Length of output: 29345 --- 🏁 Script executed: ```bash printf '%s\n' '--- indirect sample selection and result merge ---' sed -n '810,945p' src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp printf '%s\n' '--- texture format remapping implementation ---' rg -n -C 8 'RemapTextureFormat' src/graphics/guest_gpu/gpu_format.h src/graphics/guest_gpu src/graphics ``` Repository: KytyPS5/KytyPS5 Length of output: 18593 --- 🏁 Script executed: ```bash printf '%s\n' '--- PR change at the comparison ---' git diff --unified=3 db1758527751125592f57bf02f29616fa0643159 0e8f2465de1a535ff967a20ba5537d312b6b7f49 -- src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp | rg -n -C 5 'srgb_sample_decode|incompatible candidates' printf '%s\n' '--- sampled format classification ---' sed -n '180,237p' src/graphics/guest_gpu/gpu_format.cpp rg -n -C 2 'k8Srgb|k8UNorm' src/graphics/guest_gpu printf '%s\n' '--- specialization failures and call sites ---' rg -n -C 4 'BuildResourceSpecialization|SpecializationFail|MaterializeResources\\(' src/graphics/shader/recompiler ``` Repository: KytyPS5/KytyPS5 Length of output: 8241 --- 🏁 Script executed: ```bash rg -n -F -C 6 'MaterializeResources(' src/graphics/shader/recompiler rg -n -F -C 6 'BuildResourceSpecialization(' src/graphics/shader/recompiler rg -n -F -C 4 'SpecializationFail(' src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp ``` Repository: KytyPS5/KytyPS5 Length of output: 12615 --- </details> **Keep compatible mixed sRGB/UNorm indirect tables.** When `k8Srgb` and `k8UNorm` candidates meet the other table constraints, the new decode-flag comparison rejects them even though both sample as floats and use no conversion format. This makes `MaterializeResources` fail for the table. The emitter samples candidates in separate switch arms, merges their results with `OpPhi`, then applies `ResultVector` using only the root image’s decode flag. Decode each candidate in its switch arm before the merge, skip the root-level decode for that result, and remove the table-wide comparison. Add a regression test for materialization and candidate-specific decoding. <details> <summary>🐛 Suggested fix</summary> ```diff --- a/src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp +++ b/src/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpp @@ image.mip_count != image_class.mip_count || image.conversion_format != image_class.conversion_format || - image.srgb_sample_decode != image_class.srgb_sample_decode || image.shader_swizzle != image_class.shader_swizzle) { --- a/src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp +++ b/src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cpp @@ uint32_t ResultVector(ValueEmitContext& ctx, uint32_t value, Prospero::TextureNumericClass numeric_class, bool dref, - const IR::MemoryInfo& mem, bool gather = false) { + const IR::MemoryInfo& mem, bool gather = false, bool decode_srgb = true) { @@ - if (!integer && !dref && ctx.state.program.info.images[mem.resource].srgb_sample_decode) { + if (decode_srgb && !integer && !dref && + ctx.state.program.info.images[mem.resource].srgb_sample_decode) { value = SrgbDecodedVector(ctx.state, value); } @@ const auto EmitSample = [&](uint32_t resource) { @@ state.builder.AddFunction(opcode, sample_operands); return sample; }; + const auto EmitCandidateSample = [&](uint32_t resource) { + const auto sample = EmitSample(resource); + if (dref || !state.program.info.images[resource].srgb_sample_decode) { + return sample; + } + return SrgbDecodedVector(state, sample); + }; @@ - phi_words.push_back(EmitSample(image.indirect_resources[0])); + phi_words.push_back(EmitCandidateSample(image.indirect_resources[0])); @@ - phi_words.push_back(EmitSample(image.indirect_resources[candidate])); + phi_words.push_back(EmitCandidateSample(image.indirect_resources[candidate])); @@ - ctx.Define(inst, ResultVector(ctx, result, numeric_class, dref, mem)); + ctx.Define(inst, ResultVector(ctx, result, numeric_class, dref, mem, false, false)); ``` </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 ``` </details> <!-- suggestion_end --> <!-- fingerprinting:phantom:medusa:wombat --> <!-- cr-indicator-types:potential_issue --> <!-- cr-comment:v1:7028edf6960e5f3500213475 --> <!-- This is an auto-generated comment by CodeRabbit -->
Author
Owner

@⁠YuhiAida on GitHub · 2026-10-04 11:26 UTC · original

@⁠Nmzik

**@⁠YuhiAida** on GitHub · 2026-10-04 11:26 UTC · [original](https://github.com/KytyPS5/KytyPS5/pull/706#issuecomment-5979445472) @⁠Nmzik

Pull request closed

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