agc: a cached template keeps a sampled texture the lookup no longer returns, so Demon's Souls level lighting goes dark at twice the draws #8040

Closed
opened 2026-10-19 18:33:51 +00:00 by fisherjoey · 0 comments
fisherjoey commented 2026-10-19 18:33:51 +00:00 (Migrated from github.com)
Contributor

Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-19T18:33:51Z.


What happens

Demon's Souls (PPSA01341 v1.07, Linux, RTX 5070 Ti, NVIDIA 595.91.07): in the first level after New Game, indirect lighting comes out dark or black, and the title issues about twice as many indexed indirect draws per frame as in a normal run. The frame rate drops by a third, from about 9 to about 5.8 presents per 10 s. On our main-based test sets this happens in roughly 60% of runs.

We measure it per 10 s window as DRAW_INDEX_INDIRECT / (DRAW_INDIRECT + DRAW_INDEX_INDIRECT_MULTI) on queue 0. The denominator is about 24 packets per frame, so the ratio is the title's indexed indirect draws per frame. A normal level sits at 200 to 225; an affected run sits at 410 to 475.

Current main still does it. We ran main 676269473 (this morning's main, which includes #6492) with #6280, #6926, #7844 and a local stencil-export workaround that lets the title reach the level on NVIDIA. Both runs that reached the level with warm shaders crawled: a median ratio over the second half of the level of 414 and 438, at 5.92 and 5.55 presents per 10 s.

Where

A cached ShaderResources (here, dispatch templates) is reused when Revalidate proves it current. The fast proof, fastRevalidate and fastRevalidateEach (ShaderResources.cpp:2823, 2980), proves each bound sampled texture from write stamps, DCC keys and the pending registry. It never checks that the sampled lookup would still return the bound Texture object. Only the full walk (3187) repeats cachedTexture and compares objects, and it runs only when the fast proof fails. So a template whose surface memory has not changed can keep binding an object the lookup no longer returns, in two ways:

  1. The sampled cache drops or replaces the entry. cachedTexture erases an entry it finds changed and makes a new one, and eraseTexture (228) marks a held texture released. Since #6492, the next ResourceCache::Insert (3666) drops every entry holding a released texture. Until that Insert, Find (3485) still returns the template, and its fast proof still passes.
  2. The lookup's answer changes and no lookup runs. cachedTexture chooses between a snapshot and a view of a storage image by SampledFromStorageEligible and the storage registry (709). After a snapshot's surface becomes host-imported, the lookup would return a storage view instead. The cache entry is only replaced when some lookup for that surface runs. A template that is the only user of the surface never runs one, so nothing is released, #6492 has nothing to drop, and the template binds the old snapshot until it leaves the resource cache.

Evidence

All runs: Demon's Souls PPSA01341 v1.07, Linux (Nobara, kernel 7.2), RTX 5070 Ti, driver 595.91.07, 900 s from boot through New Game into the first level. Most of the work was on a set based on main ccb0c0926 (before #6492) with local patches; the PR lists them.

  • A diagnostic run dropped every dispatch template once, early in the level, and diffed each rebuild against the template it replaced. 7 rebuilds bound a different Texture object than the template had, in 5 programs. The textures were a 1600x900 format-71 target and a 1024x512 format-22 surface. In 3 of the 7, the old object was still alive.
  • A second run dropped only the 20 dispatch templates of those 5 programs at the same point and kept the other ~1100. The ratio went from 422 to about 210 in the next window and stayed there to the end of the run (median 214).
  • Before the fixes, 7 of 7 runs with no storage-cache evictions in the level crawled. The first current-main run had none either.
  • A first fix that only failed the fast proof for a texture no longer in the cache (case 1) did not help: 2 of 2 runs crawled. Its check fired 97 and 96 times in those runs, almost all on the title screen, the menu and the load: none after the level started in the first run, and once in the second. That left case 2.

Expected

A cached template should not bind a texture the sampled lookup no longer returns for its surface. A fix with tests follows in a PR.

AI-assisted: yes

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5929377716 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/issues/8040). Originally posted by [fisherjoey](https://github.com/fisherjoey) on 2026-10-19T18:33:51Z. --- ### What happens Demon's Souls (PPSA01341 v1.07, Linux, RTX 5070 Ti, NVIDIA 595.91.07): in the first level after New Game, indirect lighting comes out dark or black, and the title issues about twice as many indexed indirect draws per frame as in a normal run. The frame rate drops by a third, from about 9 to about 5.8 presents per 10 s. On our main-based test sets this happens in roughly 60% of runs. We measure it per 10 s window as `DRAW_INDEX_INDIRECT / (DRAW_INDIRECT + DRAW_INDEX_INDIRECT_MULTI)` on queue 0. The denominator is about 24 packets per frame, so the ratio is the title's indexed indirect draws per frame. A normal level sits at 200 to 225; an affected run sits at 410 to 475. Current main still does it. We ran main 676269473 (this morning's main, which includes #6492) with #6280, #6926, #7844 and a local stencil-export workaround that lets the title reach the level on NVIDIA. Both runs that reached the level with warm shaders crawled: a median ratio over the second half of the level of 414 and 438, at 5.92 and 5.55 presents per 10 s. ### Where A cached `ShaderResources` (here, dispatch templates) is reused when `Revalidate` proves it current. The fast proof, `fastRevalidate` and `fastRevalidateEach` ([ShaderResources.cpp:2823](https://github.com/boykopovar/AnyPS5/blob/f52509acc7d6db75e54d482775b20cc2b7e31057/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L2823), [2980](https://github.com/boykopovar/AnyPS5/blob/f52509acc7d6db75e54d482775b20cc2b7e31057/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L2980)), proves each bound sampled texture from write stamps, DCC keys and the pending registry. It never checks that the sampled lookup would still return the bound `Texture` object. Only the full walk ([3187](https://github.com/boykopovar/AnyPS5/blob/f52509acc7d6db75e54d482775b20cc2b7e31057/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L3187)) repeats `cachedTexture` and compares objects, and it runs only when the fast proof fails. So a template whose surface memory has not changed can keep binding an object the lookup no longer returns, in two ways: 1. The sampled cache drops or replaces the entry. `cachedTexture` erases an entry it finds changed and makes a new one, and `eraseTexture` ([228](https://github.com/boykopovar/AnyPS5/blob/f52509acc7d6db75e54d482775b20cc2b7e31057/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L228-L241)) marks a held texture released. Since #6492, the next `ResourceCache::Insert` ([3666](https://github.com/boykopovar/AnyPS5/blob/f52509acc7d6db75e54d482775b20cc2b7e31057/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L3666-L3669)) drops every entry holding a released texture. Until that Insert, `Find` ([3485](https://github.com/boykopovar/AnyPS5/blob/f52509acc7d6db75e54d482775b20cc2b7e31057/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L3485)) still returns the template, and its fast proof still passes. 2. The lookup's answer changes and no lookup runs. `cachedTexture` chooses between a snapshot and a view of a storage image by `SampledFromStorageEligible` and the storage registry ([709](https://github.com/boykopovar/AnyPS5/blob/f52509acc7d6db75e54d482775b20cc2b7e31057/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp#L709-L716)). After a snapshot's surface becomes host-imported, the lookup would return a storage view instead. The cache entry is only replaced when some lookup for that surface runs. A template that is the only user of the surface never runs one, so nothing is released, #6492 has nothing to drop, and the template binds the old snapshot until it leaves the resource cache. ### Evidence All runs: Demon's Souls PPSA01341 v1.07, Linux (Nobara, kernel 7.2), RTX 5070 Ti, driver 595.91.07, 900 s from boot through New Game into the first level. Most of the work was on a set based on main ccb0c0926 (before #6492) with local patches; the PR lists them. - A diagnostic run dropped every dispatch template once, early in the level, and diffed each rebuild against the template it replaced. 7 rebuilds bound a different `Texture` object than the template had, in 5 programs. The textures were a 1600x900 format-71 target and a 1024x512 format-22 surface. In 3 of the 7, the old object was still alive. - A second run dropped only the 20 dispatch templates of those 5 programs at the same point and kept the other ~1100. The ratio went from 422 to about 210 in the next window and stayed there to the end of the run (median 214). - Before the fixes, 7 of 7 runs with no storage-cache evictions in the level crawled. The first current-main run had none either. - A first fix that only failed the fast proof for a texture no longer in the cache (case 1) did not help: 2 of 2 runs crawled. Its check fired 97 and 96 times in those runs, almost all on the title screen, the menu and the load: none after the level started in the first run, and once in the second. That left case 2. ### Expected A cached template should not bind a texture the sampled lookup no longer returns for its surface. A fix with tests follows in a PR. AI-assisted: yes
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#8040
No description provided.