perf(agc): keep sampled views over a pending storage alias #21699
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21699"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from boykopovar/AnyPS5. Originally posted by DealPotato on 2026-11-16T15:57:31Z.
What
A surface the game renders under two storage formats of the same texel size has two storage images, and which of them has results pending alternates.
StorageTexture::pendingAliaspairs such images, andRefreshalready takes the alias's pending units on the device (borrowUnits). A cached sampled view of the surface stayed a hit only whileFindPendingnamed the view's own image or nothing, though: when the alias was the pending one,cachedTexturereplaced the view with a view of the alias. The old view was then released, and the resource cache dropped every entry holding it (dropReleasedTextures), so each of them was built again on its next use.refreshOwnObjectsstopped atForeignViewfor such a view and took the full walk.cachedTexturekeeps the view when the pending image is the view image's alias (StorageTexture::IsPendingAlias, uncompressed keys) and refreshes the view's image. The view then reads the alias's results: the two images hold the same texels under formats of the same size. A borrow already made at the alias's current version is not repeated.refreshOwnObjectsdoes the same for such a view instead of returningForeignView, and the proof that runs after it accepts the alias over the refreshed surface (PendingOverlap::alias).APS5_NO_ALIAS_VIEWS=1replaces the view as before (documented inENVIRONMENT.md;APS5_ABcan toggle it). The[textures]line counts the views kept this way.ResourceCache::TableElementBudget,APS5_RESOURCE_CACHE_TABLE_ELEMENTS) goes from 65,536 to 262,144 elements (ENVIRONMENT.md,ARCHITECTURE.md). WWE 2K26 draws its materials with about 66 distinct 1684-element bindless tables per frame, about 111,000 elements, so at 65,536 about half of those objects are evicted every frame and built again before their next use.Neither change helps WWE 2K26 alone (measured below): with the old budget the kept table objects are evicted anyway, and with the larger budget alone they are dropped when the view they hold is replaced. They are two commits.
Tested
Windows 11 Pro (build 26300), NVIDIA GeForce RTX 4070, driver 610.88. Tests with
VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1andctest -V.On this branch, the tests that cover storage aliases and the own-object refresh, sampled views of storage images, image tables and their reuse and cache bounds, the resource cache, template proofs and records, the sampled and storage caches and native depth aliases: 85 tests, 83 passed, and
agc_driver_resource_cache_pending_fail_countand its_indexvariant skipped by their own check, with noVUID-message.New execution test
agc_driver_own_refresh_view_alias: an 8888 UNORM view samples its own storage image, then R32 float stores into the same surface leave a pending alias.Revalidatetakes the own-object refresh (underAPS5_VERIFY_PROOFS=1) and keeps the view, a new build of the set keeps the cached view, a dispatch through it reads the stored texels, and the alias stays pending (its units taken on the device). WithAPS5_NO_ALIAS_VIEWSset around a further store, the build replaces the view. WithAPS5_NO_ALIAS_VIEWS=1set for the whole run, the test fails as the code before this change does: the set over the view is not proved current over the pending alias.Performance
WWE 2K26 (PPSA34299) does not reach a match on
mainalone; it was measured on a local branch:main2d74858c14with the open WWE 2K26 fixes and local workarounds (02a62e38ae), with this change on top (6d705746b4, the same two commits). Match of CM Punk vs Roman Reigns, One on One, WrestlePalooza Indianapolis.The surface behind it is a 1920x1080 target the title renders twice per frame under two formats (guest formats 36 and 29), sampled by the material draws as format 29: the sampled view changed images twice per frame, about 31 times per 10 s, and each change dropped the table objects that hold the view.
In-run A/B (
APS5_AB, 20 s phases, 4 s settle, no profiling switches; phase A setsAPS5_NO_ALIAS_VIEWS, both phases run withAPS5_RESOURCE_CACHE_TABLE_ELEMENTS=262144), on a build of the same change with extra counters. The gain is in the match after the entrances, from about 6.5 minutes in; during the entrances most dropped entries hold sampled snapshots whose content changed (about 35 per 10 s), which this change does not touch.The 10 s summary lines inside a settled phase put the difference in the draw builds:
Resources.Complete−129.0 ± 23.3 ms per frame, GPU busy per present −21.6 ± 17.3. During the entrances (9 pairs) the frame changed by −23.4 ± 17.6 ms.Each change alone, same scene: with the views kept and the old budget (
APS5_NO_ALIAS_VIEWSflipped alone), the frame after the entrances changed by +34.3 ± 33.5 ms (10 pairs) andResources.Completeby +25.8 ± 20.1 ms per frame; with only a larger budget (1,048,576 elements, profiled),Resources.Completechanged by +8.9 ± 10.7 ms per frame. Both together with a 1,048,576-element budget gave −68.5 ± 17.5 ms per frame over 24 pairs after the entrances, with dedicated video memory unchanged at 6.49 GB in both phases. A profiled run of that A/B counted the mechanism (per 10 s, reports inside one phase): view replacements 30.7 → 0, draw-build misses 1956 → 1102, entries dropped by the table budget 1042 → 0.APS5_TRACE_SECONDS=0:60captures of02a62e38aeand6d705746b4, both clean builds, taken back to back with the window opened seven minutes after the intro appeared. The shots differ between the two windows (GPU busy 239.8 and 162.6 ms per present), so this pair shows a larger difference than the A/B: frame p50 747 → 564 ms, 84 and 113 presents in the window. Queue worker 0x0'sDriver.Packetwent from 517.5 to 325.6 ms per present and the draw committer'sGraphics.Drawfrom 387.9 to 272.6. Both traces lost events of queue worker 0x0 after 38 to 45 s of the window (the summary totals are complete).tools/trace_digest.py(headers and threads)Checklist
main; no other open PR implements the same functionsNotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file.mdfiles or images added to the repository (attach them to this PR)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-19T01:00:38Z.
Review: COMMENTED
Reviewed — comments
The review is incomplete because two changed source files were available only through targeted excerpts, so a formal approval is not justified.
What I ran
Read the prepared diff at head
427d04b7745ad7a0d71ffbfbe0ee78f7e1964c93and targeted source ranges usingrepo_read.py. No build or tests were run by me.Results
Findings
Blocking
None identified in the inspected excerpts.
Non-blocking
None.
Not verified
Full text was read for
RuntimeSwitches.hpp,ShaderResources.hpp,Texture.hpp,RuntimeSwitches.cpp,OwnRefreshViewAlias.cpp,ARCHITECTURE.md, andENVIRONMENT.md.ShaderResources.cppandTexture.cppwere read only in the changed implementation ranges; their other code and callers were not reviewed. The manifest says those two full files were excluded as too large.description.mdreports Windows 11/Vulkan validation and performance runs, but these were author-reported and not run by me. No tests or build were executed.To get this to a good state
Nothing is required. Optional: complete review of the uninspected portions of
ShaderResources.cppandTexture.cppand run the relevant checks on this head.