Skip to content

Commit

Permalink
Vulkan: Cleanup backbuffer descriptor sets and pool
Browse files Browse the repository at this point in the history
  • Loading branch information
goeiecool9999 committed Nov 4, 2024
1 parent d4c4c32 commit 44a3c00
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Cafe/HW/Latte/Renderer/Vulkan/VulkanAPI.h
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ VKFUNC_DEVICE(vkAllocateDescriptorSets);
VKFUNC_DEVICE(vkFreeDescriptorSets);
VKFUNC_DEVICE(vkUpdateDescriptorSets);
VKFUNC_DEVICE(vkCreateDescriptorPool);
VKFUNC_DEVICE(vkDestroyDescriptorPool);
VKFUNC_DEVICE(vkDestroyDescriptorSetLayout);

#undef VKFUNC_INIT
Expand Down
18 changes: 14 additions & 4 deletions src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,17 @@ VulkanRenderer::~VulkanRenderer()

vkDestroyPipelineCache(m_logicalDevice, m_pipeline_cache, nullptr);

if(!m_backbufferBlitDescriptorSetCache.empty())
{
std::vector<VkDescriptorSet> freeVector;
freeVector.reserve(m_backbufferBlitDescriptorSetCache.size());
std::transform(m_backbufferBlitDescriptorSetCache.begin(), m_backbufferBlitDescriptorSetCache.end(), std::back_inserter(freeVector), [](auto& i) {
return i.second;
});
vkFreeDescriptorSets(m_logicalDevice, m_descriptorPool, freeVector.size(), freeVector.data());
}

vkDestroyDescriptorPool(m_logicalDevice, m_descriptorPool, nullptr);

for(auto& i : m_backbufferBlitPipelineCache)
{
Expand Down Expand Up @@ -3019,9 +3030,8 @@ VkDescriptorSet VulkanRenderer::backbufferBlit_createDescriptorSet(VkDescriptorS
hash += (uint64)texViewVk->GetViewRGBA();
hash += (uint64)texViewVk->GetDefaultTextureSampler(useLinearTexFilter);

static std::unordered_map<uint64, VkDescriptorSet> s_set_cache;
const auto it = s_set_cache.find(hash);
if (it != s_set_cache.cend())
const auto it = m_backbufferBlitDescriptorSetCache.find(hash);
if (it != m_backbufferBlitDescriptorSetCache.cend())
return it->second;

VkDescriptorSetAllocateInfo allocInfo = {};
Expand Down Expand Up @@ -3052,7 +3062,7 @@ VkDescriptorSet VulkanRenderer::backbufferBlit_createDescriptorSet(VkDescriptorS
vkUpdateDescriptorSets(m_logicalDevice, 1, &descriptorWrites, 0, nullptr);
performanceMonitor.vk.numDescriptorSamplerTextures.increment();

s_set_cache[hash] = result;
m_backbufferBlitDescriptorSetCache[hash] = result;
return result;
}

Expand Down
1 change: 1 addition & 0 deletions src/Cafe/HW/Latte/Renderer/Vulkan/VulkanRenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,7 @@ class VulkanRenderer : public Renderer
std::thread m_pipeline_cache_save_thread;
VkPipelineCache m_pipeline_cache{ nullptr };
std::unordered_map<uint64, VkPipeline> m_backbufferBlitPipelineCache;
std::unordered_map<uint64, VkDescriptorSet> m_backbufferBlitDescriptorSetCache;
VkPipelineLayout m_pipelineLayout{nullptr};
VkCommandPool m_commandPool{ nullptr };

Expand Down

0 comments on commit 44a3c00

Please sign in to comment.