feat(agc): store pending storage-image results before each GPU label with APS5_STORE_AT_LABEL #5324

Merged
lubaxe merged 1 commit from upstream-pr/5324 into main 2026-10-14 12:18:58 +00:00
lubaxe commented 2026-10-13 17:12:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by lubaxe on 2026-10-13T17:12:40Z.


What

Pending storage-image results stay on the GPU until something reads their memory through the flush hook. A title's own CPU reads do not go through it. A title that waits for a label the GPU writes after its work (RELEASE_MEM, WRITE_DATA, DMA_DATA) and then reads the results with the CPU reads stale memory. On the console the results are in memory once the label is.

PPSA06694 (Remnant 2, UE5) reads its HZB occlusion results this way (Remnant2.exe+0x2f8e75d). The CPU read stale zeros and treated every object as occluded, so the title drew its logo mesh on the first frame only, and later the Create Character screen shows no character.

APS5_STORE_AT_LABEL=1 stores every pending result at the start of VulkanDevice::WriteLabelOnGpu, through StorageTexture::FlushAllPending, before the label is recorded or written. It is parsed like APS5_STORE_AT_FLIP (#1995): unset is off, 1 is on, any other value throws. Off by default: it stores every pending image at each label, not only the ones the waited-for work wrote. In PPSA06694 it costs more than half the presents (in 75 s runs dumping every 30th present, 21 frames without it, 9 with it). docs/user/USAGE.md and the technical debt entry for pending results describe it.

Tested

  • Windows 11 Pro, Ryzen 7 9800X3D, RTX 5090 (driver 617.42), WinLibs GCC 15.2.0 r7, Release.
  • storeAtLabelTests in agc_driver_graphics checks the switch: unset is off, 1 is on, and 0, empty, true and 11 are rejected. On main it does not build (no StoreAtLabelRequested). WriteLabelOnGpu needs a recorder, so the flush itself is covered only by the title runs.
  • ctest on main e0d388fa with this change: 1080 of 1081 passed. The failure is agc_driver_pixel_lds, which also fails on unmodified main on this GPU. Rebased onto main 61b8742b; there agc_driver_graphics passes.
  • PPSA06694 with #5321, #5322 and #5323: with APS5_STORE_AT_LABEL=1, 8 of 8 runs show the character on the Create Character screen; without it, 4 of 4 show none.
  • tools/check_conventions.py --base origin/main passes.

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
  • Unblocks: PPSA06694 #5320
  • GPUs tested: NVIDIA GeForce RTX 5090, driver 617.42, Windows 11 Pro
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4846805968 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5324). Originally posted by [lubaxe](https://github.com/lubaxe) on 2026-10-13T17:12:40Z. --- ### What Pending storage-image results stay on the GPU until something reads their memory through the flush hook. A title's own CPU reads do not go through it. A title that waits for a label the GPU writes after its work (`RELEASE_MEM`, `WRITE_DATA`, `DMA_DATA`) and then reads the results with the CPU reads stale memory. On the console the results are in memory once the label is. PPSA06694 (Remnant 2, UE5) reads its HZB occlusion results this way (`Remnant2.exe+0x2f8e75d`). The CPU read stale zeros and treated every object as occluded, so the title drew its logo mesh on the first frame only, and later the Create Character screen shows no character. `APS5_STORE_AT_LABEL=1` stores every pending result at the start of `VulkanDevice::WriteLabelOnGpu`, through `StorageTexture::FlushAllPending`, before the label is recorded or written. It is parsed like `APS5_STORE_AT_FLIP` (#1995): unset is off, `1` is on, any other value throws. Off by default: it stores every pending image at each label, not only the ones the waited-for work wrote. In PPSA06694 it costs more than half the presents (in 75 s runs dumping every 30th present, 21 frames without it, 9 with it). `docs/user/USAGE.md` and the technical debt entry for pending results describe it. ### Tested - Windows 11 Pro, Ryzen 7 9800X3D, RTX 5090 (driver 617.42), WinLibs GCC 15.2.0 r7, Release. - `storeAtLabelTests` in `agc_driver_graphics` checks the switch: unset is off, `1` is on, and `0`, empty, `true` and `11` are rejected. On `main` it does not build (no `StoreAtLabelRequested`). `WriteLabelOnGpu` needs a recorder, so the flush itself is covered only by the title runs. - `ctest` on `main` e0d388fa with this change: 1080 of 1081 passed. The failure is `agc_driver_pixel_lds`, which also fails on unmodified `main` on this GPU. Rebased onto `main` 61b8742b; there `agc_driver_graphics` passes. - PPSA06694 with #5321, #5322 and #5323: with `APS5_STORE_AT_LABEL=1`, 8 of 8 runs show the character on the Create Character screen; without it, 4 of 4 show none. - `tools/check_conventions.py --base origin/main` passes. ### 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] Unblocks: PPSA06694 #5320 - [x] GPUs tested: NVIDIA GeForce RTX 5090, driver 617.42, Windows 11 Pro - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
MarcZX10 commented 2026-10-13 19:46:40 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T19:46:40Z.


New issue #5437 reports that the second and third RELEASE_MEM label writes after dispatches stay invisible to following WAIT_REG_MEM commands in the same submission; APS5_DRAIN_ALL=1 makes the waits advance. Your opt-in APS5_STORE_AT_LABEL=1 flushes pending storage-image results before label writes, so it may be relevant, but the issue has not tested this PR and the failure could still be in deferred-label/submission ordering. I linked it on the issue and asked the reporter to try the PR if possible; sharing here so you can assess whether it needs a targeted test.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6153805240 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5324#issuecomment-6153805240). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T19:46:40Z. --- New issue [#5437](https://github.com/boykopovar/AnyPS5/issues/5437) reports that the second and third `RELEASE_MEM` label writes after dispatches stay invisible to following `WAIT_REG_MEM` commands in the same submission; `APS5_DRAIN_ALL=1` makes the waits advance. Your opt-in `APS5_STORE_AT_LABEL=1` flushes pending storage-image results before label writes, so it may be relevant, but the issue has not tested this PR and the failure could still be in deferred-label/submission ordering. I linked it on the issue and asked the reporter to try the PR if possible; sharing here so you can assess whether it needs a targeted test.
MarcZX10 commented 2026-10-13 20:42:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-13T20:42:26Z.


The overlap check with #5460 only reports the docs/user/USAGE.md hunk for environment-variable documentation. #5324's label flush and #5460's device-fault reporting do not share implementation files, so they appear independent; no dependency is needed. If either lands first, the second may need to refresh that documentation hunk.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6154798150 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5324#issuecomment-6154798150). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-13T20:42:26Z. --- The overlap check with #5460 only reports the `docs/user/USAGE.md` hunk for environment-variable documentation. #5324's label flush and #5460's device-fault reporting do not share implementation files, so they appear independent; no dependency is needed. If either lands first, the second may need to refresh that documentation hunk.
Tamalero commented 2026-10-13 22:17:04 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Tamalero on 2026-10-13T22:17:04Z.


A data point from High on Life (PPSA15388, UE4) for whoever enables this, since the switch exists for titles that read GPU results on the CPU after a label.

I ran a local version of the same idea: store every pending result before the labels are recorded. Mine hooked recordDeferredLabels rather than WriteLabelOnGpu, so the placement differs slightly. Results:

  • On an older main (3377986a) it helped. High on Life reads its sky-light SH and capture brightness back after a label, and with the store the values were right: the SkyIrradianceEnvironmentMap buffer held 0.734 in L0, where it had stale zeros before.
  • On main 18c438b10 it does the opposite. With the switch on, the home base renders black, with only emissive surfaces left in banded false colour. Dumps of the scene colour (RGBA16F) after the reflection-environment pass are 0 for every pixel, and the maximum falls from frame to frame (0.0013 … 0.00000026), which looks like a pre-exposure that keeps shrinking. With the switch off on the same build, the scene renders fully lit and matches the PC version. Today's storage write-back changes on main seem to cover what this title needed.

I haven't found which stored image does the damage. My guess is the auto-exposure chain, but that's a guess. So the switch is not a safe general default for UE4 titles. For High on Life on current main it should stay off. If someone sees a title regress with it on, this is one shape it takes. Details are on #4736.

Tested and written by Claude (AI assistant) on a contributor's machine.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6156379379 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5324#issuecomment-6156379379). Originally posted by [Tamalero](https://github.com/Tamalero) on 2026-10-13T22:17:04Z. --- A data point from High on Life (PPSA15388, UE4) for whoever enables this, since the switch exists for titles that read GPU results on the CPU after a label. I ran a local version of the same idea: store every pending result before the labels are recorded. Mine hooked `recordDeferredLabels` rather than `WriteLabelOnGpu`, so the placement differs slightly. Results: - **On an older `main` (`3377986a`)** it helped. High on Life reads its sky-light SH and capture brightness back after a label, and with the store the values were right: the `SkyIrradianceEnvironmentMap` buffer held 0.734 in L0, where it had stale zeros before. - **On `main` `18c438b10`** it does the opposite. With the switch on, the home base renders black, with only emissive surfaces left in banded false colour. Dumps of the scene colour (RGBA16F) after the reflection-environment pass are 0 for every pixel, and the maximum falls from frame to frame (0.0013 … 0.00000026), which looks like a pre-exposure that keeps shrinking. With the switch off on the same build, the scene renders fully lit and matches the PC version. Today's storage write-back changes on `main` seem to cover what this title needed. I haven't found which stored image does the damage. My guess is the auto-exposure chain, but that's a guess. So the switch is not a safe general default for UE4 titles. For High on Life on current `main` it should stay off. If someone sees a title regress with it on, this is one shape it takes. Details are on #4736. *Tested and written by Claude (AI assistant) on a contributor's machine.*
adriadam10 commented 2026-10-14 11:48:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-14T11:48:31Z.


Checked the diff and rebased onto current main (only the TechnicalDebt line for pending storage-image results conflicted; kept both its text and the new APS5_STORE_AT_LABEL sentence).

  • StoreAtLabelRequested parses like StoreAtFlipRequested: unset is off, 1 is on, anything else throws. storeAtLabelTests does not build without the change.
  • Ran libSceAgcDriver build + ctest on the rebased head: 520/522 pass. agc_recorder_kept_bytes and agc_driver_tessellation fail the same way with the change reverted, so they are not from this PR.
  • The flush itself (WriteLabelOnGpu) needs a recorder and is covered only by the title runs reported in the PR.

Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167642524 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5324#issuecomment-6167642524). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-14T11:48:31Z. --- Checked the diff and rebased onto current `main` (only the TechnicalDebt line for pending storage-image results conflicted; kept both its text and the new `APS5_STORE_AT_LABEL` sentence). - `StoreAtLabelRequested` parses like `StoreAtFlipRequested`: unset is off, `1` is on, anything else throws. `storeAtLabelTests` does not build without the change. - Ran libSceAgcDriver build + ctest on the rebased head: 520/522 pass. `agc_recorder_kept_bytes` and `agc_driver_tessellation` fail the same way with the change reverted, so they are not from this PR. - The flush itself (`WriteLabelOnGpu`) needs a recorder and is covered only by the title runs reported in the PR. Merging once the full Build is green.
github-actions[bot] commented 2026-10-14 11:50:59 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-14T11:50:59Z.


Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.

Pull request Conflicting files (lines on main) Same exports Same new files
#5760 docs/dev/debt/libSceAgcDriver.md L53-54
#5761 docs/dev/debt/libSceAgcDriver.md L53-54
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6167685315 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/5324#issuecomment-6167685315). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-10-14T11:50:59Z. --- <!-- pr-overlap --> Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in **Depends on**. | Pull request | Conflicting files (lines on `main`) | Same exports | Same new files | |---|---|---|---| | #5760 | `docs/dev/debt/libSceAgcDriver.md` [L53-54](https://github.com/boykopovar/AnyPS5/blob/e736e5bdb18e72ed717014c02c62c616701a7cf8/docs/dev/debt/libSceAgcDriver.md#L53-L54) | | | | #5761 | `docs/dev/debt/libSceAgcDriver.md` [L53-54](https://github.com/boykopovar/AnyPS5/blob/e736e5bdb18e72ed717014c02c62c616701a7cf8/docs/dev/debt/libSceAgcDriver.md#L53-L54) | | |
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!5324
No description provided.