perf(agc): remember rejected texture descriptors in image table resolution #21501
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/21501"
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 slopezjur on 2026-11-16T09:02:37Z.
What
ShaderResources::resolveImageTablesdecodes the elements of an image table at up to three places:variantRepresentatives,arrayPartnersand the per-element decode.DecodeTextureResourcereports an invalid T# by throwing, so every invalid table element threw a C++ exception at each of those places, on every resolution of the table.variantRepresentativesalso runs on the reuse path, so a reused table paid it too.TryDecodeTextureResourcereturns the decoder's rejection instead of throwing and remembers rejected descriptors. The decode depends only on the 8 descriptor words and on whether guest shaders are PS4 (GCN) shaders, so the key is those words plus that flag.TryDecodeTextureResource. The rejection message is the oneDecodeTextureResourcethrows, so a rejected element is poisoned with the same text as before.RememberedTextureRejections(4096) descriptors and is cleared when it is full.DecodeTextureResourceare unchanged. One of them isprepareSampledinresolveImageTables, which decodes the first-layer words of a 2D array read as 2D. It runs only after the per-element decode accepted the full T#, and the narrowed words differ only in the last-slice field, set to the base slice, so the 2D-array checkbaseArray <= depthstill holds. The one check that still depends on the slice count is the mip-fit check whenbaseLevel > maxMip(LevelsFitAllocation); if it throws, it throws as onmain.New cases in
agc_driver_graphics(tests/GuestTextureResource.cpp): the rejection message matches the throwing decoder, a repeated rejected T# returns the remembered rejection and is not stored twice, a valid T# is not remembered and decodes as before, the same words decoded as a PS4 T# do not reuse the RDNA rejection, and the map stays within its bound. The count after a new rejection is checked exactly (before + 1, or 1 when the full map was cleared).Tested
Windows 11, WinLibs GCC 15.2.0 r7, Release, NVIDIA GeForce RTX 4080 SUPER (driver 621.24).
Tests matching
^(agc_|shader_)(1997) withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandVK_LOADER_DEBUG=layer, onmaindcdb92d584and on this change based on it, same tree and GPU (Vulkan SDK 1.4.363.0 layer):VUID-linesmainagc_driver_stencil_plane_memory,agc_driver_store_over_untracked)agc_driver_stencil_plane_memory,agc_driver_color_memo_baseline_disabled,agc_driver_color_memo_baseline_verify)agc_driver_upload_cache_read_only_flushis not built on either side: its test source callssetenv, which this toolchain does not declare.agc_driver_stencil_plane_memoryandagc_driver_store_over_untrackedalso fail onmain. The target memo cases ofagc_driver_target_memo_testsare not stable onmaineither. Run alone five times each with the same environment,agc_driver_color_memo_baseline_disabledfailed 4 of 5 onmainand 4 of 5 on this PR,agc_driver_color_memo_baseline_verify5 of 5 onmainand 4 of 5 on this PR, andagc_driver_target_memo_verify(which failed in another full run of this change) 5 of 5 onmain. None of these tests reaches the texture descriptor decode.Reported by domx4q on Linux: Arch Linux, GCC 16.2.1, Release, NVIDIA GeForce RTX 4090 (driver 620.70.06, Vulkan 1.4.357, layer 1.4.363.1), head
a2fa6aa512merged ontomainf0c01bc69d,ctest -R 'color_memo|target_memo|stencil_plane_memory|store_over_untracked|upload_cache_read_only|^agc_driver_graphics$' -Vwith the same environment: 64 of 64 pass onmainand on this PR, the layer inserted 64 times on each side, noVUID-. The tests that fail or do not build on the Windows toolchain above pass there on both sides.Ghost of Yōtei
PPSA26344 v02.002.000, DRS 1080p patch, Digital Deluxe "Press X" screen from a fresh save, warm shader cache. Plain
maincrawls at under 0.1 fps in this scene, so every arm uses one build ofmain53f1b9a500merged with #20017, #20018, #20519 and #20735 (APS5_BINDLESS_IMAGES=1 APS5_BINDLESS_LAZY=1). OnlylibSceAgcDriver.prxdiffers between arms. Runs alternate between arms; 330 s each withAPS5_PROFILE_DRAW=1andAPS5_TRACE_SECONDS=270:5; fps counted from the presents between 200 s and 320 s.Set 1 (NVIDIA 621.14):
Set 2 (NVIDIA 621.24), with a third arm that put a lock-free bit filter in front of the map so a never-rejected descriptor would skip the shared lock and the map search:
Every run with this PR is faster than every base run in both sets. The filter arm overlaps this PR (2.896-2.948 against 2.930-2.986), so the shared lock and map search per valid descriptor are not a measurable cost here, and the filter is not part of this PR. Per frame (set 2 digests below),
Vulkan.Dispatch.shader_resourceswent from 50.1 to 39.0 ms,Resources.Completefrom 37.8 to 28.1 ms and queue worker 0x30 busy from 102.5 to 82.9 ms. Left out: runs that stopped in the title's own load crash (access violation at 35-60 s, seen with and without this change: 3 of 10 runs in set 1, 4 of 18 in set 2, whose warm-up also ended at 227 s), and the first two rounds and the warm-up of set 2, where the NVIDIA pipeline cache was cold and 1M-word pipelines took 13-48 s each to create, pushing the load into the measured window. Not measured: other titles, other GPUs, Linux, macOS.tools/trace_digest.py: base, set 2 run 5seconds 270:5 from present 1391: 15 presents, frame p50 354.1 / p90 382.5 / p99 393.3 / max 393.3 ms, GPU busy 160.6 ms per present
NVIDIA GeForce RTX 4080 SUPER, NVIDIA 621.24, Windows 10.0.26300, 3840x2160, commit e5dcdd285cfd, dropped: no
Threads (ms per frame, title threads omitted)
tools/trace_digest.py: this PR, set 2 run 5seconds 270:5 from present 1420: 15 presents, frame p50 340.3 / p90 348.4 / p99 351.2 / max 351.2 ms, GPU busy 170.9 ms per present
NVIDIA GeForce RTX 4080 SUPER, NVIDIA 621.24, Windows 10.0.26300, 3840x2160, commit d9eb0ba1ddc8, dropped: no
Threads (ms per frame, title threads omitted)
aps5-summary.jsonl: base, set 2 run 5aps5-summary.jsonl: this PR, set 2 run 5aps5-trace-e5dcdd285cfd-13456.json.gz
aps5-trace-d9eb0ba1ddc8-3348.json.gz
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)🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T02:58:02Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this; the points below are optional.
What I ran
7755bf22a5013a5e486a1224c75c0eaf675277ff, basemain. No build and no tests in this pass.files.jsonand the fulldiff.patch.files.jsonunderreviewedwere covered.GuestTextureResource.hppandtests/GuestTextureResource.cppwere read from the diff, plus the search above.GuestTextureResource.cppwas read from the diff and head lines 140–380.ShaderResources.cppis partial (see Not verified). No file was excluded.Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/tests/GuestTextureResource.cpp:116:remembered == before + 1u || remembered == 1uaccepts a count of 1 whateverbeforewas. The1ubranch is the full-map clear case, so the check is correct but loose. An exact form would beremembered == (before == RememberedTextureRejections ? 1u : before + 1u).core/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cpp:412: every valid 8-word descriptor now takes a shared lock and astd::maplookup before it decodes (lines 412–413). The PR's timings cover this together with the saved throws and do not isolate it.Not verified
core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppis too large for the review folder. I read the changed hunks (new lines 6277–6280, 6337–6340, 6428–6433) and the image-table consumers (6410–6500, 6618–6640). The rest of the file was not read. This is why the verdict is a comment and not an approval.Sources
github.com/boykopovar/AnyPS5@7755bf22a5/core/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cpp (L397-L427)github.com/boykopovar/AnyPS5@7755bf22a5/core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp (L6426-L6433)To get this to a good state
Nothing is required.
The optional points are the two non-blocking items above. No command needs to be rerun on a new head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-17T14:36:45Z.
Review: COMMENTED
Reviewed — no blocking findings
No verified defect in the changed code. I did not re-run the tests or the performance captures, so this is a comment, not an approval.
What I ran
a2fa6aa512adc4410416730ad1dcc784ca86baa4(basemain).Results
Findings
Blocking
None.
Non-blocking
core/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cpp:423: when the remembered map reachesRememberedTextureRejections, the whole map is cleared at once. A title that produces more than 4096 distinct rejected T# values would re-decode and re-insert them in cycles. This costs time and is not a correctness problem, since a miss just runs the decoder again. Keep it unless the traces show it.Sources
github.com/boykopovar/AnyPS5@a2fa6aa512/core/libs/prx/libSceAgcDriver/Graphics/src/GuestTextureResource.cpp (L423)Not verified
agc_driver_stencil_plane_memoryfailing onmaintoo. It also reportsagc_driver_color_memo_baseline_disabledandagc_driver_color_memo_baseline_verifyfailing on this PR and flaky on both sides. The author states these do not reach the descriptor decode. I did not check that.GuestTextureResource.cppfor globals (only the GCN flag and two one-time log flags). I did not read the helpers in other files thatDecodeTextureResourcecalls, so "depends only on the 8 words and the GCN flag" is not fully verified.ShaderResources.cpparound line 6476 still callsDecodeTextureResourcedirectly on the narrowed first-layer words. It is outside the three sites this PR changes. I did not check whether that call can throw for an element that the new code accepted.GuestTextureResource.hppand the test file were read through their diff hunks only.To get this to a good state
Nothing is required.
Optional, once: