From aa1679f2c7428720d6ded0c69668311b552c60d4 Mon Sep 17 00:00:00 2001 From: Robin Kertels Date: Sat, 8 Oct 2022 00:01:42 +0200 Subject: [PATCH] VideoBackends:Vulkan: Clean up unused memory allocation code --- .../Vulkan/CommandBufferManager.cpp | 21 ---- .../Vulkan/CommandBufferManager.h | 3 - .../VideoBackends/Vulkan/VulkanContext.cpp | 103 ------------------ .../Core/VideoBackends/Vulkan/VulkanContext.h | 8 -- 4 files changed, 135 deletions(-) diff --git a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp index 42d03935b2..46712693a5 100644 --- a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp +++ b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.cpp @@ -525,13 +525,6 @@ void CommandBufferManager::BeginCommandBuffer() m_current_cmd_buffer = next_buffer_index; } -void CommandBufferManager::DeferBufferDestruction(VkBuffer object) -{ - CmdBufferResources& cmd_buffer_resources = GetCurrentCmdBufferResources(); - cmd_buffer_resources.cleanup_resources.push_back( - [object]() { vkDestroyBuffer(g_vulkan_context->GetDevice(), object, nullptr); }); -} - void CommandBufferManager::DeferBufferViewDestruction(VkBufferView object) { CmdBufferResources& cmd_buffer_resources = GetCurrentCmdBufferResources(); @@ -539,13 +532,6 @@ void CommandBufferManager::DeferBufferViewDestruction(VkBufferView object) [object]() { vkDestroyBufferView(g_vulkan_context->GetDevice(), object, nullptr); }); } -void CommandBufferManager::DeferDeviceMemoryDestruction(VkDeviceMemory object) -{ - CmdBufferResources& cmd_buffer_resources = GetCurrentCmdBufferResources(); - cmd_buffer_resources.cleanup_resources.push_back( - [object]() { vkFreeMemory(g_vulkan_context->GetDevice(), object, nullptr); }); -} - void CommandBufferManager::DeferBufferDestruction(VkBuffer buffer, VmaAllocation alloc) { CmdBufferResources& cmd_buffer_resources = GetCurrentCmdBufferResources(); @@ -561,13 +547,6 @@ void CommandBufferManager::DeferFramebufferDestruction(VkFramebuffer object) [object]() { vkDestroyFramebuffer(g_vulkan_context->GetDevice(), object, nullptr); }); } -void CommandBufferManager::DeferImageDestruction(VkImage object) -{ - CmdBufferResources& cmd_buffer_resources = GetCurrentCmdBufferResources(); - cmd_buffer_resources.cleanup_resources.push_back( - [object]() { vkDestroyImage(g_vulkan_context->GetDevice(), object, nullptr); }); -} - void CommandBufferManager::DeferImageDestruction(VkImage image, VmaAllocation alloc) { CmdBufferResources& cmd_buffer_resources = GetCurrentCmdBufferResources(); diff --git a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h index 5a4e5ff1bc..109079e698 100644 --- a/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h +++ b/Source/Core/VideoBackends/Vulkan/CommandBufferManager.h @@ -86,12 +86,9 @@ public: // Schedule a vulkan resource for destruction later on. This will occur when the command buffer // is next re-used, and the GPU has finished working with the specified resource. - void DeferBufferDestruction(VkBuffer object); void DeferBufferViewDestruction(VkBufferView object); - void DeferDeviceMemoryDestruction(VkDeviceMemory object); void DeferBufferDestruction(VkBuffer buffer, VmaAllocation alloc); void DeferFramebufferDestruction(VkFramebuffer object); - void DeferImageDestruction(VkImage object); void DeferImageDestruction(VkImage object, VmaAllocation alloc); void DeferImageViewDestruction(VkImageView object); diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp index 6df7ed3414..4d6b5c8903 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp +++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.cpp @@ -792,109 +792,6 @@ void VulkanContext::DisableDebugReports() } } -std::optional VulkanContext::GetMemoryType(u32 bits, VkMemoryPropertyFlags properties, - bool strict, bool* is_coherent) -{ - static constexpr u32 ALL_MEMORY_PROPERTY_FLAGS = VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT | - VK_MEMORY_PROPERTY_HOST_CACHED_BIT; - - const u32 mask = strict ? ALL_MEMORY_PROPERTY_FLAGS : properties; - - for (u32 i = 0; i < VK_MAX_MEMORY_TYPES; i++) - { - if ((bits & (1 << i)) != 0) - { - const VkMemoryPropertyFlags type_flags = - m_device_memory_properties.memoryTypes[i].propertyFlags; - const VkMemoryPropertyFlags supported = type_flags & mask; - if (supported == properties) - { - if (is_coherent) - *is_coherent = (type_flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) != 0; - return i; - } - } - } - - return std::nullopt; -} - -u32 VulkanContext::GetUploadMemoryType(u32 bits, bool* is_coherent) -{ - static constexpr VkMemoryPropertyFlags COHERENT_FLAGS = - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; - - // Try for coherent memory. Some drivers (looking at you, Adreno) have the cached type before the - // uncached type, so use a strict check first. - std::optional type_index = GetMemoryType(bits, COHERENT_FLAGS, true, is_coherent); - if (type_index) - return type_index.value(); - - // Try for coherent memory, with any other bits set. - type_index = GetMemoryType(bits, COHERENT_FLAGS, false, is_coherent); - if (type_index) - { - WARN_LOG_FMT(VIDEO, - "Strict check for upload memory properties failed, this may affect performance"); - return type_index.value(); - } - - // Fall back to non-coherent memory. - WARN_LOG_FMT( - VIDEO, - "Vulkan: Failed to find a coherent memory type for uploads, this will affect performance."); - type_index = GetMemoryType(bits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, false, is_coherent); - if (type_index) - return type_index.value(); - - // Shouldn't happen, there should be at least one host-visible heap. - PanicAlertFmt("Unable to get memory type for upload."); - return 0; -} - -u32 VulkanContext::GetReadbackMemoryType(u32 bits, bool* is_coherent) -{ - std::optional type_index; - - // Mali driver appears to be significantly slower for readbacks when using cached memory. - if (DriverDetails::HasBug(DriverDetails::BUG_SLOW_CACHED_READBACK_MEMORY)) - { - type_index = GetMemoryType( - bits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, true, - is_coherent); - if (type_index) - return type_index.value(); - } - - // Optimal config uses cached+coherent. - type_index = - GetMemoryType(bits, - VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT | - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT, - true, is_coherent); - if (type_index) - return type_index.value(); - - // Otherwise, prefer cached over coherent if we must choose one. - type_index = - GetMemoryType(bits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_CACHED_BIT, - false, is_coherent); - if (type_index) - return type_index.value(); - - WARN_LOG_FMT(VIDEO, "Vulkan: Failed to find a cached memory type for readbacks, this will affect " - "performance."); - type_index = GetMemoryType(bits, VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT, false, is_coherent); - *is_coherent = false; - if (type_index) - return type_index.value(); - - // We should have at least one host visible memory type... - PanicAlertFmt("Unable to get memory type for upload."); - return 0; -} - bool VulkanContext::SupportsDeviceExtension(const char* name) const { return std::any_of(m_device_extensions.begin(), m_device_extensions.end(), diff --git a/Source/Core/VideoBackends/Vulkan/VulkanContext.h b/Source/Core/VideoBackends/Vulkan/VulkanContext.h index 522ce69d13..6ba48a34f6 100644 --- a/Source/Core/VideoBackends/Vulkan/VulkanContext.h +++ b/Source/Core/VideoBackends/Vulkan/VulkanContext.h @@ -98,14 +98,6 @@ public: return m_device_properties.limits.bufferImageGranularity; } float GetMaxSamplerAnisotropy() const { return m_device_properties.limits.maxSamplerAnisotropy; } - // Finds a memory type index for the specified memory properties and the bits returned by - // vkGetImageMemoryRequirements - std::optional GetMemoryType(u32 bits, VkMemoryPropertyFlags properties, bool strict, - bool* is_coherent = nullptr); - - // Finds a memory type for upload or readback buffers. - u32 GetUploadMemoryType(u32 bits, bool* is_coherent = nullptr); - u32 GetReadbackMemoryType(u32 bits, bool* is_coherent = nullptr); // Returns true if the specified extension is supported and enabled. bool SupportsDeviceExtension(const char* name) const;