feat(agc): report live device memory allocations when the device is lost #13148
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/13148"
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 Prophet069 on 2026-10-30T04:16:01Z.
What
When the Vulkan device is lost,
[device-fault]gives no hint whether memory pressure was involved. This countsvkAllocateMemoryandvkFreeMemoryper device through a wrapper around the device proc resolver. The device-loss report then prints the live allocations and bytes per memory type, split by size class (<1 MiB … ≥256 MiB). It also lists the eight largest callers: the buffer pool operation, host imports, resident mirrors and the pixel LDS pool, with everything elseunlabelled. A warning is printed when live allocations exceedmaxMemoryAllocationCount. Labels are thread-local RAII scopes, so code without one is unaffected.tests/LiveAllocations.cppchecks counting, size classes, labels, frees and the report text against a fake resolver.Tested
ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(VVL vulkan-sdk-1.4.321.0; neither log containswas not found but was requested by env var VK_INSTANCE_LAYERS),ctest --test-dir build -R <the 63 tests of agc_shader_memory_tests, agc_driver_cmask_fast_clear_tests, agc_driver_graphics_tests and agc_driver_sample_multisample_target_tests> -Von main8c8b998620and on this branch, same machine and GPU, plus the newagc_live_allocationstest: main 63/63 passed, 0VUID-; this branch 64/64 passed, 0VUID-.agc_driver_unclamped_normalized_blend(the #12916 multi-target regression,2 draws blending two targets each) passed on main and on this branch with the same validation settings, 0VUID-.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-10-30T04:51:49Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The PR introduces an unrelated regression that rejects draws with more than one merged color target, so I cannot approve this head.
What I ran
Reviewed head
6d832a9f907d6dee6a2ffe819b5d81f3b83d35b6against currentmainbase8c8b9986204d5b1cbb23847b363df00ae832ec9c; the merge preview is clean (7ee5166fcedc64b4976c5ceb79aa7577656e7235). Environment: Linux container; no compiler invoked.Results
7ee5166fcedc64b4976c5ceb79aa7577656e7235.git diff --checkRaw local command output
git merge-tree --write-tree ...:git diff --check ...: no output (exit status 0).python tools/check_conventions.py ...:Findings
Blocking
ExportTargetMergenow returns oneTargetMergeand requiresmerge.mask == 0for each partial-write color. A draw with two eligible color targets reaches the second iteration with a nonzero mask and fails this requirement instead of emitting both merges. The current base retains the vector-returningExportTargetMergespath and its checks for multiple non-overlapping targets. This change also replaces the recompiler'stargetMergesvector with onetargetMerge, so multi-target merge information cannot be represented downstream. Keep the multi-target behavior and add a regression test with two eligible targets, or separate the live-allocation reporting change from this refactor. Evidence: PR headState.cpp, PR headRecompiler.hpp, and current-baseState.cpp.Non-blocking
None identified in this source review.
Not verified
To get this to a good state
Preserve support for multiple merged color targets and add a focused regression test, then request another review. I will rerun the merge preview, diff check, and conventions check on the updated head.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-30T05:43:43Z.
Review: CHANGES_REQUESTED
Reviewed — changes requested
The allocation counter does not observe all allocations made by this device, so the live totals and allocation-limit warning can under-report Vulkan memory use.
What I ran
Reviewed head
ac751257a9fa8571cd0051964020e97d0e35cf31on base8c8b9986204d5b1cbb23847b363df00ae832ec9c; the merge preview is clean (318b92639880d9b7e0c655535d6d6bea239efb03). Environment: Linux x86-64. I ran the following checks; no local build or tests were run.Results
Check output
Findings
Blocking
DeviceFunctionand the direct marker/upload allocations:DeviceFunctionresolves throughdeviceProc, while the new wrapper is installed incontextDeviceProcat device setup. ThevkAllocateMemory/vkFreeMemorycalls for buffer markers and display uploads useDeviceFunction, so they bypasscountedAllocateMemory/countedFreeMemory. Those allocations are omitted from the live count and report, despite the PR describing per-devicevkAllocateMemory/vkFreeMemoryaccounting. Route these calls through the wrapped resolver (while preserving any existing deferred-destruction wrapper), or explicitly include them in the same accounting path. Add a focused test that exercises these direct allocations and confirms allocation and free totals change.Non-blocking
None found in the checks above.
Sources
Not verified
I did not run local tests, a build, Linux hosted jobs, specialized hosted jobs, or a game/device-loss reproduction. The author-reported Windows/GPU tests in the PR description were not independently run in this review.
To get this to a good state
Ensure all allocations owned by this Vulkan device flow through the accounting wrapper and add coverage for the marker/upload paths. I will re-run the same non-building checks on the new head and review the focused test result.
Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-30T13:26:55Z.
Review: CHANGES_REQUESTED
Thanks for the rebase; the diff is now only this change. Checked against the head
ac751257a9, and the points @oneandonlydean and @MarcZX10 raised hold, so this stays at changes:LiveAllocations.cpp:117-127:countingDeviceProclocks the process-wide registry mutex and does a hash lookup for every name other than the two wrapped ones, on the normal path. Resolve the realvkAllocateMemory/vkFreeMemoryonce, return them without the registry and forward everything else directly. Keep per-allocation bookkeeping cheap (no strings or map nodes) or make it opt-in. Add the alternated A/B on one title (frame p50/p99,DeviceProcLookupsper frame).LiveAllocations.cpp:139-152: the registry entry is never removed, so a second device with a recycledVkDevicevalue throws "set up twice". Erase it on the raw-resolver teardown path and add a two-devices-in-a-row test.LiveAllocations.cpp:59-83: bookkeeping can throwstd::bad_allocafter the driver returnedVK_SUCCESS. Make tracking best effort, mark the statistics incomplete, and test a failure after success.VulkanDevice.cpp:2181: the counter wraps the deferred-destruction resolver, so frees are subtracted whendeferredFreeMemoryqueues them, not when Vulkan frees. Count physical frees (compose the layers the other way) or report pending frees separately, with a composed-layer test.VulkanDevice.cpp:640,:718,:752,:988,:991:DeviceFunctionand the teardown frees go throughdeviceProc, so marker and display-upload allocations bypass the counter. Route them through the wrapper and test them.The new test only uses a fake resolver; it should also cover the cases above.
Imported from boykopovar/AnyPS5. Originally posted by ligmaSec on 2026-12-03T22:54:27Z.
Review: COMMENTED
CountAllocationsregisters aVkDevicepermanently. The new registry has no erase path, whileVulkanDevice.cppdestroys the device in cleanup. If Vulkan reuses that handle when a device is recreated,emplacefails and the new initialization throws the duplicate-registration error. Please unregister after the last wrapped free and cover both a failed initialization and a second mock device registration using the same handle. The trial merge also conflicts in the device and allocation code.AI-assisted: yes.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.