Skip to content

fix(agc): assemble layered stencil plane views through DepthPlaneCopy - #26579

Merged
oneandonlydean merged 1 commit into
boykopovar:mainfrom
birdmarty:fix/agc-layered-stencil-plane-sampling
Nov 24, 2026
Merged

oneandonlydean merged 1 commit into
boykopovar:mainfrom
birdmarty:fix/agc-layered-stencil-plane-sampling

Conversation

@birdmarty

Copy link
Copy Markdown
Contributor

What

DepthSurfaceTexture previously forced every stencil view through DepthSurface::Sampled (sampled = !cropped && (stencil || (!layered && !integer))), which accepts only a single slice (depthOrLastArray == 0). Multi-slice k2DArray or kCube views over a resident depth surface's stencil plane threw sampling the stencil plane of depth surface ... is not implemented, even though multi-slice depth-plane views already assemble their slices through DepthPlaneCopy.

This change routes layered (k2DArray with depthOrLastArray != 0, or kCube) single-sample R8_UINT and R8_UNORM stencil views through DepthPlaneCopy, copying each resident slice from VK_IMAGE_ASPECT_STENCIL_BIT and detiling any non-resident slice from guest memory into a 4-byte-aligned staging stride. Single-slice stencil views stay on DepthSurface::Sampled (no extra copy for R8_UINT), and unsupported 1-byte formats (such as R8_SINT), multi-mip views, out-of-range baseArray values, and multisampled arrays still throw.

Changes

  • core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp:
    • Route stencil && layered single-sample views to DepthPlaneCopy (sampled = !cropped && !layered && (stencil || !integer)), accepting VK_FORMAT_R8_UINT and VK_FORMAT_R8_UNORM and keeping HasStencil(found->hostFormat) as the host-format check for stencil planes.
    • Extend DepthPlaneCopy for 1-byte stencil formats (VK_FORMAT_R8_UINT, VK_FORMAT_R8_UNORM): texelBytes(), sourceAspect() (VK_IMAGE_ASPECT_STENCIL_BIT), aspect() (VK_IMAGE_ASPECT_COLOR_BIT), 4-byte-aligned stagingLayerStride (for VUID-VkBufferImageCopy-bufferOffset-09101 and 4-byte detiler range alignment), {.pipeBankXor = resource.pipeBankXor} on TextureDetiler::Dispatch, and pipeBankXor in GuestLayer's cache key.
    • Add stencilSlice(device, address, base) via planeSurface(device, address) matching only active, non-retired 1-sample stencil-bearing owners of the same extent (never resurrecting a displaced older surface), call SyncStencilFromMemory and ApplyFastClear per matched slice, and key planeCopies() by base.stencilAddress for stencil views.
  • core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneSampling.cpp: add StencilArrayCase (3-slice 160x90 R8_UINT 2D array mixing 2 resident drawn stencil slices and 1 guest-memory tiled slice, baseArray = 1, redraw refresh, 2D shader image view, and displacement by a newer different-extent owner), StencilCubeCase (6-face 128x128 R8_UINT cube), StencilUnormArrayCase (2-slice 128x128 R8_UNORM 2D array), and refusal checks (R8_SINT, baseArray > lastArray).
  • core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp: verify a 2-slice R8_UINT 2D array over a D16_UNORM_S8_UINT surface stored as D24_UNORM_S8_UINT copies VK_IMAGE_ASPECT_STENCIL_BIT into an R8_UINT VK_IMAGE_ASPECT_COLOR_BIT array image, and does not reuse a displaced older slice.
  • docs/dev/debt/changes/fix-agc-layered-stencil-plane-sampling.md: document layered stencil plane sampling scope and remaining gaps.

Tested

Windows 11 Pro (build 26300), Intel Core i9-9900K, AMD Radeon RX 6800 (AMD driver 26.10.1, Windows driver 32.0.21045.16010, Vulkan 1.4.315), MinGW-w64 GCC 15.3.0, Release, main 441fa65119.

Focused set (agc_driver_graphics, agc_driver_depth_plane_sampling, agc_driver_depth_plane_sampling_evicting, agc_driver_depth_plane_guest_layers, agc_driver_stencil_plane_memory, agc_driver_stencil_copy_draw, agc_driver_depth_copy_draw, agc_driver_depth_plane_fill, agc_driver_depth_plane_buffer_memory, agc_driver_depth_surface_last_writer) with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (1.4.363.0) and VK_LOADER_DEBUG=layer:

main 441fa65119 this change
Passed / failed 10 / 0 10 / 0
Validation layer inserted 11 11
VUID- lines 0 0

Without the fix (origin/main's DepthSurface.cpp with this branch's tests), both agc_driver_depth_plane_sampling and agc_driver_graphics fail with AGC graphics: sampling the stencil plane of depth surface ... as a ... texture of guest format 5 (vk 13), tile mode 4, dimension 2, levels 0-0, slice 0 is not implemented.

Kingdom Come: Deliverance II (PPSA21704, 01.052.000):

  • What the game does: renders 32 active 1-sample 160x90 D32_SFLOAT_S8_UINT depth/stencil slices spaced 0x10000 bytes apart (0x23c20f0000..0x23c22e0000, kZ64KBX, pipeBankXor = 0) and samples them in a compute shader as a 32-slice k2DArray of R8_UINT (guest format 5).
  • Without this change: on main e60b2f74ad + PR fix(agc): accept PA_CL_CLIP_CNTL UCP_CULL_ONLY_ENA without active clip planes #26578 (fix/agc-ucp-cull-only-without-clip-planes), aborts at ~178–229 s entering the outdoor Siege of Suchdol transition with sampling the stencil plane of depth surface 0x23c22f0000 (160x90, vk format 130) as a 160x90 texture of guest format 5 (vk 13), tile mode 4, dimension 2, levels 0-0, slice 0 is not implemented (reproduced twice).
  • With this change: on main e60b2f74ad + PR fix(agc): accept PA_CL_CLIP_CNTL UCP_CULL_ONLY_ENA without active clip planes #26578 + this change (no diagnostics), passes the stop cleanly across 4 consecutive runs: renders the outdoor Siege of Suchdol battlements and valley (~20–26 FPS), completes the post-cutscene loading screen (~47–59 FPS), and enters live first-person 3D gameplay ("Main quest started: Last Rites", aiming crossbow, walking up the ramparts stairs, game saving) with 0 visual glitches and 0 driver errors.

py -3 tools/check_conventions.py --base origin/main and py -3 tools/debt_fold.py --check pass. py -3 tools/pr_overlap.py --branch fix/agc-layered-stencil-plane-sampling (2,594 open PRs): all 9 line-adjacent PRs (#10894, #18185, #19697, #20041, #22531, #22778, #24083, #24327, #25610) and 19 conflicting PRs (#1368, #1395, #6808, #7256, #7642, #9508, #9895, #9950, #10193, #11444, #11551, #13863, #13920, #13928, #13929, #15621, #20315, #22062, #22647) were checked manually; none implements layered stencil plane sampling (#1368 is stale/conflicting from Oct 2026 before DepthPlaneCopy).

Not tested: multi-mip layered stencil views, multisampled stencil arrays, console hardware, other GPUs, Linux.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • 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: none
  • Unblocks: PPSA21704 Kingdom Come: Deliverance II (PPSA21704) #26577
  • GPUs tested: AMD Radeon RX 6800 (vendor=0x1002, device=0x73bf), AMD proprietary driver 26.10.1 (Windows driver 32.0.21045.16010, Vulkan 1.4.315), Windows 11 Pro (build 26300); Khronos validation layer 1.4.363.0 on main and this change, 0 VUIDs
  • AI-assisted: yes (Antigravity)

@github-actions github-actions Bot added unblocks title Names a title ID on the Unblocks line docs agc libSceAgc* labels Nov 24, 2026
@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
PR 18185 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L2701, L2730-2731, L2771-2772, L2793-2795, L4832, L4843-4847
core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp L86, L220
PR 19557 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L3102
PR 19697 core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneSampling.cpp L77, L180, L221-224
PR 20041 core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneSampling.cpp L77, L180, L227-228
PR 22531 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L2701
core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneSampling.cpp L77
PR 22778 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L4842-4847, L4849-4852
PR 24083 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp L2793, L4831-4832, L4843-4847
PR 24327 core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp L376-378
PR 25610 core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneSampling.cpp L31, L77, L180, L224-228

Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.

Pull request Shared files not compared
PR 1368 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/DepthSurfaceReuse.cpp
PR 1395 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 6808 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7256 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 7642 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 9508 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 9895 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 9950 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10193 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10492 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10497 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 10894 core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneSampling.cpp
PR 11444 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 11551 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 13863 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 13920 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 13928 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 13929 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 15621 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
core/libs/prx/libSceAgcDriver/tests/execution/DepthPlaneSampling.cpp
PR 20315 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 22062 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 22306 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp
PR 22647 core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp

@cozejarr

Copy link
Copy Markdown
Contributor

NVIDIA test run of the focused set in the description, for a second vendor next to the RX 6800 results.

  • GPU: NVIDIA GeForce RTX 4070, driver 610.88, Windows 11 Pro 26300, WinLibs GCC 15.2 (Release)
  • Khronos validation layer 1.4.335 (built from vulkan-sdk-1.4.335.0), ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer
  • main at 9126826, and this branch at 3ac03c6 merged onto it (92cca7ed7d), in the same build tree with the test targets rebuilt for each side
  • ctest --test-dir build -V -R '^(agc_driver_graphics|agc_driver_depth_plane_sampling|agc_driver_depth_plane_sampling_evicting|agc_driver_depth_plane_guest_layers|agc_driver_stencil_plane_memory|agc_driver_stencil_copy_draw|agc_driver_depth_copy_draw|agc_driver_depth_plane_fill|agc_driver_depth_plane_buffer_memory|agc_driver_depth_surface_last_writer)$'
main this PR
passed 10 of 10 10 of 10
Insert instance layer "VK_LAYER_KHRONOS_validation" 11 11
was not found but was requested 0 0
VUID- 0 0

agc_driver_graphics logs no loader lines and no Selected GPU line on either side. The 11 inserts come from the other nine tests, the same count as in the description.

Control: the merge with main's DepthSurface.cpp and this branch's tests fails agc_driver_depth_plane_sampling, agc_driver_depth_plane_sampling_evicting and agc_driver_graphics with the error in the description, for example sampling the stencil plane of depth surface 0x200720000 (160x90, vk format 130) as a 160x90 texture of guest format 5 (vk 13), tile mode 4, dimension 2, levels 0-0, slice 0 is not implemented. So the new cases catch the missing path on NVIDIA as well. The control run also had no VUID- lines.

AI-assisted: yes. Claude Code ran these tests on this machine and wrote this report from the logs.

@zedekvdb

Copy link
Copy Markdown
Contributor

Pascal run on Windows, next to the RX 6800 and RTX 4070 results: this PR's test changes fail on main's driver and pass with this head.

Setup: Windows 11 Pro 10.0.26300, NVIDIA Quadro P3200 (Pascal, 10de:1bbb), driver 582.42, Vulkan API 1.4.312, WinLibs GCC 15.2.0 r7, Release, main c55872d43f. VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation VK_LOADER_DEBUG=layer ANYPS5_NO_SHADER_CACHE=1 ANYPS5_REQUIRE_VULKAN=1 ANYPS5_GPU="Quadro P3200", ctest -j 1 -V, 2 runs per side. Every Vulkan test selects the Quadro P3200 with the layer inserted; there are no VUID- messages.

agc_driver_depth_plane_sampling agc_driver_depth_plane_sampling_evicting, agc_driver_graphics
main 2 of 2
This PR's test changes on main's driver fails
This head (3ac03c6d52) passes 2 of 2 2 of 2

The failure on main:

AGC graphics: sampling the stencil plane of depth surface 0x200720000 (160x90, vk format 130) as a 160x90 texture of guest format 5 (vk 13), tile mode 4, dimension 2, levels 0-0, slice 0 is not implemented

AI-assisted: yes (Claude Code)

@mihiii1337

mihiii1337 commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Intel Windows A/B on exact head 3ac03c6d52fddaf02d9ce971de9148da471723e4, cleanly merged into the then-current main e5de756897f197c5875cc363977d5f9e022aeb68.

Both arms used the identical DepthPlaneSampling.cpp blob 27f8ec98a183f90dded46b79d2592acad0c86e47 on the physical Intel Raptor Lake-S Mobile graphics adapter (8086:a78b, Windows driver 32.0.101.6127, Vulkan 1.3.295, subgroup 32):

CTest main plus fixture this PR
agc_driver_depth_plane_sampling 0/3 3/3
agc_driver_depth_plane_sampling_evicting (APS5_DEPTH_PLANE_COPY_MIB=1) 0/3 3/3

Every base run stopped on the first 160x90 layered R8_UINT stencil view with the expected sampling the stencil plane ... is not implemented refusal. A separate print-only run on the patched build read 0x5a/0xa5/0x3c from the three array slices, preserved 0xa5/0x3c after redrawing slice 0 to 0x7e, read all six cube values, and produced 0.50196081/1.0 for the two R8_UNORM checks. The 1 MiB run retained four cached copies, within the fixture's expected range of one to seven.

The Intel ICD was pinned and selected the A78B adapter in all twelve unchanged test runs. Vulkan was required, shader caching was disabled, and Khronos Validation 1.4.369 was inserted once per run with zero VUID, synchronization-hazard, or missing-layer messages. The fixture's pre-existing guest write-watch subcase reported no write watch and skipped internally on this host; the new layered-stencil assertions ran. Not tested on a PS5.

AI-assisted: yes.

@oneandonlydean
oneandonlydean merged commit 37145e1 into boykopovar:main Nov 24, 2026
14 checks passed
@upipibi

upipibi commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

RTX 3070 run of 3ac03c6d52, merged with --no-ff onto main 5e9ad5f57b, against main alone.

Tested

  • NVIDIA GeForce RTX 3070 (driver 616.56, subgroup 32), Windows 11 Pro 26100, WinLibs GCC 15.2.0, Ninja, Release; ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation.
  • ctest -R "^agc_driver_(depth_plane_sampling(_evicting)?|graphics)$", 3 runs each:
    • main: 3/3 passed in all 3 runs.
    • this PR: 3/3 passed in all 3 runs.
  • Validation layer inserted in every Vulkan test (2 per run on the PR side), 0 VUID- messages. Build: 0 failed targets.

Not tested: AMD, titles.

AI-assisted (Claude Code).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

agc libSceAgc* docs unblocks title Names a title ID on the Unblocks line

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants