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
diff --git a/vulkan/libvulkan/api.cpp b/vulkan/libvulkan/api.cpp
index e7f10b3..e3f69fe 100644
--- a/vulkan/libvulkan/api.cpp
+++ b/vulkan/libvulkan/api.cpp
@@ -1098,13 +1098,19 @@
     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;
+    }
 
-    return *pPropertyCount < count ? VK_INCOMPLETE : 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 (copied == count) ? VK_SUCCESS : VK_INCOMPLETE;
 }
 
 VkResult EnumerateInstanceExtensionProperties(
@@ -1137,13 +1143,34 @@
                                         VkLayerProperties* pProperties) {
     (void)physicalDevice;
 
-    uint32_t count =
-        EnumerateDeviceLayers(pProperties ? *pPropertyCount : 0, pProperties);
+    uint32_t total_count = GetLayerCount();
 
-    if (!pProperties || *pPropertyCount > count)
+    if (!pProperties) {
+        uint32_t count = 0;
+        for (uint32_t i = 0; i < total_count; i++) {
+            if (IsLayerGlobal(GetLayer(i)))
+                count++;
+        }
+
         *pPropertyCount = count;
+        return VK_SUCCESS;
+    }
 
-    return *pPropertyCount < count ? VK_INCOMPLETE : 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 (copied == count) ? VK_SUCCESS : VK_INCOMPLETE;
 }
 
 VkResult EnumerateDeviceExtensionProperties(