Repository navigation
perf(shader): resolve image tables with fewer allocations - #18827
Conversation
Resolving a table of distinct descriptors grows the map, element and poison arrays one doubling at a time. The test resolves 1 to 1024 distinct elements and expects a fixed number of output arrays. It fails on the base (18 allocations for 64 elements).
|
This pull request is labeled |
|
Windows check of head The 38
This is a correctness check only; I did not measure the allocation or timing change. AI-assisted: yes. |
|
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.
|
|
Thanks for the Windows run, JJenkx: it covers the platform I could not test. On the |
MarcZX10
left a comment
There was a problem hiding this comment.
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
- Head:
5d42e94887ba54b64b144ec5d6571e3c1f4ca4af, basemain. - Read the review folder (
description.md,commits.md,manifest.json,diff.patch) and the house-rule sections of the ruling file. - Reader calls at the head:
repo_read.py cat core/shader/recompiler/Recompiler.hpp 590 680
repo_read.py cat core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp 1950 1985
repo_read.py cat core/shader/recompiler/Optimization/src/ResourceMaterializer.cpp 2212 2240
repo_read.py search ElementFlags core/shader
repo_read.py search allocationCount core/libs/prx/libSceAgcDriver/tests/ShaderMemory.cpp
repo_read.py search ImageElementBudget core/shader
- No build, no test run, no conventions script run.
Results
| Check | Result | Note |
|---|---|---|
| Diff has no code comments | passed | Read from diff.patch |
ElementFlags equality and at bounds |
passed | Read at head; inline bits stay zero past count |
| Four new tests registered in CMake | passed | Read from the diff |
| Build and unit tests | not run | No build in this review |
| Author-reported test run (811 tests, macOS) | not run | Not confirmed here |
tools/check_conventions.py |
not run | Author-reported |
Findings
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
- Benchmark figures in the description (99.10 vs 1.97 ns, 6.38 vs 10.45 ns, 50.3 to 16.5 ns, 29 to 7 allocations, 18 allocations without the change). The tests check bounds, not these numbers.
- Whether any caller compares result pointers across threads.
ResourceMaterializer.cpp:2215now returns a per-thread object, so the same empty result has a different address on each thread. Callers were not searched. - Compilation of the new test code (
verifyImageTableBindingGrowth,verifyEmptyImageTableResolution, and the other helpers) against the headers. - The 811-test macOS run in the description.
Files
- Read:
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). - Not read in full: all of the above except the ranges named.
To get this to a good state
- Nothing blocks this PR on the code read. Before merge, the author should run the four new tests on the change and confirm the numbers in the description.
|
Thanks for the review. On the cross-thread question: the only caller outside the tests is On the allocation bound at 65 and 129 images: those sizes use the heap fallback the description names, one allocation per call, so |
|
A Linux run, since the description lists Linux as not tested: RTX 3070 (8 GB), NVIDIA 610.57.04, Ryzen 5 5600X, Debian 13, kernel 6.12.115, GCC 13.3.0 Release, validation layer 1.4.335,
This is a correctness check only; I did not measure timings. AI-assisted: yes |
|
Windows/AMD validation on RDNA 2: the four new table cases pass.
No AMD timing number: the PR's measurement is macOS/MoltenVK; this covers the functional side on a different vendor. |
#18827 made the empty table result a function-local thread_local. On Windows its destructor runs after emulated TLS freed the object, which prx_thread_local_destructors and test_thread_local_destructors reject.
boykopovar#18827 made the empty table result a function-local thread_local. On Windows its destructor runs after emulated TLS freed the object, which prx_thread_local_destructors and test_thread_local_destructors reject.
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 feat(agc): look up table images at run time through a device image table on the GPU heap (APS5_GPU_PATH) #7642, feat(agc): serve lane-keyed, pointer and runtime image-table columns #10193, feat(agc): resolve table samplers through device image keys #13928, feat(agc): resolve runtime sampler addresses through device image keys #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)