perf(shader): resolve image tables with fewer allocations #18827
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/18827"
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 atinseau on 2026-11-12T11:45:56Z.
What
Resolving an image or sampler table (
ResolveImageTable, the shared and empty-result paths of the resource materializer) allocates more than its result needs. This PR removes four sources of allocations and of contention, each with a test on the production seam.agc_shader_table_binding_growthfails without it (17 allocations at 64 elements) and checks changed descriptors and metadata at 0, 1, 64, 65, 256 and 3000 elements. A 256-image fixture goes from 29 to 7 allocations and from 3652 to 2639 ns per resolution.agc_shader_table_resolution_growthresolves 1 to 1024 distinct elements and expects a fixed number of output arrays; without the change it counts 18 allocations for 64 elements.agc_shader_empty_table_resolutionruns four threads and checks allocation reuse, the refusal of malformed indices and that a result outlives the thread that produced it.agc_shader_shared_table_resolutionfailed first with 100 allocations on 100 hits, and checks unchanged-result reuse, changed sampler and descriptor invalidation, held-result lifetime and malformed index refusal at 1, 32, 64, 65 and 129 images.Field layouts and serialized formats are unchanged; the sized constructor is additive. The timings are fixture measurements (single process, alternating runs of the parent and the change), not a title trace.
Tested
macOS 27.0.1, Apple M3 Max (36 GB), MoltenVK 1.4.2 from Vulkan SDK 1.4.363.0, Release build with
-DBUILD_TESTING=ON, x86_64 under Rosetta 2.maindoes not run its libraries on macOS, so both sides aremain3b7f31fa7with the macOS port (the squash of #8658, which its author upstreams in parts) and local macOS build fixes for tests ofmainthat Apple clang refuses; the change side adds this PR's commits.VK_LAYER_KHRONOS_validation,VK_LOADER_DEBUG=layer,ANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1(ctest --test-dir build-macos -R '<811 test names>' -V): on the change 708 pass (the four new tests added), 71 skip, 35 fail and 1 times out; all 811 tests have the same status as onmain. The failures are the onesmainhas on macOS (MoltenVK limits and macOS-only gaps of the tests); none is new. Both runs report the same 77VUID-errors test by test, andwas not found but was requested by env var VK_INSTANCE_LAYERSappears only in the 12 lines that print the failure regex of theagc_driver_image_table_packed*tests. The change run's logs show the loader inserting the layer (Insert instance layer) in 490 tests.python3 tools/check_conventions.py --base origin/mainpasses.tools/pr_overlap.pycould not compare open pull requests that conflict withmainand shareDescriptorBindingBuilder.cpp,ResourceMaterializer.cpp,Recompiler.hppor the shader memory tests; they are image table features (for example #7642, #10193, #13928, #13929), and none reserves, isolates or inlines what this PR does.Not tested: Linux and Windows.
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 MarcZX10 on 2026-11-12T14:29:29Z.
Review: COMMENTED
Reviewed — no blocking findings
The diff reserves allocations in image and sampler table resolution, gives each thread its own empty-result owner, and adds four tests. I found no defect in the code I read, and nothing was built or run.
What I ran
5d42e94887ba54b64b144ec5d6571e3c1f4ca4af, basemain.description.md,commits.md,manifest.json,diff.patch) and the house-rule sections of the ruling file.Results
diff.patchElementFlagsequality andatboundscounttools/check_conventions.pyFindings
Blocking
None.
Non-blocking
core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp:1887:static_cast<void>(reducing.at(pair.image));followed byreducing[pair.image] = true;is a bounds check whose purpose is not stated. It keeps thestd::out_of_rangebehaviour of the oldstd::vector<bool>::at. A short comment-free rewrite is not obvious, so the intent is easy to miss. Leave as is unless the house style has a pattern for it.core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp:4817:allocations <= (count <= 64u ? 0u : 100u)allows one allocation per cache hit at 65 and 129 images. This matches the heap fallback the description names, but the bound would not catch a regression to per-hit allocation for those sizes.Not verified
ResourceMaterializer.cpp:2215now returns a per-thread object, so the same empty result has a different address on each thread. Callers were not searched.verifyImageTableBindingGrowth,verifyEmptyImageTableResolution, and the other helpers) against the headers.Files
ResourceMaterializer.cpp(diff hunks and ranges 1950–1985 and 2212–2240),Recompiler.hpp(diff hunks and 590–680),DescriptorBindingBuilder.cpp(diff hunks),agc_shader_memory_tests.cmake(diff),ShaderDiskCache.cpp(diff),ShaderMemory.cpp(diff hunks only; the file is excluded as too large).To get this to a good state