fix(agc): store a label behind pending copied write-backs without draining #8180

Merged
ntamas94 merged 6 commits from upstream-pr/8180 into main 2026-10-23 17:16:20 +00:00
ntamas94 commented 2026-10-20 01:50:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-20T01:50:52Z.


What

A written buffer the device holds as a CPU copy (a V# that no host import serves in place) gets its results back to guest memory through a CPU write-back when its batch is reaped. A label recorded after that dispatch was stored on the GPU in the same batch, so the label became visible first. A title that polled the label and then rewrote the region had its bytes overwritten by the late write-back: GuestMemory::WriteChanged stores every byte the shader changed against the bytes saved at upload.

While a copied writer is listed, WriteLabelOnGpu now stores a label of 8 bytes or less only through a completion of its batch (AfterCompletions with storedOnGpu false, reason 5), so it lands at reap after every earlier write-back, without draining the device. Recorder::PendingCompletionStores keeps later small labels behind an earlier pending completion store. Stores over 8 bytes keep the GPU store and go behind the completions only over a copied writer's range or a pending completion store. Queue 0 reaps while it spins on REWIND. APS5_DRAIN_COMPLETION_LABELS=1 drains instead (reason 2), as the first commit did. Written buffers the device imports in place bind directly and pay nothing.

#6185 makes WriteChanged keep a CPU store made after the upload. That cannot see a rewrite of the bytes the region held at upload, which is what a title does when it rebuilds the same command buffer every frame. This change orders the label after the write-back instead, so the two are complementary.

Tested

Windows 11 Pro (26200), WinLibs GCC 15.2.0 r7, NVIDIA RTX 2080. The CopiedWriterLabelOrder execution test dispatches a store through a CPU-copied V# (misaligned in its import, with APS5_CPU_COPIES=1), records a label, and checks that it is a pending completion store, that it is not visible before the batch that writes back the record is reaped, and that a CPU store made after the label survives. A cross-batch pass checks that a later label to the address of a pending completion store is neither visible before it nor overwritten by it. Without the change the label is stored on the GPU (reason 0) and the test fails. It skips on devices whose minStorageBufferOffsetAlignment lets the record bind in place (alignment 4: AMD's driver, RADV). agc_driver_copied_writer_label_order, agc_driver_copied_writer_label_order_drain, agc_driver_copied_writer_copy, agc_driver_unimported_label_order, agc_driver_alias_copy_label, agc_driver_indirect_arguments_pending_producer and all agc_driver_recorder_tests entries pass. Linux was not run locally.

Found by reading the code while bringing up Gang Beasts (CUSA04865, a PS4 title through #6977), which binds a V# into its command buffer and rebuilds that buffer every frame.

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 (ordering hole shown by the new test)
  • GPUs tested: NVIDIA RTX 2080 (Windows)
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4929855192 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8180). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-20T01:50:52Z. --- ### What A written buffer the device holds as a CPU copy (a V# that no host import serves in place) gets its results back to guest memory through a CPU write-back when its batch is reaped. A label recorded after that dispatch was stored on the GPU in the same batch, so the label became visible first. A title that polled the label and then rewrote the region had its bytes overwritten by the late write-back: `GuestMemory::WriteChanged` stores every byte the shader changed against the bytes saved at upload. While a copied writer is listed, `WriteLabelOnGpu` now stores a label of 8 bytes or less only through a completion of its batch (`AfterCompletions` with `storedOnGpu` false, reason 5), so it lands at reap after every earlier write-back, without draining the device. `Recorder::PendingCompletionStores` keeps later small labels behind an earlier pending completion store. Stores over 8 bytes keep the GPU store and go behind the completions only over a copied writer's range or a pending completion store. Queue 0 reaps while it spins on REWIND. `APS5_DRAIN_COMPLETION_LABELS=1` drains instead (reason 2), as the first commit did. Written buffers the device imports in place bind directly and pay nothing. #6185 makes `WriteChanged` keep a CPU store made after the upload. That cannot see a rewrite of the bytes the region held at upload, which is what a title does when it rebuilds the same command buffer every frame. This change orders the label after the write-back instead, so the two are complementary. ### Tested Windows 11 Pro (26200), WinLibs GCC 15.2.0 r7, NVIDIA RTX 2080. The `CopiedWriterLabelOrder` execution test dispatches a store through a CPU-copied V# (misaligned in its import, with `APS5_CPU_COPIES=1`), records a label, and checks that it is a pending completion store, that it is not visible before the batch that writes back the record is reaped, and that a CPU store made after the label survives. A cross-batch pass checks that a later label to the address of a pending completion store is neither visible before it nor overwritten by it. Without the change the label is stored on the GPU (reason 0) and the test fails. It skips on devices whose `minStorageBufferOffsetAlignment` lets the record bind in place (alignment 4: AMD's driver, RADV). `agc_driver_copied_writer_label_order`, `agc_driver_copied_writer_label_order_drain`, `agc_driver_copied_writer_copy`, `agc_driver_unimported_label_order`, `agc_driver_alias_copy_label`, `agc_driver_indirect_arguments_pending_producer` and all `agc_driver_recorder_tests` entries pass. Linux was not run locally. Found by reading the code while bringing up Gang Beasts (CUSA04865, a PS4 title through #6977), which binds a V# into its command buffer and rebuilds that buffer every frame. ### 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 (ordering hole shown by the new test) - [x] GPUs tested: NVIDIA RTX 2080 (Windows) - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
ntamas94 commented 2026-10-20 05:33:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-20T05:33:19Z.


Reviewed the shared files the overlap check could not compare. Only #7464 touches the same function: it sends a label whose destination has no host import through recorder.Sync() and a CPU store before this PR's check runs. Sync() finishes every in-flight batch, write-backs included, so that path already keeps a pending copied write-back ahead of the label, and imported labels still reach this check. The two merge without conflicts. #4449, #7618, #7668 and #8099 do not touch label or copied-writer handling.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6284167421 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8180#issuecomment-6284167421). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-20T05:33:19Z. --- Reviewed the shared files the overlap check could not compare. Only #7464 touches the same function: it sends a label whose destination has no host import through `recorder.Sync()` and a CPU store before this PR's check runs. `Sync()` finishes every in-flight batch, write-backs included, so that path already keeps a pending copied write-back ahead of the label, and imported labels still reach this check. The two merge without conflicts. #4449, #7618, #7668 and #8099 do not touch label or copied-writer handling.
wachi35676 commented 2026-10-20 12:18:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by wachi35676 on 2026-10-20T12:18:48Z.


The fix holds on NVIDIA, but on an AMD device the new test fails where it should skip.

Setup: Windows 11 (26300), WinLibs GCC 15.2.0, Release. The base is main 02fb1ce53, and the candidate is that base with 87ee5e245 merged (clean). The GPUs are an RTX 5070 Ti (NVIDIA 617.42, minStorageBufferOffsetAlignment 0x10) and an AMD Radeon iGPU (AMD proprietary 2.0.353, minStorageBufferOffsetAlignment 0x4). Both runs used ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1.

NVIDIA:

  • With the PR, agc_driver_copied_writer_label_order and the other label tests (copied_writer_copy, unimported_label_order, same_queue_label_wait, alias_copy_label, pipelined_predicated_label_order) pass 6 of 6, three times.
  • Negative control: the new test alone on main fails 2 of 2 with copied writer: the label after the dispatch was handled with reason 0, expected 2.
  • To check that the ordering bug is real, and not only a reason code, I changed the expected reason to 0 and ran the test on main. It fails 3 of 3 with the label is visible but the record holds 0xc0001000, the dispatch stored 0x00000001, so on main the label becomes visible before the copied write-back lands.
  • The related set of 59 tests (msaa, multisample, label, stencil, tessellation, write_tracking, resident and so on, plus agc_driver_graphics) passes 59 of 59. stencil_ref_export skips because the GPU has no stencil export.

AMD iGPU:

  • agc_driver_copied_writer_label_order fails 3 of 3 with the PR, and the same way on main: copied writer: 0 write-back completions are pending after the dispatch, expected 1 (the test needs APS5_CPU_COPIES=1 and a storage buffer offset alignment above 4).
  • With a 4-byte alignment the misaligned V# is imported in place, so no CPU copy is made. The test's precondition does not hold on this device, and the test reports a failure instead of VulkanTestSkipped. RADV also reports 4, so Linux AMD runs should hit this as well.
  • Could the first pass return VulkanTestSkipped when no write-back completion is pending (or when minStorageBufferOffsetAlignment <= 4)?
  • Apart from this test, the related set is unchanged: 58 of 59 pass.

From the code: the new early return 2 runs whenever copiedWriters or DrawCopiedWriters() is non-empty. The overlap branch just below it (CopiedWriterOverlaps, reason 5, the completion memcpy) needs a listed writer, so it can now be reached only with APS5_LABEL_GATE_ALL=1 and no writers listed. Every label recorded while any copied writer is listed now drains the device, even when the label does not overlap the writer. If that is intended, the reason-5 path is now dead in normal runs and could go.

Not run: the validation layer, Linux, and a title.

AI-assisted: yes (Claude Code); results above were run on this machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6290671019 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8180#issuecomment-6290671019). Originally posted by [wachi35676](https://github.com/wachi35676) on 2026-10-20T12:18:48Z. --- The fix holds on NVIDIA, but on an AMD device the new test fails where it should skip. Setup: Windows 11 (26300), WinLibs GCC 15.2.0, Release. The base is `main` `02fb1ce53`, and the candidate is that base with `87ee5e245` merged (clean). The GPUs are an RTX 5070 Ti (NVIDIA 617.42, `minStorageBufferOffsetAlignment` 0x10) and an AMD Radeon iGPU (AMD proprietary 2.0.353, `minStorageBufferOffsetAlignment` 0x4). Both runs used `ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1`. NVIDIA: - With the PR, `agc_driver_copied_writer_label_order` and the other label tests (`copied_writer_copy`, `unimported_label_order`, `same_queue_label_wait`, `alias_copy_label`, `pipelined_predicated_label_order`) pass 6 of 6, three times. - Negative control: the new test alone on `main` fails 2 of 2 with `copied writer: the label after the dispatch was handled with reason 0, expected 2`. - To check that the ordering bug is real, and not only a reason code, I changed the expected reason to 0 and ran the test on `main`. It fails 3 of 3 with `the label is visible but the record holds 0xc0001000, the dispatch stored 0x00000001`, so on `main` the label becomes visible before the copied write-back lands. - The related set of 59 tests (msaa, multisample, label, stencil, tessellation, write_tracking, resident and so on, plus `agc_driver_graphics`) passes 59 of 59. `stencil_ref_export` skips because the GPU has no stencil export. AMD iGPU: - `agc_driver_copied_writer_label_order` fails 3 of 3 with the PR, and the same way on `main`: `copied writer: 0 write-back completions are pending after the dispatch, expected 1 (the test needs APS5_CPU_COPIES=1 and a storage buffer offset alignment above 4)`. - With a 4-byte alignment the misaligned V# is imported in place, so no CPU copy is made. The test's precondition does not hold on this device, and the test reports a failure instead of `VulkanTestSkipped`. RADV also reports 4, so Linux AMD runs should hit this as well. - Could the first pass return `VulkanTestSkipped` when no write-back completion is pending (or when `minStorageBufferOffsetAlignment <= 4`)? - Apart from this test, the related set is unchanged: 58 of 59 pass. From the code: the new early `return 2` runs whenever `copiedWriters` or `DrawCopiedWriters()` is non-empty. The overlap branch just below it (`CopiedWriterOverlaps`, reason 5, the completion memcpy) needs a listed writer, so it can now be reached only with `APS5_LABEL_GATE_ALL=1` and no writers listed. Every label recorded while any copied writer is listed now drains the device, even when the label does not overlap the writer. If that is intended, the reason-5 path is now dead in normal runs and could go. Not run: the validation layer, Linux, and a title. AI-assisted: yes (Claude Code); results above were run on this machine.
oneandonlydean commented 2026-10-21 01:29:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T01:29:30Z.


@ntamas94 thanks for the fix. The ordering bug is real: wachi35676's control shows the label becoming visible on main while the dispatch's record still holds the old value. Two things before this can go further:

  1. The new test should skip where its precondition can't hold. On devices whose minStorageBufferOffsetAlignment is 4 (AMD proprietary, and RADV), the misaligned buffer is imported in place, no CPU copy is made, and CopiedWriterLabelOrder fails at "0 write-back completions are pending after the dispatch, expected 1". Please return VulkanTestSkipped with a skipped, ... line naming the device limitation when no write-back is pending (or when the alignment is 4 or less). Then the test fails only on the ordering it checks.

  2. The early return 2 drains on every label while any copied writer is listed, including labels that don't overlap it. CPU-copied writers also occur in default runs (regions above APS5_GPU_COPY_MAX_KIB or outside imports), so this can add a device drain per label in normal play. It also leaves the reason-5 path below (the deferred completion store, no drain) reachable only with APS5_LABEL_GATE_ALL=1, and the comment above it no longer matches the code. Could the label take that existing deferred path whenever any copied writer is listed, instead of draining? The completion store runs at reap after the earlier write-back, so it should keep the order your test checks without a drain. If you keep the drain, please add a frame-time comparison on a title that hits it.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6305753787 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8180#issuecomment-6305753787). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T01:29:30Z. --- @ntamas94 thanks for the fix. The ordering bug is real: wachi35676's control shows the label becoming visible on `main` while the dispatch's record still holds the old value. Two things before this can go further: 1. **The new test should skip where its precondition can't hold.** On devices whose `minStorageBufferOffsetAlignment` is 4 (AMD proprietary, and RADV), the misaligned buffer is imported in place, no CPU copy is made, and `CopiedWriterLabelOrder` fails at "0 write-back completions are pending after the dispatch, expected 1". Please return `VulkanTestSkipped` with a `skipped, ...` line naming the device limitation when no write-back is pending (or when the alignment is 4 or less). Then the test fails only on the ordering it checks. 2. **The early `return 2` drains on every label while any copied writer is listed, including labels that don't overlap it.** CPU-copied writers also occur in default runs (regions above `APS5_GPU_COPY_MAX_KIB` or outside imports), so this can add a device drain per label in normal play. It also leaves the reason-5 path below (the deferred completion store, no drain) reachable only with `APS5_LABEL_GATE_ALL=1`, and the comment above it no longer matches the code. Could the label take that existing deferred path whenever any copied writer is listed, instead of draining? The completion store runs at reap after the earlier write-back, so it should keep the order your test checks without a drain. If you keep the drain, please add a frame-time comparison on a title that hits it.
ntamas94 commented 2026-10-21 11:08:52 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-21T11:08:52Z.


@oneandonlydean thanks, both points addressed in baa0ca3df.

1. Test skip. CopiedWriterLabelOrder now returns VulkanTestSkipped when no write-back is pending after the dispatch and the record offset (+0x1004) is a multiple of the device's minStorageBufferOffsetAlignment, with skipped, the device reports a minStorageBufferOffsetAlignment of 4, so the dispatch binds its record at +0x1004 in place and nothing is written back; .... On a device whose alignment is above 4, a missing write-back still fails the test, so a regression there is not hidden.

2. No drain per label. I tried the reason-5 path as you suggested, but it doesn't keep the order for the case the test checks. That path first records the label on the GPU into the host import (recordStore), so a polling title sees it as soon as the GPU runs the batch. AfterCompletions(..., storedOnGpu=true) then skips its CPU store unless a write-back overlapped the label's own bytes. For a label away from the copied writer, which is the case here, it behaves like reason 0, and the test fails at "the label is visible before the batch that writes back the dispatch's record was reaped".

What the PR does now:

  • While a copied writer is listed, a label of 8 bytes or less (every RELEASE_MEM, fence WRITE_DATAs) is not recorded on the GPU. A completion of the open (or newest in-flight) batch stores it at reap via AfterCompletions(..., storedOnGpu=false), and WriteLabelOnGpu returns 5. Completions run in push order and batches finish front-first, so it lands after every earlier write-back. There is no WaitIdle: every caller already treats 5 as stored.
  • A new Recorder::PendingCompletionStores counts only guest stores still to be made by completions (not EOP deliveries or write-backs). While it is non-zero, later small labels take the same route, so a later GPU label can't become visible before an earlier completion store or land under it at one address. A new cross-batch pass in the test covers this.
  • Stores over 8 bytes (DUMP_CONST_RAM, COPY_DATA, DMA_DATA payloads that later GPU work reads through the import) keep the GPU store. Over a copied writer's range they keep the existing GPU-store-plus-re-store path, which is reachable by default again, and its comment is updated.
  • GPU work recorded after such a label syncs through its batch before reading the range (the label is a pending write of its batch), and queue 0 now also reaps while it spins on REWIND, so a title polling the label there can't wait forever.
  • APS5_DRAIN_COMPLETION_LABELS=1 brings back the drain (reason 2); a second ctest entry runs the test with it.

The debt entry lists what this still leaves out of order: larger stores and GPU-made DMA_DATA copies away from those ranges, a small label landing after GPU writes recorded behind it, and a nested sync from inside a write-back over a pending storage image.

Tested on Windows 11, RTX 2080: agc_driver_copied_writer_label_order, agc_driver_copied_writer_label_order_drain, agc_driver_copied_writer_copy, agc_driver_unimported_label_order, agc_driver_alias_copy_label, agc_driver_indirect_arguments_pending_producer and all agc_driver_recorder_tests entries pass, also after merging current main (95968952e); conventions pass. Since there's no drain left I didn't add a frame-time comparison; I can post Gang Beasts numbers if you'd still like them.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6314455652 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8180#issuecomment-6314455652). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-21T11:08:52Z. --- @oneandonlydean thanks, both points addressed in baa0ca3df. **1. Test skip.** `CopiedWriterLabelOrder` now returns `VulkanTestSkipped` when no write-back is pending after the dispatch and the record offset (+0x1004) is a multiple of the device's `minStorageBufferOffsetAlignment`, with `skipped, the device reports a minStorageBufferOffsetAlignment of 4, so the dispatch binds its record at +0x1004 in place and nothing is written back; ...`. On a device whose alignment is above 4, a missing write-back still fails the test, so a regression there is not hidden. **2. No drain per label.** I tried the reason-5 path as you suggested, but it doesn't keep the order for the case the test checks. That path first records the label on the GPU into the host import (`recordStore`), so a polling title sees it as soon as the GPU runs the batch. `AfterCompletions(..., storedOnGpu=true)` then skips its CPU store unless a write-back overlapped the label's own bytes. For a label away from the copied writer, which is the case here, it behaves like reason 0, and the test fails at "the label is visible before the batch that writes back the dispatch's record was reaped". What the PR does now: - While a copied writer is listed, a label of 8 bytes or less (every RELEASE_MEM, fence WRITE_DATAs) is not recorded on the GPU. A completion of the open (or newest in-flight) batch stores it at reap via `AfterCompletions(..., storedOnGpu=false)`, and `WriteLabelOnGpu` returns 5. Completions run in push order and batches finish front-first, so it lands after every earlier write-back. There is no WaitIdle: every caller already treats 5 as stored. - A new `Recorder::PendingCompletionStores` counts only guest stores still to be made by completions (not EOP deliveries or write-backs). While it is non-zero, later small labels take the same route, so a later GPU label can't become visible before an earlier completion store or land under it at one address. A new cross-batch pass in the test covers this. - Stores over 8 bytes (DUMP_CONST_RAM, COPY_DATA, DMA_DATA payloads that later GPU work reads through the import) keep the GPU store. Over a copied writer's range they keep the existing GPU-store-plus-re-store path, which is reachable by default again, and its comment is updated. - GPU work recorded after such a label syncs through its batch before reading the range (the label is a pending write of its batch), and queue 0 now also reaps while it spins on REWIND, so a title polling the label there can't wait forever. - `APS5_DRAIN_COMPLETION_LABELS=1` brings back the drain (reason 2); a second ctest entry runs the test with it. The debt entry lists what this still leaves out of order: larger stores and GPU-made DMA_DATA copies away from those ranges, a small label landing after GPU writes recorded behind it, and a nested sync from inside a write-back over a pending storage image. Tested on Windows 11, RTX 2080: `agc_driver_copied_writer_label_order`, `agc_driver_copied_writer_label_order_drain`, `agc_driver_copied_writer_copy`, `agc_driver_unimported_label_order`, `agc_driver_alias_copy_label`, `agc_driver_indirect_arguments_pending_producer` and all `agc_driver_recorder_tests` entries pass, also after merging current `main` (95968952e); conventions pass. Since there's no drain left I didn't add a frame-time comparison; I can post Gang Beasts numbers if you'd still like them.
oneandonlydean commented 2026-10-21 11:26:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-21T11:26:50Z.


@ntamas94 thanks, both points are addressed, and you're right about reason 5. It records the label on the GPU first, so a label away from the copied writer becomes visible before the write-back, exactly as in reason 0. My suggestion couldn't have kept the order the test checks.

The new route reads correctly. A small label goes into the open or newest in-flight batch's completions. Completions run in push order and batches finish front-first, so it lands after every earlier write-back, whatever range that write-back covers. PendingCompletionStores is counted in AfterCompletions and in the late count in NoteWrittenBack, and dropped in finish, discard and the destructor, so it can't leak. Larger stores keep the existing overlap path. Queue 0 reaping on REWIND covers a title that spins there. The test skip and the new _drain variant also look right. Merged onto current main, the changed files compile.

One question, and it's the reason we'd like a frame-time check before merging. PendingCompletionStores is process-wide and stays above zero until the batch holding the store finishes. Each small label that takes this route adds one to the open batch. With the GPU a frame or two behind, which is the normal state, can the count fall back to zero once the copied writers are gone? If not, every RELEASE_MEM and fence label after the first copied writer is stored at reap for as long as the queue stays busy, on every queue, not only the one with the writer. Default runs keep CPU-copied writers (regions above APS5_GPU_COPY_MAX_KIB, or outside imports), so titles will hit this. The [sync] profile line's "behind completions" count on a title run would show how often it happens. If it stays high after the writers are gone, counting per queue would at least keep the other queues on GPU stores.

Not blocking on the code. Once CI is green, we'll measure frame time on our own titles before merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6314769376 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8180#issuecomment-6314769376). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-21T11:26:50Z. --- @ntamas94 thanks, both points are addressed, and you're right about reason 5. It records the label on the GPU first, so a label away from the copied writer becomes visible before the write-back, exactly as in reason 0. My suggestion couldn't have kept the order the test checks. The new route reads correctly. A small label goes into the open or newest in-flight batch's completions. Completions run in push order and batches finish front-first, so it lands after every earlier write-back, whatever range that write-back covers. `PendingCompletionStores` is counted in `AfterCompletions` and in the late count in `NoteWrittenBack`, and dropped in `finish`, `discard` and the destructor, so it can't leak. Larger stores keep the existing overlap path. Queue 0 reaping on REWIND covers a title that spins there. The test skip and the new `_drain` variant also look right. Merged onto current `main`, the changed files compile. One question, and it's the reason we'd like a frame-time check before merging. `PendingCompletionStores` is process-wide and stays above zero until the batch holding the store finishes. Each small label that takes this route adds one to the open batch. With the GPU a frame or two behind, which is the normal state, can the count fall back to zero once the copied writers are gone? If not, every RELEASE_MEM and fence label after the first copied writer is stored at reap for as long as the queue stays busy, on every queue, not only the one with the writer. Default runs keep CPU-copied writers (regions above `APS5_GPU_COPY_MAX_KIB`, or outside imports), so titles will hit this. The `[sync]` profile line's "behind completions" count on a title run would show how often it happens. If it stays high after the writers are gone, counting per queue would at least keep the other queues on GPU stores. Not blocking on the code. Once CI is green, we'll measure frame time on our own titles before merging.
ntamas94 commented 2026-10-22 07:37:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by ntamas94 on 2026-10-22T07:37:26Z.


@oneandonlydean I measured whether PendingCompletionStores drops back to zero once the copied writers are gone, on Gang Beasts (CUSA04865). I used a local counter (not part of this PR) that sorts every imported label of 8 bytes or less by the route it takes. There were two 5-minute runs through the menu, level0, level4 and level16:

run small labels behind a listed copied writer behind pending completion stores only on the GPU
copied writers forced (APS5_CPU_COPIES=1) 88,696 0 60 88,636
default 136,570 0 65 136,505

The pending-only route comes in short bursts during level loads, then stays flat for minutes while small labels keep arriving. With copied writers forced it went 0 → 23 in the first load and 29 → 60 in a later one, then stayed at 60 for the remaining ~30k labels. In the default run it reached 34, later 65, and stayed at 65 for the last ~60k labels. So the counter does fall back to zero between bursts, and the chain does not keep itself going here. All of these labels were on queue 0.

Frame time, A/B on the same build and the same scene:

  • "PR" is the PR's label path. "main path" is the same build with a local switch that skips the block this PR adds, so labels take main's route.
  • Gang Beasts sits on the title menu with no input, captured with APS5_TRACE_SECONDS=40:20 (aps5-summary.jsonl).
  • The runs alternated three times each on an idle machine: RTX 2080, driver 617.14, Windows 10.0.26200, 1920x1080.
run presents frame p50 frame p99 frame max GPU busy / present driver Packet ms / frame
main path 1 1077 18.77 22.96 24.78 10.95 12.53
PR 1 1198 16.68 17.02 25.75 10.92 9.90
main path 2 1115 17.41 24.92 71.50 11.54 11.31
PR 2 971 19.34 33.80 439.85 12.45 13.37
main path 3 1199 16.68 16.95 17.33 11.06 9.74
PR 3 1198 16.68 18.48 22.68 11.07 9.81

The scene is vsync-bound (16.68 ms) when a run is clean. The spread between runs of the same variant is larger than any difference between the variants:

  • mean p50: 17.57 ms (PR) vs 17.62 ms (main path);
  • mean driver Packet time: 11.03 vs 11.19 ms per frame.

PR run 2 has one 440 ms hitch. I can't tie it to this path: the pending-only route is taken only during level loads, and there was no load in that window. I have the six traces if you want them.

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6335408041 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/8180#issuecomment-6335408041). Originally posted by [ntamas94](https://github.com/ntamas94) on 2026-10-22T07:37:26Z. --- @oneandonlydean I measured whether `PendingCompletionStores` drops back to zero once the copied writers are gone, on Gang Beasts (CUSA04865). I used a local counter (not part of this PR) that sorts every imported label of 8 bytes or less by the route it takes. There were two 5-minute runs through the menu, level0, level4 and level16: | run | small labels | behind a listed copied writer | behind pending completion stores only | on the GPU | |---|---|---|---|---| | copied writers forced (`APS5_CPU_COPIES=1`) | 88,696 | 0 | 60 | 88,636 | | default | 136,570 | 0 | 65 | 136,505 | The pending-only route comes in short bursts during level loads, then stays flat for minutes while small labels keep arriving. With copied writers forced it went 0 → 23 in the first load and 29 → 60 in a later one, then stayed at 60 for the remaining ~30k labels. In the default run it reached 34, later 65, and stayed at 65 for the last ~60k labels. So the counter does fall back to zero between bursts, and the chain does not keep itself going here. All of these labels were on queue 0. Frame time, A/B on the same build and the same scene: - "PR" is the PR's label path. "main path" is the same build with a local switch that skips the block this PR adds, so labels take main's route. - Gang Beasts sits on the title menu with no input, captured with `APS5_TRACE_SECONDS=40:20` (`aps5-summary.jsonl`). - The runs alternated three times each on an idle machine: RTX 2080, driver 617.14, Windows 10.0.26200, 1920x1080. | run | presents | frame p50 | frame p99 | frame max | GPU busy / present | driver `Packet` ms / frame | |---|---|---|---|---|---|---| | main path 1 | 1077 | 18.77 | 22.96 | 24.78 | 10.95 | 12.53 | | PR 1 | 1198 | 16.68 | 17.02 | 25.75 | 10.92 | 9.90 | | main path 2 | 1115 | 17.41 | 24.92 | 71.50 | 11.54 | 11.31 | | PR 2 | 971 | 19.34 | 33.80 | 439.85 | 12.45 | 13.37 | | main path 3 | 1199 | 16.68 | 16.95 | 17.33 | 11.06 | 9.74 | | PR 3 | 1198 | 16.68 | 18.48 | 22.68 | 11.07 | 9.81 | The scene is vsync-bound (16.68 ms) when a run is clean. The spread between runs of the same variant is larger than any difference between the variants: - mean p50: 17.57 ms (PR) vs 17.62 ms (main path); - mean driver `Packet` time: 11.03 vs 11.19 ms per frame. PR run 2 has one 440 ms hitch. I can't tie it to this path: the pending-only route is taken only during level loads, and there was no load in that window. I have the six traces if you want them. 🤖 Generated with [Claude Code](https://claude.com/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!8180
No description provided.