fix(agc): fall back to direct sampling when a multisampled depth-stencil shadow copy loses stencil #16908
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/16908"
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 akkadbakkad89 on 2026-11-07T21:33:07Z.
What
Refs #16883. On Intel's Windows driver, copying a multisampled depth-stencil image into the sample shadow with
vkCmdCopyImageloses the stencil plane: the leading bytes land and the rest of the plane stays at its old contents. Reproduced on UHD 630 (driver 1656924); the reporter hit the same on a second Intel driver.vkCmdBlitImagefails identically, and the stencil aspect is dropped even when the destination is a same-sample-countR8_UINTimage, so no transfer-path variant preserves it.The depth-surface constructor already queries whether the shadow layout and the directly-sampled attachment layout are each supported. When both are, and the format carries stencil, the surface now probes the mechanism it is about to rely on: it writes a per-16x16-tile stencil pattern (one
vkCmdClearAttachmentsrect per tile, inside a render pass) on a non-tile-aligned 129x67 multisampled attachment created with the same usage and create flags as the real images, issues the same image copy the shadow refresh uses, and reads the shadow's stencil plane back through the detiler's per-sample compute readback, comparing every element. If the plane didn't survive, the surface takes the direct path (sampled usage on the attachment) instead of the shadow. The result is cached per (format, sample count) inContext; when the detiler is unavailable the copy can't be verified, so the path that doesn't copy is preferred. A probe failure at any Vulkan call counts as a failed probe and takes the direct path, the known-good one.Direct sampling exposed a second Intel defect: a stencil-only
vkCmdClearDepthStencilImageon the now-sampled attachment freezes every subsequent render-pass depth write while stencil writes keep landing. Stencil-only clears on the direct path therefore run as a render pass whose stencil load op isCLEAR; all other clears keep the transfer path.Tested
Windows 11,
ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(loader confirms the layer).agc_driver_native_depth_stencil_view,agc_driver_native_depth_uniform_planes,agc_driver_native_depth_publicationfail onmainat the stencil mismatch; all three pass with this change (the fullnative_multisample_depthsuite goes 19/19).main.mainlogs 46xVUID-VkWriteDescriptorSet-descriptorType-04149+ 54xVUID-vkCmdDraw-None-09600; the change logs none. Intel:mainlogs 8x04149+ 12x09600before aborting at the failed assertion; the change logs 8xVUID-vkCmdDispatch-groupCountX-00386that only became reachable once the test no longer aborts - it comes from the test's ownFetch::Runhelper (tests/execution/NativeMultisampleDepth.cpp:523) dispatching ~69144 workgroups past Intel's 65536maxComputeWorkGroupCount[0], a latent test-side defect outside this change's code.Adjacent work: #15750 fixes the same-shaped copy failure on RADV GFX6-8 by giving the shadow attachment usage; adding that usage was verified not to help on Intel (the copy still drops stencil), which is why this probes behavior rather than tweaking usage. The two changes touch neighboring code but no overlapping lines (
tools/pr_overlap.pyclean).Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T23:02:16Z.
Review: COMMENTED
Intel cell for #16883, which I opened. Head
9ba3aec69amerged ontomain302864d48c(clean), Windows 11 x64, WinLibs GCC 15.2.0 r7, Release,ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1, 3 runs per GPU,agc_driver_native_depth_*.mainstencil_viewuniform_planespublicationSo two of the three tests from #16883 are fixed here, but
publicationstill fails. Forcing direct sampling for every D32S8 MSAA view (the experiment in #16883) makes all three pass on the same driver, so the fallback itself is right and it's the probe's verdict that doesn't cover the publication case. The probe size isn't the cause, since growing the extent to 64x64 changes nothing.The probe only checks a uniform stencil.
ProbeStencilShadowCopy(DepthSurface.cpp:551-630) fills the source with0xa5everywhere and checks that every sample reads back0xa5. A driver that loses or mixes per-sample stencil can still return the same uniform value.publicationwrites live, distinct samples. (Inference: I haven't instrumented which(format, samples)it probes; the passing direct-sampling run is what points here.) Writing a value that depends on the pixel and sample index, and comparing per element, would make the probe test what the views need.catch (...) { works = true; }(line 625-626). If any step of the probe throws, the result is cached as "shadow copy works", i.e. the path #16883 shows is broken on this driver, and the exception is gone. Returningfalsethere falls back to direct sampling, which is the path that is known to give the right stencil, or letting it propagate keeps the error visible.No validation layer on this machine.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-11-11T21:06:09Z.
Review: CHANGES_REQUESTED
Thanks for the fast turnaround on the probe usage/extent. Remaining points on
ed6fffcd93:DepthSurface.cpp:711/:742: the probe clears the whole plane to one value (0xa5) and checks every sample equals it. A driver that drops or mixes per-sample or per-pixel stencil can still return a uniform plane, and #16883's reports (jeej1k, gabichuuuuu) showagc_driver_native_depth_publicationstill failing on UHD 770 with this probe. Please fill the source with a value that depends on the pixel and sample (e.g. a render pass or per-aspect write that gives distinct bytes, or several scissored clears) and compare per element, so the probe tests what the views need.DepthSurface.cpp:743-745:catch (...) { works = true; }turns any probe failure into "the shadow copy works", which is the path that loses stencil on Intel, and drops the exception. Returnfalse(direct sampling, known-good) or let it propagate; if you keeptruedeliberately, narrow it to the specific Vulkan call you mean to tolerate.Fixes #16883, but UHD 770publicationwas not re-measured on this head. Either get a UHD 770 run (@jeej1k offered one) showing it passes, or change it toRefs #16883, as @oneandonlydean asked.The rest (barriers, usage/flags matching
sampleShadowUsage(), render-pass stencil clear and its teardown, debt entry) reads fine.