agc: sampled 8_SRGB decode on a device without R8_SRGB — measured filtering order and the fix shape it rules out (Ghost of Yōtei PPSA26344) #3751
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-11T16:27:18Z.
Sampled sRGB decode on a device without the sRGB format — measured filtering order, and what it rules out
SpirvImageEmitter.cppthrows"samples or gathers an sRGB image the device cannot sample, which is not implemented"for8_SRGB/8_8_SRGB, whichTechnicalDebt.mdrecords as a known gap. This note adds the measurement the implementation decision turns on, so the obvious implementation is not attempted by mistake.Why a device hits this.
Graphics::SrgbDecodeFormatsprobesFormat8SrgbandFormat8_8Srgband only offers shader-side decode where the device cannot sample the sRGB variant but can sample the UNorm one. On lavapipe bothFORMAT_R8_SRGBandFORMAT_R8G8_SRGBappear invulkaninfo's unsupported list, so the mask is non-empty and the path is reachable. Only those two formats can enter the mask, so a title that trips this is sampling an R8 or R8G8 sRGB image.What was measured, and on what. A 2×1
R8G8B8A8_SRGBimage with texel0 R=255 and texel1 R=0, sampled at u=0.5 with aVK_FILTER_LINEARsampler. The two candidate orders predict different values:Result, identical on two independent drivers:
So both measured drivers decode sRGB to linear before filtering — filtering happens in linear space — and the two agreeing makes it very unlikely to be vendor-specific.
What that rules out. A post-sample decode — bind the UNorm view, sample, then apply the sRGB EOTF to the result — is exact only where no interpolation happens: gathers, and samples whose sampler does not blend between texels. Where the sampler does interpolate it is wrong, and wrong in the direction above:
0.214where the reference produces0.5. That is presumably why this was left as debt, and it means the two halves of the debt are not equally cheap:Two routes for the interpolating case, in case it helps decide:
R8_SRGB→ a UNorm/float view holding linear values) and sample that. Hardware filtering is then already in linear space and is exact by construction; the cost moves to the write path and to the memory the proxy needs.Reproduction on a title. Ghost of Yōtei (PPSA26344) compute shader
0x8000376e00, presentation path:Instrumenting the sampler lookup for its sampled sRGB images shows the title's S# filter fields in both encodings,
magFilter = (words2 >> 20) & 3andminFilter = (words2 >> 22) & 3:so the title exercises both. The failing access itself resolves to
Format8Srgb(guest format 128,SrgbDecodeBit1) — a sampled, non-storage, non-packed, non-table image — but its own sampler's filter does not need to be known to make the point below:srgbDecodeCompatibleis cleared by aneedsSamplerflag that carries no filtering information, and the reject aborts the compile before any pass reads the sampler words. A point-only increment would therefore first have to have the filter plumbed into that decision; a filter-independent route avoids the question entirely.Environment: CachyOS, lavapipe (Mesa 26.2.4, LLVM 23.1.1) and NVIDIA 615.71.09, on a tree carrying the merged
#3300dispatch split, which is what let the title reach this wall.Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-11T16:34:30Z.
I am tracing the unsupported sampling path to see what a correct per-texel implementation would need to cover. Could you capture the four S# descriptor dwords for the specific failing image access in shader
0x8000376e00, together with its decoded sample opcode/flags (implicit or explicit LOD, gradients, offset, gather)? The dump currently establishes that the title uses both point and bilinear samplers, but not which sampler is paired with the access that triggers the compile failure. That distinction will help build a focused regression case and avoid assuming the failing path is bilinear.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-11T21:47:54Z.
Reproduces on a current stack, and the guard relaxation is not the fix
Two runs of one build —
main14a7e64dcplus the two still-open table PRs (#757e904eb18c, #7581ff81c241) — on lavapipe (Mesa 26.2.4, LLVM 23.1.1): one with a cold shader cache (0 hits, 232 misses at the point of failure) and one warm (1153 hits, 0 misses), on an otherwise idle box.Both runs abort here, at the same shader. Neither log names the min/max reduction refusal (
0x80003af600) or the unnormalized-sampler fold — the run dies at the sRGB shader, so the paths that would emit them are not reached in these two runs.Why this wall comes first here and not on the tree I measured before. On the older tree this issue was filed from, the sRGB refusal had been relaxed locally, which is why that run got past this shader and stopped on the min/max reduction instead. The two results are the same sequence seen from different starting points, not a disagreement: on a current tree, with the guard intact, the sRGB access is what the presentation path reaches first.
Scope. This holds only where the device probe finds no R8_SRGB sampling. On lavapipe
FORMAT_R8_SRGBandFORMAT_R8G8_SRGBare both unsupported, soSrgbDecodeFormatsis non-empty and the shader-side decode path is taken; the RTX 3080 Ti I also run on does support samplingFORMAT_R8_SRGB, so this wall cannot be provoked there at all.What not to do. I have a local branch that "passes" this wall with a two-file guard relaxation (
ResourceMaterializer.cpp,SpirvImageEmitter.cpp; +2/−8 — the same commit also carries unrelated scalar-aperture modelling): theSrgbUnsupportedreject ininspectImageDescriptor, thesrgbDecodeCompatibleterm in theRuntimeImageModescondition, and the emit-time refusal inEmitSamplingOp. That is a relaxation, not a decode: it lets the post-sample decode run in exactly the case this issue measured to be wrong in principle, so it would trade a refusal for a wrong colour. I did not capture a rendered frame from that branch, so this is the reason not to port it rather than a measurement of it — recording it here so a later reader does not mistake it for the fix.What I could not check. No AMD GPU here. No part of this is device-independent: the wall exists only on devices without R8_SRGB sampling, and no R8_SRGB-capable device — including my Ampere box — can provoke it. The filtering-order numbers are this issue's measurement on lavapipe and the 3080 Ti, quoted rather than reproduced.
Hermes Agent 🤖 at your service — AI assistance: the build, the runs and this write-up were produced by an AI agent on the contributor's machine.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T17:26:22Z.
I set out to get you the four dwords for that access and could not — here is the instrument, and what
blocked it
I added the dump you need and ran it. It works, and it captures real sampler descriptors — these are
other pipelines, not yours, see below:
But it is not the access you asked about. Shader
0x8000376e00never appears in the run at all — zerooccurrences in the log — so those descriptors belong to other pipelines. I would rather say that than hand
you four dwords and imply they came from your shader.
Why the shader is unreachable here. On the CI device (lavapipe,
LLVM 23.1.1) it is never compiled.The run logs, in this order:
So the sRGB refusal never fires — not because the guard is wrong, but because nothing reaches the access.
That order is itself the data point: the first fatal wall this title meets is the llvmpipe dispatch
limit, not the sampling path. An earlier instrumented run on this same stack printed the dimensions the
current build omits:
(129199x1x1, device limit 65535x65535x65535). On the 3080 Ti the same build does nothit that wall at all (no dispatch-limit abort anywhere in that run), which is where I would try next.
The instrument, so it can be captured where the shader is reachable. A four-line helper beside
SamplerCacheDisabled, plus one line in the sampler loop, gated by an env var — what is printed is what thedriver is about to use, not a re-derivation:
It goes in
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp, in the samplerelsebranchthat requires
elementWords == 4just above the loop (line 3117), so the four dwords are contiguous and instored order.
compareissamplerDepthCompare,unnormalizedthe unnormalized-coordinate metadata, bothper-element and travelling with the words.
One limitation I would rather flag than let you find. That is one of two places that fill
samplerSources.addSamplerTable(ShaderResources.cpp:3455) does the same push for sampler-tablebindings and has no dump — so if the failing access arrives through the table path, this instrument stays
silent. If that is what happens, the same line belongs there too; I have not covered it.
On the flags half of your question. I did not get to it. The implicit/explicit-LOD, derivative, offset
and gather distinctions are the
RdnaImageSampleFlag*bits;ImageSampleExplicitLod(flags, stage)(
IrMetadata/Resources.hpp:113) is the explicit-LOD predicate the recompiler already applies(
ShaderInfoCollector.cpp:467,SpirvImageEmitter.cpp:1309), and it does not cover offset or gather — sothe decode exists, I just have no access to decode it for. I am not going to guess at the opcode.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-12T18:11:47Z.
Correcting my comment above: "the shader is never reached" is wrong.
I wrote that on the CI device this access is never compiled and that the sRGB refusal never fires. Both
false. Eight runs on 2026-10-11 carry it, all on the same lavapipe ICD the CI device uses
(
llvmpipe (LLVM 23.1.1)) — run locally, as the earlier comment's runs were:and one of them names the request explicitly (
compute shader 0x8000376e00 (shader_8000376e00.req)).So the wall is reachable on that device, and has been reached. What I actually measured was narrower
than what I asserted: the run I instrumented died earlier, on the llvmpipe dispatch limit
(
compute shader 0x8000393600: Vulkan dispatch: workgroup count exceeds device limits), so that run nevergot to this shader. I turned "this run did not reach it" into "this device never reaches it". The
first is a measurement; the second is false.
This helps your question rather than weakens it: the four S# dwords are obtainable here. The instrument
below is the right one and it works — it printed real descriptors on my run
(
[sampler] binding=57 element=0 dwords=00000092 00fff000 05500000 00000000 compare=0 unnormalized=0).What it needs is a run whose stack gets past the dispatch wall first. One of the 2026-10-11 runs
demonstrably does — it logs the
0x8000393600pipeline and then reaches this shader — and mine did not.I am chasing that rather than asking you to.
Written with AI assistance.
Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-13T02:15:57Z.
@MarcZX100, these are the image (T#) dwords for the failing access, not the S# dwords and opcode flags you asked for; those are still not captured (see the end).
On
main510a2188c+ #757 + #758 (llvmpipe, LLVM 23.1.1) the run now reaches0x8000376e00; the earlier run in this thread did not. I added a temporaryfprintfat the refusal inResourceMaterializer.cpp:231(PoisonReason::SrgbUnsupported, thedecoded.srgbDecode && !base.srgbDecodeCompatiblebranch) and ran the title once:format=128isIrBufferFormat::Format8Srgb(BufferFormat.hpp:87), so this is the single-channel R8 case, not R8G8.dims=3isDim2D.table=4294967295isNoTable: the image is bound directly, not through a bindless table.storage=0: it is a sampled image.src=21is the image resource'ssource;pc=0xf48is itsfirstUsePc, the first use of the image, not necessarily the access that triggered the refusal.ResourceTracker.cpp:1361clearssrgbDecodeCompatiblewhen an opcode withneedsSamplertouches the image.Not captured: the paired sampler dwords, the sample opcode, and its flags (LOD mode, gradients, offset, gather). So this still does not say whether the access interpolates, which separates the cheap half of the debt from the expensive one. The instrument is not in the tree. Capturing the rest means printing the
ImageOpcodeInfoand the sampler resource at the same site; I have not done that.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-13T02:23:57Z.
@MarcZX100, the sample opcode and flags for the R8 sRGB image from my previous comment (same build:
main510a2188c+ #757 + #758, llvmpipe LLVM 23.1.1). I temporarily printed everyneedsSampleraccess inResourceTracker.cppMergeforsource == 21. The line atpc=0xf48:op=428isImageGatherRaw(IrOpcodeindex 428; 427 isImageSampleRaw).flags=0x20isRdnaImageSampleFlagLevelZero: no gradients, bias, offset or compare.dmask=0x1is one channel, with a 2-component address.sourceappears atpc=0x104cwithsampler=3, same flags.By the split in this issue, a gather falls in the non-interpolating half, where decoding after the fetch equals decoding each texel.
ResourceTracker.cpp:1361clearssrgbDecodeCompatiblefor everyneedsSampleropcode, which is what makesResourceMaterializer.cpp:231refuse.Limits:
0x8000376e00only byfirstUsePc == 0xf48from the T# dump in my previous comment. The[DBG-OP]lines carry no shader id andsource == 21is shared by many shaders, so another shader whosesrc=21image first appears at0xf48would print the same line. The0xf48gathers show up in two places in the log, well before the abort, so I cannot show they belong to the failing shader.materializeTables(RuntimeImageMode), beforeResolveImageTablesreaches the sampler-pair loop (~line 919), so the sampler words are never read.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-13T02:49:14Z.
@MarcZX100, a follow-up to the R8 sRGB gather above (same build:
main510a2188c+ #757 + #758, llvmpipe LLVM 23.1.1). I tried a local spike that letsImageGatherRawkeep the sRGB decode:ResourceTracker.cpp:1361no longer clearssrgbDecodeCompatiblefor a gather, andSpirvImageEmitter.cppskips the sRGB refusal for gathers and runsDecodeSrgbTexelon the gathered lanes (5 lines; not pushed).With the spike, this run no longer logs the sRGB refusal, and
0x8000376e00now logs a different one,SpirvImageEmitter.cpp:1052inMakeSampleSetup:I printed every hit on that check (temporary
fprintf, not in the tree). 33 hits in one run, from 30 distinct(source, pc)accesses, allImageGatherRaw, all withconv=30 srgb=0.conv=30isIrBufferFormat::Format11_11_10UNorm.srcranges over 0 to 48, so this is not one shader. The run aborts on the same refusal in shader0x80003d0600; the other refusals are logged as non-fatal "could not be prepared after registration".So on this build the sRGB gather is not the last wall on the way through: gathering a converted unorm image is a separate gap that sits right behind it. I have not read the emitted SPIR-V for the sRGB gather, so I cannot say the decoded values are correct. The run aborts before anything is presented.
Question for you: is the converted-unorm refusal at line 1052 meant to also cover gathers, which return whole texels and are not filtered? If gathers can go through
UnpackImageGatherplus a unorm-to-float step, I can try that as its own change.Imported from boykopovar/AnyPS5. Originally posted by Dextroid17 on 2026-10-13T03:25:02Z.
Correction to my comment above: I called the spike "5 lines". The saved diff is 36 lines (the
ResourceTracker.cppchange plus the emitter changes), so "a small local patch" is the accurate description. Nothing else in that comment changes.