perf(recompiler): scan image-table key buffers in bulk #7101
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/7101"
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 XairRrR on 2026-10-17T11:42:20Z.
What
TableSnapshotter::Narrowreads the key buffer of an image-table column to find which records the shader can select. It read one key at a time: aPageAccessiblelookup and a single-wordreadMemoryper key. In Uncharted: Legacy of Thieves Collection (PPSA05684), gameplay scans about 20,000 keys per table snapshot.Changes (
ResourceMaterializer.cpponly):readWords) and the key stride is a multiple of 4 and at most 64 bytes, the scan checks each page of the key span once and reads the span with onereadWordscall. With a stride of 64 bytes or less every page in the span holds a key, so the pages checked are the ones the word-by-word scan checked. Other strides, and runtimes withoutreadWords, keep the word-by-word scan.key * stridecannot wrap. A key that wraps takes the old path (relative % stride,relative / stride), so wrapped keys still select the record the 32-bit address arithmetic reaches.ScalarBufferDwordtest is skipped for later keys.Measured in PPSA05684 gameplay with
APS5_PROFILE_DRAW=1, image-table time per snapshot: about 6.5 ms before, 5 ms after. That build also carried other local changes (the same scene, warm shader cache); this branch on its own was not run in the title.Overlap with open PRs:
ShaderMemory::readWordscopy lazy pages by block. That is complementary: with it the key span read here also avoids per-wordread()calls insideShaderMemory.skip()in the same loop a reason. Textual conflict only; whichever merges second needs to rebase.Tested
Arch Linux (kernel 7.2.9-zen), NVIDIA RTX 4070 Ti SUPER, driver 615.78.08, GCC 16.2.1, Release,
BUILD_TESTING=ON.verifyImageTableBulkKeyScaninagc_shader_bindless(agc_shader_memory_tests --bindless). It captures the material table shader twice, once with onlyreadMemoryand once withreadWordstoo. It checks that:0x08000003) wraps when multiplied by the 32-byte stride and is the only one that selects record 3.main'sResourceMaterializer.cppit fails withimage table bulk key scan: the keys were read word by word although a bulk reader exists.image table bulk key scan: the narrowed codes are wrong.ctest -j4 -R "image_table|bindless|agc_shader_": the 15 built tests pass (agc_driver_image_table,_cache,_cache_bounds,_reuse,agc_driver_bindless_images,agc_shader_bindless,agc_shader_memory,agc_shader_srt_read_patching, and the otheragc_shader_*tests ofagc_shader_memory_tests).python3 tools/check_conventions.py --base origin/main: passed.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)Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-17T12:07:13Z.
Other open pull requests touch the same code. Merging one will break the other, or both implement the same thing. If this one builds on them, list them in Depends on.
main)core/shader/recompiler/Optimization/src/ResourceMaterializer.cppL508-512Some 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/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/libs/prx/libSceAgcDriver/tests/ShaderMemory.cppcore/shader/recompiler/Optimization/src/ResourceMaterializer.cppImported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-17T12:29:33Z.
@XairRrR full CI on 4ca1dc650 fails one Windows check that comes from this PR:
prx_thread_local_destructors.That's the new
thread_local std::vector<std::uint32_t> span;inResourceMaterializer.cpp. The fix is the project'sHostThreadLocalhelper (prx/libc/include/HostThreadLocal.hpp).DrawRegisterKey.cpphas an example:HostThreadLocal<Type, Tag>()returns a reference you can keep using the same way. A plain local vector also works if the reuse across calls isn't important.The other two Windows failures in that run (
conventions_function_bodiestimeouts) are a known runner-load flake, not this PR. Linux is green.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-10-17T15:28:40Z.
Thanks @oneandonlydean, good catch. Fixed in
bf0c51e4c(amended): the key words are now read into a scratch vector that is a member ofTableSnapshotter, so it is reused across the columns of one snapshot and there is nothread_localleft inResourceMaterializer.cpp.agc_shader_bindless,agc_shader_memoryand theagc_driver_image_table*tests pass on Linux,nmshows no__cxa_thread_atexitreference in the object any more, and the conventions check passes.