perf(agc): back the GDS with shared memory on every GPU with host imports #21303

Open
Gag21 wants to merge 1 commit from upstream-pr/21303 into main
Gag21 commented 2026-11-16 05:00:07 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Gag21 on 2026-11-16T05:00:07Z.


What

Background. On AMD GCN/RDNA GPUs, GDS (Global Data Share) is on-chip memory accessible by all workgroups across the GPU. Titles like CUSA01709 use GDS for append/consume counters (e.g. at GDS offsets 0x40/0x44) and synchronize these counters with memory via DMA_DATA packets. Commit d4cf5cbeec introduced anonymous shared memory backing for the GDS with host pointer import (Pm4::RequestImportableGds), enabling DMA_DATA copies between GDS and guest memory to execute directly on the GPU without CPU stalls. However, VulkanDevice.cpp previously restricted Pm4::RequestImportableGds strictly to VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU.

The problem. On discrete GPUs (such as NVIDIA GeForce RTX 3070 or AMD Radeon dGPUs), gating Pm4::RequestImportableGds behind integrated forced GDS to remain in a private anonymous mapping (Pm4::GdsImportable() is false). Consequently:

  • Every DMA_DATA copy from GDS to guest memory (and GDS fills following GPU work) was classified as unimported, forcing Recorder::SyncThrough to stall the CPU and wait for GPU completion (preparePacketMemory -> Pm4::ResolveStore -> GuestMemory::Read -> Recorder::SyncThrough).
  • On compute queues, DMA_DATA packet execution was severely degraded (from ~0.15 ms to 7–40 ms per packet), resulting in multi-second frame stalls (5 to 18 second frames during cutscenes in CUSA01709).

The fix. Remove the integrated-GPU restriction from VulkanDevice.cpp:1945:

  • Pm4::RequestImportableGds(state->hostPointerImport) requests shared GDS host pointer import on every GPU that supports host pointer import.
  • On discrete GPUs capable of host pointer import, the GDS buffer is imported directly, keeping DMA_DATA copies entirely on the GPU without CPU stalls.
  • If a device or driver refuses the host pointer import, RejectGdsImport() retains clean fallback to private GDS mapping.
  • APS5_NO_SHARED_GDS=1 continues to provide an explicit opt-out switch to retain private GDS mappings.
  • Register agc_driver_gds_dma_fill_shared in CTest alongside agc_driver_gds_dma_fill_private to ensure continuous CI coverage of both shared importable and private GDS configurations.
  • Update docs/dev/ENVIRONMENT.md description for APS5_NO_SHARED_GDS.

Tested

  • OS / Toolchain: Windows 11 Pro 10.0.26300, GCC 16.2.0 (WinLibs UCRT), CMake 4.4.4, Ninja.
  • GPU: NVIDIA GeForce RTX 3070 (driver 621.01), Vulkan 1.4.363.1.
  • Unit & Execution Tests:
    • agc_driver_gds_dma_fill_tests executed directly on RTX 3070:
      • Shared import: host imports at shutdown: 6 live (2.3 MiB); made 7 (2.4 MiB), refused 0 -> GDS imported on discrete GPU, all tests passed.
      • Negative control (APS5_NO_SHARED_GDS=1): host imports at shutdown: 6 live (1.3 MiB); made 6 (1.3 MiB) -> private mapping cleanly preserved, all tests passed.
    • CTest runs in build-b:
      • agc_driver_gds_dma_fill_shared Passed (1.27 sec)
      • agc_driver_gds_dma_fill_private Passed (1.25 sec)
      • 100% tests passed.
  • Vulkan Validation Layer Comparison:
    • Ran agc_driver_gds_dma_fill_tests with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, VK_LOADER_DEBUG=layer.
    • Confirmed layer inserted: Enabled By: Environment Variable VK_INSTANCE_LAYERS, Manifest: C:\VulkanSDK\1.4.363.1\Bin\VkLayer_khronos_validation.json.
    • No "was not found but was requested by env var" warnings.
    • 0 VUID- validation errors logged.
  • Conventions & Overlap:
    • python tools/check_conventions.py --base origin/main: passed with 0 errors.
    • python tools/offline_overlap.py --branch perf/agc-gds-host-import-discrete-gpu: 0 overlaps across 1,588 open PRs.
    • python tools/fast_dup_check.py: 0 duplicates.
  • Game Performance (CUSA01709, RTX 3070):
    • Compute queue DMA_DATA packet time reduced from ~1,400 ms per 9,000 packets to 636 ms per 12,031 packets.
    • Cutscene frame rates (trace_digest.py):
      • Run 70 (private GDS mapping on discrete GPU, with APS5_GNM_SUBMIT_WAIT_IDLE=1): 1.73 FPS, longest frame 18.3 s.
      • Run 75 (shared GDS mapping on RTX 3070, with APS5_GNM_SUBMIT_WAIT_IDLE=1): 4.11 FPS, longest frame 1.0 s (2.37x speedup).
      • Run 76 (shared GDS mapping on RTX 3070, without APS5_GNM_SUBMIT_WAIT_IDLE=1): 4.89 FPS (2.82x speedup).

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: none
  • Unblocks: none
  • GPUs tested: NVIDIA GeForce RTX 3070 (driver 621.01, Vulkan 1.4.363.1)
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5331336513 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21303). Originally posted by [Gag21](https://github.com/Gag21) on 2026-11-16T05:00:07Z. --- ### What **Background.** On AMD GCN/RDNA GPUs, GDS (Global Data Share) is on-chip memory accessible by all workgroups across the GPU. Titles like CUSA01709 use GDS for append/consume counters (e.g. at GDS offsets 0x40/0x44) and synchronize these counters with memory via `DMA_DATA` packets. Commit `d4cf5cbeec` introduced anonymous shared memory backing for the GDS with host pointer import (`Pm4::RequestImportableGds`), enabling `DMA_DATA` copies between GDS and guest memory to execute directly on the GPU without CPU stalls. However, `VulkanDevice.cpp` previously restricted `Pm4::RequestImportableGds` strictly to `VK_PHYSICAL_DEVICE_TYPE_INTEGRATED_GPU`. **The problem.** On discrete GPUs (such as NVIDIA GeForce RTX 3070 or AMD Radeon dGPUs), gating `Pm4::RequestImportableGds` behind `integrated` forced GDS to remain in a private anonymous mapping (`Pm4::GdsImportable()` is false). Consequently: - Every `DMA_DATA` copy from GDS to guest memory (and GDS fills following GPU work) was classified as unimported, forcing `Recorder::SyncThrough` to stall the CPU and wait for GPU completion (`preparePacketMemory` -> `Pm4::ResolveStore` -> `GuestMemory::Read` -> `Recorder::SyncThrough`). - On compute queues, `DMA_DATA` packet execution was severely degraded (from ~0.15 ms to 7–40 ms per packet), resulting in multi-second frame stalls (5 to 18 second frames during cutscenes in CUSA01709). **The fix.** Remove the integrated-GPU restriction from `VulkanDevice.cpp:1945`: - `Pm4::RequestImportableGds(state->hostPointerImport)` requests shared GDS host pointer import on every GPU that supports host pointer import. - On discrete GPUs capable of host pointer import, the GDS buffer is imported directly, keeping `DMA_DATA` copies entirely on the GPU without CPU stalls. - If a device or driver refuses the host pointer import, `RejectGdsImport()` retains clean fallback to private GDS mapping. - `APS5_NO_SHARED_GDS=1` continues to provide an explicit opt-out switch to retain private GDS mappings. - Register `agc_driver_gds_dma_fill_shared` in CTest alongside `agc_driver_gds_dma_fill_private` to ensure continuous CI coverage of both shared importable and private GDS configurations. - Update `docs/dev/ENVIRONMENT.md` description for `APS5_NO_SHARED_GDS`. ### Tested - **OS / Toolchain:** Windows 11 Pro 10.0.26300, GCC 16.2.0 (WinLibs UCRT), CMake 4.4.4, Ninja. - **GPU:** NVIDIA GeForce RTX 3070 (driver 621.01), Vulkan 1.4.363.1. - **Unit & Execution Tests:** - `agc_driver_gds_dma_fill_tests` executed directly on RTX 3070: - Shared import: `host imports at shutdown: 6 live (2.3 MiB); made 7 (2.4 MiB), refused 0` -> GDS imported on discrete GPU, all tests passed. - Negative control (`APS5_NO_SHARED_GDS=1`): `host imports at shutdown: 6 live (1.3 MiB); made 6 (1.3 MiB)` -> private mapping cleanly preserved, all tests passed. - CTest runs in `build-b`: - `agc_driver_gds_dma_fill_shared` Passed (1.27 sec) - `agc_driver_gds_dma_fill_private` Passed (1.25 sec) - 100% tests passed. - **Vulkan Validation Layer Comparison:** - Ran `agc_driver_gds_dma_fill_tests` with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `VK_LOADER_DEBUG=layer`. - Confirmed layer inserted: `Enabled By: Environment Variable VK_INSTANCE_LAYERS`, `Manifest: C:\VulkanSDK\1.4.363.1\Bin\VkLayer_khronos_validation.json`. - No "was not found but was requested by env var" warnings. - 0 `VUID-` validation errors logged. - **Conventions & Overlap:** - `python tools/check_conventions.py --base origin/main`: passed with 0 errors. - `python tools/offline_overlap.py --branch perf/agc-gds-host-import-discrete-gpu`: 0 overlaps across 1,588 open PRs. - `python tools/fast_dup_check.py`: 0 duplicates. - **Game Performance (CUSA01709, RTX 3070):** - Compute queue `DMA_DATA` packet time reduced from ~1,400 ms per 9,000 packets to 636 ms per 12,031 packets. - Cutscene frame rates (`trace_digest.py`): - Run 70 (private GDS mapping on discrete GPU, with `APS5_GNM_SUBMIT_WAIT_IDLE=1`): 1.73 FPS, longest frame 18.3 s. - Run 75 (shared GDS mapping on RTX 3070, with `APS5_GNM_SUBMIT_WAIT_IDLE=1`): 4.11 FPS, longest frame 1.0 s (2.37x speedup). - Run 76 (shared GDS mapping on RTX 3070, without `APS5_GNM_SUBMIT_WAIT_IDLE=1`): 4.89 FPS (2.82x speedup). ### 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: none - [x] Unblocks: none - [x] GPUs tested: NVIDIA GeForce RTX 3070 (driver 621.01, Vulkan 1.4.363.1) - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-11-16 05:15:42 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-16T05:15:42Z.

Review: APPROVED


Reviewed — looks good

Nothing in the inspected changes blocks merging; the PR description reports successful execution on an RTX 3070, but I did not run the tests independently.

What I ran

Reviewed head cc1c02bfe4eda847c8f2c241520158360f3737de against the prepared diff. No tests or builds were run. I read all changed lines and the relevant GDS allocation, import fallback, packet handling, and execution test code.

Results

Check Result Note
Changed-line review passed All three changed files inspected
GDS fallback and packet path passed Import refusal keeps the copy path available
Tests and build not run Execution results are author-reported

Findings

Blocking

None.

Non-blocking

None.

Not verified

I did not independently run CTest, build the project, reproduce the reported performance measurements, or test on physical GPUs. VulkanDevice.cpp was read through repo_read.py; it was excluded from the prepared files/ folder because of size. Files listed as reviewed in the manifest: core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp, core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_gds_dma_fill_tests.cmake, and docs/dev/ENVIRONMENT.md. No changed files were excluded from review.

To get this to a good state

Nothing is required.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5915339464 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21303#pullrequestreview-5915339464). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-11-16T05:15:42Z. **Review:** APPROVED --- # Reviewed — looks good Nothing in the inspected changes blocks merging; the PR description reports successful execution on an RTX 3070, but I did not run the tests independently. ## What I ran Reviewed head `cc1c02bfe4eda847c8f2c241520158360f3737de` against the prepared diff. No tests or builds were run. I read all changed lines and the relevant GDS allocation, import fallback, packet handling, and execution test code. ## Results | Check | Result | Note | |---|---|---| | Changed-line review | passed | All three changed files inspected | | GDS fallback and packet path | passed | Import refusal keeps the copy path available | | Tests and build | not run | Execution results are author-reported | ## Findings ### Blocking None. ### Non-blocking None. ## Not verified I did not independently run CTest, build the project, reproduce the reported performance measurements, or test on physical GPUs. `VulkanDevice.cpp` was read through `repo_read.py`; it was excluded from the prepared `files/` folder because of size. Files listed as reviewed in the manifest: `core/libs/prx/libSceAgcDriver/Execution/src/VulkanDevice.cpp`, `core/libs/prx/libSceAgcDriver/tests/cmake/agc_driver_gds_dma_fill_tests.cmake`, and `docs/dev/ENVIRONMENT.md`. No changed files were excluded from review. ## To get this to a good state Nothing is required.
ligmaSec commented 2026-12-03 17:42:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T17:42:03Z.

Review: COMMENTED


I tested cc1c02bfe4 against main at 9d362fb088 on Linux with Mesa lavapipe. The GCN scalar-buffer control and both existing GDS DMA fill cases passed on both revisions. The branch's shared-backing case also passed. All logs show Khronos validation 1.4.369 inserted with Vulkan required and the shader cache disabled, and contain no missing-layer warnings or VUID- messages. This verifies the paths exercised on software Vulkan. It does not measure the performance of a discrete GPU.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6175204711 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/21303#pullrequestreview-6175204711). Originally posted by [ligmaSec](https://github.com/ligmaSec) on 2026-12-03T17:42:03Z. **Review:** COMMENTED --- I tested `cc1c02bfe4` against `main` at `9d362fb088` on Linux with Mesa lavapipe. The GCN scalar-buffer control and both existing GDS DMA fill cases passed on both revisions. The branch's shared-backing case also passed. All logs show Khronos validation 1.4.369 inserted with Vulkan required and the shader cache disabled, and contain no missing-layer warnings or `VUID-` messages. This verifies the paths exercised on software Vulkan. It does not measure the performance of a discrete GPU. AI-assisted: yes.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/21303:upstream-pr/21303'
git switch 'upstream-pr/21303'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/21303'
git switch 'upstream-pr/21303'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/21303'
git switch 'upstream-pr/21303'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/21303'
git switch 'main'
git merge --squash 'upstream-pr/21303'
git switch 'main'
git merge --ff-only 'upstream-pr/21303'
git switch 'main'
git merge 'upstream-pr/21303'
git push origin 'main'
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!21303
No description provided.