shader: give depth-compare samplers their own sampler variant #1733
No reviewers
Labels
No labels
bug
documentation
duplicate
enhancement
GPU
GUI
help wanted
question
Shaders
Video
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/KytyPS5--KytyPS5!1733
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1733"
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?
@Nawid3333 on GitHub · 2026-10-19 20:04 UTC · original
Nawid3333:shader/sampler-compare-variants→main· +39 −4 · 3 files · 1 commits · openA guest S# carries a depth compare function in bits 14:12. On RDNA2, only
SAMPLE*C*andGATHER*C*take the z-compare operand. So one sampler source can be used both by a compare instruction and by a non-compare instruction.AddSamplerdeduplicates samplers by source, while the image entries carrydepth_compare. Both uses then share one Vulkan sampler with a singlecompareEnable.The Vulkan spec (Texel Input Operations) lists cases in which the returned texel is poison; two of them apply here. The first is an
OpImage*Dref*instruction with a sampler whosecompareEnableisVK_FALSE. The second is a non-Dref instruction with a sampler whosecompareEnableisVK_TRUE. A shared sampler is wrong for one of the two sides on every host.Some hosts do not support depth comparison for
VK_FORMAT_R32_SFLOAT. There the validation layer also rejects the pairing. Two NVIDIA logs show this:vkCmdDrawIndexed(): the sampled image descriptor [Set 0, Binding 80, Index 0, variable image_24] has VkImageView with format of VK_FORMAT_R32_SFLOAT which doesn't support VK_FORMAT_FEATURE_2_SAMPLED_IMAGE_DEPTH_COMPARISON_BIT.(VUID-vkCmdDrawIndexed-None-06479).vkCmdDispatch(): ... Binding 24 ... VK_FORMAT_R32_SFLOAT ...(VUID-vkCmdDispatch-None-06479), ASTRO BOT (PPSA21567), RTX 5060 Ti 16 GB.Change:
SamplerClassgainsCompare, andClassifySamplerreturns it for depth-compare images. The existing sampler plan, which already splits Float/Integer border variants of one guest sampler, then builds a compare variant that shares the guest descriptor.depth_comparecomes from its class;integer_bordernow tests== Integer.depth_compare.ResourceMaterialization.cpp,spirvEmitterImage.cpp,tests/ResourceMaterializationTests.cpp(+39/-4). Branch head040e658f0, one commit on upstream main39936ffa3.TestCompareSamplerUsesOwnVariant: one sampler shared by a compare image and a plain k32Float image must give 3 sampler entries, 2 runtime descriptors, and each pair's sampler compare equal to its image's compare.This supersedes #1625. ricardocacco asked me to open it from this branch and will close #1625 as superseded. He confirmed that
AddSamplerdeduplicates by source while the image entries carrydepth_compare. He never reproduced the VUID locally. He calls the device loss in his runs unrelated. I do not claim this fixes the NVIDIA device loss. It fixes the invalid sampler/image pairing above.Named games: ASTRO BOT (PPSA21567, the
VUID-vkCmdDispatch-None-06479log in #1476) and Astro's Playroom (PPSA01325, theVUID-vkCmdDrawIndexed-None-06479log in #1476, canonical report #1552).Tests
Local, Windows, Release:
ResourceMaterializationTestson main39936ffa3with only the new test added:ResourceMaterializationTests: failed: shared compare sampler did not get its own variant. The same on0cad4672before the rebase.040e658f0):ResourceMaterializationTests: all cases passed.resource_tracking_tests:resource tracking tests passedwith the fix and on main;shader_cfg_testsgives the same output on both.Fork CI on
040e658f0: run 44942861601: the Windows, Linux and macOS jobs pass (build plus the CPU tests CI runs, includingresource_materializationandresource_tracking).gpu_verify on GPU0 (RX 9070 XT) and GPU1 (RDNA2 iGPU), run on
bc553dcabefore the rebase:ComparisonDepthTexture,ImageSampleA16CompareBiasRdna2AddressOrderandImageGatherCompareOpcodeswith native and 32-wide host subgroups. They pass with the fix and on main, with 0 validation messages. They do not show the problem on these GPUs.Note:
BuildSamplerPlanpropagates class usage one level, from a paired sampler to its indirect candidates, as it already does for the Integer class. A nested indirect sampler chain under a compare sampler would therefore hit the existingEXIT_IFin the candidate remap, like an Integer chain does today. I have not seen such chains, but I have not proven they cannot occur.If you would rather handle this differently, feel free to close it and say what you would prefer.
AI use
I used Claude Code (AI agent) to find the cause, write the change and the test, and run the checks. I reviewed the diff and the results.
🤖 Generated with Claude Code
@coderabbitai[bot] on GitHub · 2026-10-19 20:13 UTC · original · edited 2026-11-21 19:52 UTC
Walkthrough
Sampler planning now distinguishes comparison samplers from integer and float samplers. Specialization sets
depth_comparefor comparison bindings and limitsinteger_borderto integer bindings. SPIR-V emission matches sampler variants by integer-border and comparison state. A new test checks the variants and their guest sampler snapshots.Suggested reviewers:
nmzikChange: Bug fix
Merge Risk:
Minimal · up to
040e6This change gives depth-compare samplers their own sampler variant so compare and non-compare uses of one guest sampler no longer share compare state. No actionable merge-blocking risk was found. The separate NVIDIA device loss reported by a tester is outside this PR's stated scope.
Pre-merge checks:
3 ·
1
#1625] is open and directly linked. Its coding requirement:RenderExecutor::PrepareBindingswalksShaderInfo::sampled_pairs. For a sampler withdepth_compare == truepaired with an image whose …#1625guard inRenderExecutor::PrepareBindings: clear the compare-enable bits for a depth-compare sampler paired with a non-depth image, and log the shader hash and stage. Add automated coverage for that behavior. Or …SamplerClass::CompareandClassifySamplerinResourceMaterialization.cpproute depth-compare images to a compare variant that shares the guest sa…Full details: Title check
Explanation
The title names the main change: depth-compare samplers get their own sampler variant. The raw summary confirms the Compare sampler class, the new variant, and the depth_compare matching in the SPIR-V lookup. The title is specific and matches the changeset.
Full details: Description check
Explanation
The description explains the cause (one guest sampler source shared by compare and non-compare instructions, causing a wrong compareEnable state), the fix (Compare class and separate variants), the files touched, the new test, and the test results. It relates directly to the changeset.
Full details: Out of Scope Changes check
Explanation
The supplied whole-PR summary lists three files.
SamplerClass::CompareandClassifySamplerinResourceMaterialization.cpproute depth-compare images to a compare variant that shares the guest sampler descriptor. ThespirvEmitterImage.cppchange makes the typed-variant lookup matchdepth_compare.TestCompareSamplerUsesOwnVariantcovers this pairing. All three changes address the compare-sampler and image pairing described by [#1625] and the PR description. No unrelated change appears in the supplied evidence. The current head diff could not be read, so this conclusion rests on the PR summary. The PR description notes that nested indirect sampler chains under a compare sampler may hit an existingEXIT_IF. That is a correctness risk, not an out-of-scope change.Full details: Linked Issues check
Explanation
[
#1625] is open and directly linked. Its coding requirement:RenderExecutor::PrepareBindingswalksShaderInfo::sampled_pairs. For a sampler withdepth_compare == truepaired with an image whoseinfo.IsDepth()is false, it clears the compare-enable bits (fields[0] &= ~(0x7u << 12u)) and logs the shader hash and stage. The whole-PR evidence lists changes only inResourceMaterialization.cpp,spirvEmitterImage.cppandtests/ResourceMaterializationTests.cpp. NoRenderExecutor::PrepareBindingschange is listed. The PR description states that the PR replaces the guard with separate compare and plain sampler variants. That approach does not clear compare state or log the shader hash and stage at the bind site. The requirement stays unmet. The current head diff could not be read (changed blobs are missing from the checkout), so this verdict relies on the supplied PR summary. The PR also adds no test for the#1625guard behavior. Separate sampler variants may remove the invalid pairing, but they do not implement the requested guard. The incremental changes since the previous review could not be inspected, so this conclusion is unchanged from the previous assessment.Resolution
Either implement the
#1625guard inRenderExecutor::PrepareBindings: clear the compare-enable bits for a depth-compare sampler paired with a non-depth image, and log the shader hash and stage. Add automated coverage for that behavior. Or obtain maintainer confirmation that#1625is closed as superseded, so it no longer applies as an active linked requirement. Then re-run this assessment.Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Share
@theantipopau on GitHub · 2026-10-20 00:48 UTC · original · approved these changes
Verified the full chain: BuildSamplerPlan is generic over mapping.size() (bitmask usage, per-type bindings), so the 2→3 widening needs no other edits; ClassifySampler routes depth_compare images to Compare; ApplyResourceSpecialization types the variants (integer_border now Integer-only, depth_compare on Compare); the emitter lookup matches depth_compare; the post-hoc depth_compare |= in the pair loop only re-asserts the typed value. Test covers variant split, flag match per pair, and shared guest descriptor. All three platform builds green.
@Nawid3333 on GitHub · 2026-10-20 19:39 UTC · original
Tester confirmation on NVIDIA: @fabled-aesop ran ASTRO BOT (PPSA21564, 01.007.000) on an RTX 5080 (driver 610.88) with main
7b7f9a7+ #1528 + this PR and Vulkan validation on, and got no validation errors, no VUID-...-06479 (#1511). Before this PR the same pairing error was reported on NVIDIA in ASTRO BOT and Astro's Playroom (#1476).The device loss in that game is still there and is a separate problem: validation reports nothing before it (fabled-aesop suspects the BVH/RT compute shaders).
@coderabbitai[bot] on GitHub · 2026-10-28 18:39 UTC · original · reviewed
Actionable comments posted: 1
c3fcbae9-9840-42f0-8ed9-3defe227e34bReviewing files that changed from the base of the PR and between
bc553dca0eandeb3f34cd45.src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpptests/ResourceMaterializationTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
@ -1949,3 +1952,4 @@samplers[index].depth_compare = binding.type == SamplerClass::Compare;}for (uint32_t index = 0; index < sampler_plan.bindings.size(); index++) {const auto& binding = sampler_plan.bindings[index];@coderabbitai[bot] on GitHub · 2026-10-28 18:39 UTC · original · edited 2026-10-28 18:51 UTC
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 5352
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 21375
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 9136
Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4155
Propagate compare usage through nested sampler candidates.
When a compare sampler contains a deeper indirect sampler,
BuildSamplerPlanassignsCompareonly to the immediate candidate. This remap can then produceUINT32_MAXfor the deeper candidate. In non-final builds,EXIT_IFlogs a fatal error and exits the process with status 321. Propagate usage through the complete indirect-sampler chain before creating the mappings.Suggested fix
@ -1949,3 +1952,4 @@samplers[index].depth_compare = binding.type == SamplerClass::Compare;}for (uint32_t index = 0; index < sampler_plan.bindings.size(); index++) {const auto& binding = sampler_plan.bindings[index];@Nawid3333 on GitHub · 2026-10-28 18:51 UTC · original
The one-hop copy is main's
BuildSamplerPlan, which this PR doesn't touch:usage[candidate] |= usage[pair.sampler]moves the whole class bitset, so a sampler two hops away has had the same gap for the Integer class. This PR only adds the Compare class to that bitset.For the samplers
ApplyResourceSpecializationappends, the case can't happen: an appended sampler getsindirect_resources.clear(), and its root must be a base sampler (EXIT_IF(source.indirect_root >= base_sampler_count)). A deeper chain would need a base sampler's candidates to include a sampler that has candidates of its own. I haven't found a path that builds that, and no game log so far shows the emitter's "has no typed sampler variant" failure, so I'd rather not widenBuildSamplerPlanin this PR without a shader that needs it.@ -1949,3 +1952,4 @@samplers[index].depth_compare = binding.type == SamplerClass::Compare;}for (uint32_t index = 0; index < sampler_plan.bindings.size(); index++) {const auto& binding = sampler_plan.bindings[index];@coderabbitai[bot] on GitHub · 2026-10-28 18:52 UTC · original
@Nawid3333 You’re right. My finding assumed a reachable nested sampler chain without establishing how the code creates that chain.
The supplied code supports your explanation:
BuildSamplerPlancopies the whole usage bitset, not onlyCompare.ApplyResourceSpecializationclearsindirect_resourceson appended sampler candidates and requires their roots to be base samplers.A deeper chain would therefore need a base sampler candidate that has candidates of its own. I did not establish that construction path. The hypothetical failure is not enough to justify this Major finding against the PR.
I withdraw the finding. No recursive propagation change is required for this review comment.
✅ Review thread resolved.
You are interacting with an AI system.
@coderabbitai[bot] on GitHub · 2026-11-21 19:52 UTC · original · reviewed
2ad58b60-dc2a-4812-bbd0-4882fc7d9374Reviewing files that changed from the base of the PR and between
eb3f34cd45and040e658f0d.src/graphics/shader/recompiler/backend/spirv/spirvEmitterImage.cppsrc/graphics/shader/recompiler/ir/passes/ResourceMaterialization.cpptests/ResourceMaterializationTests.cppIncluded review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.