Repository navigation
fix(agc): release the stencil shadow probe image once when its allocation fails - #26178
Conversation
…tion fails ProbeStencilShadowCopy handed the image to an OwnedImage and then destroyed it by hand when Allocate threw, so unwinding destroyed the same handle a second time. The OwnedImage is now created empty, takes the handle after vkCreateImage succeeds and is the only owner, which also closes the leak if make_shared throws after the image exists. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
|
Looks good on AMD RDNA4 with the Khronos validation layer. The depth and stencil tests I ran pass 3/3 on the head, with 0 What this run adds.
Code.
Negative control (fault injection).
GPU. Head
Validation.
Host:
AI-assisted: yes |
Superseabas
left a comment
There was a problem hiding this comment.
Windows check of head 2c96bd7c5b with GCC 16 on an NVIDIA and an AMD GPU, merged onto main 071799dc88 (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 with ANYPS5_REQUIRE_VULKAN=1, ANYPS5_NO_SHADER_CACHE=1 and VK_INSTANCE_LAYERS=VK_LAYER_KHRONOS_validation. GPUs, each picked with ANYPS5_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) destroys image when it is set, and the catch destroyed 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.cpp creates 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)
mihiii1337
left a comment
There was a problem hiding this comment.
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_tests with GCC 15.2. The exact-head test passed with VK_LAYER_KHRONOS_validation, ANYPS5_REQUIRE_VULKAN=1, and shader caching disabled on both physical notebook adapters:
- Intel RaptorLake-S Mobile Graphics (
8086:a78b), driver 101.6127, Vulkan 1.3.295: 1/1 passed. - NVIDIA GeForce RTX 4070 Laptop (
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.
|
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.
|
MarcZX10
left a comment
There was a problem hiding this comment.
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 in core/libs/prx/libSceAgcDriver/Graphics/src/DepthSurface.cpp and the OwnedImage definition and destructor in Texture.hpp and Texture.cpp. The manifest lists one changed file, included in the review bundle; no changed files were excluded.
Results
| Check | Result | Note |
|---|---|---|
| Diff and ownership path | passed | Single-owner cleanup is consistent with OwnedImage destruction. |
| Tests | not run | The description reports Windows GPU test runs; I did not run them. |
| Allocation failure control | not run | No failure-injection test was run. |
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.
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