fix(agc): reuse a recycled descriptor set only for a table of its own size #6567
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/6567"
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 SleglJan on 2026-10-15T20:56:03Z.
What
DescriptorCache::AllocateRewrittenhanded out any recycled set of the requested layout.PrepareDrawBindingstakes that path for the snapshot sets of recorded draws (every draw unlessAPS5_SYNC_DRAWSis set).PrepareDrawBindingswrites the table's present elements, up to its current element count, into whichever recycled set it gets.VUID-VkWriteDescriptorSet-dstArrayElement-00321.A set from a chain pool now records the variable count it was allocated with, as a dedicated-pool set already does since #6454. Recycled sets are kept per layout and variable count, so a draw reuses a set only for a table of the same size, and allocates otherwise.
Tested
Linux 7.2.10 (CachyOS), RTX 3080 with NVIDIA 615.78.08, GCC 16.2.1, Release,
BUILD_TESTING=ON.main8a526d449, after #6454 merged. Arch Linux container on a 16-thread Xeon E5-2640 v3, GCC 16.2.1, Release, lavapipe (Mesa 26.2.4).mainplus only the test hunk:agc_driver_graphicsandagc_descriptor_cachefail witha recycled descriptor set served a larger variable image table than it was allocated for.agc_descriptor_pool_reset_failureandagc_compute_descriptor_layout_flags.ctest -R 'agc|shader|recompiler|request|tess': this change 747 of 765 pass, andmain8a526d449built the same way also 747 of 765. Both fail the same 18; the container does not permit userfaultfd, and 15 of them report guest memory that is not write-watched or needs to be.main.agc_driver_graphics(descriptorCacheTests, mock device) has a new case: a set allocated for a 3-element table is recycled, then the same layout is asked for with 5 elements and again with 3.mainfa9365ca7it fails witha recycled descriptor set served a larger variable image table than it was allocated for.ctest -R '^agc': 596 tests, 1 failure, 1 skipped.agc_driver_store_over_untrackedfails onmaintoo (#6359, #6385), andagc_driver_stencil_ref_exportis skipped.main4186f06a9with local changes the title needs, plus #6537's change, without this one;dstArrayElement-00321.00321messages 007 showed before came from #6537's cause. This change rests on the test above.main5d9dcc42d(https://github.com/boykopovar/AnyPS5/pull/6567#issuecomment-6210190589):mainit crashed on the driver thread in 4 of 6 runs once it reached character creation;mainfaulted in the same scene of the opening cinematic, on a store 16 bytes past a 0x208-byte block insidevkUpdateDescriptorSetsfromShaderResources::PrepareDrawBindings;agc_driver_graphicspasses on an RTX 5080 (NVIDIA 615.78.08), a Radeon 610M (RADV) and lavapipe.maina5e2a80c6plus other PRs and a local change, listed at https://github.com/boykopovar/AnyPS5/pull/6537#issuecomment-6213402865):corrupted double-linked listat 470 s, andmunmap_chunk(): invalid pointerat 390 s withMALLOC_CHECK_;main55b968a239with RADV on a Radeon 680M, run by fma-rc:mainplus only the test hunk fails 3 of 3 runs witha recycled descriptor set served a larger variable image table than it was allocated for. With the change it passes 3 of 3, andmainalone, without the test hunk, passes 3 of 3.main93e54cedd, from before #6537, plus #6280's driver commit b9badf4c2 and a local stencil patch that doesn't touch descriptors; https://github.com/boykopovar/AnyPS5/pull/6567#issuecomment-6248294928):libSceAgcDriver.prx, the run reached the 900 s stop with no heap message, core or device loss. Their own patch with the sameShaderResources.hpp/.cpphunks, written before they found this PR, did the same in 3 of 3 runs;agc_descriptor_cache,agc_driver_graphics,agc_descriptor_pool_reset_failureandagc_compute_descriptor_layout_flagspass on lavapipe with 544e7afb3 onmainccb0c0926.Related
PrepareDrawBindingspaired the fragment image table's write with the set-0 binding.std::optional<std::uint32_t> variableCounttoSetAllocationfor its kept sets and set it on dedicated-pool sets. This change keeps that member, fills it onAllocate's two chain-pool returns (a hit in an existing chained pool, and a new chained pool), and keysrecycledby layout and count. Pooled sets keep a null layout and no sizes, as onmain.Checklist
main; no other open PR implements the same functions.mdfiles or images added to the repository🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by github-actions[bot] on 2026-10-15T21:03:03Z.
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.
core/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/tests/Graphics.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppcore/libs/prx/libSceAgcDriver/Graphics/include/ShaderResources.hppcore/libs/prx/libSceAgcDriver/Graphics/src/ShaderResources.cppImported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-16T07:14:27Z.
Demon's Souls (PPSA01341) reaches this. On
main5d9dcc42dit crashes on the driver thread in 4 of 6 runs once it reaches character creation, as a SIGSEGV in the decode memo walk ordouble free or corruption, so something was overwriting the heap.I ran it with a small LD_PRELOAD allocator that ends every 0x1f0..0x210-byte block at a PROT_NONE page. It runs slower that way, and both runs on
mainfaulted earlier, in the same scene of the opening cinematic (~1360 s): a store inlibnvidia-glcore615.78.08 16 bytes past a 0x208-byte block, insidevkUpdateDescriptorSetscalled fromShaderResources::PrepareDrawBindings(fromrecordDraw/Graphics::Draw). That is the write past a recycled set's variable count you describe.With this PR on the same
main, two runs with the same steps went through that scene to the end (1550 s) with no fault.agc_driver_graphicspasses on an RTX 5080 (NVIDIA 615.78.08), a Radeon 610M (RADV) and lavapipe.Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-16T07:33:15Z.
Thanks @fma-rc, that's the first title reported to reach this, and the guard-page runs pin it to the same write. I added your result to Tested.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by fdfawef324 on 2026-10-16T10:24:18Z.
A Windows data point to go with fma-rc's: Demon's Souls (PPSA01342), RTX 3060, NVIDIA 591.86, Windows Server 2025 (26100), MinGW-w64 GCC 15.2.0, Release. The per-run table is on #6537. Every run with the fix had both this PR and #6537 cherry-picked (patch-identical to 544e7afb3 and
9800f3ab9), so these runs can't say which one matters for this title.maina5e2a80c6+ other PRs and a local change (listed on #6537)VK_ERROR_DEVICE_LOSTat 778 s (still looking into it)nvoglv64.dll, at the same call as fma-rc's guard-page fault. The firstlibSceAgcDriverreturn address on the stack isShaderResources::PrepareDrawBindings+0x1df9, right after its onlyvkUpdateDescriptorSetscall. This PR's cause and #6537's both write through that call, so the site doesn't pick between them.VulkanDevice::PrepareDispatch; we can't tie it to either PR.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-16T10:33:17Z.
Thanks @fdfawef324, a second platform and driver on Demon's Souls: with #6537 and this PR, 2 of 4 runs reached your 3000 s limit, where all 6 without died. I added your result to Tested, with your note that these runs can't tell the two apart.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-17T22:07:49Z.
Death Stranding 2 (PPSA02015) reaches this too, Linux, RTX 5080. On my DS2 stack without this PR, runs died on glibc heap errors (
corrupted double-linked listat 470 s,munmap_chunk(): invalid pointerat 390 s withMALLOC_CHECK_). With the PR on the same stack, three runs went 460, 536 and 1280 s and none hit a heap error. They ended on device memory (#6890) and later stops.The test also holds on current main
55b968a239, RADV on a 680M: main plus only your test hunk fails 3/3 witha recycled descriptor set served a larger variable image table than it was allocated for, main plus the PR passes 3/3, main alone 3/3.Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-17T22:13:41Z.
Thanks @fma-rc. Death Stranding 2 is the second game reported to reach this, after Demon's Souls, and the RADV runs show that the test holds on current
maintoo. I've added both to Tested.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-18T09:34:17Z.
Demon's Souls (PPSA01341 v1.07) on Linux hits this too. Here the base has neither #6537 nor this PR, so the runs separate the two causes.
Setup: Nobara 44 (kernel 7.2.0), RTX 5070 Ti, NVIDIA 595.91.07, GCC 16.2.1, Release. The base is
main93e54ceddplus #6280's driver-side commit b9badf4c2 and a local one-file stencil patch that doesn't touch descriptors. Thatmainpredates #6537 (merged 2026-10-18). Every run used the same route (title, character creation, the first tutorial level), the same warm shader cache and the same stop at 900 s, with no compiler running on the host.Without the change, 5 of 5 runs died in the level between 366 s and 680 s on glibc heap checks:
corrupted size vs. prev_sizetwice (680 s, 452 s),free(): invalid pointeronce (366 s) and SIGSEGV twice (415 s, 393 s). In 4 of the 5, the frame content stopped changing first (at about 275 s in three runs, 366 s in one) while[present]and the draw counters kept going, and the abort came 85 to 140 s later. Four of the five runs carried one extra change each (no b9badf4c2 in one, thenAPS5_STORE_AT_FLIP=1, #6926 or #6931 cherry-picked). None of them changed the outcome.With this PR's commit 544e7afb3 cherry-picked onto that base, and only
libSceAgcDriver.prxswapped, the run reached the 903 s stop and exited 0: no heap message, no core, no device loss. A patch of ours with the same ShaderResources.hpp/.cpp hunks, written from the samevkUpdateDescriptorSetswrite before we found this PR, did the same in 3 of 3 runs (two crash checks and one profiled run, 900 s each). So on this base it's 4 of 4 clean with the fix and 5 of 5 crashed without it, same night, same procedure. The level frame rate was 0.80 fps median in both arms (the title is CPU-bound here), so the change costs nothing we can measure.Your
agc_descriptor_cachecase passes on lavapipe (Mesa 26.2.1 llvmpipe) with 544e7afb3 cherry-picked ontomainccb0c0926, along withagc_driver_graphics,agc_descriptor_pool_reset_failureandagc_compute_descriptor_layout_flags.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-18T09:53:31Z.
Thanks @fisherjoey, I've added your runs to Tested. Like fma-rc's earlier Demon's Souls runs, yours are on a base without #6537, so the fix arm has this change and not #6537's. The Windows runs had both and couldn't tell them apart.
AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by fisherjoey on 2026-10-19T02:30:19Z.
#6454 has landed on
main, so this is now the "whichever lands second" case from the description. The bug is still there onmain40393b0f9:SetAllocationhasstd::optional<std::uint32_t> variableCountand the new kept-set path compares it, butrecycledis still keyed by layout alone, and the two chain-pool returns inAllocateleavevariableCountempty. A recycled set can still go to a draw whose table is larger than the one it was allocated for.Here is how we resolved it on our local stack, keeping
main's struct:recycledbecomesstd::map<std::pair<VkDescriptorSetLayout, std::uint32_t>, std::vector<SetAllocation>>.AllocateRewrittenlooks up{layout, variableCount.value_or(0u)}, andRecyclefiles the set under{layout, allocation.variableCount.value_or(0u)}.Allocatefill in the count:return {set, pool.handle, index - 1, updateAfterBind, VK_NULL_HANDLE, {}, variableCount, {}};and the same forchain.size() - 1. The dedicated-pool return onmainalready records it.With that on
main40393b0f9(plus #6280 and #6926, which don't touch descriptors), lavapipe passes 1535 of 1536 tests. The one failure isapplication_heap_lazy, which also failed on our previous stack. We haven't run Demon's Souls on this rebased build yet, so the game result in my earlier comment is from the older base.AI-assisted: yes
Imported from boykopovar/AnyPS5. Originally posted by SleglJan on 2026-10-19T03:02:48Z.
@fisherjoey thanks. The rebase is pushed as
04aef899aonmain8a526d449, and it is the resolution you describe:main'sstd::optionalvariableCountstays;recycledis keyed by layout and the set'svariableCount.value_or(0u)in bothAllocateRewrittenandRecycle;Allocatenow fill in the count.On a Linux container with lavapipe,
main8a526d449plus only the test hunk failsagc_driver_graphicsandagc_descriptor_cachewitha recycled descriptor set served a larger variable image table than it was allocated for. Both pass with the change. With the change, the wideragc|shader|recompiler|request|tessset fails the same 18 of 765 tests asmainbuilt the same way. Details are in the description.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by Capmare on 2026-10-19T12:50:14Z.
Confirming this on a title: Marvel's Wolverine (PPSA03671), Linux, NVIDIA GeForce RTX 4070 SUPER (driver 615.71.09), on a tree with #7395. Before this change the game died at about present 580, during the first build of an image table with 12,447 entries. The host heap was corrupted, and the crash site changed from run to run. With
VK_LAYER_KHRONOS_validationthe cause shows asVUID-VkWriteDescriptorSet-dstArrayElement-00321:pDescriptorWrites[106].dstArrayElement (12438) + descriptorCount (1) is larger than pDescriptorCounts (12435)for a recycled set.I found it independently and made the same change locally: the recycled sets are keyed by layout and variable count. With it, 6 of 6 runs of 240 seconds survive. Before, 6 of 6 crashed at about 110 seconds. So this PR fixes the crash that stops Wolverine there.