fix(agc): preserve storage image dependencies during ahead dispatch capture #4724

Closed
Scramblrrrr wants to merge 2 commits from upstream-pr/4724 into main
Scramblrrrr commented 2026-10-12 19:48:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T19:48:20Z.


What

A compute shader can write indirect dispatch arguments through a storage image. Ahead capture currently records only guest-buffer write ranges, so it can resolve the later CPU/thread-dimension indirect dispatch before that image writer executes and reuse stale counts.

The synthetic regression starts with 1x2x2 arguments, writes X=3 through an R32 storage image, and counts the following dispatch's invocations. The pre-fix CPU path dispatched 4 instead of 12 groups. The GPU indirect path already passes.

Include written direct GuestImages/StorageImage surface ranges, including their DCC metadata, in the existing ahead dependency scan. Proven read-only image elements are excluded. The existing overlap check then leaves the dependent dispatch for normal ordered execution instead of parking stale arguments. This does not add runtime image-table store support.

Unbound storage slots are skipped before descriptor decoding, matching the storage binder. The fixture also stores to an unbound slot alongside the real surface; decoding that slot first would terminate the ahead queue with a null-base error.

The fixture is entirely synthetic; no title shader, capture or assets are included. Related #4586 tracks CP packet writes in the same ahead walk; this change covers shader storage-image writes through appendWrittenRanges and has no dependency on that PR. No 007 performance or title-stop claim is made.

Tested

Windows 11, GCC 15.2, NVIDIA RTX 5070 Ti, Release, SPIRV-Tools OFF; head 22b4d43f42 on main 88107b7de6.

  • Native GPU execution: both image-indirect variants and the existing buffer-written indirect regression pass, 3/3 in 1.22 seconds, no skips.
  • Earlier production-only negative control on base 2f4cc8983 restores that base's WrittenBuffers.cpp while leaving the fixture and registration unchanged: the CPU image case fails with 1x2x2/counter 4; the GPU image and buffer cases pass. Restore/rebuild passes all three.
  • Null-slot production-only negative: retain the extended two-store fixture and restore WrittenBuffers.cpp from 964bf62f; both image-indirect variants fail with guest texture descriptor has a null base address. Restore/rebuild passes all three controls.
  • Branch conventions and git diff --check pass. Linux/macOS have not been tested locally; CI results pending.

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; no silent stubs added
  • No notes, investigation Markdown files or images added to the repository
  • No new third-party code
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: none confirmed; investigated alongside #2523
  • AI-assisted: yes, Codex
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4834252489 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4724). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T19:48:20Z. --- ### What A compute shader can write indirect dispatch arguments through a storage image. Ahead capture currently records only guest-buffer write ranges, so it can resolve the later CPU/thread-dimension indirect dispatch before that image writer executes and reuse stale counts. The synthetic regression starts with 1x2x2 arguments, writes X=3 through an R32 storage image, and counts the following dispatch's invocations. The pre-fix CPU path dispatched 4 instead of 12 groups. The GPU indirect path already passes. Include written direct GuestImages/StorageImage surface ranges, including their DCC metadata, in the existing ahead dependency scan. Proven read-only image elements are excluded. The existing overlap check then leaves the dependent dispatch for normal ordered execution instead of parking stale arguments. This does not add runtime image-table store support. Unbound storage slots are skipped before descriptor decoding, matching the storage binder. The fixture also stores to an unbound slot alongside the real surface; decoding that slot first would terminate the ahead queue with a null-base error. The fixture is entirely synthetic; no title shader, capture or assets are included. Related #4586 tracks CP packet writes in the same ahead walk; this change covers shader storage-image writes through appendWrittenRanges and has no dependency on that PR. No 007 performance or title-stop claim is made. ### Tested Windows 11, GCC 15.2, NVIDIA RTX 5070 Ti, Release, SPIRV-Tools OFF; head 22b4d43f42a5ed134e39fff17108b4049e6b3c72 on main 88107b7de6cd7c7952c496345ffc4f413bef374b. - Native GPU execution: both image-indirect variants and the existing buffer-written indirect regression pass, 3/3 in 1.22 seconds, no skips. - Earlier production-only negative control on base 2f4cc8983 restores that base's WrittenBuffers.cpp while leaving the fixture and registration unchanged: the CPU image case fails with 1x2x2/counter 4; the GPU image and buffer cases pass. Restore/rebuild passes all three. - Null-slot production-only negative: retain the extended two-store fixture and restore WrittenBuffers.cpp from 964bf62f; both image-indirect variants fail with guest texture descriptor has a null base address. Restore/rebuild passes all three controls. - Branch conventions and git diff --check pass. Linux/macOS have not been tested locally; CI results pending. ### 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 - [x] Unimplemented paths throw; no silent stubs added - [x] No notes, investigation Markdown files or images added to the repository - [x] No new third-party code - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: none confirmed; investigated alongside #2523 - [x] AI-assisted: yes, Codex
Scramblrrrr commented 2026-10-12 21:57:20 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T21:57:20Z.


Acknowledged the #4662 overlap. The reported CMakeLists.txt hunk registers independent native fixtures: this PR's storage-image ahead-dependency check and #4662's GPU-mapping-on-fiber check. The production fixes are in different paths, and neither requires the other. When combining the test-registration hunks, both entries must be retained. Current GitHub mergeability is MERGEABLE. This comment is scope/registration analysis, not a claim of a combined game or native test. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6133357029 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4724#issuecomment-6133357029). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T21:57:20Z. --- Acknowledged the #4662 overlap. The reported CMakeLists.txt hunk registers independent native fixtures: this PR's storage-image ahead-dependency check and #4662's GPU-mapping-on-fiber check. The production fixes are in different paths, and neither requires the other. When combining the test-registration hunks, both entries must be retained. Current GitHub mergeability is MERGEABLE. This comment is scope/registration analysis, not a claim of a combined game or native test. AI-assisted: Codex.
Scramblrrrr commented 2026-10-12 22:44:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T22:44:27Z.


Windows/RTX5070Ti/GCC15.2 runtime-port cross-test e5b9cd193 (https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-host-write-image-ahead), on our experimental007 runtime-table stack plus revised shared-host-write tracking. Fixture source matches this PR; production adapts surface-span lookup to that stack's existing API. No title data is part of the fixture.

Native image-indirect CPU/thread-dimensions, image-indirect GPU control and buffer-indirect control3/3 PASS1.82s. Production-only negative restores WrittenBuffers.cpp from preceding09f0f6394, fixtures/CMake unchanged: thread-dimensions FAIL, counter4 instead of12; GPU image and buffer controls PASS. Restored/touched/rebuilt positive3/3 PASS1.31s; no skips. Source clean. This is not a current-main-only/full-suite test.

Only patched graphics650B9EAD4A1AD5DE5A29323FA4430EABE20A82DBDD11CD0FAE6A47C582AD18FA now staged; revised libcA1AE7842 unchanged. Normal warm-cache/cache16 game run starting, no sampler/profile or concurrent builds/native tests. No007 rendering/crash/FPS claim yet. AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6134050570 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4724#issuecomment-6134050570). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T22:44:27Z. --- Windows/RTX5070Ti/GCC15.2 runtime-port cross-test e5b9cd193 (https://github.com/Scramblrrrr/AnyPS5/tree/codex/first-light-host-write-image-ahead), on our experimental007 runtime-table stack plus revised shared-host-write tracking. Fixture source matches this PR; production adapts surface-span lookup to that stack's existing API. No title data is part of the fixture. Native image-indirect CPU/thread-dimensions, image-indirect GPU control and buffer-indirect control3/3 PASS1.82s. Production-only negative restores WrittenBuffers.cpp from preceding09f0f6394, fixtures/CMake unchanged: thread-dimensions FAIL, counter4 instead of12; GPU image and buffer controls PASS. Restored/touched/rebuilt positive3/3 PASS1.31s; no skips. Source clean. This is not a current-main-only/full-suite test. Only patched graphics650B9EAD4A1AD5DE5A29323FA4430EABE20A82DBDD11CD0FAE6A47C582AD18FA now staged; revised libcA1AE7842 unchanged. Normal warm-cache/cache16 game run starting, no sampler/profile or concurrent builds/native tests. No007 rendering/crash/FPS claim yet. AI-assisted: Codex.
Scramblrrrr commented 2026-10-12 22:55:19 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-12T22:55:19Z.


Image-ordering runtime port e5b9cd193/graphics650B9EAD/libcA1AE7842/cache16 ended intentionally22:54:41.830UTC, ~3m03 after Resume22:51:38.445, not a crash. Final frame1982/~0.19FPS, bright shape over black; same incomplete scene. Last private22.817GB/free4.700GB. Four bounded working-set trims during the full run (including startup); FPS is not a clean benchmark. Runtime image-table deferred write-backs remain unsupported. No clear007 rendering/FPS improvement from #4724 in this single run; native ordering red/green proof remains separate.

Prepared existing #4535 652cb0b author-preserved port on this stack, codex/first-light-deferred-shared-tracking head4135e2871, preserving newer #4661 host-write correction, per4KiB settlement and local alias mappings. Details on #4535. Native build started only after game ended; nothing from that branch staged yet. Still leaving runtime-table stores/reference-texture work to SleglJan; branch heads unchanged at last check.

AI-assisted: Codex.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6134187512 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4724#issuecomment-6134187512). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-12T22:55:19Z. --- Image-ordering runtime port e5b9cd193/graphics650B9EAD/libcA1AE7842/cache16 ended intentionally22:54:41.830UTC, ~3m03 after Resume22:51:38.445, not a crash. Final frame1982/~0.19FPS, bright shape over black; same incomplete scene. Last private22.817GB/free4.700GB. Four bounded working-set trims during the full run (including startup); FPS is not a clean benchmark. Runtime image-table deferred write-backs remain unsupported. No clear007 rendering/FPS improvement from #4724 in this single run; native ordering red/green proof remains separate. Prepared existing #4535 652cb0b author-preserved port on this stack, codex/first-light-deferred-shared-tracking head4135e2871, preserving newer #4661 host-write correction, per4KiB settlement and local alias mappings. Details on #4535. Native build started only after game ended; nothing from that branch staged yet. Still leaving runtime-table stores/reference-texture work to SleglJan; branch heads unchanged at last check. AI-assisted: Codex.
Scramblrrrr commented 2026-10-13 05:54:46 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T05:54:46Z.


Rebased and pushed 964bf62f05 on main 88107b7de6. Preserved the new GPU-map-on-fiber library link alongside our thread-dimensions test registration. Windows Release / GCC15.2 / RTX5070Ti, Vulkan required: CPU image-indirect, GPU image-indirect, buffer-written indirect 3/3 PASS 2.76 s, no skips. Scoped conventions/diff checks pass; source clean. Only test-registration conflict resolved; production behavior unchanged. Earlier negative evidence remains labeled with its original base in the description. Nothing from this current-main build was staged into 007. AI-assisted (Codex).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6139246510 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4724#issuecomment-6139246510). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-13T05:54:46Z. --- Rebased and pushed 964bf62f05031c3b45775b493aea13b93ea6f1f6 on main 88107b7de6cd7c7952c496345ffc4f413bef374b. Preserved the new GPU-map-on-fiber library link alongside our thread-dimensions test registration. Windows Release / GCC15.2 / RTX5070Ti, Vulkan required: CPU image-indirect, GPU image-indirect, buffer-written indirect 3/3 PASS 2.76 s, no skips. Scoped conventions/diff checks pass; source clean. Only test-registration conflict resolved; production behavior unchanged. Earlier negative evidence remains labeled with its original base in the description. Nothing from this current-main build was staged into 007. AI-assisted (Codex).
SleglJan commented 2026-10-13 14:52:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-13T14:52:37Z.


Review finding from a stack carrying this change (pre-rebase 6b6abed5e, same loop; Linux, GCC 16.2.1, RTX 3080, NVIDIA 615.71.09; 007 First Light), line numbers from head 964bf62f0.

Mechanism: the loop this PR adds to appendWrittenRanges (WrittenBuffers.cpp 27-37) decodes every written storage element with DecodeTextureResource, whose null-base check throws guest texture descriptor has a null base address (GuestTextureResource.cpp:58). The binder treats such an element as an unbound slot and binds no guest surface for it (ShaderResources.cpp:3343: words[0] == 0u && (words[1] & 0xffu) == 0u), so a dispatch with an unbound storage slot is valid on main; when the ahead resolver (queues other than 0) reaches it, this loop throws on its compiled result. The resource.baseAddress != 0 test on line 34 never sees a zero, since the decode throws first. The call at DispatchAhead.cpp:173 sits after the try around the ahead dispatch(...) (155-158) and nothing on the way out catches it, so the queue worker's catch (...) reports it (QueueWorker.cpp:218-221); ReportFailure hands it to the video output, and the presenter ends the process with [videoout] presentation failed: AGC graphics: guest texture descriptor has a null base address, without the compute shader 0x...: prefix the dispatch catches add, which is how it was traced here. Two runs on our stack ended this way.

Fix: apply the binder's rule before the decode, or IsNullTextureResource from #4779 if that lands first (it also treats TYPE=0 as null, on which this loop would otherwise throw unsupported image type 0). On our stack the same decode in #1201's DrawWriteRanges is covered by a unit test (a two-element StorageImage binding, one zeroed and one real descriptor: throws before, one range after); appendWrittenRanges being a private static of Driver, this PR's fixture could add an unbound slot to its dispatch instead.

AI-assisted: yes (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148352503 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4724#issuecomment-6148352503). Originally posted by [SleglJan](https://github.com/SleglJan) on 2026-10-13T14:52:37Z. --- Review finding from a stack carrying this change (pre-rebase 6b6abed5e, same loop; Linux, GCC 16.2.1, RTX 3080, NVIDIA 615.71.09; 007 First Light), line numbers from head 964bf62f0. Mechanism: the loop this PR adds to `appendWrittenRanges` (`WrittenBuffers.cpp` 27-37) decodes every written storage element with `DecodeTextureResource`, whose null-base check throws `guest texture descriptor has a null base address` (`GuestTextureResource.cpp:58`). The binder treats such an element as an unbound slot and binds no guest surface for it (`ShaderResources.cpp:3343`: `words[0] == 0u && (words[1] & 0xffu) == 0u`), so a dispatch with an unbound storage slot is valid on main; when the ahead resolver (queues other than 0) reaches it, this loop throws on its compiled result. The `resource.baseAddress != 0` test on line 34 never sees a zero, since the decode throws first. The call at `DispatchAhead.cpp:173` sits after the `try` around the ahead `dispatch(...)` (155-158) and nothing on the way out catches it, so the queue worker's `catch (...)` reports it (`QueueWorker.cpp:218-221`); `ReportFailure` hands it to the video output, and the presenter ends the process with `[videoout] presentation failed: AGC graphics: guest texture descriptor has a null base address`, without the `compute shader 0x...:` prefix the dispatch catches add, which is how it was traced here. Two runs on our stack ended this way. Fix: apply the binder's rule before the decode, or `IsNullTextureResource` from #4779 if that lands first (it also treats TYPE=0 as null, on which this loop would otherwise throw `unsupported image type 0`). On our stack the same decode in #1201's `DrawWriteRanges` is covered by a unit test (a two-element `StorageImage` binding, one zeroed and one real descriptor: throws before, one range after); `appendWrittenRanges` being a private static of `Driver`, this PR's fixture could add an unbound slot to its dispatch instead. AI-assisted: yes (Claude Code).
Scramblrrrr commented 2026-10-13 15:23:44 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T15:23:44Z.


Thanks for tracing this. I reproduced the mismatch in source: the storage binder checks the null base before decode, while appendWrittenRanges decodes first. I have prepared the matching pre-decode null-base guard and extended this PR's existing ahead image-indirect fixture to issue a store to an unbound slot alongside the real surface. I will validate the new fixture against the old production loop, then restore/rebuild positives before pushing. #4779 remains open; this correction follows the existing binder rule and does not assume its broader TYPE=0 handling. Nothing from this revision is staged into the running game yet.

AI-assisted: yes (Codex).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6148983424 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4724#issuecomment-6148983424). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-13T15:23:44Z. --- Thanks for tracing this. I reproduced the mismatch in source: the storage binder checks the null base before decode, while appendWrittenRanges decodes first. I have prepared the matching pre-decode null-base guard and extended this PR's existing ahead image-indirect fixture to issue a store to an unbound slot alongside the real surface. I will validate the new fixture against the old production loop, then restore/rebuild positives before pushing. #4779 remains open; this correction follows the existing binder rule and does not assume its broader TYPE=0 handling. Nothing from this revision is staged into the running game yet. AI-assisted: yes (Codex).
Scramblrrrr commented 2026-10-13 15:29:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Scramblrrrr on 2026-10-13T15:29:50Z.


Fixed and pushed 22b4d43f42. appendWrittenRanges now applies the binder's null-base rule before DecodeTextureResource. The synthetic shader stores to a null slot and the real argument image; both CPU/thread-dimension and GPU variants still finish with the expected 3x2x2 arguments /12 invocations.

Windows Release /GCC15.2/RTX5070Ti, Vulkan required: restored final3/3 controls PASS1.22s, no skips. Production-only negative retains extended fixture and restores WrittenBuffers.cpp from964bf62f: both image-indirect variants FAIL with guest texture descriptor has a null base address. This reproduces the review finding independently of title data. Source/conventions/diff clean, description updated. #4779's broader TYPE=0 rule remains a separate open change. Not yet staged into007.

Thanks for the precise trace. AI-assisted: yes (Codex).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6149104201 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4724#issuecomment-6149104201). Originally posted by [Scramblrrrr](https://github.com/Scramblrrrr) on 2026-10-13T15:29:50Z. --- Fixed and pushed 22b4d43f42a5ed134e39fff17108b4049e6b3c72. appendWrittenRanges now applies the binder's null-base rule before DecodeTextureResource. The synthetic shader stores to a null slot and the real argument image; both CPU/thread-dimension and GPU variants still finish with the expected 3x2x2 arguments /12 invocations. Windows Release /GCC15.2/RTX5070Ti, Vulkan required: restored final3/3 controls PASS1.22s, no skips. Production-only negative retains extended fixture and restores WrittenBuffers.cpp from964bf62f: both image-indirect variants FAIL with guest texture descriptor has a null base address. This reproduces the review finding independently of title data. Source/conventions/diff clean, description updated. #4779's broader TYPE=0 rule remains a separate open change. Not yet staged into007. Thanks for the precise trace. AI-assisted: yes (Codex).
oneandonlydean commented 2026-10-14 02:32:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-14T02:32:34Z.


Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6159583467 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4724#issuecomment-6159583467). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-14T02:32:34Z. --- Closing: no title is known to reach this. With the queue at 700+ open PRs, please hold off on new PRs that don't name a title needing the change until it's down. If a title stops on this on current main, reopen with the title ID and the log line.

Pull request closed

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!4724
No description provided.