From 42d58bd77c241b52c4ba0e3b6e5d130f2a51c79f Mon Sep 17 00:00:00 2001 From: Lynix Date: Wed, 18 Mar 2020 13:58:30 +0100 Subject: [PATCH] Vulkan: Add physical device extension listing --- .../VulkanRenderer/Wrapper/Instance.hpp | 1 + .../Wrapper/InstanceFunctions.hpp | 1 + .../VulkanRenderer/Wrapper/PhysicalDevice.hpp | 1 + src/Nazara/VulkanRenderer/Vulkan.cpp | 9 ++++++ .../VulkanRenderer/Wrapper/Instance.cpp | 30 ++++++++++++++++++- 5 files changed, 41 insertions(+), 1 deletion(-) diff --git a/include/Nazara/VulkanRenderer/Wrapper/Instance.hpp b/include/Nazara/VulkanRenderer/Wrapper/Instance.hpp index 5ce955bca..5ec96ec0d 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/Instance.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/Instance.hpp @@ -34,6 +34,7 @@ namespace Nz inline PFN_vkVoidFunction GetDeviceProcAddr(VkDevice device, const char* name); + bool GetPhysicalDeviceExtensions(VkPhysicalDevice device, std::vector* extensionProperties); inline VkPhysicalDeviceFeatures GetPhysicalDeviceFeatures(VkPhysicalDevice device); inline VkFormatProperties GetPhysicalDeviceFormatProperties(VkPhysicalDevice device, VkFormat format); inline bool GetPhysicalDeviceImageFormatProperties(VkPhysicalDevice physicalDevice, VkFormat format, VkImageType type, VkImageTiling tiling, VkImageUsageFlags usage, VkImageCreateFlags flags, VkImageFormatProperties* imageFormatProperties); diff --git a/include/Nazara/VulkanRenderer/Wrapper/InstanceFunctions.hpp b/include/Nazara/VulkanRenderer/Wrapper/InstanceFunctions.hpp index 4f37b2767..a08459ba5 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/InstanceFunctions.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/InstanceFunctions.hpp @@ -5,6 +5,7 @@ // Vulkan core NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkCreateDevice) NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkDestroyInstance) +NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkEnumerateDeviceExtensionProperties) NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkEnumeratePhysicalDevices) NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetDeviceProcAddr) NAZARA_VULKANRENDERER_INSTANCE_FUNCTION(vkGetPhysicalDeviceFeatures) diff --git a/include/Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp b/include/Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp index 3e58e1f16..0e95917c2 100644 --- a/include/Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp +++ b/include/Nazara/VulkanRenderer/Wrapper/PhysicalDevice.hpp @@ -21,6 +21,7 @@ namespace Nz VkPhysicalDeviceFeatures features; VkPhysicalDeviceMemoryProperties memoryProperties; VkPhysicalDeviceProperties properties; + std::unordered_set extensions; std::vector queueFamilies; }; } diff --git a/src/Nazara/VulkanRenderer/Vulkan.cpp b/src/Nazara/VulkanRenderer/Vulkan.cpp index d0d6b9da6..a3bab8bbf 100644 --- a/src/Nazara/VulkanRenderer/Vulkan.cpp +++ b/src/Nazara/VulkanRenderer/Vulkan.cpp @@ -202,6 +202,15 @@ namespace Nz deviceInfo.memoryProperties = s_instance.GetPhysicalDeviceMemoryProperties(physDevice); deviceInfo.properties = s_instance.GetPhysicalDeviceProperties(physDevice); + std::vector extensions; + if (s_instance.GetPhysicalDeviceExtensions(physDevice, &extensions)) + { + for (auto& extProperty : extensions) + deviceInfo.extensions.emplace(extProperty.extensionName); + } + else + NazaraWarning("Failed to query physical device extensions for " + String(deviceInfo.properties.deviceName) + " (0x" + String::Number(deviceInfo.properties.deviceID, 16) + ')'); + s_physDevices.emplace_back(std::move(deviceInfo)); } diff --git a/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp b/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp index e7b0330d7..e70f2ef9d 100644 --- a/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp +++ b/src/Nazara/VulkanRenderer/Wrapper/Instance.cpp @@ -83,9 +83,37 @@ namespace Nz return true; } + bool Instance::GetPhysicalDeviceExtensions(VkPhysicalDevice device, std::vector* extensionProperties) + { + NazaraAssert(extensionProperties, "Invalid extension properties vector"); + + // First, query physical device count + UInt32 extensionPropertyCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t + m_lastErrorCode = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionPropertyCount, nullptr); + if (m_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to query extension properties count: " + TranslateVulkanError(m_lastErrorCode)); + return false; + } + + if (extensionPropertyCount == 0) + return true; //< No extension available + + // Now we can get the list of the available physical device + extensionProperties->resize(extensionPropertyCount); + m_lastErrorCode = vkEnumerateDeviceExtensionProperties(device, nullptr, &extensionPropertyCount, extensionProperties->data()); + if (m_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to query extension properties count: " + TranslateVulkanError(m_lastErrorCode)); + return false; + } + + return true; + } + bool Instance::GetPhysicalDeviceQueueFamilyProperties(VkPhysicalDevice device, std::vector* queueFamilyProperties) { - NazaraAssert(queueFamilyProperties, "Invalid device vector"); + NazaraAssert(queueFamilyProperties, "Invalid family properties vector"); // First, query physical device count UInt32 queueFamiliesCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t