fix(agc): return a synchronous draw's render target memory to the image pool #9188
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/9188"
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 thuanquang on 2026-10-21T14:43:45Z.
What
A synchronous draw (a draw into a color target that has no resident image) renders into a
RenderTarget, a per-draw image of the target's size.RenderTargettakes its memory from the image pool (AllocateImageMemory) but freed it withvkFreeMemory, so the pool never got the memory back. Every synchronous draw therefore created and freed device memory of the whole target's size.It now keeps the allocation's size and memory type and returns the memory with
ReleaseImageMemory, asOwnedImagedoes. The next synchronous draw of the same size takes it from the pool. The image is still destroyed before its memory is released. Today the only productionRenderTargetis the synchronous draw's, and it is destroyed afterSubmitAndWait.Tested
Rechecked merged onto
main14c99b52ac(2026-10-26, AMD Windows driver 32.0.21045.16010):RenderTargetMemoryReusefails withmain'sResources.cpp(the twoFAIL:lines below) in 3 of 3 rounds; with this change it passes 3 of 3.agc_driver_cmask_fast_clear,agc_driver_srgb8_color_targetandagc_driver_packed_unorm4444_color_target.VUID-errors are 3 ofVUID-VkPipelineColorBlendStateCreateInfo-pAttachments-00605inagc_driver_srgb8_color_target. Plainmain14c99b52acreports the same 3 there (#6782 enablesindependentBlend).Rebased onto
main513ca7e558(headfc74d9349f) for the needs-rebase conflict: #7919 added theagc_snapshot_copy_failuretest block next toagc_buffer_pool_tests, whosetarget_sourcesline this PR extends withResources.cpp. Both are kept and the PR's change is unchanged (git range-diff). On this head, built clean: the 12 tests below, 3 rounds, all pass; under the Khronos validation layer 12 of 12 pass with 0VUID-lines, the layer inserted 11 times, no "was not found" line.New test case:
RenderTargetMemoryReuseinagc_buffer_pool(mock device, CPU only). It checks that a released render target's memory stays in the image pool and that the next render target of the same size takes it.agc_buffer_pool_testsnow also compilesResources.cpp.mainf90a3f7297with only the test fails:RX 6700 XT (gfx1031), AMD Windows driver 32.0.21045.5002, Windows 11 26200, MinGW GCC 15.2 Release:
agc_buffer_pool, 10 tests that draw through non-resident color targets andagc_driver_linear_target_resident, whose target is imported and resident:agc_driver_uint8x4_color_target_no_residentagc_driver_color1555_target,agc_driver_color565_targetagc_driver_packed_float_color_target,agc_driver_packed_unorm_color_target,agc_driver_packed_mip_tail_targetagc_driver_pixel32_ar_export,agc_driver_pixel_uint16_exportagc_driver_pixel_ancillary_word,agc_driver_pixel_fixed_point_positionagc_driver_linear_target_residentKhronos validation layer A/B (
VK_LOADER_DEBUG=layershows the layer inserted in all 11 GPU test processes on both sides, with no "was not found" line), same 12 tests:mainwith only the new test: 11 of 12 pass (the new case fails as above), 0VUID-lines.VUID-lines.PPSA14363 (METAL GEAR SOLID Master Collection Vol. 1, own dump), RX 6700 XT:
APS5_PROFILE_DRAW=1, warm shader cache, the same scripted input (title screen, Game Selection, Start Game).sceNpTrophy2GetTrophyInfo: trophy 19 is not in .../trophy00.ucp, was bypassed locally; #9115 fixes it.[draws]and[bufferpool]lines, per 10 s window in the PS1 section:mainf90a3f7297preparephase per synchronous draw (allocation and image creation)writeBackphase per synchronous draw (includes the free)The game reached its 3000th guest flip (
flipcounts of the[packets]lines, PS1 logos) after 107.9 s onmainand 69.4 s with this change. On both sides the host stopped presenting about 60 s into the run, while the guest kept flipping. That happened withAPS5_PROFILE_DRAW=1on this unattended desktop, so treat the flip times as rough. The per-draw rows above don't depend on it.Gameplay, 2026-10-22:
main6ef5a1c4c9+ #9115 + #9373 on both sides.libSceAgcDriver.prxwas built with and without #9188 and #9202; nothing else differs. Two 600 s runs per side, alternating, with the same scripted input andAPS5_PROFILE_DRAW=1:No run stopped. The second run with both changes was slower at the Dock (107 to 147 presents per 10 s, against 124 to 196 in the first). These runs held only this PC's GPU lock, so other work on the PC may have slowed it. The title's progress is tracked in its bring-up discussion, #9615.
With #9879: #9879 creates the host import of these three targets. In our runs with its branch (2026-10-23), the PS1 part made no synchronous draws on the RX 6700 XT, so once #9879 is merged this change no longer affects PPSA14363 on that GPU. It still applies to every target #9879 keeps synchronous (listed in #9879). The two PRs don't depend on each other and merge cleanly in either order.
Other GPUs, from reviewers: @MaxLikesCode, NVIDIA GeForce RTX 4090, driver 617.42, Windows 11 Pro 26200, head
c9a9831f7merged ontomain38d3c0858:mainand with this PR, without and with the validation layer, with noVUID-lines.tools/select_tests.pyon the merged tree: 1166 of 1169 pass. The 3 that fail (agc_driver_sample_order,_grid_reference,_recipe_depth_locations) fail the same way onmainon that GPU (#9313).Not tested: AMD GPUs other than the RX 6700 XT, Linux. The PS1 section is still far from 60 fps: each synchronous draw also copies the whole 24 MiB target in and out. That is a separate change.
Overlap: #10194 (@harry-z-kang) adds allocation accounting on the same render-target release path in
Resources.cpp; agreed order: this PR first, then #10194 rebases around itsReleaseImageMemorycall.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 MaxLikesCode on 2026-10-21T19:53:22Z.
RTX 4090 (Ada) on Windows, head
c9a9831f7merged ontomain38d3c0858(clean).NVIDIA GeForce RTX 4090, driver 617.42, Windows 11 Pro 26200, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON. The 12 tests from the description (agc_buffer_pooland the 11 that draw through non-resident color targets) withANYPS5_REQUIRE_VULKAN=1andANYPS5_NO_SHADER_CACHE=1, 3 runs without and 3 withVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(Vulkan-ValidationLayersvulkan-sdk-1.4.363.0, implicit layers disabled). The loader log shows the layer inserted in all 11 GPU test processes, and no log haswas not found but was requested by env var VK_INSTANCE_LAYERS.VUID-mainmain+ #9188tools/select_tests.pyon the merged tree: 1166 of the 1169 selected tests pass. The 3 failures areagc_driver_sample_order,_grid_referenceand_recipe_depth_locations, which fail the same way onmainon this GPU (#9313, fixed by #9056).agc_driver_image_array_window_past_layer_limitis left out: it does not compile with MinGW (#8310).AI-assisted: yes (Claude Code)