From 25700b452535ce7ae838bfe832392b46ed555ed2 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 28 Apr 2016 06:36:09 +0800 Subject: vulkan: refactor layer enumeration Replace Enumerate*Layers by a set of new functions that do not distinguish instance and device layers. The new functions are also careful not to pollute the rest of the loader with std containers. There should be no user-visible change. Bug: 27911856 Change-Id: I4790fadc1aa2ea934a4628bce55dd45892f15e0b --- vulkan/libvulkan/api.cpp | 43 +++++++++++++++++++++++++++++++++++-------- 1 file changed, 35 insertions(+), 8 deletions(-) (limited to 'vulkan/libvulkan/api.cpp') diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp index e7f10b351b..e3f69fea82 100644 --- a/vulkan/libvulkan/api.cpp +++ b/vulkan/libvulkan/api.cpp @@ -1098,13 +1098,19 @@ VkResult EnumerateInstanceLayerProperties(uint32_t* pPropertyCount, if (!EnsureInitialized()) return VK_ERROR_INITIALIZATION_FAILED; - uint32_t count = - EnumerateInstanceLayers(pProperties ? *pPropertyCount : 0, pProperties); + uint32_t count = GetLayerCount(); - if (!pProperties || *pPropertyCount > count) + if (!pProperties) { *pPropertyCount = count; + return VK_SUCCESS; + } + + uint32_t copied = std::min(*pPropertyCount, count); + for (uint32_t i = 0; i < copied; i++) + pProperties[i] = GetLayerProperties(GetLayer(i)); + *pPropertyCount = copied; - return *pPropertyCount < count ? VK_INCOMPLETE : VK_SUCCESS; + return (copied == count) ? VK_SUCCESS : VK_INCOMPLETE; } VkResult EnumerateInstanceExtensionProperties( @@ -1137,13 +1143,34 @@ VkResult EnumerateDeviceLayerProperties(VkPhysicalDevice physicalDevice, VkLayerProperties* pProperties) { (void)physicalDevice; - uint32_t count = - EnumerateDeviceLayers(pProperties ? *pPropertyCount : 0, pProperties); + uint32_t total_count = GetLayerCount(); + + if (!pProperties) { + uint32_t count = 0; + for (uint32_t i = 0; i < total_count; i++) { + if (IsLayerGlobal(GetLayer(i))) + count++; + } - if (!pProperties || *pPropertyCount > count) *pPropertyCount = count; + return VK_SUCCESS; + } + + uint32_t count = 0; + uint32_t copied = 0; + for (uint32_t i = 0; i < total_count; i++) { + const Layer& layer = GetLayer(i); + if (!IsLayerGlobal(layer)) + continue; + + count++; + if (copied < *pPropertyCount) + pProperties[copied++] = GetLayerProperties(layer); + } + + *pPropertyCount = copied; - return *pPropertyCount < count ? VK_INCOMPLETE : VK_SUCCESS; + return (copied == count) ? VK_SUCCESS : VK_INCOMPLETE; } VkResult EnumerateDeviceExtensionProperties( -- cgit v1.2.3-59-g8ed1b