fix(agc): load depth planes through a copy image on AMD integrated GPUs #15015

Merged
sharveshprabhu merged 1 commit from upstream-pr/15015 into main 2026-11-15 19:13:13 +00:00
sharveshprabhu commented 2026-11-02 10:14:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by sharveshprabhu on 2026-11-02T10:14:03Z.


What

On AMD's proprietary Windows driver, a vkCmdCopyBufferToImage into a depth image that was drawn, in VK_IMAGE_LAYOUT_GENERAL, leaves some 8x8 tiles that the next depth test treats as holding the depth drawn before the copy, although the copied values read back correctly. This is what fails agc_driver_depth_plane_partial_store_buffer_copy on a Radeon 780M (#13867).

On integrated GPUs with that driver (VK_DRIVER_ID_AMD_PROPRIETARY and VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU), copyPlane's buffer path now copies the staging buffer into a transfer-only image of the depth format (TRANSFER_DST_OPTIMAL, then TRANSFER_SRC_OPTIMAL) and from it into the depth plane with vkCmdCopyImage, with the same regions. The image is created once per depth surface, kept by the recorder while a copy uses it, and released with the surface. Copies into colour storage images and stencil planes are unchanged.

  • APS5_NO_DEPTH_UPLOAD_IMAGE=1 keeps the direct buffer copy (row added to docs/dev/ENVIRONMENT.md).
  • SetDepthUploadImage(true) forces the path on any device; DepthUploadCount() counts its loads.
  • New test agc_driver_depth_plane_partial_store_upload_image runs the partial store test through the path on every device, so lavapipe exercises it too. The test now requires uploads when the path is forced.

A standalone Vulkan program (no AnyPS5 code) that draws a 384x200 D32_SFLOAT image at 0.5, copies 0.75 into x 128-255, y 128-199 with vkCmdCopyBufferToImage in GENERAL, then draws at 0.6 with LESS, reproduces it; the validation layer with synchronization validation reports nothing for it:

Standalone program, 200 iterations Radeon 780M RTX 5060
buffer -> depth image 27 failed 0 failed
buffer -> R32_SFLOAT image -> buffer -> depth image (AnyPS5's sequence) 37 failed 0 failed
buffer -> transfer-only depth image -> vkCmdCopyImage 0 failed 0 failed

Each failure is 64 or 128 texels short inside the block and none outside. The program's source can be attached.

Discrete cards don't show it: an RX 9070 XT (RDNA 4, also 32.0.32015.7029) passes the AnyPS5 test and the standalone program at 1000 iterations, and an RX 6700 XT (RDNA 2) passes the AnyPS5 test. So the path is limited to integrated GPUs; if a discrete AMD card shows the stale tiles, the device-type check can be dropped. A Radeon 860M (RDNA 3.5) passes without the path on Adrenalin 26.10.2 (32.0.32015.12012) and with it, while the 780M still fails on that driver, so a driver version check would not separate them; both report Vulkan driverVersion 0x8001a0.

Tested

Windows 11 Home 10.0.26300, AMD Ryzen 7 260 with Radeon 780M (1002:1900, VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU, driver 32.0.32015.12012) and NVIDIA GeForce RTX 5060 Laptop GPU (driver 32.0.16.1742), Release, BUILD_TESTING=ON, ANYPS5_REQUIRE_VULKAN=1.

On main 5b1d381d5a, WinLibs GCC 15.2.0 r7 (CI's package), separate ctest runs:

Test GPU Failed
agc_driver_depth_plane_partial_store_buffer_copy (5 upload image loads per run) Radeon 780M 0 of 60
same, APS5_NO_DEPTH_UPLOAD_IMAGE=1 (same binary) Radeon 780M 10 of 40
agc_driver_depth_plane_partial_store_upload_image Radeon 780M 0 of 20
agc_driver_depth_plane_partial_store_image_copy Radeon 780M 0 of 20
agc_driver_depth_plane_partial_store_unimported Radeon 780M 0 of 20
agc_driver_depth_plane_partial_store_buffer_copy (0 upload image loads) RTX 5060 0 of 20
agc_driver_depth_plane_partial_store_upload_image RTX 5060 0 of 20
  • ctest -R depth: 65 of 65 pass on both GPUs.
  • Validation on main 5b1d381d5a, MSYS2 UCRT64 GCC 16.2.0 build, ctest -R depth -V with VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation (MSYS2 1.4.363), ANYPS5_NO_SHADER_CACHE=1, VK_LOADER_DEBUG=layer showing the layer inserted in every test and no failed to load or was not found but was requested by env var VK_INSTANCE_LAYERS: main 63 of 64 and the change 64 of 65 pass on both GPUs, the rest skipped (agc_driver_native_depth_driver_queued_fill, on both sides), 0 VUID- lines on either side.
  • On the 780M with driver 32.0.32015.7029 and main 88e804b0a7: _buffer_copy 0 of 100, 8 of 40 with APS5_NO_DEPTH_UPLOAD_IMAGE=1; ctest -R "agc_\|video_out\|shader" 1315 of 1316 on the 780M (agc_driver_sample_order_grid_reference fails as in #12277, also without this change), 1316 of 1316 on the RTX 5060.
  • Linux, on main 88e804b0a7, WSL Ubuntu 24.04 with lavapipe (Mesa 25.2.8), GCC 13.3, the Linux job's configure flags plus -DANYPS5_ENABLE_SPIRV_TOOLS=ON, ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx ctest -R depth: 50 passed, 2 skipped (check_skips.py: expected); _upload_image made 5 loads through the image, _buffer_copy none.
  • python3 tools/check_conventions.py --base origin/main and python3 tools/check_test_registration.py pass.

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: Fixes #13867
  • Unblocks: none
  • GPUs tested: AMD Radeon 780M (drivers 32.0.32015.7029 and 32.0.32015.12012, Windows 11), NVIDIA GeForce RTX 5060 Laptop GPU (driver 32.0.16.1742, Windows 11)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5118605209 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15015). Originally posted by [sharveshprabhu](https://github.com/sharveshprabhu) on 2026-11-02T10:14:03Z. --- ### What On AMD's proprietary Windows driver, a `vkCmdCopyBufferToImage` into a depth image that was drawn, in `VK_IMAGE_LAYOUT_GENERAL`, leaves some 8x8 tiles that the next depth test treats as holding the depth drawn before the copy, although the copied values read back correctly. This is what fails `agc_driver_depth_plane_partial_store_buffer_copy` on a Radeon 780M (#13867). On integrated GPUs with that driver (`VK_DRIVER_ID_AMD_PROPRIETARY` and `VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU`), `copyPlane`'s buffer path now copies the staging buffer into a transfer-only image of the depth format (`TRANSFER_DST_OPTIMAL`, then `TRANSFER_SRC_OPTIMAL`) and from it into the depth plane with `vkCmdCopyImage`, with the same regions. The image is created once per depth surface, kept by the recorder while a copy uses it, and released with the surface. Copies into colour storage images and stencil planes are unchanged. - `APS5_NO_DEPTH_UPLOAD_IMAGE=1` keeps the direct buffer copy (row added to `docs/dev/ENVIRONMENT.md`). - `SetDepthUploadImage(true)` forces the path on any device; `DepthUploadCount()` counts its loads. - New test `agc_driver_depth_plane_partial_store_upload_image` runs the partial store test through the path on every device, so lavapipe exercises it too. The test now requires uploads when the path is forced. A standalone Vulkan program (no AnyPS5 code) that draws a 384x200 `D32_SFLOAT` image at 0.5, copies 0.75 into x 128-255, y 128-199 with `vkCmdCopyBufferToImage` in `GENERAL`, then draws at 0.6 with `LESS`, reproduces it; the validation layer with synchronization validation reports nothing for it: | Standalone program, 200 iterations | Radeon 780M | RTX 5060 | |---|---|---| | buffer -> depth image | 27 failed | 0 failed | | buffer -> R32_SFLOAT image -> buffer -> depth image (AnyPS5's sequence) | 37 failed | 0 failed | | buffer -> transfer-only depth image -> `vkCmdCopyImage` | 0 failed | 0 failed | Each failure is 64 or 128 texels short inside the block and none outside. The program's source can be attached. Discrete cards don't show it: an RX 9070 XT (RDNA 4, also 32.0.32015.7029) passes the AnyPS5 test and the standalone program at 1000 iterations, and an RX 6700 XT (RDNA 2) passes the AnyPS5 test. So the path is limited to integrated GPUs; if a discrete AMD card shows the stale tiles, the device-type check can be dropped. A Radeon 860M (RDNA 3.5) passes without the path on Adrenalin 26.10.2 (32.0.32015.12012) and with it, while the 780M still fails on that driver, so a driver version check would not separate them; both report Vulkan `driverVersion` `0x8001a0`. ### Tested <!-- OS, title or homebrew, what was checked. "Not tested" is a valid answer. A performance change: the summary lines of main and of this PR from the same machine and scene, with the traces attached, captured as the Performance report issue form describes. --> Windows 11 Home 10.0.26300, AMD Ryzen 7 260 with Radeon 780M (`1002:1900`, `VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU`, driver 32.0.32015.12012) and NVIDIA GeForce RTX 5060 Laptop GPU (driver 32.0.16.1742), Release, `BUILD_TESTING=ON`, `ANYPS5_REQUIRE_VULKAN=1`. On `main` `5b1d381d5a`, WinLibs GCC 15.2.0 r7 (CI's package), separate `ctest` runs: | Test | GPU | Failed | |---|---|---| | `agc_driver_depth_plane_partial_store_buffer_copy` (5 upload image loads per run) | Radeon 780M | 0 of 60 | | same, `APS5_NO_DEPTH_UPLOAD_IMAGE=1` (same binary) | Radeon 780M | 10 of 40 | | `agc_driver_depth_plane_partial_store_upload_image` | Radeon 780M | 0 of 20 | | `agc_driver_depth_plane_partial_store_image_copy` | Radeon 780M | 0 of 20 | | `agc_driver_depth_plane_partial_store_unimported` | Radeon 780M | 0 of 20 | | `agc_driver_depth_plane_partial_store_buffer_copy` (0 upload image loads) | RTX 5060 | 0 of 20 | | `agc_driver_depth_plane_partial_store_upload_image` | RTX 5060 | 0 of 20 | - `ctest -R depth`: 65 of 65 pass on both GPUs. - Validation on `main` `5b1d381d5a`, MSYS2 UCRT64 GCC 16.2.0 build, `ctest -R depth -V` with `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation` (MSYS2 1.4.363), `ANYPS5_NO_SHADER_CACHE=1`, `VK_LOADER_DEBUG=layer` showing the layer inserted in every test and no `failed to load` or `was not found but was requested by env var VK_INSTANCE_LAYERS`: `main` 63 of 64 and the change 64 of 65 pass on both GPUs, the rest skipped (`agc_driver_native_depth_driver_queued_fill`, on both sides), 0 `VUID-` lines on either side. - On the 780M with driver 32.0.32015.7029 and `main` `88e804b0a7`: `_buffer_copy` 0 of 100, 8 of 40 with `APS5_NO_DEPTH_UPLOAD_IMAGE=1`; `ctest -R "agc_\|video_out\|shader"` 1315 of 1316 on the 780M (`agc_driver_sample_order_grid_reference` fails as in #12277, also without this change), 1316 of 1316 on the RTX 5060. - Linux, on `main` `88e804b0a7`, WSL Ubuntu 24.04 with lavapipe (Mesa 25.2.8), GCC 13.3, the Linux job's configure flags plus `-DANYPS5_ENABLE_SPIRV_TOOLS=ON`, `ANYPS5_REQUIRE_VULKAN=1 GALLIUM_OVERRIDE_CPU_CAPS=avx ctest -R depth`: 50 passed, 2 skipped (`check_skips.py`: expected); `_upload_image` made 5 loads through the image, `_buffer_copy` none. - `python3 tools/check_conventions.py --base origin/main` and `python3 tools/check_test_registration.py` pass. ### 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: Fixes #13867 - [x] Unblocks: none - [x] GPUs tested: AMD Radeon 780M (drivers 32.0.32015.7029 and 32.0.32015.12012, Windows 11), NVIDIA GeForce RTX 5060 Laptop GPU (driver 32.0.16.1742, Windows 11) - [x] AI-assisted: yes
BunnyFl commented 2026-11-02 11:27:17 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-02T11:27:17Z.

Review: APPROVED


Looks right to me, with a data point from a second AMD generation on the same driver.

Code. The upload image goes UNDEFINED → TRANSFER_DST_OPTIMAL → TRANSFER_SRC_OPTIMAL for each copy and only the copied regions are read back, so the undefined contents outside them never reach the depth plane. Re-entering from UNDEFINED with source stage TRANSFER also orders the reuse after the previous copy's read. Colour storage and stencil copies keep the direct path, the recorder keeps the image alive while a copy uses it, and it's released with the surface.

Tested on Windows 11, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT (RDNA4, VK_DRIVER_ID_AMD_PROPRIETARY, driver 32.0.32015.7029, the same version as your 780M), with ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:

  • On main, agc_driver_depth_plane_partial_store_buffer_copy passed 20 of 20 runs. The stale-tile bug doesn't reproduce on RDNA4 with this driver.
  • With head 59f84aa1e5 merged onto main, the unimported, buffer_copy and new upload_image tests passed 20 of 20 runs each. The buffer cases report 5 upload image loads, so the new path is taken on this device. No log has a VUID- or SYNC-HAZARD line.

Non-blocking: since RDNA4 doesn't show the bug, the workaround could be keyed more narrowly than the whole driver ID. That said, it costs one extra image copy per depth upload and stays correct where it isn't needed, and the opt-out variable is there, so applying it to all AMD proprietary drivers seems a reasonable default until more devices are measured.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5735841737 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15015#pullrequestreview-5735841737). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-02T11:27:17Z. **Review:** APPROVED --- Looks right to me, with a data point from a second AMD generation on the same driver. **Code.** The upload image goes `UNDEFINED → TRANSFER_DST_OPTIMAL → TRANSFER_SRC_OPTIMAL` for each copy and only the copied regions are read back, so the undefined contents outside them never reach the depth plane. Re-entering from `UNDEFINED` with source stage `TRANSFER` also orders the reuse after the previous copy's read. Colour storage and stencil copies keep the direct path, the recorder keeps the image alive while a copy uses it, and it's released with the surface. **Tested** on Windows 11, WinLibs GCC 15.2.0, Release, AMD Radeon RX 9070 XT (RDNA4, `VK_DRIVER_ID_AMD_PROPRIETARY`, driver 32.0.32015.7029, the same version as your 780M), with `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`: - On `main`, `agc_driver_depth_plane_partial_store_buffer_copy` passed 20 of 20 runs. The stale-tile bug doesn't reproduce on RDNA4 with this driver. - With head `59f84aa1e5` merged onto `main`, the `unimported`, `buffer_copy` and new `upload_image` tests passed 20 of 20 runs each. The buffer cases report `5 upload image loads`, so the new path is taken on this device. No log has a `VUID-` or `SYNC-HAZARD` line. Non-blocking: since RDNA4 doesn't show the bug, the workaround could be keyed more narrowly than the whole driver ID. That said, it costs one extra image copy per depth upload and stays correct where it isn't needed, and the opt-out variable is there, so applying it to all AMD proprietary drivers seems a reasonable default until more devices are measured.
BunnyFl commented 2026-11-04 15:37:53 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T15:37:53Z.

Review: APPROVED


@sharveshprabhu re-checked at 226d4869ff. git range-diff of my approved 59f84aa1e5 against this head shows two changes to this PR's own patch:

  • The copy-image path is now on only for integrated GPUs on AMD's proprietary driver (core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:1490 adds deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU). That matches the runs in this thread: the 780M fails without it, and the 860M and discrete cards don't need it.
  • The test list adds main's image_copy variant next to the new upload_image one, and docs/dev/ENVIRONMENT.md describes the narrower scope.

What I ran: head 226d4869ff merged onto main b11c7bf84f (merge 8444a96394), Windows 11, WinLibs GCC, Release, AMD Radeon RX 9070 XT (discrete), driver 32.0.32015.12012, with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation:

  • agc_driver_depth_plane_partial_store*: 5 of 5 pass on the merge, 4 of 4 on main (the upload_image test is new). Neither log has a VUID- or SYNC-HAZARD line or a missing-layer line.
  • On this discrete card the default path now matches main: 0 upload-image loads in agc_driver_depth_plane_partial_store and _unimported, with the same shader-pass and direct-copy counts as main. _upload_image, which forces the path, reports 5 upload-image loads and passes. So this card exercises the path itself only through the forced test, not through the device check.
  • pr_overlap.py --branch: 88 open PRs touch the same files, none the same exports.
<!-- greyfinch-sync:boykopovar/AnyPS5:review:5771143094 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/15015#pullrequestreview-5771143094). Originally posted by [BunnyFl](https://github.com/BunnyFl) on 2026-11-04T15:37:53Z. **Review:** APPROVED --- @sharveshprabhu re-checked at `226d4869ff`. `git range-diff` of my approved `59f84aa1e5` against this head shows two changes to this PR's own patch: - The copy-image path is now on only for integrated GPUs on AMD's proprietary driver (`core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp:1490` adds `deviceType == VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU`). That matches the runs in this thread: the 780M fails without it, and the 860M and discrete cards don't need it. - The test list adds `main`'s `image_copy` variant next to the new `upload_image` one, and `docs/dev/ENVIRONMENT.md` describes the narrower scope. **What I ran:** head `226d4869ff` merged onto `main` `b11c7bf84f` (merge `8444a96394`), Windows 11, WinLibs GCC, Release, AMD Radeon RX 9070 XT (discrete), driver 32.0.32015.12012, with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1` and `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`: - `agc_driver_depth_plane_partial_store*`: 5 of 5 pass on the merge, 4 of 4 on `main` (the `upload_image` test is new). Neither log has a `VUID-` or `SYNC-HAZARD` line or a missing-layer line. - On this discrete card the default path now matches `main`: 0 upload-image loads in `agc_driver_depth_plane_partial_store` and `_unimported`, with the same shader-pass and direct-copy counts as `main`. `_upload_image`, which forces the path, reports 5 upload-image loads and passes. So this card exercises the path itself only through the forced test, not through the device check. - `pr_overlap.py --branch`: 88 open PRs touch the same files, none the same exports.
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!15015
No description provided.