fix(agc): fall back to direct sampling when a multisampled depth-stencil shadow copy loses stencil #16908

Merged
akkadbakkad89 merged 5 commits from upstream-pr/16908 into main 2026-11-15 19:52:01 +00:00
akkadbakkad89 commented 2026-11-07 21:33:07 +00:00 (Migrated from github.com)

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 vkCmdCopyImage loses 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. vkCmdBlitImage fails identically, and the stencil aspect is dropped even when the destination is a same-sample-count R8_UINT image, 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 vkCmdClearAttachments rect 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) in Context; 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 vkCmdClearDepthStencilImage on 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 is CLEAR; 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).

  • Intel UHD 630, driver 1656924: agc_driver_native_depth_stencil_view, agc_driver_native_depth_uniform_planes, agc_driver_native_depth_publication fail on main at the stencil mismatch; all three pass with this change (the full native_multisample_depth suite goes 19/19).
  • NVIDIA RTX 3070, driver 617.42: all three pass; the probe verifies the copy and the shadow path is retained, unchanged from main.
  • Validation ledger, NVIDIA: main logs 46x VUID-VkWriteDescriptorSet-descriptorType-04149 + 54x VUID-vkCmdDraw-None-09600; the change logs none. Intel: main logs 8x 04149 + 12x 09600 before aborting at the failed assertion; the change logs 8x VUID-vkCmdDispatch-groupCountX-00386 that only became reachable once the test no longer aborts - it comes from the test's own Fetch::Run helper (tests/execution/NativeMultisampleDepth.cpp:523) dispatching ~69144 workgroups past Intel's 65536 maxComputeWorkGroupCount[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.py clean).

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Fixes: Refs #16883
  • Unblocks: none
  • GPUs tested: Intel UHD 630 (driver 1656924, Windows 11); NVIDIA RTX 3070 (driver 617.42, Windows 11)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5206027791 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16908). Originally posted by [akkadbakkad89](https://github.com/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 `vkCmdCopyImage` loses 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. `vkCmdBlitImage` fails identically, and the stencil aspect is dropped even when the destination is a same-sample-count `R8_UINT` image, 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 `vkCmdClearAttachments` rect 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) in `Context`; 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 `vkCmdClearDepthStencilImage` on 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 is `CLEAR`; 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). - Intel UHD 630, driver 1656924: `agc_driver_native_depth_stencil_view`, `agc_driver_native_depth_uniform_planes`, `agc_driver_native_depth_publication` fail on `main` at the stencil mismatch; all three pass with this change (the full `native_multisample_depth` suite goes 19/19). - NVIDIA RTX 3070, driver 617.42: all three pass; the probe verifies the copy and the shadow path is retained, unchanged from `main`. - Validation ledger, NVIDIA: `main` logs 46x `VUID-VkWriteDescriptorSet-descriptorType-04149` + 54x `VUID-vkCmdDraw-None-09600`; the change logs none. Intel: `main` logs 8x `04149` + 12x `09600` before aborting at the failed assertion; the change logs 8x `VUID-vkCmdDispatch-groupCountX-00386` that only became reachable once the test no longer aborts - it comes from the test's own `Fetch::Run` helper (`tests/execution/NativeMultisampleDepth.cpp:523`) dispatching ~69144 workgroups past Intel's 65536 `maxComputeWorkGroupCount[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.py` clean). ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Fixes: Refs #16883 - [x] Unblocks: none - [x] GPUs tested: Intel UHD 630 (driver 1656924, Windows 11); NVIDIA RTX 3070 (driver 617.42, Windows 11) - [x] AI-assisted: yes
gabichuuuuu commented 2026-11-07 23:02:16 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-07T23:02:16Z.

Review: COMMENTED


Intel cell for #16883, which I opened. Head 9ba3aec69a merged onto main 302864d48c (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_*.

main this PR this PR, probe extent 64x64
Intel iGPU, driver 101.70xx: stencil_view fail pass 3/3 pass 3/3
Intel: uniform_planes fail pass 3/3 pass 3/3
Intel: publication fail fail 3/3 ("publication lost live samples, HTILE, padding or guest writes") fail 3/3
NVIDIA laptop GPU (Turing), driver 610 pass pass 3/3 pass

So two of the three tests from #16883 are fixed here, but publication still 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 with 0xa5 everywhere and checks that every sample reads back 0xa5. A driver that loses or mixes per-sample stencil can still return the same uniform value. publication writes 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. Returning false there 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.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5815473236 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16908#pullrequestreview-5815473236). Originally posted by [gabichuuuuu](https://github.com/gabichuuuuu) on 2026-11-07T23:02:16Z. **Review:** COMMENTED --- Intel cell for #16883, which I opened. Head `9ba3aec69a` merged onto `main` `302864d48c` (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_*`. | | `main` | this PR | this PR, probe extent 64x64 | |---|---|---|---| | Intel iGPU, driver 101.70xx: `stencil_view` | fail | pass 3/3 | pass 3/3 | | Intel: `uniform_planes` | fail | pass 3/3 | pass 3/3 | | Intel: `publication` | fail | **fail 3/3** ("publication lost live samples, HTILE, padding or guest writes") | **fail 3/3** | | NVIDIA laptop GPU (Turing), driver 610 | pass | pass 3/3 | pass | So two of the three tests from #16883 are fixed here, but `publication` still 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 with `0xa5` everywhere and checks that every sample reads back `0xa5`. A driver that loses or mixes per-sample stencil can still return the same uniform value. `publication` writes 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. Returning `false` there 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.
adriadam10 commented 2026-11-11 21:06:09 +00:00 (Migrated from github.com)

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) show agc_driver_native_depth_publication still 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. Return false (direct sampling, known-good) or let it propagate; if you keep true deliberately, narrow it to the specific Vulkan call you mean to tolerate.
  • The description says Fixes #16883, but UHD 770 publication was not re-measured on this head. Either get a UHD 770 run (@jeej1k offered one) showing it passes, or change it to Refs #16883, as @oneandonlydean asked.

The rest (barriers, usage/flags matching sampleShadowUsage(), render-pass stencil clear and its teardown, debt entry) reads fine.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5865301798 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16908#pullrequestreview-5865301798). Originally posted by [adriadam10](https://github.com/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) show `agc_driver_native_depth_publication` still 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. Return `false` (direct sampling, known-good) or let it propagate; if you keep `true` deliberately, narrow it to the specific Vulkan call you mean to tolerate. - The description says `Fixes #16883`, but UHD 770 `publication` was not re-measured on this head. Either get a UHD 770 run (@jeej1k offered one) showing it passes, or change it to `Refs #16883`, as @oneandonlydean asked. The rest (barriers, usage/flags matching `sampleShadowUsage()`, render-pass stencil clear and its teardown, debt entry) reads fine.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!16908
No description provided.