Vulkan/VkLoader: Add EnumerateInstance[Extension|Layer]Properties helper

Former-commit-id: a7cfc73816266cef944f7cb3c668be0b86bbfcbf
This commit is contained in:
Lynix 2016-04-24 04:37:31 +02:00
parent 22a31c72ed
commit da401af52c
2 changed files with 57 additions and 0 deletions

View File

@ -22,6 +22,9 @@ namespace Nz
Loader() = delete; Loader() = delete;
~Loader() = delete; ~Loader() = delete;
static bool EnumerateInstanceExtensionProperties(std::vector<VkExtensionProperties>* properties, const char* layerName = nullptr);
static bool EnumerateInstanceLayerProperties(std::vector<VkLayerProperties>* properties);
static inline PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name); static inline PFN_vkVoidFunction GetInstanceProcAddr(VkInstance instance, const char* name);
static bool Initialize(); static bool Initialize();
@ -39,6 +42,7 @@ namespace Nz
private: private:
static DynLib s_vulkanLib; static DynLib s_vulkanLib;
static VkResult s_lastErrorCode;
}; };
} }
} }

View File

@ -9,6 +9,56 @@ namespace Nz
{ {
namespace Vk namespace Vk
{ {
bool Loader::EnumerateInstanceExtensionProperties(std::vector<VkExtensionProperties>* 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<VkLayerProperties>* 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() bool Loader::Initialize()
{ {
#ifdef NAZARA_PLATFORM_WINDOWS #ifdef NAZARA_PLATFORM_WINDOWS
@ -42,6 +92,8 @@ namespace Nz
#undef NAZARA_VULKAN_LOAD_GLOBAL #undef NAZARA_VULKAN_LOAD_GLOBAL
s_lastErrorCode = VkResult::VK_SUCCESS;
return true; return true;
} }
@ -55,6 +107,7 @@ namespace Nz
#undef NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL #undef NAZARA_VULKAN_GLOBAL_FUNCTION_IMPL
DynLib Loader::s_vulkanLib; DynLib Loader::s_vulkanLib;
VkResult Loader::s_lastErrorCode;
void Loader::Uninitialize() void Loader::Uninitialize()
{ {