AGC: sets that sample a depth surface never pass the fast proof (no record) #1132

Closed
opened 2026-10-07 13:24:17 +00:00 by fisherjoey · 2 comments
fisherjoey commented 2026-10-07 13:24:17 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-07T13:24:17Z.


Summary

cachedTexture (Graphics/src/ShaderResources.cpp:285 on main e79c971f) returns DepthSurfaceTexture's object before any logLookup. A set that samples a depth surface therefore has no lookup record for that element, so fastRevalidate fails with no record (:1446) on every reuse and Revalidate takes the full walk. The walk then succeeds, because the depth surface hands out the same object each time, so the only cost is one full walk per dispatch.

Evidence

Demon's Souls (PPSA01341 v1.07), PS Studios movie, per 10 s:

  • [rescache] revalidate 90839 calls 4934.6 ms: fast 72142, full 18697. Fast-fail no record 18100. Full walks 3574 ms (191 us each).
  • [recipe] indirect: proofs fast 2187, full 9547, 133.6 us per proof.

The attract movie shows the same pattern: about 15k no record fast-fails per 10 s.

Proposed fix

  • The depth return logs a record flagged as depth, and ValidatedSurface carries the flag.
  • Both fast proofs (fastRevalidate, fastRevalidateEach) prove a depth element with a new DepthSurfaceHolds(context, address, texture): the newest surface at the address still hands out that object, which is what the walk's DepthSurfaceTexture lookup would return. The memory, keys and pending checks are skipped for that element.
  • A new fast-fail reason, depth surface, covers the case where the surface no longer hands it out.

Measured on the movie, per 10 s:

before (two runs) after
revalidate calls: fast / full 72142 / 18697 101101 / 2617
indirect proofs: fast / T1 refreshed / full 2187 / not logged / 9547 3017 / 8396 / 463
proof per hit 140.5 us 112.7 us
indirect device call 193.9-229.6 us 145.7 us

The fps did not change on its own: queue 0's wait for the GPU mutex took up the time saved (254-255 presents per 10 s before, 255 after). agc_driver_graphics and guest_agc_driver_resources pass.

#425 and #454 change the same lookup: per-use depth copies that never serve templates, and retired surfaces. A depth record would have to skip per-use copies, and DepthSurfaceHolds would have to treat a retired surface as not holding. I'd base the change on those if they land first.

Found on Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti (595.91.07), with Demon's Souls PPSA01341 v1.07. Measured on main at c1241ad0 with #157, #861, #864 and #1051, plus the path fix from #1047.

I can send a PR for this if the approach looks right.

AI-assisted: yes.

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5745734509 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1132). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-07T13:24:17Z. --- ### Summary `cachedTexture` (`Graphics/src/ShaderResources.cpp:285` on `main` e79c971f) returns `DepthSurfaceTexture`'s object before any `logLookup`. A set that samples a depth surface therefore has no lookup record for that element, so `fastRevalidate` fails with `no record` (:1446) on every reuse and `Revalidate` takes the full walk. The walk then succeeds, because the depth surface hands out the same object each time, so the only cost is one full walk per dispatch. ### Evidence Demon's Souls (PPSA01341 v1.07), PS Studios movie, per 10 s: - `[rescache] revalidate 90839 calls 4934.6 ms: fast 72142, full 18697`. Fast-fail `no record` 18100. Full walks 3574 ms (191 us each). - `[recipe] indirect`: proofs fast 2187, full 9547, 133.6 us per proof. The attract movie shows the same pattern: about 15k `no record` fast-fails per 10 s. ### Proposed fix - The depth return logs a record flagged as depth, and `ValidatedSurface` carries the flag. - Both fast proofs (`fastRevalidate`, `fastRevalidateEach`) prove a depth element with a new `DepthSurfaceHolds(context, address, texture)`: the newest surface at the address still hands out that object, which is what the walk's `DepthSurfaceTexture` lookup would return. The memory, keys and pending checks are skipped for that element. - A new fast-fail reason, `depth surface`, covers the case where the surface no longer hands it out. Measured on the movie, per 10 s: | | before (two runs) | after | |---|---|---| | revalidate calls: fast / full | 72142 / 18697 | 101101 / 2617 | | indirect proofs: fast / T1 refreshed / full | 2187 / not logged / 9547 | 3017 / 8396 / 463 | | proof per hit | 140.5 us | 112.7 us | | indirect device call | 193.9-229.6 us | 145.7 us | The fps did not change on its own: queue 0's wait for the GPU mutex took up the time saved (254-255 presents per 10 s before, 255 after). `agc_driver_graphics` and `guest_agc_driver_resources` pass. #425 and #454 change the same lookup: per-use depth copies that never serve templates, and retired surfaces. A depth record would have to skip per-use copies, and `DepthSurfaceHolds` would have to treat a retired surface as not holding. I'd base the change on those if they land first. Found on Linux 7.2 (Nobara 44), GCC 16, RTX 5070 Ti (595.91.07), with Demon's Souls PPSA01341 v1.07. Measured on `main` at c1241ad0 with #157, #861, #864 and #1051, plus the path fix from #1047. I can send a PR for this if the approach looks right. AI-assisted: yes.
fisherjoey commented 2026-10-07 18:01:17 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-07T18:01:17Z.


The fix described above is ready on a branch, rebased on current main (cea1ef13): https://github.com/fisherjoey/AnyPS5/compare/main...fisherjoey:AnyPS5:fix/depth-surface-record

One commit. It adds the depth record, DepthSurfaceHolds in both fast proofs, and a depth surface fast-fail reason. The full walk is unchanged. agc_driver and guest_agc_driver pass (159 of 159; agc_driver_lds_atomics64 and agc_driver_scalar_sop1 excluded, they fail on this GPU on main too). It has no new test, since the proof path would need a real draw into a depth target.

I'll open the PR if the approach looks right.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6043781959 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1132#issuecomment-6043781959). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-07T18:01:17Z. --- The fix described above is ready on a branch, rebased on current `main` (cea1ef13): https://github.com/fisherjoey/AnyPS5/compare/main...fisherjoey:AnyPS5:fix/depth-surface-record One commit. It adds the depth record, `DepthSurfaceHolds` in both fast proofs, and a `depth surface` fast-fail reason. The full walk is unchanged. `agc_driver` and `guest_agc_driver` pass (159 of 159; `agc_driver_lds_atomics64` and `agc_driver_scalar_sop1` excluded, they fail on this GPU on `main` too). It has no new test, since the proof path would need a real draw into a depth target. I'll open the PR if the approach looks right.
klosixgaming-arch commented 2026-10-08 11:53:07 +00:00 (Migrated from github.com)
Author
Contributor

Imported from boykopovar/AnyPS5. Originally posted by klosixgaming-arch on 2026-10-08T11:53:07Z.


This is a valuable performance optimization for depth surface validation. Based on my review of recent PRs related to the AGC driver and shader recompiler, I can provide some context:

The issue correctly identifies that cachedTexture returns DepthSurfaceTexture's object before any logLookup, which means sets that sample a depth surface never pass the fast proof. The proposed fix of logging a record flagged as depth and proving it with a new DepthSurfaceHolds check seems reasonable.

Some observations based on similar issues I've seen:

  1. The measured improvements (revalidate calls: full walks reduced from 18697 to 2617 per 10 s) are significant
  2. The fact that the fps didn't change on its own (queue 0's wait for the GPU mutex took up the time saved) suggests this optimization should be combined with other improvements for maximum benefit
  3. The coordination needed with PRs #425 and #454 is important to ensure compatibility

I'd suggest implementing this fix, as it addresses a real performance bottleneck in depth surface validation that affects many titles.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6059266612 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/1132#issuecomment-6059266612). Originally posted by [klosixgaming-arch](https://github.com/klosixgaming-arch) on 2026-10-08T11:53:07Z. --- This is a valuable performance optimization for depth surface validation. Based on my review of recent PRs related to the AGC driver and shader recompiler, I can provide some context: The issue correctly identifies that `cachedTexture` returns `DepthSurfaceTexture`'s object before any `logLookup`, which means sets that sample a depth surface never pass the fast proof. The proposed fix of logging a record flagged as depth and proving it with a new `DepthSurfaceHolds` check seems reasonable. Some observations based on similar issues I've seen: 1. The measured improvements (revalidate calls: full walks reduced from 18697 to 2617 per 10 s) are significant 2. The fact that the fps didn't change on its own (queue 0's wait for the GPU mutex took up the time saved) suggests this optimization should be combined with other improvements for maximum benefit 3. The coordination needed with PRs #425 and #454 is important to ensure compatibility I'd suggest implementing this fix, as it addresses a real performance bottleneck in depth surface validation that affects many titles.
Sign in to join this conversation.
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#1132
No description provided.