Repository navigation
fix(shader): emulate sRGB sampling when unsupported - #5371
likecrank-dotcom wants to merge 1 commit into
Conversation
AI assistance: OpenAI Codex (AI) implemented and validated this change. The human author remains responsible for review and submission.
|
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with 273e269 merged into main 18c438b:
AI-assisted: yes (Claude Code) |
adriadam10
left a comment
There was a problem hiding this comment.
Measured on RDNA2 (gfx1035) with tools/hw-oracle: image_sample_lz of 8_SRGB and 8_8_SRGB with point filtering returns the bf16 SrgbToLinear table value bit for bit. That holds under wrap, clamp-to-edge and all three clamp-to-border colours, out-of-range coordinates included. Bilinear decodes before filtering and stays within 1.1e-3 of a decode-then-filter model (8-bit HW weights). So the fallback's semantics match the hardware. Build and the AgcDriver/Agc tests pass on the PR head. The PR needs to be reworked on current main before it can go in:
- Conflicts with
mainthat aren't mechanical. #4475 replacedImageResource::indirectRoot/NoIndirectImagewith image tables (NoTable), and the runtime image metadata block this PR extends inDescriptorBindingBuilder.cpp:448-450no longer exists. The new table path has to decide what happens to an sRGB table entry (still zero-read, or refused). mainnow turns unsupported images intorejectImage(PoisonReason::SrgbUnsupported, ...)indecodeImageDescriptorinstead of throwing. The throws inemulatedSrgbSampleState(ResourceMaterializer.cpp:587-627) should follow that model, so an unsupported shape behaves the same way as onmain.- The execution test only exercises clamp-to-edge without offsets (
SamplerDescriptorword00x92).EmitEmulatedSrgbSamplealso implements wrap, clamp-to-border (transparent black, opaque black, white) and texel offsets, and none of these run. Please add rows with coordinates outside [0, 1] for each address mode and one with an offset. The point rows can also compare againstSrgbToLinearbit for bit instead of within 0.005, because the hardware does.
adriadam10
left a comment
There was a problem hiding this comment.
Thanks for the work; the semantics are right (decode before filter matches RDNA2 point and bilinear sampling, measured earlier in this thread). The problem is that the base moved under it:
- #6054 (merged 2026-10-18) already samples 8_SRGB / 8_8_SRGB on devices without R8_SRGB / R8G8_SRGB through an RGBA8 sRGB copy, which decodes before filtering. The shader decode now only runs when the device cannot blit R8/RG8 to RGBA8, or with
APS5_SRGB_SHADER_DECODE=1; those cases still throw onmain(docs/dev/debt/shader.md, "Samples and gathers"). Please say in the PR which real device hits that case. If none does, this fallback has no user and should be dropped; if one does, rebase ontomainand scope the PR to it. - The branch conflicts with
mainbeyond adjacency:ImageResource::indirectRoot/NoIndirectImagebecame image tables (NoTable), anddecodeImageDescriptor/inspectImageDescriptor(ResourceMaterializer.cpp) now returnrejectImage(PoisonReason::SrgbUnsupported, ...)instead of throwing. The throws inemulatedSrgbSampleStateshould follow that model, and the table path has to decide what an sRGB table entry does. SpirvImageEmitter.cppEmitEmulatedSrgbSample: wrap, clamp-to-border (transparent black, opaque black, white) and texel offsets are implemented but no test runs them. Add rows with coordinates outside [0, 1] for each address mode and one with an offset, and compare the point rows bit for bit againstSrgbToLinear(the hardware does).docs/dev/debt/shader.md: the new line must replace the current "Samples and gathers" line onmain(it now describes the copy path), not the old throw line.
Happy to re-review once rebased.
Verdictstale+rebase Findings
Freshness envelope
Cross-PR ledger
|
|
@likecrank-dotcom I agree with adriadam10's second review on this head, and the decision is yours to make. Since #6054 main already samples R8 and RG8 sRGB through an RGBA8 copy, so this shader decode only runs on a device that cannot blit R8/RG8 to RGBA8, or with APS5_SRGB_SHADER_DECODE=1. Which real device hits that case? If none does, the fallback has no user and should be dropped. If one does, please rebase onto main (the PR is conflicting), follow the rejectImage(PoisonReason::SrgbUnsupported, ...) model for the unsupported shapes, and add the address mode and offset rows he listed. |
Validation run: PR #5371
|
MarcZX10
left a comment
There was a problem hiding this comment.
Reviewed — changes requested
Changes are required before merge: fix sRGB mode dispatch so specialized modules emit fallback sampling only for sRGB descriptors.
What I ran
- Reviewed head
273e2695e4df17f5036cef403b761ebb406547cfand the prepared patch; no commands or tests were run. - Read
description.md,commits.md,manifest.json,diff.patch,ResourceMaterializer.cpp,DescriptorBindingBuilder.cpp,SpirvImageEmitter.cpp,RuntimeAbi.hpp,Resources.hpp, andImageSampleForceDegamma.cpp.
Results
| Check | Result | Note |
|---|---|---|
| Patch review | failed | One verified dispatch defect |
| Tests | not run | Author reports Windows GPU tests |
| Excluded files | not applicable | files.json was not available through the reader |
Findings
Blocking
SpirvImageEmitter.cpp:1506— The fallback is selected using the staticimage.srgbDecodemode before the runtime descriptor format is resolved.RuntimeImageModesadds both ordinary and sRGB modes for eligible images, andEmitImageemits both as separate specialized branches, but the sRGB branch’s sample operation is emitted as unconditional fallback code. When the descriptor is UNORM, that branch still decodes its texels as sRGB; when the descriptor is sRGB, the ordinary branch can also be selected and sample through the native path. The format-dependent mode therefore does not reliably select matching behavior. Make the fallback conditional on the selected mode or descriptor format, and verify both descriptor variants.
Non-blocking
None.
Not verified
CMakeLists.txt,ShaderMemory.cpp,ImageSrgbLoad.cpp,PipelineSpecialization.hpp, anddocs/dev/debt/shader.mdwere not read directly from repository paths; their prepared diff sections were reviewed where present.- The manifest lists these ten changed files, all marked included.
files.jsonand the packaged full-file texts were unavailable through the reader, so complete file coverage and exclusions could not be confirmed. - No tests, build, console runtime, or PS5 gfx1013 behavior was run or confirmed. Test results in the description are author-reported.
To get this to a good state
Fix mode-dependent sRGB dispatch, then run the focused CTest group on the new head and confirm both sRGB and UNORM descriptor behavior.
|
I am closing this for now. The maintainer review of 14 Oct asked for the sRGB emulation to match the RDNA2 image_sample_lz measurements on 8_SRGB and 8_8_SRGB bit for bit, and there has been no push since 13 Oct. The branch also conflicts with main in several shader files, and part of it has landed already. You are welcome to reopen or push a rebased branch at any time and we will look at it again. |
What
Issue #3751 reports sampled R8_SRGB/R8G8_SRGB images failing on devices that cannot sample those Vulkan formats. This adds a shader fallback for direct, single-mip 2D images: fetch texels through the UNORM view, decode each texel from sRGB, then apply point or bilinear filtering. The shader receives the sampler state through runtime metadata in registration modules or specialization constants in specialized modules.
Unsupported shapes and sampler modes still fail with explicit diagnostics; gathers and bindless image tables remain unsupported. Updated the old sRGB load test so it no longer expects ordinary sampling to fail when the fallback is enabled. The separate fallback test checks R8 and RG8 point and bilinear results against a per-texel decode-and-filter oracle.
Tested
Windows 11 Pro, WinLibs MinGW GCC 15.2.0, CMake 4.4.4, NVIDIA GeForce RTX 5060 Ti (driver 617.14).
agc_shader_memory,agc_driver_image_sample_force_degamma,agc_driver_image_srgb_load,agc_driver_image_sample_srgb_fallback, andagc_driver_emulated_color_compare_srgb_decode: 5/5 passed, repeated three times (15 successful executions).tools/check_conventions.py --base origin/main --head HEADandgit diff --check origin/main...HEADpassed.Checklist
main; no other open PR implements the same functions