fix(agc): retain used descriptor sets in pipeline libraries #4456

Merged
Mouhand-Kaddo merged 2 commits from upstream-pr/4456 into main 2026-10-12 21:41:32 +00:00
Mouhand-Kaddo commented 2026-10-12 12:17:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-12T12:17:27Z.


What

Demon's Souls (PPSA01342) needs correct graphics-pipeline-library descriptor layouts while testing its image-table support. Split libraries currently assume pre-rasterization uses set 0 and fragment uses set 1, but ordinary fragment shaders can use set 0. Derive each part's used-set mask from its compiled bindings, retain exactly those native layouts, and include the selected layouts in its cache key. Invalid sets throw before shifting.

The original Linux investigation baseline ffa198407e70296c50d0011a4157a430408dd00e stopped earlier on a captured title shader:

resource analysis failed: GetImageResource dword 0 is not a valid runtime value

That prerequisite is covered by #757/#758, not this PR. After applying their table support, the native image-table test stopped at:

Thread 1 "agc_driver_imag" received signal SIGSEGV, Segmentation fault.
#8 AgcDriver::Graphics::LinkPipelineFromLibraries (...) from libSceAgcDriver.prx

The used-set correction passes that RADV test and has a standalone regression on current main.

Original overlap checks: #4363 fixes depth/stencil/view-mask state; #4445 fixes shader-module lifetime and is now merged and included in this branch's base. They touch the same linker for different behavior. Pairwise git merge-tree --write-tree checks against both heads are clean. Neither implements this descriptor-layout correction.

Tested

Windows review follow-up: rebased onto public main 27873b0f7 (includes #4445). Windows 11, WinLibs GCC 15.2.0 r7, Release, SPIRV-Tools enabled, RX 6900 XT / AMD driver 32.0.21045.5002.

  • Before correcting the mock, agc_driver_graphics reproduces shader library tests leaked Vulkan objects after the rebase. mockDestroyShaderModule now ignores VK_NULL_HANDLE, matching Vulkan destruction semantics for the moved-from modules.
  • All six focused checks listed below pass with --repeat until-fail:3 --timeout 30 (18 executions, no CTest skips). Default native pipeline-library linking passes with link-time optimization enabled. The explicit off and fast-only variants also pass. The graphics check takes about 5.5 seconds per run.
  • With the corrected mock and the three production pipeline files restored to upstream main, agc_driver_graphics still fails with shader library lost a used set or retained an unused set. The mock correction does not weaken the descriptor-layout regression.
  • Built the Windows relinker and libs runtime targets. Conventions and git diff --check pass.
  • Demon's Souls PPSA01342, Windows: relinked its clean ELF backups into a separate runtime using these rebuilt libraries, with the shader cache and default pipeline-library/LTO settings enabled. No missing imports. The RX 6900 XT initialized and shaders compiled and cached, but registration reported GetImageResource dword 0 is not a valid runtime value, matching the earlier image-resource investigation above. No menu or frame capture was verified within 600 seconds; the debugger showed the main thread in AwaitRegisteredPreparation. The test process was stopped at the limit. Gameplay remains unverified.

Linux, RX 6900 XT, RADV. Built the explicit test targets.

  • On clean public main plus only the new regression, agc_driver_graphics fails: AGC graphics: shader library lost a used set or retained an unused set.
  • With this production fix, six checks pass: agc_driver_graphics, agc_descriptor_pool_reset_failure, agc_compute_descriptor_layout_flags, agc_pipeline_library, agc_pipeline_library_off, agc_pipeline_library_fast_only. The regression exercises both shader parts with masks 0/1/2/3, native layout handles, push-constant slots, cache invalidation/reuse, and invalid set 32.
  • Native pipeline-library reuse checks run on RADV; the off variant deliberately creates whole pipelines. The broader graphics suite reports unavailable guest-arena heap-mirror checks, which are not coverage claimed here.
  • git diff --check and python3 tools/check_conventions.py --base HEAD^ pass.

Separate integration result, not this PR alone: Demon's Souls reached the main menu (New Game/Settings visible and user-confirmed interaction) on c36fd0a0 plus #757/#758/#4288/#3991/#4402, this fix, and a local split-descriptor-load correction. New Game then produced a black screen. Gameplay beyond the menu is unverified.

That title run temporarily used Linux udmabuf size_limit_mb=2048 instead of 64 because larger GPU imports were rejected at the default limit. The user restored 64 afterward and it was read back. The focused PR checks ran after restoration. Game assets were read directly through an enforced read-only view of the Windows gaming drive, without copying the game or changing its inputs.

Checklist

  • Based on current main; no duplicate of this descriptor-layout correction found. Same-linker changes in #4363/#4445 are disclosed above.
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt. No new stubs.
  • No notes, investigation .md files or images added to the repository
  • New third-party code is a submodule built from source. No third-party code added.
  • Generic behaviour, not specific to one title
  • Depends on: none for this fix. Full title bring-up still needs the separately listed support changes.
  • Unblocks: Demon's Souls PPSA01342 pipeline-layout blocker with image-table support; related Game bring-up #1283. Does not alone unblock public-main startup.
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4829276945 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4456). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-12T12:17:27Z. --- ### What Demon's Souls (PPSA01342) needs correct graphics-pipeline-library descriptor layouts while testing its image-table support. Split libraries currently assume pre-rasterization uses set 0 and fragment uses set 1, but ordinary fragment shaders can use set 0. Derive each part's used-set mask from its compiled bindings, retain exactly those native layouts, and include the selected layouts in its cache key. Invalid sets throw before shifting. The original Linux investigation baseline `ffa198407e70296c50d0011a4157a430408dd00e` stopped earlier on a captured title shader: ```text resource analysis failed: GetImageResource dword 0 is not a valid runtime value ``` That prerequisite is covered by #757/#758, not this PR. After applying their table support, the native image-table test stopped at: ```text Thread 1 "agc_driver_imag" received signal SIGSEGV, Segmentation fault. #8 AgcDriver::Graphics::LinkPipelineFromLibraries (...) from libSceAgcDriver.prx ``` The used-set correction passes that RADV test and has a standalone regression on current main. Original overlap checks: #4363 fixes depth/stencil/view-mask state; #4445 fixes shader-module lifetime and is now merged and included in this branch's base. They touch the same linker for different behavior. Pairwise `git merge-tree --write-tree` checks against both heads are clean. Neither implements this descriptor-layout correction. ### Tested Windows review follow-up: rebased onto public `main` `27873b0f7` (includes #4445). Windows 11, WinLibs GCC 15.2.0 r7, Release, SPIRV-Tools enabled, RX 6900 XT / AMD driver 32.0.21045.5002. - Before correcting the mock, `agc_driver_graphics` reproduces `shader library tests leaked Vulkan objects` after the rebase. `mockDestroyShaderModule` now ignores `VK_NULL_HANDLE`, matching Vulkan destruction semantics for the moved-from modules. - All six focused checks listed below pass with `--repeat until-fail:3 --timeout 30` (18 executions, no CTest skips). Default native pipeline-library linking passes with link-time optimization enabled. The explicit off and fast-only variants also pass. The graphics check takes about 5.5 seconds per run. - With the corrected mock and the three production pipeline files restored to upstream `main`, `agc_driver_graphics` still fails with `shader library lost a used set or retained an unused set`. The mock correction does not weaken the descriptor-layout regression. - Built the Windows relinker and `libs` runtime targets. Conventions and `git diff --check` pass. - Demon's Souls PPSA01342, Windows: relinked its clean ELF backups into a separate runtime using these rebuilt libraries, with the shader cache and default pipeline-library/LTO settings enabled. No missing imports. The RX 6900 XT initialized and shaders compiled and cached, but registration reported `GetImageResource dword 0 is not a valid runtime value`, matching the earlier image-resource investigation above. No menu or frame capture was verified within 600 seconds; the debugger showed the main thread in `AwaitRegisteredPreparation`. The test process was stopped at the limit. Gameplay remains unverified. Linux, RX 6900 XT, RADV. Built the explicit test targets. - On clean public main plus only the new regression, `agc_driver_graphics` fails: `AGC graphics: shader library lost a used set or retained an unused set`. - With this production fix, six checks pass: `agc_driver_graphics`, `agc_descriptor_pool_reset_failure`, `agc_compute_descriptor_layout_flags`, `agc_pipeline_library`, `agc_pipeline_library_off`, `agc_pipeline_library_fast_only`. The regression exercises both shader parts with masks 0/1/2/3, native layout handles, push-constant slots, cache invalidation/reuse, and invalid set 32. - Native pipeline-library reuse checks run on RADV; the off variant deliberately creates whole pipelines. The broader graphics suite reports unavailable guest-arena heap-mirror checks, which are not coverage claimed here. - `git diff --check` and `python3 tools/check_conventions.py --base HEAD^` pass. Separate integration result, not this PR alone: Demon's Souls reached the main menu (New Game/Settings visible and user-confirmed interaction) on `c36fd0a0` plus #757/#758/#4288/#3991/#4402, this fix, and a local split-descriptor-load correction. New Game then produced a black screen. Gameplay beyond the menu is unverified. That title run temporarily used Linux `udmabuf` `size_limit_mb=2048` instead of 64 because larger GPU imports were rejected at the default limit. The user restored 64 afterward and it was read back. The focused PR checks ran after restoration. Game assets were read directly through an enforced read-only view of the Windows gaming drive, without copying the game or changing its inputs. ### Checklist - [x] Based on current `main`; no duplicate of this descriptor-layout correction found. Same-linker changes in #4363/#4445 are disclosed above. - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs). No new stubs. - [x] No notes, investigation `.md` files or images added to the repository - [x] New third-party code is a submodule built from source. No third-party code added. - [x] Generic behaviour, not specific to one title - [x] Depends on: none for this fix. Full title bring-up still needs the separately listed support changes. - [x] Unblocks: Demon's Souls PPSA01342 pipeline-layout blocker with image-table support; related [Game bring-up #1283](https://github.com/boykopovar/AnyPS5/discussions/1283). Does not alone unblock public-main startup. - [x] AI-assisted: yes
kr4y4 commented 2026-10-12 18:39:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by kr4y4 on 2026-10-12T18:39:48Z.


Windows run on current main, which now has #4445.

Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head cace9368c merged into main 2a5eca11c, with no conflicts.

  • agc_pipeline_library, agc_pipeline_library_off, agc_pipeline_library_fast_only, agc_descriptor_pool_reset_failure and agc_compute_descriptor_layout_flags pass on both GPUs with --repeat until-fail:3.
  • agc_driver_graphics fails on both GPUs in every run with shader library tests leaked Vulkan objects.
    • It isn't a leak: mock.live ends at -4.
    • #4445 was merged after this branch's base 8fa5cc486. Since then, a prebuild hands its shader modules to the library and calls vkDestroyShaderModule on the moved-from VK_NULL_HANDLE, and ClearPipelineLibraries destroys the kept modules later.
    • mockDestroyShaderModule also counts the null destroy, so each kept module is counted down twice. In the first pass (mask 0), where the test stops, four modules are kept by the clear, which gives -4. A trace of the mock's handles shows the null destroys and the four destroys at the clear.
  • With mockDestroyShaderModule skipping it (if (module != VK_NULL_HANDLE) --mock.live;), agc_driver_graphics passes on both GPUs with --repeat until-fail:3.
  • With that mock change and main's Pipeline.cpp, PipelineLibrary.cpp and PipelineLibrary.hpp, it fails on both GPUs with shader library lost a used set or retained an unused set. So the regression still catches the bug.
  • Full suite (ctest --timeout 120 --parallel 4): the only failures are agc_driver_graphics above and, on the iGPU, agc_driver_f32_dot2_rounding, which fails the same way on main (no shaderFloat64, #4528).

Written with AI assistance.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6130380608 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4456#issuecomment-6130380608). Originally posted by [kr4y4](https://github.com/kr4y4) on 2026-10-12T18:39:48Z. --- Windows run on current `main`, which now has #4445. Setup: Windows 11 (26200), WinLibs GCC 15.2.0 r7, Release, CI configure flags, an RTX 4070 Laptop GPU and an Intel Raptor Lake-S iGPU. The head cace9368c merged into `main` 2a5eca11c, with no conflicts. - `agc_pipeline_library`, `agc_pipeline_library_off`, `agc_pipeline_library_fast_only`, `agc_descriptor_pool_reset_failure` and `agc_compute_descriptor_layout_flags` pass on both GPUs with `--repeat until-fail:3`. - `agc_driver_graphics` fails on both GPUs in every run with `shader library tests leaked Vulkan objects`. - It isn't a leak: `mock.live` ends at -4. - #4445 was merged after this branch's base 8fa5cc486. Since then, a prebuild hands its shader modules to the library and calls `vkDestroyShaderModule` on the moved-from `VK_NULL_HANDLE`, and `ClearPipelineLibraries` destroys the kept modules later. - `mockDestroyShaderModule` also counts the null destroy, so each kept module is counted down twice. In the first pass (mask 0), where the test stops, four modules are kept by the clear, which gives -4. A trace of the mock's handles shows the null destroys and the four destroys at the clear. - With `mockDestroyShaderModule` skipping it (`if (module != VK_NULL_HANDLE) --mock.live;`), `agc_driver_graphics` passes on both GPUs with `--repeat until-fail:3`. - With that mock change and `main`'s `Pipeline.cpp`, `PipelineLibrary.cpp` and `PipelineLibrary.hpp`, it fails on both GPUs with `shader library lost a used set or retained an unused set`. So the regression still catches the bug. - Full suite (`ctest --timeout 120 --parallel 4`): the only failures are `agc_driver_graphics` above and, on the iGPU, `agc_driver_f32_dot2_rounding`, which fails the same way on `main` (no `shaderFloat64`, #4528). Written with AI assistance.
oneandonlydean commented 2026-10-12 20:34:34 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-12T20:34:34Z.


The full build fails agc_driver_graphics on Linux and on Windows with this merged onto main: AGC graphics: shader library tests leaked Vulkan objects (https://github.com/boykopovar/AnyPS5/actions/runs/38276879354). kr4y4's run above explains it: since #4445 a prebuild destroys the moved-from VK_NULL_HANDLE module and mockDestroyShaderModule counts that too, so mock.live ends at -4. Please rebase over #4445 and make the mock skip the null handle; I'll rebuild after that.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132152754 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4456#issuecomment-6132152754). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-12T20:34:34Z. --- The full build fails `agc_driver_graphics` on Linux and on Windows with this merged onto main: `AGC graphics: shader library tests leaked Vulkan objects` (https://github.com/boykopovar/AnyPS5/actions/runs/38276879354). kr4y4's run above explains it: since #4445 a prebuild destroys the moved-from `VK_NULL_HANDLE` module and `mockDestroyShaderModule` counts that too, so `mock.live` ends at -4. Please rebase over #4445 and make the mock skip the null handle; I'll rebuild after that.
Mouhand-Kaddo commented 2026-10-12 21:25:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Mouhand-Kaddo on 2026-10-12T21:25:22Z.


@oneandonlydean Done. Rebased over #4445 and updated the mock to ignore VK_NULL_HANDLE, as requested.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6132894604 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4456#issuecomment-6132894604). Originally posted by [Mouhand-Kaddo](https://github.com/Mouhand-Kaddo) on 2026-10-12T21:25:22Z. --- @oneandonlydean Done. Rebased over #4445 and updated the mock to ignore `VK_NULL_HANDLE`, as requested.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4456
No description provided.