From da401af52c2c82a5f0f85bad486f868f8807e745 Mon Sep 17 00:00:00 2001 From: Lynix Date: Sun, 24 Apr 2016 04:37:31 +0200 Subject: [PATCH] Vulkan/VkLoader: Add EnumerateInstance[Extension|Layer]Properties helper Former-commit-id: a7cfc73816266cef944f7cb3c668be0b86bbfcbf --- include/Nazara/Vulkan/VkLoader.hpp | 4 +++ src/Nazara/Vulkan/VkLoader.cpp | 53 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/include/Nazara/Vulkan/VkLoader.hpp b/include/Nazara/Vulkan/VkLoader.hpp index c700451c5..f12429b28 100644 --- a/include/Nazara/Vulkan/VkLoader.hpp +++ b/include/Nazara/Vulkan/VkLoader.hpp @@ -22,6 +22,9 @@ namespace Nz Loader() = delete; ~Loader() = delete; + static bool EnumerateInstanceExtensionProperties(std::vector* properties, const char* layerName = nullptr); + static bool EnumerateInstanceLayerProperties(std::vector* properties); + static inline PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name); static bool Initialize(); @@ -39,6 +42,7 @@ namespace Nz private: static DynLib s_vulkanLib; + static VkResult s_lastErrorCode; }; } } diff --git a/src/Nazara/Vulkan/VkLoader.cpp b/src/Nazara/Vulkan/VkLoader.cpp index c4a6f08b5..c9d2a360d 100644 --- a/src/Nazara/Vulkan/VkLoader.cpp +++ b/src/Nazara/Vulkan/VkLoader.cpp @@ -9,6 +9,56 @@ namespace Nz { namespace Vk { + bool Loader::EnumerateInstanceExtensionProperties(std::vector* properties, const char* layerName) + { + NazaraAssert(properties, "Invalid device vector"); + + // First, query physical device count + UInt32 propertyCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t + s_lastErrorCode = vkEnumerateInstanceExtensionProperties(layerName, &propertyCount, properties->data()); + if (s_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to get instance extension properties count"); + return false; + } + + // Now we can get the list of the available physical device + properties->resize(propertyCount); + s_lastErrorCode = vkEnumerateInstanceExtensionProperties(layerName, &propertyCount, properties->data()); + if (s_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to enumerate instance extension properties"); + return false; + } + + return true; + } + + bool Loader::EnumerateInstanceLayerProperties(std::vector* properties) + { + NazaraAssert(properties, "Invalid device vector"); + + // First, query physical device count + UInt32 propertyCount = 0; // Remember, Nz::UInt32 is a typedef on uint32_t + s_lastErrorCode = vkEnumerateInstanceLayerProperties(&propertyCount, properties->data()); + if (s_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to get instance layer properties count"); + return false; + } + + // Now we can get the list of the available physical device + properties->resize(propertyCount); + s_lastErrorCode = vkEnumerateInstanceLayerProperties(&propertyCount, properties->data()); + if (s_lastErrorCode != VkResult::VK_SUCCESS) + { + NazaraError("Failed to enumerate instance layer properties"); + return false; + } + + return true; + } + bool Loader::Initialize() { #ifdef NAZARA_PLATFORM_WINDOWS @@ -42,6 +92,8 @@ namespace Nz #undef NAZARA_VULKAN_LOAD_GLOBAL + s_lastErrorCode = VkResult::VK_SUCCESS; + return true; } @@ -55,6 +107,7 @@ namespace Nz #undef NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL DynLib Loader::s_vulkanLib; + VkResult Loader::s_lastErrorCode; void Loader::Uninitialize() {