fix(agc): note what a raw-pointer store can reach as pending writes #16375

Merged
muhmuhkuh merged 4 commits from upstream-pr/16375 into main 2026-11-10 11:44:03 +00:00
muhmuhkuh commented 2026-11-06 13:17:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by muhmuhkuh on 2026-11-06T13:17:40Z.


What

A dispatch or draw whose shaders store through raw pointers noted no pending write over what it can reach, so a CPU read or a capture right after it read the descriptor table the work was about to rewrite. A build that uses buffer addresses and writes through them now notes the guest ranges the device can read as pending writes, as it already does for the elements it writes by descriptor, so the next reader waits for the work.

agc_driver_raw_pointer_store_pending covers a compute dispatch and a draw whose V# table a dispatch rewrites through a raw pointer, in the same submission, each with a control where an earlier submission did the store.

Changed: Graphics/src/ShaderResources.cpp (5 lines), new tests/execution/RawPointerStorePending.cpp and its CMake registration.

Tested

Windows 11 Pro 10.0.26200, MinGW GCC (DevTools mingw64), Release, one build directory for main (5eff724cde) and for each branch, built incrementally. Vulkan runs with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation, ctest -R <names> -V; every log shows the validation layer inserted (instance and device) and has 0 was not found but was requested by env var VK_INSTANCE_LAYERS, 0 VUID-, 0 SYNC-HAZARD, 0 device-lost lines. Same 16 focused tests on main and on the branch plus the two new tests: 18/18 passed on the branch, 16/16 on main. With the five lines of ShaderResources.cpp taken from main, agc_driver_raw_pointer_store_pending_inline and _items fail 2/2: both same-submission cases WRONG (compute lane 0 holds 0x1001 instead of 0x2001, draw brightest byte 0 instead of 255) while both controls stay correct; with the change all four cases are correct. The change builds and passes without any other branch applied. The Vulkan runs above used main 5eff724cde. The branch was then rebased onto 921621976c (188 commits later, none of them change the files of this PR) and the same CPU tests rerun with no Vulkan device (VK_LOADER_DRIVERS_DISABLE=*): 13 passed, 6 skipped on main and 8 on the branch (the two new tests need a device), 0 failed. main has moved on to e8b1bd3d7f since; a merge of the branch into it has no conflict.

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 3080 Ti, driver 610.88, Windows 11 Pro 10.0.26200
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5188414524 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16375). Originally posted by [muhmuhkuh](https://github.com/muhmuhkuh) on 2026-11-06T13:17:40Z. --- ### What A dispatch or draw whose shaders store through raw pointers noted no pending write over what it can reach, so a CPU read or a capture right after it read the descriptor table the work was about to rewrite. A build that uses buffer addresses and writes through them now notes the guest ranges the device can read as pending writes, as it already does for the elements it writes by descriptor, so the next reader waits for the work. `agc_driver_raw_pointer_store_pending` covers a compute dispatch and a draw whose V# table a dispatch rewrites through a raw pointer, in the same submission, each with a control where an earlier submission did the store. Changed: `Graphics/src/ShaderResources.cpp` (5 lines), new `tests/execution/RawPointerStorePending.cpp` and its CMake registration. ### Tested Windows 11 Pro 10.0.26200, MinGW GCC (DevTools mingw64), Release, one build directory for `main` (5eff724cdecf) and for each branch, built incrementally. Vulkan runs with `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, `VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation`, `ctest -R <names> -V`; every log shows the validation layer inserted (instance and device) and has 0 `was not found but was requested by env var VK_INSTANCE_LAYERS`, 0 `VUID-`, 0 `SYNC-HAZARD`, 0 device-lost lines. Same 16 focused tests on `main` and on the branch plus the two new tests: 18/18 passed on the branch, 16/16 on `main`. With the five lines of `ShaderResources.cpp` taken from `main`, `agc_driver_raw_pointer_store_pending_inline` and `_items` fail 2/2: both same-submission cases WRONG (compute lane 0 holds 0x1001 instead of 0x2001, draw brightest byte 0 instead of 255) while both controls stay correct; with the change all four cases are correct. The change builds and passes without any other branch applied. The Vulkan runs above used `main` 5eff724cdecf. The branch was then rebased onto 921621976c52 (188 commits later, none of them change the files of this PR) and the same CPU tests rerun with no Vulkan device (VK_LOADER_DRIVERS_DISABLE=*): 13 passed, 6 skipped on `main` and 8 on the branch (the two new tests need a device), 0 failed. `main` has moved on to e8b1bd3d7f since; a merge of the branch into it has no conflict. ### Checklist - [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 3080 Ti, driver 610.88, Windows 11 Pro 10.0.26200 - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
milescoviello commented 2026-11-06 17:19:03 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by milescoviello on 2026-11-06T17:19:03Z.

Review: COMMENTED


One cost question about the five lines in MarkGpuWrites. For an address-based build, GuestBufferMemory::DeviceReads returns every space->base region that has a direct or mirror buffer, not just the ranges the program stores through. For a BDA program that can be whole guest pools. Noting all of that as pending writes means any CPU read, capture or label poll that overlaps those pools afterwards waits for the work, until it retires, including reads of memory the program never touches. In titles where most compute is address-based (Ghost of Tsushima's heavy programs are), that could serialize a lot of unrelated readers behind each dispatch.

Two things might bound it: note only the regions the build actually marks writable or stores into (if the BDA analysis knows them), or keep the wide note only while the dispatch is in the same submission as the reader, which is the case the test covers. I'm going to run Metal Gear Solid 4 (PPSA18194, about 6,000 address-based builds per 10 s at its title screen) with and without this change on Linux / RTX 4070 Ti and will post the worker-wait numbers here.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5804147802 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/16375#pullrequestreview-5804147802). Originally posted by [milescoviello](https://github.com/milescoviello) on 2026-11-06T17:19:03Z. **Review:** COMMENTED --- One cost question about the five lines in `MarkGpuWrites`. For an address-based build, `GuestBufferMemory::DeviceReads` returns every `space->base` region that has a direct or mirror buffer, not just the ranges the program stores through. For a BDA program that can be whole guest pools. Noting all of that as pending writes means any CPU read, capture or label poll that overlaps those pools afterwards waits for the work, until it retires, including reads of memory the program never touches. In titles where most compute is address-based (Ghost of Tsushima's heavy programs are), that could serialize a lot of unrelated readers behind each dispatch. Two things might bound it: note only the regions the build actually marks writable or stores into (if the BDA analysis knows them), or keep the wide note only while the dispatch is in the same submission as the reader, which is the case the test covers. I'm going to run Metal Gear Solid 4 (PPSA18194, about 6,000 address-based builds per 10 s at its title screen) with and without this change on Linux / RTX 4070 Ti and will post the worker-wait numbers here. AI-assisted: yes (Claude Code)
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!16375
No description provided.