From 1c9bf262e6c40a1747558abea31b2fdd786d6eb7 Mon Sep 17 00:00:00 2001 From: Magnus Norddahl Date: Mon, 25 Mar 2019 21:30:03 +0100 Subject: [PATCH] - hook up VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT --- src/rendering/vulkan/system/vk_device.cpp | 9 ++++++++- src/rendering/vulkan/system/vk_device.h | 6 ++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/rendering/vulkan/system/vk_device.cpp b/src/rendering/vulkan/system/vk_device.cpp index ede17b59b..cc4676ba6 100644 --- a/src/rendering/vulkan/system/vk_device.cpp +++ b/src/rendering/vulkan/system/vk_device.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "vk_device.h" #include "vk_swapchain.h" @@ -215,10 +216,16 @@ void VulkanDevice::SelectPhysicalDevice() transferFamily = SupportedDevices[selected].transferFamily; } +bool VulkanDevice::SupportsDeviceExtension(const char *ext) const +{ + return std::find(EnabledDeviceExtensions.begin(), EnabledDeviceExtensions.end(), ext) != EnabledDeviceExtensions.end(); +} + void VulkanDevice::CreateAllocator() { VmaAllocatorCreateInfo allocinfo = {}; - // allocinfo.flags = VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT; // To do: enable this for better performance + if (SupportsDeviceExtension(VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME) && SupportsDeviceExtension(VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME)) + allocinfo.flags = VMA_ALLOCATOR_CREATE_KHR_DEDICATED_ALLOCATION_BIT; allocinfo.physicalDevice = PhysicalDevice.Device; allocinfo.device = device; allocinfo.preferredLargeHeapBlockSize = 64 * 1024 * 1024; diff --git a/src/rendering/vulkan/system/vk_device.h b/src/rendering/vulkan/system/vk_device.h index 9ad9ba40d..231f1692e 100644 --- a/src/rendering/vulkan/system/vk_device.h +++ b/src/rendering/vulkan/system/vk_device.h @@ -62,7 +62,7 @@ public: // Device setup VkPhysicalDeviceFeatures UsedDeviceFeatures = {}; std::vector EnabledDeviceExtensions = { VK_KHR_SWAPCHAIN_EXTENSION_NAME }; - std::vector OptionalDeviceExtensions = { VK_EXT_HDR_METADATA_EXTENSION_NAME }; + std::vector OptionalDeviceExtensions = { VK_EXT_HDR_METADATA_EXTENSION_NAME, VK_KHR_DEDICATED_ALLOCATION_EXTENSION_NAME, VK_KHR_GET_MEMORY_REQUIREMENTS_2_EXTENSION_NAME }; VulkanPhysicalDevice PhysicalDevice; bool DebugLayerActive = false; @@ -83,11 +83,13 @@ private: void CreateInstance(); void CreateSurface(); void SelectPhysicalDevice(); + void SelectFeatures(); void CreateDevice(); void CreateAllocator(); void ReleaseResources(); - void SelectFeatures(); + bool SupportsDeviceExtension(const char *ext) const; + static bool CheckRequiredFeatures(const VkPhysicalDeviceFeatures &f); VkDebugUtilsMessengerEXT debugMessenger = VK_NULL_HANDLE;