Skip to content

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

Closed
JJenkx wants to merge 1 commit into
boykopovar:mainfrom
JJenkx:fix/agc-disable-degamma-srgb-textures
Closed

JJenkx wants to merge 1 commit into
boykopovar:mainfrom
JJenkx:fix/agc-disable-degamma-srgb-textures

Conversation

@JJenkx

@JJenkx JJenkx commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

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# (fix(shader): preserve vector destinations through TYPE 2 and 3 buffer descriptors #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

…disables degamma

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tablefrogpillow

Copy link
Copy Markdown
Contributor

Real-AMD coverage — the sRGB-as-UNORM path (a sampler with DISABLE_DEGAMMA on an sRGB texture) holds across GCN5, RDNA2 and RDNA3. agc_driver_image_disabled_degamma, head 61b4473e, Khronos validation 1.4.363, ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1:

GPU arch result
RX Vega 56 (RADV VEGA10, gfx900, Wave64) GCN5 Pass, 0 VUID
Ryzen 7000 iGPU (RADV RAPHAEL, gfx1036) RDNA2 Pass
RX 7900 GRE (RADV NAVI31, gfx1100) RDNA3 Pass, 0 VUID
lavapipe SW Pass

The 1×1 texel (40, 120, 200, 255) comes back as the UNORM value through the point sampler for 8_8_8_8, 8 and 8_8 on all four. sRGB decode is a sampler-hardware behavior, so the clean GCN5 Wave64 pass — beyond your RX 6650 XT (RDNA2) run — confirms SKIP_DEGAMMA is honored the same way across the GCN→RDNA span.

AI-assisted: yes

@JJenkx

JJenkx commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the GCN5, RDNA2 and RDNA3 runs. One distinction for whoever reviews this: the execution test goes through Vulkan after this change has already rewritten the sRGB T# to UNORM, so these runs show the rewrite samples correctly on those drivers, not how the hardware itself treats the S# bit. The hardware evidence for the bit is still the RX 6650 XT oracle measurement in the description (gfx1032 only); it is not measured on a PS5 or on GCN.

AI-assisted: yes

@JJenkx

JJenkx commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Correction to the title evidence in this PR's description. The PPSA02306 and PPSA02630 descriptors it cites (image words in buffer and sampler slots) appear to come from pixel programs the driver should not run (draws whose color write masks reach no formatted target); I have not traced each descriptor to its draw, but the stops disappear when those programs are skipped. With only #21747's one-line change to PixelProgramSkipped (ColorWriteMask(cx) == 0 instead of CB_TARGET_MASK & CB_SHADER_MASK) on main 8db3d3761785, and none of my descriptor PRs, 120 s with Cross every 15 s from 30 s on an RX 6650 XT: PPSA02306 (2,725 frames), PPSA02630 (1,531) and PPSA05626 (4,099) each ran the full 120 s with exit 0 (one run each). On main these titles stop within 18 to 72 s on such descriptors.

So these titles do not need this PR once #21747 is merged, and the description's "stops on it" no longer motivates it. What remains is the hardware behaviour this PR implements, measured as the description states; it applies only when a program really samples or loads through such a descriptor. I am leaving the PR open on that basis, and the maintainers may reasonably decide it is not worth the code without a title that needs it.

AI-assisted: yes

@MarcZX10 MarcZX10 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@JJenkx

JJenkx commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the review. I do not think the refusal is reached for the rewritten cases, because it runs on the materialized descriptor, not the guest's:

  • materializeDisabledDegamma rewrites the image's word 1 format in the ResourceSnapshot (128, 129, 130 to 1, 14, 56).
  • DescriptorBindingBuilder fills GuestImages bindings from that snapshot (snapshot.images.at(...), copied into physical.guestDescriptor, DescriptorBindingBuilder.cpp around line 753).
  • ShaderResources.cpp:5994 decodes resource.format from binding.guestDescriptor, so for a rewritten image it sees 8_8_8_8_UNORM, 8_UNORM or 8_8_UNORM and RequireDisablesDegammaOn does not throw. It still throws for the cases the rewrite leaves alone (mixed sampler states, BC sRGB formats, table images), which is intended.

agc_driver_image_disabled_degamma exercises exactly this path end to end through device.Draw: with the change it draws the UNORM values for all three formats, and with materializeDisabledDegamma disabled it fails with the original disables degamma with an sRGB texture refusal, as the description says. The real-AMD runs above (GCN5, RDNA2, RDNA3, lavapipe) also pass.

If you see a path where binding.guestDescriptor is filled from guest memory rather than the snapshot, please point me at it and I will add a case for it.

AI-assisted: yes

@JJenkx

JJenkx commented Nov 18, 2026

Copy link
Copy Markdown
Contributor Author

Closing this as a duplicate of my own earlier #20728, which I should have found before opening it. DISABLE_DEGAMMA here is the same S# word 0 bit 31 that #20728 calls SKIP_DEGAMMA. #20728 covers more: it selects a UNORM view instead of rewriting the materialized format, handles the BC sRGB formats this PR leaves refused, keeps FORCE_DEGAMMA's precedence when both bits are set, and has a 70-mode gfx1032 measurement behind it. Reviewers should look at #20728 instead.

The real-AMD runs above and the review discussion apply to this PR's approach only. As the comment above says, the PPSA02630 draws that motivated it appear to come from pixel programs #21747 skips.

AI-assisted: yes

@JJenkx JJenkx closed this Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs shader core/shader

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants