perf(agc): bind a one-layer 2D array table entry to the 2D texture of its surface #15710
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/15710"
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 hugodearaujo on 2026-11-04T08:57:02Z.
What
Marvel's Spider-Man 2 (PPSA03016) binds its whole texture heap as one image table every frame: about 19,400 entries, but only about 9,300 distinct surfaces. Almost every texture is in the table twice, once through a 2D T# and once through a 2D-array T# with one slice (
BASE_ARRAY=LAST_ARRAY= 0). The two T#s are equal except for the type field (word 3 bits 28-31: 9 and 13), and the shader samples the second one through a 2D-array instruction.cachedTexturekeys textures by their words, so each surface got two images with the same Vulkan shape and the same texels. On this title one resolution of the table made 18,356 textures over 9,312 surfaces, 12,007 MiB of device memory, more than the sampled cache budget (6.1 to 7.7 GB there), so every resolution re-created thousands of textures it could not keep ([texture-cache]: 4,500 to 9,600 "used uncached" per 10 s).resolveImageTablesnow pairs such entries before it resolves the table (arrayPartners): an entry whose shape isImage2DArray, whose T# is a one-slice 2D array, and whose words equal a 2D entry's words except for the type field binds that 2D entry's texture through aVK_IMAGE_VIEW_TYPE_2D_ARRAYview of the same image.Texture::ArrayView()(new): a one-layer 2D-array view of a single-layer 2D texture, created on first use from the view the constructor made (same format, components, levels and minimum LOD).createFirstLayerViewrecords it, so every texture constructor that makes a 2D view offers it; depth-plane textures do not, and their partners resolve as before.ArrayView()for those entries; the per-entry checks (bind: sampler pairing) run as for any entry.[textures]counts the entries bound this way.Related: #13796 does the same pairing for storage images (
SurfaceKey); this one is for the sampled textures of an image table, which never go through the storage cache when they are block-compressed (all of this title's pairs).Tested
Linux 7.2.11, AMD Radeon RX 9070 XT, RADV Mesa 26.2.6, Release.
agc_driver_image_table_array_views: one compute shader with twoimage_sample_lzof one table (a 2D instruction reading the record the first keys buffer names, a 2D-array instruction at slice 0 reading the record the second names), 256-bit T#s. Cases: a 2D T# and a one-slice 2D-array T# of one surface (the array entry binds the 2D texture, both read the surface's texels, and both read the new texels after the guest rewrites the surface); an array T# over another surface; an array T# with another swizzle (red = constant 1); a two-slice array T# of the same surface. The last three must not pair and must read their own data.arrayPartnersis not called, so no entry pairs): the first case fails with "the one-layer 2D array entry did not bind the 2D entry's texture (0 shared)"; with the change: passes. Repeated onmain5b1d381d5a.VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ANYPS5_NO_SHADER_CACHE=1,ANYPS5_REQUIRE_VULKAN=1),^agc_driver_image_table|^agc_driver_bindless_images: onmainacf7ac208a9 of 9 pass (one skipped,agc_driver_image_table_vouched_lookups), onmain+ this change 10 of 10; 0VUID-lines and no "was not found but was requested" line in either log. The same on the Spider-Man stack below, and onmain5b1d381d5a+ this change (9 pass,agc_driver_image_table_vouched_lookupsskipped as onmain, noVUID-line).agc_driver_graphics,agc_driver_sampled_cache_budget*andagc_driver_storage_cache_budget*pass onmain+ this change.main4f41f4c375+ #9969 + #8939 + #13646 + #15399 + #15555 + #15649 (needed to get past loading), each with my memory guard (it stops the game when the GPU's free VRAM and GTT both run low, or GTT alone does):GetImageResource dword 0 is not a valid runtime value; chain: ReadConstBuffer@pc=0x0000a5b0(...), at 197, 258 and 229 s. The run with the counter on bound 231,236 entries through the 2D texture of their surface.418ca34d98merged ontomainb8194198cf, and on a Windows 11 VM with a GeForce GT 1030 (WinLibs GCC 15.2 UCRT), merged ontomain2d27859b05,agc_driver_image_table_array_viewspasses 3 of 3 runs.Performance
Interval summaries (
APS5_TRACE_SUMMARY_EVERY=10) from the runs above, the same 10-second slot after the table on both sides.04cfe95c14is the stack with #10256, and6ce8f42b3fadds this change. Frame time after the table goes from 1 present per 10 s, at a p50 of 10.7 s, to 10 presents at a p50 of 1.0 s, because the table stops re-creating textures it cannot keep. No trace window was captured. This is a memory change, and these lines only show the re-creation thrash ending; they are not a frame-time claim for a steady scene.Checklist
main; no other open PR implements the same functions (#13796 pairs 2D and one-slice 2D-array storage images in the storage cache, not image table textures)NotImplemented_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)main)Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-04T15:58:16Z.
Review: APPROVED
Head
2c8d89549fmerged onto currentmainb11c7bf84f(clean merge, local only): code read, red/green check and a run on two Windows GPUs, NVIDIA and AMD's Windows driver, which the description and the CI runs don't cover. I don't have the title, so the memory and frame numbers are not reproduced here.Windows 11 Home 10.0.26200, Ryzen 7 7700X, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release,BUILD_TESTING=ON.ANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation,ctest -R '^(agc_driver_image_table.*|agc_driver_bindless_images.*|agc_driver_sampled_cache_budget.*|agc_driver_storage_cache_budget.*)$',ANYPS5_GPUselecting the device (confirmed bySelected GPU):main10de:2c05)1002:164e)VUID-lines and no missing-layer line on either side.agc_driver_image_table_vouched_lookupsruns here (not skipped) and passes.agc_driver_image_table_array_viewsandagc_driver_graphics: 3 of 3 on each GPU. The new test printsimage table array view tests passed.ShaderResources.cpptaken back frommainfails the new test on both GPUs withthe one-layer 2D array entry did not bind the 2D entry's texture (0 shared).check_conventions.py --base mainpasses on the merge.Read through the change:
arrayPartnerspairs only aImage2DArray-shaped entry whose T# decodes as a one-slice 2D array (baseArrayanddepthOrLastArray0) with aImage2D-shaped 2D entry whose eight words match once word 3's type field is masked, and only when their depth-compare flags agree. Written (storage) entries and null or undecodable T#s are left out.table.elementTexturesslot is set before its array entry looks it up. A partner that was rejected or substituted (max()), or a texture without an array view, falls back to the entry's own resolution.bindgoes throughplace, which always appends totextures, soarrayViewTextures.insert(textures.size() - 1u)names the slot that entry just took. A rejectedbindreturns a message and nothing is recorded.binding.flags != 0) readsarrayViewTextures. The compactVK_DESCRIPTOR_TYPE_SAMPLED_IMAGEpath doesn't, and table entries don't go through it.ArrayView()is created once under its own mutex from the constructor's 2D view info: same format, components and level range,layerCount1, its min LOD kept,pNextreplaced by a sampled-only usage. It is destroyed inrelease()with the other views. A 2D-array view of a single-layer 2D image is valid Vulkan, and the validation layer agrees on both drivers.I found nothing to change.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T16:08:21Z.
Review: APPROVED
@hugodearaujo this adds the Windows and AMD proprietary run that the description doesn't have. The pairing reads right to me, and it passes on the RX 9070 XT here.
Reading:
arrayPartners(core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp:5514) masks only the type field of word 3 (:5533). It pairs anImage2DArrayentry withbaseArray == 0anddepthOrLastArray == 0to a 2D entry with the same words and the same depth-compare flag. Written (storage) entries and undecodable T#s are skipped.bind(:5579-5601), which runs the same sampler checks as for any entry.bindonly returns empty afterplacepushes the texture (:5573,:5599).arrayViewTextures.insert(textures.size() - 1u)(:5682) then names that entry's own texture slot.reusable = false(:5650,:5679), as #10256's substitutes do.Texture::ArrayView()(core/libs/prx/libSceAgcDriver/Graphics/src/Texture.cpp:1274) is created lazily underarrayMutex, and the release path destroys it next to the sRGB views (:1314-1315).What I ran: head
2c8d89549fmerged ontomainb11c7bf84f(mergea83f093357), Windows 11, WinLibs GCC, Release, AMD Radeon RX 9070 XT, driver 32.0.32015.12012, withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. Your set,^agc_driver_image_table|^agc_driver_bindless_images:agc_driver_image_table_array_views.main: 9 of 9 pass. Neither log has aVUID-,SYNC-HAZARDor missing-layer line, andagc_driver_image_table_vouched_lookupsran rather than skipped on this GPU.partnersalways empty inresolveImageTables(:5647),agc_driver_image_table_array_viewsfails withthe one-layer 2D array entry did not bind the 2D entry's texture (0 shared), as your description says.One question, not blocking:
ArrayView()builds its view fromarrayInfowith a freshpNextchain, holding only the sampled-usage struct and, when it is nonzero,VkImageViewMinLodCreateInfoEXT(Texture.cpp:1278-1287).createFirstLayerViewkeeps only the min LOD from the original chain (:1209-1216). Does any 2D texture constructor put something else in that chain, such as a usage restriction or a YCbCr or ASTC struct, that the array view would then lack? If none does today, that's fine. A line in the debt entry would keep it from being missed later.Not checked here: the Spider-Man 2 runs, which need your stack, and the perf numbers, which come from your machine.
Imported from boykopovar/AnyPS5. Originally posted by BunnyFl on 2026-11-04T21:14:10Z.
Review: APPROVED
@hugodearaujo re-checked at
dce73ab2b5, still approved.git range-diffagainst my approval of2c8d89549f: your commit is unchanged, anddce73ab2b5is the merge ofmainthat resolved theShaderResources.cppconflict next to #15741. I built and ran that merge rather than reading the resolution only.What I ran
Windows 11 Pro 10.0.26300, WinLibs GCC 15.2, Release, AMD Radeon RX 9070 XT (driver 32.0.32015.12012), this head merged cleanly onto
mainb611e634f7(5241ad6f5a), withANYPS5_REQUIRE_VULKAN=1 ANYPS5_NO_SHADER_CACHE=1 VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validationandctest -V:agc_driver_image_table*,agc_driver_bindless_images, and the newagc_driver_image_table_array_views): 10 of 10 pass. NoVUID-orSYNC-HAZARDlines, and nowas not found but was requested by env var VK_INSTANCE_LAYERSline.core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppfrommainfailsagc_driver_image_table_array_viewsand passes the other 9, again with noVUID-orSYNC-HAZARDlines.Overlap
I left this out of my first review;
tools/pr_overlap.py --branchon this head:resolveImageTables(resource,guestBytes,firstLayer) at the same lines (core/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cpp:5691onmain) where this PR adds the one-layer array choice. Whichever lands second has to redo its change on the other.ImageTableReuseCounts(core/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hpp:161onmain) and to itsreturninImageTableReuses. A mechanical conflict only.main, and the tool could not compare them. Of those, 15 change the functions this PR touches; apart from #13796 and #10743 (per-layer storage views of a 2D array), they are larger reworks of the same functions (GPU image tables and descriptor heaps: #7642, #9508, #10193, #13928, #13929; table reuse: #6223, #6340; others: #6280, #6481, #6804, #10049, #10497, #15059).Imported from boykopovar/AnyPS5. Originally posted by gabichuuuuu on 2026-11-08T15:48:41Z.
Review: COMMENTED
Ran
cbc54ed039merged onmain302864d48con Windows 11 x64 (WinLibs GCC 15.2), on an NVIDIA laptop GPU (Turing, driver 621) and an Intel iGPU (driver 101.70xx), withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Khronos validation layer 1.4.368),ctest -R '^agc_driver_image_table' -V:mainImageTableArrayViews.cppreadsImageTableReuseCounts::arrayViewsShared, which this PR adds, so there's no run of the tests without the change.agc_driver_image_table_cacheopen none). No log haswas not found but was requested by env var VK_INSTANCE_LAYERS, and no log on either side has aVUID-. To be sure validation messages reach these logs, the same layer with best practices on printed 28BestPractices-warnings into anagc_driver_recorderlog on each GPU.AI-assisted: yes.