perf(agc): index the resource cache by a four-lane key hash #6972
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6972"
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 meh7an on 2026-10-16T22:57:15Z.
What
ResourceCacheholds the shader resource objects of draws and dispatches. Its keys are about a hundred words: the device, the stages and their bindings' guest descriptors. Every draw and every dispatch looks one up (Find, orTouchon a recipe hit). The cache indexes its LRU list with anstd::unordered_map<Key, iterator, KeyHash>:KeyHashis FNV-1a over every word: one multiply per word, each waiting on the one before.KeyHashisnoexcept, so libstdc++ keeps no hash code in the nodes. A lookup's bucket walk hashes the key of every node it passes again, to find where its bucket ends.The index is now a
HashSlotMap(Execution/include/HashSlotMap.hpp) keyed by the key's hash:RemoveImage.hashSlotMapTests(graphics tests) covers:On the S2 page of Sonic Origins Plus's main menu, the queue worker spent, per frame (APS5 sampler, 15 s):
ResourceCache::Find: 0.52 to 0.27. In a profile of an earlier build, 45 of its 70 samples were its own code, mostly the inlined FNV over the key, and 23 the bucket walk.std::_Hashtable::_M_find_before_node, the bucket walk: 0.26 to 0.06. What remains belongs to other hash tables.That is about 1.5% of the worker's frame (31 samples).
#6492 adds another walk over the cache's entries that reads
it->firstandit->second. Whichever of the two lands second changes them toit->hashandit->resources.Tested
Windows 11 (10.0.26300), WinLibs GCC 15.2.0 (UCRT), Release, NVIDIA GeForce RTX 2080 Ti, driver 617.14.
7d728b109with this change, the full ctest suite passes 1337 of 1341 tests.agc_driver_gpu_indirect_arguments_misaligned_writer_aheadis not run: main itself does not compile it with MinGW (alignas(65536)).select_testsfails in its setup on Windows without the symlink privilege (WinError 1314fromsymlink_to), as on main.agc_driver_multisample_fill_host_onlyfailed once ("the sentinel fill did not land"). That is main's own race, #6512, which #6522 fixes. With #6522's line added it failed 0 of 200 runs (8 at a time).guest_positioned_close(libkernel and libc only) ended with 0xc0000409 once in the parallel run. Alone it passes 5 of 5.APS5_TRACE_SECONDS=200:15on the same machine in one session, caches warm. Traces attached.This pair overstates the change: its target is about 1.5% of the worker's frame, and windows of this page vary by a few percent at the median. The title FPS during the two captures was 10.82 and 11.12. The sampled pair, 10.56 to 10.84 FPS, is the better estimate.
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)Traces and summary lines (baseline 245e35555, whose summary says b1909f43b4d1; this change 557d4dafb, whose summary says 245e35555cf4):
keyhash-traces.zip
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-16T23:09:45Z.
Some comparisons could not be completed because a pull request conflicts with the base branch. Review these shared files manually before concluding that there is no overlap.
core/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppImported from boykopovar/AnyPS5. Originally posted by keravyn-ops on 2026-10-17T09:59:26Z.
AMD / Windows run of this PR at 5b3c1ea31: Radeon 780M (RDNA 3, 0x15bf), AMD driver 25.10.20.01 (32.0.21020.1007), Windows 11 Home 10.0.26100, WinLibs GCC 15.2.0 r7, Release.
Every ctest entry built from the test targets this PR changes passes (14):
agc_driver_undithered_alpha_to_coverage_state(0.11 s):289: Existing undithered alpha-to-coverage states passedagc_driver_alpha_to_coverage_state(0.02 s):290: Alpha-to-coverage state and refusal tests passedagc_driver_prepared_graphics_prebuild_unset(0.16 s):292: prebuild policy native readback passedagc_driver_prepared_graphics_prebuild_0(0.13 s):293: prebuild policy native readback passedagc_driver_prepared_graphics_prebuild_1(0.13 s):294: prebuild policy native readback passedagc_driver_graphics(4.93 s):327: Graphics validation tests passedagc_driver_prepared_graphics(0.13 s):588: prepared graphics ABI tests passedagc_driver_prepared_unregistered_graphics(0.15 s):591: prepared unregistered graphics tests passedagc_sparse_buffer_holes(0.04 s):708: sparse buffer hole tests passedagc_pipeline_journal(0.07 s):712: pipeline journal recipe, record and replay tests passedagc_descriptor_pool_reset_failure(0.02 s)agc_driver_address_space_teardown(0.02 s):767: address-space device teardown releases cached guest allocationsagc_compute_descriptor_layout_flags(0.02 s):798: Descriptor layout native and captured binding flags passedagc_driver_covered_centroid_state(0.02 s):799: Covered-centroid and multisample state checks passedAI-assisted: yes (runs made on the device above).
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-19T12:40:14Z.
Review: CHANGES_REQUESTED
Thanks, the
HashSlotMapitself reads correctly (growth, backward-shift erase including the wrapped run, key 0, and the test pins them). It now conflicts withmain, and not mechanically:ResourceCacheonmainhas adaptive capacity (capacity,fixedCapacity,baseEntries, shrink window) and new helpersnoteEvicted(key),noteReturn(key),noteUse(key),dropReleasedTextures(evicted).Find,InsertandTouchcall them, andInsertno longer uses the staticcapacitylambda your diff edits (ShaderResources.cpparound theInserthunk).noteEvicted/noteUsestill take aKeyand useKeyHash{}(key)for their own tables, soKeyHashcannot simply be removed. Decide whether they take the newhashKeyvalue (thenevictedKeys/usedKeysare keyed by it) or keep the old hash.ResourceCachehas other places that readentriesas pairs (->first/->second) onmain; they need theEntrystruct too.Please rebase on current
mainand re-measure:noteUseadds work perFind/Touch, so the ~1.5% of the worker's frame may differ. Keep the trace-vs-sampler caveat in the body.Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-20T13:39:28Z.
This pull request is labeled
perf, so it needs the summary line of a capture onmainand one with the change, from the same title, scene and machine, as the Performance report form asks. Please paste bothaps5-summary.jsonllines, attach the two traces and add the output oftools/trace_digest.py.Imported from boykopovar/AnyPS5. Originally posted by meh7an on 2026-10-20T14:44:14Z.
Closing this: on current main it shows no gain.
1d4164552(ae33fb54f).KeyHashand its pass over the key on everyFindandTouchare gone.agc_driver_pipelined_dispatch_itemfailed 1 of 40 runs under load on both.1d4164552:That isn't worth a new map in the cache. Thanks @adriadam10 for the review and @keravyn-ops for the AMD run.
Pull request closed