perf(agc): reuse image tables that hold storage-viewed entries #15563
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15563"
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 XatiX on 2026-11-03T19:02:29Z.
What
An image table was reused across draws only if every one of its entries was provably unchanged. One entry that failed the check, for example a sampled texture viewed through its cached storage image (
SampledFromStorageEligible: host-imported memory and a storage-capable, uncompressed format), made the whole table resolve again on every draw.Now such an entry is marked live in the remembered table. When the table is reused, a live entry is resolved through
cachedTextureon every draw, as a fresh table resolves it, and the remaining entries are reused as before.CachedTableTexturesand the revalidation path skip live entries in the same way. Entries that are rejected, written by the dispatch, or past the table capacity are handled as before.PPSA18653 binds a table of about 14,200 entries in each of about 730 draws per frame. About 1.6% of each table (about 229 entries) are storage-viewed, so no table was ever reused, and
Resources.Completetook about 5.5 s per frame.The new step in
agc_driver_image_table_reusehost-imports a guest block, so its entries are storage-viewed, and then checks three things:On
mainit fails with0 reused and 3 resolved tables, expected 3 and 0.Tested
ctest -V -R "table|texture|storage|sampled|bindless"withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1andANYPS5_REQUIRE_VULKAN=1. Both runs were on the same machine, with the related execution tests built (ANYPS5_AGC_EXECUTION_TESTS):main: 115/117 passed. Onlyagc_driver_image_table_reuseandagc_driver_image_table_reuse_draw_pipelinefail;VUID-error. The same 4 tests skip in both runs (multisampled pass order and 3 packed16 storage formats). Logs attached.APS5_TRACE_SECONDS=20:60after a warm run, with no other trace or profile switch and the log not redirected.maincannot reach this screen on its own, so both builds carry #15327 (GPU hang) and the opt-in clock change, run withAPS5_FAIL_UNKNOWN_CLOCKS=1. The base is68a15ec229and the change is12ed9524c8, the same tree plus this commit. Traces attached.Resources.Completeper frametools/check_conventions.pypasses.tools/pr_overlap.py --branchreports one line overlap, with #9508 atShaderResources.cppL5466-5467: both change the capacity condition of the reuse loop, and the merge keeps both.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)aps5-trace-12ed9524c874-25392.json.gz
aps5-trace-68a15ec2299e-15048.json.gz
change-ctest.log
main-ctest.log
🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T19:14:11Z.
Review: APPROVED
Reviewed — approved
The change marks entries that cannot be proven unchanged as live and re-resolves them through
cachedTextureon every reuse. That path does the same work as a fresh resolve. The new test step fails onmainand passes with the change, and I found nothing blocking.What I ran
Head
38e7f40892e428811467e05ede279911e15151e0,main1e658521a0a599872612bb91949311e2956b5283, merged tree48eb641f852164cb1e1a8b7d4575de365ac2b81c. Debian 13 VM, 2× Xeon Gold 6136, GCC 14.2.0, lavapipe (Mesa 26.1.6, LLVM 19).Results
git diff --checkcheck_conventions.pymain(agc_driver_division, the denormal-mode tests,vector_constant_factor_tininessand one unwrap test)VUID-lines compared withmainagc_driver_image_table_reuse(validation on)agc_driver_image_table_reuse_draw_pipeline(validation on)Host imports are available on lavapipe here, so
RunViewedStoreactually ran. The "host imports are unavailable" skip line does not appear in the output.Negative control
I restored
ShaderResources.cppfrommainand kept the new test. Both tests then fail with the message the description quotes:output
After I restored the merged file and rebuilt, both tests pass again, and
git status --porcelainis empty.Findings
Blocking
None.
Non-blocking
A table with no reusable entries now takes a reuse slot. In the fresh path, an entry that fails the lookup-log check is pushed as live (
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp:5649-5651), andreusablestays true. So a table whose entries are all live is still remembered atShaderResources.cpp:5656-5665. Two examples are a table of DCC-compressed entries and a table of entries withlooked->source != nullptr.mainsuch a table was never remembered.TableCurrentandCachedTableTexturesand then resolves every entry again anyway, so it gains nothing.ReusedTableCount = 4thread-local slots (ShaderResources.cpp:2032), which can push out a table that does benefit from reuse.Suggested fix: skip
RememberTablewhen no element is non-live and non-rejected (for example, whenfresh.queriesis empty).The live branch in
revalidateFullrepeats the fallback loop. The new branch atShaderResources.cpp:3827-3836repeats the decode andcachedTexturecomparison of the fallback loop atShaderResources.cpp:3847-3855. A small shared lambda would keep the two from drifting apart, for example if the fallback later gainslayerRowsBindingthe way the non-table walk atShaderResources.cpp:3795has it.I also checked these and found no problem:
resolveLivedoes the same steps as the fresh path (decodeEntry,prepareSampledwithCompletePendingCpuWrites,lookupSampled,bind). In the reuse path,storageTableanditem != nullptralready exclude theimageWrittenand missing-binding branches.nextadvances the same way inCachedTableTextures, in the capacity branch and in the reuse loop.{{}, {}, {}, 0, firstLayer, false, {}, true}is correct. It matches the field order (livecomes aftermessage).reusable. Sofresh.elementskeeps its size equal tobinding.count.Not verified
68a15ec229/12ed9524c8) also carry #15327 and are not the PR head, as the description says.Imported from boykopovar/AnyPS5. Originally posted by XairRrR on 2026-11-03T20:07:03Z.
Review: APPROVED
Re-checked — approved
Commit
b2ca8faf64resolves both non-blocking points from my last review. A table whose entries are all live is no longer remembered, and the tworevalidateFullpaths sharecurrentTableEntry. The tests and the negative control behave as expected.What changed since my last review
b2ca8faf64("keep tables with nothing to reuse out of the reuse slots"). Commit38e7f40892is unchanged.ShaderResources.cpp:5677-5678addsanyKept. A table is remembered only when at least one element is not live. Rejected elements count as not live, so a table of rejected entries is still remembered, as onmain.ShaderResources.cpp:3812-3820adds thecurrentTableEntrylambda, which is now used by the live branch (:3838) and by the fallback loop (:3853).RunViewedStorenow points recordsViewed..Recordsat a second block that is not imported (plain). The table therefore mixes kept and live entries, and the expected count goes from 3 reused / 0 resolved to 4 / 0. A new step atImageTableReuse.cpp:296-301binds a table of only storage-viewed entries and expects 0 reused and 2 resolved.What I ran
Head
b2ca8faf642de09526cd5d4a7b98574d7e7a7b5f,main086c0686c8adff3ee648fdbe34e0b0b647e1d511, merged tree0a25af341deac165d5a9ded01ebc7082aa852e88. Debian 13 VM, 2× Xeon Gold 6136, GCC 14.2.0, lavapipe (Mesa 26.1.6, LLVM 19).git diff --checkcheck_conventions.pymainagc_driver_image_table_reuse/_draw_pipeline(validation on)RunViewedStoreranagc_driver_image_gather_volume. These lines come frommain, not from this PR (see below)anyKeptremoved)a table of only storage-viewed entries, which has nothing to reuse: 1 reused and 1 resolved tables, expected 0 and 2(the message the author quoted)ShaderResources.cppfrommain)a table of storage-viewed and other entries, ...: 0 reused and 4 resolved tables, expected 4 and 0git status --porcelainis emptyAbout the
agc_driver_image_gather_volumelines. The script marks them "(test not run on main)" because the test was added tomainafter the validation baseline1e65852. I ran it with validation on, once with the PR'sShaderResources.cppand once withmain's. Both runs give the same IDs, so they come frommain, not from this PR:VUID counts, the same with either file
Previous findings
ShaderResources.cpp:5677-5678now remembers a table only if some element is not live. With that condition removed, the new step fails with1 reused and 1 resolved tables, expected 0 and 2; with it, the step passes. The author chose "any element not live" instead of my suggestedfresh.queriesempty, so tables of rejected entries are still remembered as onmain. That keeps their rejection messages from being decoded again, which is reasonable.revalidateFullrepeats the fallback loop: Resolved. Both paths now callcurrentTableEntry(ShaderResources.cpp:3812-3820, used at:3838and:3853). The fallback condition is equivalent to the old one: thetextureIndex >= textures.size()guard moved into the lambda, and the comparison is the same||chain. The lambda capturestextureIndexby reference, and both callers advance it after the call, as before.New findings
Blocking
None.
Non-blocking
None.
Not verified
68a15ec229/12ed9524c8, which carry #15327 and the first commit only. The second commit only narrows when a table is remembered, so it should not slow the measured scene, but I have not measured that.