fix(agc): order deferred import settles with main-queue accesses #8527

Merged
eliasbruno124-dev merged 3 commits from upstream-pr/8527 into main 2026-10-23 18:59:55 +00:00
eliasbruno124-dev commented 2026-10-20 15:12:32 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by eliasbruno124-dev on 2026-10-20T15:12:32Z.


What

Order Windows deferred host-import settle reads with earlier and later main-queue accesses to the same memory. GTA III reports SYNC-HAZARD-WRITE-RACING-READ when a main-queue fill races the deferred four-byte copy on the separate settle queue.

Allocate batch commands from the main pool and submit on the main queue, with barriers around the copies. Submission remains asynchronous on the CPU. Reuse the existing import buffer, removing the alternate-family alias from this path. Retirement checks a bounded 60-second fence wait and propagates failure before releasing the batch's resources.

The ordering tests cover both settle-family configurations and reject reported SYNC-HAZARD- or VUID- messages when validation is enabled. Their byte assertions alone can pass on unfixed drivers. A separate regression injects timeout and device-loss results, checks error propagation and retained imports, then verifies exactly one release after a successful wait. The first-use check requires earlier main-queue reads to finish before rewatching. Both comparison arms include the scratch-copy barriers needed by the existing canaries.

Rebased linearly onto f40cdebce2, keeping both recorder selection flags from the conflict. Main queue/pool access is protected by GuestMemory::GpuMutex, including queue-0 commits, presentation and command allocation/free. Overlap refreshed on 2026-10-23: #9941 owns the separate synchronous initial-DCC settle change; #9670 adds a separate presentation queue. Neither is a dependency or a replacement for this correction.

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA RTX 3060 Laptop GPU, driver 617.42, WinLibs GCC 15.2.0 r7, Release. Real Khronos layer with synchronization validation, ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1, sequential ctest -V.
  • Same 28 focused tests and final test sources: production GuestBufferMemory.cpp from main f40cdebce2 versus candidate a0ecec3d3. Baseline: four failing cases, two READ-RACING-WRITE and three WRITE-RACING-READ reports. Candidate: 28/28 pass, no skips or validation errors; longest case 2.94 seconds. The set covers deferred settles, both ordering configurations, retirement errors, import lifetime, flip stores and VideoOut presentation.
  • The prior unbounded implementation separately fails the new bounded-wait assertion. Timeout/device loss are injected return values after actual GPU work completes, not physical GPU hangs or a measured 60-second timeout. Project conventions and git diff --check pass.
  • Original GTA III, PPSA03527/01.003.000, was compared on the earlier full-runtime commits cabd80f47 and c64cfdee2: identical resources/settings, default deferred settles, empty private caches, no inputs or other unmerged PRs, all 61 observed runtime modules verified. Each observation was stopped after 300 seconds rather than reaching a normal guest exit.
Earlier GTA III validation reports Base Candidate
SYNC-HAZARD-WRITE-RACING-READ 3 0
VUID-VkImageViewCreateInfo-usage-02275 10 10

Those races concern a main-queue vkCmdFillBuffer and the settle vkCmdCopyBuffer, over 4096-, 65536- and 12288-byte buffers. The separate image-view errors remain. Renderer exports show the opening logo, not gameplay. This title evidence belongs to the named pre-rebase commits; the new review correction has native comparison coverage, not a fresh title run.

No FPS or loading-time gain is claimed. Main-queue batching latency, a real device-loss event, other GPU vendors, Linux and macOS were not measured locally. The earlier title observations had validation/profiling/readback enabled, and Git metadata work overlapped part of the candidate observation.

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 RTX 3060 Laptop GPU, driver 617.42, Windows 11 Pro 10.0.26300
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4937897182 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8527). Originally posted by [eliasbruno124-dev](https://github.com/eliasbruno124-dev) on 2026-10-20T15:12:32Z. --- ### What Order Windows deferred host-import settle reads with earlier and later main-queue accesses to the same memory. GTA III reports `SYNC-HAZARD-WRITE-RACING-READ` when a main-queue fill races the deferred four-byte copy on the separate settle queue. Allocate batch commands from the main pool and submit on the main queue, with barriers around the copies. Submission remains asynchronous on the CPU. Reuse the existing import buffer, removing the alternate-family alias from this path. Retirement checks a bounded 60-second fence wait and propagates failure before releasing the batch's resources. The ordering tests cover both settle-family configurations and reject reported `SYNC-HAZARD-` or `VUID-` messages when validation is enabled. Their byte assertions alone can pass on unfixed drivers. A separate regression injects timeout and device-loss results, checks error propagation and retained imports, then verifies exactly one release after a successful wait. The first-use check requires earlier main-queue reads to finish before rewatching. Both comparison arms include the scratch-copy barriers needed by the existing canaries. Rebased linearly onto `f40cdebce2`, keeping both recorder selection flags from the conflict. Main queue/pool access is protected by `GuestMemory::GpuMutex`, including queue-0 commits, presentation and command allocation/free. Overlap refreshed on 2026-10-23: #9941 owns the separate synchronous initial-DCC settle change; #9670 adds a separate presentation queue. Neither is a dependency or a replacement for this correction. ### 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 Pro 10.0.26300, NVIDIA RTX 3060 Laptop GPU, driver 617.42, WinLibs GCC 15.2.0 r7, Release. Real Khronos layer with synchronization validation, `ANYPS5_REQUIRE_VULKAN=1`, `ANYPS5_NO_SHADER_CACHE=1`, sequential `ctest -V`. - Same 28 focused tests and final test sources: production `GuestBufferMemory.cpp` from main `f40cdebce2` versus candidate `a0ecec3d3`. Baseline: four failing cases, two `READ-RACING-WRITE` and three `WRITE-RACING-READ` reports. Candidate: 28/28 pass, no skips or validation errors; longest case 2.94 seconds. The set covers deferred settles, both ordering configurations, retirement errors, import lifetime, flip stores and VideoOut presentation. - The prior unbounded implementation separately fails the new bounded-wait assertion. Timeout/device loss are injected return values after actual GPU work completes, not physical GPU hangs or a measured 60-second timeout. Project conventions and `git diff --check` pass. - Original GTA III, PPSA03527/01.003.000, was compared on the earlier full-runtime commits `cabd80f47` and `c64cfdee2`: identical resources/settings, default deferred settles, empty private caches, no inputs or other unmerged PRs, all 61 observed runtime modules verified. Each observation was stopped after 300 seconds rather than reaching a normal guest exit. | Earlier GTA III validation reports | Base | Candidate | |---|---:|---:| | `SYNC-HAZARD-WRITE-RACING-READ` | 3 | 0 | | `VUID-VkImageViewCreateInfo-usage-02275` | 10 | 10 | Those races concern a main-queue `vkCmdFillBuffer` and the settle `vkCmdCopyBuffer`, over 4096-, 65536- and 12288-byte buffers. The separate image-view errors remain. Renderer exports show the opening logo, not gameplay. This title evidence belongs to the named pre-rebase commits; the new review correction has native comparison coverage, not a fresh title run. No FPS or loading-time gain is claimed. Main-queue batching latency, a real device-loss event, other GPU vendors, Linux and macOS were not measured locally. The earlier title observations had validation/profiling/readback enabled, and Git metadata work overlapped part of the candidate observation. ### 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 RTX 3060 Laptop GPU, driver 617.42, Windows 11 Pro 10.0.26300 - [x] AI-assisted: yes
oneandonlydean commented 2026-10-21 03:10:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T03:10:37Z.


@eliasbruno124-dev thanks, the barriers and the alias removal look right. Two questions before merge:

  1. Moving the settle batch to context.pool and context.queue makes it share two externally synchronized objects with the main recorder. submitSettleBatch holds settleQueueMutex, and settleUnwatchedImports only runs it while this thread holds GuestMemory::GpuMutex. Is every other vkQueueSubmit to context.queue, and every allocation, reset or free on context.pool, also made under GpuMutex? Please point to where that holds for the queue-0 committer and the present path, or add the lock the main queue uses.
  2. waitSettleBatch now waits with UINT64_MAX. A GPU hang during retirement would then block the thread holding GpuMutex forever, where before it gave up after 10 s. Is that intended, or would a long bounded wait followed by a fatal error be better?
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6307069514 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8527#issuecomment-6307069514). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T03:10:37Z. --- @eliasbruno124-dev thanks, the barriers and the alias removal look right. Two questions before merge: 1. Moving the settle batch to `context.pool` and `context.queue` makes it share two externally synchronized objects with the main recorder. `submitSettleBatch` holds `settleQueueMutex`, and `settleUnwatchedImports` only runs it while this thread holds `GuestMemory::GpuMutex`. Is every other `vkQueueSubmit` to `context.queue`, and every allocation, reset or free on `context.pool`, also made under `GpuMutex`? Please point to where that holds for the queue-0 committer and the present path, or add the lock the main queue uses. 2. `waitSettleBatch` now waits with `UINT64_MAX`. A GPU hang during retirement would then block the thread holding `GpuMutex` forever, where before it gave up after 10 s. Is that intended, or would a long bounded wait followed by a fatal error be better?
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!8527
No description provided.