Repository navigation
fix(shader): emulate sRGB sampling when unsupported - #5371
Open
likecrank-dotcom wants to merge 1 commit into
Open
likecrank-dotcom wants to merge 1 commit into
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.
This was referenced Oct 13, 2026
|
Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with 273e269 merged into main 18c438b:
AI-assisted: yes (Claude Code) |
This was referenced Oct 14, 2026
adriadam10
requested changes
Oct 14, 2026
adriadam10
left a comment
Collaborator
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.
This was referenced Oct 14, 2026
This was referenced Oct 15, 2026
This was referenced Oct 15, 2026
Closed
Open
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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