fix(agc): recycle detiler descriptor pools once their batches complete #6168

Merged
parl0v merged 3 commits from upstream-pr/6168 into main 2026-10-15 08:43:52 +00:00
parl0v commented 2026-10-15 00:10:45 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-15T00:10:45Z.


What

TextureDetiler::BeginBatch reset the texture, image and CMASK descriptor pools only when Recorder::Idle(). A title that keeps the recorder busy never reaches that point, so every 64 detiles added a new 64-set pool until vkAllocateDescriptorSets failed with -2 (VK_ERROR_OUT_OF_DEVICE_MEMORY). On PPSA25344 (Sword of the Sea) with #6060 the title holds near 9 FPS, the process climbs to about 31.6 GB private and stops with

[videoout] presentation failed: compute shader ...: AGC graphics: vkAllocateDescriptorSets texture detiler: Vulkan result -2

after 12 and 22 minutes in two runs.

Each pool now carries the serial of the newest recorder batch that used one of its sets (Recorder::OpenSerial()). When the current pool is full, the next pool whose serial is at or below Recorder::CompletedThrough() (the newest serial with no batch still in flight) is reset and reused; only when none is free is a new pool created. The idle reset in BeginBatch stays. The three pool sets share this ring (DescriptorRing).

Tested

Windows 10, PPSA25344 title screen, APS5_PROFILE_DRAW=1, RTX 3060, same relinked executable, 40 min each:

build 10 s windows frames stop private bytes
#6060 71 6,474 -2 at 12 min ~31.6 GB
#6060 130 12,025 -2 at 22 min —
#6060 + this PR 239 (full 40 min) 23,678 none 10.00 GB at 1 min, 10.36 at 12, 10.39 at 22, 10.42 at 29.5

The last twelve windows of the 40-min run average 9.99 FPS. An earlier 15-min run of the same build went from 9.92 to 10.45 GB with no stop.

With main's import path (#6060 built, APS5_NO_WATCHED_PRIVATE_IMPORTS=1) SotS's title runs at about 3 FPS (#5596), the recorder goes idle between frames and the pools are reset there, so a 40-min run doesn't stop (238 windows, 7,132 frames). The stop needs a title fast enough to keep batches in flight, which #6060 and #5851 both give it.

ctest -R '^agc_': 563 of 564 on RTX 4060; agc_shader_disk_cache fails the same way on main.

Checklist

  • Based on current main; no other open PR implements the same functions
  • 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 under Silent stubs in their library's technical debt file
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • Unblocks: PPSA25344 (Sword of the Sea): stops after 12–22 min of the title with #6060
  • GPUs tested: NVIDIA GeForce RTX 4060, driver 617.42, Windows 10 (AGC tests); NVIDIA GeForce RTX 3060, driver 617.42, Windows 10 (40-min title runs)
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4866256195 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6168). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-15T00:10:45Z. --- ### What `TextureDetiler::BeginBatch` reset the texture, image and CMASK descriptor pools only when `Recorder::Idle()`. A title that keeps the recorder busy never reaches that point, so every 64 detiles added a new 64-set pool until `vkAllocateDescriptorSets` failed with -2 (`VK_ERROR_OUT_OF_DEVICE_MEMORY`). On PPSA25344 (Sword of the Sea) with #6060 the title holds near 9 FPS, the process climbs to about 31.6 GB private and stops with ``` [videoout] presentation failed: compute shader ...: AGC graphics: vkAllocateDescriptorSets texture detiler: Vulkan result -2 ``` after 12 and 22 minutes in two runs. Each pool now carries the serial of the newest recorder batch that used one of its sets (`Recorder::OpenSerial()`). When the current pool is full, the next pool whose serial is at or below `Recorder::CompletedThrough()` (the newest serial with no batch still in flight) is reset and reused; only when none is free is a new pool created. The idle reset in `BeginBatch` stays. The three pool sets share this ring (`DescriptorRing`). ### Tested Windows 10, PPSA25344 title screen, `APS5_PROFILE_DRAW=1`, RTX 3060, same relinked executable, 40 min each: | build | 10 s windows | frames | stop | private bytes | |---|---|---|---|---| | #6060 | 71 | 6,474 | -2 at 12 min | ~31.6 GB | | #6060 | 130 | 12,025 | -2 at 22 min | — | | #6060 + this PR | 239 (full 40 min) | 23,678 | none | 10.00 GB at 1 min, 10.36 at 12, 10.39 at 22, 10.42 at 29.5 | The last twelve windows of the 40-min run average 9.99 FPS. An earlier 15-min run of the same build went from 9.92 to 10.45 GB with no stop. With `main`'s import path (#6060 built, `APS5_NO_WATCHED_PRIVATE_IMPORTS=1`) SotS's title runs at about 3 FPS (#5596), the recorder goes idle between frames and the pools are reset there, so a 40-min run doesn't stop (238 windows, 7,132 frames). The stop needs a title fast enough to keep batches in flight, which #6060 and #5851 both give it. `ctest -R '^agc_'`: 563 of 564 on RTX 4060; `agc_shader_disk_cache` fails the same way on `main`. ### Checklist - [x] Based on current `main`; no other open PR implements the same functions - [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 under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] Unblocks: PPSA25344 (Sword of the Sea): stops after 12–22 min of the title with #6060 - [x] GPUs tested: NVIDIA GeForce RTX 4060, driver 617.42, Windows 10 (AGC tests); NVIDIA GeForce RTX 3060, driver 617.42, Windows 10 (40-min title runs) - [x] AI-assisted: yes
MarcZX10 commented 2026-10-15 00:12:31 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-15T00:12:31Z.

Code review location: core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetilerDescriptors.cpp; line 37

@@ -1,55 +1,71 @@
 #include "prx/libSceAgcDriver/Graphics/include/Recorder.hpp"
 #include "prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp"
 #include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
+#include <algorithm>
 #include <array>
+#include <limits>
 
 namespace AgcDriver::Graphics {
 
 void TextureDetiler::BeginBatch() {
     GuestMemory::AssertGpuLockHeld("TextureDetiler::BeginBatch");
-    // Sets of recorded work that has not completed stay allocated; the pools are recycled once the
-    // recorder is idle again.
     if (const auto* recorder = Recorder::Active(); recorder != nullptr && !recorder->Idle()) return;
-    for (const auto pool : descriptorPools) {
-        Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool texture detiler");
-    }
-    allocatedSets = 0;
-    for (const auto pool : cmaskDescriptorPools) {
-        Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool CMASK clear");
-    }
-    allocatedCmaskSets = 0;
-    for (const auto pool : imageDescriptorPools) {
-        Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool texture detiler");
-    }
-    allocatedImageSets = 0;
+    resetRing(descriptorSets, "vkResetDescriptorPool texture detiler");
+    resetRing(cmaskDescriptorSets, "vkResetDescriptorPool CMASK clear");
+    resetRing(imageDescriptorSets, "vkResetDescriptorPool texture detiler");
 }
 
-VkDescriptorSet TextureDetiler::allocateSet(bool image) {
+void TextureDetiler::resetRing(DescriptorRing& ring, const char* resetWhat) {
+    for (const auto pool : ring.pools) Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), resetWhat);
+    std::fill(ring.serials.begin(), ring.serials.end(), std::uint64_t{0});
+    ring.current = 0;
+    ring.used = 0;
+}
+
+VkDescriptorSet TextureDetiler::allocateFrom(DescriptorRing& ring, VkDescriptorSetLayout layout, const std::vector<VkDescriptorPoolSize>& sizes, const char* createWhat, const char* allocateWhat, const char* resetWhat) {
     constexpr std::uint32_t setsPerPool = 64;
-    auto& pools = image ? imageDescriptorPools : descriptorPools;
-    auto& allocated = image ? allocatedImageSets : allocatedSets;
-    const auto poolIndex = allocated / setsPerPool;
-    if (poolIndex == pools.size()) {
-        std::array<VkDescriptorPoolSize, 2> sizes{};
-        sizes[0] = {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, image ? setsPerPool : setsPerPool * 2};
-        sizes[1] = {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, setsPerPool};
-        VkDescriptorPoolCreateInfo info{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
-        info.maxSets = setsPerPool;
-        info.poolSizeCount = image ? 2u : 1u;
-        info.pPoolSizes = sizes.data();
-        pools.reserve(pools.size() + 1);
-        VkDescriptorPool pool = VK_NULL_HANDLE;
-        Check(context.Function<PFN_vkCreateDescriptorPool>("vkCreateDescriptorPool")(context.device, &info, nullptr, &pool), "vkCreateDescriptorPool texture detiler");
-        pools.push_back(pool);
+    const auto* recorder = Recorder::Active();
+    if (ring.pools.empty() || ring.used == setsPerPool) {
+        const auto completed = recorder != nullptr ? recorder->CompletedThrough() : std::numeric_limits<std::uint64_t>::max();
+        auto next = ring.pools.size();
+        for (std::size_t step = 1; step < ring.pools.size(); ++step) {
+            const auto index = (ring.current + step) % ring.pools.size();
+            if (ring.serials[index] <= completed) {
+                next = index;
+                break;
+            }
+        }

When this pool reaches 64 sets, the search begins at (ring.current + 1) and iterates only step < ring.pools.size(), so it never considers the current pool. If the current pool’s last-use serial has completed (the common case when there is just one pool, or after older pools are busy), this allocates a new pool instead of resetting the completed one. Under a sustained workload this can still grow descriptor-pool memory without bound. Could the selection check ring.current too when its serial is <= completed? A regression test with one pool whose serial is completed at the next allocation would cover this.

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4277636033 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6168#discussion_r4277636033). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-15T00:12:31Z. **Code review location:** `core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetilerDescriptors.cpp`; line 37 ~~~~diff @@ -1,55 +1,71 @@ #include "prx/libSceAgcDriver/Graphics/include/Recorder.hpp" #include "prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp" #include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp" +#include <algorithm> #include <array> +#include <limits> namespace AgcDriver::Graphics { void TextureDetiler::BeginBatch() { GuestMemory::AssertGpuLockHeld("TextureDetiler::BeginBatch"); - // Sets of recorded work that has not completed stay allocated; the pools are recycled once the - // recorder is idle again. if (const auto* recorder = Recorder::Active(); recorder != nullptr && !recorder->Idle()) return; - for (const auto pool : descriptorPools) { - Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool texture detiler"); - } - allocatedSets = 0; - for (const auto pool : cmaskDescriptorPools) { - Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool CMASK clear"); - } - allocatedCmaskSets = 0; - for (const auto pool : imageDescriptorPools) { - Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool texture detiler"); - } - allocatedImageSets = 0; + resetRing(descriptorSets, "vkResetDescriptorPool texture detiler"); + resetRing(cmaskDescriptorSets, "vkResetDescriptorPool CMASK clear"); + resetRing(imageDescriptorSets, "vkResetDescriptorPool texture detiler"); } -VkDescriptorSet TextureDetiler::allocateSet(bool image) { +void TextureDetiler::resetRing(DescriptorRing& ring, const char* resetWhat) { + for (const auto pool : ring.pools) Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), resetWhat); + std::fill(ring.serials.begin(), ring.serials.end(), std::uint64_t{0}); + ring.current = 0; + ring.used = 0; +} + +VkDescriptorSet TextureDetiler::allocateFrom(DescriptorRing& ring, VkDescriptorSetLayout layout, const std::vector<VkDescriptorPoolSize>& sizes, const char* createWhat, const char* allocateWhat, const char* resetWhat) { constexpr std::uint32_t setsPerPool = 64; - auto& pools = image ? imageDescriptorPools : descriptorPools; - auto& allocated = image ? allocatedImageSets : allocatedSets; - const auto poolIndex = allocated / setsPerPool; - if (poolIndex == pools.size()) { - std::array<VkDescriptorPoolSize, 2> sizes{}; - sizes[0] = {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, image ? setsPerPool : setsPerPool * 2}; - sizes[1] = {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, setsPerPool}; - VkDescriptorPoolCreateInfo info{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; - info.maxSets = setsPerPool; - info.poolSizeCount = image ? 2u : 1u; - info.pPoolSizes = sizes.data(); - pools.reserve(pools.size() + 1); - VkDescriptorPool pool = VK_NULL_HANDLE; - Check(context.Function<PFN_vkCreateDescriptorPool>("vkCreateDescriptorPool")(context.device, &info, nullptr, &pool), "vkCreateDescriptorPool texture detiler"); - pools.push_back(pool); + const auto* recorder = Recorder::Active(); + if (ring.pools.empty() || ring.used == setsPerPool) { + const auto completed = recorder != nullptr ? recorder->CompletedThrough() : std::numeric_limits<std::uint64_t>::max(); + auto next = ring.pools.size(); + for (std::size_t step = 1; step < ring.pools.size(); ++step) { + const auto index = (ring.current + step) % ring.pools.size(); + if (ring.serials[index] <= completed) { + next = index; + break; + } + } ~~~~ --- When this pool reaches 64 sets, the search begins at `(ring.current + 1)` and iterates only `step < ring.pools.size()`, so it never considers the current pool. If the current pool’s last-use serial has completed (the common case when there is just one pool, or after older pools are busy), this allocates a new pool instead of resetting the completed one. Under a sustained workload this can still grow descriptor-pool memory without bound. Could the selection check `ring.current` too when its serial is `<= completed`? A regression test with one pool whose serial is completed at the next allocation would cover this.
parl0v commented 2026-10-15 00:17:33 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-15T00:17:33Z.

Code review location: core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetilerDescriptors.cpp; line 37

@@ -1,55 +1,71 @@
 #include "prx/libSceAgcDriver/Graphics/include/Recorder.hpp"
 #include "prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp"
 #include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp"
+#include <algorithm>
 #include <array>
+#include <limits>
 
 namespace AgcDriver::Graphics {
 
 void TextureDetiler::BeginBatch() {
     GuestMemory::AssertGpuLockHeld("TextureDetiler::BeginBatch");
-    // Sets of recorded work that has not completed stay allocated; the pools are recycled once the
-    // recorder is idle again.
     if (const auto* recorder = Recorder::Active(); recorder != nullptr && !recorder->Idle()) return;
-    for (const auto pool : descriptorPools) {
-        Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool texture detiler");
-    }
-    allocatedSets = 0;
-    for (const auto pool : cmaskDescriptorPools) {
-        Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool CMASK clear");
-    }
-    allocatedCmaskSets = 0;
-    for (const auto pool : imageDescriptorPools) {
-        Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool texture detiler");
-    }
-    allocatedImageSets = 0;
+    resetRing(descriptorSets, "vkResetDescriptorPool texture detiler");
+    resetRing(cmaskDescriptorSets, "vkResetDescriptorPool CMASK clear");
+    resetRing(imageDescriptorSets, "vkResetDescriptorPool texture detiler");
 }
 
-VkDescriptorSet TextureDetiler::allocateSet(bool image) {
+void TextureDetiler::resetRing(DescriptorRing& ring, const char* resetWhat) {
+    for (const auto pool : ring.pools) Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), resetWhat);
+    std::fill(ring.serials.begin(), ring.serials.end(), std::uint64_t{0});
+    ring.current = 0;
+    ring.used = 0;
+}
+
+VkDescriptorSet TextureDetiler::allocateFrom(DescriptorRing& ring, VkDescriptorSetLayout layout, const std::vector<VkDescriptorPoolSize>& sizes, const char* createWhat, const char* allocateWhat, const char* resetWhat) {
     constexpr std::uint32_t setsPerPool = 64;
-    auto& pools = image ? imageDescriptorPools : descriptorPools;
-    auto& allocated = image ? allocatedImageSets : allocatedSets;
-    const auto poolIndex = allocated / setsPerPool;
-    if (poolIndex == pools.size()) {
-        std::array<VkDescriptorPoolSize, 2> sizes{};
-        sizes[0] = {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, image ? setsPerPool : setsPerPool * 2};
-        sizes[1] = {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, setsPerPool};
-        VkDescriptorPoolCreateInfo info{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO};
-        info.maxSets = setsPerPool;
-        info.poolSizeCount = image ? 2u : 1u;
-        info.pPoolSizes = sizes.data();
-        pools.reserve(pools.size() + 1);
-        VkDescriptorPool pool = VK_NULL_HANDLE;
-        Check(context.Function<PFN_vkCreateDescriptorPool>("vkCreateDescriptorPool")(context.device, &info, nullptr, &pool), "vkCreateDescriptorPool texture detiler");
-        pools.push_back(pool);
+    const auto* recorder = Recorder::Active();
+    if (ring.pools.empty() || ring.used == setsPerPool) {
+        const auto completed = recorder != nullptr ? recorder->CompletedThrough() : std::numeric_limits<std::uint64_t>::max();
+        auto next = ring.pools.size();
+        for (std::size_t step = 1; step < ring.pools.size(); ++step) {
+            const auto index = (ring.current + step) % ring.pools.size();
+            if (ring.serials[index] <= completed) {
+                next = index;
+                break;
+            }
+        }

Thanks, you're right that it skipped the current pool. Fixed in 0e15b9be9: the search now runs step <= ring.pools.size(), so it ends at the current pool and resets it when its serial is completed. Before, this cost one pool more than needed rather than unbounded growth (the skipped pool was the first one checked at the next fill, and the 40-min SotS run held at 10.4 GB), but it was still a pool too many.

The test you suggested is in tests/TextureDetiler.cpp: three pools' worth of dispatches with no batch in flight, and the pool count has to stay the same. It fails on 8e56f5610 and passes now. ctest -R '^agc_' is 563/564 on the RTX 4060 (only agc_shader_disk_cache, as on main).

<!-- greyfinch-sync:boykopovar/AnyPS5:review-comment:4277666258 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6168#discussion_r4277666258). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-15T00:17:33Z. **Code review location:** `core/libs/prx/libSceAgcDriver/Graphics/src/TextureDetilerDescriptors.cpp`; line 37 ~~~~diff @@ -1,55 +1,71 @@ #include "prx/libSceAgcDriver/Graphics/include/Recorder.hpp" #include "prx/libSceAgcDriver/Graphics/include/TextureDetiler.hpp" #include "prx/libSceAgcDriver/Execution/include/GuestMemory.hpp" +#include <algorithm> #include <array> +#include <limits> namespace AgcDriver::Graphics { void TextureDetiler::BeginBatch() { GuestMemory::AssertGpuLockHeld("TextureDetiler::BeginBatch"); - // Sets of recorded work that has not completed stay allocated; the pools are recycled once the - // recorder is idle again. if (const auto* recorder = Recorder::Active(); recorder != nullptr && !recorder->Idle()) return; - for (const auto pool : descriptorPools) { - Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool texture detiler"); - } - allocatedSets = 0; - for (const auto pool : cmaskDescriptorPools) { - Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool CMASK clear"); - } - allocatedCmaskSets = 0; - for (const auto pool : imageDescriptorPools) { - Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), "vkResetDescriptorPool texture detiler"); - } - allocatedImageSets = 0; + resetRing(descriptorSets, "vkResetDescriptorPool texture detiler"); + resetRing(cmaskDescriptorSets, "vkResetDescriptorPool CMASK clear"); + resetRing(imageDescriptorSets, "vkResetDescriptorPool texture detiler"); } -VkDescriptorSet TextureDetiler::allocateSet(bool image) { +void TextureDetiler::resetRing(DescriptorRing& ring, const char* resetWhat) { + for (const auto pool : ring.pools) Check(context.Function<PFN_vkResetDescriptorPool>("vkResetDescriptorPool")(context.device, pool, 0), resetWhat); + std::fill(ring.serials.begin(), ring.serials.end(), std::uint64_t{0}); + ring.current = 0; + ring.used = 0; +} + +VkDescriptorSet TextureDetiler::allocateFrom(DescriptorRing& ring, VkDescriptorSetLayout layout, const std::vector<VkDescriptorPoolSize>& sizes, const char* createWhat, const char* allocateWhat, const char* resetWhat) { constexpr std::uint32_t setsPerPool = 64; - auto& pools = image ? imageDescriptorPools : descriptorPools; - auto& allocated = image ? allocatedImageSets : allocatedSets; - const auto poolIndex = allocated / setsPerPool; - if (poolIndex == pools.size()) { - std::array<VkDescriptorPoolSize, 2> sizes{}; - sizes[0] = {VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, image ? setsPerPool : setsPerPool * 2}; - sizes[1] = {VK_DESCRIPTOR_TYPE_STORAGE_IMAGE, setsPerPool}; - VkDescriptorPoolCreateInfo info{VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO}; - info.maxSets = setsPerPool; - info.poolSizeCount = image ? 2u : 1u; - info.pPoolSizes = sizes.data(); - pools.reserve(pools.size() + 1); - VkDescriptorPool pool = VK_NULL_HANDLE; - Check(context.Function<PFN_vkCreateDescriptorPool>("vkCreateDescriptorPool")(context.device, &info, nullptr, &pool), "vkCreateDescriptorPool texture detiler"); - pools.push_back(pool); + const auto* recorder = Recorder::Active(); + if (ring.pools.empty() || ring.used == setsPerPool) { + const auto completed = recorder != nullptr ? recorder->CompletedThrough() : std::numeric_limits<std::uint64_t>::max(); + auto next = ring.pools.size(); + for (std::size_t step = 1; step < ring.pools.size(); ++step) { + const auto index = (ring.current + step) % ring.pools.size(); + if (ring.serials[index] <= completed) { + next = index; + break; + } + } ~~~~ --- Thanks, you're right that it skipped the current pool. Fixed in 0e15b9be9: the search now runs `step <= ring.pools.size()`, so it ends at the current pool and resets it when its serial is completed. Before, this cost one pool more than needed rather than unbounded growth (the skipped pool was the first one checked at the next fill, and the 40-min SotS run held at 10.4 GB), but it was still a pool too many. The test you suggested is in `tests/TextureDetiler.cpp`: three pools' worth of dispatches with no batch in flight, and the pool count has to stay the same. It fails on 8e56f5610 and passes now. `ctest -R '^agc_'` is 563/564 on the RTX 4060 (only `agc_shader_disk_cache`, as on `main`).
parl0v commented 2026-10-15 00:25:18 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-15T00:25:18Z.


Same 40-min run with #5851 instead of #6060 (box 2, RTX 3060, SotS title, 8.45 FPS over its last twelve 10 s windows): it stops after 73 windows (about 12 min) with the same

[videoout] presentation failed: compute shader ...: AGC graphics: vkAllocateDescriptorSets texture detiler: Vulkan result -2

So the stop follows the frame rate, not either import change: both PRs that bring SotS back to ~9 FPS reach it, and main's import path at ~3 FPS doesn't.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6181490417 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6168#issuecomment-6181490417). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-15T00:25:18Z. --- Same 40-min run with #5851 instead of #6060 (box 2, RTX 3060, SotS title, 8.45 FPS over its last twelve 10 s windows): it stops after 73 windows (about 12 min) with the same ``` [videoout] presentation failed: compute shader ...: AGC graphics: vkAllocateDescriptorSets texture detiler: Vulkan result -2 ``` So the stop follows the frame rate, not either import change: both PRs that bring SotS back to ~9 FPS reach it, and `main`'s import path at ~3 FPS doesn't.
coltken95 commented 2026-10-15 00:41:22 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by coltken95 on 2026-10-15T00:41:22Z.


Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with 0e15b9be9 merged into main ab9a47684:

  • With the PR: all 8 tests built from the changed test files pass, including agc_driver_graphics.
  • With main's detiler sources (Recorder.hpp, TextureDetiler.hpp, TextureDetiler.cpp, TextureDetilerDescriptors.cpp): agc_driver_graphics fails with AGC graphics: a full descriptor pool whose batches completed must be reset and reused, not joined by a new pool; the other 7 pass.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6181694065 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6168#issuecomment-6181694065). Originally posted by [coltken95](https://github.com/coltken95) on 2026-10-15T00:41:22Z. --- Tested on Linux x86-64 (Release build, lavapipe / llvmpipe LLVM 20.1.2), with 0e15b9be9 merged into main ab9a47684: - With the PR: all 8 tests built from the changed test files pass, including `agc_driver_graphics`. - With main's detiler sources (`Recorder.hpp`, `TextureDetiler.hpp`, `TextureDetiler.cpp`, `TextureDetilerDescriptors.cpp`): `agc_driver_graphics` fails with `AGC graphics: a full descriptor pool whose batches completed must be reset and reused, not joined by a new pool`; the other 7 pass. AI-assisted: yes (Claude Code)
parl0v commented 2026-10-15 01:12:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-15T01:12:37Z.


@coltken95 thanks, good to have the test failing on main's detiler sources on a second OS.

A second 40-min SotS title run with this PR at 0e15b9be9 (on top of #6060): 23,605 frames, 9.96 FPS over the last twelve windows, no stop, private bytes 10.01 → 10.34 GB, +18 MB over the last 15 min.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6182079212 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6168#issuecomment-6182079212). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-15T01:12:37Z. --- @coltken95 thanks, good to have the test failing on `main`'s detiler sources on a second OS. A second 40-min SotS title run with this PR at 0e15b9be9 (on top of #6060): 23,605 frames, 9.96 FPS over the last twelve windows, no stop, private bytes 10.01 → 10.34 GB, +18 MB over the last 15 min.
fma-rc commented 2026-10-15 03:47:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by fma-rc on 2026-10-15T03:47:41Z.


A question on head 0e15b9be9, from reading the code. In allocateFrom (TextureDetilerDescriptors.cpp lines 27 to 39), when Recorder::Active() is null, completed is std::numeric_limits<std::uint64_t>::max() and every pool's serial is stored as 0 (line 62). So once the current pool holds 64 sets, the next pool in the ring is reset at once, and with a single pool that is the pool just filled. If any caller detiles without an active recorder and puts more than 64 sets into one command buffer before submitting it, the sets already bound there would be freed before it runs. If no such path exists, a throw there would make that explicit.

The runs here did not reach that case. Current main a077a88df with this PR merged: its 4 tests pass on an RTX 5080 (NVIDIA), the Ryzen 7800X3D's integrated Radeon (RADV) and lavapipe. Under VK_LAYER_KHRONOS_validation on NVIDIA and RADV they report the same messages as main's tests (pre-existing vkCmdPipelineBarrier access-mask ones) and nothing about descriptor sets. On a Radeon 680M the new test also fails on main's detiler sources.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6183942274 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6168#issuecomment-6183942274). Originally posted by [fma-rc](https://github.com/fma-rc) on 2026-10-15T03:47:41Z. --- A question on head 0e15b9be9, from reading the code. In `allocateFrom` (`TextureDetilerDescriptors.cpp` lines 27 to 39), when `Recorder::Active()` is null, `completed` is `std::numeric_limits<std::uint64_t>::max()` and every pool's serial is stored as 0 (line 62). So once the current pool holds 64 sets, the next pool in the ring is reset at once, and with a single pool that is the pool just filled. If any caller detiles without an active recorder and puts more than 64 sets into one command buffer before submitting it, the sets already bound there would be freed before it runs. If no such path exists, a throw there would make that explicit. The runs here did not reach that case. Current main a077a88df with this PR merged: its 4 tests pass on an RTX 5080 (NVIDIA), the Ryzen 7800X3D's integrated Radeon (RADV) and lavapipe. Under `VK_LAYER_KHRONOS_validation` on NVIDIA and RADV they report the same messages as main's tests (pre-existing `vkCmdPipelineBarrier` access-mask ones) and nothing about descriptor sets. On a Radeon 680M the new test also fails on main's detiler sources.
frankea commented 2026-10-15 04:04:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by frankea on 2026-10-15T04:04:01Z.


Windows run of 0e15b9be9 merged onto main a077a88df (clean); Windows 11 10.0.26200, Ryzen 7 5800X, RTX 4090 (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 r7, Release, default environment.

  • Full ctest: 1250 of 1252, 14 environment skips. The two failures are on main at this base and not from this PR: agc_driver_image_plane_address_on_line (fails on main e52e140f5, reported on #5583) and guest_kqueue (#5493's new DeniedParentWatch case under an elevated session, reported there). Both pass on main fa539dd9b.
  • No title here, so nothing on the 40-minute detiler run.

Tested with AI assistance (Claude Code).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6184129398 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6168#issuecomment-6184129398). Originally posted by [frankea](https://github.com/frankea) on 2026-10-15T04:04:01Z. --- Windows run of `0e15b9be9` merged onto `main` `a077a88df` (clean); Windows 11 10.0.26200, Ryzen 7 5800X, RTX 4090 (NVIDIA 616.92), MinGW-w64 GCC 15.2.0 r7, Release, default environment. - Full ctest: 1250 of 1252, 14 environment skips. The two failures are on `main` at this base and not from this PR: `agc_driver_image_plane_address_on_line` (fails on `main` `e52e140f5`, reported on #5583) and `guest_kqueue` (#5493's new `DeniedParentWatch` case under an elevated session, reported there). Both pass on `main` `fa539dd9b`. - No title here, so nothing on the 40-minute detiler run. Tested with AI assistance (Claude Code).
adriadam10 commented 2026-10-15 08:07:48 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T08:07:48Z.

Review: CHANGES_REQUESTED


Checked on the PR merged onto current main: build + ctest of libSceAgcDriver are green (agc_driver_tessellation segfaults on main as well), and agc_driver_graphics fails with the detiler sources reverted, so the new test does exercise the recycling.

One point to fix:

  • TextureDetilerDescriptors.cpp:29 and :62: with no active Recorder, completed is UINT64_MAX and every serial is stored as 0, so as soon as the current pool holds 64 sets the next ring slot is reset immediately, and with a single pool that is the pool just filled. Sets already recorded into the same command buffer would be freed before it runs; before this PR a new pool was created there (the reset only happened in BeginBatch). This is the case @fma-rc asked about above. Without a recorder there is no completion information, so the ring should not reuse a pool (create a new one, as before), or throw if that path cannot happen. Please add a test case for it (more than 64 Dispatch calls with no active recorder, asserting no pool is reset while its sets are bound).

The rest (serial taken from OpenSerial(), CompletedThrough() bound, the idle reset kept in BeginBatch) looks right to me.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5530008707 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6168#pullrequestreview-5530008707). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T08:07:48Z. **Review:** CHANGES_REQUESTED --- Checked on the PR merged onto current main: build + ctest of libSceAgcDriver are green (`agc_driver_tessellation` segfaults on main as well), and `agc_driver_graphics` fails with the detiler sources reverted, so the new test does exercise the recycling. One point to fix: - `TextureDetilerDescriptors.cpp:29` and `:62`: with no active `Recorder`, `completed` is `UINT64_MAX` and every serial is stored as 0, so as soon as the current pool holds 64 sets the next ring slot is reset immediately, and with a single pool that is the pool just filled. Sets already recorded into the same command buffer would be freed before it runs; before this PR a new pool was created there (the reset only happened in `BeginBatch`). This is the case @fma-rc asked about above. Without a recorder there is no completion information, so the ring should not reuse a pool (create a new one, as before), or throw if that path cannot happen. Please add a test case for it (more than 64 `Dispatch` calls with no active recorder, asserting no pool is reset while its sets are bound). The rest (serial taken from `OpenSerial()`, `CompletedThrough()` bound, the idle reset kept in `BeginBatch`) looks right to me.
adriadam10 commented 2026-10-15 08:15:12 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-15T08:15:12Z.

Review: APPROVED


Checked on the PR merged onto current main: build + ctest of libSceAgcDriver are green (agc_driver_tessellation segfaults on main as well).

Added one commit on your branch (fix(agc): keep detiler descriptor pools unrecycled without a recorder) for the case @fma-rc asked about: with no active Recorder, completed was UINT64_MAX and every serial 0, so a full pool reset the next ring slot at once (with one pool, the one just filled) while its sets could still be recorded in the same command buffer. Without a recorder there is no completion information, so completed is now 0 and those sets get serial UINT64_MAX: such pools are only reset by BeginBatch (as on main), and a full one is joined by a new pool.

The detiler test ran its 192 dispatches with no recorder, so it required exactly that reuse. It is now two cases: with no recorder, no pool is reset and new pools are created; with an active recorder, 4 batches of 64 dispatches with Sync() between them keep the pool count of the first batch. agc_driver_graphics passes, fails with your previous lines (a descriptor pool was reset with no recorder ...), and fails with a ring that never reuses (a full descriptor pool whose batches completed must be reset and reused ...).

The rest (serial taken from OpenSerial(), CompletedThrough() bound, the idle reset kept in BeginBatch) looks right to me. Merging once the full Build is green.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5530083976 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/6168#pullrequestreview-5530083976). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-15T08:15:12Z. **Review:** APPROVED --- Checked on the PR merged onto current main: build + ctest of libSceAgcDriver are green (`agc_driver_tessellation` segfaults on main as well). Added one commit on your branch (`fix(agc): keep detiler descriptor pools unrecycled without a recorder`) for the case @fma-rc asked about: with no active `Recorder`, `completed` was `UINT64_MAX` and every serial 0, so a full pool reset the next ring slot at once (with one pool, the one just filled) while its sets could still be recorded in the same command buffer. Without a recorder there is no completion information, so `completed` is now 0 and those sets get serial `UINT64_MAX`: such pools are only reset by `BeginBatch` (as on main), and a full one is joined by a new pool. The detiler test ran its 192 dispatches with no recorder, so it required exactly that reuse. It is now two cases: with no recorder, no pool is reset and new pools are created; with an active recorder, 4 batches of 64 dispatches with `Sync()` between them keep the pool count of the first batch. `agc_driver_graphics` passes, fails with your previous lines (`a descriptor pool was reset with no recorder ...`), and fails with a ring that never reuses (`a full descriptor pool whose batches completed must be reset and reused ...`). The rest (serial taken from `OpenSerial()`, `CompletedThrough()` bound, the idle reset kept in `BeginBatch`) looks right to me. Merging once the full Build is green.
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!6168
No description provided.