renderer: drop compare state when a compare sampler is paired with a colour view #1625
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!1625
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1625"
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?
@ricardocacco on GitHub · 2026-10-17 22:39 UTC · original
ricardocacco:guard-compare-sampler→main· +37 −3 · 1 files · 2 commits · openWhat happens
On Astro Bot (PPSA21567) the recompiler emits a compute shader whose descriptor set pairs a depth-comparison sampler with a colour image view (
VK_FORMAT_R32_SFLOAT). The validation layer reports, atvkCmdDispatch:which is precisely that rule: a comparison sampler may only be combined with a depth/stencil image view. The sample itself is undefined either way, but on this machine the illegal combination ends in an NVIDIA device lost (
nvlddmkmEvent ID 153, "Error occurred on GPUID: 100", same second) and the renderer surfaces it asi.e.
EXIT_NOT_IMPLEMENTED(result != vk::Result::eSuccess)afterdevice.waitSemaphores(&wait_info, UINT64_MAX)stops returningeSuccess. Nothing in that message names the binding, which is what makes the failure expensive to diagnose.What this patch does
ShaderInfo::sampled_pairsalready carries the exact image/sampler pairing for each compiled program.RenderExecutor::PrepareBindingsnow walks that list: if a sampler withdepth_compare == trueis paired with a bound image whoseinfo.IsDepth()is false, it clears the compare-enable bit (fields[0] &= ~(0x7u << 12u), the same mask the non-compare path already clears) and logs the shader hash and stage.No defined information is lost — the descriptor was already illegal and the sampled value undefined. What changes is that the failure becomes a named log line instead of a GPU hang.
Caveats
depth_comparecomes fromImageSampleFlagCompareinResourceTracking::AddImage(), while the paired sampler'sDepthCompareFunc() != 0); I have not root-caused that.clang-cl 23.1.3(MSVC 19.44 headers) run against the exact command line CMake generates for this translation unit (-std:c++20 /W3,-O2, same includes/macros): zero errors, zero warnings, both before and after the change. The full link was not exercised here. CI for this PR is currentlyaction_required(first-time contributor, needs a maintainer to approve the run), so the build matrix is still the authority.EXITon the mismatch may be the better behaviour for a debug build; I opted not to abort on a case that today "only" hangs the GPU. Happy to switch if you prefer.FindImage/exact_formataliasing floated in #1476 does not apply:Bit32 & D32 != D32andSameBacking()also checkstile_mode, andFindGuestDepthFormatPolicy(k32Float)exists, so the depth-format table is not the gap.Context
Environment of the capture: Windows 11, RTX 5060 Ti 16 GB, NVIDIA 617.42, Vulkan SDK 1.4.363 validation layers, build
bd8f0da.@coderabbitai[bot] on GitHub · 2026-10-17 22:53 UTC · original · edited 2026-10-17 23:25 UTC
📝 Walkthrough
PrepareBindingschecks sampled image and sampler pairs that use depth comparison. If a paired image is not a depth image, it disables comparison for that sampler and logs the shader hash and stage when a mismatch occurs.NativeSamplernow accepts this per-sampler permission and clears compare state when comparison is not allowed.Suggested reviewers:
nmzikPriority: ➖ Normal
Change: Bug fix
Merge Risk: 🔵 Low · up to
70ae8The guard avoids the invalid compare-sampler and colour-view pairing in the common case. In rare cases a rebound image could still change type after the check, so the validation error could recur. Consider recomputing eligibility after rebinding.
Pre-merge checks:
4 ·
1
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
Comment
@coderabbitai helpto get the list of available commands.@coderabbitai[bot] on GitHub · 2026-10-17 22:53 UTC · original · edited 2026-10-17 23:21 UTC
On
src/graphics/host_gpu/renderer/pipeline/descriptors.cppline 727 (outdated):🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 1090
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 42191
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 13055
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 7489
Guard against a null
bound.image_idbeforeGetImage.ResolveTexturereturns a binding without animage_idfor a null descriptor. The new loop passes that ID toTextureCache::GetImage.SlotVector::operator[]rejects the invalid ID withEXIT_IF(!is_allocated(id)). A compare sampler paired with a null image can therefore terminate binding preparation.Proposed fix
📝 Committable suggestion
✅ Addressed in commit
70ae891@coderabbitai[bot] on GitHub · 2026-10-17 22:54 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
4d0fe02a-605f-479d-8c37-613f078abd14📥 Commits
Reviewing files that changed from the base of the PR and between
763d3be3a9andba536173c0.📒 Files selected for processing: 1
src/graphics/host_gpu/renderer/pipeline/descriptors.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 7 remain after this review.
@ricardocacco on GitHub · 2026-10-17 23:21 UTC · original
Pushed
70ae891: the depth check indexed the texture cache with the prepared binding id, which is INVALID for a null descriptor and stale once the image is retired. TextureCache::GetImage asserts on both and aborts with slotVector.h:41; the guard now uses m_slot_images.try_get and leaves the sampler alone for those bindings.Found by running ASTRO BOT (PPSA21567) locally with this patch on top of the #1528 SRT fix: without it the emulator dies with was !is_allocated(id), with it the game gets past asset loading and pipeline creation and the next fatal is a GPU device loss, which this patch does not cover.
@ -712,0 +727,4 @@// Null and already-retired bindings have no image to inspect; the descriptor path// reports those on its own, so leave the sampler untouched here.const auto* image =m_context.GetTextureCache().m_slot_images.try_get(bound.image_id);@coderabbitai[bot] on GitHub · 2026-10-17 23:25 UTC · original
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
🔎 Supported by static analysis
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 15703
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19842
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 18162
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 19332
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 14682
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 6252
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2807
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 2505
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 8947
🏁 Script executed:
Repository: KytyPS5/KytyPS5
Length of output: 4254
Recompute compare eligibility after
RebindImages.When
RebindImagesreplaces a paired image, recomputesampler_compare_okbefore creating or committing the sampler. A non-depth request can initially resolve to a cached depth image, then resolve to a color image after the cached image is retired.CommitBindingsuses the rebound image view with the sampler created earlier, which can recreate the Vulkan validation error.@coderabbitai[bot] on GitHub · 2026-10-17 23:25 UTC · original · reviewed
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
8568777f-635a-4373-970c-5fb3211ddf5d📥 Commits
Reviewing files that changed from the base of the PR and between
ba536173c0and70ae891d26.📒 Files selected for processing: 1
src/graphics/host_gpu/renderer/pipeline/descriptors.cppIncluded review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 6 remain after this review.
@Nawid3333 on GitHub · 2026-10-19 17:16 UTC · original
@ricardocacco I traced the shared-sampler case behind the guard in this PR. Here is the root cause and a tested fix.
Root cause.
AddSamplerreturns an existing entry whenm_info.samplers[i].source == source(ResourceTracking.cpp:3827-3833), so compare state is not part of the key. Image entries do includedepth_comparein their key (ResourceTracking.cpp:3793). A guest sampler can be used by both of these:IMAGE_SAMPLE_C, whose image gets a D32 view (descriptors.cpp:553-556);IMAGE_SAMPLEof a k32Float texture (R32_SFLOAT view).ResourceMaterialization.cpp:1853 then merges the two uses:
The result is one sampler with compare enabled for both pairs. descriptors.cpp:640-641 clears S# bits 14:12 (the RDNA2 compare func) only when
depth_compareis false. For the plain sample, Vulkan Texel Input Operations makes the texel poison: "The SPIR-V instruction is not one of the OpImage*Dref* instructions and the sampler compareEnable is VK_TRUE". #1476 has two NVIDIA logs showing an R32_SFLOAT view without SAMPLED_IMAGE_DEPTH_COMPARISON:The guard in #1625. It sets
sampler_compare_ok[pair.sampler] = falsefor every sampler paired with a non-depth image. With the shared entry, that also turns compare off for the Dref shadow lookup. That hits the other poison case: "The SPIR-V instruction is one of the OpImage*Dref* instructions and the sampler compareEnable is VK_FALSE".Fix. Branch
shader/sampler-compare-variants(commitbc553dcaon top of current upstream main0cad4672, +39/-4: https://github.com/Nawid3333/KytyPS5/commits/shader/sampler-compare-variants):SamplerClassgainsCompare, andClassifySamplerreturns it for depth-compare images.depth_comparecomes from its class.integer_bordernow tests== Integer.depth_compare.Tests. New test
TestCompareSamplerUsesOwnVariant(ResourceMaterializationTests) has sampler 1 shared by a compare image and a plain k32Float image. It expects 3 sampler entries, 2 runtime descriptors, and each pair's sampler compare equal to its image's compare. It fails on main ("shared compare sampler did not get its own variant") and passes with the fix.resource_tracking_testspass.GPU results. I ran on GPU 0 and GPU 1, with native and 32-wide host subgroups. ComparisonDepthTexture, ImageSampleA16CompareBiasRdna2AddressOrder and ImageGatherCompareOpcodes pass with the fix, with 0 validation messages. They also pass on main, so they do not reproduce the bug and only show no regression. The full suite (811 entries per compute config, 30 graphics entries per GPU) shows no differences between fix and main.
Next step, your call:
shader/sampler-compare-variantsthat references #1625.Written with Claude Code (AI): it traced the code and wrote the fix and test; I reviewed and ran them.
@ricardocacco on GitHub · 2026-10-19 19:50 UTC · original
Thanks @Nawid3333 — going with your offer, so please open the PR against
KytyPS5/KytyPS5fromshader/sampler-compare-variants(bc553dca) and reference this one (#1625). Authorship stays entirely with you; no co-author credit needed.A few notes:
main(0cad4672):AddSamplerdedups only bysource, while image entries carrydepth_comparein their key. So one guest sampler really can be paired with both a depth-compare view and a non-depth one, and a per-sampler boolean cannot represent that. The variant approach is the right shape, and this guard here only fixes one direction of the mismatch — it can leave the Dref side withcompareEnable=false, which is exactly the opposite VUID.action_required, first-time contributor), so your PR is the better vehicle for the fix regardless.On verification: locally I never reproduced the VUID on either side — with the guard applied the check never fired and Khronos validation stayed silent up to the unrelated device-lost that ends those runs, so your GPU results are the validation here, not mine. If you keep the new test (
TestCompareSamplerUsesOwnVariant) in the PR that is the piece that makes the change reviewable on its own.@Nawid3333 on GitHub · 2026-10-19 20:04 UTC · original
@ricardocacco opened as #1733 (branch shader/sampler-compare-variants,
bc553dca), referencing this PR. Thanks again for the analysis that pointed at the sampler/image mismatch.@Nawid3333 on GitHub · 2026-11-21 20:07 UTC · original
@ricardocacco #1733 is now one commit on current main (
040e658f0): its test still fails on main39936ffa3(shared compare sampler did not get its own variant) and passes with the change. If you still see it as covering this one, could you close #1625 as superseded, as planned? While both are open, CodeRabbit lists this PR's guard as an open requirement of #1733.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.