fix(shader): sample sRGB textures as UNORM when every paired sampler disables degamma #22644

Closed
JJenkx wants to merge 1 commit from upstream-pr/22644 into main
JJenkx commented 2026-11-17 23:57:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by JJenkx on 2026-11-17T23:57:41Z.


What

A sampler with DISABLE_DEGAMMA (S# word 0 bit 31, SKIP_DEGAMMA in Mesa's gfx10 register description) paired with an sRGB texture threw guest sampler descriptor disables degamma with an sRGB texture, which is not implemented (RequireDisablesDegammaOn). Destruction AllStars (PPSA02630) stops on it.

The bit makes the hardware return the stored values of an sRGB texture without the sRGB-to-linear conversion, which is what the UNORM format of the same layout returns. materializeDisabledDegamma (next to materializeForcedDegamma, which does the opposite for FORCE_DEGAMMA on RGBA8_UINT) rewrites a direct, sampled-only, non-comparison image of format 8_SRGB, 8_8_SRGB or 8_8_8_8_SRGB (128, 129, 130) to 8_UNORM, 8_8_UNORM or 8_8_8_8_UNORM (1, 14, 56) when every sampler it is paired with sets the bit. Mixed sampler states, the BC sRGB formats (unmeasured) and table images keep the guest format, so they still reach the existing refusal.

Hardware measurement

tools/hw-oracle on an RX 6650 XT (gfx1032, RDNA2, Linux 7.2.14, hsa-rocr 10.1, clang 23.1.5; wave32, IEEE off, DX10 clamp on, denormals preserved, round to nearest even, FP16 overflow off). A 1x1 texel with bytes (40, 120, 200, 255), image_sample and image_sample_lz DIM 2D, point sampler 00000092 00fff000 05500000 0, with and without bit 31:

Format without the bit with the bit
8_8_8_8_SRGB (130) (0.0212, 0.1875, 0.5781, 1.0), decoded (0.1569, 0.4706, 0.7843, 1.0)
8_8_8_8_UNORM (56) (0.1569, 0.4706, 0.7843, 1.0) (0.1569, 0.4706, 0.7843, 1.0)
8_SRGB (128) 0.0212 0.1569
8_UNORM (1) 0.1569 0.1569
8_8_SRGB (129) (0.0212, 0.1875) (0.1569, 0.4706)
8_8_UNORM (14) (0.1569, 0.4706) (0.1569, 0.4706)

So with the bit, each sRGB format returns exactly what its UNORM format returns, and the bit does nothing on UNORM. This is an RDNA2 measurement, not PS5 evidence.

Tested

Linux 7.2.14, Ryzen 9 7950X, RX 6650 XT, RADV (Mesa 26.2.7), GCC 16.2.1, Release, ANYPS5_ENABLE_SPIRV_TOOLS=OFF.

  • New agc_driver_image_disabled_degamma: draws a 1x1 texel (40, 120, 200, 255) through a point sampler for 8_8_8_8, 8 and 8_8. With the bit, the sRGB texture draws exactly what the UNORM texture draws, and the bit changes nothing on UNORM; without the bit the sRGB texture still decodes its data channels. With materializeDisabledDegamma disabled the test fails with the original disables degamma with an sRGB texture refusal.
  • PPSA01886 (3,940 frames) and PPSA02664 (3,861 frames), 70 s each, Cross every 15 s from 30 s: exit 0.
  • PPSA02630 (120 s, two runs) stopped on its other stops first, at 34 s on an anisotropic unnormalized sampler and at 20 s on a TYPE 2 V# (#22628), so neither run reached the degamma draw; this PR does not unblock it.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: none
  • Unblocks: none
  • GPUs tested: AMD Radeon RX 6650 XT, RADV (Mesa 26.2.7), Linux 7.2.14
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5367191981 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22644). Originally posted by [JJenkx](https://github.com/JJenkx) on 2026-11-17T23:57:41Z. --- ### What A sampler with DISABLE_DEGAMMA (S# word 0 bit 31, `SKIP_DEGAMMA` in Mesa's gfx10 register description) paired with an sRGB texture threw `guest sampler descriptor disables degamma with an sRGB texture, which is not implemented` (`RequireDisablesDegammaOn`). Destruction AllStars (PPSA02630) stops on it. The bit makes the hardware return the stored values of an sRGB texture without the sRGB-to-linear conversion, which is what the UNORM format of the same layout returns. `materializeDisabledDegamma` (next to `materializeForcedDegamma`, which does the opposite for FORCE_DEGAMMA on RGBA8_UINT) rewrites a direct, sampled-only, non-comparison image of format 8_SRGB, 8_8_SRGB or 8_8_8_8_SRGB (128, 129, 130) to 8_UNORM, 8_8_UNORM or 8_8_8_8_UNORM (1, 14, 56) when every sampler it is paired with sets the bit. Mixed sampler states, the BC sRGB formats (unmeasured) and table images keep the guest format, so they still reach the existing refusal. ### Hardware measurement `tools/hw-oracle` on an RX 6650 XT (gfx1032, RDNA2, Linux 7.2.14, hsa-rocr 10.1, clang 23.1.5; wave32, IEEE off, DX10 clamp on, denormals preserved, round to nearest even, FP16 overflow off). A 1x1 texel with bytes (40, 120, 200, 255), `image_sample` and `image_sample_lz` DIM 2D, point sampler `00000092 00fff000 05500000 0`, with and without bit 31: | Format | without the bit | with the bit | |---|---|---| | 8_8_8_8_SRGB (130) | (0.0212, 0.1875, 0.5781, 1.0), decoded | (0.1569, 0.4706, 0.7843, 1.0) | | 8_8_8_8_UNORM (56) | (0.1569, 0.4706, 0.7843, 1.0) | (0.1569, 0.4706, 0.7843, 1.0) | | 8_SRGB (128) | 0.0212 | 0.1569 | | 8_UNORM (1) | 0.1569 | 0.1569 | | 8_8_SRGB (129) | (0.0212, 0.1875) | (0.1569, 0.4706) | | 8_8_UNORM (14) | (0.1569, 0.4706) | (0.1569, 0.4706) | So with the bit, each sRGB format returns exactly what its UNORM format returns, and the bit does nothing on UNORM. This is an RDNA2 measurement, not PS5 evidence. ### Tested Linux 7.2.14, Ryzen 9 7950X, RX 6650 XT, RADV (Mesa 26.2.7), GCC 16.2.1, Release, `ANYPS5_ENABLE_SPIRV_TOOLS=OFF`. - New `agc_driver_image_disabled_degamma`: draws a 1x1 texel (40, 120, 200, 255) through a point sampler for 8_8_8_8, 8 and 8_8. With the bit, the sRGB texture draws exactly what the UNORM texture draws, and the bit changes nothing on UNORM; without the bit the sRGB texture still decodes its data channels. With `materializeDisabledDegamma` disabled the test fails with the original `disables degamma with an sRGB texture` refusal. - PPSA01886 (3,940 frames) and PPSA02664 (3,861 frames), 70 s each, Cross every 15 s from 30 s: exit 0. - PPSA02630 (120 s, two runs) stopped on its other stops first, at 34 s on an anisotropic unnormalized sampler and at 20 s on a TYPE 2 V# (#22628), so neither run reached the degamma draw; this PR does not unblock it. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: none - [x] Unblocks: none - [x] GPUs tested: AMD Radeon RX 6650 XT, RADV (Mesa 26.2.7), Linux 7.2.14 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-18 01:40:05 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-18T01:40:05Z.

Review: CHANGES_REQUESTED


Reviewed — changes requested

Changes are required before merge: remove or defer the earlier sRGB/disabled-degamma refusal so execution can reach the new materialization logic.

What I ran

Reviewed head 61b4473e2c5ab779761259d1e920965e821ca624 using the prepared diff and repo_read.py; no commands or tests were run.

Results

Check Result Note
Diff and changed files passed Three changed files inspected
Runtime call path passed Earlier refusal remains active
Tests not run No test execution available

Findings

Blocking

  • core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp:3009 applies the descriptor rewrite during materialization, but ShaderResources.cpp:5994 still calls RequireDisablesDegammaOn while processing the guest texture and sampler. Sampler.cpp:171 throws for this exact pairing, so the draw is rejected before it can reach the changed materializer. Remove or update that refusal for the supported cases, while retaining it for unsupported cases.

Non-blocking

None.

Not verified

Tests were not run. All three changed files listed in the manifest were included; source context was read for the materializer and the earlier refusal path. The prepared bundle does not provide a readable files.json, so additional file exclusions were not verified. PS5 behavior is not verified; the description reports RDNA2 measurements only.

To get this to a good state

Update the earlier refusal path to permit the supported direct sampled sRGB cases, then rerun the relevant tests.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5949570506 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/22644#pullrequestreview-5949570506). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-18T01:40:05Z. **Review:** CHANGES_REQUESTED --- # Reviewed — changes requested Changes are required before merge: remove or defer the earlier sRGB/disabled-degamma refusal so execution can reach the new materialization logic. ## What I ran Reviewed head `61b4473e2c5ab779761259d1e920965e821ca624` using the prepared diff and `repo_read.py`; no commands or tests were run. ## Results | Check | Result | Note | |---|---|---| | Diff and changed files | passed | Three changed files inspected | | Runtime call path | passed | Earlier refusal remains active | | Tests | not run | No test execution available | ## Findings ### Blocking - `core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp:3009` applies the descriptor rewrite during materialization, but `ShaderResources.cpp:5994` still calls `RequireDisablesDegammaOn` while processing the guest texture and sampler. `Sampler.cpp:171` throws for this exact pairing, so the draw is rejected before it can reach the changed materializer. Remove or update that refusal for the supported cases, while retaining it for unsupported cases. ### Non-blocking None. ## Not verified Tests were not run. All three changed files listed in the manifest were included; source context was read for the materializer and the earlier refusal path. The prepared bundle does not provide a readable `files.json`, so additional file exclusions were not verified. PS5 behavior is not verified; the description reports RDNA2 measurements only. ## To get this to a good state Update the earlier refusal path to permit the supported direct sampled sRGB cases, then rerun the relevant tests.

Pull request closed

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!22644
No description provided.