From 2c751d39f8f7b947ba30bd143f033dde7f6d5efe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Thu, 12 Oct 2023 09:01:34 +0200 Subject: [PATCH] Vulkan: Add simple delete count to GPU profiler, to make sure we don't have more resource churn Also fix the render pass type name lookup table. --- Common/GPU/Vulkan/VulkanContext.cpp | 21 +++++++++++++++++++++ Common/GPU/Vulkan/VulkanContext.h | 9 +++++++++ Common/GPU/Vulkan/VulkanQueueRunner.cpp | 8 -------- Common/GPU/Vulkan/VulkanRenderManager.cpp | 2 ++ 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/Common/GPU/Vulkan/VulkanContext.cpp b/Common/GPU/Vulkan/VulkanContext.cpp index b100e83a96..05607469c8 100644 --- a/Common/GPU/Vulkan/VulkanContext.cpp +++ b/Common/GPU/Vulkan/VulkanContext.cpp @@ -1666,80 +1666,101 @@ void VulkanDeleteList::Take(VulkanDeleteList &del) { } void VulkanDeleteList::PerformDeletes(VulkanContext *vulkan, VmaAllocator allocator) { + int deleteCount = 0; + for (auto &callback : callbacks_) { callback.func(vulkan, callback.userdata); + deleteCount++; } callbacks_.clear(); VkDevice device = vulkan->GetDevice(); for (auto &cmdPool : cmdPools_) { vkDestroyCommandPool(device, cmdPool, nullptr); + deleteCount++; } cmdPools_.clear(); for (auto &descPool : descPools_) { vkDestroyDescriptorPool(device, descPool, nullptr); + deleteCount++; } descPools_.clear(); for (auto &module : modules_) { vkDestroyShaderModule(device, module, nullptr); + deleteCount++; } modules_.clear(); for (auto &buf : buffers_) { vkDestroyBuffer(device, buf, nullptr); + deleteCount++; } buffers_.clear(); for (auto &buf : buffersWithAllocs_) { vmaDestroyBuffer(allocator, buf.buffer, buf.alloc); + deleteCount++; } buffersWithAllocs_.clear(); for (auto &bufView : bufferViews_) { vkDestroyBufferView(device, bufView, nullptr); + deleteCount++; } bufferViews_.clear(); for (auto &imageWithAlloc : imagesWithAllocs_) { vmaDestroyImage(allocator, imageWithAlloc.image, imageWithAlloc.alloc); + deleteCount++; } imagesWithAllocs_.clear(); for (auto &imageView : imageViews_) { vkDestroyImageView(device, imageView, nullptr); + deleteCount++; } imageViews_.clear(); for (auto &mem : deviceMemory_) { vkFreeMemory(device, mem, nullptr); + deleteCount++; } deviceMemory_.clear(); for (auto &sampler : samplers_) { vkDestroySampler(device, sampler, nullptr); + deleteCount++; } samplers_.clear(); for (auto &pipeline : pipelines_) { vkDestroyPipeline(device, pipeline, nullptr); + deleteCount++; } pipelines_.clear(); for (auto &pcache : pipelineCaches_) { vkDestroyPipelineCache(device, pcache, nullptr); + deleteCount++; } pipelineCaches_.clear(); for (auto &renderPass : renderPasses_) { vkDestroyRenderPass(device, renderPass, nullptr); + deleteCount++; } renderPasses_.clear(); for (auto &framebuffer : framebuffers_) { vkDestroyFramebuffer(device, framebuffer, nullptr); + deleteCount++; } framebuffers_.clear(); for (auto &pipeLayout : pipelineLayouts_) { vkDestroyPipelineLayout(device, pipeLayout, nullptr); + deleteCount++; } pipelineLayouts_.clear(); for (auto &descSetLayout : descSetLayouts_) { vkDestroyDescriptorSetLayout(device, descSetLayout, nullptr); + deleteCount++; } descSetLayouts_.clear(); for (auto &queryPool : queryPools_) { vkDestroyQueryPool(device, queryPool, nullptr); + deleteCount++; } queryPools_.clear(); + deleteCount_ = deleteCount; } void VulkanContext::GetImageMemoryRequirements(VkImage image, VkMemoryRequirements *mem_reqs, bool *dedicatedAllocation) { diff --git a/Common/GPU/Vulkan/VulkanContext.h b/Common/GPU/Vulkan/VulkanContext.h index 4dea4ed380..0d0e93417f 100644 --- a/Common/GPU/Vulkan/VulkanContext.h +++ b/Common/GPU/Vulkan/VulkanContext.h @@ -138,6 +138,10 @@ public: void Take(VulkanDeleteList &del); void PerformDeletes(VulkanContext *vulkan, VmaAllocator allocator); + int GetLastDeleteCount() const { + return deleteCount_; + } + private: std::vector cmdPools_; std::vector descPools_; @@ -157,6 +161,7 @@ private: std::vector descSetLayouts_; std::vector queryPools_; std::vector callbacks_; + int deleteCount_ = 0; }; // VulkanContext manages the device and swapchain, and deferred deletion of objects. @@ -392,6 +397,10 @@ public: return availablePresentModes_; } + int GetLastDeleteCount() const { + return frame_[curFrame_].deleteList.GetLastDeleteCount(); + } + private: bool ChooseQueue(); diff --git a/Common/GPU/Vulkan/VulkanQueueRunner.cpp b/Common/GPU/Vulkan/VulkanQueueRunner.cpp index b785d48f3a..556924bced 100644 --- a/Common/GPU/Vulkan/VulkanQueueRunner.cpp +++ b/Common/GPU/Vulkan/VulkanQueueRunner.cpp @@ -677,20 +677,12 @@ const char *AspectToString(VkImageAspectFlags aspect) { static const char *rpTypeDebugNames[] = { "RENDER", "RENDER_DEPTH", - "RENDER_INPUT", - "RENDER_DEPTH_INPUT", "MV_RENDER", "MV_RENDER_DEPTH", - "MV_RENDER_INPUT", - "MV_RENDER_DEPTH_INPUT", "MS_RENDER", "MS_RENDER_DEPTH", - "MS_RENDER_INPUT", - "MS_RENDER_DEPTH_INPUT", "MS_MV_RENDER", "MS_MV_RENDER_DEPTH", - "MS_MV_RENDER_INPUT", - "MS_MV_RENDER_DEPTH_INPUT", "BACKBUF", }; diff --git a/Common/GPU/Vulkan/VulkanRenderManager.cpp b/Common/GPU/Vulkan/VulkanRenderManager.cpp index 8b18b512c1..e5f3eeba2e 100644 --- a/Common/GPU/Vulkan/VulkanRenderManager.cpp +++ b/Common/GPU/Vulkan/VulkanRenderManager.cpp @@ -681,6 +681,8 @@ void VulkanRenderManager::BeginFrame(bool enableProfiling, bool enableLogProfile renderCPUTimeMs_.Update((frameData.profile.cpuEndTime - frameData.profile.cpuStartTime) * 1000.0); renderCPUTimeMs_.Format(line, sizeof(line)); str << line; + snprintf(line, sizeof(line), "Resource deletions: %d\n", vulkan_->GetLastDeleteCount()); + str << line; for (int i = 0; i < numQueries - 1; i++) { uint64_t diff = (queryResults[i + 1] - queryResults[i]) & timestampDiffMask; double milliseconds = (double)diff * timestampConversionFactor;