Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ class DescriptorCache {
std::vector<Pool> pools;
std::vector<Pool> updateAfterBindPools;
std::vector<VkDescriptorPool> dedicated;
std::unordered_map<VkDescriptorSetLayout, std::vector<SetAllocation>> recycled;
std::map<std::pair<VkDescriptorSetLayout, std::uint32_t>, std::vector<SetAllocation>> recycled;
std::vector<SetAllocation> kept;
Stats stats;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3856,7 +3856,7 @@ DescriptorCache::SetAllocation DescriptorCache::Allocate(VkDescriptorSetLayout l
if (result == VK_SUCCESS) {
++stats.sets;
++pool.liveSets;
return {set, pool.handle, index - 1, updateAfterBind};
return {set, pool.handle, index - 1, updateAfterBind, VK_NULL_HANDLE, {}, variableCount, {}};
}
if (result != VK_ERROR_OUT_OF_POOL_MEMORY && result != VK_ERROR_FRAGMENTED_POOL) Check(result, "vkAllocateDescriptorSets");
pool.exhausted = true;
Expand All @@ -3877,13 +3877,13 @@ DescriptorCache::SetAllocation DescriptorCache::Allocate(VkDescriptorSetLayout l
Check(allocate(context.device, &allocation, &set), "vkAllocateDescriptorSets");
chain.back().liveSets = 1;
++stats.sets;
return {set, pool, chain.size() - 1, updateAfterBind};
return {set, pool, chain.size() - 1, updateAfterBind, VK_NULL_HANDLE, {}, variableCount, {}};
}

DescriptorCache::SetAllocation DescriptorCache::AllocateRewritten(VkDescriptorSetLayout layout, std::span<const VkDescriptorPoolSize> sizes, bool updateAfterBind, std::optional<std::uint32_t> variableCount) {
{
std::lock_guard lock(mutex);
if (const auto found = recycled.find(layout); found != recycled.end() && !found->second.empty()) {
if (const auto found = recycled.find({layout, variableCount.value_or(0u)}); found != recycled.end() && !found->second.empty()) {
const auto allocation = found->second.back();
found->second.pop_back();
return allocation;
Expand All @@ -3897,7 +3897,7 @@ void DescriptorCache::Recycle(VkDescriptorSetLayout layout, const SetAllocation&
{
std::lock_guard lock(mutex);
try {
auto& list = recycled[layout];
auto& list = recycled[{layout, allocation.variableCount.value_or(0u)}];
if (list.size() < 4096) {
list.push_back(allocation);
return;
Expand Down
9 changes: 9 additions & 0 deletions core/libs/prx/libSceAgcDriver/tests/Graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5591,6 +5591,15 @@ void descriptorCacheTests() {
const auto reused = cache.Allocate(fittingLayout, fitting, true, 0u);
Require(reused.pool == chained.pool && mock.variableDescriptorCount == 0u, "reusing an update-after-bind pool lost an empty variable image table");
cache.Free(reused);
const auto rewritten = cache.AllocateRewritten(fittingLayout, fitting, true, 3u);
cache.Recycle(fittingLayout, rewritten);
const std::array<VkDescriptorPoolSize, 2> grown{{{VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, 17}, {VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, 5}}};
const auto larger = cache.AllocateRewritten(fittingLayout, grown, true, 5u);
Require(larger.set != rewritten.set && mock.variableDescriptorCount == 5u, "a recycled descriptor set served a larger variable image table than it was allocated for");
const auto same = cache.AllocateRewritten(fittingLayout, fitting, true, 3u);
Require(same.set == rewritten.set, "a recycled descriptor set was not reused for a variable image table of its own size");
cache.Free(larger);
cache.Free(same);
expectFailure([&] { cache.Allocate(fittingLayout, fitting, false, 3u); }, "descriptor set exceeds the device's per-set descriptor limit");
}
Require(mock.live == 0, "the combined descriptor cache leaked a pool or layout");
Expand Down
Loading