fix(agc): release the stencil shadow probe image once when its allocation fails #26178
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/26178"
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 Plyxen on 2026-11-23T11:45:47Z.
What
ProbeStencilShadowCopy(Graphics/src/DepthSurface.cpp) destroys a probe image twice when its memory allocation fails. Themakelambda hands the image to anOwnedImageand then, ifAllocatethrows, destroys the image by hand and rethrows; unwinding then runsOwnedImage::~OwnedImage(), which callsvkDestroyImageon the same handle. The probe's outercatchonly runs after that. The image also leaks ifmake_sharedthrows aftervkCreateImagesucceeded.OwnedImageis now created empty, takes the handle oncevkCreateImagehas succeeded, and is the only owner. The manualvkDestroyImageand itstry/catchare gone.mihiii1337 found this shape in the resolve probe of #25911, which I had copied from here; #25911 fixes its own copy and this is the original. Of the other places in this file that hand an image to an
OwnedImage, the depth upload image, the native depth samples, the sampled depth shadow andDepthPlaneCopyrelease it through one owner;Texture.cppalready creates the owner empty first, as this change does. I did not trace the failure paths of the depth surface's own image.tools/pr_overlap.py --branchconfirms no overlap, and could not compare 20 open pull requests that conflict withmainand changeDepthSurface.cpp(#1368, #1395, #6808, #7256, #7642, #9508, #9895, #9950, #10193, #11444, #11551, #13863, #13920, #13928, #13929, #15621, #18185, #20315, #22062, #22647). I read each one'sDepthSurface.cpppatch: none changes a line ofProbeStencilShadowCopy.Tested
Windows 11 Pro 10.0.26200, Ryzen 7 9800X3D, WinLibs GCC 15.2.0 r7, Release,
BUILD_TESTING=ON,main318cc76b1eand the change on it, same machine.ANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1,VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation(1.4.363),VK_LOADER_DEBUG=layer, GPU selected withANYPS5_GPU,ctest --test-dir build -R '^agc_.*(depth|stencil)' -V -j 2(116 tests).mainVUID-VUID-VUID-VUID-The loader logs
Insert instance layer "VK_LAYER_KHRONOS_validation"158 times in each of the four logs and neverwas not found but was requested by env var VK_INSTANCE_LAYERS.A separate build with a temporary print at the top of the probe (not in this change) shows that 14 of the 116 tests run it, 187 times on each GPU, for
D32_SFLOAT_S8_UINTat 2, 4 and 8 samples:agc_driver_stencil_copy_draw,agc_driver_stencil_replay,_no_gpland_unsuppressed, and tenagc_driver_native_depth_*tests.The failing path itself is not tested: no test makes the probe's allocation fail, so the double destroy is shown by reading the code, and these runs only show that the success path is unchanged.
tools/check_conventions.pypasses. Not run on Linux or macOS. No title tested.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)1002:13c0), driver 24.30.36 (32.0.13036.4), Windows 11; NVIDIA GeForce RTX 5080 (10de:2c02), driver 616.56, Windows 11🤖 Generated with Claude Code
Imported from boykopovar/AnyPS5. Originally posted by Superseabas on 2026-11-23T12:38:04Z.
Review: APPROVED
Windows check of head
2c96bd7c5bwith GCC 16 on an NVIDIA and an AMD GPU, merged ontomain071799dc88(clean merge), and a read of the ownership change.Setup: Windows 11 Home 10.0.26200, WinLibs GCC 16.2.0 (
x86_64-ucrt-posix-seh, r3), Release full build, run from PowerShell withANYPS5_REQUIRE_VULKAN=1,ANYPS5_NO_SHADER_CACHE=1andVK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked withANYPS5_GPU: NVIDIA GeForce RTX 5070 Ti (621.01) and the Ryzen 7 7700X's integrated AMD Radeon (1002:164e, Adrenalin 26.10.2). This was built together with #26096, #26174 and #26179, which touch other files.^(agc_driver_stencil.*|agc_driver_native_depth.*)$(the 14 tests that reach the probe, and the rest of those two groups):main44 of 44, and with this PR 44 of 44 in 2 of 2 runs, on both GPUs. The skips are the same on both sides:agc_driver_native_depth_driver_queued_fill(Windows by design) on both GPUs, andagc_driver_stencil_ref_exporton the RTX. NoVUID-lines.The code: the double destroy is real on
main.~OwnedImage(Texture.cpp:66) destroysimagewhen it is set, and thecatchdestroyed it first. With the owner created empty, every exit destroys the image once:vkCreateImagefails: the owner holds no image, andReleaseImageMemoryreturns at once for null memory.Allocatethrows: the owner holds the image but no allocation.vkBindImageMemoryfails: the owner holds both.Texture.cppcreates empty owners the same way (:379,:638,:653,:1017). As the description says, no test makes the allocation fail, so the runs only show the success path is unchanged.AI-assisted: yes (Claude Code)
Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-23T12:44:11Z.
Review: APPROVED
Reviewed and built exact head
2c96bd7c5b1462ca8ec134244abaa51f8234db6f.The ownership change closes both failure windows: the owner exists before
vkCreateImage, receives the handle through a non-throwing assignment immediately after successful creation, and is then the sole image destroyer through allocation and bind failures. A focused native lifetime A/B with the same ownership sequence produced two destroys on the old allocation-failure path and exactly one on the PR path; the PR success control also destroyed exactly once. The independently reported Vulkan fault injection confirms the same result through the real validation layer.I also configured the full recursive checkout and built
agc_driver_stencil_copy_draw_testswith GCC 15.2. The exact-head test passed withVK_LAYER_KHRONOS_validation,ANYPS5_REQUIRE_VULKAN=1, and shader caching disabled on both physical notebook adapters:8086:a78b), driver 101.6127, Vulkan 1.3.295: 1/1 passed.10de:2860), driver 621.01, Vulkan 1.4.357: 1/1 passed.Both runs selected and reported the intended adapter, executed the actual Vulkan stencil-copy draw, and printed that both stencil values were written at the rasterized locations. No validation error appeared. This verifies the unchanged success path on these two GPUs; it is not a console/title test. Hosted Windows and project checks are green.
AI-assisted: yes.
Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-11-25T08:26:30Z.
Review: COMMENTED
Reviewed — no blocking findings
Nothing blocks this change; the points below are optional.
What I ran
Reviewed head
2c96bd7c5b1462ca8ec134244abaa51f8234db6f. I did not run commands or tests. I read the changed lines incore/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cppand theOwnedImagedefinition and destructor inTexture.hppandTexture.cpp. The manifest lists one changed file, included in the review bundle; no changed files were excluded.Results
OwnedImagedestruction.Findings
Blocking
None.
Non-blocking
None.
Not verified
I did not read the full 5,406-line changed file or run tests. The allocation-failure path itself was not exercised. The author reports success-path test runs on Windows with Radeon and NVIDIA GPUs; those results were not independently verified. No Linux or macOS run was reported.
To get this to a good state
Nothing is required.